linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2, x86 CPA]: Add selfsnoop support
@ 2009-04-08 14:59 Uros Bizjak
  0 siblings, 0 replies; only message in thread
From: Uros Bizjak @ 2009-04-08 14:59 UTC (permalink / raw)
  To: Linux Kernel Mailing List; +Cc: Ingo Molnar, x86

[-- Attachment #1: Type: text/plain, Size: 2245 bytes --]

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>


[-- Attachment #2: p.diff --]
[-- Type: text/plain, Size: 1202 bytes --]

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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-04-08 14:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-08 14:59 [PATCH v2, x86 CPA]: Add selfsnoop support Uros Bizjak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).