This is a note to let you know that I've just added the patch titled KVM: x86: Drop .post_leave_smm(), i.e. the manual post-RSM MMU reset to the 5.10-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: kvm-x86-drop-.post_leave_smm-i.e.-the-manual-post-rs.patch and it can be found in the queue-5.10 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 44547012febf343ca7bf53890bbe2a42c22aaa0d Author: Sean Christopherson <seanjc@xxxxxxxxxx> Date: Wed Jun 9 11:56:18 2021 -0700 KVM: x86: Drop .post_leave_smm(), i.e. the manual post-RSM MMU reset [ Upstream commit 0128116550acf52043a0aa5cca3caa85e3853aca ] Drop the .post_leave_smm() emulator callback, which at this point is just a wrapper to kvm_mmu_reset_context(). The manual context reset is unnecessary, because unlike enter_smm() which calls vendor MSR/CR helpers directly, em_rsm() bounces through the KVM helpers, e.g. kvm_set_cr4(), which are responsible for processing side effects. em_rsm() is already subtly relying on this behavior as it doesn't manually do kvm_update_cpuid_runtime(), e.g. to recognize CR4.OSXSAVE changes. Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx> Message-Id: <20210609185619.992058-9-seanjc@xxxxxxxxxx> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx> Stable-dep-of: 055f37f84e30 ("KVM: x86: emulator: update the emulation mode after rsm") Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 2e6d7640c4ed..d5da89271318 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -2741,8 +2741,14 @@ static int em_rsm(struct x86_emulate_ctxt *ctxt) if (ret != X86EMUL_CONTINUE) goto emulate_shutdown; - ctxt->ops->post_leave_smm(ctxt); - + /* + * Note, the ctxt->ops callbacks are responsible for handling side + * effects when writing MSRs and CRs, e.g. MMU context resets, CPUID + * runtime updates, etc... If that changes, e.g. this flow is moved + * out of the emulator to make it look more like enter_smm(), then + * those side effects need to be explicitly handled for both success + * and shutdown. + */ return X86EMUL_CONTINUE; emulate_shutdown: diff --git a/arch/x86/kvm/kvm_emulate.h b/arch/x86/kvm/kvm_emulate.h index 148ba21d0646..3650db9e5ed5 100644 --- a/arch/x86/kvm/kvm_emulate.h +++ b/arch/x86/kvm/kvm_emulate.h @@ -233,7 +233,6 @@ struct x86_emulate_ops { void (*exiting_smm)(struct x86_emulate_ctxt *ctxt); int (*pre_leave_smm)(struct x86_emulate_ctxt *ctxt, const char *smstate); - void (*post_leave_smm)(struct x86_emulate_ctxt *ctxt); void (*triple_fault)(struct x86_emulate_ctxt *ctxt); int (*set_xcr)(struct x86_emulate_ctxt *ctxt, u32 index, u64 xcr); }; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index ef43bfa1b3a8..e04e97b0661c 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -7013,11 +7013,6 @@ static int emulator_pre_leave_smm(struct x86_emulate_ctxt *ctxt, return kvm_x86_ops.pre_leave_smm(emul_to_vcpu(ctxt), smstate); } -static void emulator_post_leave_smm(struct x86_emulate_ctxt *ctxt) -{ - kvm_mmu_reset_context(emul_to_vcpu(ctxt)); -} - static void emulator_triple_fault(struct x86_emulate_ctxt *ctxt) { kvm_make_request(KVM_REQ_TRIPLE_FAULT, emul_to_vcpu(ctxt)); @@ -7072,7 +7067,6 @@ static const struct x86_emulate_ops emulate_ops = { .get_hflags = emulator_get_hflags, .exiting_smm = emulator_exiting_smm, .pre_leave_smm = emulator_pre_leave_smm, - .post_leave_smm = emulator_post_leave_smm, .triple_fault = emulator_triple_fault, .set_xcr = emulator_set_xcr, };