Skip to content

Commit 19bff88

Browse files
waylingavpatel
authored andcommitted
RISC-V: KVM: Redirect AMO load/store misaligned traps to guest
The M-mode redirects an unhandled misaligned trap back to S-mode when not delegating it to VS-mode(hedeleg). However, KVM running in HS-mode terminates the VS-mode software when back from M-mode. The KVM should redirect the trap back to VS-mode, and let VS-mode trap handler decide the next step. Here is a way to handle misaligned traps in KVM, not only directing them to VS-mode or terminate it. Signed-off-by: wchen <waylingII@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 7832908 commit 19bff88

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

arch/riscv/include/asm/csr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@
8282
#define EXC_INST_ACCESS 1
8383
#define EXC_INST_ILLEGAL 2
8484
#define EXC_BREAKPOINT 3
85+
#define EXC_LOAD_MISALIGNED 4
8586
#define EXC_LOAD_ACCESS 5
87+
#define EXC_STORE_MISALIGNED 6
8688
#define EXC_STORE_ACCESS 7
8789
#define EXC_SYSCALL 8
8890
#define EXC_HYPERVISOR_SYSCALL 9

arch/riscv/kvm/vcpu_exit.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run,
183183
run->exit_reason = KVM_EXIT_UNKNOWN;
184184
switch (trap->scause) {
185185
case EXC_INST_ILLEGAL:
186+
case EXC_LOAD_MISALIGNED:
187+
case EXC_STORE_MISALIGNED:
186188
if (vcpu->arch.guest_context.hstatus & HSTATUS_SPV) {
187189
kvm_riscv_vcpu_trap_redirect(vcpu, trap);
188190
ret = 1;

0 commit comments

Comments
 (0)