From: "David Hildenbrand (Arm)" <david@kernel.org>
To: Arnd Bergmann <arnd@arndb.de>, Yeoreum Yun <yeoreum.yun@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, loongarch@lists.linux.dev,
linux-mips@vger.kernel.org,
Linux-Arch <linux-arch@vger.kernel.org>,
kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org,
x86@kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com,
"linux-csky@vger.kernel.org" <linux-csky@vger.kernel.org>,
linux-m68k@lists.linux-m68k.org,
"linux-openrisc@vger.kernel.org" <linux-openrisc@vger.kernel.org>
Cc: Russell King <linux@armlinux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Ankur Arora <ankur.a.arora@oracle.com>,
Mike Rapoport <rppt@kernel.org>,
Magnus Lindholm <linmag7@gmail.com>,
Christophe Leroy <chleroy@kernel.org>,
Klara Modin <klarasmodin@gmail.com>,
Huacai Chen <chenhuacai@kernel.org>,
WANG Xuerui <kernel@xen0n.name>,
"Kirill A. Shutemov" <kas@kernel.org>,
zhangtianyang@loongson.cn, wangyuli@aosc.io,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Lorenzo Stoakes <ljs@kernel.org>, Jason Gunthorpe <jgg@ziepe.ca>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Ryan Roberts <ryan.roberts@arm.com>,
Pasha Tatashin <pasha.tatashin@soleen.com>,
Rohan McLure <rmclure@linux.ibm.com>,
Baolin Wang <baolin.wang@linux.alibaba.com>,
Tejun Heo <tj@kernel.org>, Kevin Brodsky <kevin.brodsky@arm.com>,
Anup Patel <anup@brainfault.org>,
atish.patra@linux.dev, Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>, "H. Peter Anvin" <hpa@zytor.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
qi.zheng@linux.dev, Shakeel Butt <shakeel.butt@linux.dev>,
Kairui Song <kasong@tencent.com>, Barry Song <baohua@kernel.org>,
Axel Rasmussen <axelrasmussen@google.com>,
Yuanchu Xie <yuanchu@google.com>, Wei Xu <weixugc@google.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Alexander Potapenko <glider@google.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Yang Shi <yang@os.amperecomputing.com>,
chaitanyas.prakash@arm.com, Ard Biesheuvel <ardb@kernel.org>,
guoren <guoren@kernel.org>,
yang.li85200@gmail.com, Alexander Viro <viro@zeniv.linux.org.uk>,
Dinh Nguyen <dinguyen@kernel.org>,
"schuster.simon@siemens-energy.com"
<schuster.simon@siemens-energy.com>,
Vivian Wang <wangruikang@iscas.ac.cn>,
junhui.liu@pigmoral.tech, Muchun Song <muchun.song@linux.dev>,
"Vishal Moola (Oracle)" <vishal.moola@gmail.com>,
Nam Cao <namcao@linutronix.de>, Pavel Machek <pavel@kernel.org>,
djbw@kernel.org, yu-cheng.yu@intel.com,
Baolu Lu <baolu.lu@linux.intel.com>,
Jonathan Cameron <Jonathan.Cameron@huawei.com>,
Coiby Xu <coxu@redhat.com>, Andreas Larsson <andreas@gaisler.com>,
"Liam R. Howlett" <liam@infradead.org>,
"Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Stafford Horne <shorne@gmail.com>,
Jonas Bonn <jonas@southpole.se>,
Stefan Kristiansson <stefan.kristiansson@saunalahti.fi>
Subject: Re: [RFC PATCH 02/34] ARM: mm: make 2-level pgd_t a scalar
Date: Mon, 13 Jul 2026 18:04:54 +0200 [thread overview]
Message-ID: <2858abeb-4134-4768-9a35-a569d5c86e10@kernel.org> (raw)
In-Reply-To: <d57f5b18-583d-4848-9d74-65b15c93dcf8@app.fastmail.com>
On 7/13/26 17:38, Arnd Bergmann wrote:
> On Mon, Jul 13, 2026, at 15:55, Yeoreum Yun wrote:
>> From: "David Hildenbrand (Arm)" <david@kernel.org>
>>
>> We don't want pgd_t to be an array, as it prohibits returning it from a
>> function, like pgdp_get().
>
> What should pgdp_get() return on ARM 2-stage page tables then?
> Does it return just the first entry or concatenate the two?
It is rather obscure what we do (below).
This patch tries to keep the existing behavior.
>
>> +typedef u64 pgdval_t;
>
>> +static inline pmdval_t pgd_val(pgd_t pgd)
>> +{
>> + return (*(pmdval_t (*)[2])&pgd)[0];
>> +}
>
> This could use a comment to explain what this actually
> returns and why the second entry is discarded.
It's rather crazy. We have two page table levels, but fake that we have 3.
There is some documentation in arch/arm/include/asm/pgtable-2level.h
/*
* Hardware-wise, we have a two level page table structure, where the first
* level has 4096 entries, and the second level has 256 entries. Each entry
* is one 32-bit word. Most of the bits in the second level entry are used
* by hardware, and there aren't any "accessed" and "dirty" bits.
*
* Linux on the other hand has a three level page table structure, which can
* be wrapped to fit a two level page table structure easily - using the PGD
* and PTE only. However, Linux also expects one "PTE" table per page, and
* at least a "dirty" bit.
*
* Therefore, we tweak the implementation slightly - we tell Linux that we
* have 2048 entries in the first level, each of which is 8 bytes (iow, two
* hardware pointers to the second level.) The second level contains two
* hardware PTE tables arranged contiguously, preceded by Linux versions
* which contain the state information Linux needs. We, therefore, end up
* with 512 entries in the "PTE" level.
*
* This leads to the page tables having the following layout:
*
* pgd pte
* | |
* +--------+
* | | +------------+ +0
* +- - - - + | Linux pt 0 |
* | | +------------+ +1024
* +--------+ +0 | Linux pt 1 |
* | |-----> +------------+ +2048
* +- - - - + +4 | h/w pt 0 |
* | |-----> +------------+ +3072
* +--------+ +8 | h/w pt 1 |
* | | +------------+ +4096
*
So we interpret two 32bit entries as a pair (64bit value). Together they span
2x256 values.
Then we make PTRS_PER_PTE = 512, to iterate all of them (both pairs).
Let me do some more digging to come up with something I can confidentially
document here ... maybe I'll just refer to the comment in pgtable-2level.h.
--
Cheers,
David
next prev parent reply other threads:[~2026-07-13 16:05 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-13 13:55 [RFC PATCH 00/34] mm: optimize unnecessary loads due to ptep_get() and friends out Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 01/34] ARM: mm: make nommu pgd_t a scalar Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 02/34] ARM: mm: make 2-level " Yeoreum Yun
2026-07-13 15:38 ` Arnd Bergmann
2026-07-13 16:04 ` David Hildenbrand (Arm) [this message]
2026-07-13 16:26 ` David Hildenbrand (Arm)
2026-07-14 10:26 ` Pedro Falcato
2026-07-14 10:54 ` David Hildenbrand (Arm)
2026-07-14 11:55 ` Arnd Bergmann
2026-07-14 13:34 ` David Laight
2026-07-14 15:06 ` Arnd Bergmann
2026-07-14 12:34 ` David Laight
2026-07-14 13:03 ` David Hildenbrand (Arm)
2026-07-13 13:55 ` [RFC PATCH 03/34] ARM: mm: remove custom pgdp_get() Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 04/34] LoongArch: mm: define pud_leaf() only when PUD exists Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 05/34] MIPS: " Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 06/34] mm/pgtable: define (pgd|p4d|pud)_leaf() for folded page tables Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 07/34] mm/pgtable: define (pgd|p4d|pud)_offset_lockless() " Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 08/34] loongarch: kvm: remove stack copy address of pXd in pXd_offset() Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 09/34] riscv: " Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 10/34] x86: mm: carve out the generic compile-time folded pgtable case in effective_prot() Yeoreum Yun
2026-07-13 14:19 ` Dave Hansen
2026-07-13 14:41 ` David Hildenbrand (Arm)
2026-07-13 14:55 ` Dave Hansen
2026-07-13 15:02 ` David Hildenbrand (Arm)
2026-07-13 17:57 ` Dave Hansen
2026-07-13 19:49 ` David Hildenbrand (Arm)
2026-07-13 20:27 ` Dave Hansen
2026-07-13 21:17 ` David Hildenbrand (Arm)
2026-07-13 21:40 ` Dave Hansen
2026-07-14 10:50 ` David Hildenbrand (Arm)
2026-07-14 11:40 ` Yeoreum Yun
2026-07-14 14:35 ` Dave Hansen
2026-07-13 14:48 ` Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 11/34] mm: vmscan: remove stack copy address of pud pass in wallk_pud_range() Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 12/34] arm64: mm: use proper set_pXd() for generic compile-time folded patable in kasan_early_init() Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 13/34] arm64: mm: define pud_set_huge() when __PGTABLE_PMD_FOLDED not defined Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 14/34] csky: mm: use proper set_pXd() for generic compile-time folded patable in vmalloc_fault() Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 15/34] mips: mm: use proper set_pXd() for generic compile-time folded patable in vmalloc_fault path Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 16/34] nios2: " Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 17/34] riscv: mm: use proper set_pXd() for generic compile-time folded patable in vmalloc_fault() Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 18/34] riscv: mm: use proper set_pXd() for generic compile-time folded patable in setup_vm_final() Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 19/34] x86: power: use proper set_pXd() for generic compile-time folded patable in resume_one_md_table_init() Yeoreum Yun
2026-07-13 14:38 ` Dave Hansen
2026-07-13 14:59 ` David Hildenbrand (Arm)
2026-07-13 15:01 ` Yeoreum Yun
2026-07-13 13:55 ` [RFC PATCH 20/34] x86: kexec: use proper set_pXd() for generic compile-time folded patable in machine_kexec_page_table_set_one() Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 21/34] x86: platform: use proper set_pXd() for generic compile-time folded patable in setup_olpc_ofw_pgd() Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 22/34] x86: mm: use proper set_pXd() for generic compile-time folded patable in one_md_table_init() Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 23/34] x86: mm: skip pud setup when using generic compile-time folded pagetable Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 24/34] x86: mm: call try_to_free_pmd_page() when CONFIG_PGTABLE_LEVELS > 2 Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 25/34] x86: mm: remove usage of pgd_page_vaddr() for CONFIG_x86_PAE Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 26/34] x86: mm: define pudp_set_access_flags() when CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD is enabled only Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 27/34] m68k: mm: remove usage of pgd_page_vaddr() for CONFIG_PGTABLE_LEVELS=3 Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 28/34] arm: mm: use proper pgtable APIs for generic compile-time folded patable in kasan_init() Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 29/34] mm/pgtable: disallow calling folded set_pgd/set_p4d/set_pud Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 30/34] mm/pgtable: disallow calling folded (pgd|p4d|pud)_page, pgd_page_vaddr() and (p4d|pud)_pgtable Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 31/34] mm/pgtable: optimize pmdp_get() and friends for folded pagetable levels Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 32/34] openrisc/pgtable: drop __pmd_offset() Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 33/34] mm/pgtable: catch abuse of folded dummy pgd_t/p4d_t/pud_t Yeoreum Yun
2026-07-13 13:56 ` [RFC PATCH 34/34] arm64: pgtable: convert pte_present() from macro to static inline Yeoreum Yun
2026-07-13 14:08 ` [RFC PATCH 00/34] mm: optimize unnecessary loads due to ptep_get() and friends out David Hildenbrand (Arm)
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=2858abeb-4134-4768-9a35-a569d5c86e10@kernel.org \
--to=david@kernel.org \
--cc=Jonathan.Cameron@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=alex@ghiti.fr \
--cc=andreas@gaisler.com \
--cc=andreyknvl@gmail.com \
--cc=ankur.a.arora@oracle.com \
--cc=anshuman.khandual@arm.com \
--cc=anup@brainfault.org \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=atish.patra@linux.dev \
--cc=axelrasmussen@google.com \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=baolu.lu@linux.intel.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=chaitanyas.prakash@arm.com \
--cc=chenhuacai@kernel.org \
--cc=chleroy@kernel.org \
--cc=coxu@redhat.com \
--cc=dave.hansen@linux.intel.com \
--cc=dinguyen@kernel.org \
--cc=djbw@kernel.org \
--cc=dvyukov@google.com \
--cc=geert@linux-m68k.org \
--cc=glider@google.com \
--cc=guoren@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=hpa@zytor.com \
--cc=jgg@ziepe.ca \
--cc=jonas@southpole.se \
--cc=junhui.liu@pigmoral.tech \
--cc=kas@kernel.org \
--cc=kasan-dev@googlegroups.com \
--cc=kasong@tencent.com \
--cc=kernel@xen0n.name \
--cc=kevin.brodsky@arm.com \
--cc=klarasmodin@gmail.com \
--cc=kvm-riscv@lists.infradead.org \
--cc=liam@infradead.org \
--cc=linmag7@gmail.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-csky@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-openrisc@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=ljs@kernel.org \
--cc=loongarch@lists.linux.dev \
--cc=luto@kernel.org \
--cc=mhocko@kernel.org \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=muchun.song@linux.dev \
--cc=namcao@linutronix.de \
--cc=palmer@dabbelt.com \
--cc=pasha.tatashin@soleen.com \
--cc=pavel@kernel.org \
--cc=peterz@infradead.org \
--cc=pjw@kernel.org \
--cc=qi.zheng@linux.dev \
--cc=rmclure@linux.ibm.com \
--cc=rppt@kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=schuster.simon@siemens-energy.com \
--cc=shakeel.butt@linux.dev \
--cc=shorne@gmail.com \
--cc=stefan.kristiansson@saunalahti.fi \
--cc=surenb@google.com \
--cc=tglx@kernel.org \
--cc=tj@kernel.org \
--cc=tsbogend@alpha.franken.de \
--cc=vbabka@kernel.org \
--cc=vincenzo.frascino@arm.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vishal.moola@gmail.com \
--cc=wangruikang@iscas.ac.cn \
--cc=wangyuli@aosc.io \
--cc=weixugc@google.com \
--cc=will@kernel.org \
--cc=x86@kernel.org \
--cc=yang.li85200@gmail.com \
--cc=yang@os.amperecomputing.com \
--cc=yeoreum.yun@arm.com \
--cc=yu-cheng.yu@intel.com \
--cc=yuanchu@google.com \
--cc=zhangtianyang@loongson.cn \
/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