aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/boot/cpuflags.c
diff options
context:
space:
mode:
authorTom Lendacky <[email protected]>2025-07-29 18:41:29 +0000
committerBorislav Petkov (AMD) <[email protected]>2025-08-06 17:17:22 +0000
commit7b306dfa326f70114312b320d083b21fa9481e1e (patch)
treef039016549ed7d1793a097f88448598b1419c8f4 /arch/x86/boot/cpuflags.c
parentMerge tag 'x86-platform-2025-07-29' of git://git.kernel.org/pub/scm/linux/ker... (diff)
downloadkernel-7b306dfa326f70114312b320d083b21fa9481e1e.tar.gz
kernel-7b306dfa326f70114312b320d083b21fa9481e1e.zip
x86/sev: Evict cache lines during SNP memory validation
An SNP cache coherency vulnerability requires a cache line eviction mitigation when validating memory after a page state change to private. The specific mitigation is to touch the first and last byte of each 4K page that is being validated. There is no need to perform the mitigation when performing a page state change to shared and rescinding validation. CPUID bit Fn8000001F_EBX[31] defines the COHERENCY_SFW_NO CPUID bit that, when set, indicates that the software mitigation for this vulnerability is not needed. Implement the mitigation and invoke it when validating memory (making it private) and the COHERENCY_SFW_NO bit is not set, indicating the SNP guest is vulnerable. Co-developed-by: Michael Roth <[email protected]> Signed-off-by: Michael Roth <[email protected]> Signed-off-by: Tom Lendacky <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Acked-by: Thomas Gleixner <[email protected]>
Diffstat (limited to 'arch/x86/boot/cpuflags.c')
-rw-r--r--arch/x86/boot/cpuflags.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/arch/x86/boot/cpuflags.c b/arch/x86/boot/cpuflags.c
index 916bac09b464..63e037e94e4c 100644
--- a/arch/x86/boot/cpuflags.c
+++ b/arch/x86/boot/cpuflags.c
@@ -106,5 +106,18 @@ void get_cpuflags(void)
cpuid(0x80000001, &ignored, &ignored, &cpu.flags[6],
&cpu.flags[1]);
}
+
+ if (max_amd_level >= 0x8000001f) {
+ u32 ebx;
+
+ /*
+ * The X86_FEATURE_COHERENCY_SFW_NO feature bit is in
+ * the virtualization flags entry (word 8) and set by
+ * scattered.c, so the bit needs to be explicitly set.
+ */
+ cpuid(0x8000001f, &ignored, &ebx, &ignored, &ignored);
+ if (ebx & BIT(31))
+ set_bit(X86_FEATURE_COHERENCY_SFW_NO, cpu.flags);
+ }
}
}