Message ID | 20220128121912.509006-16-maz@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | KVM: arm64: ARMv8.3/8.4 Nested Virtualization support | expand |
On Fri, Jan 28, 2022 at 12:18:23PM +0000, Marc Zyngier wrote: > HCR_EL2.E2H is nasty, as a flip of this bit completely changes the way > we deal with a lot of the state. So when the guest flips this bit > (sysregs are live), do the put/load dance so that we have a consistent > state. > > Yes, this is slow. Don't do it. I'd hope this is very unlikely! > > Suggested-by: Alexandru Elisei <alexandru.elisei@arm.com> > Signed-off-by: Marc Zyngier <maz@kernel.org> Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
On 2022-02-01 16:51, Russell King (Oracle) wrote: > On Fri, Jan 28, 2022 at 12:18:23PM +0000, Marc Zyngier wrote: >> HCR_EL2.E2H is nasty, as a flip of this bit completely changes the way >> we deal with a lot of the state. So when the guest flips this bit >> (sysregs are live), do the put/load dance so that we have a consistent >> state. >> >> Yes, this is slow. Don't do it. > > I'd hope this is very unlikely! A guest OS would probably do it once per CPU bring-up. So I'm not too bothered about the speed. But that's only one of the many cases where we need to do this put/load game. At this stage, we don't care too much. But the last two patches give you a glimpse of what sort of fine-grained optimisation we will eventually want to do for this not to suck too much. But again, this is NV, and it gives a whole new sense to "being slow". > >> >> Suggested-by: Alexandru Elisei <alexandru.elisei@arm.com> >> Signed-off-by: Marc Zyngier <maz@kernel.org> > > Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Thanks, M.
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index ace4a54caef9..102bc4906723 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -183,9 +183,24 @@ void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg) goto memory_write; if (unlikely(get_el2_to_el1_mapping(reg, &el1r, &xlate))) { + bool need_put_load; + if (!is_hyp_ctxt(vcpu)) goto memory_write; + /* + * HCR_EL2.E2H is nasty: it changes the way we interpret a + * lot of the EL2 state, so treat is as a full state + * transition. + */ + need_put_load = ((reg == HCR_EL2) && + vcpu_el2_e2h_is_set(vcpu) != !!(val & HCR_E2H)); + + if (need_put_load) { + preempt_disable(); + kvm_arch_vcpu_put(vcpu); + } + /* * Always store a copy of the write to memory to avoid having * to reverse-translate virtual EL2 system registers for a @@ -193,6 +208,11 @@ void vcpu_write_sys_reg(struct kvm_vcpu *vcpu, u64 val, int reg) */ __vcpu_sys_reg(vcpu, reg) = val; + if (need_put_load) { + kvm_arch_vcpu_load(vcpu, smp_processor_id()); + preempt_enable(); + } + switch (reg) { case ELR_EL2: write_sysreg_el1(val, SYS_ELR);
HCR_EL2.E2H is nasty, as a flip of this bit completely changes the way we deal with a lot of the state. So when the guest flips this bit (sysregs are live), do the put/load dance so that we have a consistent state. Yes, this is slow. Don't do it. Suggested-by: Alexandru Elisei <alexandru.elisei@arm.com> Signed-off-by: Marc Zyngier <maz@kernel.org> --- arch/arm64/kvm/sys_regs.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)