public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yeoreum Yun <yeoreum.yun@arm.com>
To: Yang Shi <yang@os.amperecomputing.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>,
	Will Deacon <will@kernel.org>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, linux-rt-devel@lists.linux.dev,
	catalin.marinas@arm.com, akpm@linux-oundation.org,
	david@kernel.org, kevin.brodsky@arm.com,
	quic_zhenhuah@quicinc.com, dev.jain@arm.com,
	chaitanyas.prakash@arm.com, bigeasy@linutronix.de,
	clrkwllms@kernel.org, rostedt@goodmis.org,
	lorenzo.stoakes@oracle.com, ardb@kernel.org, jackmanb@google.com,
	vbabka@suse.cz, mhocko@suse.com
Subject: Re: [PATCH v5 2/3] arm64: mmu: avoid allocating pages while splitting the linear mapping
Date: Wed, 21 Jan 2026 08:32:29 +0000	[thread overview]
Message-ID: <aXCPHaylUbRJ3CME@e129823.arm.com> (raw)
In-Reply-To: <02bb61cc-f0be-41e5-b8b2-59768afd5254@os.amperecomputing.com>

> > > My concern is that if a secondary CPU can race and cause a split, that is
> > > unsound because we have determined that although the primary CPU supports BBML2,
> > > at least one of the secondary CPUs does not. So splitting a live mapping is unsafe.
> > >
> > > I just had a brief chat with Rutland, and he agrees that this _could_ be a
> > > problem. Basically there is a window between onlining the secondary cpus and
> > > entering the stop_machine() where one of those cpus _could_ end up doing
> > > something that causes us to split the linear map.
>
> If I remember correctly, split_kernel_leaf_mapping() does call
> system_supports_bbml2_noabort() before doing real split. So we basically
> should fall into two categories:
>
> 1. bbml2_noabort is supported on all cpus. Everything is fine.
> 2. bbml2_noabort is not supported on all cpus. split_kernel_leaf_mapping()
> just returns 0. Kernel doesn't split page table, so there won't be TLB
> conflict issue. But the following page prot update may see unexpected block
> mapping, then a   WARN  will be raised and it will return -EINVAL. So the
> worst case is the caller will fail (IIRC all the callers of set_memory_*()
> handle the failure), and we can know who is trying to change linear mapping
> before the linear mapping gets                    finalized. AFAICT I
> haven't seen such WARN yet.

Thanks for the great detail :)
I've missed system_supports_bbml2_noabort() in split_kernel_leaf_mapping().

>
> > >
> > > I'm not immediately sure how to solve that.
>
> Do we need some synchronization mechanism? If the linear mapping is not
> finalized yet, split_kernel_leaf_mapping() will spin. For example, something
> like this off the top of my head,
>
> DEFINE_STATIC_KEY_FALSE(linear_mapping_finalized);
>
> Once the linear mapping is finalized, we can call
> static_branch_enable(&linear_mapping_finalized);
>
> In split_kernel_leaf_mapping(), we can just do:
>
> retry:
>     if (!static_branch_likely(&linear_mapping_finalized))
>         goto retry;
>
>
> There may be better way to handle it. But this case should be very unlikely
> IMHO. It sounds crazy to have such complicated kernel threads run so early.
> I'm not sure whether we should pay immediate attention to it or not.

Thinking about it again, I’m not sure whether
it is acceptable to use a sleepable synchronization mechanism at this stage,
like split_kernel_leaf_mapping() does with mutex_lock()
(even though it may be technically possible).
It also feels odd that this function can be called at this point in time.

If this is indeed considered problematic,
I think it would be better to simply return -EINVAL immediately
when linear_mapping_finalized has not yet been completed.

--
Sincerely,
Yeoreum Yun

  reply	other threads:[~2026-01-21  8:33 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-05 20:23 [PATCH v5 0/3] fix wrong usage of memory allocation APIs under PREEMPT_RT in arm64 Yeoreum Yun
2026-01-05 20:23 ` [PATCH v5 1/3] arm64: mmu: introduce pgtable_alloc_t Yeoreum Yun
2026-01-05 20:23 ` [PATCH v5 2/3] arm64: mmu: avoid allocating pages while splitting the linear mapping Yeoreum Yun
2026-01-19 17:28   ` Will Deacon
2026-01-19 21:24     ` Yeoreum Yun
2026-01-20  8:56       ` Ryan Roberts
2026-01-20  9:29         ` Yeoreum Yun
2026-01-20 10:40           ` Ryan Roberts
2026-01-20 10:54             ` Yeoreum Yun
2026-01-20 15:53             ` Will Deacon
2026-01-20 16:16               ` Yeoreum Yun
2026-01-20 16:22               ` Ryan Roberts
2026-01-20 16:31                 ` Yeoreum Yun
2026-01-20 17:35                   ` Ryan Roberts
2026-01-20 17:49                     ` Yeoreum Yun
2026-01-21  0:12                     ` Yang Shi
2026-01-21  8:32                       ` Yeoreum Yun [this message]
2026-01-21 10:20                         ` Ryan Roberts
2026-01-21 11:30                           ` Yeoreum Yun
2026-01-21 22:57                           ` Yang Shi
2026-01-22  7:42                             ` Yeoreum Yun
2026-01-22 13:47                               ` Ryan Roberts
2026-01-20 22:24           ` Yang Shi
2026-01-20 23:01             ` Yeoreum Yun
2026-01-21  0:43               ` Yang Shi
2026-01-21  8:15                 ` Yeoreum Yun
2026-01-05 20:23 ` [PATCH v5 3/3] arm64: mmu: avoid allocating pages while installing ng-mapping for KPTI Yeoreum Yun
2026-01-19 17:31   ` Will Deacon
2026-01-19 21:30     ` Yeoreum Yun
2026-01-20 11:44       ` Will Deacon
2026-01-20 15:30         ` Yeoreum Yun

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=aXCPHaylUbRJ3CME@e129823.arm.com \
    --to=yeoreum.yun@arm.com \
    --cc=akpm@linux-oundation.org \
    --cc=ardb@kernel.org \
    --cc=bigeasy@linutronix.de \
    --cc=catalin.marinas@arm.com \
    --cc=chaitanyas.prakash@arm.com \
    --cc=clrkwllms@kernel.org \
    --cc=david@kernel.org \
    --cc=dev.jain@arm.com \
    --cc=jackmanb@google.com \
    --cc=kevin.brodsky@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=lorenzo.stoakes@oracle.com \
    --cc=mhocko@suse.com \
    --cc=quic_zhenhuah@quicinc.com \
    --cc=rostedt@goodmis.org \
    --cc=ryan.roberts@arm.com \
    --cc=vbabka@suse.cz \
    --cc=will@kernel.org \
    --cc=yang@os.amperecomputing.com \
    /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