From: Greg KH <gregkh@linuxfoundation.org>
To: Harry Yoo <harry.yoo@oracle.com>
Cc: stable@vger.kernel.org, Dave Hansen <dave.hansen@linux.intel.com>,
Kiryl Shutsemau <kas@kernel.org>, Mike Rapoport <rppt@kernel.org>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
David Hildenbrand <david@redhat.com>,
Alexander Potapenko <glider@google.com>,
Alistair Popple <apopple@nvidia.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Andrey Ryabinin <ryabinin.a.a@gmail.com>,
Andy Lutomirski <luto@kernel.org>,
"Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
Anshuman Khandual <anshuman.khandual@arm.com>,
Ard Biesheuvel <ardb@kernel.org>, Arnd Bergmann <arnd@arndb.de>,
bibo mao <maobibo@loongson.cn>, Borislav Betkov <bp@alien8.de>,
Christoph Lameter <cl@gentwo.org>,
Dennis Zhou <dennis@kernel.org>, Dev Jain <dev.jain@arm.com>,
Dmitriy Vyukov <dvyukov@google.com>,
Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>,
Ingo Molnar <mingo@redhat.com>, Jane Chu <jane.chu@oracle.com>,
Joao Martins <joao.m.martins@oracle.com>,
Joerg Roedel <joro@8bytes.org>,
John Hubbard <jhubbard@nvidia.com>,
Kevin Brodsky <kevin.brodsky@arm.com>,
Liam Howlett <liam.howlett@oracle.com>,
Michal Hocko <mhocko@suse.com>,
Oscar Salvador <osalvador@suse.de>, Peter Xu <peterx@redhat.com>,
Peter Zijlstra <peterz@infradead.org>,
Qi Zheng <zhengqi.arch@bytedance.com>,
Ryan Roberts <ryan.roberts@arm.com>,
Suren Baghdasaryan <surenb@google.com>, Tejun Heo <tj@kernel.org>,
Thomas Gleinxer <tglx@linutronix.de>,
Thomas Huth <thuth@redhat.com>,
Uladzislau Rezki <urezki@gmail.com>,
Vincenzo Frascino <vincenzo.frascino@arm.com>,
Vlastimil Babka <vbabka@suse.cz>,
Pedro Falcato <pfalcato@suse.de>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH V2 6.12.y] mm: introduce and use {pgd,p4d}_populate_kernel()
Date: Tue, 9 Sep 2025 15:52:14 +0200 [thread overview]
Message-ID: <2025090947-everglade-hassle-bcbc@gregkh> (raw)
In-Reply-To: <20250909055432.7584-1-harry.yoo@oracle.com>
On Tue, Sep 09, 2025 at 02:54:32PM +0900, Harry Yoo wrote:
> Introduce and use {pgd,p4d}_populate_kernel() in core MM code when
> populating PGD and P4D entries for the kernel address space. These
> helpers ensure proper synchronization of page tables when updating the
> kernel portion of top-level page tables.
>
> Until now, the kernel has relied on each architecture to handle
> synchronization of top-level page tables in an ad-hoc manner. For
> example, see commit 9b861528a801 ("x86-64, mem: Update all PGDs for direct
> mapping and vmemmap mapping changes").
>
> However, this approach has proven fragile for following reasons:
>
> 1) It is easy to forget to perform the necessary page table
> synchronization when introducing new changes.
> For instance, commit 4917f55b4ef9 ("mm/sparse-vmemmap: improve memory
> savings for compound devmaps") overlooked the need to synchronize
> page tables for the vmemmap area.
>
> 2) It is also easy to overlook that the vmemmap and direct mapping areas
> must not be accessed before explicit page table synchronization.
> For example, commit 8d400913c231 ("x86/vmemmap: handle unpopulated
> sub-pmd ranges")) caused crashes by accessing the vmemmap area
> before calling sync_global_pgds().
>
> To address this, as suggested by Dave Hansen, introduce _kernel() variants
> of the page table population helpers, which invoke architecture-specific
> hooks to properly synchronize page tables. These are introduced in a new
> header file, include/linux/pgalloc.h, so they can be called from common
> code.
>
> They reuse existing infrastructure for vmalloc and ioremap.
> Synchronization requirements are determined by ARCH_PAGE_TABLE_SYNC_MASK,
> and the actual synchronization is performed by
> arch_sync_kernel_mappings().
>
> This change currently targets only x86_64, so only PGD and P4D level
> helpers are introduced. Currently, these helpers are no-ops since no
> architecture sets PGTBL_{PGD,P4D}_MODIFIED in ARCH_PAGE_TABLE_SYNC_MASK.
>
> In theory, PUD and PMD level helpers can be added later if needed by other
> architectures. For now, 32-bit architectures (x86-32 and arm) only handle
> PGTBL_PMD_MODIFIED, so p*d_populate_kernel() will never affect them unless
> we introduce a PMD level helper.
>
> [harry.yoo@oracle.com: fix KASAN build error due to p*d_populate_kernel()]
> Link: https://lkml.kernel.org/r/20250822020727.202749-1-harry.yoo@oracle.com
> Link: https://lkml.kernel.org/r/20250818020206.4517-3-harry.yoo@oracle.com
> Fixes: 8d400913c231 ("x86/vmemmap: handle unpopulated sub-pmd ranges")
> Suggested-by: Dave Hansen <dave.hansen@linux.intel.com>
> Acked-by: Kiryl Shutsemau <kas@kernel.org>
> Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> Acked-by: David Hildenbrand <david@redhat.com>
> Cc: Alexander Potapenko <glider@google.com>
> Cc: Alistair Popple <apopple@nvidia.com>
> Cc: Andrey Konovalov <andreyknvl@gmail.com>
> Cc: Andrey Ryabinin <ryabinin.a.a@gmail.com>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Aneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
> Cc: Anshuman Khandual <anshuman.khandual@arm.com>
> Cc: Ard Biesheuvel <ardb@kernel.org>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: bibo mao <maobibo@loongson.cn>
> Cc: Borislav Betkov <bp@alien8.de>
> Cc: Christoph Lameter (Ampere) <cl@gentwo.org>
> Cc: Dennis Zhou <dennis@kernel.org>
> Cc: Dev Jain <dev.jain@arm.com>
> Cc: Dmitriy Vyukov <dvyukov@google.com>
> Cc: Gwan-gyeong Mun <gwan-gyeong.mun@intel.com>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Jane Chu <jane.chu@oracle.com>
> Cc: Joao Martins <joao.m.martins@oracle.com>
> Cc: Joerg Roedel <joro@8bytes.org>
> Cc: John Hubbard <jhubbard@nvidia.com>
> Cc: Kevin Brodsky <kevin.brodsky@arm.com>
> Cc: Liam Howlett <liam.howlett@oracle.com>
> Cc: Michal Hocko <mhocko@suse.com>
> Cc: Oscar Salvador <osalvador@suse.de>
> Cc: Peter Xu <peterx@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Qi Zheng <zhengqi.arch@bytedance.com>
> Cc: Ryan Roberts <ryan.roberts@arm.com>
> Cc: Suren Baghdasaryan <surenb@google.com>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Thomas Gleinxer <tglx@linutronix.de>
> Cc: Thomas Huth <thuth@redhat.com>
> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com>
> Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
> Cc: Vlastimil Babka <vbabka@suse.cz>
> Cc: Pedro Falcato <pfalcato@suse.de>
> Cc: stable@vger.kernel.org
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> [ Adjust context ]
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
> ---
> include/linux/pgalloc.h | 29 +++++++++++++++++++++++++++++
> include/linux/pgtable.h | 13 +++++++------
> mm/kasan/init.c | 12 ++++++------
> mm/percpu.c | 6 +++---
> mm/sparse-vmemmap.c | 6 +++---
> 5 files changed, 48 insertions(+), 18 deletions(-)
> create mode 100644 include/linux/pgalloc.h
Can you resend these with the upstream git id from Linus's tree in it,
so we know how to compare it with the original?
thanks,
greg k-h
next prev parent reply other threads:[~2025-09-09 13:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-06 18:41 FAILED: patch "[PATCH] mm: introduce and use {pgd,p4d}_populate_kernel()" failed to apply to 6.12-stable tree gregkh
2025-09-08 1:09 ` [PATCH 6.12.y] mm: introduce and use {pgd,p4d}_populate_kernel() Harry Yoo
2025-09-08 12:39 ` Harry Yoo
2025-09-09 13:50 ` Greg KH
2025-09-09 13:51 ` Greg KH
2025-09-09 5:54 ` [PATCH V2 " Harry Yoo
2025-09-09 13:52 ` Greg KH [this message]
2025-09-09 13:52 ` Greg KH
2025-09-09 13:58 ` Harry Yoo
2025-09-09 14:15 ` [PATCH V3 " Harry Yoo
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=2025090947-everglade-hassle-bcbc@gregkh \
--to=gregkh@linuxfoundation.org \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=aneesh.kumar@linux.ibm.com \
--cc=anshuman.khandual@arm.com \
--cc=apopple@nvidia.com \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=bp@alien8.de \
--cc=cl@gentwo.org \
--cc=dave.hansen@linux.intel.com \
--cc=david@redhat.com \
--cc=dennis@kernel.org \
--cc=dev.jain@arm.com \
--cc=dvyukov@google.com \
--cc=glider@google.com \
--cc=gwan-gyeong.mun@intel.com \
--cc=harry.yoo@oracle.com \
--cc=jane.chu@oracle.com \
--cc=jhubbard@nvidia.com \
--cc=joao.m.martins@oracle.com \
--cc=joro@8bytes.org \
--cc=kas@kernel.org \
--cc=kevin.brodsky@arm.com \
--cc=liam.howlett@oracle.com \
--cc=lorenzo.stoakes@oracle.com \
--cc=luto@kernel.org \
--cc=maobibo@loongson.cn \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=peterz@infradead.org \
--cc=pfalcato@suse.de \
--cc=rppt@kernel.org \
--cc=ryabinin.a.a@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=stable@vger.kernel.org \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=thuth@redhat.com \
--cc=tj@kernel.org \
--cc=urezki@gmail.com \
--cc=vbabka@suse.cz \
--cc=vincenzo.frascino@arm.com \
--cc=zhengqi.arch@bytedance.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