Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: "Naveen N Rao (AMD)" <naveen@kernel.org>,
	Sean Christopherson <seanjc@google.com>,
	Borislav Petkov <bp@alien8.de>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>,
	Nikunj A Dadhania <nikunj@amd.com>,
	Neeraj Upadhyay <neeraj.upadhyay@amd.com>,
	Tianyu Lan <tiala@microsoft.com>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	Thomas Gleixner <tglx@kernel.org>
Subject: Re: [RFC PATCH v3 04/27] x86/apic: Use AVIC_INCOMPLETE_IPI VMGEXIT for Secure AVIC IPI handling
Date: Mon, 13 Jul 2026 12:59:50 -0500	[thread overview]
Message-ID: <29a8e63c-d317-4717-ace2-9471e9866eb2@amd.com> (raw)
In-Reply-To: <97a8081fb548567f004f31e2afb02bd06d7a9982.1783490022.git.naveen@kernel.org>

On 7/8/26 01:32, Naveen N Rao (AMD) wrote:
> x2apic_savic driver currently uses SVM_EXIT_MSR to have the hypervisor
> emulate ICR writes and to be able to deliver IPIs. However, the driver
> also sets APIC_IRR in the APIC backing page of the target vCPU, so the
> expectation is only for the hypervisor to notify/wake up the target
> vCPU.
> 
> This is incorrect since SVM_EXIT_MSR is for requesting full emulation of
> a certain MSR access -- and hypervisors expect to be able to _inject_
> (set APIC_IRR) *and* deliver the interrupt to the target. This can
> result in duplicate interrupts at the guest (assuming the guest is
> allowing that vector to be injected by the hypervisor).
> 
> Instead, have the driver do AVIC_INCOMPLETE_IPI exit so that it is clear
> on what the hypervisor needs to do. This is the same exit used by SVM
> AVIC when it has already set APIC_IRR in the target vCPU APIC backing
> page to request the hypervisor to send an AVIC doorbell/wake up the
> target vCPU. Add the newly added exit ID AVIC_IPI_FAILURE_UNACCELERATED
> (ID number 5) and use the same to signal that this is a Secure AVIC
> access that is not accelerated by hardware.

Except that the GHCB specification doesn't have this support, so you can't
really do this. And if you want it to be part of the GHCB spec it will
need to be a new feature bit at this point so that the guest knows that
the hypervisor can support this new exit code.

With the current guest code, can't the hypervisor support know that for
Secure AVIC it only needs to schedule the vCPU since it is assumed the
guest updated the target backing page?

Thanks,
Tom

