From: Yang Shi <yang@os.amperecomputing.com>
To: Ryan Roberts <ryan.roberts@arm.com>,
will@kernel.org, catalin.marinas@arm.com,
Miko.Lenczewski@arm.com, scott@os.amperecomputing.com,
cl@gentwo.org
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Dev Jain <dev.jain@arm.com>
Subject: Re: [v3 PATCH 0/6] arm64: support FEAT_BBM level 2 and large block mapping when rodata=full
Date: Thu, 29 May 2025 10:35:25 -0700 [thread overview]
Message-ID: <a1ff2646-f429-4626-8541-19c7f301fc23@os.amperecomputing.com> (raw)
In-Reply-To: <936cc91a-b345-4e52-9cb5-922c9810c469@arm.com>
On 5/29/25 8:33 AM, Ryan Roberts wrote:
> On 29/05/2025 09:48, Ryan Roberts wrote:
>
> [...]
>
>>>>> Regarding the linear map repainting, I had a chat with Catalin, and he reminded
>>>>> me of a potential problem; if you are doing the repainting with the machine
>>>>> stopped, you can't allocate memory at that point; it's possible a CPU was inside
>>>>> the allocator when it stopped. And I think you need to allocate intermediate
>>>>> pgtables, right? Do you have a solution to that problem? I guess one approach
>>>>> would be to figure out how much memory you will need and pre-allocate prior to
>>>>> stoping the machine?
>>>> OK, I don't remember we discussed this problem before. I think we can do
>>>> something like what kpti does. When creating the linear map we know how many
>>>> PUD and PMD mappings are created, we can record the number, it will tell how
>>>> many pages we need for repainting the linear map.
>>> Looking the kpti code further, it looks like kpti also allocates memory with the
>>> machine stopped, but it calls memory allocation on cpu 0 only.
>> Oh yes, I hadn't spotted that. It looks like a special case that may be ok for
>> kpti though; it's allocating a fairly small amount of memory (max levels=5 so
>> max order=3) and it's doing it with GFP_ATOMIC. So if my understanding of the
>> page allocator is correct, then this should be allocated from a per-cpu reserve?
>> Which means that it never needs to take a lock that other, stopped CPUs could be
>> holding. And GFP_ATOMIC guarrantees that the thread will never sleep, which I
>> think is not allowed while the machine is stopped.
The pcp should be set up by then, but I don't think it is actually
populated until the first allocation happens IIRC.
>>
>>> IIUC this
>>> guarantees the code will not be called on a CPU which was inside the allocator
>>> when it stopped because CPU 0 is running stop_machine().
>> My concern was a bit more general; if any other CPU was inside the allocator
>> holding a lock when the machine was stopped, then if CPU 0 comes along and makes
>> a call to the allocator that requires the lock, then we have a deadlock.
>>
>> All that said, looking at the stop_machine() docs, it says:
>>
>> * Description: This causes a thread to be scheduled on every cpu,
>> * each of which disables interrupts. The result is that no one is
>> * holding a spinlock or inside any other preempt-disabled region when
>> * @fn() runs.
>>
>> So I think my deadlock concern was unfounded. I think as long as you can
>> garrantee that fn() won't try to sleep then you should be safe? So I guess
>> allocating from within fn() should be safe as long as you use GFP_ATOMIC?
Yes, the deadlock should be not a concern.
The other comment also said:
* On each target cpu, @fn is run in a process context with the highest
priority
* preempting any task on the cpu and monopolizing it.
Since the fn is running in a process context, so sleep should be ok?
Sleep should just can happen when allocation requires memory reclaim due
to insufficient memory for kpti and repainting linear map usecases. But
I do agree GFP_ATOMIC is safer.
> I just had another conversation about this internally, and there is another
> concern; we obviously don't want to modify the pgtables while other CPUs that
> don't support BBML2 could be accessing them. Even in stop_machine() this may be
> possible if the CPU stacks and task structure (for example) are allocated out of
> the linear map.
>
> So we need to be careful to follow the pattern used by kpti; all secondary CPUs
> need to switch to the idmap (which is installed in TTBR0) then install the
> reserved map in TTBR1, then wait for CPU 0 to repaint the linear map, then have
> the secondary CPUs switch TTBR1 back to swapper then switch back out of idmap.
So the below code should be ok?
cpu_install_idmap()
Busy loop to wait for cpu 0 done
cpu_uninstall_idmap()
>
> Given CPU 0 supports BBML2, I think it can just update the linear map live,
> without needing to do the idmap dance?
Yes, I think so too.
Thanks,
Yang
>
> Thanks,
> Ryan
>
>
>> Thanks,
>> Ryan
>>
next prev parent reply other threads:[~2025-05-29 17:35 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-04 22:19 Yang Shi
2025-03-04 22:19 ` [v3 PATCH 1/6] arm64: Add BBM Level 2 cpu feature Yang Shi
2025-03-04 22:19 ` [v3 PATCH 2/6] arm64: cpufeature: add AmpereOne to BBML2 allow list Yang Shi
2025-03-14 10:58 ` Ryan Roberts
2025-03-17 17:50 ` Yang Shi
2025-03-04 22:19 ` [v3 PATCH 3/6] arm64: mm: make __create_pgd_mapping() and helpers non-void Yang Shi
2025-03-14 11:51 ` Ryan Roberts
2025-03-17 17:53 ` Yang Shi
2025-05-07 8:18 ` Ryan Roberts
2025-05-07 22:19 ` Yang Shi
2025-03-04 22:19 ` [v3 PATCH 4/6] arm64: mm: support large block mapping when rodata=full Yang Shi
2025-03-08 1:53 ` kernel test robot
2025-03-14 13:29 ` Ryan Roberts
2025-03-17 17:57 ` Yang Shi
2025-03-04 22:19 ` [v3 PATCH 5/6] arm64: mm: support split CONT mappings Yang Shi
2025-03-14 13:33 ` Ryan Roberts
2025-03-04 22:19 ` [v3 PATCH 6/6] arm64: mm: split linear mapping if BBML2 is not supported on secondary CPUs Yang Shi
2025-03-13 17:28 ` [v3 PATCH 0/6] arm64: support FEAT_BBM level 2 and large block mapping when rodata=full Yang Shi
2025-03-13 17:36 ` Ryan Roberts
2025-03-13 17:40 ` Yang Shi
2025-04-10 22:00 ` Yang Shi
2025-04-14 13:03 ` Ryan Roberts
2025-04-14 21:24 ` Yang Shi
2025-05-02 11:51 ` Ryan Roberts
2025-05-05 21:39 ` Yang Shi
2025-05-07 7:58 ` Ryan Roberts
2025-05-07 21:16 ` Yang Shi
2025-05-28 0:00 ` Yang Shi
2025-05-28 3:47 ` Dev Jain
2025-05-28 13:13 ` Ryan Roberts
2025-05-28 15:18 ` Yang Shi
2025-05-28 17:12 ` Yang Shi
2025-05-29 8:48 ` Ryan Roberts
2025-05-29 15:33 ` Ryan Roberts
2025-05-29 17:35 ` Yang Shi [this message]
2025-05-29 18:30 ` Ryan Roberts
2025-05-29 19:52 ` Yang Shi
2025-05-30 7:17 ` Ryan Roberts
2025-05-30 21:21 ` Yang Shi
2025-05-29 7:36 ` Ryan Roberts
2025-05-29 16:37 ` Yang Shi
2025-05-29 17:01 ` Ryan Roberts
2025-05-29 17:50 ` Yang Shi
2025-05-29 18:34 ` Ryan Roberts
2025-05-29 20:52 ` Yang Shi
2025-05-30 7:59 ` Ryan Roberts
2025-05-30 17:18 ` Yang Shi
2025-06-02 10:47 ` Ryan Roberts
2025-06-02 20:55 ` Yang Shi
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=a1ff2646-f429-4626-8541-19c7f301fc23@os.amperecomputing.com \
--to=yang@os.amperecomputing.com \
--cc=Miko.Lenczewski@arm.com \
--cc=catalin.marinas@arm.com \
--cc=cl@gentwo.org \
--cc=dev.jain@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ryan.roberts@arm.com \
--cc=scott@os.amperecomputing.com \
--cc=will@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®