From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BCF7E340DB6 for ; Tue, 9 Sep 2025 13:52:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757425964; cv=none; b=ZNayNDkD/YjxZPxOxAbqNywR79UJ5J1O7O26JSyRkcI4ewPjQ1Rcmdln/burQgqwGodQnBqw2qPUHIX+VcwMMJhTM7i7r+/lG1XiGKumvefcb5rD43t19M3vxz+zMkLWfxTkWdLdnhSzfwsDrZgQPQexphv8UV1TkkoAJXmigEI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1757425964; c=relaxed/simple; bh=MF9pjSFELRIqBxogecJdZPXZ3eJWzyN9Bl5b+Obom1o=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=II/W5ijIVAnIZnbKnOBkoic0KbWa+KG9hKBwJsPHhs4m6a+xIoG01Iv3P28eOzodJQKJX9f/paE2i26NREkrOk5k/xVp/TAEPZhVfdL1Ih/M99dJvPsM587itm7L3dIazzxOsn+waNP594cHFiC2TX3s8qbhZRFxIcEPyGkUR0M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=0hI8MZoe; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="0hI8MZoe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A41EC4CEF4; Tue, 9 Sep 2025 13:52:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1757425964; bh=MF9pjSFELRIqBxogecJdZPXZ3eJWzyN9Bl5b+Obom1o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0hI8MZoe1N2GwdKXzN84pXIAUieUuZsKtWa18iK/BjJ68oD9dhzfZyrfeHpagV1ZE aPi7WSqM6XDActrXSw9JWKXTCpvODIiSbdHKnIdmVaWyGwnLhFeW6QW98dWA3CP6Mj PaxNT3LfWA0LDELxv5wPlpd9htZEcapQ6uWxQtbg= Date: Tue, 9 Sep 2025 15:52:35 +0200 From: Greg KH To: Harry Yoo Cc: stable@vger.kernel.org, Dave Hansen , Kiryl Shutsemau , Mike Rapoport , Lorenzo Stoakes , David Hildenbrand , Alexander Potapenko , Alistair Popple , Andrey Konovalov , Andrey Ryabinin , Andy Lutomirski , "Aneesh Kumar K . V" , Anshuman Khandual , Ard Biesheuvel , Arnd Bergmann , bibo mao , Borislav Betkov , Christoph Lameter , Dennis Zhou , Dev Jain , Dmitriy Vyukov , Gwan-gyeong Mun , Ingo Molnar , Jane Chu , Joao Martins , Joerg Roedel , John Hubbard , Kevin Brodsky , Liam Howlett , Michal Hocko , Oscar Salvador , Peter Xu , Peter Zijlstra , Qi Zheng , Ryan Roberts , Suren Baghdasaryan , Tejun Heo , Thomas Gleinxer , Thomas Huth , Uladzislau Rezki , Vincenzo Frascino , Vlastimil Babka , Pedro Falcato , Andrew Morton Subject: Re: [PATCH V2 6.12.y] mm: introduce and use {pgd,p4d}_populate_kernel() Message-ID: <2025090923-depth-rebuttal-925c@gregkh> References: <2025090602-bullwhip-runner-63fe@gregkh> <20250909055432.7584-1-harry.yoo@oracle.com> <2025090947-everglade-hassle-bcbc@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2025090947-everglade-hassle-bcbc@gregkh> On Tue, Sep 09, 2025 at 03:52:14PM +0200, Greg KH wrote: > 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 > > Acked-by: Kiryl Shutsemau > > Reviewed-by: Mike Rapoport (Microsoft) > > Reviewed-by: Lorenzo Stoakes > > Acked-by: David Hildenbrand > > Cc: Alexander Potapenko > > Cc: Alistair Popple > > Cc: Andrey Konovalov > > Cc: Andrey Ryabinin > > Cc: Andy Lutomirski > > Cc: Aneesh Kumar K.V > > Cc: Anshuman Khandual > > Cc: Ard Biesheuvel > > Cc: Arnd Bergmann > > Cc: bibo mao > > Cc: Borislav Betkov > > Cc: Christoph Lameter (Ampere) > > Cc: Dennis Zhou > > Cc: Dev Jain > > Cc: Dmitriy Vyukov > > Cc: Gwan-gyeong Mun > > Cc: Ingo Molnar > > Cc: Jane Chu > > Cc: Joao Martins > > Cc: Joerg Roedel > > Cc: John Hubbard > > Cc: Kevin Brodsky > > Cc: Liam Howlett > > Cc: Michal Hocko > > Cc: Oscar Salvador > > Cc: Peter Xu > > Cc: Peter Zijlstra > > Cc: Qi Zheng > > Cc: Ryan Roberts > > Cc: Suren Baghdasaryan > > Cc: Tejun Heo > > Cc: Thomas Gleinxer > > Cc: Thomas Huth > > Cc: Uladzislau Rezki (Sony) > > Cc: Vincenzo Frascino > > Cc: Vlastimil Babka > > Cc: Pedro Falcato > > Cc: stable@vger.kernel.org > > Signed-off-by: Andrew Morton > > [ Adjust context ] > > Signed-off-by: Harry Yoo > > --- > > 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? Same for the other backports, sorry I forgot to say that here.