[PATCH 08/11] x86/snp: allow disabling MFDM

Tycho Andersen posted 11 patches 8 hours ago
[PATCH 08/11] x86/snp: allow disabling MFDM
Posted by Tycho Andersen 8 hours ago
From: "Tycho Andersen (AMD)" <tycho@kernel.org>

The SNP x86 shutdown path needs to disable MFDM, since as the comment for
k8_check_syscfg_dram_mod_en(), the "BIOS" is supposed clear it, or the
kernel in the case of module unload and shutdown followed by kexec.

Change this helper to allow for disabling it.

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

diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
index 53bc0c7f2c50..cf984b8f4493 100644
--- a/arch/x86/virt/svm/sev.c
+++ b/arch/x86/virt/svm/sev.c
@@ -132,7 +132,7 @@ static unsigned long snp_nr_leaked_pages;
 #undef pr_fmt
 #define pr_fmt(fmt)	"SEV-SNP: " fmt
 
-static void mfd_enable(void *arg)
+static void mfd_reconfigure(void *arg)
 {
 	u64 val;
 
@@ -141,7 +141,10 @@ static void mfd_enable(void *arg)
 
 	rdmsrq(MSR_AMD64_SYSCFG, val);
 
-	val |= MSR_AMD64_SYSCFG_MFDM;
+	if (arg)
+		val |= MSR_AMD64_SYSCFG_MFDM;
+	else
+		val &= ~MSR_AMD64_SYSCFG_MFDM;
 
 	wrmsrq(MSR_AMD64_SYSCFG, val);
 }
@@ -532,7 +535,7 @@ void snp_prepare_for_snp_init(void)
 	 * MtrrFixDramModEn is not shared between threads on a core,
 	 * therefore it must be set on all CPUs prior to enabling SNP.
 	 */
-	on_each_cpu(mfd_enable, NULL, 1);
+	on_each_cpu(mfd_reconfigure, (void *)1, 1);
 
 	on_each_cpu(snp_enable, NULL, 1);
 
-- 
2.53.0
Re: [PATCH 08/11] x86/snp: allow disabling MFDM
Posted by Tom Lendacky 6 hours ago
On 3/2/26 13:13, Tycho Andersen wrote:
> From: "Tycho Andersen (AMD)" <tycho@kernel.org>
> 
> The SNP x86 shutdown path needs to disable MFDM, since as the comment for
> k8_check_syscfg_dram_mod_en(), the "BIOS" is supposed clear it, or the
> kernel in the case of module unload and shutdown followed by kexec.
> 
> Change this helper to allow for disabling it.
> 
> Signed-off-by: Tycho Andersen (AMD) <tycho@kernel.org>

This could be squashed with the next patch, but either way:

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

> ---
>  arch/x86/virt/svm/sev.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index 53bc0c7f2c50..cf984b8f4493 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -132,7 +132,7 @@ static unsigned long snp_nr_leaked_pages;
>  #undef pr_fmt
>  #define pr_fmt(fmt)	"SEV-SNP: " fmt
>  
> -static void mfd_enable(void *arg)
> +static void mfd_reconfigure(void *arg)
>  {
>  	u64 val;
>  
> @@ -141,7 +141,10 @@ static void mfd_enable(void *arg)
>  
>  	rdmsrq(MSR_AMD64_SYSCFG, val);
>  
> -	val |= MSR_AMD64_SYSCFG_MFDM;
> +	if (arg)
> +		val |= MSR_AMD64_SYSCFG_MFDM;
> +	else
> +		val &= ~MSR_AMD64_SYSCFG_MFDM;
>  
>  	wrmsrq(MSR_AMD64_SYSCFG, val);
>  }
> @@ -532,7 +535,7 @@ void snp_prepare_for_snp_init(void)
>  	 * MtrrFixDramModEn is not shared between threads on a core,
>  	 * therefore it must be set on all CPUs prior to enabling SNP.
>  	 */
> -	on_each_cpu(mfd_enable, NULL, 1);
> +	on_each_cpu(mfd_reconfigure, (void *)1, 1);
>  
>  	on_each_cpu(snp_enable, NULL, 1);
>