lkml.org 
[lkml]   [2009]   [Apr]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH v2, x86 CPA]: Add selfsnoop support
Hello!

This is second variant of a selfsnoop support for recent x86 CPUs. The
patch is effectively a one-liner and avoids calling clflush and wbinvd
to invalidate caches when CPU supports selfsnoop.

The patch applies to current git and -tip trees. This patch was tested
on Ubuntu 2.6.29.1 kernel:

processor : 0
vendor_id : GenuineIntel
cpu family : 15
model : 1
model name : Intel(R) Pentium(R) 4 CPU 1.60GHz
stepping : 2
cpu MHz : 1594.873
cache size : 256 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 2
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush dts acpi
mmx fxsr sse sse2 ss ht tm up pebs bts sync_rdtsc
bogomips : 3194.10
clflush size : 64

with CONFIG_CPA_DEBUG. Relevant self-test lines from the boot log are:

Apr 8 14:46:57 ubuntudsp kernel: [ 1.861293] Write protecting the
kernel text: 3988k
Apr 8 14:46:57 ubuntudsp kernel: [ 1.861298] Testing CPA: Reverting
c1000000-c13e5000
Apr 8 14:46:57 ubuntudsp kernel: [ 1.861412] Testing CPA: write
protecting again
Apr 8 14:46:57 ubuntudsp kernel: [ 1.861610] Write protecting the
kernel read-only data: 1776k
Apr 8 14:46:57 ubuntudsp kernel: [ 1.861615] Testing CPA: undo
c13e5000-c15a1000
Apr 8 14:46:57 ubuntudsp kernel: [ 1.861665] Testing CPA: write
protecting again
Apr 8 14:46:57 ubuntudsp kernel: [ 1.898397] exe used greatest stack
depth: 6808 bytes left
...
Apr 8 14:47:03 ubuntudsp kernel: [ 30.771018] CPA self-test:
Apr 8 14:47:03 ubuntudsp kernel: [ 30.771228] 4k 4992 large 155 gb 0
x 5147[c0000000-e7f7f000] miss 0
Apr 8 14:47:03 ubuntudsp kernel: [ 30.786583] 4k 148352 large 15 gb
0 x 148367[c0000000-e7f7f000] miss 0
Apr 8 14:47:03 ubuntudsp kernel: [ 30.793998] 4k 148352 large 15 gb
0 x 148367[c0000000-e7f7f000] miss 0
Apr 8 14:47:03 ubuntudsp kernel: [ 30.794010] ok.

The patched kernel was used on my workstation for my daily work for
several days (XWin, heavily compilations, IPTV, internet browsing) and I
didn't found any problems with the patched kernel.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>

diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
index 0beba0d..267f3ca 100644
--- a/arch/x86/include/asm/cpufeature.h
+++ b/arch/x86/include/asm/cpufeature.h
@@ -242,6 +242,7 @@ extern const char * const x86_power_flags[32];
#define cpu_has_x2apic boot_cpu_has(X86_FEATURE_X2APIC)
#define cpu_has_xsave boot_cpu_has(X86_FEATURE_XSAVE)
#define cpu_has_hypervisor boot_cpu_has(X86_FEATURE_HYPERVISOR)
+#define cpu_has_selfsnoop boot_cpu_has(X86_FEATURE_SELFSNOOP)

#if defined(CONFIG_X86_INVLPG) || defined(CONFIG_X86_64)
# define cpu_has_invlpg 1
diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index d71e1b6..bbca9d2 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -875,10 +875,10 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages,
goto out;

/*
- * No need to flush, when we did not set any of the caching
- * attributes:
+ * No need to flush when CPU supports self snoop or
+ * when we did not set any of the caching attributes:
*/
- cache = cache_attr(mask_set);
+ cache = cpu_has_selfsnoop ? 0 : cache_attr(mask_set);

/*
* On success we use clflush, when the CPU supports it to
\
 
 \ /
  Last update: 2009-04-08 17:03    [W:0.024 / U:24.256 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site