Skip to content

Commit edef528

Browse files
author
Marc Zyngier
committed
arm64: KVM: VHE: Differenciate host/guest sysreg save/restore
With ARMv8, host and guest share the same system register file, making the save/restore procedure completely symetrical. With VHE, host and guest now have different requirements, as they use different sysregs. In order to prepare for this, add split sysreg save/restore functions for both host and guest. No functional changes yet. Acked-by: Christoffer Dall <[email protected]> Signed-off-by: Marc Zyngier <[email protected]>
1 parent 915ccd1 commit edef528

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

arch/arm64/kvm/hyp/hyp.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ void __vgic_v3_restore_state(struct kvm_vcpu *vcpu);
153153
void __timer_save_state(struct kvm_vcpu *vcpu);
154154
void __timer_restore_state(struct kvm_vcpu *vcpu);
155155

156-
void __sysreg_save_state(struct kvm_cpu_context *ctxt);
157-
void __sysreg_restore_state(struct kvm_cpu_context *ctxt);
156+
void __sysreg_save_host_state(struct kvm_cpu_context *ctxt);
157+
void __sysreg_restore_host_state(struct kvm_cpu_context *ctxt);
158+
void __sysreg_save_guest_state(struct kvm_cpu_context *ctxt);
159+
void __sysreg_restore_guest_state(struct kvm_cpu_context *ctxt);
158160
void __sysreg32_save_state(struct kvm_vcpu *vcpu);
159161
void __sysreg32_restore_state(struct kvm_vcpu *vcpu);
160162

arch/arm64/kvm/hyp/switch.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int __hyp_text __guest_run(struct kvm_vcpu *vcpu)
102102
host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
103103
guest_ctxt = &vcpu->arch.ctxt;
104104

105-
__sysreg_save_state(host_ctxt);
105+
__sysreg_save_host_state(host_ctxt);
106106
__debug_cond_save_host_state(vcpu);
107107

108108
__activate_traps(vcpu);
@@ -116,7 +116,7 @@ static int __hyp_text __guest_run(struct kvm_vcpu *vcpu)
116116
* to Cortex-A57 erratum #852523.
117117
*/
118118
__sysreg32_restore_state(vcpu);
119-
__sysreg_restore_state(guest_ctxt);
119+
__sysreg_restore_guest_state(guest_ctxt);
120120
__debug_restore_state(vcpu, kern_hyp_va(vcpu->arch.debug_ptr), guest_ctxt);
121121

122122
/* Jump in the fire! */
@@ -125,15 +125,15 @@ static int __hyp_text __guest_run(struct kvm_vcpu *vcpu)
125125

126126
fp_enabled = __fpsimd_enabled();
127127

128-
__sysreg_save_state(guest_ctxt);
128+
__sysreg_save_guest_state(guest_ctxt);
129129
__sysreg32_save_state(vcpu);
130130
__timer_save_state(vcpu);
131131
__vgic_save_state(vcpu);
132132

133133
__deactivate_traps(vcpu);
134134
__deactivate_vm(vcpu);
135135

136-
__sysreg_restore_state(host_ctxt);
136+
__sysreg_restore_host_state(host_ctxt);
137137

138138
if (fp_enabled) {
139139
__fpsimd_save_state(&guest_ctxt->gp_regs.fp_regs);
@@ -165,7 +165,7 @@ void __hyp_text __noreturn __hyp_panic(void)
165165
host_ctxt = kern_hyp_va(vcpu->arch.host_cpu_context);
166166
__deactivate_traps(vcpu);
167167
__deactivate_vm(vcpu);
168-
__sysreg_restore_state(host_ctxt);
168+
__sysreg_restore_host_state(host_ctxt);
169169
}
170170

171171
/* Call panic for real */

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
#include "hyp.h"
2525

2626
/* ctxt is already in the HYP VA space */
27-
void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
27+
static void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
2828
{
2929
ctxt->sys_regs[MPIDR_EL1] = read_sysreg(vmpidr_el2);
3030
ctxt->sys_regs[CSSELR_EL1] = read_sysreg(csselr_el1);
@@ -57,7 +57,17 @@ void __hyp_text __sysreg_save_state(struct kvm_cpu_context *ctxt)
5757
ctxt->gp_regs.spsr[KVM_SPSR_EL1]= read_sysreg(spsr_el1);
5858
}
5959

60-
void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
60+
void __hyp_text __sysreg_save_host_state(struct kvm_cpu_context *ctxt)
61+
{
62+
__sysreg_save_state(ctxt);
63+
}
64+
65+
void __hyp_text __sysreg_save_guest_state(struct kvm_cpu_context *ctxt)
66+
{
67+
__sysreg_save_state(ctxt);
68+
}
69+
70+
static void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
6171
{
6272
write_sysreg(ctxt->sys_regs[MPIDR_EL1], vmpidr_el2);
6373
write_sysreg(ctxt->sys_regs[CSSELR_EL1], csselr_el1);
@@ -90,6 +100,16 @@ void __hyp_text __sysreg_restore_state(struct kvm_cpu_context *ctxt)
90100
write_sysreg(ctxt->gp_regs.spsr[KVM_SPSR_EL1], spsr_el1);
91101
}
92102

103+
void __hyp_text __sysreg_restore_host_state(struct kvm_cpu_context *ctxt)
104+
{
105+
__sysreg_restore_state(ctxt);
106+
}
107+
108+
void __hyp_text __sysreg_restore_guest_state(struct kvm_cpu_context *ctxt)
109+
{
110+
__sysreg_restore_state(ctxt);
111+
}
112+
93113
void __hyp_text __sysreg32_save_state(struct kvm_vcpu *vcpu)
94114
{
95115
u64 *spsr, *sysreg;

0 commit comments

Comments
 (0)