[PATCH 9/9] x86/mm/pat: use cpa_flush() on CPA errors
From: Mike Rapoport (Microsoft)
Date: Thu Nov 12 2026 - 11:49:06 EST
When __change_page_attr_set_clr() fails, change_page_attr_set_clr()
calls cpa_flush_all() instead of cpa_flush(). The flush depends on the
error code rather than on what CPA changed.
Force a flush of the entire TLB on error and always call cpa_flush().
The TLB flush stays the same. When cache attributes change and the CPU
supports CLFLUSH, the requested range is flushed with clflush instead
of wbinvd on all CPUs.
Signed-off-by: Mike Rapoport (Microsoft) <rppt@xxxxxxxxxx>
---
arch/x86/mm/pat/set_memory.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 80b5a2faefd7c..2ff37ff1cecdc 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2152,13 +2152,14 @@ static int change_page_attr_set_clr(unsigned long addr, int numpages,
/*
* On error; flush everything to be sure.
*/
- if (ret) {
- cpa_flush_all(cache);
- goto out;
- }
+ if (ret)
+ cpa.force_flush_all = 1;
cpa_flush(&cpa, cache);
+ if (ret)
+ goto out;
+
if (!(cpa.flags & CPA_COLLAPSE))
goto out;
--
2.53.0