Skip to content

Commit 4c47eb1

Browse files
Marc Zyngierrkrcmar
authored andcommitted
arm64: KVM: VHE: Context switch MDSCR_EL1
The kprobe enablement work has uncovered that changes made by a guest to MDSCR_EL1 were propagated to the host when VHE was enabled, leading to unexpected exception being delivered. Moving this register to the list of registers that are always context-switched fixes the issue. Fixes: 9c6c356 ("arm64: KVM: VHE: Split save/restore of registers shared between guest and host") Cc: [email protected] #4.6 Reported-by: Tirumalesh Chalamarla <[email protected]> Tested-by: Tirumalesh Chalamarla <[email protected]> Signed-off-by: Marc Zyngier <[email protected]> Signed-off-by: Radim Krčmář <[email protected]>
1 parent b244c9f commit 4c47eb1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/arm64/kvm/hyp/sysreg-sr.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ static void __hyp_text __sysreg_do_nothing(struct kvm_cpu_context *ctxt) { }
2727
/*
2828
* Non-VHE: Both host and guest must save everything.
2929
*
30-
* VHE: Host must save tpidr*_el[01], actlr_el1, sp0, pc, pstate, and
31-
* guest must save everything.
30+
* VHE: Host must save tpidr*_el[01], actlr_el1, mdscr_el1, sp0, pc,
31+
* pstate, and guest must save everything.
3232
*/
3333

3434
static void __hyp_text __sysreg_save_common_state(struct kvm_cpu_context *ctxt)
@@ -37,6 +37,7 @@ static void __hyp_text __sysreg_save_common_state(struct kvm_cpu_context *ctxt)
3737
ctxt->sys_regs[TPIDR_EL0] = read_sysreg(tpidr_el0);
3838
ctxt->sys_regs[TPIDRRO_EL0] = read_sysreg(tpidrro_el0);
3939
ctxt->sys_regs[TPIDR_EL1] = read_sysreg(tpidr_el1);
40+
ctxt->sys_regs[MDSCR_EL1] = read_sysreg(mdscr_el1);
4041
ctxt->gp_regs.regs.sp = read_sysreg(sp_el0);
4142
ctxt->gp_regs.regs.pc = read_sysreg_el2(elr);
4243
ctxt->gp_regs.regs.pstate = read_sysreg_el2(spsr);
@@ -61,7 +62,6 @@ static void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
6162
ctxt->sys_regs[AMAIR_EL1] = read_sysreg_el1(amair);
6263
ctxt->sys_regs[CNTKCTL_EL1] = read_sysreg_el1(cntkctl);
6364
ctxt->sys_regs[PAR_EL1] = read_sysreg(par_el1);
64-
ctxt->sys_regs[MDSCR_EL1] = read_sysreg(mdscr_el1);
6565

6666
ctxt->gp_regs.sp_el1 = read_sysreg(sp_el1);
6767
ctxt->gp_regs.elr_el1 = read_sysreg_el1(elr);
@@ -90,6 +90,7 @@ static void __hyp_text __sysreg_restore_common_state(struct kvm_cpu_context *ctx
9090
write_sysreg(ctxt->sys_regs[TPIDR_EL0], tpidr_el0);
9191
write_sysreg(ctxt->sys_regs[TPIDRRO_EL0], tpidrro_el0);
9292
write_sysreg(ctxt->sys_regs[TPIDR_EL1], tpidr_el1);
93+
write_sysreg(ctxt->sys_regs[MDSCR_EL1], mdscr_el1);
9394
write_sysreg(ctxt->gp_regs.regs.sp, sp_el0);
9495
write_sysreg_el2(ctxt->gp_regs.regs.pc, elr);
9596
write_sysreg_el2(ctxt->gp_regs.regs.pstate, spsr);
@@ -114,7 +115,6 @@ static void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
114115
write_sysreg_el1(ctxt->sys_regs[AMAIR_EL1], amair);
115116
write_sysreg_el1(ctxt->sys_regs[CNTKCTL_EL1], cntkctl);
116117
write_sysreg(ctxt->sys_regs[PAR_EL1], par_el1);
117-
write_sysreg(ctxt->sys_regs[MDSCR_EL1], mdscr_el1);
118118

119119
write_sysreg(ctxt->gp_regs.sp_el1, sp_el1);
120120
write_sysreg_el1(ctxt->gp_regs.elr_el1, elr);

0 commit comments

Comments
 (0)