All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ashish Kalra" <Ashish.Kalra@amd.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH v13 2/5] x86/sev: Disable CPU hotplug while SNP is active
Date: Wed, 02 Sep 2026 21:51:29 +0000	[thread overview]
Message-ID: <20260902215130.260101F000E9@smtp.kernel.org> (raw)
In-Reply-To: <2c97a61a22a4808d422367e50db7ee0103a49860.1788296083.git.ashish.kalra@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Critical] PM Suspend (S3) bypasses CPU hotplug disable, leading to security breakdown
- [High] CPU hotplug remains enabled on kexec boot if setup_rmptable() fails
--

commit c91487bb659a8ce73e581c086c8aa1aa19f4b9aa
Author: Ashish Kalra <ashish.kalra@amd.com>
x86/sev: Disable CPU hotplug while SNP is active

This patch disables CPU hotplug while SNP is active to ensure no CPU comes
online without the SnpEn bit set. It ties hotplug to the SNP-enable bit by
disabling it in snp_prepare() and re-enabling it in snp_shutdown().

> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index cff285d8ad8e3..558f7924a3f85 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c

[ ... ]

> @@ -526,14 +525,18 @@ int snp_prepare(void)
>  
>  	clear_rmp();
>  
> -	cpus_read_lock();
> +	/*
> +	 * No CPU may come online without SnpEn while SNP is active; disable
> +	 * hotplug here and re-enable it in snp_shutdown().
> +	 */
> +	cpu_hotplug_disable();

[Severity: Critical]
Does this sequence prevent CPUs from being onlined without SnpEn set during
power management transitions?

While cpu_hotplug_disable() blocks sysfs-initiated hotplug operations, it
appears that system suspend (S3) and hibernation (S4) bypass this mechanism.
During suspend, the PM core uses freeze_secondary_cpus() and
thaw_secondary_cpus(), which explicitly call _cpu_down() and _cpu_up()
regardless of the cpu_hotplug_disabled counter.

Additionally, MSR_AMD64_SYSCFG is not included in the list of MSRs saved and
restored during PM transitions in arch/x86/power/cpu.c.

If a system with SNP active goes to sleep and resumes, will the secondary
CPUs wake up without the SnpEn bit set, potentially breaking the SEV-SNP
security model by failing to enforce RMP checks?

[ ... ]

> @@ -577,6 +582,8 @@ EXPORT_SYMBOL_FOR_MODULES(snp_shutdown, "ccp");
>   */
>  int __init snp_rmptable_init(void)
>  {
> +	u64 val;
> +
>  	if (WARN_ON_ONCE(!cc_platform_has(CC_ATTR_HOST_SEV_SNP)))
>  		return -ENOSYS;
>  
> @@ -586,6 +593,15 @@ int __init snp_rmptable_init(void)
>  	if (!setup_rmptable())
>  		return -ENOSYS;

[Severity: High]
If setup_rmptable() fails and returns -ENOSYS early, do we leave CPU hotplug
enabled even though the hardware might still have SNP enabled from a previous
kernel?

When booting via kexec from an SNP-enabled kernel, the CPUs retain the SnpEn
bit in MSR_AMD64_SYSCFG. If setup_rmptable() fails here (for example, due to
a memremap failure), the function exits before reaching the new check that
disables CPU hotplug.

Because the function failed, the kernel clears CC_ATTR_HOST_SEV_SNP. If a CPU
is subsequently hotplugged via sysfs, the new kernel will not set SnpEn on
it, resulting in a state where boot CPUs have SnpEn set but the hotplugged
CPU does not.

Could this early return be moved after the MSR_AMD64_SYSCFG_SNP_EN check to
ensure hotplug is disabled whenever the hardware indicates SNP is active?

> +
> +	/*
> +	 * On a kexec boot SNP may already be enabled (legacy firmware leaves
> +	 * SnpEn set across shutdown), in which case snp_prepare() bails without
> +	 * disabling CPU hotplug, so disable it here.
> +	 */
> +	rdmsrq(MSR_AMD64_SYSCFG, val);
> +	if (val & MSR_AMD64_SYSCFG_SNP_EN)
> +		cpu_hotplug_disable();
> +
>  	/*
>  	 * Setting crash_kexec_post_notifiers to 'true' to ensure that SNP panic
>  	 * notifier is invoked to do SNP IOMMU shutdown before kdump.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788296083.git.ashish.kalra@amd.com?part=2

  reply	other threads:[~2026-09-02 21:51 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-02 21:27 [PATCH v13 0/5] Add RMPOPT support Ashish Kalra
2026-09-02 21:27 ` [PATCH v13 1/5] x86/cpufeatures: Add X86_FEATURE_RMPOPT feature flag Ashish Kalra
2026-09-02 21:28 ` [PATCH v13 2/5] x86/sev: Disable CPU hotplug while SNP is active Ashish Kalra
2026-09-02 21:51   ` sashiko-bot [this message]
2026-09-02 22:12     ` Kalra, Ashish
2026-09-02 21:28 ` [PATCH v13 3/5] x86/sev: Initialize RMPOPT configuration MSRs Ashish Kalra
2026-09-02 21:44   ` sashiko-bot
2026-09-02 21:56     ` Kalra, Ashish
2026-09-02 21:28 ` [PATCH v13 4/5] x86/sev: Add support to perform RMP optimizations asynchronously Ashish Kalra
2026-09-02 21:36   ` Dave Hansen
2026-09-02 21:57   ` sashiko-bot
2026-09-02 22:36     ` Kalra, Ashish
2026-09-05  1:29   ` Borislav Petkov
2026-09-08 20:21     ` Kalra, Ashish
2026-09-09  1:52       ` Borislav Petkov
2026-09-09 13:55         ` Kalra, Ashish
2026-09-02 21:29 ` [PATCH v13 5/5] x86/sev: Re-enable RMP optimizations on SNP guest shutdown Ashish Kalra
2026-09-02 21:37   ` Dave Hansen
2026-09-02 22:01   ` sashiko-bot
2026-09-02 22:45     ` Kalra, Ashish
2026-09-06 17:24   ` Borislav Petkov

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=20260902215130.260101F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Ashish.Kalra@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.