mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Melody Wang <huibo.wang@amd.com>
Cc: x86@kernel.org, LKML <linux-kernel@vger.kernel.org>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	Stefano Garzarella <sgarzare@redhat.com>,
	James Bottomley <James.Bottomley@hansenpartnership.com>,
	Claudio Carvalho <cclaudio@linux.ibm.com>
Subject: Re: [PATCH v1 1/8] x86/sev: Make SVSM calls preemption-safe
Date: Mon, 31 Aug 2026 18:19:34 -0700	[thread overview]
Message-ID: <20260901011934.GGapYoJvmhws1D7iAL@fat_crate.local> (raw)
In-Reply-To: <8e6e89b87e34a8eb2a20d52b0d92c26e7a61ac42.1787973545.git.huibo.wang@amd.com>

+ folks who added the vtpm stuff.

On Sat, Aug 29, 2026 at 03:39:39AM +0000, Melody Wang wrote:
> Two functions in the the SVSM vTPM guest implementation do not disable
> preemption when fetching CAA.

"	... when fetching the SVSM Calling Area Address (CAA).

The SVSM CAA..."

This way, you introduce what CAA means and then use the abbreviation.

> The SVSM calling area is a per-CPU structure. When a thread is preempted
> and migrated to a different CPU after fetching the per-CPU Calling Area
> Address (CAA), the SVSM call will execute on the new CPU with the

and here you can use "CAA" directly because you've explained it above.

> original CPU's CAA. Which is wrong.
> 
> Move the CAA fetching operation inside svsm_perform_call_protocol()
> which disables interrupts around the SVSM call and thus runs
> preemption-safe.
> 
> Signed-off-by: Melody Wang <huibo.wang@amd.com>

Should this be CC:stable so that it gets backported?

I think we want to do that and mark it with

Fixes: 770de678bc28 ("x86/sev: Add SVSM vTPM probe/send_command functions")

> ---
>  arch/x86/coco/sev/svsm.c | 11 +++++++++--
>  1 file changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/x86/coco/sev/svsm.c b/arch/x86/coco/sev/svsm.c
> index 916d62cd17dc..92ea93f506c0 100644
> --- a/arch/x86/coco/sev/svsm.c
> +++ b/arch/x86/coco/sev/svsm.c
> @@ -74,6 +74,15 @@ int svsm_perform_call_protocol(struct svsm_call *call)
>  
>  	flags = native_local_irq_save();
>  
> +	/*
> +	 * 'caa' is a per-CPU variable. To avoid using a stale or incorrect
> +	 * 'caa' if the task is preempted or migrates to another CPU after it

"... or migrated to another CPU after the CAA has been fetched..."

> +	 * is fetched, always fetch 'caa' and then issue the SVSM call with
> +	 * interrupts disabled. This ensures the correct 'caa' is used even
> +	 * under preemption or CPU migration.

s/even under preemption or CPU migration//

That's kinda clear.

Leaving in the rest for the newly CCed.

> +	 */
> +	call->caa = svsm_get_caa();
> +
>  	ghcb = __sev_get_ghcb(&state);
>  
>  	do {
> @@ -321,7 +330,6 @@ int snp_svsm_vtpm_send_command(u8 *buffer)
>  {
>  	struct svsm_call call = {};
>  
> -	call.caa = svsm_get_caa();
>  	call.rax = SVSM_VTPM_CALL(SVSM_VTPM_CMD);
>  	call.rcx = __pa(buffer);
>  
> @@ -345,7 +353,6 @@ bool snp_svsm_vtpm_probe(void)
>  	if (!snp_vmpl)
>  		return false;
>  
> -	call.caa = svsm_get_caa();
>  	call.rax = SVSM_VTPM_CALL(SVSM_VTPM_QUERY);
>  
>  	if (svsm_perform_call_protocol(&call))
> -- 
> 2.43.0
> 

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette

  reply	other threads:[~2026-09-01  1:19 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-29  3:39 [PATCH v1 0/8] Alternate Injection: Secure Interrupt Delivery for SEV-SNP Guests - Guest Support Melody Wang
2026-08-29  3:39 ` [PATCH v1 1/8] x86/sev: Make SVSM calls preemption-safe Melody Wang
2026-09-01  1:19   ` Borislav Petkov [this message]
2026-09-10  8:53     ` Stefano Garzarella
2026-08-29  3:39 ` [PATCH v1 2/8] x86/sev: Add support for Alternate Injection Melody Wang
2026-09-03  0:44   ` Borislav Petkov
2026-08-29  3:39 ` [PATCH v1 3/8] x86/apic: Add an SVSM APIC driver Melody Wang
2026-09-06  2:09   ` Borislav Petkov
2026-08-29  3:39 ` [PATCH v1 4/8] x86/sev: Route unsupported APIC register accesses to the hypervisor APIC emulation Melody Wang
2026-09-09  0:30   ` Borislav Petkov
2026-08-29  3:39 ` [PATCH v1 5/8] x86/sev: Add a function to contain all SEV-specific setup operations Melody Wang
2026-09-09 19:54   ` Borislav Petkov
2026-08-29  3:39 ` [PATCH v1 6/8] x86/sev: Register the guest with the SVSM APIC protocol Melody Wang
2026-09-10  1:34   ` Borislav Petkov
2026-08-29  3:39 ` [PATCH v1 7/8] x86/sev: Allow the guest to configure interrupt vectors for the hypervisor Melody Wang
2026-09-11  3:27   ` Borislav Petkov
2026-08-29  3:39 ` [PATCH v1 8/8] x86/sev: Indicate that Alternate Injection is supported in the 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=20260901011934.GGapYoJvmhws1D7iAL@fat_crate.local \
    --to=bp@alien8.de \
    --cc=James.Bottomley@hansenpartnership.com \
    --cc=cclaudio@linux.ibm.com \
    --cc=huibo.wang@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sgarzare@redhat.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®