Linux CXL
 help / color / mirror / Atom feed
* [PATCH] x86, memregion: Avoid big hammer from cpu_cache_invalidate_memregion()
@ 2026-01-22  1:58 Davidlohr Bueso
  2026-01-24  0:16 ` dan.j.williams
  0 siblings, 1 reply; 2+ messages in thread
From: Davidlohr Bueso @ 2026-01-22  1:58 UTC (permalink / raw)
  To: dave.hansen, peterz, bp
  Cc: hpa, dan.j.williams, Jonathan.Cameron, dave.jiang, dave,
	linux-kernel, x86, linux-cxl

The reason for getting away with wbinvd_on_all_cpus() was originally
that the users at the time were a one time at boot occurrence, so it
mitigated a lot of the effects of the system-wide disruptiveness and
cache destruction. This has now changed with users such as provisioning
memory through CXL Dynamic Capacity Devices.

Lets instead use clflushopt and only invalidate the range in question.
The performance of course scales poorly with the region size but is
ultimately less invasive.

Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
---
 arch/x86/mm/pat/set_memory.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 6c6eb486f7a6..4a1c4f6bec17 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -372,6 +372,19 @@ int cpu_cache_invalidate_memregion(phys_addr_t start, size_t len)
 {
 	if (WARN_ON_ONCE(!cpu_cache_has_invalidate_memregion()))
 		return -ENXIO;
+
+	if (static_cpu_has(X86_FEATURE_CLFLUSHOPT)) {
+		void *vaddr = memremap(start, len, MEMREMAP_WB);
+
+		if (!vaddr)
+			goto fallback;
+
+		clflush_cache_range(vaddr, len);
+		memunmap(vaddr);
+
+		return 0;
+	}
+fallback:
 	wbinvd_on_all_cpus();
 	return 0;
 }
-- 
2.39.5


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

end of thread, other threads:[~2026-01-24  0:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-22  1:58 [PATCH] x86, memregion: Avoid big hammer from cpu_cache_invalidate_memregion() Davidlohr Bueso
2026-01-24  0:16 ` dan.j.williams

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox