From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796144971; b=sHA9qTAzbZ+iBF8oEiXAqHOjeV0YjvvbLd5PpLlpK2Z9SiIa4EX1WNRkusLMNgeNgBe+ rRclEzBQpuXC0GogqT04mLOFeqjWebc5amSz1LXKU5VUriMTg7z+dIzInKbQ66KnFwhQY PwUfY9EuvAkxtIT747WZQukrPqhrsekanux2KA/7myo7gUvpgvMU2pBJLsbXAgh2WLMFg a0ES8F5+8b19QWxFunUyGkLDFQ07qh07ZqCrTQoKrDfSCGyXzw9WgMNu3IpeYAGzX77rM I6ow8jGt+pa4T40Ax+YQnWzQeC3y8ZG+1uG1k18ayr2OdMKpvo0oTyg79mRwy7Q53VA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796144971; h=DMARC-Filter:Received:Received:DKIM-Signature:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=D3cdYqMOy5gSGW+C+sJhiaOyugjNBtyTl/Ge+hnxSNM=; b=jQ8QQiNiGJumDyvG2hJu5I4toVufaUcGy8zjn1ZARq428cFfyV3PAkKDt5jOdnaUJI9C +Em0htWhDFfmcaphKLEWXj47HxcuQ26gU3MW1l97oXlRNoVVLQWYt5ZtfTf5VTaUX2NsW risEy20nM30tF3OI35tdsH5ZcpezPjbq+oyk55Nx+thrZnXi0ZhmVcUsCJJK1fl6dx9D9 Q2djgLvN5Lq8OmDh00P/CYKU23D+qg3FqlTgSQTR9Af5OcD8L7X3qb7X2fceKwZalwOrX pLfWuKjcr61dyvLub/qo66kxjVSZ28WKM3vnlTuX3NYDL+eIpgLM6l4cNN7W8xoue3w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=k2Ot72mT; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F51E606A31A; Tue, 1 Dec 2026 17:09:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7F51E606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=k2Ot72mT 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 4D5971BC0; Tue, 1 Dec 2026 09:09:27 -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 A7ED33F7D8; Tue, 1 Dec 2026 09:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796144970; bh=R9bRCD5m/3D38nug2fd2gxDlO7ATHYUeIQKzY8uKVrE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=k2Ot72mTm5zL7584sJFxIyIOPO9hFiNEteeg4ObG9vRknzWmbvt/yO9P6BE9AHH/i XNht/2nhpf4UJmDUI6nej4jp3xUV5roE2m9eEI7HIoSnbKNN8VloCgL4gpy2A0kjLp NKh4aWG5BMve+9/dqi9x7z7FNwVX+TPRD3Ob2KMA= From: Yeoreum Yun Date: Tue, 01 Dec 2026 17:07:21 +0000 Subject: [PATCH v4 19/20] mm/pgtable: disallow calling folded set_pgd/set_p4d/set_pud with dummy X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261201-dummy_ptxp3-v4-19-9dec1da6a49a@arm.com> References: <20261201-dummy_ptxp3-v4-0-9dec1da6a49a@arm.com> In-Reply-To: <20261201-dummy_ptxp3-v4-0-9dec1da6a49a@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 , Muhammad Usama Anjum X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3491; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=gy+Ej7FtQpsh1KLyz6rA9EUVpynWMS+QLtgnLzOGdd4=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBrDv7DIXQmDyuI9CDEGpDd6fPTNjfgS2QQ8KRP9 p841mpoqPWJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCaw7+wwAKCRBt1cPRWsUx MyFgC/0f3MFT7yyakcYs684xfm8JvOY6YoTe0GjEIFACXSAOI7aZvwy29pg4qq4oRzOTyEtbQAK /VPTHYq3VboVIREcIL16t8zMO87dhocgXDLZZEyoG8ClyVwc2t3ip0bpMagKHceGbRXBp6Mk9E+ ijKGVMqlMuUkD4N+JliWSuqRbgvpUzDveG0yjb95JKC3xg4huYBcsSGiZ+60p6TvwmmNfte0AWJ juTk8T0lKItUAnI2wrnXoRuwRDnr6ZwHA+HYbO3ZhwhGWBUq+fqQZxRk7alLi1opEZBMmcwaZNF u2q3xlfqQncKkxBZzAeYZB0d2oVXWXcTtd5t1qeDIpgpekLNuy8pLzoNuvEqVgPxjybMZY5z6l2 74lEbHr4trrprow9ILiX3F2L/J0zSJMEUTw1+tK70zOe4rJ/hAZB5rd9GZ61auCl9ies/XyBxL9 68I/LtESI/HoTkVTyE3XGgeDjbt7v9ImGAeuYZ7Xr7e+yYCJUlzIPj5Qzu2oPYzvJhVFM= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 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: make the compiler complain if set_pgd()/set_p4d()/set_pud() are called with dummy values for folded page-table levels. 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(). Link: [1] https://lore.kernel.org/all/0019d675-ce3d-4a5c-89ed-f126c45145c9@kernel.org/ Co-developed-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum Signed-off-by: Yeoreum Yun Signed-off-by: David Hildenbrand (Arm) --- include/asm-generic/pgtable-nop4d.h | 11 ++++++----- include/asm-generic/pgtable-nopmd.h | 10 +++++----- include/asm-generic/pgtable-nopud.h | 11 ++++++----- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgtable-nop4d.h index 1c076c4dbca0b..c40b78de5657e 100644 --- a/include/asm-generic/pgtable-nop4d.h +++ b/include/asm-generic/pgtable-nop4d.h @@ -27,11 +27,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 inline pgd_t pgdp_get(const pgd_t *pgdp) { diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h index f3979cd878bd4..ecae9c8d94149 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 inline pud_t pudp_get(const pud_t *pudp) { diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h index 1f89eddf56943..d955ce0769856 100644 --- a/include/asm-generic/pgtable-nopud.h +++ b/include/asm-generic/pgtable-nopud.h @@ -34,11 +34,12 @@ 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 inline p4d_t p4dp_get(const p4d_t *p4dp) { -- 2.43.0