[PATCH 01/11] x86/snp: drop support for SNP hotplug

Tycho Andersen posted 11 patches 8 hours ago
[PATCH 01/11] x86/snp: drop support for SNP hotplug
Posted by Tycho Andersen 8 hours ago
From: "Tycho Andersen (AMD)" <tycho@kernel.org>

During an SNP_INIT(_EX), the SEV firmware checks that all CPUs have SNPEn
set, and fails if they do not. As such, it does not make sense to have
offline CPUs: the firmware will fail initialization because of the offlined
ones that the kernel did not initialize.

Futher, there is a bug: SNP_INIT(_EX) require MFDM to be set in addition to
SNPEn which the previous hotplug code did not do. Since
k8_check_syscfg_dram_mod_en() enforces this be cleared, hotplug wouldn't
work.

Drop the hotplug code. Collapse the __{mfd,snp}__enable() wrappers into
their non-__ versions, since the cpu number argument is no longer needed.

Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>
---
 arch/x86/virt/svm/sev.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)

diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
index a4f3a364fb65..1446011c6337 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -130,33 +130,26 @@ static unsigned long snp_nr_leaked_pages;
 #undef pr_fmt
 #define pr_fmt(fmt)	"SEV-SNP: " fmt
 
-static int __mfd_enable(unsigned int cpu)
+static __init void mfd_enable(void *arg)
 {
 	u64 val;
 
 	if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
-		return 0;
+		return;
 
 	rdmsrq(MSR_AMD64_SYSCFG, val);
 
 	val |= MSR_AMD64_SYSCFG_MFDM;
 
 	wrmsrq(MSR_AMD64_SYSCFG, val);
-
-	return 0;
 }
 
-static __init void mfd_enable(void *arg)
-{
-	__mfd_enable(smp_processor_id());
-}
-
-static int __snp_enable(unsigned int cpu)
+static __init void snp_enable(void *arg)
 {
 	u64 val;
 
 	if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
-		return 0;
+		return;
 
 	rdmsrq(MSR_AMD64_SYSCFG, val);
 
@@ -164,13 +157,6 @@ static int __snp_enable(unsigned int cpu)
 	val |= MSR_AMD64_SYSCFG_SNP_VMPL_EN;
 
 	wrmsrq(MSR_AMD64_SYSCFG, val);
-
-	return 0;
-}
-
-static __init void snp_enable(void *arg)
-{
-	__snp_enable(smp_processor_id());
 }
 
 static void __init __snp_fixup_e820_tables(u64 pa)
@@ -553,8 +539,6 @@ int __init snp_rmptable_init(void)
 	on_each_cpu(snp_enable, NULL, 1);
 
 skip_enable:
-	cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/rmptable_init:online", __snp_enable, NULL);
-
 	/*
 	 * Setting crash_kexec_post_notifiers to 'true' to ensure that SNP panic
 	 * notifier is invoked to do SNP IOMMU shutdown before kdump.
-- 
2.53.0
Re: [PATCH 01/11] x86/snp: drop support for SNP hotplug
Posted by Tom Lendacky 7 hours ago
On 3/2/26 13:13, Tycho Andersen wrote:
> [Some people who received this message don't often get email from tycho@kernel.org. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> From: "Tycho Andersen (AMD)" <tycho@kernel.org>
> 
> During an SNP_INIT(_EX), the SEV firmware checks that all CPUs have SNPEn
> set, and fails if they do not. As such, it does not make sense to have
> offline CPUs: the firmware will fail initialization because of the offlined
> ones that the kernel did not initialize.
> 
> Futher, there is a bug: SNP_INIT(_EX) require MFDM to be set in addition to
> SNPEn which the previous hotplug code did not do. Since
> k8_check_syscfg_dram_mod_en() enforces this be cleared, hotplug wouldn't
> work.
> 
> Drop the hotplug code. Collapse the __{mfd,snp}__enable() wrappers into
> their non-__ versions, since the cpu number argument is no longer needed.
> 
> Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>

Reviewed-by: Tom Lendacky <thomas.lendacky@amd.com>

> ---
>  arch/x86/virt/svm/sev.c | 24 ++++--------------------
>  1 file changed, 4 insertions(+), 20 deletions(-)
> 
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index a4f3a364fb65..1446011c6337 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -130,33 +130,26 @@ static unsigned long snp_nr_leaked_pages;
>  #undef pr_fmt
>  #define pr_fmt(fmt)    "SEV-SNP: " fmt
> 
> -static int __mfd_enable(unsigned int cpu)
> +static __init void mfd_enable(void *arg)
>  {
>         u64 val;
> 
>         if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
> -               return 0;
> +               return;
> 
>         rdmsrq(MSR_AMD64_SYSCFG, val);
> 
>         val |= MSR_AMD64_SYSCFG_MFDM;
> 
>         wrmsrq(MSR_AMD64_SYSCFG, val);
> -
> -       return 0;
>  }
> 
> -static __init void mfd_enable(void *arg)
> -{
> -       __mfd_enable(smp_processor_id());
> -}
> -
> -static int __snp_enable(unsigned int cpu)
> +static __init void snp_enable(void *arg)
>  {
>         u64 val;
> 
>         if (!cc_platform_has(CC_ATTR_HOST_SEV_SNP))
> -               return 0;
> +               return;
> 
>         rdmsrq(MSR_AMD64_SYSCFG, val);
> 
> @@ -164,13 +157,6 @@ static int __snp_enable(unsigned int cpu)
>         val |= MSR_AMD64_SYSCFG_SNP_VMPL_EN;
> 
>         wrmsrq(MSR_AMD64_SYSCFG, val);
> -
> -       return 0;
> -}
> -
> -static __init void snp_enable(void *arg)
> -{
> -       __snp_enable(smp_processor_id());
>  }
> 
>  static void __init __snp_fixup_e820_tables(u64 pa)
> @@ -553,8 +539,6 @@ int __init snp_rmptable_init(void)
>         on_each_cpu(snp_enable, NULL, 1);
> 
>  skip_enable:
> -       cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "x86/rmptable_init:online", __snp_enable, NULL);
> -
>         /*
>          * Setting crash_kexec_post_notifiers to 'true' to ensure that SNP panic
>          * notifier is invoked to do SNP IOMMU shutdown before kdump.
> --
> 2.53.0
>