Skip to contentSkip to conversation

KVM: x86: Load SMRAM in a single shot when leaving SMM

PATCH Paolo Bonzini 2 participants 3 messages Apr 10, 2019 2 messages not in the archive KVM

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

Paolo Bonzini

author maintainer
#2 lore raw
Quoted 4 lines · Sean Christopherson

Ostensibly, the only motivation for having HF_SMM_MASK set throughout the loading of state from the SMRAM save state area is so that the memory accesses from GET_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

#3 lore raw
Quoted 8 lines · Paolo Bonzini
Quoted 4 lines · Sean Christopherson

Ostensibly, the only motivation for having HF_SMM_MASK set throughout the loading of state from the SMRAM save state area is so that the memory accesses from GET_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.

author maintainer Applied
#4 lore raw

Re: [PATCH 0/3] KVM: x86: clear HF_SMM_MASK before loading state

In reply to a message not in the archive
Quoted 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_MASK being cleared only after RSM completes, i.e. loading non-SMM state while is_smm() returns true is unsurprisingly problematic.

Rather than dance around the issue of HF_SMM_MASK being set when loading SMSTATE into architectural state, rework RSM emulation itself to clear
HF_SMM_MASK prior to loading architectural state. AFAICT, the only
motivation for having HF_SMM_MASK set throughout is so that the memory access from GET_SMSTATE() are tagged with role.smm (though arguably even that is unnecessary). Sidestep that particular issue by taking the enter_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() to x86.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 of em_rsm() to x86.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 code kvm_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