From: Melody Wang <huibo.wang@amd.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <bonzini@redhat.com>
Cc: LKML <linux-kernel@vger.kernel.org>, <kvm@vger.kernel.org>,
Joerg Roedel <joro@8bytes.org>, <x86@kernel.org>,
Melody Wang <huibo.wang@amd.com>,
"Thomas Lendacky" <thomas.lendacky@amd.com>
Subject: [RFC PATCH v5 7/8] KVM: SVM: Add support for the SEV-SNP #HV IPI NAE event
Date: Mon, 9 Nov 2026 03:18:39 +0000 [thread overview]
Message-ID: <84d844c08a9f09a2ea1a44df7d36fe0b21324a69.1794171754.git.huibo.wang@amd.com> (raw)
In-Reply-To: <cover.1794171754.git.huibo.wang@amd.com>
The #HV IPI NAE event allows the guest to send an IPI to other vCPUs in
the guest when Restricted Injection is enabled. Implement the NAE event
as per GHCB specification.
Co-developed-by: Thomas Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Thomas Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Melody Wang <huibo.wang@amd.com>
---
arch/x86/include/uapi/asm/svm.h | 1 +
arch/x86/kvm/lapic.c | 12 ++++++++++++
arch/x86/kvm/lapic.h | 2 ++
arch/x86/kvm/svm/sev.c | 21 +++++++++++++++++++++
4 files changed, 36 insertions(+)
diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h
index d84a13ac4627..1c0165e9db16 100644
--- a/arch/x86/include/uapi/asm/svm.h
+++ b/arch/x86/include/uapi/asm/svm.h
@@ -122,6 +122,7 @@
#define SVM_VMGEXIT_HVDB_SET 1
#define SVM_VMGEXIT_HVDB_QUERY 2
#define SVM_VMGEXIT_HVDB_CLEAR 3
+#define SVM_VMGEXIT_HV_IPI 0x80000015ull
#define SVM_VMGEXIT_SNP_RUN_VMPL 0x80000018ull
#define SVM_VMGEXIT_SAVIC 0x8000001aull
#define SVM_VMGEXIT_SAVIC_REGISTER_GPA 0
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
index 037a4599d6f1..3a83bdd13b5a 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -3673,3 +3673,15 @@ void kvm_lapic_exit(void)
static_key_deferred_flush(&apic_sw_disabled);
WARN_ON(static_branch_unlikely(&apic_sw_disabled.key));
}
+
+int kvm_xapic_x2apic_send_ipi(struct kvm_vcpu *vcpu, u64 data)
+{
+ struct kvm_lapic *apic = vcpu->arch.apic;
+
+ if (!kvm_lapic_enabled(vcpu))
+ return 1;
+
+ kvm_apic_send_ipi(apic, (u32)data, (u32)(data >> 32));
+ return 0;
+}
+EXPORT_SYMBOL_FOR_KVM_INTERNAL(kvm_xapic_x2apic_send_ipi);
diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h
index 8530a6333bdd..e5e6730bfcca 100644
--- a/arch/x86/kvm/lapic.h
+++ b/arch/x86/kvm/lapic.h
@@ -194,6 +194,8 @@ int kvm_hv_vapic_msr_read(struct kvm_vcpu *vcpu, u32 msr, u64 *data);
int kvm_lapic_set_pv_eoi(struct kvm_vcpu *vcpu, u64 data, unsigned long len);
void kvm_lapic_exit(void);
+int kvm_xapic_x2apic_send_ipi(struct kvm_vcpu *vcpu, u64 data);
+
u64 kvm_x2apic_disable_read_intercept_reg_mask(struct kvm_vcpu *vcpu);
static inline void kvm_lapic_set_irr(int vec, struct kvm_lapic *apic)
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 9aafa6167ae6..b7c2993f8c63 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -4414,6 +4414,22 @@ static int sev_snp_hv_doorbell_page(struct vcpu_svm *svm)
return 0;
}
+static int sev_snp_hv_ipi(struct vcpu_svm *svm)
+{
+ struct kvm_vcpu *vcpu = &svm->vcpu;
+ u64 icr_info;
+
+ if (!is_sev_snp_guest(vcpu))
+ return -EINVAL;
+
+ icr_info = svm->vmcb->control.exit_info_1;
+
+ if (kvm_xapic_x2apic_send_ipi(vcpu, icr_info))
+ return -EINVAL;
+
+ return 0;
+}
+
static int sev_handle_vmgexit_msr_protocol(struct vcpu_svm *svm)
{
struct vmcb_control_area *control = &svm->vmcb->control;
@@ -4566,6 +4582,7 @@ static bool is_snp_only_vmgexit(u64 exit_code)
case SVM_VMGEXIT_EXT_GUEST_REQUEST:
case SVM_VMGEXIT_PSC:
case SVM_VMGEXIT_HVDB_PAGE:
+ case SVM_VMGEXIT_HV_IPI:
return true;
default:
return false;
@@ -4754,6 +4771,10 @@ int sev_handle_vmgexit(struct kvm_vcpu *vcpu)
svm_vmgexit_bad_input(svm, GHCB_ERR_INVALID_INPUT);
return 1;
+ case SVM_VMGEXIT_HV_IPI:
+ if (sev_snp_hv_ipi(svm))
+ svm_vmgexit_bad_input(svm, GHCB_ERR_INVALID_INPUT);
+ return 1;
case SVM_VMGEXIT_UNSUPPORTED_EVENT:
/*
* Note, the _guest_ is reporting an unsupported #VC, i.e. this
--
2.43.0
next prev parent reply other threads:[~2026-11-09 3:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 3:18 [RFC PATCH v5 0/8] Add SEV-SNP restricted injection hypervisor support Melody Wang
2026-11-09 3:18 ` [RFC PATCH v5 1/8] x86/sev: Define the #HV doorbell page structure Melody Wang
2026-11-09 3:18 ` [RFC PATCH v5 2/8] KVM: SVM: Add support for the SEV-SNP #HV doorbell page NAE event Melody Wang
2026-11-09 3:18 ` [RFC PATCH v5 3/8] KVM: SVM: Inject #HV when Restricted Injection is active Melody Wang
2026-11-09 3:18 ` [RFC PATCH v5 4/8] KVM: SVM: Inject NMIs " Melody Wang
2026-11-09 3:18 ` [RFC PATCH v5 5/8] KVM: SVM: Inject MCEs " Melody Wang
2026-11-09 3:18 ` Melody Wang [this message]
2026-11-09 3:18 ` [RFC PATCH v5 8/8] KVM: SVM: Enable Restricted Injection for an SEV-SNP guest Melody Wang
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=84d844c08a9f09a2ea1a44df7d36fe0b21324a69.1794171754.git.huibo.wang@amd.com \
--to=huibo.wang@amd.com \
--cc=bonzini@redhat.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=seanjc@google.com \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®