From: Tom Lendacky <thomas.lendacky@amd.com>
To: Melody Wang <huibo.wang@amd.com>,
Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Joerg Rodel <joro@8bytes.org>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v4 5/7] KVM: SVM: Inject MCEs when Restricted Injection is active
Date: Tue, 28 Apr 2026 14:24:44 -0500 [thread overview]
Message-ID: <c1e1f24e-3407-444d-b17a-9c543d8d3edd@amd.com> (raw)
In-Reply-To: <51f8c478c5fc09b3bdeb8329c682a01fbe0ea5db.1777048608.git.huibo.wang@amd.com>
On 4/24/26 12:42, Melody Wang wrote:
> When Restricted Injection is active, only #HV exceptions can be injected
> into the SEV-SNP guest.
>
> Detect that, and then follow the #HV doorbell communication from the
> GHCB specification to inject the MCEs.
>
> 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/asm/kvm-x86-ops.h | 1 +
> arch/x86/include/asm/kvm_host.h | 1 +
> arch/x86/kvm/svm/sev.c | 16 ++++++++++++++--
> arch/x86/kvm/svm/svm.c | 17 +++++++++++++++++
> arch/x86/kvm/svm/svm.h | 2 ++
> arch/x86/kvm/vmx/main.c | 10 ++++++++++
> arch/x86/kvm/vmx/vmx.c | 5 +++++
> arch/x86/kvm/vmx/x86_ops.h | 1 +
> arch/x86/kvm/x86.c | 7 +++++++
> 9 files changed, 58 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> index 61e1e54deb07..2483357bdd97 100644
> --- a/arch/x86/kvm/svm/sev.c
> +++ b/arch/x86/kvm/svm/sev.c
> @@ -5371,6 +5371,8 @@ static void __sev_snp_inject(enum inject_type type, struct kvm_vcpu *vcpu)
>
> if (type == INJECT_NMI)
> hvdb->events.nmi = 1;
> + else if (type == INJECT_MCE)
> + hvdb->events.mce = 1;
> else
> hvdb->events.vector = vcpu->arch.interrupt.nr;
>
> @@ -5386,6 +5388,11 @@ bool sev_snp_queue_exception(struct kvm_vcpu *vcpu)
> if (!sev_snp_is_rinj_active(vcpu))
> return false;
>
> + if (vcpu->arch.exception.vector == MC_VECTOR) {
> + __sev_snp_inject(INJECT_MCE, vcpu);
> + return true;
> + }
> +
> /*
> * Restricted Injection is enabled, only #HV is supported.
> * If the vector is not HV_VECTOR, do not inject the exception,
> @@ -5454,7 +5461,7 @@ void sev_snp_cancel_injection(struct kvm_vcpu *vcpu)
>
> /*
> * KVM only injects a single event each time (prepare_hv_injection),
> - * so when events.nmi is true, the vector will be zero
> + * so when events.nmi is true, the MCE and vector will be zero.
This is confusing. I think you mean to say
so when events.nmi or events.mce is true, the vector will be zero.
correct?
Thanks,
Tom
> */
> if (hvdb->events.vector)
> svm->vmcb->control.event_inj |= hvdb->events.vector |
> @@ -5463,6 +5470,9 @@ void sev_snp_cancel_injection(struct kvm_vcpu *vcpu)
> if (hvdb->events.nmi)
> svm->vmcb->control.event_inj |= SVM_EVTINJ_TYPE_NMI;
>
> + if (hvdb->events.mce)
> + svm->vmcb->control.event_inj |= MC_VECTOR | SVM_EVTINJ_TYPE_EXEPT;
> +
> hvdb->events.pending_events = 0;
>
> out:
next prev parent reply other threads:[~2026-04-28 19:24 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-24 17:42 [PATCH v4 0/7] Add SEV-SNP restricted injection hypervisor support Melody Wang
2026-04-24 17:42 ` [PATCH v4 1/7] x86/sev: Define the #HV doorbell page structure Melody Wang
2026-04-24 17:42 ` [PATCH v4 2/7] KVM: SVM: Add support for the SEV-SNP #HV doorbell page NAE event Melody Wang
2026-04-24 17:42 ` [PATCH v4 3/7] KVM: SVM: Inject #HV when Restricted Injection is active Melody Wang
2026-04-28 11:12 ` Joerg Rodel
2026-04-28 17:58 ` Melody Wang
2026-04-28 19:17 ` Tom Lendacky
2026-04-24 17:42 ` [PATCH v4 4/7] KVM: SVM: Inject NMIs " Melody Wang
2026-04-24 17:42 ` [PATCH v4 5/7] KVM: SVM: Inject MCEs " Melody Wang
2026-04-28 10:50 ` Joerg Rodel
2026-04-28 18:19 ` Melody Wang
2026-04-28 19:24 ` Tom Lendacky [this message]
2026-04-28 23:00 ` Melody Wang
2026-04-24 17:50 ` [PATCH 6/7] KVM: SVM: Add support for the SEV-SNP #HV IPI NAE event Melody Wang
2026-04-24 17:51 ` [PATCH v4 7/7] KVM: SVM: Enable Restricted Injection for an SEV-SNP guest Melody Wang
2026-04-28 10:52 ` Joerg Rodel
2026-04-28 18:25 ` 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=c1e1f24e-3407-444d-b17a-9c543d8d3edd@amd.com \
--to=thomas.lendacky@amd.com \
--cc=huibo.wang@amd.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.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