kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] VMX: nested migration fixes for 32 bit nested guests
@ 2021-11-15 13:18 Maxim Levitsky
  2021-11-15 13:18 ` [PATCH v2 1/2] KVM: nVMX: don't use vcpu->arch.efer when checking host state on nested state load Maxim Levitsky
  2021-11-15 13:18 ` [PATCH v2 2/2] KVM: x86/mmu: include efer.lma in extended mmu role Maxim Levitsky
  0 siblings, 2 replies; 6+ messages in thread
From: Maxim Levitsky @ 2021-11-15 13:18 UTC (permalink / raw)
  To: kvm
  Cc: Vitaly Kuznetsov, Joerg Roedel,
	maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	open list:X86 ARCHITECTURE (32-BIT AND 64-BIT),
	Thomas Gleixner, Sean Christopherson, Paolo Bonzini, Jim Mattson,
	Ingo Molnar, H. Peter Anvin, Wanpeng Li, Borislav Petkov,
	Maxim Levitsky

This is hopefully the last issue I was tracking in regard to nested migration,
as far as I know.

The issue is that migration of L1 which is normal 64 bit guest,
but is running a 32 bit nested guest is broken on VMX and I finally found out why.

There are two bugs, both related to the fact that qemu first restores SREGS
of L2, and only then sets the nested state. That haunts us till this day.

First issue is that vmx_set_nested_state does some checks on the host
state stored in vmcs12, but it uses the current IA32_EFER which is from L2.
Thus, consistency checks fail.

Second issue (happens on both VMX and SVM with npt/ept enabled in both L0 and L1)
is that after migration L1 mmu (aka root_mmu) is initialized by L2's IA32_EFER
due to the way qemu loads SREGS before the nested state, and later is not
initialized again because in this particular case the 32 bitness of L2's IA32_EFER
is not captured in mmu role.

V2:
Thanks to Sean and Paolo for helping me make more correct fixes for both of the issues.

I still haven't researched the 'fixes' tag, since I suspect that 32 bit nested
migration wasn't tested much ever, so this bug might be present since long time ago.

Best regards,
	Maxim Levitsky

Maxim Levitsky (2):
  KVM: nVMX: don't use vcpu->arch.efer when checking host state on
    nested state load
  KVM: x86/mmu: include efer.lma in extended mmu role

 arch/x86/include/asm/kvm_host.h |  1 +
 arch/x86/kvm/mmu/mmu.c          |  1 +
 arch/x86/kvm/vmx/nested.c       | 22 +++++++++++++++++-----
 3 files changed, 19 insertions(+), 5 deletions(-)

-- 
2.26.3



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-11-16 10:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-15 13:18 [PATCH v2 0/2] VMX: nested migration fixes for 32 bit nested guests Maxim Levitsky
2021-11-15 13:18 ` [PATCH v2 1/2] KVM: nVMX: don't use vcpu->arch.efer when checking host state on nested state load Maxim Levitsky
2021-11-15 15:50   ` Sean Christopherson
2021-11-16 10:03     ` Paolo Bonzini
2021-11-15 13:18 ` [PATCH v2 2/2] KVM: x86/mmu: include efer.lma in extended mmu role Maxim Levitsky
2021-11-15 20:44   ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).