From: Tom Lendacky <thomas.lendacky@amd.com>
To: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>,
kvm@vger.kernel.org, seanjc@google.com, pbonzini@redhat.com
Cc: linux-kernel@vger.kernel.org, nikunj@amd.com,
Santosh.Shukla@amd.com, Vasant.Hegde@amd.com,
Suravee.Suthikulpanit@amd.com, bp@alien8.de,
David.Kaplan@amd.com, huibo.wang@amd.com, naveen.rao@amd.com,
tiala@microsoft.com
Subject: Re: [RFC PATCH v2 11/17] KVM: SVM: Enable NMI support for Secure AVIC guests
Date: Tue, 23 Sep 2025 10:25:54 -0500 [thread overview]
Message-ID: <37ce869b-b74a-5000-60b5-643a60443750@amd.com> (raw)
In-Reply-To: <20250923050317.205482-12-Neeraj.Upadhyay@amd.com>
On 9/23/25 00:03, Neeraj Upadhyay wrote:
> The Secure AVIC hardware introduces a new model for handling Non-Maskable
> Interrupts (NMIs). This model differs significantly from standard SVM, as
> guest NMI state is managed by the hardware and is not visible to KVM.
>
> Consequently, KVM can no longer use the generic EVENT_INJ mechanism and
> must not track NMI masking state in software. Instead, it must adopt the
> vNMI (Virtual NMI) flow, which is the only mechanism supported by
> Secure AVIC.
>
> Enable NMI support by making three key changes:
>
> 1. Enable NMI in VMSA: Set the V_NMI_ENABLE_MASK bit in the VMSA's
> vintr_ctr field. This is a hardware prerequisite to enable the
> vNMI feature for the guest.
>
> 2. Use vNMI for Injection: Modify svm_inject_nmi() to use the vNMI
> flow for Secure AVIC guests. When an NMI is requested, set the
> V_NMI_PENDING_MASK in the VMCB instead of using EVENT_INJ.
>
> 3. Update NMI Windowing: Modify svm_nmi_allowed() to reflect that
> hardware now manages NMI blocking. KVM's only responsibility is to
> avoid queuing a new vNMI if one is already pending. The check is
> now simplified to whether V_NMI_PENDING_MASK is already set.
>
> Co-developed-by: Kishon Vijay Abraham I <kvijayab@amd.com>
> Signed-off-by: Kishon Vijay Abraham I <kvijayab@amd.com>
> Signed-off-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
> ---
> arch/x86/kvm/svm/sev.c | 2 +-
> arch/x86/kvm/svm/svm.c | 56 ++++++++++++++++++++++++++----------------
> 2 files changed, 36 insertions(+), 22 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 2dee210efb37..7c66aefe428a 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -885,7 +885,7 @@ static int sev_es_sync_vmsa(struct vcpu_svm *svm)
> save->sev_features = sev->vmsa_features;
>
> if (sev_savic_active(vcpu->kvm))
> - save->vintr_ctrl |= V_GIF_MASK;
> + save->vintr_ctrl |= V_GIF_MASK | V_NMI_ENABLE_MASK;
>
> /*
> * Skip FPU and AVX setup with KVM_SEV_ES_INIT to avoid
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index fdd612c975ae..a945bc094c1a 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -3635,27 +3635,6 @@ static int pre_svm_run(struct kvm_vcpu *vcpu)
> return 0;
> }
>
> -static void svm_inject_nmi(struct kvm_vcpu *vcpu)
> -{
> - struct vcpu_svm *svm = to_svm(vcpu);
> -
> - svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI;
> -
> - if (svm->nmi_l1_to_l2)
> - return;
> -
> - /*
> - * No need to manually track NMI masking when vNMI is enabled, hardware
> - * automatically sets V_NMI_BLOCKING_MASK as appropriate, including the
> - * case where software directly injects an NMI.
> - */
> - if (!is_vnmi_enabled(svm)) {
> - svm->nmi_masked = true;
> - svm_set_iret_intercept(svm);
> - }
> - ++vcpu->stat.nmi_injections;
> -}
A pre-patch that moves this function would make the changes you make to
it in this patch more obvious.
Thanks,
Tom
> -
> static bool svm_is_vnmi_pending(struct kvm_vcpu *vcpu)
> {
> struct vcpu_svm *svm = to_svm(vcpu);
> @@ -3689,6 +3668,33 @@ static bool svm_set_vnmi_pending(struct kvm_vcpu *vcpu)
> return true;
> }
>
> +static void svm_inject_nmi(struct kvm_vcpu *vcpu)
> +{
> + struct vcpu_svm *svm = to_svm(vcpu);
> +
> + if (sev_savic_active(vcpu->kvm)) {
> + svm_set_vnmi_pending(vcpu);
> + ++vcpu->stat.nmi_injections;
> + return;
> + }
> +
> + svm->vmcb->control.event_inj = SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_NMI;
> +
> + if (svm->nmi_l1_to_l2)
> + return;
> +
> + /*
> + * No need to manually track NMI masking when vNMI is enabled, hardware
> + * automatically sets V_NMI_BLOCKING_MASK as appropriate, including the
> + * case where software directly injects an NMI.
> + */
> + if (!is_vnmi_enabled(svm)) {
> + svm->nmi_masked = true;
> + svm_set_iret_intercept(svm);
> + }
> + ++vcpu->stat.nmi_injections;
> +}
> +
> static void svm_inject_irq(struct kvm_vcpu *vcpu, bool reinjected)
> {
> struct vcpu_svm *svm = to_svm(vcpu);
> @@ -3836,6 +3842,14 @@ bool svm_nmi_blocked(struct kvm_vcpu *vcpu)
> static int svm_nmi_allowed(struct kvm_vcpu *vcpu, bool for_injection)
> {
> struct vcpu_svm *svm = to_svm(vcpu);
> +
> + /* Secure AVIC only support V_NMI based NMI injection. */
> + if (sev_savic_active(vcpu->kvm)) {
> + if (svm->vmcb->control.int_ctl & V_NMI_PENDING_MASK)
> + return 0;
> + return 1;
> + }
> +
> if (svm->nested.nested_run_pending)
> return -EBUSY;
>
next prev parent reply other threads:[~2025-09-23 15:26 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-23 5:03 [RFC PATCH v2 00/17] AMD: Add Secure AVIC KVM Support Neeraj Upadhyay
2025-09-23 5:03 ` [RFC PATCH v2 01/17] KVM: x86/lapic: Differentiate protected APIC interrupt mechanisms Neeraj Upadhyay
2025-09-23 5:03 ` [RFC PATCH v2 02/17] x86/cpufeatures: Add Secure AVIC CPU feature Neeraj Upadhyay
2025-09-23 5:03 ` [RFC PATCH v2 03/17] KVM: SVM: Add support for Secure AVIC capability in KVM Neeraj Upadhyay
2025-09-23 5:03 ` [RFC PATCH v2 04/17] KVM: SVM: Set guest APIC protection flags for Secure AVIC Neeraj Upadhyay
2025-09-23 5:03 ` [RFC PATCH v2 05/17] KVM: SVM: Do not intercept SECURE_AVIC_CONTROL MSR for SAVIC guests Neeraj Upadhyay
2025-09-23 13:55 ` Tom Lendacky
2025-09-25 5:16 ` Upadhyay, Neeraj
2025-09-25 13:54 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 06/17] KVM: SVM: Implement interrupt injection for Secure AVIC Neeraj Upadhyay
2025-09-23 14:47 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 07/17] KVM: SVM: Add IPI Delivery Support " Neeraj Upadhyay
2025-09-23 5:03 ` [RFC PATCH v2 08/17] KVM: SVM: Do not inject exception " Neeraj Upadhyay
2025-09-23 15:00 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 09/17] KVM: SVM: Do not intercept exceptions for Secure AVIC guests Neeraj Upadhyay
2025-09-23 15:15 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 10/17] KVM: SVM: Set VGIF in VMSA area " Neeraj Upadhyay
2025-09-23 15:16 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 11/17] KVM: SVM: Enable NMI support " Neeraj Upadhyay
2025-09-23 15:25 ` Tom Lendacky [this message]
2025-09-23 5:03 ` [RFC PATCH v2 12/17] KVM: SVM: Add VMGEXIT handler for Secure AVIC backing page Neeraj Upadhyay
2025-09-23 16:02 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 13/17] KVM: SVM: Add IOAPIC EOI support for Secure AVIC guests Neeraj Upadhyay
2025-09-23 16:15 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 14/17] KVM: x86/ioapic: Disable RTC EOI tracking for protected APIC guests Neeraj Upadhyay
2025-09-23 16:23 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 15/17] KVM: SVM: Check injected timers for Secure AVIC guests Neeraj Upadhyay
2025-09-23 16:32 ` Tom Lendacky
2025-09-23 5:03 ` [RFC PATCH v2 16/17] KVM: x86/cpuid: Disable paravirt APIC features for protected APIC Neeraj Upadhyay
2025-09-23 5:03 ` [RFC PATCH v2 17/17] KVM: SVM: Advertise Secure AVIC support for SNP guests Neeraj Upadhyay
2025-09-23 10:02 ` [syzbot ci] Re: AMD: Add Secure AVIC KVM Support syzbot ci
2025-09-23 10:17 ` Upadhyay, Neeraj
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=37ce869b-b74a-5000-60b5-643a60443750@amd.com \
--to=thomas.lendacky@amd.com \
--cc=David.Kaplan@amd.com \
--cc=Neeraj.Upadhyay@amd.com \
--cc=Santosh.Shukla@amd.com \
--cc=Suravee.Suthikulpanit@amd.com \
--cc=Vasant.Hegde@amd.com \
--cc=bp@alien8.de \
--cc=huibo.wang@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=naveen.rao@amd.com \
--cc=nikunj@amd.com \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
--cc=tiala@microsoft.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox