From: Marc Zyngier <maz@kernel.org>
To: Sam Edwards <cfsworks@gmail.com>
Cc: Ard Biesheuvel <ardb@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Ryan Roberts <ryan.roberts@arm.com>,
Baruch Siach <baruch@tkos.co.il>,
Kevin Brodsky <kevin.brodsky@arm.com>,
Joey Gouly <joey.gouly@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH] arm64/boot: Zero-initialize idmap PGDs before use
Date: Sun, 24 Aug 2025 09:55:34 +0100 [thread overview]
Message-ID: <874itx14l5.wl-maz@kernel.org> (raw)
In-Reply-To: <CAH5Ym4h+2w6aayzsVu__3qu3-6ETq1HK7u18yGzOrRqZ--2H9w@mail.gmail.com>
Hi Sam,
On Sun, 24 Aug 2025 04:05:05 +0100,
Sam Edwards <cfsworks@gmail.com> wrote:
>
> On Sat, Aug 23, 2025 at 5:29 PM Ard Biesheuvel <ardb@kernel.org> wrote:
> >
[...]
> > Under which conditions would PGD_SIZE assume a value greater than PAGE_SIZE?
>
> I might be doing my math wrong, but wouldn't 52-bit VA with 4K
> granules and 5 levels result in this?
No. 52bit VA at 4kB granule results in levels 0-3 each resolving 9
bits, and level -1 resolving 4 bits. That's a total of 40 bits, plus
the 12 bits coming directly from the VA making for the expected 52.
> Each PTE represents 4K of virtual memory, so covers VA bits [11:0]
> (this is level 3)
That's where you got it wrong. The architecture is pretty clear that
each level resolves PAGE_SHIFT-3 bits, hence the computation
above. The bottom PAGE_SHIFT bits are directly extracted from the VA,
without any translation.
> Each PMD has 512 PTEs, the index of which covers VA bits [20:12] (this
> is level 2)
> Each PUD references 512 PMDs, the index covering VA [29:21] (this is level 1)
> Each P4D references 512 PUDs, indexed by VA [38:30] (this is level 0)
> The PGD, at level -1, therefore has to cover VA bits [51:39], which
> means it has a 13-bit index: 8192 entries of 8 bytes each would make
> it 16 pages in size.
>
> > Note that at stage 1, arm64 does not support page table concatenation,
> > and so the root page table is never larger than a page.
>
> Doesn't PGD_SIZE refer to the size used for userspace PGDs after the
> boot progresses beyond stage 1? (What do you mean by "never" here?
> "Under no circumstances is it larger than a page at stage 1"? Or
> "during the entire lifecycle of the system, there is no time at which
> it's larger than a page"?)
Never, ever, is a S1 table bigger than a page. This concept doesn't
exist in the architecture. Only S2 tables can use concatenation at the
top-most level, for up to 16 pages (in order to skip a level when
possible).
The top-level can be smaller than a page, with some alignment
constraints, but that's about the only degree of freedom you have for
S1 page tables.
Thanks,
M.
--
Jazz isn't dead. It just smells funny.
next prev parent reply other threads:[~2025-08-24 8:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-22 4:15 [PATCH] arm64/boot: Zero-initialize idmap PGDs before use Sam Edwards
2025-08-23 22:25 ` Ard Biesheuvel
2025-08-23 23:55 ` Sam Edwards
2025-08-24 0:29 ` Ard Biesheuvel
2025-08-24 3:05 ` Sam Edwards
2025-08-24 8:55 ` Marc Zyngier [this message]
2025-08-24 23:43 ` Sam Edwards
2025-08-25 9:12 ` Marc Zyngier
2025-08-25 23:26 ` Sam Edwards
2025-08-26 9:50 ` Mark Rutland
2025-08-26 10:18 ` Ard Biesheuvel
2025-08-26 19:33 ` Sam Edwards
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=874itx14l5.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=anshuman.khandual@arm.com \
--cc=ardb@kernel.org \
--cc=baruch@tkos.co.il \
--cc=catalin.marinas@arm.com \
--cc=cfsworks@gmail.com \
--cc=joey.gouly@arm.com \
--cc=kevin.brodsky@arm.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--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