> 
> Fixes: 2c6978ea1a85 ("x86/apic: Add support to send IPI for Secure AVIC")
> Signed-off-by: Naveen N Rao (AMD) <naveen@kernel.org>
> ---
>  arch/x86/include/asm/svm.h |  1 +
>  arch/x86/coco/sev/core.c   | 18 +++++++++++++++++-
>  2 files changed, 18 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h
> index aa63431ba92c..42ececa8963d 100644
> --- a/arch/x86/include/asm/svm.h
> +++ b/arch/x86/include/asm/svm.h
> @@ -284,6 +284,7 @@ enum avic_ipi_failure_cause {
>  	AVIC_IPI_FAILURE_INVALID_TARGET,
>  	AVIC_IPI_FAILURE_INVALID_BACKING_PAGE,
>  	AVIC_IPI_FAILURE_INVALID_IPI_VECTOR,
> +	AVIC_IPI_FAILURE_UNACCELERATED,
>  };
>  
>  #define AVIC_PHYSICAL_MAX_INDEX_MASK	GENMASK_ULL(11, 0)
> diff --git a/arch/x86/coco/sev/core.c b/arch/x86/coco/sev/core.c
> index 7ed3da998489..69c75ea543a3 100644
> --- a/arch/x86/coco/sev/core.c
> +++ b/arch/x86/coco/sev/core.c
> @@ -1014,13 +1014,29 @@ void savic_ghcb_msr_write(u32 reg, u64 value)
>  	struct ghcb_state state;
>  	enum es_result res;
>  	struct ghcb *ghcb;
> +	u64 exit_info_2;
>  
>  	guard(irqsave)();
>  
>  	ghcb = __sev_get_ghcb(&state);
>  	vc_ghcb_invalidate(ghcb);
>  
> -	res = __vc_handle_msr(ghcb, &ctxt, true);
> +	if (reg == APIC_ICR) {
> +		/*
> +		 * Exit with AVIC_INCOMPLETE_IPI to request hypervisor to notify
> +		 * the target vCPU(s). exit_info_1 is just the ICR value.
> +		 * exit_info_2 encodes exit id in the upper 32-bits, and icrh
> +		 * (IPI dest, since Secure AVIC is x2APIC-only) in the lower 32-bits.
> +		 */
> +		exit_info_2 = (u64)(AVIC_IPI_FAILURE_UNACCELERATED) << 32;
> +		exit_info_2 |= upper_32_bits(value);
> +
> +		res = sev_es_ghcb_hv_call(ghcb, &ctxt, SVM_EXIT_AVIC_INCOMPLETE_IPI,
> +					  value, exit_info_2);
> +	} else {
> +		res = __vc_handle_msr(ghcb, &ctxt, true);
> +	}
> +
>  	if (res != ES_OK) {
>  		pr_err("Secure AVIC MSR (0x%llx) write returned error (%d)\n", msr, res);
>  		/* MSR writes should never fail. Any failure is fatal error for SNP guest */


  reply	other threads:[~2026-07-13 17:59 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  6:31 [RFC PATCH v3 00/27] KVM: SVM: Add support for SEV-SNP Secure AVIC Naveen N Rao (AMD)
2026-07-08  6:31 ` [RFC PATCH v3 01/27] x86/apic: Propagate APIC_SPIV writes to hv for " Naveen N Rao (AMD)
2026-07-10  2:03   ` Borislav Petkov
2026-07-10 15:02     ` Naveen N Rao
2026-07-11  4:37       ` Borislav Petkov
2026-07-13 17:38       ` Tom Lendacky
2026-07-14  8:57         ` Naveen N Rao
2026-07-08  6:32 ` [RFC PATCH v3 02/27] x86/apic: Drop savic_eoi() in favor of native_apic_msr_eoi() " Naveen N Rao (AMD)
2026-07-13 17:43   ` Tom Lendacky
2026-07-14  9:02     ` Naveen N Rao
2026-07-08  6:32 ` [RFC PATCH v3 03/27] x86/kvm: Disable PV_SEND_IPI if Secure AVIC is enabled Naveen N Rao (AMD)
2026-07-13 17:52   ` Tom Lendacky
2026-07-14  9:42     ` Naveen N Rao
2026-07-08  6:32 ` [RFC PATCH v3 04/27] x86/apic: Use AVIC_INCOMPLETE_IPI VMGEXIT for Secure AVIC IPI handling Naveen N Rao (AMD)
2026-07-13 17:59   ` Tom Lendacky [this message]
2026-07-14 10:03     ` Naveen N Rao
2026-07-08  6:32 ` [RFC PATCH v3 05/27] x86/cpufeatures: Add Secure AVIC CPU feature Naveen N Rao (AMD)
2026-07-13 18:32   ` Tom Lendacky
2026-07-08  6:32 ` [RFC PATCH v3 06/27] KVM: SVM: Add helper to check if Secure AVIC is enabled for a guest Naveen N Rao (AMD)
2026-07-13 18:35   ` Tom Lendacky
2026-07-08  6:32 ` [RFC PATCH v3 07/27] KVM: SVM: Set guest_apic_protected if Secure AVIC is enabled Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 08/27] kvm: irqfd: Have kvm_arch_has_irq_bypass() take struct kvm pointer Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 09/27] KVM: SVM: Disable IRQ bypass for Secure AVIC Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 10/27] KVM: SVM: Add avic_ipiv_is_soft_disabled() as a wrapper around enable_ipiv Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 11/27] KVM: SVM: Disable IPIv for Secure AVIC Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 12/27] KVM: SVM: Short-circuit a few AVIC flows " Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 13/27] KVM: SVM: Warn if we ever receive AVIC_UNACCELERATED_ACCESS #VMEXIT Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 14/27] KVM: SVM: Do not inhibit AVIC for SEV-SNP guests if Secure AVIC is enabled Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 15/27] KVM: SVM: Set VGIF in VMSA area for Secure AVIC guests Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 16/27] KVM: SVM: Add handler for VMGEXIT Secure AVIC NAE event Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 17/27] KVM: SVM: Do not intercept SECURE_AVIC_CONTROL MSR for Secure AVIC guests Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 18/27] KVM: x86: Add a new kvm_x86_op protected_apic_has_injectable_intr() Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 19/27] KVM: SVM: Implement kvm_x86_ops->protected_apic_has_injectable_intr() for Secure AVIC Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 20/27] KVM: SVM: Implement kvm_x86_ops->protected_apic_has_interrupt() " Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 21/27] KVM: SVM: Add interrupt delivery support for Secure AVIC guests Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 22/27] KVM: SVM: Add support for incomplete IPI handling for Secure AVIC Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 23/27] KVM: SVM: Add support for injecting NMIs for Secure AVIC guests Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 24/27] KVM: SVM: Mandate use of split irqchip for Secure AVIC Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 25/27] KVM: SVM: Do not inject exceptions " Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 26/27] KVM: SVM: Do not intercept exceptions for Secure AVIC guests Naveen N Rao (AMD)
2026-07-08  6:32 ` [RFC PATCH v3 27/27] KVM: SVM: Advertise Secure AVIC support for SEV-SNP guests Naveen N Rao (AMD)
2026-07-08  9:20 ` [RFC PATCH v3 00/27] KVM: SVM: Add support for SEV-SNP Secure AVIC Naveen N Rao

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=29a8e63c-d317-4717-ace2-9471e9866eb2@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=naveen@kernel.org \
    --cc=neeraj.upadhyay@amd.com \
    --cc=nikunj@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=tglx@kernel.org \
    --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