From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4625EC624D5 for ; Wed, 2 Sep 2026 11:59:23 +0000 (UTC) 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:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yhitWwgNN4zHBIXHGzb+EEUftUB4qCv1vtxhFISj/iI=; b=0uLjUiDFrBXRT/ 1ASyJfzNnEOf6+9ZYyL2BS65bAOEH3MDHz6J4h0KRa1CTmdC4tsrCph/pvOeuCvaCVIZV+v+NvCey VbcgVJbuzHy8qJkG+/PGFpfDUX7yE/6ZPkAwiZBoTsgyweDr5PVKiopm0xu8QPZLLyhEHLftMuKWI u0otG230zgFDxQfu1drksQOt8CC7GK+v8HmP0UG+oU+rUmeQzTVBEWlseDGZWYIbbShDN7DnqUnZB r4AlrLn7D4LsWvwhSy6ott0nEH9TWeN6C6JVhoE5YqfOmD9SfpYTSiVt9AfJerTv2hRW00J35QULG Pa01ythL7I9OK/hNljVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1jcX-0000000EbPB-22jT; Wed, 02 Sep 2026 11:59:13 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1x1jcV-0000000EbN7-3iKa; Wed, 02 Sep 2026 11:59:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Cc:To:In-Reply-To:References: Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Sender:Reply-To:Content-ID:Content-Description; bh=9eB+ckADl6cNZSWU+azu196Av1opZMRhWv857WroVYg=; b=RFGzYBv9C4lhXR2IgREuA/Cmrn aPfQqBQY9enJGk5/Wm2bL6Gha2Uz0ESYTwgjjwxAKOt2xKqI2cj/nuhVcHw1+WNUToYSoBIFP+yT3 XbyxZQNWx+hhEDCzNJ6skTBZRP6FM4Sr8IXrPB00ite48Kzud4oluY9cB1BQy4h+1cAqDP/VkEoaG VfPuydNjYEw7l0H2Vnx2IuG7X0IlWMt5ohSAU4GsmnwThb/2IuJ7NHWU+1Zvp0oiSkgObSeGXwzcq YOmKTh3EfMfSZGFZYauwFfvbDLXRiZT92Cr+QETdZXww1/CHOyLiBVkC77+Ke9Qb1IVu7Eov/Nmnn d0M90mTA==; Received: from foss.arm.com ([217.140.110.172]) by desiato.infradead.org with esmtp (Exim 4.99.2 #2 (Red Hat Linux)) id 1x1jcS-0000000Bw26-354L; Wed, 02 Sep 2026 11:59:10 +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 CF2F91D70; Wed, 2 Sep 2026 04:59:02 -0700 (PDT) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 56F7C3F85F; Wed, 2 Sep 2026 04:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1788350346; bh=AfwOXSEHMTQsnG2+qWsR4+w3Q4/ql0WTR/iHlOKjwaI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=t99y+xgyLegCQNYEHLqIP1/4h51JZeASaITofkJ+uqtcnjVBOwDz220u8Kq+eRfGY GnRjjt56vNhz6+VrhW6JOdO6LVlc8nFY5XIeyl26nMP2KZU5TsZCORV8vVd72ygs9A 8XEICkOS9ziFjCyhFlw063vS0574g7wl2P4smJ3s= From: Yeoreum Yun Date: Wed, 02 Sep 2026 12:56:22 +0100 Subject: [PATCH RFC v3 20/21] mm/pgtable: disallow calling folded set_pgd/set_p4d/set_pud with dummy MIME-Version: 1.0 Message-Id: <20260902-dummy_ptxp3-v3-20-5d8f5b17c25c@arm.com> References: <20260902-dummy_ptxp3-v3-0-5d8f5b17c25c@arm.com> In-Reply-To: <20260902-dummy_ptxp3-v3-0-5d8f5b17c25c@arm.com> To: 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 , David Hildenbrand , 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 Cc: 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, Yeoreum Yun X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3417; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=9L1q4F5kPd3azF2pD0kiOqnAVRIpN920wuNvT7C/1AA=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqmA7rB7zMDTJiWjAJpFJrQOzF3ZWkpsd/OFNQX B7+gQ6qR7mJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCapgO6wAKCRBt1cPRWsUx M9ShDADCzv6zsjlAV5TzwCcUdqbNBXk1JjPzUyfDC+vb7W9bj2Ta2yGc/81HofWsmyx9kuhVsnT CXpHFei3Q2/ZYfQ6S0QwakGaA/NEjRDvU3LnV7JGb+UKNAXsACT02nLqR6NwNjP+aM1KBPp9rE1 qnmlv7mrg849enZixHGNAMVNSfzDIAX6eQV2HhbAnqfatjuB6QXfD+EqC1Pw2E+rKryr4Un2a0s SRK7v4I8nAxccfMBHnX6aKgX2Bm0T2wAPyUOQExlQ7M5MPOwPynM/E1NYUpVvCnoMlRqcGFM9vn G18AewtF84hchri946QSiUxbliKRd9DyKB01EJwtFrykJmwJShwtxsDXqR3oBAoywTjnosH/Pth 1U8tMzqBhyS/nHfubwvnGd9VWkmqfBnqY7S/VQ3q8stNtv32OfwTMVd1OYgtAjc0bCqO9HRycPf imeYM8+4OUhsTHXDwVrJjJUU6J0g7YqhDEBoNQmfCTF/QlvZdX1AF/BzeE6Nq6Z9Y66HU= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260902_125909_180954_A2ED3ED3 X-CRM114-Status: GOOD ( 14.01 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 d2dccf7542da..12b01768134b 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 2afbf2d8659d..11b04c107129 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 3264673c0c38..5ee8f1852cd8 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 }); \ +}) + static __always_inline p4d_t p4dp_get(p4d_t *p4dp) { -- 2.43.0 _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv