Re: [PATCH] x86/mm: Revert INVLPGB optimization for set_memory code

From: Edgecombe, Rick P

Date: Tue Apr 21 2026 - 14:43:23 EST


On Tue, 2026-04-21 at 08:19 -0700, Dave Hansen wrote:
> 86e6815b316e made the mistake of assuming that the virtual addresses
> in the cpa_data are always contiguous. It got things right when neither
> CPA_ARRAY/CPA_PAGES_ARRAY is used, but theoretically wrong when either
> of those is used.
>
> In the i915 case, it probably failed to flush some WB TLB entries and
> install WC ones, leaving some data in the caches and not flushing it
> out to where the device could see it. That eventually caused graphics
> problems.

Reviewed-by: Rick Edgecombe <rick.p.edgecombe@xxxxxxxxx>

Makes sense. And I see the merit in just trying to revert the change. But I
think a change to fix the optimization is also temptingly small:

diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
index 40581a720fe82..2a7ee1848f7ed 100644
--- a/arch/x86/mm/pat/set_memory.c
+++ b/arch/x86/mm/pat/set_memory.c
@@ -2089,6 +2089,7 @@ static int change_page_attr_set_clr(unsigned long *addr,
int numpages,
cpa.flags = in_flag;
cpa.curpage = 0;
cpa.force_split = force_split;
+ cpa.force_flush_all = in_flag & (CPA_PAGES_ARRAY | CPA_ARRAY);

ret = __change_page_attr_set_clr(&cpa, 1);


Also, could add:
Fixes: 86e6815b316ec ("x86/mm: Change cpa_flush() to call flush_kernel_range()
directly")