]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
x86/cacheinfo: Extract out cache self-snoop checks
authorAhmed S. Darwish <darwi@linutronix.de>
Mon, 24 Mar 2025 13:33:21 +0000 (14:33 +0100)
committerIngo Molnar <mingo@kernel.org>
Tue, 25 Mar 2025 09:23:24 +0000 (10:23 +0100)
The logic of not doing a cache flush if the CPU declares cache self
snooping support is repeated across the x86/cacheinfo code.  Extract it
into its own function.

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20250324133324.23458-27-darwi@linutronix.de
arch/x86/kernel/cpu/cacheinfo.c

index 7b274da7c725bd196fbcc8968c86ae46a56f0273..231470cdc1da0baa539f7fecd5c3d09d8c7531ab 100644 (file)
@@ -646,6 +646,17 @@ int populate_cache_leaves(unsigned int cpu)
 static unsigned long saved_cr4;
 static DEFINE_RAW_SPINLOCK(cache_disable_lock);
 
+/*
+ * Cache flushing is the most time-consuming step when programming the
+ * MTRRs.  On many Intel CPUs without known erratas, it can be skipped
+ * if the CPU declares cache self-snooping support.
+ */
+static void maybe_flush_caches(void)
+{
+       if (!static_cpu_has(X86_FEATURE_SELFSNOOP))
+               wbinvd();
+}
+
 void cache_disable(void) __acquires(cache_disable_lock)
 {
        unsigned long cr0;
@@ -663,14 +674,7 @@ void cache_disable(void) __acquires(cache_disable_lock)
        cr0 = read_cr0() | X86_CR0_CD;
        write_cr0(cr0);
 
-       /*
-        * Cache flushing is the most time-consuming step when programming
-        * the MTRRs. Fortunately, as per the Intel Software Development
-        * Manual, we can skip it if the processor supports cache self-
-        * snooping.
-        */
-       if (!static_cpu_has(X86_FEATURE_SELFSNOOP))
-               wbinvd();
+       maybe_flush_caches();
 
        /* Save value of CR4 and clear Page Global Enable (bit 7) */
        if (cpu_feature_enabled(X86_FEATURE_PGE)) {
@@ -685,9 +689,7 @@ void cache_disable(void) __acquires(cache_disable_lock)
        if (cpu_feature_enabled(X86_FEATURE_MTRR))
                mtrr_disable();
 
-       /* Again, only flush caches if we have to. */
-       if (!static_cpu_has(X86_FEATURE_SELFSNOOP))
-               wbinvd();
+       maybe_flush_caches();
 }
 
 void cache_enable(void) __releases(cache_disable_lock)