Re: [PATCH 1/9] x86/mm/pat: flush the TLB when only an alias mapping changed

From: Mike Rapoport

Date: Thu Nov 26 2026 - 02:34:58 EST


On Wed, Nov 25, 2026 at 08:38:18PM +0000, Edgecombe, Rick P wrote:
> On Wed, 2026-11-25 at 10:59 +0200, Mike Rapoport wrote:
> > > I think this^ only added a flush where there wasn't one before, fixing a
> > > different issue. I don't think it is the origination of this behavior for
> > > the
> > > case of when the primary target already has the right permission, but not
> > > the
> > > alias.
> >
> > Right, it was c31c7d4844ea ("x86: CPA, fix alias checks") that moved the
> > alias update into a copy and from thenn the alias's flag never got back to
> > the primary request.
> >
> > ab5130186d74 only adds the unnecessary flush when alias does not change.
>
> So the order goes?
>
> 1. c31c7d4844ea ("x86: CPA, fix alias checks") introduces missing flush
> 2. 935f5839827e ("x86/mm/cpa: Optimize cpa_flush_array() TLB invalidation")
> introduces optimization, and different type of missing flush then this patch
> addresses
> 3. ab5130186d74 ("x86/mm/cpa: Flush direct map alias during cpa") rolls back
> optimization such that the missing flush in 2 is restored.
> 4. Then this patch fixes the missing flush in 1 and marks 3 as fixes?
>
> Or some even more complicated combo? I think a lurking missing flush is a bigger
> issue than any extra flush that is not hit in practice (from the below). So 1
> would be a better fixes commit.

The right Fixes: is c31c7d4844ea ("x86: CPA, fix alias checks") IMO.
 
> > > BTW does this type of permission change happen anywhere in the kernel, where
> > > the
> > > primary and alias start mismatched? How frequently does it happen?
> >
> > Like the cover letter said it's "unlikely to happen in practice" :)
> >
> > Currently there are no callers in the tree that could trigger that.
> >
> > I'm working the generic set_memory_core [1] and the bots keep yelling at me
> > whenever I touch anything around.
> >
> > So while is a defense against potential future issues, the change is simple
> > and I think it's better to have it.
> >
> > Might also save us from reviewing several LLM generated reports that would
> > find the same thing ;-)
>
> Yea duplicates and AI false positives are a problem. But changing the code to
> prevent the reports seems backwards. Though I don't have any other solution then
> just drown in things to check.

The change is more to prevent a potential future issue than to stop AI
reports.

With more and more use cases using set_memory, adding code that ensures
there is no missing flush now is better than hunting it down when some new
caller hits it :)

> > [1]
> > https://lore.kernel.org/all/20260721-generic-set-memory-v0-1-v1-0-2c1fc62306b3@xxxxxxxxxx
>
> Neat... But I think set_memory() was never the ideal interface for kernel memory
> management. Maybe this is step towards that?

The very first one, yes.

Right now it's a total mess:

https://docs.kernel.org/mm/kernel-page-tables.html

and the first step I'm working on is at least to make all architectures
behave consistently.

--
Sincerely yours,
Mike.