Skip to content

Commit 9c6c356

Browse files
author
Marc Zyngier
committed
arm64: KVM: VHE: Split save/restore of registers shared between guest and host
A handful of system registers are still shared between host and guest, even while using VHE (tpidr*_el[01] and actlr_el1). Also, some of the vcpu state (sp_el0, PC and PSTATE) must be save/restored on entry/exit, as they are used on the host as well. In order to facilitate the introduction of a VHE-specific sysreg save/restore, make move the access to these registers to their own save/restore functions. No functional change. Reviewed-by: Christoffer Dall <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent edef528 commit 9c6c356

File tree

1 file changed

+33
-15
lines changed

1 file changed

+33
-15
lines changed

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

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,29 @@
2323

2424
#include "hyp.h"
2525

26-
/* ctxt is already in the HYP VA space */
26+
/*
27+
* Non-VHE: Both host and guest must save everything.
28+
*
29+
* VHE: Host must save tpidr*_el[01], actlr_el1, sp0, pc, pstate, and
30+
* guest must save everything.
31+
*/
32+
33+
static void __hyp_text __sysreg_save_common_state(struct kvm_cpu_context *ctxt)
34+
{
35+
ctxt->sys_regs[ACTLR_EL1] = read_sysreg(actlr_el1);
36+
ctxt->sys_regs[TPIDR_EL0] = read_sysreg(tpidr_el0);
37+
ctxt->sys_regs[TPIDRRO_EL0] = read_sysreg(tpidrro_el0);
38+
ctxt->sys_regs[TPIDR_EL1] = read_sysreg(tpidr_el1);
39+
ctxt->gp_regs.regs.sp = read_sysreg(sp_el0);
40+
ctxt->gp_regs.regs.pc = read_sysreg(elr_el2);
41+
ctxt->gp_regs.regs.pstate = read_sysreg(spsr_el2);
42+
}
43+
2744
static void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
2845
{
2946
ctxt->sys_regs[MPIDR_EL1] = read_sysreg(vmpidr_el2);
3047
ctxt->sys_regs[CSSELR_EL1] = read_sysreg(csselr_el1);
3148
ctxt->sys_regs[SCTLR_EL1] = read_sysreg(sctlr_el1);
32-
ctxt->sys_regs[ACTLR_EL1] = read_sysreg(actlr_el1);
3349
ctxt->sys_regs[CPACR_EL1] = read_sysreg(cpacr_el1);
3450
ctxt->sys_regs[TTBR0_EL1] = read_sysreg(ttbr0_el1);
3551
ctxt->sys_regs[TTBR1_EL1] = read_sysreg(ttbr1_el1);
@@ -41,17 +57,11 @@ static void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
4157
ctxt->sys_regs[MAIR_EL1] = read_sysreg(mair_el1);
4258
ctxt->sys_regs[VBAR_EL1] = read_sysreg(vbar_el1);
4359
ctxt->sys_regs[CONTEXTIDR_EL1] = read_sysreg(contextidr_el1);
44-
ctxt->sys_regs[TPIDR_EL0] = read_sysreg(tpidr_el0);
45-
ctxt->sys_regs[TPIDRRO_EL0] = read_sysreg(tpidrro_el0);
46-
ctxt->sys_regs[TPIDR_EL1] = read_sysreg(tpidr_el1);
4760
ctxt->sys_regs[AMAIR_EL1] = read_sysreg(amair_el1);
4861
ctxt->sys_regs[CNTKCTL_EL1] = read_sysreg(cntkctl_el1);
4962
ctxt->sys_regs[PAR_EL1] = read_sysreg(par_el1);
5063
ctxt->sys_regs[MDSCR_EL1] = read_sysreg(mdscr_el1);
5164

52-
ctxt->gp_regs.regs.sp = read_sysreg(sp_el0);
53-
ctxt->gp_regs.regs.pc = read_sysreg(elr_el2);
54-
ctxt->gp_regs.regs.pstate = read_sysreg(spsr_el2);
5565
ctxt->gp_regs.sp_el1 = read_sysreg(sp_el1);
5666
ctxt->gp_regs.elr_el1 = read_sysreg(elr_el1);
5767
ctxt->gp_regs.spsr[KVM_SPSR_EL1]= read_sysreg(spsr_el1);
@@ -60,19 +70,31 @@ static void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
6070
void __hyp_text __sysreg_save_host_state(struct kvm_cpu_context *ctxt)
6171
{
6272
__sysreg_save_state(ctxt);
73+
__sysreg_save_common_state(ctxt);
6374
}
6475

6576
void __hyp_text __sysreg_save_guest_state(struct kvm_cpu_context *ctxt)
6677
{
6778
__sysreg_save_state(ctxt);
79+
__sysreg_save_common_state(ctxt);
80+
}
81+
82+
static void __hyp_text __sysreg_restore_common_state(struct kvm_cpu_context *ctxt)
83+
{
84+
write_sysreg(ctxt->sys_regs[ACTLR_EL1], actlr_el1);
85+
write_sysreg(ctxt->sys_regs[TPIDR_EL0], tpidr_el0);
86+
write_sysreg(ctxt->sys_regs[TPIDRRO_EL0], tpidrro_el0);
87+
write_sysreg(ctxt->sys_regs[TPIDR_EL1], tpidr_el1);
88+
write_sysreg(ctxt->gp_regs.regs.sp, sp_el0);
89+
write_sysreg(ctxt->gp_regs.regs.pc, elr_el2);
90+
write_sysreg(ctxt->gp_regs.regs.pstate, spsr_el2);
6891
}
6992

7093
static void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
7194
{
7295
write_sysreg(ctxt->sys_regs[MPIDR_EL1], vmpidr_el2);
7396
write_sysreg(ctxt->sys_regs[CSSELR_EL1], csselr_el1);
7497
write_sysreg(ctxt->sys_regs[SCTLR_EL1], sctlr_el1);
75-
write_sysreg(ctxt->sys_regs[ACTLR_EL1], actlr_el1);
7698
write_sysreg(ctxt->sys_regs[CPACR_EL1], cpacr_el1);
7799
write_sysreg(ctxt->sys_regs[TTBR0_EL1], ttbr0_el1);
78100
write_sysreg(ctxt->sys_regs[TTBR1_EL1], ttbr1_el1);
@@ -84,17 +106,11 @@ static void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
84106
write_sysreg(ctxt->sys_regs[MAIR_EL1], mair_el1);
85107
write_sysreg(ctxt->sys_regs[VBAR_EL1], vbar_el1);
86108
write_sysreg(ctxt->sys_regs[CONTEXTIDR_EL1], contextidr_el1);
87-
write_sysreg(ctxt->sys_regs[TPIDR_EL0], tpidr_el0);
88-
write_sysreg(ctxt->sys_regs[TPIDRRO_EL0], tpidrro_el0);
89-
write_sysreg(ctxt->sys_regs[TPIDR_EL1], tpidr_el1);
90109
write_sysreg(ctxt->sys_regs[AMAIR_EL1], amair_el1);
91110
write_sysreg(ctxt->sys_regs[CNTKCTL_EL1], cntkctl_el1);
92111
write_sysreg(ctxt->sys_regs[PAR_EL1], par_el1);
93112
write_sysreg(ctxt->sys_regs[MDSCR_EL1], mdscr_el1);
94113

95-
write_sysreg(ctxt->gp_regs.regs.sp, sp_el0);
96-
write_sysreg(ctxt->gp_regs.regs.pc, elr_el2);
97-
write_sysreg(ctxt->gp_regs.regs.pstate, spsr_el2);
98114
write_sysreg(ctxt->gp_regs.sp_el1, sp_el1);
99115
write_sysreg(ctxt->gp_regs.elr_el1, elr_el1);
100116
write_sysreg(ctxt->gp_regs.spsr[KVM_SPSR_EL1], spsr_el1);
@@ -103,11 +119,13 @@ static void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
103119
void __hyp_text __sysreg_restore_host_state(struct kvm_cpu_context *ctxt)
104120
{
105121
__sysreg_restore_state(ctxt);
122+
__sysreg_restore_common_state(ctxt);
106123
}
107124

108125
void __hyp_text __sysreg_restore_guest_state(struct kvm_cpu_context *ctxt)
109126
{
110127
__sysreg_restore_state(ctxt);
128+
__sysreg_restore_common_state(ctxt);
111129
}
112130

113131
void __hyp_text __sysreg32_save_state(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)