Skip to contentSkip to conversation

x86/virt/sev: Revert "Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN"

PATCH Applied Tycho Andersen 3 participants 4 messages Jul 7 x86

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 x86/virt/sev: Revert "Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN"

From: "Tycho Andersen (AMD)" <[email protected]>

This reverts commit 99cf1fb58e68 ("x86/virt/sev: Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN").

Section 8.8 of the SNP spec says:

Before invoking SNP_INIT_EX with INIT_RMP set to 1, software must ensure that no CPUs contain dirty cache lines for the memory containing the RMP.

Cachelines can be moved from cache to cache in a dirty state. The wbinvd_on_all_cpus() before SNP_INIT_EX flushes the caches for each cpu, but if the IPIs for WBINVD race with this dirty cacheline movement, it is possible that they may not get flushed violating the firmware requirement.

Doing wbinvd_on_all_cpus() before setting SNPEn is safer since the RMP table is not yet in use.

[ Heroically bisected by Srikanth. ]
Fixes 99cf1fb58e68 ("x86/virt/sev: Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN")
---
 arch/x86/virt/svm/sev.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/virt/svm/sev.c +2 -0
index 8bcdce98f6dc..cff285d8ad8e 100644
@@ -536,6 +536,8 @@ int snp_prepare(void)
 		goto unlock;
 	}
 
+	wbinvd_on_all_cpus();
+
 	/*
 	 * MtrrFixDramModEn is not shared between threads on a core,
 	 * therefore it must be set on all CPUs prior to enabling SNP.

base-commit: aa6d9def48ea424a50c21de90ebe609c383cb05d

Signature · 1 line
2.55.0
#1 lore raw
Quoted 1 line · Tycho Andersen

Subject: [PATCH v4]

Ugh, sorry, this is the *public* v1. Got my automation wrong.

Thanks,

Tycho

Reviewed-by on v4 1/1
#2 lore raw
In reply to Tycho Andersen
Quoted 16 lines · Tycho Andersen

From: "Tycho Andersen (AMD)" <[email protected]>

This reverts commit 99cf1fb58e68 ("x86/virt/sev: Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN").

Section 8.8 of the SNP spec says:

Before invoking SNP_INIT_EX with INIT_RMP set to 1, software must ensure that no CPUs contain dirty cache lines for the memory containing the RMP.

Cachelines can be moved from cache to cache in a dirty state. The wbinvd_on_all_cpus() before SNP_INIT_EX flushes the caches for each cpu, but if the IPIs for WBINVD race with this dirty cacheline movement, it is possible that they may not get flushed violating the firmware requirement.

Quoted 8 lines

Doing wbinvd_on_all_cpus() before setting SNPEn is safer since the RMP table is not yet in use.

[ Heroically bisected by Srikanth. ]
Fixes 99cf1fb58e68 ("x86/virt/sev: Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN")
Quoted 19 lines
---
 arch/x86/virt/svm/sev.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/virt/svm/sev.c +2 -0
index 8bcdce98f6dc..cff285d8ad8e 100644
@@ -536,6 +536,8 @@ int snp_prepare(void)
 		goto unlock;
 	}
 
+	wbinvd_on_all_cpus();
+
 	/*
 	 * MtrrFixDramModEn is not shared between threads on a core,
 	 * therefore it must be set on all CPUs prior to enabling SNP.

base-commit: aa6d9def48ea424a50c21de90ebe609c383cb05d

#3 lore raw
In reply to Tycho Andersen
The following commit has been merged into the x86/urgent branch of tip:

The following commit has been merged into the x86/urgent branch of tip:

Commit-ID:     4c2509f3b79756679a02bea649c6a7501b58f52c
Gitweb:        https://git.kernel.org/tip/4c2509f3b79756679a02bea649c6a7501b58f52c
Author:        Tycho Andersen (AMD) <[email protected]>
AuthorDate:    Tue, 07 Jul 2026 09:00:33 -06:00
Committer:     Borislav Petkov (AMD) <[email protected]>
CommitterDate: Tue, 07 Jul 2026 09:11:17 -07:00

x86/virt/sev: Revert "Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN"

Revert

99cf1fb58e68 ("x86/virt/sev: Drop WBINVD before setting MSR_AMD64_SYSCFG_SNP_EN").

Section 8.8 of the SNP spec says:

Before invoking SNP_INIT_EX with INIT_RMP set to 1, software must ensure that no CPUs contain dirty cache lines for the memory containing the RMP.

Cachelines can be moved from cache to cache in a dirty state. The wbinvd_on_all_cpus() before SNP_INIT_EX flushes the caches for each CPU, but if the IPIs for WBINVD race with this dirty cacheline movement, it is possible that they may not get flushed, violating the firmware requirement.

Doing wbinvd_on_all_cpus() before setting SNPEn is safer since the RMP table is not yet in use.

[ Heroically bisected by Srikanth. ]
[ bp: Massage commit message. ]

---
 arch/x86/virt/svm/sev.c | 2 ++
 1 file changed, 2 insertions(+)
arch/x86/virt/svm/sev.c +2 -0
index 8bcdce9..cff285d 100644
@@ -536,6 +536,8 @@ int snp_prepare(void)
 		goto unlock;
 	}
 
+	wbinvd_on_all_cpus();
+
 	/*
 	 * MtrrFixDramModEn is not shared between threads on a core,
 	 * therefore it must be set on all CPUs prior to enabling SNP.