From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43B4E606A320 for ; Tue, 1 Dec 2026 16:46:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=L71ZF0/h; dkim=fail reason="signature verification failed" (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=gfJeda/3 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=2Ozt47HulUJ/fhddGXFpYwZVjGnsGd00eHeiHWxy4jc=; b=L71ZF0/h6bi1Ezv1C/obf4ICM9 rEExwYGvSDWGEafFTDVdJIdbjPQduRVWZDSspFqfsT4R+6XQPhbt4TDVxSVJGOdMR/Iv38u7j23nu 790J5WY2UI+NPoEaLDyxAtkv/uULwKlqDkGMMpQjxl6PYJkADobWFwzimW0ZnbMM0cSdnagcN9XlG dAEk3OpZWDJNwNG/uZ0rnY3QppcxGCiQl3Oksm9cnHomVfXLw22+kMLn6aChSwvxusT4JqO2/Udxa pvnOGoK2fxv4s8bAEgb7Q7TxtZojEMhgGPBrjrZkUGOri4nSbP5DTWuzWxFhh1sAGxlwzFmBDPkHG CnnAu9CQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYQza-00000008lpu-2zLv; Tue, 01 Dec 2026 16:46:10 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYQzU-00000008lon-2fnO; Tue, 01 Dec 2026 16:46:07 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C5B321516; Tue, 1 Dec 2026 08:45:59 -0800 (PST) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 39A413F86F; Tue, 1 Dec 2026 08:45:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796143562; bh=n6+PkDwSVCu7YyikERYaE9c3qP7ftCUkfRLzNFOk9v4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gfJeda/3dQrB7nNOSSYaWMKsoeuWikVICPhncX6hZJjpz+J6zZ199MnEdUC3ECsUb nc5eW0XCDd+ZMzgNu4rfL8bvnn61Pfg1ZgoujW+WS5gpAHTP8mCkGnZZGRA73MjY4d OuydpMsUVQ4s2KGFBeDy6GO4F8T+TPEnMdjGIqD0= Date: Tue, 1 Dec 2026 16:45:52 +0000 From: Yeoreum Yun To: "David Hildenbrand (Arm)" Cc: Yeoreum Yun , Russell King , Huacai Chen , WANG Xuerui , Thomas Bogendoerfer , Catalin Marinas , Will Deacon , Arnd Bergmann , Andrew Morton , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , Johannes Weiner , Michal Hocko , Lorenzo Stoakes , Tianrui Zhao , Bibo Mao , Anup Patel , Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Jonas Bonn , Stefan Kristiansson , Stafford Horne , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-openrisc@vger.kernel.org Subject: Re: [PATCH v3 19/20] mm/pgtable: disallow calling folded set_pgd/set_p4d/set_pud with dummy Message-ID: References: <20261130-dummy_ptxp3-v3-0-456081a8ed0e@arm.com> <20261130-dummy_ptxp3-v3-19-456081a8ed0e@arm.com> <713213d4-12a6-4866-bd85-18b42443e640@kernel.org> X-Archived-By: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <713213d4-12a6-4866-bd85-18b42443e640@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_084605_262329_51E38A73 X-CRM114-Status: GOOD ( 23.50 ) X-Spam-Score: -4.4 (----) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Tue, Dec 01, 2026 at 01:17:54PM +0100, David Hildenbrand (Arm) wrote: > On 11/30/26 18:18, Yeoreum Yun wrote: > > From: "David Hildenbrand (Arm)" > > > > pXdp_get() could return a dummy value for a page-table level folded at > > compile time. Passing this value to set_pXd() could cause unexpected > > behavior. > > > > Prevent this at compile time by ensuring that all calls to > > set_pgd()/set_p4d()/set_pud() are compiled out for folded page-table > > levels. Make the compiler complain if these helpers are called with > > dummy values. > > > > Since there are places where set_pXd() is called even when > > the corresponding page-table level is folded at compile time, > > drop the incorrect comments for set_pXd(). > > > > Signed-off-by: David Hildenbrand (Arm) > > Co-developed-by: Yeoreum Yun > > Signed-off-by: Yeoreum Yun > > --- > > include/asm-generic/pgtable-nop4d.h | 11 ++++++----- > > include/asm-generic/pgtable-nopmd.h | 10 +++++----- > > include/asm-generic/pgtable-nopud.h | 12 +++++++----- > > 3 files changed, 18 insertions(+), 15 deletions(-) > > > > diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgtable-nop4d.h > > index d2dccf7542da5..12b01768134b5 100644 > > --- a/include/asm-generic/pgtable-nop4d.h > > +++ b/include/asm-generic/pgtable-nop4d.h > > @@ -28,11 +28,12 @@ static inline bool pgd_leaf(pgd_t pgd) { return false; } > > > > #define pgd_populate(mm, pgd, p4d) do { } while (0) > > #define pgd_populate_safe(mm, pgd, p4d) do { } while (0) > > -/* > > - * (p4ds are folded into pgds so this doesn't get actually called, > > - * but the define is needed for a generic inline function.) > > - */ > > -#define set_pgd(pgdptr, pgdval) set_p4d((p4d_t *)(pgdptr), (p4d_t) { pgdval }) > > + > > +#define set_pgd(pgdptr, pgdval) \ > > +({ \ > > + pgd_check_dummy(pgdval); \ > > + set_p4d((p4d_t *)(pgdptr), (p4d_t) { pgdval }); \ > > +}) > > > > static __always_inline pgd_t pgdp_get(pgd_t *pgdp) > > { > > diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h > > index 2afbf2d8659dc..11b04c1071295 100644 > > --- a/include/asm-generic/pgtable-nopmd.h > > +++ b/include/asm-generic/pgtable-nopmd.h > > @@ -37,11 +37,11 @@ static inline void pud_clear(pud_t *pud) { } > > > > #define pud_populate(mm, pmd, pte) do { } while (0) > > > > -/* > > - * (pmds are folded into puds so this doesn't get actually called, > > - * but the define is needed for a generic inline function.) > > - */ > > -#define set_pud(pudptr, pudval) set_pmd((pmd_t *)(pudptr), (pmd_t) { pudval }) > > +#define set_pud(pudptr, pudval) \ > > +({ \ > > + pud_check_dummy(pudval); \ > > + set_pmd((pmd_t *)(pudptr), (pmd_t) { pudval }); \ > > +}) > > > > static __always_inline pud_t pudp_get(pud_t *pudp) > > { > > diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h > > index 3264673c0c386..5ee8f1852cd8c 100644 > > --- a/include/asm-generic/pgtable-nopud.h > > +++ b/include/asm-generic/pgtable-nopud.h > > @@ -35,11 +35,13 @@ static inline bool p4d_leaf(p4d_t p4d) { return false; } > > > > #define p4d_populate(mm, p4d, pud) do { } while (0) > > #define p4d_populate_safe(mm, p4d, pud) do { } while (0) > > -/* > > - * (puds are folded into p4ds so this doesn't get actually called, > > - * but the define is needed for a generic inline function.) > > - */ > > -#define set_p4d(p4dptr, p4dval) set_pud((pud_t *)(p4dptr), (pud_t) { p4dval }) > > + > > +#define set_p4d(p4dptr, p4dval) \ > > +({ \ > > + p4d_check_dummy(p4dval); \ > > + set_pud((pud_t *)(p4dptr), (pud_t) { p4dval }); \ > > +}) > > + > > > > Extra empty line that can be dropped. Yes. I'll drop it. Thanks! -- Sincerely, Yeoreum Yun _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv