KVM: x86: Replace .set_hflags() with dedicated .exiting_smm() helper
authorSean Christopherson <seanjc@google.com>
Wed, 9 Jun 2021 18:56:13 +0000 (11:56 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 17 Jun 2021 17:09:34 +0000 (13:09 -0400)
Replace the .set_hflags() emulator hook with a dedicated .exiting_smm(),
moving the SMM and SMM_INSIDE_NMI flag handling out of the emulator in
the process.  This is a step towards consolidating much of the logic in
kvm_smm_changed(), including the SMM hflags updates.

No functional change intended.

Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210609185619.992058-4-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/emulate.c
arch/x86/kvm/kvm_emulate.h
arch/x86/kvm/x86.c

index 63f9ca1c0ce063c68c6b1e36f26d1e046e49da2d..4996eec7aa79fce12109989639f859c1f0716711 100644 (file)
@@ -2535,8 +2535,7 @@ static int em_rsm(struct x86_emulate_ctxt *ctxt)
        if ((ctxt->ops->get_hflags(ctxt) & X86EMUL_SMM_INSIDE_NMI_MASK) == 0)
                ctxt->ops->set_nmi_mask(ctxt, false);
 
-       ctxt->ops->set_hflags(ctxt, ctxt->ops->get_hflags(ctxt) &
-               ~(X86EMUL_SMM_INSIDE_NMI_MASK | X86EMUL_SMM_MASK));
+       ctxt->ops->exiting_smm(ctxt);
 
        /*
         * Get back to real mode, to prepare a safe state in which to load
index 357cfd1ccafd7d6ec8a7f7270dd1945a2764687e..298bb0da7b973dfec513260f415c6789f85746a9 100644 (file)
@@ -230,7 +230,7 @@ struct x86_emulate_ops {
        void (*set_nmi_mask)(struct x86_emulate_ctxt *ctxt, bool masked);
 
        unsigned (*get_hflags)(struct x86_emulate_ctxt *ctxt);
-       void (*set_hflags)(struct x86_emulate_ctxt *ctxt, unsigned hflags);
+       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);
index 7bd1ddfec5221a66a3d699803b42c307b6080893..15a9859b604647b5e98c6a726e4d4e1a92f00b61 100644 (file)
@@ -7214,11 +7214,11 @@ static unsigned emulator_get_hflags(struct x86_emulate_ctxt *ctxt)
        return emul_to_vcpu(ctxt)->arch.hflags;
 }
 
-static void emulator_set_hflags(struct x86_emulate_ctxt *ctxt, unsigned emul_flags)
+static void emulator_exiting_smm(struct x86_emulate_ctxt *ctxt)
 {
        struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
 
-       vcpu->arch.hflags = emul_flags;
+       vcpu->arch.hflags &= ~(HF_SMM_MASK | HF_SMM_INSIDE_NMI_MASK);
        kvm_mmu_reset_context(vcpu);
 }
 
@@ -7284,7 +7284,7 @@ static const struct x86_emulate_ops emulate_ops = {
        .guest_has_fxsr      = emulator_guest_has_fxsr,
        .set_nmi_mask        = emulator_set_nmi_mask,
        .get_hflags          = emulator_get_hflags,
-       .set_hflags          = emulator_set_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,