linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH, x86]: Disable CPA cache flush for selfsnoop targets
@ 2019-07-11  8:12 Uros Bizjak
  2019-07-11 14:39 ` Andy Lutomirski
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Uros Bizjak @ 2019-07-11  8:12 UTC (permalink / raw)
  To: linux-kernel; +Cc: x86, Andrew Lutomirski, Thomas Gleixner

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

Recent patch [1] disabled a self-snoop feature on a list of processor
models with a known errata, so we are confident that the feature
should work on remaining models also for other purposes than to speed
up MTRR programming.

I would like to resurrect an old patch [2] that avoids calling clflush
and wbinvd
to invalidate caches when CPU supports selfsnoop.

The patch was ported to latest Fedora kernel (5.1.16) and tested with
CONFIG_CPA_DEBUG on INTEL_FAM6_IVYBRIDGE_X. The relevant ports of
dmesg show:

...
< hundreds of CPA protect messages, resulting from set_memory_rw CPA
undo test in mm/init_64.c >
CPA  protect  Rodata RO: 0xffffffffbd1fe000 - 0xffffffffbd1fefff PFN
1461fe req 8000000000000063 prevent 0000000000000002
CPA  protect  Rodata RO: 0xffff889c461fe000 - 0xffff889c461fefff PFN
1461fe req 8000000000000063 prevent 0000000000000002
Testing CPA: again
Freeing unused kernel image memory: 2016K
Freeing unused kernel image memory: 4K
x86/mm: Checked W+X mappings: passed, no W+X pages found.
rodata_test: all tests were successful
x86/mm: Checking user space page tables
x86/mm: Checked W+X mappings: passed, no W+X pages found.

and from CPA selftest:

CPA self-test:
 4k 36352 large 4021 gb 0 x 81[ffff889b00098000-ffff889bdf7ff000] miss 133120
 4k 180224 large 3740 gb 0 x 81[ffff889b00098000-ffff889bdf7ff000] miss 133120
 4k 180224 large 3740 gb 0 x 81[ffff889b00098000-ffff889bdf7ff000] miss 133120
ok.

[1] https://lkml.org/lkml/2019/6/27/828
[2] https://lkml.org/lkml/2009/4/8/508

Uros.

[-- Attachment #2: 0001-Disable-CPA-cache-flush-for-selfsnoop-targets.patch --]
[-- Type: text/x-patch, Size: 1003 bytes --]

From 17cbad5d45b6ae26dbcfe02deba597c83cd63a0d Mon Sep 17 00:00:00 2001
From: Uros Bizjak <ubizjak@gmail.com>
Date: Wed, 10 Jul 2019 15:01:44 +0200
Subject: [PATCH] Disable CPA cache flush for selfsnoop targets

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
 arch/x86/mm/pageattr.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
index 6a9a77a403c9..8893ef5f70cd 100644
--- a/arch/x86/mm/pageattr.c
+++ b/arch/x86/mm/pageattr.c
@@ -1725,10 +1725,11 @@ 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 = !!pgprot2cachemode(mask_set);
+	cache = !static_cpu_has(X86_FEATURE_SELFSNOOP) &&
+		pgprot2cachemode(mask_set);
 
 	/*
 	 * On error; flush everything to be sure.
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2019-07-16  0:32 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-11  8:12 [RFC PATCH, x86]: Disable CPA cache flush for selfsnoop targets Uros Bizjak
2019-07-11 14:39 ` Andy Lutomirski
2019-07-11 19:00   ` Uros Bizjak
2019-07-15  8:24 ` Thomas Gleixner
2019-07-15 12:04   ` Uros Bizjak
2019-07-15 16:31 ` Andi Kleen
2019-07-15 18:41   ` Thomas Gleixner
2019-07-15 19:19     ` Uros Bizjak
2019-07-15 19:30       ` Thomas Gleixner
2019-07-15 19:38         ` Andi Kleen
2019-07-15 22:12           ` Andy Lutomirski
2019-07-15 22:53             ` Andi Kleen
2019-07-15 23:10               ` Andy Lutomirski
2019-07-16  0:32                 ` Andi Kleen
2019-07-15 19:39     ` Andi Kleen
2019-07-15 19:44       ` Andy Lutomirski
2019-07-15 19:46       ` Thomas Gleixner

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).