mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
To: Mike Rapoport <rppt@kernel.org>
Cc: Dave Hansen <dave.hansen@linux.intel.com>,
	 Andy Lutomirski <luto@kernel.org>,
	Borislav Petkov <bp@alien8.de>,
	 "Denis V . Lunev" <den@openvz.org>,
	Ingo Molnar <mingo@redhat.com>, Juergen Gross <jgross@suse.com>,
	 Kiryl Shutsemau <kas@kernel.org>,
	"H. Peter Anvin" <hpa@zytor.com>,
	 Peter Zijlstra <peterz@infradead.org>,
	Thomas Gleixner <tglx@kernel.org>,
	linux-kernel@vger.kernel.org,  x86@kernel.org,
	Dave Hansen <dave.hansen@intel.com>
Subject: Re: [PATCH] x86/mm/pat: don't gate cpa_lock on debug_pagealloc_enabled()
Date: Tue, 21 Jul 2026 16:49:13 +0100	[thread overview]
Message-ID: <al-MrKyIafA8QR_8@lucifer> (raw)
In-Reply-To: <20260715144519.934289-1-rppt@kernel.org>

On Wed, Jul 15, 2026 at 05:45:19PM +0300, Mike Rapoport wrote:
> From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>
>
> Dave Hansen says:
>   My only question is *why*!?!? Why add extra locking complexity and rules
>   to optimize debug_pagealloc, which is already horrendously slow.
>
> Stop gating cpa_lock on debug_pagealloc_enabled() to simplify the code.
>
> Suggested-by: Dave Hansen <dave.hansen@intel.com>
> Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
>  arch/x86/mm/pat/set_memory.c | 19 +++++++------------
>  1 file changed, 7 insertions(+), 12 deletions(-)
>
> diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c
> index d023a40a1e03..e8316f5ffa8a 100644
> --- a/arch/x86/mm/pat/set_memory.c
> +++ b/arch/x86/mm/pat/set_memory.c
> @@ -62,10 +62,9 @@ enum cpa_warn {
>  static const int cpa_warn_level = CPA_PROTECT;
>
>  /*
> - * Serialize cpa() (for !DEBUG_PAGEALLOC which uses large identity mappings)
> - * using cpa_lock. So that we don't allow any other cpu, with stale large tlb
> - * entries change the page attribute in parallel to some other cpu
> - * splitting a large page entry along with changing the attribute.
> + * Serialize cpa() using cpa_lock so that we don't allow any other cpu, with
> + * stale large tlb entries, to change the page attribute in parallel to some
> + * other cpu splitting a large page entry along with changing the attribute.
>   */
>  static DEFINE_SPINLOCK(cpa_lock);
>
> @@ -1235,11 +1234,9 @@ static int split_large_page(struct cpa_data *cpa, pte_t *kpte,
>  {
>  	struct ptdesc *ptdesc;
>
> -	if (!debug_pagealloc_enabled())
> -		spin_unlock(&cpa_lock);
> +	spin_unlock(&cpa_lock);

-> _irqsave() is needed I think :) see below

>  	ptdesc = pagetable_alloc(GFP_KERNEL, 0);
> -	if (!debug_pagealloc_enabled())
> -		spin_lock(&cpa_lock);
> +	spin_lock(&cpa_lock);

-> _irqrestore() as below

>  	if (!ptdesc)
>  		return -ENOMEM;
>
> @@ -2023,11 +2020,9 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int primary)
>  		if (cpa->flags & (CPA_ARRAY | CPA_PAGES_ARRAY))
>  			cpa->numpages = 1;
>
> -		if (!debug_pagealloc_enabled())
> -			spin_lock(&cpa_lock);
> +		spin_lock(&cpa_lock);
>  		ret = __change_page_attr(cpa, primary);
> -		if (!debug_pagealloc_enabled())
> -			spin_unlock(&cpa_lock);
> +		spin_unlock(&cpa_lock);

__kernel_map_pages() can be called from irq context:

< GFP_ATOMIC context >
kfree() or whatever
-> ...
-> __free_pages_prepare()
-> debug_pagealloc_unmap_pages()
-> __kernel_map_pages()
-> __change_page_attr_set_clr()
-> cpa_lock spins [irqs off]

Sooo you're spin locking in irq context here, which is probably not a good idea.

All the cpa_lock spin locks have to be updated to reflect this.

So spin_lock_irqsave/restore I think?

But note that this turns Denis's cpa_lock patch ([0]) into a deadlock because
it's held across an IPI on TLB flush. So that has to be changed too, or possibly
dropped. I'll reply about that over there!

>  		if (ret)
>  			goto out;
>
>
> base-commit: a13c140cc289c0b7b3770bce5b3ad42ab35074aa
> --
> 2.53.0
>
>

Thanks, Lorenzo

[0]:https://lore.kernel.org/all/20260715183453.2381141-1-den@openvz.org/

  parent reply	other threads:[~2026-07-21 15:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-15 14:45 Mike Rapoport
2026-07-15 15:08 ` Dave Hansen
2026-07-15 15:10 ` [tip: x86/mm] x86/mm/pat: Don't " tip-bot2 for Mike Rapoport (Microsoft)
2026-07-21 15:49 ` Lorenzo Stoakes (ARM) [this message]
2026-07-22  8:51   ` [PATCH] x86/mm/pat: don't " Mike Rapoport
2026-07-22  8:54     ` Lorenzo Stoakes (ARM)
2026-07-28 13:53 ` Breno Leitao
2026-07-28 15:19   ` 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=al-MrKyIafA8QR_8@lucifer \
    --to=ljs@kernel.org \
    --cc=bp@alien8.de \
    --cc=dave.hansen@intel.com \
    --cc=dave.hansen@linux.intel.com \
    --cc=den@openvz.org \
    --cc=hpa@zytor.com \
    --cc=jgross@suse.com \
    --cc=kas@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rppt@kernel.org \
    --cc=tglx@kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®