The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Tom Lendacky <thomas.lendacky@amd.com>
To: Ashish Kalra <Ashish.Kalra@amd.com>,
	tglx@linutronix.de, mingo@redhat.com,
	dave.hansen@linux.intel.com, x86@kernel.org, bp@alien8.de,
	hpa@zytor.com
Cc: kees@kernel.org, michael.roth@amd.com, nikunj@amd.com,
	seanjc@google.com, ardb@kernel.org, gustavoars@kernel.org,
	sgarzare@redhat.com, linux-kernel@vger.kernel.org,
	linux-hardening@vger.kernel.org, kexec@lists.infradead.org,
	linux-coco@lists.linux.dev
Subject: Re: [PATCH] x86/sev: Fix SNP guest kdump hang/softlockup/panic
Date: Tue, 22 Apr 2025 09:53:44 -0500	[thread overview]
Message-ID: <787ce95c-2d7c-b005-6b6b-c379f0a9f603@amd.com> (raw)
In-Reply-To: <20250421204453.318557-1-Ashish.Kalra@amd.com>

On 4/21/25 15:44, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
> 

No need to add to what Boris already said on the commit message and
comments, so just looking at the code.

> +
> +		/*
> +		 * Issue AP destroy on all APs (to ensure they are kicked out
> +		 * of guest mode) to allow using RMPADJUST to remove the VMSA
> +		 * tag on VMSA pages especially for guests that allow HLT to
> +		 * not be intercepted.
> +		 */
> +
> +		local_irq_save(flags);
> +
> +		ghcb = __sev_get_ghcb(&state);
> +
> +		vc_ghcb_invalidate(ghcb);
> +		ghcb_set_rax(ghcb, vmsa->sev_features);
> +
> +		/* Issue VMGEXIT AP Destroy NAE event */
> +
> +		ghcb_set_sw_exit_code(ghcb, SVM_VMGEXIT_AP_CREATION);
> +		ghcb_set_sw_exit_info_1(ghcb,
> +					((u64)apic_id << 32)	|
> +					((u64)snp_vmpl << 16)	|
> +					SVM_VMGEXIT_AP_DESTROY);
> +		ghcb_set_sw_exit_info_2(ghcb, __pa(vmsa));
> +
> +		sev_es_wr_ghcb_msr(__pa(ghcb));
> +		VMGEXIT();
> +
> +		if (!ghcb_sw_exit_info_1_is_valid(ghcb) ||
> +		    lower_32_bits(ghcb->save.sw_exit_info_1)) {
> +			pr_err("SNP AP Destroy error\n");
> +			local_irq_restore(flags);
> +			return;
> +		}
> +
> +		__sev_put_ghcb(&state);
> +
> +		local_irq_restore(flags);

It looks like this whole block above is very similar to the block in
wakeup_cpu_via_vmgexit(). It makes sense to create a single function
that takes either SVM_VMGEXIT_AP_CREATE or SVM_VMGEXIT_AP_DESTROY as an
argument and processes appropriately.

> +
> +		snp_cleanup_vmsa(vmsa, apic_id);
> +	}
> +}
> +
>  void snp_kexec_finish(void)
>  {
>  	struct sev_es_runtime_data *data;
> @@ -987,6 +1088,8 @@ void snp_kexec_finish(void)
>  	if (!IS_ENABLED(CONFIG_KEXEC_CORE))
>  		return;
>  
> +	sev_snp_shutdown_all_aps();
> +
>  	unshare_all_memory();
>  
>  	/*
> @@ -1254,6 +1357,8 @@ static int wakeup_cpu_via_vmgexit(u32 apic_id, unsigned long start_ip)
>  	/* Record the current VMSA page */
>  	per_cpu(sev_vmsa, cpu) = vmsa;
>  
> +	per_cpu(sev_vcpu_apic_id, cpu) = apic_id;

Is this really needed? Can't you use the cpuid_to_apicid array or create
a function in the topology.c file to return the APIC ID?

Thanks,
Tom

> +
>  	return ret;
>  }
>  

      parent reply	other threads:[~2025-04-22 14:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-21 20:44 [PATCH] x86/sev: Fix SNP guest kdump hang/softlockup/panic Ashish Kalra
2025-04-21 21:23 ` Borislav Petkov
2025-04-22 14:53 ` Tom Lendacky [this message]

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=787ce95c-2d7c-b005-6b6b-c379f0a9f603@amd.com \
    --to=thomas.lendacky@amd.com \
    --cc=Ashish.Kalra@amd.com \
    --cc=ardb@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=gustavoars@kernel.org \
    --cc=hpa@zytor.com \
    --cc=kees@kernel.org \
    --cc=kexec@lists.infradead.org \
    --cc=linux-coco@lists.linux.dev \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael.roth@amd.com \
    --cc=mingo@redhat.com \
    --cc=nikunj@amd.com \
    --cc=seanjc@google.com \
    --cc=sgarzare@redhat.com \
    --cc=tglx@linutronix.de \
    --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