From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
maciej.szmigiero@oracle.com
Subject: Re: [PATCH v2 8/8] KVM: x86: do not define KVM_REQ_SMI if SMM disabled
Date: Fri, 14 Oct 2022 21:06:37 +0000 [thread overview]
Message-ID: <Y0nPXfVT1pUaGppn@google.com> (raw)
In-Reply-To: <20220929172016.319443-9-pbonzini@redhat.com>
On Thu, Sep 29, 2022, Paolo Bonzini wrote:
> This ensures that all the relevant code is compiled out, in fact
> the process_smi stub can be removed too.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/include/asm/kvm_host.h | 2 ++
> arch/x86/kvm/smm.h | 1 -
> arch/x86/kvm/x86.c | 6 ++++++
> 3 files changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index d11697504471..d58d4a62b227 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -81,7 +81,9 @@
> #define KVM_REQ_NMI KVM_ARCH_REQ(9)
> #define KVM_REQ_PMU KVM_ARCH_REQ(10)
> #define KVM_REQ_PMI KVM_ARCH_REQ(11)
> +#ifdef CONFIG_KVM_SMM
> #define KVM_REQ_SMI KVM_ARCH_REQ(12)
> +#endif
> #define KVM_REQ_MASTERCLOCK_UPDATE KVM_ARCH_REQ(13)
> #define KVM_REQ_MCLOCK_INPROGRESS \
> KVM_ARCH_REQ_FLAGS(14, KVM_REQUEST_WAIT | KVM_REQUEST_NO_WAKEUP)
> diff --git a/arch/x86/kvm/smm.h b/arch/x86/kvm/smm.h
> index 7ccce6b655ca..a6795b93ba30 100644
> --- a/arch/x86/kvm/smm.h
> +++ b/arch/x86/kvm/smm.h
> @@ -28,7 +28,6 @@ void process_smi(struct kvm_vcpu *vcpu);
> static inline int kvm_inject_smi(struct kvm_vcpu *vcpu) { return -ENOTTY; }
> static inline bool is_smm(struct kvm_vcpu *vcpu) { return false; }
> static inline void kvm_smm_changed(struct kvm_vcpu *vcpu, bool in_smm) { WARN_ON_ONCE(1); }
> -static inline void process_smi(struct kvm_vcpu *vcpu) { WARN_ON_ONCE(1); }
I think it's worth adding one more patch to kill off kvm_smm_changed() too. Most
of the affected code already has references to CONFIG_KVM_SMM nearby.
---
arch/x86/include/asm/kvm_host.h | 3 ++-
arch/x86/kvm/smm.c | 4 ++++
arch/x86/kvm/smm.h | 2 --
arch/x86/kvm/x86.c | 18 +++++++++---------
4 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 0b0a82c0bb5c..6c572cf1cf8d 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -1994,10 +1994,11 @@ enum {
#define HF_NMI_MASK (1 << 3)
#define HF_IRET_MASK (1 << 4)
#define HF_GUEST_MASK (1 << 5) /* VCPU is in guest-mode */
+
+#ifdef CONFIG_KVM_SMM
#define HF_SMM_MASK (1 << 6)
#define HF_SMM_INSIDE_NMI_MASK (1 << 7)
-#ifdef CONFIG_KVM_SMM
# define __KVM_VCPU_MULTIPLE_ADDRESS_SPACE
# define KVM_ADDRESS_SPACE_NUM 2
# define kvm_arch_vcpu_memslots_id(vcpu) ((vcpu)->arch.hflags & HF_SMM_MASK ? 1 : 0)
diff --git a/arch/x86/kvm/smm.c b/arch/x86/kvm/smm.c
index 740fca1cf3a3..12480446c43b 100644
--- a/arch/x86/kvm/smm.c
+++ b/arch/x86/kvm/smm.c
@@ -10,6 +10,10 @@
void kvm_smm_changed(struct kvm_vcpu *vcpu, bool entering_smm)
{
+ BUILD_BUG_ON(HF_GUEST_MASK != X86EMUL_GUEST_MASK);
+ BUILD_BUG_ON(HF_SMM_MASK != X86EMUL_SMM_MASK);
+ BUILD_BUG_ON(HF_SMM_INSIDE_NMI_MASK != X86EMUL_SMM_INSIDE_NMI_MASK);
+
trace_kvm_smm_transition(vcpu->vcpu_id, vcpu->arch.smbase, entering_smm);
if (entering_smm) {
diff --git a/arch/x86/kvm/smm.h b/arch/x86/kvm/smm.h
index 131fbe1817d5..9935045fcf20 100644
--- a/arch/x86/kvm/smm.h
+++ b/arch/x86/kvm/smm.h
@@ -29,8 +29,6 @@ void process_smi(struct kvm_vcpu *vcpu);
#else
static inline int kvm_inject_smi(struct kvm_vcpu *vcpu) { return -ENOTTY; }
static inline bool is_smm(struct kvm_vcpu *vcpu) { return false; }
-static inline void kvm_smm_changed(struct kvm_vcpu *vcpu, bool in_smm) { WARN_ON_ONCE(1); }
-
/*
* emulator_leave_smm is used as a function pointer, so the
* stub is defined in x86.c.
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 56004890a717..ec74d579ca1b 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5103,10 +5103,12 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
events->sipi_vector = 0; /* never valid when reporting to user space */
+#ifdef CONFIG_KVM_SMM
events->smi.smm = is_smm(vcpu);
events->smi.pending = vcpu->arch.smi_pending;
events->smi.smm_inside_nmi =
!!(vcpu->arch.hflags & HF_SMM_INSIDE_NMI_MASK);
+#endif
events->smi.latched_init = kvm_lapic_latched_init(vcpu);
events->flags = (KVM_VCPUEVENT_VALID_NMI_PENDING
@@ -5194,12 +5196,7 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
vcpu->arch.apic->sipi_vector = events->sipi_vector;
if (events->flags & KVM_VCPUEVENT_VALID_SMM) {
- if (!IS_ENABLED(CONFIG_KVM_SMM) &&
- (events->smi.smm ||
- events->smi.pending ||
- events->smi.smm_inside_nmi))
- return -EINVAL;
-
+#ifdef CONFIG_KVM_SMM
if (!!(vcpu->arch.hflags & HF_SMM_MASK) != events->smi.smm) {
kvm_x86_ops.nested_ops->leave_nested(vcpu);
kvm_smm_changed(vcpu, events->smi.smm);
@@ -5214,6 +5211,12 @@ static int kvm_vcpu_ioctl_x86_set_vcpu_events(struct kvm_vcpu *vcpu,
vcpu->arch.hflags &= ~HF_SMM_INSIDE_NMI_MASK;
}
+#else
+ if (events->smi.smm || events->smi.pending ||
+ events->smi.smm_inside_nmi)
+ return -EINVAL;
+#endif
+
if (lapic_in_kernel(vcpu)) {
if (events->smi.latched_init)
set_bit(KVM_APIC_INIT, &vcpu->arch.apic->pending_events);
@@ -8228,9 +8231,6 @@ static void init_emulate_ctxt(struct kvm_vcpu *vcpu)
(cs_l && is_long_mode(vcpu)) ? X86EMUL_MODE_PROT64 :
cs_db ? X86EMUL_MODE_PROT32 :
X86EMUL_MODE_PROT16;
- BUILD_BUG_ON(HF_GUEST_MASK != X86EMUL_GUEST_MASK);
- BUILD_BUG_ON(HF_SMM_MASK != X86EMUL_SMM_MASK);
- BUILD_BUG_ON(HF_SMM_INSIDE_NMI_MASK != X86EMUL_SMM_INSIDE_NMI_MASK);
ctxt->interruptibility = 0;
ctxt->have_exception = false;
base-commit: f7641bcac507589d34b20d30cceb7067f8bcfd08
--
next prev parent reply other threads:[~2022-10-14 21:06 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-29 17:20 [PATCH v2 0/8] KVM: x86: allow compiling out SMM support Paolo Bonzini
2022-09-29 17:20 ` [PATCH v2 1/8] KVM: x86: start moving SMM-related functions to new files Paolo Bonzini
2022-10-14 19:38 ` Sean Christopherson
2022-10-24 12:31 ` Maxim Levitsky
2022-09-29 17:20 ` [PATCH v2 2/8] KVM: x86: move SMM entry to a new file Paolo Bonzini
2022-10-24 12:32 ` Maxim Levitsky
2022-09-29 17:20 ` [PATCH v2 3/8] KVM: x86: move SMM exit " Paolo Bonzini
2022-10-24 12:32 ` Maxim Levitsky
2022-09-29 17:20 ` [PATCH v2 4/8] KVM: x86: do not go through ctxt->ops when emulating rsm Paolo Bonzini
2022-10-01 13:10 ` kernel test robot
2022-10-01 13:41 ` kernel test robot
2022-10-02 2:42 ` kernel test robot
2022-10-14 21:04 ` Sean Christopherson
2022-10-24 12:32 ` Maxim Levitsky
2022-09-29 17:20 ` [PATCH v2 5/8] KVM: allow compiling out SMM support Paolo Bonzini
2022-10-24 12:32 ` Maxim Levitsky
2022-09-29 17:20 ` [PATCH v2 6/8] KVM: x86: compile out vendor-specific code if SMM is disabled Paolo Bonzini
2022-10-24 12:32 ` Maxim Levitsky
2022-09-29 17:20 ` [PATCH v2 7/8] KVM: x86: remove SMRAM address space if SMM is not supported Paolo Bonzini
2022-10-24 12:33 ` Maxim Levitsky
2022-09-29 17:20 ` [PATCH v2 8/8] KVM: x86: do not define KVM_REQ_SMI if SMM disabled Paolo Bonzini
2022-10-14 21:06 ` Sean Christopherson [this message]
2022-10-24 12:33 ` Maxim Levitsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y0nPXfVT1pUaGppn@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maciej.szmigiero@oracle.com \
--cc=pbonzini@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.