KVM: x86: Load SMRAM in a single shot when leaving SMM
Paolo Bonzini
maintainerQuoted 4 lines · Sean Christopherson
Ostensibly, the only motivation for having
HF_SMM_MASKset throughout the loading of state from the SMRAM save state area is so that the memory accesses fromGET_SMSTATE()are tagged with role.smm (though arguably even that is unnecessary).
Why is that unnecessary? If they do not have role.smm they would access video RAM or TSEG, not the state save area.
Paolo
Re: [PATCH 0/3] KVM: x86: clear HF_SMM_MASK before loading state
In reply to a message not in the archiveQuoted 26 lines · Sean Christopherson
RSM emulation is currently broken on VMX when the interrupted guest has CR4.VMXE=1. Similar breakage has also occurred in the past due to
HF_SMM_MASKbeing cleared only after RSM completes, i.e. loading non-SMM state whileis_smm()returns true is unsurprisingly problematic.Rather than dance around the issue of
HF_SMM_MASKbeing set when loading SMSTATE into architectural state, rework RSM emulation itself to clearHF_SMM_MASKprior to loading architectural state. AFAICT, the only
motivation for havingHF_SMM_MASKset throughout is so that the memory access fromGET_SMSTATE()are tagged with role.smm (though arguably even that is unnecessary). Sidestep that particular issue by taking theenter_smm()approach of reading all of SMSTATE into a buffer and then loading state from the buffer.The actual fix is the same concept as an earlier RFC, but without first moving
em_rsm()tox86.c, i.e. doesn't add a big pile of dependent patches before fixing the bug. I'm still planning on sending a series to move the bulk ofem_rsm()tox86.c, but it'll be a true cleanup.[1] https://patchwork.kernel.org/cover/10875623/
Sean Christopherson (3):
KVM: x86: Load SMRAM in a single shot when leaving SMM
KVM: x86: Open codekvm_set_hflags
KVM: x86: clear SMM flags before loading state while leaving SMM
Quoted 8 lines
arch/x86/include/asm/kvm_emulate.h | 4 +- arch/x86/include/asm/kvm_host.h | 5 +- arch/x86/kvm/emulate.c | 160 +++++++++++++++-------------- arch/x86/kvm/svm.c | 30 ++---- arch/x86/kvm/vmx/vmx.c | 4 +- arch/x86/kvm/x86.c | 38 ++++--- 6 files changed, 118 insertions(+), 123 deletions(-)
Queued, thanks. I only changed the name of the emulator callback from smm_changed to post_leave_smm, since it is invoked only on RSM.
Paolo
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines · Sean Christopherson
Ostensibly, the only motivation for having
HF_SMM_MASKset throughout the loading of state from the SMRAM save state area is so that the memory accesses fromGET_SMSTATE()are tagged with role.smm (though arguably even that is unnecessary).Why is that unnecessary? If they do not have role.smm they would access video RAM or TSEG, not the state save area.
You're right, feel free to strike that line from the record. For some reason I had it in my mind that enter_smm() was writing SMRAM before setting HF_SMM_MASK.