All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Rapoport <rppt@kernel.org>
To: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>
Cc: "luto@kernel.org" <luto@kernel.org>,
	"x86@kernel.org" <x86@kernel.org>,
	"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
	"peterz@infradead.org" <peterz@infradead.org>,
	"bp@alien8.de" <bp@alien8.de>,
	"mingo@redhat.com" <mingo@redhat.com>,
	"tglx@kernel.org" <tglx@kernel.org>,
	"hpa@zytor.com" <hpa@zytor.com>,
	"thomas.lendacky@amd.com" <thomas.lendacky@amd.com>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 1/9] x86/mm/pat: flush the TLB when only an alias mapping changed
Date: Wed, 25 Nov 2026 10:59:56 +0200	[thread overview]
Message-ID: <awajjPwS-dKPnsKT@kernel.org> (raw)
In-Reply-To: <b7bd4a18c420fe65728f4d50b69e2be0d1d39aaa.camel@intel.com>

On Tue, Nov 24, 2026 at 10:49:28PM +0000, Edgecombe, Rick P wrote:
> On Thu, 2026-11-12 at 18:31 +0200, Mike Rapoport (Microsoft) wrote:
> > CPA flushes the TLB only when CPA_FLUSHTLB is set. cpa_process_alias()
> > sets the flag only in alias_cpa and never in the original request.
> > 
> > When the requested range already has the new protection and only its
> > alias changes, the alias keeps stale TLB entries. For example:
> > 
> > 	/* the vmalloc mapping is created read-only */
> > 	p = vmap(pages, nr, VM_MAP, PAGE_KERNEL_RO);
> > 
> > 	/* only the direct map changes and nothing is flushed */
> > 	set_memory_ro((unsigned long)p, nr);
> > 
> > Setting ->force_flush_all in cpa_process_alias() does not help: it only
> > chooses how the TLB is flushed, and cpa_flush() is skipped entirely
> > without CPA_FLUSHTLB.
> > 
> > Worse, when the alias wasn't changed at all, for example when the primary
> > mapping changes from ROX to RO or vice versa, ->force_flush_all in
> > cpa_process_alias() causes an unnecessary flush of all TLBs.
> > 
> > Propagate CPA_FLUSHTLB from the alias update to the original request, and
> > flush the entire TLB only when an alias actually changed.
> > 
> > Fixes: ab5130186d74 ("x86/mm/cpa: Flush direct map alias during cpa")
> 
> 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.
 
> 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 ;-)

[1] https://lore.kernel.org/all/20260721-generic-set-memory-v0-1-v1-0-2c1fc62306b3@kernel.org
 
-- 
Sincerely yours,
Mike.

  reply	other threads:[~2026-11-25  9:00 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-12 16:31 [PATCH 0/9] x86/mm: CPA robustness fixes and cleanups Mike Rapoport (Microsoft)
2026-11-12 16:31 ` [PATCH 1/9] x86/mm/pat: flush the TLB when only an alias mapping changed Mike Rapoport (Microsoft)
2026-11-24 22:49   ` Edgecombe, Rick P
2026-11-25  8:59     ` Mike Rapoport [this message]
2026-11-25 20:38       ` Edgecombe, Rick P
2026-11-26  7:34         ` Mike Rapoport
2026-11-30 22:55           ` Edgecombe, Rick P
2026-12-01 11:50             ` Mike Rapoport
2026-11-12 16:31 ` [PATCH 2/9] x86/mm: don't set kernel_set_to_readonly when write protecting fails Mike Rapoport (Microsoft)
2026-11-24 23:01   ` Edgecombe, Rick P
2026-11-25  9:05     ` Mike Rapoport
2026-11-25 20:39       ` Edgecombe, Rick P
2026-11-26  7:42         ` Mike Rapoport
2026-11-12 16:31 ` [PATCH 3/9] x86/mm/pat: don't populate page tables in set_memory_{en,de}crypted() Mike Rapoport (Microsoft)
2026-11-17 16:15   ` Tom Lendacky
2026-11-12 16:31 ` [PATCH 4/9] x86/mm/pat: don't BUG() on inconsistent page count Mike Rapoport (Microsoft)
2026-11-24 22:57   ` Edgecombe, Rick P
2026-11-25  9:11     ` Mike Rapoport
2026-11-25 20:46       ` Edgecombe, Rick P
2026-11-26  7:50         ` Mike Rapoport
2026-11-12 16:31 ` [PATCH 5/9] x86/mm/pat: don't warn about W^X violations before mark_rodata_ro() Mike Rapoport (Microsoft)
2026-11-12 21:46   ` Salvatore Bonaccorso
2026-11-15  6:25     ` Mike Rapoport
2026-11-15 13:52       ` Salvatore Bonaccorso
2026-11-12 16:31 ` [PATCH 6/9] x86/mm/pat: remove CPA_ARRAY Mike Rapoport (Microsoft)
2026-11-12 16:31 ` [PATCH 7/9] x86/mm/pat: pass the address to CPA by value Mike Rapoport (Microsoft)
2026-11-12 16:31 ` [PATCH 8/9] x86/mm/pat: move the collapse of large pages out of cpa_flush() Mike Rapoport (Microsoft)
2026-11-12 16:31 ` [PATCH 9/9] x86/mm/pat: use cpa_flush() on CPA errors Mike Rapoport (Microsoft)
2026-11-24 15:57 ` [PATCH 0/9] x86/mm: CPA robustness fixes and cleanups Mike Rapoport

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=awajjPwS-dKPnsKT@kernel.org \
    --to=rppt@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rick.p.edgecombe@intel.com \
    --cc=tglx@kernel.org \
    --cc=thomas.lendacky@amd.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.