From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3300A485956; Mon, 21 Sep 2026 10:56:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988199; cv=none; b=iJTvDi+ALjKNxVClzQXorUN3vPkCYBy9lZNBamU8owdqeX4d02JRN+iNBMxrV+gAVhDHJT20Y7XBAkQgRnVQJTzz8+uPCpxddLdx5WKcfuu8Uuq9063rXpjITsu1w5cdVTaMnbBIvw3JtIoqnkr5Gye0XXpaj+RYpnunyxQxEV4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988199; c=relaxed/simple; bh=vEzrqCWaH6sVkcTMp6OI/QOpWZT9yXWBiNbXxiv6lmA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DuCfCOJMei8y6Noni/WQlj0XYieBV6wpFVdYRGyzk56Hb9mUrtGyi90NvGkLEZUrc8BEHw5Lz7ULnF5ALPqeHlRkY+ExEo8V2czBL5TEwsIaOw3L8GdjnqMHbpITyfbTt01LXop+2uoOAEJPytoHuwKmbosay27ueaDXSD7C+hc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=LoVIGTLg; arc=none smtp.client-ip=217.140.110.172 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.b="LoVIGTLg" 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 1B0511D13; Mon, 21 Sep 2026 03:56:33 -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 7B6A43F86C; Mon, 21 Sep 2026 03:56:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988196; bh=vEzrqCWaH6sVkcTMp6OI/QOpWZT9yXWBiNbXxiv6lmA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=LoVIGTLgqzJ/qsqv8y1uGB4x3jrgj3tiInD07+v3on40VZbIKUJCAuRuyG/NV29tp 2kYvHL/ObZV5edLNO5Ve1LLYQoVIgW623hWmFpOHtD/L2MkwE2PM9UirSqKqtoX4Rd H6xBWMlbZQB3YaYeY2mpGRniH91/tkMG7ynZ8B04= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:23 +0100 Subject: [PATCH 01/21] ARM: mm: make nommu pgd_t a scalar Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-1-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1081; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=ODmKgHrv0SlU2okc3grPddikJ1BO4DLAINSWVDYQruI=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1LlWiizi4t012wrwJwrwJTjWi/Wb29nF79i J4qQoShg02JAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENSwAKCRBt1cPRWsUx MweXDADISibCvJvF96puZBjP6/j4fMPKgIlf5MS3C5eSagiY6JFxwj3lAIkbhiPFMPYCnHBJnoL 2GA0NpEJpJyNWbhsAV12S4u7OvsEXVxhwfJkIzZS58W9csiUCIZFEIJeeoRnQzGnOFzFUkakRVx qkc8XmG8/eJznmc+Dxlnulm0n2bZYi5j54S/rQd/Ikdo5m9A+FMeYf04ijW4O0svRQScvjMFPe6 kVraASsRz5EGbbRfoH4SMzCaalxthaqxKHBUq7g+H588eoHoKXinUFv1W98H6pqtwKWe5asm+To Eq0zBQRFHajwr8D6LBzww0jQnu+df2It+l03o7y/78Q44wTlBaVaUJDhnjb5Pdeawtwtx9Z7aj8 duzExW/pl4kS3fr3Qof0bszw06VRUoqAUgb0W9KH9UoDBlwrzFdOABfQtidFW/gnhWEAX7o8d6b xzsbDSxkRRzb2wd4Lxch76ZEGXJe1I90lQHqznhSf5wCWubXXZK8jVHUqdjrcZKH73914= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" As pgd_t is returned from a function, like pgdp_get(). pgd_t shouldn't be an array. There is no need to match the actual arm page tables, because with nommu there are no page tables. It's all just in place to make the compiler happy. Making it a scalar will make the compiler happy. So let's just use an u32. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- arch/arm/include/asm/page-nommu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/page-nommu.h b/arch/arm/include/asm/page-= nommu.h index e74415c959bea..88659b38e2364 100644 --- a/arch/arm/include/asm/page-nommu.h +++ b/arch/arm/include/asm/page-nommu.h @@ -18,12 +18,12 @@ */ typedef unsigned long pte_t; typedef unsigned long pmd_t; -typedef unsigned long pgd_t[2]; +typedef unsigned long pgd_t; typedef unsigned long pgprot_t; =20 #define pte_val(x) (x) #define pmd_val(x) (x) -#define pgd_val(x) ((x)[0]) +#define pgd_val(x) (x) #define pgprot_val(x) (x) =20 #define __pte(x) (x) --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4164486620; Mon, 21 Sep 2026 10:56:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988206; cv=none; b=ptg0ONNrVk0rf7pB+5pDQ0ZMITji6NZCJuPnUzNU76/cfI7JE/h8tN6CRYyga9KpRKU3V/Nzp80nR2xAwlN9crP2wY9N7EQ2HMLiMDmnicW7xu83c4uF8sPXMApexlIttMH9gGPjvF6hNQPpKeY72NM8tLQRW3Nel2O+/IH5e20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988206; c=relaxed/simple; bh=MWIk55sq3Xl5IhFPSCZgQqnLya5ldzX0H6ZlzYM7l/s=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IQ+Jo558uL3i0mTrMfhfQITLE/Sg9FGKqelS93I8AKfcKaGZ+GUhU9cWlnfyt+qJxdp9CfQhZqmI3WKY1f8whQnnAr0ZDvYmAgdccSnT62FsD/azTEARg2TNeBELRP0Gg7ERFJ9/oDYGBJ0900f/GLtPZEbZ3DzKfF4icYJjd24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=jmExSGw2; arc=none smtp.client-ip=217.140.110.172 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.b="jmExSGw2" 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 8EC071D70; Mon, 21 Sep 2026 03:56:40 -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 EC3F63F86C; Mon, 21 Sep 2026 03:56:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988204; bh=MWIk55sq3Xl5IhFPSCZgQqnLya5ldzX0H6ZlzYM7l/s=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jmExSGw2LCoPoWhLv7wl3mcvZhvvMu/EFGtYz/YIjBdIYLmZ8xYhg+Bt8Lk13zyPM uN6j9Bi3PcRRphGGPrmscaNUQ1hMTG6ePRq5Ad874ubG9TqkzhXg+MtwYO6s/uX21/ w+FObAyJbBmnpGp1xy4Af27ePeH4jFFQJWayxXdA= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:24 +0100 Subject: [PATCH 02/21] ARM: mm: make 2-level pgd_t a scalar Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-2-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2019; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=4Z0osGAP3S0civxPu6dKKFX1qsd70Ol0fauRungSauY=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1LPMd3bY5l97IcQgb37uybVOO0YHrmaWze2 pZkKGx8ILSJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENSwAKCRBt1cPRWsUx Mwi2C/95zvtyR94wqriOwlZeIlIVdVW5IF05ARsQWsZciGmadMujO3xVKbNNHmP7n4X6txHc9Bt 1yPnW09kbOfe7xYWAPC4nw7e/Hz3E9vAZKgyIA+coj/w3E4SPS7GTyJ73zHuaoDvwAQEISXVRPW Pc2D0qopExouM3mWXINlfYnSOrYBHF4n6Li9Svio9m9EvcuV7NFR6d7+63k62CpNiUtK+tbIl0T RjaODkF1exxt6WziJl3rlm/T5QqRmjtA7pQyQ0EsNsVW91e7QgyT12RizaKDjYq/R7+ybfAinCt vRf66DRuwomc5tDPxoUIYUjiLa+sJLJr8TY0hv+mQ1Q4/4hMCPHnlYAGZShYe9PiTNmx6Mebzaw Uf8pO5f6ifwoPDZYfnwsLX3DPUMkDWnDejDdUiskVvMfbwCSuyIZeeDy3cP8ZxoJbVzyOdfp5Ok 0ZzHyHaELLDw/lpY50IvDiCohQ0OsFlKpDv5F9Z6evbkrsXVyMpScSsKxaQVtexaZTtl0= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" As pgd_t is returned from a function like pgdp_get(), pgd_t shouldn't be an array. So, just use an u64, and extract the right 32bit value in pgd_val(). Leave the STRICT_MM_TYPECHECKS case alone for now. As an alternative, the STRICT_MM_TYPECHECKS approach could be used here as well, but using an u64 looks conceptually cleaner, even though pgd_val() gets a bit more involved. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- arch/arm/include/asm/pgtable-2level-types.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/arch/arm/include/asm/pgtable-2level-types.h b/arch/arm/include= /asm/pgtable-2level-types.h index 650e793f41429..805044ea315b7 100644 --- a/arch/arm/include/asm/pgtable-2level-types.h +++ b/arch/arm/include/asm/pgtable-2level-types.h @@ -25,7 +25,7 @@ typedef struct { pteval_t pgprot; } pgprot_t; =20 #define pte_val(x) ((x).pte) #define pmd_val(x) ((x).pmd) -#define pgd_val(x) ((x).pgd[0]) +#define pgd_val(x) ((x).pgd[0]) #define pgprot_val(x) ((x).pgprot) =20 #define __pte(x) ((pte_t) { (x) } ) @@ -36,14 +36,28 @@ typedef struct { pteval_t pgprot; } pgprot_t; /* * .. while these make it easier on the compiler */ +typedef u64 pgdval_t; + typedef pteval_t pte_t; typedef pmdval_t pmd_t; -typedef pmdval_t pgd_t[2]; +typedef pgdval_t pgd_t; typedef pteval_t pgprot_t; =20 #define pte_val(x) (x) #define pmd_val(x) (x) -#define pgd_val(x) ((x)[0]) + +static inline pmdval_t pgd_val(pgd_t pgd) +{ + /* + * A PGD entry actually corresponds to two PMD entries in the PMD table. + * Both PMD entries point to PTE tables residing in the same physical pag= e, + * but at different offsets. See include/asm/pgtable-2level.h for details. + * + * Historically, pgd_val() has returned the lower of the two PMD entries. + */ + return (*(pmdval_t (*)[2])&pgd)[0]; +} + #define pgprot_val(x) (x) =20 #define __pte(x) (x) --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 02DDF483BC5; Mon, 21 Sep 2026 10:56:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988213; cv=none; b=ZrMdxJlr1dzrdapc4D2oeBcmm22DREY9ZgPVj6JTOtcDb9ElEOeCzbKdK0YUulFiE1W+DW/mFN+AieCT26bolIHSiwgVfuB42FkkvyBKRRAM33zoFevMt5XVIekx1Vt0/MlRFwITUr+yeeDEOA+5mKjJj7Q3axK6pZfowzsIbuo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988213; c=relaxed/simple; bh=pfH49/wekZWH0tUlmAGPYfXLPMYhwWIki53rOu3JrVc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oc9gNjls6BWc7XqD9YzuPO+JYHOkniuSzX+omz3R2vaNpL2rWyBFn83PE4DRyALSE/EkivknF+/Hbfr/WSW07J4eD0iofIzTqgUq5tms5Dq6K5anXEl1ZsO4EUIQo7s9FspkUnJAv8OHZVhNLobF6acA7E8aV0rLWgyZCmS+2q4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Olwk11hT; arc=none smtp.client-ip=217.140.110.172 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.b="Olwk11hT" 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 08EE71DB5; Mon, 21 Sep 2026 03:56:48 -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 6A0CC3F86C; Mon, 21 Sep 2026 03:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988211; bh=pfH49/wekZWH0tUlmAGPYfXLPMYhwWIki53rOu3JrVc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Olwk11hTmNoCQY0yieoGRI6nr2tZK+9Y8vNgJkjNBvabvI4jw3ecE117CoBDHRZcA VaHf6/WYeKfqcXLlbCGFFRZ7VeZS5wzBGURhdMIHRzkGy/szUC29S0SOD5k+/st/hm ZKDb93jOuQfIb93pn4lDETSPnOoAPOixVE8trrQ8= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:25 +0100 Subject: [PATCH 03/21] ARM: mm: remove custom pgdp_get() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-3-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=794; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=yi3BzhiHjasTHpKXh1MmDEBzfM1jM8lRPSh1W8s2lTo=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1MhweskEeRkdPnGVTUHtMQosteIoTZTcWZ7 m70DkNoOo+JAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENTAAKCRBt1cPRWsUx M1pdC/9eWcL8m/evh/5ze5hTI1UzJJ9731T8JXRUtUacBadzNoIsOzFTtZcP/L/LZXeSCg+qPJI GlkbXXgrRzR0Y1cTWBK5XsScCAxuXdVnmkam0g6EpCc91YkNc9mg0Xvj0hhcBeYo5b6yy4EcsGk Eqqr8Kdfj+dow9d1FDFwO6RPyIgwXw4NOvVhy8Ye1AtUMFp57bmqyuyzFZvHE/b3dh10GbTVvQl zd7uAbnS0shbhwLl6nwID4BUlrc8uNzszZy7xbLQD7VD4tzIl0LPHUN1JeJoAiLWd+i4ixBSnNc VKFX7FvI1lzQ6+mpKnBPOJfihjR9O8/IFykRTKwpakx9mvghn3bIAmuYr31vKk4LmF6NUC3WKiQ lchWJeCYXYaUqbEhxl2y760Y5hHJIi1DIDkUYCunpdebAxongZeEyzxUpcxw9e005xG4lOa9qP1 //r/dM5ak9J8No9Oco0jmCsMc2ZGFGwv/0xNxtVsYmmZoYo8sBtsLujJukxT5yfXw1zC4= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" Now that pgd_t is no longer an array and rely on the common code pgdp_get(), which is a static inline function that returns pgd_t. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- arch/arm/include/asm/pgtable.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h index 8dd17d20faa33..ff3868acea945 100644 --- a/arch/arm/include/asm/pgtable.h +++ b/arch/arm/include/asm/pgtable.h @@ -134,8 +134,6 @@ extern pgprot_t phys_mem_access_prot(struct file *file,= unsigned long pfn, =20 extern pgd_t swapper_pg_dir[PTRS_PER_PGD]; =20 -#define pgdp_get(pgpd) READ_ONCE(*pgdp) - #define pud_page(pud) pmd_page(__pmd(pud_val(pud))) #define pud_write(pud) pmd_write(__pmd(pud_val(pud))) =20 --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A7B5F483BEE; Mon, 21 Sep 2026 10:56:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988221; cv=none; b=hrfNj0dpw8J2Hv5a06Eww9tsSbVpElEJRcHisBfS/YmEq/NSUzS7LuOdf/Vb9cckXzlosOCIP8jS46AHLWBwbFwwA3qCzJdbtsSauONyx10AtAmKA2Hn07e9abXdJ8X/Rxai6v59nVosTQ78cE2itnatXznMTnXzIb/HFbr4JUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988221; c=relaxed/simple; bh=rnI7y0Fpi9EpSaKs0zPg/sympiblJU7quGD2p5tv2as=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FlgCwt8iSexa8aqQwUF7tHkKY1zOw36F44uNthooDfnraIV3Bks4wuQnm14Pmy/h7C3XxFO6i1vJho+R5JCHakGSBzkmPGxEahGEF/vGDE1JqNEY0Rce6FGAYwvubWn5BoCVQOppc+IjzApPTVnTfsIcZ7iB7IFnx3IpbmWq1/k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Erxu0w3k; arc=none smtp.client-ip=217.140.110.172 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.b="Erxu0w3k" 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 7B0B41CE0; Mon, 21 Sep 2026 03:56:55 -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 DA2C53F86C; Mon, 21 Sep 2026 03:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988219; bh=rnI7y0Fpi9EpSaKs0zPg/sympiblJU7quGD2p5tv2as=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Erxu0w3k0j6ub5hHfj+RN6pEhjSNKHkKz8ooYKskXllnoLVwJ8Ut4DZ7NeEJ5/rDP SPY3vbUR4axOfHnsqT+sZBjZVHL/E9nsVWbpsXIhcl8s27YOeWUOZEH7qpSiFxdsmr myTCIU+NKUGM4uM3qVejSjvoXD/mXvabuVl3WG3g= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:26 +0100 Subject: [PATCH 04/21] LoongArch: mm: define pud_leaf() only when PUD exists Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-4-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=993; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=uHP3fCujvTA7teOGPJseRh4165tfxVj1UjkqwzmtCWQ=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1MsnYSzGCrfSvMhPR2nenqzfaOWd2TWY08B FS8dv7UCUWJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENTAAKCRBt1cPRWsUx MwVVDADY86GBwYvZ/9NRAVbtoFfHEGdfPzdSbaqYPaX2rteHd+ssXS7FQyNXF7l/1y5jgMN6f8T u7ZaYgOKw41FfG1EJ8ZIDiu9bHuqzDTTvuRML+XcjRwJXrhPRAztnbXo/OZ1RTqo729jpcB5Xl9 9PS3DceEj++x8zDzmyN8uxazCUfLRsT6GzwULKx9ysQ+5jUUhYPliUTuPjjCAry4VEjHRk2u0Ed vQh9FTH94HI/jFBfC4SZtHDWf6T1x5Mb0/CSBtnqPk4Pme3fbJMuU2FsPfmyKx2KBuYHJkBfRDZ 2znp1ATgR9+XFXRZo4l/N1jmwBMxYXnA63Q4aLVjuDFyHKRaqnvXBv39ZW6q6spPgH9F7MIAiZ8 X6kHCzMocHrCdxMnZwrD4R9ifssomtcBwjrY1xxB7PCNiew50qsZ9SlhqunzUmYP5D4KRNdR9Eu yEbDNwJYCgqoM0+XH0D/u8DleX7OGnVzPCTqimSGz40CcsWXg4oKF9+WTv4QSQoYAQubY= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" In include/asm-generic/pgtable-nopmd.h, pud_leaf() is hardcoded to return false as inline function, but it misses the "define pud_leaf pud_leaf" part. To prepare for fixing that, define pud_leaf() only when __PAGETABLE_PMD_FOLDED isn't defined. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- arch/loongarch/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/loongarch/include/asm/pgtable.h b/arch/loongarch/include/= asm/pgtable.h index cf29a4c8ac593..8aee4fc27a26e 100644 --- a/arch/loongarch/include/asm/pgtable.h +++ b/arch/loongarch/include/asm/pgtable.h @@ -630,7 +630,9 @@ static inline long pmd_protnone(pmd_t pmd) #endif /* CONFIG_ARCH_HAS_PTE_PROTNONE */ =20 #define pmd_leaf(pmd) ((pmd_val(pmd) & _PAGE_HUGE) !=3D 0) +#ifndef __PAGETABLE_PMD_FOLDED #define pud_leaf(pud) ((pud_val(pud) & _PAGE_HUGE) !=3D 0) +#endif =20 /* * We provide our own get_unmapped area to cope with the virtual aliasing --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB4B4483BFB; Mon, 21 Sep 2026 10:57:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988228; cv=none; b=Y9RjA4akB+v9lGYafI660aqm0SQ1SxdZ0ivxLKDQlUZ2C1bECvbFes0z9In/6yRzb2czaG84+WmvvHVfs8frhLkktXTfQ8ctkE2V69Y3WZcp7WjCE/S8syvKOxIYG/67YsVWEc3W9/VA+ALYnQnBtObcbOI+XW4HckMsF2/uMUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988228; c=relaxed/simple; bh=t0SkgFkvYDykWTdwPClx+wiQRsFxgewU3m4qBQArb9Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=H7YNXHR7Z2BcBtu+RMGc/EQHojr5smX68yqDNei1/k33qahouulzGHdo8rA4Eo4UCARG4+GXbN48Gz56c+BDje8QIzlAUl65SYDj9Ro1J2n2H0/YvzgtgUuYk5468RzElVJXl2h0Yfs8ji3Aayw0E+Ni2sjcc0lyIuc1G6KugwE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=OBFz6Z+R; arc=none smtp.client-ip=217.140.110.172 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.b="OBFz6Z+R" 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 E62EB1570; Mon, 21 Sep 2026 03:57: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 563473F86C; Mon, 21 Sep 2026 03:56:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988226; bh=t0SkgFkvYDykWTdwPClx+wiQRsFxgewU3m4qBQArb9Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OBFz6Z+Raz7I8ibgsDiaiNLTnQsX4oLEoKjZPRodWantEpoXhmxG8yAOCFS64FQx6 TnSa1uoOW4JI3vs3idHKAZLQrb2k4cp73AJbVjUGApg0VIpLWNjF8iXjbLwLCJOMOP KH6BsKk5W9konyiN3h+HCCs6a4q5K9z2QxYNfnPk= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:27 +0100 Subject: [PATCH 05/21] MIPS: mm: define pud_leaf() only when PUD exists Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-5-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=952; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=yLp6pLFkEq1XlBsrO8HJPn9OYitILCqfI5l0JaR3PzY=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1NTZ/a+wId/oXop6nBRx7GoTqL9a7Er/mVm I4zdOrs16GJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENTQAKCRBt1cPRWsUx M7A5C/9647RRGO+Rm053IZPrkfpK1qoCf6h7h++dBQM7iWcjgmIysinuJZ/9flN7m3N7/8s0k1F Qg8UBSKcYxAPzyP7KMXSKbC6blVlpHWz3kExm+/5ZAnSr3JetwJGEw0WoHg0g85dvAd2y+KV0nj fcMLKAxYW9EKQIqMG7nuATB+F1lWeLPWUKEeZ5Xr3zYvC2diB9VgvhinADx3ajrN78j7ASV1xes 7//vZ8p602dtxNE82CTR6O3KYyUFHq7mNoysyRhtRvpNYl2Ts3NfvwNVO6vCLxhNLIIYu7s2mAc n2FreTnlSvWWzFZQfZrm8tZrPteyXRjmWvqXceNsbR4SJYTafBHwQjLRLGhy8+k1iRjDqguBSwy LsoRrK1Q0udKYrD3CKiy34mvfTgVS17T60Z0/lwKClICrmLYbw/pQoCMDwpPvb9abrZB8uyEsZG 4+DpL7SndbO4XS1cejsKbd6M7jig6sw/xhWPdMK/bJQQY3QqubKCQrarXnjeyHzIhJkqw= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" In include/asm-generic/pgtable-nopmd.h, pud_leaf() has hardcoded to return false as inline function, but it misses the "define pud_leaf" part. To prepare for fixing that, define pud_leaf() only when __PAGETABLE_PMD_FOLDED isn't defined. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- arch/mips/include/asm/pgtable.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtabl= e.h index fa7b935f947ca..151f4d15bd12b 100644 --- a/arch/mips/include/asm/pgtable.h +++ b/arch/mips/include/asm/pgtable.h @@ -745,8 +745,10 @@ static inline pmd_t pmdp_huge_get_and_clear(struct mm_= struct *mm, =20 #ifdef _PAGE_HUGE #define pmd_leaf(pmd) ((pmd_val(pmd) & _PAGE_HUGE) !=3D 0) +#ifndef __PAGETABLE_PMD_FOLDED #define pud_leaf(pud) ((pud_val(pud) & _PAGE_HUGE) !=3D 0) #endif +#endif =20 #define gup_fast_permitted(start, end) (!cpu_has_dc_aliases) =20 --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C4752486BBD; Mon, 21 Sep 2026 10:57:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988236; cv=none; b=Y9mOJpYoA2tXUYY1Glngbvv4VxBA7dc1hw7oYM771vnQBhq8nCO1CTqC5Nc3D5rbKQrHTL1e+Sx9eWwmhumBnIrJLbD8JQB/Od1bu+E8fnEU0fu1r+Krs9HSSSSMw302TLa8cddxDHr+GgxAyAViDNdRNwwX9ogkEYF63D7m5rQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988236; c=relaxed/simple; bh=evfeL7lk1yM+NSCKYrKsUpK8FtfFqKH2c2v1uANMiZA=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RmcN7Mx97kUKSkXuX08WgMqHYmyQ+R3to5zEsgwsI9aDcdcbIJ0SXHaTwiL6jr4hZ47GRMmhrZuOyUbb1KYBMgaCG0YSH9b7TtLyLDix09QenQjXFhG1t1k/ATDICszcdgqR/MpnCLgSiZLAQKvyZMhaCpreqbVKyK6Wqq6/wdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Xin7nkqt; arc=none smtp.client-ip=217.140.110.172 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.b="Xin7nkqt" 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 60C1A1CE0; Mon, 21 Sep 2026 03:57:10 -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 C61543F86C; Mon, 21 Sep 2026 03:57:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988233; bh=evfeL7lk1yM+NSCKYrKsUpK8FtfFqKH2c2v1uANMiZA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Xin7nkqtoZA/IKaN1bsZASwfU+1NECaZN6VEF7DCQgeeZsASTdyE/P29B2ESqDwcR 3PrnBYPE/iqT9P6uIvyqAv78zmz38U4I100s9VY7jCzhFHAKe9uNEexPk71cCPA/I8 rPv9w1Vloof+Vj/9mT37AC9r1STb2mNCpt1D2qq4= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:28 +0100 Subject: [PATCH 06/21] mm/pgtable: define (pgd|p4d|pud)_leaf() for folded page tables Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-6-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2651; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=MsUi6fKiy4C8DH1qxUfB7PhJ8/xMmbWjYscC+NJ7HZ8=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1NMAsihcMqWtTNq8wXGlyLqx/OjaZfBDhWO BQRXRP3kPaJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENTQAKCRBt1cPRWsUx M1JWC/4oEz21sKhzCLwgY6I/1KB5pft90w3HXdaylhrNZwNhAioe8Je0Oz2Rjw8hBIMkvhd3e0w zA69tHAwWWTuBHTswnnt0DeIqTvlxzCwlA48r0Z7UkYQkkd1IK5dTX+29BumgcET7QxrdKuGFc8 8RI08NCJyK3BuFSev/59cyoZFG0OX6kdSx9hMs3055MvaT8IVAv9XSclmUpwINFPH1qeA8l3/Jm JTv+7Cgpp9VtbAss1UR0jmvFTjHEyFbVvzemKonJiLlgg2DGpEZjwSU7hkvNUm+6Ni/AqDrrHJK D1EaTGvZDnm+C8lMK1IDSiqwgTJKIUIAUrgVzEh4QIp7qyoMLw2GuKIv+1Ztdzoi6z+CYqlpDUj L5tiwukcbc94p3teYqPPwP+UnafkHm0JuyqywJaziI4mD1XrAKI1OMPviw0mfqXOwyjjB/BggSq 20fhyXt51a2D5K+CexmOCQ/jx9XLyZmEWUJInumOy6SrMuxQhUsc9KzqpJGjAszheuAWA= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" Define (pgd|p4d|pud)_leaf(), hard-coding it to "false". Note that it's missed to define pud_leaf() before, allowing architectures to unknowingly overwrite it. Still use static inline functions (type checking), and while at it, just use "bool" as a return value. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- include/asm-generic/pgtable-nop4d.h | 3 +++ include/asm-generic/pgtable-nopmd.h | 3 ++- include/asm-generic/pgtable-nopud.h | 3 +++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgta= ble-nop4d.h index 1cf739ee38aa1..c6a5a43899b50 100644 --- a/include/asm-generic/pgtable-nop4d.h +++ b/include/asm-generic/pgtable-nop4d.h @@ -22,6 +22,9 @@ static inline int pgd_none(pgd_t pgd) { return 0; } static inline int pgd_bad(pgd_t pgd) { return 0; } static inline int pgd_present(pgd_t pgd) { return 1; } static inline void pgd_clear(pgd_t *pgd) { } +static inline bool pgd_leaf(pgd_t pgd) { return false; } +#define pgd_leaf pgd_leaf +#define p4d_ERROR(p4d) (pgd_ERROR((p4d).pgd)) =20 #define pgd_populate(mm, pgd, p4d) do { } while (0) #define pgd_populate_safe(mm, pgd, p4d) do { } while (0) diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgta= ble-nopmd.h index ff4235cf84d77..4e5aaf253b6a5 100644 --- a/include/asm-generic/pgtable-nopmd.h +++ b/include/asm-generic/pgtable-nopmd.h @@ -31,7 +31,8 @@ static inline int pud_none(pud_t pud) { return 0; } static inline int pud_bad(pud_t pud) { return 0; } static inline int pud_present(pud_t pud) { return 1; } static inline int pud_user(pud_t pud) { return 0; } -static inline int pud_leaf(pud_t pud) { return 0; } +static inline bool pud_leaf(pud_t pud) { return false; } +#define pud_leaf pud_leaf static inline void pud_clear(pud_t *pud) { } =20 #define pud_populate(mm, pmd, pte) do { } while (0) diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgta= ble-nopud.h index eedee8e3ad68f..6c9bca78047c4 100644 --- a/include/asm-generic/pgtable-nopud.h +++ b/include/asm-generic/pgtable-nopud.h @@ -29,6 +29,9 @@ static inline int p4d_none(p4d_t p4d) { return 0; } static inline int p4d_bad(p4d_t p4d) { return 0; } static inline int p4d_present(p4d_t p4d) { return 1; } static inline void p4d_clear(p4d_t *p4d) { } +static inline bool p4d_leaf(p4d_t p4d) { return false; } +#define p4d_leaf p4d_leaf +#define pud_ERROR(pud) (p4d_ERROR((pud).p4d)) =20 #define p4d_populate(mm, p4d, pud) do { } while (0) #define p4d_populate_safe(mm, p4d, pud) do { } while (0) --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1D6FB485500; Mon, 21 Sep 2026 10:57:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988243; cv=none; b=mfMXQykhtuYYd1qTChHOEAghFFzecg42892qNQgNLrF2R5MMqUQE8O+eIpvj+mL8Z0eB1eHVxZ4B2W9wxEMW3EZAa9iIoQ1C9MglJArgTxInbOawoaS6+wko/aeCkT2Rt0FLQSRJrHCRq5vhmgat97n/8xda9EH19TUaVhRg9tw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988243; c=relaxed/simple; bh=eO/TuCYXsMbuYK8M0gFZvx7bvQHzfV5/hkWKu/RsUj4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=o4LOzaie5HfSb2D2lpZJmBhUMAcT8xbB4RlbqV+4fqpHzBdZQOHiEjaaxzuoGfX4P5jNPyBQS8uNz+6B12d5eulO3SGCahnDvMB5e++9JgayrGCMbWS5ts627SIFO60VpO0OPp6AKC+ySdGotAiRQDFfSX7s05p/BcIiFXelX08= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=UOyMy1XU; arc=none smtp.client-ip=217.140.110.172 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.b="UOyMy1XU" 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 D16551570; Mon, 21 Sep 2026 03:57:17 -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 40E833F86C; Mon, 21 Sep 2026 03:57:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988241; bh=eO/TuCYXsMbuYK8M0gFZvx7bvQHzfV5/hkWKu/RsUj4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UOyMy1XUl+FN5ZFNQorWnnKPtv/UkQZgHPGlzeaRpx0D75+94J6h4tByCGqfzlsOc NmGVh/Uea3V+aklixbWlJ9Kz0A2C+SPMhys5dT/vscoe8tU3iR7tGcB5VXHs7zjr7o 1lw0ePXHwklUI/LIfoNOQPXsfuy4NgsrXncJg6FE= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:29 +0100 Subject: [PATCH 07/21] mm/pgtable: define (pgd|p4d|pud)_offset_lockless() for folded page tables Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-7-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4366; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=zbP/UAv5r1ecRg6w3p/1fVSqT9+jMUkB+linIaJOv8Q=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1Olg/kp2O12ZhBFsprJTLwJprUFHtBPBboc xsbot1EFYuJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENTgAKCRBt1cPRWsUx M9M0C/4omPEQYtMsmhr5u98NEFHzremiNZ24+AVOBDXTL+rJoYL/1w6it+HEgBZjKKRb1YpvT5a xzVvByW0NmxLHkS1C/N1PMUe8Y4v1TxJUnTrrnnujUMcyWrEjMVbDul0gKHFZJsIXo+Y5jCHcE8 o7nstAfRNVP0jsYT4A0swLzAVx82gz5mYQ9xbh1mvQIC8KGwW0HSzesy8GLGafXd4rTpmQhp6c8 FIvu17DbNJG43dukNhzi2rTu0HGYqn2GG7Z6DQ5d3QCZZkjBTHhShsHvtYmvxdbOeKHOXh34xXq 2paWtI/ipWGZ/zqFv/TF15VlryOyvMcF4ZNYvUKCQrvfZvgnZ/l2mgiF4a6HTWXFYeGFlewj6nz rgP6hVmN51A2FA5SEUKAcs21tcP99SeU25vHkI6TW3ad9swA9i/BHG5yftJwbr4dwszKeFahtQj qg9S4LKfbCjV8hC8w7FbIuTX6eIY1qUH6i70JIks3i9F1KNAtzfUAu+vIDSiAVc5xY52s= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" The default helpers fallback to pud_offset(), passing a pointer to the stack value. Let's provide variants that do exactly what (pgd|p4d|pud)_offset() do, but ignore the passed pgd_t/p4d_t/pud_t, consequently not working on a pointer to the stack value like the default handlers would. With this patch, Drop the arm64 custom variant that did that. As it documen= ts: Note: reusing the original pointer means that it may be dereferenced the same (live) page-table entry multiple times. This is safe because it is still only loaded once in the context of each level and the CPU guarantees same-address read-after-read ordering. Do not document this, as the double read will be removed in the next patch. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- arch/arm64/include/asm/pgtable.h | 23 ----------------------- include/asm-generic/pgtable-nop4d.h | 7 +++++++ include/asm-generic/pgtable-nopmd.h | 7 +++++++ include/asm-generic/pgtable-nopud.h | 7 +++++++ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgta= ble.h index e89ec5f4787b4..a3c882e46777a 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1180,29 +1180,6 @@ static inline bool pgtable_l5_enabled(void) { return= false; } #define p4d_clear_fixmap() =20 #define p4d_offset_kimg(dir,addr) ((p4d_t *)dir) - -static inline -p4d_t *p4d_offset_lockless_folded(pgd_t *pgdp, pgd_t pgd, unsigned long ad= dr) -{ - /* - * With runtime folding of the pud, pud_offset_lockless() passes - * the 'pgd_t *' we return here to p4d_to_folded_pud(), which - * will offset the pointer assuming that it points into - * a page-table page. However, the fast GUP path passes us a - * pgd_t allocated on the stack and so we must use the original - * pointer in 'pgdp' to construct the p4d pointer instead of - * using the generic p4d_offset_lockless() implementation. - * - * Note: reusing the original pointer means that we may - * dereference the same (live) page-table entry multiple times. - * This is safe because it is still only loaded once in the - * context of each level and the CPU guarantees same-address - * read-after-read ordering. - */ - return p4d_offset(pgdp, addr); -} -#define p4d_offset_lockless p4d_offset_lockless_folded - #endif /* CONFIG_PGTABLE_LEVELS > 4 */ =20 #define pgd_set_fixmap(addr) ((pgd_t *)set_fixmap_offset(FIX_PGD, addr)) diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgta= ble-nop4d.h index c6a5a43899b50..019c3f074b771 100644 --- a/include/asm-generic/pgtable-nop4d.h +++ b/include/asm-generic/pgtable-nop4d.h @@ -39,6 +39,13 @@ static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned lon= g address) return (p4d_t *)pgd; } =20 +static inline p4d_t *p4d_offset_lockless(pgd_t *pgdp, pgd_t pgd, + unsigned long address) +{ + return (p4d_t *)pgdp; +} +#define p4d_offset_lockless p4d_offset_lockless + #define p4d_val(x) (pgd_val((x).pgd)) #define __p4d(x) ((p4d_t) { __pgd(x) }) =20 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgta= ble-nopmd.h index 4e5aaf253b6a5..1dd5b165234be 100644 --- a/include/asm-generic/pgtable-nopmd.h +++ b/include/asm-generic/pgtable-nopmd.h @@ -49,6 +49,13 @@ static inline pmd_t * pmd_offset(pud_t * pud, unsigned l= ong address) } #define pmd_offset pmd_offset =20 +static inline pmd_t *pmd_offset_lockless(pud_t *pudp, pud_t pud, + unsigned long address) +{ + return (pmd_t *)pudp; +} +#define pmd_offset_lockless pmd_offset_lockless + #define pmd_val(x) (pud_val((x).pud)) #define __pmd(x) ((pmd_t) { __pud(x) } ) =20 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgta= ble-nopud.h index 6c9bca78047c4..5a2b0a81ae197 100644 --- a/include/asm-generic/pgtable-nopud.h +++ b/include/asm-generic/pgtable-nopud.h @@ -47,6 +47,13 @@ static inline pud_t *pud_offset(p4d_t *p4d, unsigned lon= g address) } #define pud_offset pud_offset =20 +static inline pud_t *pud_offset_lockless(p4d_t *p4dp, p4d_t p4d, + unsigned long address) +{ + return (pud_t *)p4dp; +} +#define pud_offset_lockless pud_offset_lockless + #define pud_val(x) (p4d_val((x).p4d)) #define __pud(x) ((pud_t) { __p4d(x) }) =20 --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8C7EE48E0C6; Mon, 21 Sep 2026 10:57:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988251; cv=none; b=m9uOjDHaH0FZa5FKbgVlmkcWrcBsH1YHE9QXgxTCSFybChExl/AQksLVHGgYA6z3ZVYLTj0sfnFllLYAFkzVtmYJAerXvwx3/OPE6wB9Ufz6wNer7wzhA5gYX+8JoBXuoXbowOTxCMahYcBfKAYdOTJ6Tbf+cWmNFcH+nT7Umgo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988251; c=relaxed/simple; bh=ywGIUWe4eG9Fo7o6yUhrB9doRugWRJ87ez63n7dCtOo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=YdHSymmywU+xZAGK+dpWSB4Dka/CcKTh9Ov5F5x1u/NwcldvDed/gCh54o39Z4PHrAuhdM8fdE+qktenXZkWkpQjVOmEg6wzySC5bpW/l/+kknStsTBs+ob9kCH8RjgB8+O+xFlTbfkj3oHgsNFk1ERhYh8pXPRRTIIRgWyNPAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=TG7hL96k; arc=none smtp.client-ip=217.140.110.172 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.b="TG7hL96k" 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 8F6801570; Mon, 21 Sep 2026 03:57:25 -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 B11E63F86C; Mon, 21 Sep 2026 03:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988249; bh=ywGIUWe4eG9Fo7o6yUhrB9doRugWRJ87ez63n7dCtOo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=TG7hL96k21J46PvtLC59HQcHZYmuTxx9rr3LlmBn3clj7nC0IKikp8QCrZXShJiox fJA0U5SPbxEnut2fgoLETk2PoTNcFpOzCPKxMO9mqeqjhO1uEMR7RAtABKtRMHEHQ0 b6ZmFs8B7G0JeikmhUafh8z+0+Is/vD6upLImixU= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:30 +0100 Subject: [PATCH 08/21] mm: vmscan: remove stack copy address of pud/pmd pass in walk_pud/pmd_range() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-8-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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, Muhammad Usama Anjum , Yeoreum Yun X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1416; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=ywGIUWe4eG9Fo7o6yUhrB9doRugWRJ87ez63n7dCtOo=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1ONrk530uquKqsKokVTVRoFTxsseBHhNflE f+mOH3t5ViJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENTgAKCRBt1cPRWsUx M6i5C/4jxR695g+aGeGrIAp5Hq3EK+JsBl4Xkw64Rh+MB3TRHC7oHN9GqMwjA0R8KVzPNX4iDSb opQlxOkF6mlSjUJGYxtqS1/XQG7tmGB0boaY6gUG0tIPmXOnfHwRWhoUKxqSVO71aiHCKtMDHx3 bvrSwgP3w3zc8ggNJdnUy0wQcByFeJFXtAC1548O4Arfhb/ldpChjkVK3Ttsmgib2gqXAlb7o7e 9kQEaAz1xbJx7+O2HbWqlXUHkPJFlrsGFKRoGNPmv+WuUmj9QEtHRlA1kSF54i0Omq+aH1S2gwL 2LgEZ9bPoknyuFN6E9vrtpQYA1cCcuMTcUiDtUbwVryNrTwccRxsgqHoeJstzUoQ56opOp8sTAF Pb7joEtKSjOyjqcbbb/o2KTzQKHOb0DIdBIOTo6cAmoMHyo+NbTIe28IZaY5snJlAQuUdvNKFNo qjJD+aHKgVLGvNKvkeq2VdMiw2jy3gEJ6IWGuxArucd2EPLm46Ivh5Ej3meNBg4nU8tb0= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 The behaviour of pXdp_get() will change with generic compile-time folded page tables. To prepare for that, replace passing the address of a stack copy of a pud/pmd to walk_pmd/pte_range() with passing the pud/pmd pointer directly so that makes allowing folded entries to be ignored and check the concurrent access proeprly otherwise pXd_same() would return always true. There should be no functional change. Reviewed-by: Muhammad Usama Anjum Signed-off-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum --- mm/vmscan.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 836f50814ffae..f771443cd78b6 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -3871,7 +3871,7 @@ static void walk_pmd_range(pud_t *pud, unsigned long = start, unsigned long end, =20 walk->mm_stats[MM_NONLEAF_FOUND]++; =20 - if (!walk_pte_range(&val, addr, next, args)) + if (!walk_pte_range(pmd + i, addr, next, args)) continue; =20 walk->mm_stats[MM_NONLEAF_ADDED]++; @@ -3907,7 +3907,7 @@ static int walk_pud_range(p4d_t *p4d, unsigned long s= tart, unsigned long end, if (!pud_present(val) || WARN_ON_ONCE(pud_leaf(val))) continue; =20 - walk_pmd_range(&val, addr, next, args); + walk_pmd_range(pud + i, addr, next, args); =20 if (need_resched() || walk->batched >=3D MAX_LRU_BATCH) { end =3D (addr | ~PUD_MASK) + 1; --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2605F48595C; Mon, 21 Sep 2026 10:57:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988259; cv=none; b=LJ86imoJYZoZR6HejVpIjM2rl7sdrbVBW9otcGkq8hFza5JnZUQYtr3wdOGleD/yUsaK0uMSY8QeajpmMpfrhyKhOHdrfxCTqUORA1mp6zBzKyoQNUNPTo7+E1kvlH8rHog+A96/yb0MqBj3DWdrKy4l7Pzx1jzWJKy9Glvzr98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988259; c=relaxed/simple; bh=tenWdx/UAPDDmgqvhn1jTW0rtV2ElcnA6e+1jtwaJs8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KL6ks1UjQhjh/Ukh/oaCZCuieJhAj7DsgLYFteUhxKUBsjtbvUI9anZuaLnfBzCid7fqCtSRDqVLZMQBVwOLU0Ch1usFQB0QTLUdm5nO7OC7hkK3Kv10bxS3ILSVGO7oUMyPOQYCk3qoLyUxo+Kr7xrpQlEV37s2HgfaG3KolqE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=r3qQ0wEn; arc=none smtp.client-ip=217.140.110.172 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.b="r3qQ0wEn" 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 293551570; Mon, 21 Sep 2026 03:57:33 -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 6DC153F86C; Mon, 21 Sep 2026 03:57:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988256; bh=tenWdx/UAPDDmgqvhn1jTW0rtV2ElcnA6e+1jtwaJs8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=r3qQ0wEnceoNCSAemMvOXk/eg6xJzFlkI2IyMBaatbiz4/x7s7q8hXTaO0Vl8MDQ4 rS0/4H24aYxcUvmqdedXNG5j5+laQn70ovdDLv2Urbd3WHUzthrh0Kec8w0w+ul6hy 3zGTSf1mygcnWXtKW69QPNHlW0tU/7g+HwsoV8R8= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:31 +0100 Subject: [PATCH 09/21] loongarch: kvm: remove stack copy address of pXd in pXd_offset() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-9-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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=2052; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=tenWdx/UAPDDmgqvhn1jTW0rtV2ElcnA6e+1jtwaJs8=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1PJaEMk0o9SRiHZSjHIfm+GrA188fN+4hRU 6wJUgjEtAaJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENTwAKCRBt1cPRWsUx M8LxC/9j9lKenvxhbWb1SDdCXY3s7kZnCDH1casxpL2CIqsMn1jRkSXlvvWc0FK7/ooO4WCtNPY isddhbQdba3tQ14ARwFYleVeWNNmiT05JGvjASoPg50ySoGJaDe19OE4hZWOghnmxjkdc86g7jL gcCOPOwe9mQY4LNYG8oZF9///bcv3szPoREYgWxSzP1vxiY0prT9Dyfrv3zTgfStuBUY4ntnptW G6zFnDbNPzkifb/jVOuDI1ksUJyOcnJzCCWQh8wAul/S21IO6AC6udNQZCpR4UHngkTh0e7kUgq arNAcFyIjLTCw2utF3PQlxLJylHPboWGN6Qby0dJF/WPvfwiMZ5ZqM7rzEP8W0iKnUglDk7bkpP V87UdgAwIoTi1oSvrjliTDJV5yEBgdqYWHvSXN54WMH8yzs8AO3xWzAryfmg1jwsGVfcCNvBtRA 5hUpniFYmqdNtZll1Rh6ljx/ikMnaZyFYSHYscH16HGIFR1qU5Wck0IPfXF0jYchNE1jQ= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 The behaviour of pXdp_get() will change with generic compile-time folded page tables. To prepare for that, rework host_pfn_mapping_level() to avoid use of a stack copy of a pXd and pass it as argument to pXd_offset() so that the folded entries value is ignored. Replace direct uses of stack-based pXd values with pXd_offset_lockless(). And there should be no functional change. Reviewed-by: David Hildenbrand (Arm) Signed-off-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum --- arch/loongarch/kvm/mmu.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c index e104897aa5328..837b40bb694f4 100644 --- a/arch/loongarch/kvm/mmu.c +++ b/arch/loongarch/kvm/mmu.c @@ -669,10 +669,10 @@ static int host_pfn_mapping_level(struct kvm *kvm, gf= n_t gfn, int level =3D 0; unsigned long hva; unsigned long flags; - pgd_t pgd; - p4d_t p4d; - pud_t pud; - pmd_t pmd; + pgd_t *pgdp, pgd; + p4d_t *p4dp, p4d; + pud_t *pudp, pud; + pmd_t *pmdp, pmd; =20 /* * Note, using the already-retrieved memslot and __gfn_to_hva_memslot() @@ -698,19 +698,23 @@ static int host_pfn_mapping_level(struct kvm *kvm, gf= n_t gfn, * value) and then p*d_offset() walks into the target huge page instead * of the old page table (sees the new value). */ - pgd =3D pgdp_get(pgd_offset(kvm->mm, hva)); + pgdp =3D pgd_offset(kvm->mm, hva); + pgd =3D pgdp_get(pgdp); if (pgd_none(pgd)) goto out; =20 - p4d =3D p4dp_get(p4d_offset(&pgd, hva)); + p4dp =3D p4d_offset_lockless(pgdp, pgd, hva); + p4d =3D p4dp_get(p4dp); if (p4d_none(p4d) || !p4d_present(p4d)) goto out; =20 - pud =3D pudp_get(pud_offset(&p4d, hva)); + pudp =3D pud_offset_lockless(p4dp, p4d, hva); + pud =3D pudp_get(pudp); if (pud_none(pud) || !pud_present(pud)) goto out; =20 - pmd =3D pmdp_get(pmd_offset(&pud, hva)); + pmdp =3D pmd_offset_lockless(pudp, pud, hva); + pmd =3D pmdp_get(pmdp); if (pmd_none(pmd) || !pmd_present(pmd)) goto out; =20 --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D675A486E69; Mon, 21 Sep 2026 10:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988266; cv=none; b=unT1wzjdcbJ+tOZxRbpbMM5qg+Pa8d8XcUFqQaO5AnlLhm232PDhxzb57nUkv3aloiOPrbGnK0KvrdqJUm2ZqqEts4+aumOi0wgQStIv2ge4CQ9+xUEF0pG2W/CdFaIdgACX2G+0B9WmbumZd0ZYd38FHxAhHFUtgR7B72Lmx44= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988266; c=relaxed/simple; bh=KiXQHGuhfMlh69+vDPC8O/k2WRfNJbgSm7Gu8QYG2aY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JLc3Lv4vABtAuksXz/i4l+KE7oEJO8mGp5jVPMrHYB/dV0nLdd+0+fsJQFzxIfK5RrkZdUE2JH3yYIxk9grmEppJ9wW5SI9Z+89kbA851excbJj8884BbincOZpDE1nqNMFd5/gs86h7oRaqoz05vlXHAFR9XTcii+jnHgQFPso= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=acOOrhxG; arc=none smtp.client-ip=217.140.110.172 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.b="acOOrhxG" 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 BBDEA1D13; Mon, 21 Sep 2026 03:57:40 -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 091B03F86C; Mon, 21 Sep 2026 03:57:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988264; bh=KiXQHGuhfMlh69+vDPC8O/k2WRfNJbgSm7Gu8QYG2aY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=acOOrhxGt24gm0TRAbQDXTQ9bBBp3Bj56XEBgnVOotqP+qiG7YJVhkcGW+xrwcb2a USmOAWcGi1YbzXXz+GFEN3it02D0/yYErePOTiGnto1f4lTnlkzD119S+FRZwhYPnm tRzn3ffsctlJfSwSOqlNejAXL1s2WdK0ogZ6I3bk= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:32 +0100 Subject: [PATCH 10/21] riscv: kvm: remove stack copy address of pXd in pXd_offset() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-10-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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=2080; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=KiXQHGuhfMlh69+vDPC8O/k2WRfNJbgSm7Gu8QYG2aY=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1P/lW6m6B1mTpRP6bpmebttNlScQQ9pFLGp +TLi5+fe6mJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENTwAKCRBt1cPRWsUx MzRxDACbWH4JATwoeni8FvpOIlAtj13UB3cW+c35hpt9oGzmcDZ+kjukMqctT6h2L2N5pHpsDgV vmayApcPPlarU6k8ZQpvBb7KJ1cYGUNPU474TxmX2vBVITXF3mbHMgRoEbIqhbltrGT8uBoVyCo KgDVi+KDgkbOrzeKUfL6m7D9VLVgLaNDamzt7DvVVqiCTUJRUSmv5DxuOqilRyUUWgRg66cEh0f fNgaSTYxDBBBOqd6xi9vA+7R/D8gaYslxHah31gen9zR/KRiSCVO8oSWE7qao685EtRbhlF8C/w 3me3Bkz4+kVb6rnCMuV0mt4yG2kuNCmzvgORQC8TBdutWp1pmcamhxcvxqCjL3WpVuFoo+iztFK qrF8TVoPbY7wwUVBdeD8kZ/Lg3FUZf4niWpEI3+/yEQZqeiImeTuLoEd2uelVxIt79PiLiF5ED/ 4IEDN1fi5/NH35mcjNFuUFg9VZ1c9qX2muen0gS+XMIvV6EzYFJk5Fv4kXIUQGEyvngIk= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 The behaviour of pXdp_get() will change with generic compile-time folded page tables. To prepare for that, rework get_hva_mapping_size() to avoid use of a stack copy of a pXd and pass it as argument to pXd_offset() so that the folded entries value is ignored. Replace direct uses of stack-based pXd values with pXd_offset_lockless() and there should be no functional change. Reviewed-by: David Hildenbrand (Arm) Signed-off-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum --- arch/riscv/kvm/mmu.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/mmu.c b/arch/riscv/kvm/mmu.c index 5c5c77f98bf0f..b97224e14fc16 100644 --- a/arch/riscv/kvm/mmu.c +++ b/arch/riscv/kvm/mmu.c @@ -450,10 +450,10 @@ static int get_hva_mapping_size(struct kvm *kvm, { int size =3D PAGE_SIZE; unsigned long flags; - pgd_t pgd; - p4d_t p4d; - pud_t pud; - pmd_t pmd; + pgd_t *pgdp, pgd; + p4d_t *p4dp, p4d; + pud_t *pudp, pud; + pmd_t *pmdp, pmd; =20 /* * Disable IRQs to prevent concurrent tear down of host page tables, @@ -469,15 +469,18 @@ static int get_hva_mapping_size(struct kvm *kvm, * value) and then p*d_offset() walks into the target huge page instead * of the old page table (sees the new value). */ - pgd =3D pgdp_get(pgd_offset(kvm->mm, hva)); + pgdp =3D pgd_offset(kvm->mm, hva); + pgd =3D pgdp_get(pgdp); if (pgd_none(pgd)) goto out; =20 - p4d =3D p4dp_get(p4d_offset(&pgd, hva)); + p4dp =3D p4d_offset_lockless(pgdp, pgd, hva); + p4d =3D p4dp_get(p4dp); if (p4d_none(p4d) || !p4d_present(p4d)) goto out; =20 - pud =3D pudp_get(pud_offset(&p4d, hva)); + pudp =3D pud_offset_lockless(p4dp, p4d, hva); + pud =3D pudp_get(pudp); if (pud_none(pud) || !pud_present(pud)) goto out; =20 @@ -486,7 +489,8 @@ static int get_hva_mapping_size(struct kvm *kvm, goto out; } =20 - pmd =3D pmdp_get(pmd_offset(&pud, hva)); + pmdp =3D pmd_offset_lockless(pudp, pud, hva); + pmd =3D pmdp_get(pmdp); if (pmd_none(pmd) || !pmd_present(pmd)) goto out; =20 --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 68E66486E69; Mon, 21 Sep 2026 10:57:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988274; cv=none; b=SupWfdB47aJdmv2OjDNuL3ouk8lbTI+iTKf05AXXwArci7HDdLaHFoU+wp3oXfY3h1TYEtLH8SQmLSNjKpfPPHNdA4nHt9MblCFfmvtjW5WZy9WQL5+3r5e7reCtbIbzaK9R4+jmCqt2Rc7m1fH5Knq1dH8liNIPTIHpjfEKawo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988274; c=relaxed/simple; bh=uF4DfWzXa9EkGf1I0Bn2aL3RfBnTbP81TBjbavbJ8QQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AqG870ZGWuoberLWRxO6fJvuViEE1STdWLLkFKm3LrU8cqrNR5SDg6Y5s6XgOmtQUnzVUnkMMqOo6dDPF73XlGFBWVeYPUO92SnoX3rDTT2wRB40QXAzphL9JrsoQJLiq73+/dMQVKMvIrBQVcI/EEIiUBsFESvw5ZuO20ksFB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=b2oxv8G3; arc=none smtp.client-ip=217.140.110.172 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.b="b2oxv8G3" 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 589AC1CE0; Mon, 21 Sep 2026 03:57:48 -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 98F113F9AB; Mon, 21 Sep 2026 03:57:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988271; bh=uF4DfWzXa9EkGf1I0Bn2aL3RfBnTbP81TBjbavbJ8QQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=b2oxv8G3acXR+b4U8Ke9KSVZQ8NqKzHIB8Xl/ycl/nGOLEQlcX18PIjAeIg7B3tpb 7HmCy4J3ydk3qZfbtrFLpV4tABhoN+2/B17S+yQ+WsYgwEYTPLCQRkt0ZeSX/hLPMx Aa+nRIFl1reImGlNGptnuq9oq9dvqnppsyrc+NyE= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:33 +0100 Subject: [PATCH 11/21] riscv: mm: use proper set_pXd() for generic compile-time folded patable in vmalloc_fault() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-11-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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=3753; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=uF4DfWzXa9EkGf1I0Bn2aL3RfBnTbP81TBjbavbJ8QQ=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1QAg31Sog0FCjc3kuChuSeE5nwlfWLMD4sT IBC+fegfX2JAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUAAKCRBt1cPRWsUx Mx8TDACfGiY1tFbMNuqJzhqG74lnH8gGDp7+4K0KfmvivFAxuHooIWaalWIlCiXzXZGwXVbHHwy EPxRgkJ1uw1jlH3gDOGxNETf15cT+KdPWxc2IPcZjimn44GpN/tHq3ie/ILysREci576iJCfLl4 hZhn/31gf80m5wAoruCFpkdOoDK9vI2gDH1iAE7dcktlPtXovnfLAUzOVfzwDk1sJuYI3BsByOn l1dM0H6rX2RhzKIfJT02RA3stLjqjS4aqMUOuIEyQ7uCm/vePyl/toLHSfNlXeAFt+vkDA1BaNk G2Mqub8YtbPcYMJILsZALUoZGulrUViemuEn1MQuFSk3xeW6LvdIps5z0pgD/hyMDOQMsf9zlaq 43upc2P7Di2WqF1BalL1zetYzreAC4iO8Ass4iBh3zl5KSk4v4cizRvztC13VZGm8bZN2nr/A/H LW9L0Tf5m0dkB2RXOoknui/VOBmrN6PvMrEVqP3go7fwbJPESPNAgPLiosUQHnJ16thBo= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 The behaviour of pXdp_get() will change with generic compile-time folded page tables, making it invalid to use set_pXd() with the result of pXdp_get(). Instead, the appropriate first-level set_pXd() must be paired with the corresponding pXdp_get(). Therefore, call the appropriate set_pXd() for generic compile-time folded page tables so that vmalloc_fault() continues to handle folded entries correctly when checking pXd_present(). There should be no functional change. Since most architectures use a similar pattern to handle vmalloc fault by syncing the faulted entry, it would be worth cleaning this up by introducing a common helper in the near future. Signed-off-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum --- arch/riscv/mm/fault.c | 52 ++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/arch/riscv/mm/fault.c b/arch/riscv/mm/fault.c index 04ed6f8acae4f..b2bcaf10d13f1 100644 --- a/arch/riscv/mm/fault.c +++ b/arch/riscv/mm/fault.c @@ -167,14 +167,16 @@ bad_area(struct pt_regs *regs, struct mm_struct *mm, = int code, =20 static inline void vmalloc_fault(struct pt_regs *regs, int code, unsigned = long addr) { - pgd_t *pgd, *pgd_k; - pud_t *pud_k; - p4d_t *p4d_k; - pmd_t *pmd_k; - pte_t *pte_k; + pgd_t *pgdp_k, *pgdp, pgd_k; + p4d_t *p4dp_k, *p4dp; + pud_t *pudp_k, *pudp, pud_k; + pmd_t *pmdp_k, *pmdp, pmd_k; + pte_t *ptep_k; int index; unsigned long pfn; =20 + BUILD_BUG_ON(CONFIG_PGTABLE_LEVELS !=3D 5 && CONFIG_PGTABLE_LEVELS !=3D 2= ); + /* User mode accesses just cause a SIGSEGV */ if (user_mode(regs)) return do_trap(regs, SIGSEGV, code, addr); @@ -189,39 +191,51 @@ static inline void vmalloc_fault(struct pt_regs *regs= , int code, unsigned long a */ index =3D pgd_index(addr); pfn =3D csr_read(CSR_SATP) & SATP_PPN; - pgd =3D (pgd_t *)pfn_to_virt(pfn) + index; - pgd_k =3D init_mm.pgd + index; =20 - if (!pgd_present(pgdp_get(pgd_k))) { + pgdp =3D (pgd_t *)pfn_to_virt(pfn) + index; + pgdp_k =3D init_mm.pgd + index; + + pgd_k =3D pgdp_get(pgdp_k); + if (!pgd_present(pgd_k)) { no_context(regs, addr); return; } - set_pgd(pgd, pgdp_get(pgd_k)); + if (CONFIG_PGTABLE_LEVELS =3D=3D 5) + set_pgd(pgdp, pgd_k); =20 - p4d_k =3D p4d_offset(pgd_k, addr); - if (!p4d_present(p4dp_get(p4d_k))) { + p4dp =3D p4d_offset(pgdp, addr); + p4dp_k =3D p4d_offset(pgdp_k, addr); + if (!p4d_present(p4dp_get(p4dp_k))) { no_context(regs, addr); return; } =20 - pud_k =3D pud_offset(p4d_k, addr); - if (!pud_present(pudp_get(pud_k))) { + pudp =3D pud_offset(p4dp, addr); + pudp_k =3D pud_offset(p4dp_k, addr); + + pud_k =3D pudp_get(pudp_k); + if (!pud_present(pud_k)) { no_context(regs, addr); return; } - if (pud_leaf(pudp_get(pud_k))) + if (pud_leaf(pud_k)) goto flush_tlb; =20 /* * Since the vmalloc area is global, it is unnecessary * to copy individual PTEs */ - pmd_k =3D pmd_offset(pud_k, addr); - if (!pmd_present(pmdp_get(pmd_k))) { + pmdp =3D pmd_offset(pudp, addr); + pmdp_k =3D pmd_offset(pudp_k, addr); + + pmd_k =3D pmdp_get(pmdp_k); + if (!pmd_present(pmd_k)) { no_context(regs, addr); return; } - if (pmd_leaf(pmdp_get(pmd_k))) + if (CONFIG_PGTABLE_LEVELS =3D=3D 2) + set_pmd(pmdp, pmd_k); + if (pmd_leaf(pmd_k)) goto flush_tlb; =20 /* @@ -230,8 +244,8 @@ static inline void vmalloc_fault(struct pt_regs *regs, = int code, unsigned long a * addresses. If we don't do this, this will just * silently loop forever. */ - pte_k =3D pte_offset_kernel(pmd_k, addr); - if (!pte_present(ptep_get(pte_k))) { + ptep_k =3D pte_offset_kernel(pmdp_k, addr); + if (!pte_present(ptep_get(ptep_k))) { no_context(regs, addr); return; } --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EA73E48F039; Mon, 21 Sep 2026 10:57:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988281; cv=none; b=vBlQpgIbkKKvrXg+lz/zAJyem4pv4CHd8K/5gyPH3gxKGO7H02qlB6HXlhbH8FV+/Q0sD/B0Jb1OHqusp1D7iq8TAUTJAp0sgJmSgGGdpt8daaZKrVN5RwyF/HMS2tLd2f2EOGImR3HjhMpV/tkAuiWKYx0DjGkMeQjkazToIB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988281; c=relaxed/simple; bh=Y8EwOxLNbw4UfgGXcWJN4XYR7fgRn1Moj06vSGiaGhw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gY2MVFK6Cpm4bDpyF9qQY6Xx08FhsoH3wNGdM+sVPSmeFlcFDML2Dkzf6Ko03F+aYdr43g8sc6Ruwe69RFZRO4EaY1TVhxArqCULKGJr/++zXyY56qvnad8pab6ymXxCEUDWJn2DkSNV/co4ypMX/7gWNxEq8vNcQBMwWZa2YVI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=Acv2ig2s; arc=none smtp.client-ip=217.140.110.172 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.b="Acv2ig2s" 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 E73E61570; Mon, 21 Sep 2026 03:57:55 -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 3592C3F86C; Mon, 21 Sep 2026 03:57:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988279; bh=Y8EwOxLNbw4UfgGXcWJN4XYR7fgRn1Moj06vSGiaGhw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Acv2ig2sdtBQm1rWWS02siT0WU0ZatIgo532lzW7QnReSNXQH1ySM+8DelzsQa55e 0TVi9G11NlTKdUH74Sp6k0cO+qCtLFbvrelhmtDh0SsbAsGd/j0A7ufpMeXn2Es2yz Xmxo3CKqJ1ia+7cA6vpupVw3peojMkInMbV3ExN4= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:34 +0100 Subject: [PATCH 12/21] mm/pgtable: redefine PGTABLE_LEVEL enum with ascend order from PGD Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-12-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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=1282; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=Y8EwOxLNbw4UfgGXcWJN4XYR7fgRn1Moj06vSGiaGhw=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1QUaPfd/TdZdMCVJig81AKqOVJKDuhmr9iK mpmDD+NEl+JAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUAAKCRBt1cPRWsUx MzrLC/9aTw7wgAVsVSkyAx9JoerSy/E93mC4rUycb4dvDtSfmjpnvXqlvMNOZ0X4B5Tw+BHjFpL 9jH7TfpouVsi3ilgGlYWmhFqe3BTMspr76UeuII7d1gg8OfdV923kIjDcgioZarrRikees4YSip 5uqKCkUTlyqCGmKOuU7nhOAK7tW4wYh0FmSWSpiG0PLWIeBMOwyBw/zW8ypmQTnMIIB1wuLzs/u 7ROCVrCCjQ/dan0IYAxg+t7qTPtpD8XuY7kE8NURgpEKId4bCFhy3U/wB3lIQdsLHM2mgGlnKYV zy6aNQBGpN9mKjDtE/bZGY6gmk+CVWrUNVbiSTouNAfpiUTsGa+e6Yl0KqWvXhip7lrYnaQWTzm Q2l8/kQPPW5++rC7+eeJkINpxVX3PFWYeBJwLOBF75Lr6+GAyvrtK5usO7NuLcJLTYaKd/1JKHL OxP80e+rles/44lu4BlVndGbnxkSWb4UFg7VdtjQ5e0MfYATc+XAacUtqoHmAK6Nsi+34= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 The PGTABLE_LEVEL enum values appear to be ordered in the opposite direction from their intended usage. Intuitively, higher page table levels should have smaller enum values, but PTE is currently assigned 0. For consistency and cleanup, reverse the enum value ordering. Since there is no current user relies on these numbers to be ascending from PTE->PGD, so it can be changed to be ascending from PGD->PTE, in the direction of the page table walk. Reviewed-by: David Hildenbrand (Arm) Signed-off-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum --- include/linux/pgtable.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index e3c8ab96941c5..3186096a6e130 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -2288,11 +2288,11 @@ static inline bool arch_has_pfn_modify_check(void) typedef unsigned int pgtbl_mod_mask; =20 enum pgtable_level { - PGTABLE_LEVEL_PTE =3D 0, - PGTABLE_LEVEL_PMD, - PGTABLE_LEVEL_PUD, + PGTABLE_LEVEL_PGD =3D 0, PGTABLE_LEVEL_P4D, - PGTABLE_LEVEL_PGD, + PGTABLE_LEVEL_PUD, + PGTABLE_LEVEL_PMD, + PGTABLE_LEVEL_PTE, }; =20 static inline const char *pgtable_level_to_str(enum pgtable_level level) --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 942E33BBFAE; Mon, 21 Sep 2026 10:58:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988289; cv=none; b=t0FNTUNL8t/+D5h+y5T+13WmpPdK4KMfVL+SD18lf41FeTTolZImJdiY6G0Jxu7yIvAqdUyHMzVWkASwnMVhB2WpZwl3XoVXJBBx3/83bJgaHv9u04h9oLVASNCP5hAw9sQlNJe5mYSRXsnVXVv+j34I7HdN55deTuUcJCR8VBU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988289; c=relaxed/simple; bh=QT9fPVqU5/4s3W6imYoTDQhJSgG9AGqR+95WBjnEkEc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DAjsLRKvr95+86P8A5X+sJWNY1gwSW9wfrJfKEeSj+w602sYnaVKlA1n3csWhCg1Okkv80cTTk1HwJFABNFlWbRCrtLKr/fNOM7Iqo5NDUuyYAPEzlOMtd+YFNnu9s2Ex/xMIKrZUZOyGXPVSemlQgxecw7Vlyqgk8zMlpjwhII= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=RapZB+cy; arc=none smtp.client-ip=217.140.110.172 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.b="RapZB+cy" 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 A69D01D13; Mon, 21 Sep 2026 03:58:03 -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 C5BB13F86C; Mon, 21 Sep 2026 03:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988287; bh=QT9fPVqU5/4s3W6imYoTDQhJSgG9AGqR+95WBjnEkEc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RapZB+cyvYCqcKuvvXP8Q5zCAZ8HtO5VfaCyq+X5aXl5qtuACKqvDvIUWmBHExBam zJtjhHKa+kKgXxR2PFLZdBznGeftmCGqlKRKH/Meqcz0kAc74vnCVEPpb/p/GT8OZQ nnGLTw5FRGFiKQx715GBOH6ozV8GlMY9H1RMMOo8= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:35 +0100 Subject: [PATCH 13/21] x86/mm: Introduce helper for checking direct map 1G page support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-13-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 , Sohil Mehta X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5614; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=cCsKnjI6qzm+njvp4POS4T02dkWd2WA7n/CKoGzKwuk=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1R2L2UpoT9CAW2mhYF4L0pEeRV4+Rs981h3 CWikwBSbGyJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUQAKCRBt1cPRWsUx MwunDADTJF7Ucnl/y729ahXOh1c+4bQ17vWVJkTrbFm8evuZKa1BZQ1DJXx5lXQnN2dTlpT7HX3 RFq17CtruESXdlm6fvsVMCx7BC2Hk/5varLSUEUD/USUM2ZFeJ5tjlPCfb10U6fFT0ZBusn9MZj nlnQfAV2nO8pa2iusqKGpXXdUFXVXI1doy+8AGcFEMlc9X1+2UfTHYFLC5/7gjghQUX0WSoW6Yg vatDG4UA42ssMXj3CIfFaS8+zsK2RNTPDMhELkhccaLuPoG0YHHHDp14BrmqS49ZU2TrZ06Aof5 +9FE+RnthbyGI/nJVcLFDppo0wfLK1apIBJVEwMgxmpPAbdh0O5KJ/Jy6Sz2cf2gQJYFy28LcQe 9FpQRoZgbkspXZeONETZOq1JRpFmftUCjsy0MMLMi7OgxA1ZYWogZ7ehZe7UnX9wJGGuLEjWdxZ 7vKImHWTNVCMFmS6RLqnAnx1JKcEZDVAPkafX7IaDBPOBJcSHJ1X1BVTjt4S0e/v9iAiU= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: Dave Hansen There is an existing variable (direct_gbpages) that says whether the kernel can and should use 1G pages in the direct map. It is driven by a bunch of other machinery. At least: 1. Hardware support for 1G pages 2. Kconfig support for 1G direct mappings 3. Kernel command line overrides Most code just checks the 'direct_gbpages' variable itself. But there are cases where 1G mappings are compile-time disabled (via X86_DIRECT_GBPAGES) and 'direct_gbpages' is always 0. Unfortunately, that constraint is invisible to the compiler. This opacity has been historically functionally harmless; it only leaves a bit of dead code. But, there are plans to tigthen up the compile-time checks around folded page table levels. The build will break if that dead code appears reachable to the compiler. Making the compile-time config visible to the compiler fixes the build. Add a helper to replace 'direct_gbpages' checks. Check the Kconfig option and base CPU support before looking at the variable. This lets the compiler optimize things better, especially collapse_pud_page() where most of the function can now be optimized out when the PUD level is folded. Notes: Use boot_cpu_has() instead of cpu_feature_enabled(). There's no required/disabled features for 1G pages themselves (X86_DIRECT_GBPAGES is for kernel mappings only) and the static_cpu_has() infrastructure is just gets in the compiler's way. This makes 64-bit build marginally larger (20 bytes in one compile) and 32-bit builds less marginally _smaller_ (~700 bytes). Signed-off-by: Dave Hansen Reviewed-by: Yeoreum Yun Tested-by: Yeoreum Yun Link: https://lore.kernel.org/all/20260902-dummy_ptxp3-v3-15-5d8f5b17c25c@a= rm.com/ [1] Reviewed-by: Sohil Mehta Tested-by: Muhammad Usama Anjum --- arch/x86/include/asm/pgtable.h | 14 ++++++++++++++ arch/x86/kernel/cpu/common.c | 2 +- arch/x86/kernel/machine_kexec_64.c | 2 +- arch/x86/mm/init.c | 2 +- arch/x86/mm/pat/set_memory.c | 6 +++--- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index d5f4917c1edcb..c7adc00d49863 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1163,6 +1163,20 @@ static inline int pgd_none(pgd_t pgd) #ifndef __ASSEMBLER__ =20 extern int direct_gbpages; +static inline bool direct_gbpages_enabled(void) +{ + /* Check the direct map config option: */ + if (!IS_ENABLED(CONFIG_X86_DIRECT_GBPAGES)) + return false; + + /* Check the CPU feature: */ + if (!boot_cpu_has(X86_FEATURE_GBPAGES)) + return false; + + /* Check the command-line and early setup variable: */ + return direct_gbpages; +} + void init_mem_mapping(void); void early_alloc_pgt_buf(void); void __init poking_init(void); diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index c7352827f491d..4693ba98ca380 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -2660,7 +2660,7 @@ void __init arch_cpu_finalize_init(void) * Right now we don't do that with gbpages because there seems * very little benefit for that case. */ - if (!direct_gbpages) + if (!direct_gbpages_enabled()) set_memory_4k((unsigned long)__va(0), 1); } else { fpu__init_check_bugs(); diff --git a/arch/x86/kernel/machine_kexec_64.c b/arch/x86/kernel/machine_k= exec_64.c index c3f4a389992da..0da0e89f2611a 100644 --- a/arch/x86/kernel/machine_kexec_64.c +++ b/arch/x86/kernel/machine_kexec_64.c @@ -257,7 +257,7 @@ static int init_pgtable(struct kimage *image, unsigned = long control_page) info.kernpg_flag |=3D _PAGE_ENC; } =20 - if (direct_gbpages) + if (direct_gbpages_enabled()) info.direct_gbpages =3D true; =20 for (i =3D 0; i < nr_pfn_mapped; i++) { diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 079f8c7e9e3cd..f0f4a06584c61 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -251,7 +251,7 @@ static void __init probe_page_size_mask(void) __default_kernel_pte_mask &=3D ~_PAGE_GLOBAL; =20 /* Enable 1 GB linear kernel mappings if available: */ - if (direct_gbpages && boot_cpu_has(X86_FEATURE_GBPAGES)) { + if (direct_gbpages_enabled()) { printk(KERN_INFO "Using GB pages for direct mapping\n"); page_size_mask |=3D 1 << PG_LEVEL_1G; } else { diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index a1a061d995b31..261dda5f9f57c 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -128,7 +128,7 @@ void arch_report_meminfo(struct seq_file *m) seq_printf(m, "DirectMap4M: %8lu kB\n", direct_pages_count[PG_LEVEL_2M] << 12); #endif - if (direct_gbpages) + if (direct_gbpages_enabled()) seq_printf(m, "DirectMap1G: %8lu kB\n", direct_pages_count[PG_LEVEL_1G] << 20); } @@ -1315,7 +1315,7 @@ static int collapse_pud_page(pud_t *pud, unsigned lon= g addr, pmd_t *pmd, first; int i; =20 - if (!direct_gbpages) + if (!direct_gbpages_enabled()) return 0; =20 addr &=3D PUD_MASK; @@ -1697,7 +1697,7 @@ static int populate_pud(struct cpa_data *cpa, unsigne= d long start, p4d_t *p4d, /* * Map everything starting from the Gb boundary, possibly with 1G pages */ - while (boot_cpu_has(X86_FEATURE_GBPAGES) && end - start >=3D PUD_SIZE) { + while (direct_gbpages_enabled() && end - start >=3D PUD_SIZE) { set_pud(pud, pud_mkhuge(pfn_pud(cpa->pfn, canon_pgprot(pud_pgprot)))); =20 --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39B8F489FDE; Mon, 21 Sep 2026 10:58:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988297; cv=none; b=lXabdLsHTHmX2aT2kPmmq2c5Ea5qCG6dWayzNQD2Dxs1Dn9FVUVncwFocNd0XQ3yHrzT9Tr3pOfuOJXw0WHijAP0osdebT5+8wj8Iqk44ut4S56vbojdtyUAW/nIGteaGtizZiuPEAy6A/gM+DER2S3ZvMfeqT/rAM/SympXEW4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988297; c=relaxed/simple; bh=zghhBXP63HUkMVsnVTW1BBI8m5GQHzJyarBmwmrVkLw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nOV4DOTg65o0Pdc7AsBORjhE7ya58XHU+hLohJBHAOeXberR42SzDoZaFbf+27Y9RWTX/e+zFmK5xeInMlgqYruNG9jmp+b9w08m5P3TWlJ3ZSPdNeDrUX/mLKftO/wX6MGlZmerxL8zWxJGA9QFFRCbQSrlLZEhEdo3g8G2rMk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=MorCeI/0; arc=none smtp.client-ip=217.140.110.172 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.b="MorCeI/0" 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 40BDB1570; Mon, 21 Sep 2026 03:58:11 -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 825133F86C; Mon, 21 Sep 2026 03:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988294; bh=zghhBXP63HUkMVsnVTW1BBI8m5GQHzJyarBmwmrVkLw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MorCeI/0C/ThGp2D4ZEh7K7qiGRxxQCGAsOHcPHI8GDUa1xn7PAojRccrrdxW6og8 7gC8n59mRHcXPujdGPAn1COCNTSdHIzjz22YYHLWyrX2pcSMdp+njUrasxT+e7EdHJ XyalCkCDo/UbMgMots6tY7qOdO97VEdNuudBqO4c= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:36 +0100 Subject: [PATCH 14/21] x86: mm: use pgtable_level enum in effective_prot_pXd() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-14-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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=2497; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=zghhBXP63HUkMVsnVTW1BBI8m5GQHzJyarBmwmrVkLw=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1RutA9R6RYKg0XGt206R+FZYSBvFY5A7m64 WCknKwpoKOJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUQAKCRBt1cPRWsUx M1QqC/48OSPJozKEnLVOpX6otIW9FV5BhnqTBmb/jwyRutaZTgzJxzVOUro/bD5JHER9PhjqHfC eNHCzQ1aUnfnS7hLDorqqVWwzassmuk8DAzqYuKYx91zEvDYa7JHkMxtVu+yZwGD4suG0HUTQf+ dBbV/wqn4/Ti6iKvRok/awM2egxq3wOCeRisJK0d/rzhD4FGVvxR1DillMtTLyoQbZfBChN9JQP NS9xULrwDo4o0EjfcCUWv39K5oJhzQyWbtp9oqdCn/su/PFFe/MqZkv7neLUboJQqVqggUuY8T9 0m+0FAwi7HeXPlZGKY54LikTFhGv8+Q1tjO3XDJqbLRmZjXxuoSNMR53I02cOkTtEfur207dk5u PqU8kFQ9uSI+wNPOym96FPcqi5SPQomkOAkxT1DTaDPdy9LP/KsdH6btJ2oVPH4ATfgpa/1ZL5h FjqEaVjHTPbvc7Tq5zEvipHN2jBSw3foGfVlRqGbIDxVSrv3u88KbKb0TC3yEmyALLVEY= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 Instead of using hard-coded integers in effective_prot_pXd(), use the page-table level enum so that architecture code does not need to know the numeric value of each page-table level, while also providing type safety. This also prepares for using generic MM helpers, mm_first_pgtable_level() which use symbolic names for page-table levels rather than integers. There should be no functional change. Reviewed-by: David Hildenbrand (Arm) Acked-by: Dave Hansen Signed-off-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum --- arch/x86/mm/dump_pagetables.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index 2afa7a23340e9..a18a61e732c3d 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -248,13 +248,13 @@ static void note_wx(struct pg_state *st, unsigned lon= g addr) (void *)st->start_address); } =20 -static void effective_prot(struct ptdump_state *pt_st, int level, u64 val) +static void effective_prot(struct ptdump_state *pt_st, enum pgtable_level = level, u64 val) { struct pg_state *st =3D container_of(pt_st, struct pg_state, ptdump); pgprotval_t prot =3D val & PTE_FLAGS_MASK; pgprotval_t effective; =20 - if (level > 0) { + if (level > PGTABLE_LEVEL_PGD) { pgprotval_t higher_prot =3D st->prot_levels[level - 1]; =20 effective =3D (higher_prot & prot & (_PAGE_USER | _PAGE_RW)) | @@ -268,27 +268,27 @@ static void effective_prot(struct ptdump_state *pt_st= , int level, u64 val) =20 static void effective_prot_pte(struct ptdump_state *st, pte_t pte) { - effective_prot(st, 4, pte_val(pte)); + effective_prot(st, PGTABLE_LEVEL_PTE, pte_val(pte)); } =20 static void effective_prot_pmd(struct ptdump_state *st, pmd_t pmd) { - effective_prot(st, 3, pmd_val(pmd)); + effective_prot(st, PGTABLE_LEVEL_PMD, pmd_val(pmd)); } =20 static void effective_prot_pud(struct ptdump_state *st, pud_t pud) { - effective_prot(st, 2, pud_val(pud)); + effective_prot(st, PGTABLE_LEVEL_PUD, pud_val(pud)); } =20 static void effective_prot_p4d(struct ptdump_state *st, p4d_t p4d) { - effective_prot(st, 1, p4d_val(p4d)); + effective_prot(st, PGTABLE_LEVEL_P4D, p4d_val(p4d)); } =20 static void effective_prot_pgd(struct ptdump_state *st, pgd_t pgd) { - effective_prot(st, 0, pgd_val(pgd)); + effective_prot(st, PGTABLE_LEVEL_PGD, pgd_val(pgd)); } =20 =20 --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1660489FDB; Mon, 21 Sep 2026 10:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988305; cv=none; b=uQjvtrvZ8M7u+inPQidWxc/9wDnzZo7iejVtkyOIDzKj8iGVhUzKcAdJPR3Sq0+B0G/Jh+WTFlluwKUIFPsReHrRjx69AF7HF6/wIBSTOSDk/U2BLJsRgwXItGC8m2ou9+IDDp2hTfjKvfrFhGoTAJAXNIrWWtpv7yzwC+ed1Eg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988305; c=relaxed/simple; bh=utmINuOW9x2oHy5QTeHH6EJ3UzwqSRAUlGRF/Q9Zr9w=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=tZBaVvSQZvHt4W6D6MIOWPhvz9nUiSUb9YRyy8kUblG52DhBsAG98/RsButlGLfAtPuoz0hzv2t2I+rHicHA/EoKFelVq0ljA6SfmGF4C88bLzqMYB/7mKopa523Io95HvOZ16oOH+HE4kHZBJWClYta4cOon5LmgknSopVjQSc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=YL9DNg9T; arc=none smtp.client-ip=217.140.110.172 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.b="YL9DNg9T" 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 E11331CE0; Mon, 21 Sep 2026 03:58:18 -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 1D95E3F86C; Mon, 21 Sep 2026 03:58:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988302; bh=utmINuOW9x2oHy5QTeHH6EJ3UzwqSRAUlGRF/Q9Zr9w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YL9DNg9TygaMLA+6ABmNi8Caz/etNmqKeQ4S1Php9cUgauo5VZuZq2oyMxzC1UnA3 sQjA6XjNfxb5Sfavvr4J5cPJV1ub4QtNsoXtsN7AYSIp8NmW+u+JOVu2sMIYjwVp23 5qp/anN+IE4UyqZMUn8TfJLXHPK8y+iHCUjHuDqo= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:37 +0100 Subject: [PATCH 15/21] x86: mm: carve out the generic compile-time folded pgtable case in effective_prot() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-15-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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=4850; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=utmINuOW9x2oHy5QTeHH6EJ3UzwqSRAUlGRF/Q9Zr9w=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1S1hUmFwKYutGjknVs3EfJa02hkOz1+sVrz Nt7e2HHFbCJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUgAKCRBt1cPRWsUx M4ztDACstHhQGkp2lzf026PXElKRVH5pN2UHEBDoHpCfhCT0PGU9NnuZhZ4adtSi0gmb5yJECZ+ GJwBPGy8ePxuxh87ECWLBX0FJ3HavCpZueK6xmBzdPeUtKfsJ+49BCX8+mZUijeksVmy9e4lDGX xYw9+oFa7r13sh5Ve1eySb5C1oLRmI0rxEWdGkluXK8YtAgV6KVVpodhZxZ4Y3LV10HExieovQA F1WyaWAf37wnCFSeOSYHSbdY5kQZdJbO7ODSG2U50AzNysgh7GBxfnFg+bEp5gzwDHxgQvvi49Q hNNx9zmXTq8lHsglrmKuYgeGrc27jkQ8iUowCFifM36aAC2VHLbJSa47WoQYELvVOGSpPuprEWM K+dyIkb+rkTaK7e38jUgeDVeyWxsz/Lj47nH49SY+no5kMkhgzP6Xg0V91KzOtE9E6SjkOBKrQR UJkaJf7EfpBVXQb//klJUcVH3CXodhSHG82mUtLSBs2nPuDnzGtHIUFOZDCkY2Al/QA/4= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 The behaviour of pXdp_get() will change with generic compile-time folded page tables. To prepare for that, rework effective_prot() to ignore any folded page tables entries, as it will unconditionally get called by ptdump core with pXd_val(pXdp_get()), and the value for folded entries really should be ignored. For this, introduce mm_first_pgtable_level() to identify the first real page-table level, move mm_pXd_folded() in !__ASSEMBLER__ and update effective_prot with higher_prot only when the current entry is not folded nor the first level. There should be no functional change. Reviewed-by: David Hildenbrand (Arm) Acked-by: Dave Hansen Signed-off-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum --- arch/x86/mm/dump_pagetables.c | 6 +++-- include/linux/pgtable.h | 61 ++++++++++++++++++++++++++++++++-------= ---- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/arch/x86/mm/dump_pagetables.c b/arch/x86/mm/dump_pagetables.c index a18a61e732c3d..2acbe41eb58f2 100644 --- a/arch/x86/mm/dump_pagetables.c +++ b/arch/x86/mm/dump_pagetables.c @@ -38,6 +38,7 @@ struct pg_state { bool check_wx; unsigned long wx_pages; struct seq_file *seq; + struct mm_struct *mm; }; =20 struct addr_marker { @@ -254,7 +255,7 @@ static void effective_prot(struct ptdump_state *pt_st, = enum pgtable_level level, pgprotval_t prot =3D val & PTE_FLAGS_MASK; pgprotval_t effective; =20 - if (level > PGTABLE_LEVEL_PGD) { + if (level > mm_first_pgtable_level(st->mm)) { pgprotval_t higher_prot =3D st->prot_levels[level - 1]; =20 effective =3D (higher_prot & prot & (_PAGE_USER | _PAGE_RW)) | @@ -452,7 +453,8 @@ bool ptdump_walk_pgd_level_core(struct seq_file *m, .level =3D -1, .to_dmesg =3D dmesg, .check_wx =3D checkwx, - .seq =3D m + .seq =3D m, + .mm =3D mm, }; =20 ptdump_walk_pgd(&st.ptdump, mm, pgd); diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 3186096a6e130..ed7101a13ce9c 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -392,6 +392,22 @@ static inline void lazy_mmu_mode_pause(void) {} static inline void lazy_mmu_mode_resume(void) {} #endif =20 +/* + * On some architectures it depends on the mm if the p4d/pud or pmd + * layer of the page table hierarchy is folded or not. + */ +#ifndef mm_p4d_folded +#define mm_p4d_folded(mm) __is_defined(__PAGETABLE_P4D_FOLDED) +#endif + +#ifndef mm_pud_folded +#define mm_pud_folded(mm) __is_defined(__PAGETABLE_PUD_FOLDED) +#endif + +#ifndef mm_pmd_folded +#define mm_pmd_folded(mm) __is_defined(__PAGETABLE_PMD_FOLDED) +#endif + #ifndef pte_batch_hint /** * pte_batch_hint - Number of pages that can be added to batch without sca= nning. @@ -2313,6 +2329,36 @@ static inline const char *pgtable_level_to_str(enum = pgtable_level level) } } =20 +#ifdef CONFIG_MMU +/** + * mm_first_pgtable_level - return the first non-folded page-table level + * @mm: The mm structure. + * + * With runtime- or compile-time folded page tables, page-table walkers + * effectively skip the folded top-level page tables, treating them as + * always-present entries pointing to the next lower-level page table. + * + * Return the first page-table level in @mm that is not folded. + * + * Return: the first non-folded page-table level. + */ +static inline enum pgtable_level mm_first_pgtable_level(struct mm_struct *= mm) +{ + /* + * "PMD folded" actually means "PMD is folded into PUD", and + * pud_present() etc. are hard-coded to look like present page table + * levels, whereby pmd_present() etc. contain real logic. + */ + if (mm_pmd_folded(mm)) + return PGTABLE_LEVEL_PMD; + if (mm_pud_folded(mm)) + return PGTABLE_LEVEL_PUD; + if (mm_p4d_folded(mm)) + return PGTABLE_LEVEL_P4D; + return PGTABLE_LEVEL_PGD; +} +#endif /* CONFIG_MMU */ + void ptval_bytes_to_hex_str(char *buf, size_t buf_size, const void *entry,= size_t entry_size); =20 #define ptval_to_str(buf, val) \ @@ -2349,21 +2395,6 @@ void ptval_bytes_to_hex_str(char *buf, size_t buf_si= ze, const void *entry, size_ #ifndef has_transparent_pud_hugepage #define has_transparent_pud_hugepage() IS_BUILTIN(CONFIG_HAVE_ARCH_TRANSPA= RENT_HUGEPAGE_PUD) #endif -/* - * On some architectures it depends on the mm if the p4d/pud or pmd - * layer of the page table hierarchy is folded or not. - */ -#ifndef mm_p4d_folded -#define mm_p4d_folded(mm) __is_defined(__PAGETABLE_P4D_FOLDED) -#endif - -#ifndef mm_pud_folded -#define mm_pud_folded(mm) __is_defined(__PAGETABLE_PUD_FOLDED) -#endif - -#ifndef mm_pmd_folded -#define mm_pmd_folded(mm) __is_defined(__PAGETABLE_PMD_FOLDED) -#endif =20 #ifndef p4d_offset_lockless #define p4d_offset_lockless(pgdp, pgd, address) p4d_offset(&(pgd), address) --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 607EF48AE17; Mon, 21 Sep 2026 10:58:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988311; cv=none; b=gm1N8JE0E7/6aookkBJYG+XQc+75KpvNd6N4sde81ZIFL6ULC8SYMFdT/GJgCcKqcHup/cQ0Q/0Pz2JdCqUcT32dtwpMhGI0XQ+Oc1f8LvSF0LxDEv9eDMvCLANRC9HbodauT/eWIeQcZejOzXCXu4hf+dh20DnH7Hl59cEmvqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988311; c=relaxed/simple; bh=fSF1q0uZ2D6D7eSotmHP8T3BZdnaiPG7UdplRIp/5/4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VhAHokSqnxZw7KmxOW8AR3vCPX4355Q803aryuBAAP7t9RvcTJXXN0ULM1LgunUpdQLwyYw5wi/4gctyXPqtl9wJtoH0Ebd/YXVtALGc2kDdrIHzrDpokx/2yZvg3OPFBr3mHKq3pNFaUoueH3v8qkMZHflHeAZtZqkIykJczKM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=X3s/HhVM; arc=none smtp.client-ip=217.140.110.172 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.b="X3s/HhVM" 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 4D1441CE0; Mon, 21 Sep 2026 03:58:26 -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 AD2943F9AB; Mon, 21 Sep 2026 03:58:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988309; bh=fSF1q0uZ2D6D7eSotmHP8T3BZdnaiPG7UdplRIp/5/4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=X3s/HhVMmwzSQHhqq9MFWj0m6FUOVQG5sixXBNURROyV6ePF/1f5WSnJzpvwZBNK1 QqsYNRvkgifOqK8lofwytBap6NlT+LrwggMFa6+2446aU5pOoBTY1kIi1cGTtqCZTN uHkua1WMDV/dmcg1aD+uOrvLGLVf0dKrwSWDm1Ag= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:38 +0100 Subject: [PATCH 16/21] openrisc/pgtable: drop __pmd_offset() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-16-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=883; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=HHmjFCiPkfuAa6Yg+gCAN1VqpmgkbnXOKSW8+pCvqDs=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1SPbcNzmztqXWyqwma14L9CzqkX4tJ7x7vo vWbJ/HD30CJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUgAKCRBt1cPRWsUx M4PADAC4wQdqV+mgxWbIBoHOjsRsIdJ4n1uUYYBv3wqYHNgh5+2Lk0XLqzv6zPlZye8658zEGXj vgxv0IMjozo9kMQmRzUvCUgqElgfOwU8DUeEQsA3jlvHIGAwe+qRaQ0TO2J/59o6qpcHgJbdXh+ z/NlcJc72jKMSnH9rNqp4ajPHyXuddYrsjENQBZPndlr23wfYGGcWekO6uC2NH2OLbvRUOOySX9 FdxnXJVw3frabk+zVNtsYakl4/mWXZrhXG/zWh3Jnvq+4m6Dv0K4EUAtlRwizkYXph78QlNH4I1 R63HWezZlORLk45PXkp9zwMCQmssS+rzDgQf5tMm3+uvh8QGnqinH/0+s+zCmR4NZSeFg0JYM/9 Y2NbE8DNZ95kpUtUWkPyYG/9VYQNEejRP8eCknF95Fy7xSmh1ANcZfr515q2JunHbDNQJBtNjpr g4qJObrzFSR+5ZGT/ylRR9xgwQuj6B6Ug3pDRerJOBlq011A/stSkRMHiOCGWaN60k+y8= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" The macro is unused, and will collide with a folded page table helper. Let's just remove it. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- arch/openrisc/include/asm/pgtable.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/openrisc/include/asm/pgtable.h b/arch/openrisc/include/as= m/pgtable.h index 13afcc0bd8631..7fceed641610c 100644 --- a/arch/openrisc/include/asm/pgtable.h +++ b/arch/openrisc/include/asm/pgtable.h @@ -331,9 +331,6 @@ static inline unsigned long pmd_page_vaddr(pmd_t pmd) return ((unsigned long) __va(pmd_val(pmd) & PAGE_MASK)); } =20 -#define __pmd_offset(address) \ - (((address) >> PMD_SHIFT) & (PTRS_PER_PMD-1)) - #define PFN_PTE_SHIFT PAGE_SHIFT #define pte_pfn(x) ((unsigned long)(((x).pte)) >> PAGE_SHIFT) #define pfn_pte(pfn, prot) __pte((((pfn) << PAGE_SHIFT)) | pgprot_val(pro= t)) --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5AF948B395; Mon, 21 Sep 2026 10:58:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988320; cv=none; b=GoHi3ieBOiUUy+eTlS9MPiRfujH61BAJI5BNJ1IhZhCa6bNYlfRtE3TF4mxiba5z/pNQ/60+l4bYWQ3bKJ6uu9XdwQY3Ghmo+CwRTdtxUf0bdWTVeB2flG/y6GJUvMmgnwWYYbwx/bz+rgnv17PQYSe3Lj7AYotymEr3LsTOZq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988320; c=relaxed/simple; bh=3qwcredkJP47Q0knCs8r2zQMj6PgEaC6pvNuESy4rVM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qUQMdAAlSq/1isu0ClZsHDRzN8FXtkeBsaTyrPMWbHzT4Y+CwTcFXimKf9DnPrmgW0kTLu3YSHeI2/NfPZzSjja0f88L4BAcgSs/5aEGRzHatMI7Dngso0bbn2Ne5SfQZfCtcn2X7Jtj3f2L3o4EXZkigx9nM3Gd4I7Z3WoKQno= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=hvuE/Wi4; arc=none smtp.client-ip=217.140.110.172 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.b="hvuE/Wi4" 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 BC8271CE0; Mon, 21 Sep 2026 03:58:33 -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 2873B3F86C; Mon, 21 Sep 2026 03:58:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988317; bh=3qwcredkJP47Q0knCs8r2zQMj6PgEaC6pvNuESy4rVM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hvuE/Wi4k3zHRTGvhHLv7qEZuHMY0xnCn6XOItTYrVn+OhipX/sBYMg25561UiIq3 RpT94PSQayXRgO948FTi0TvDbCYL9jwft2tj6/+iYiehoSFPT1g9OkC7kpfEpgFV89 zO5jMOW720AB5rQiJwGMMmHqgxDSFh7JsyEh20Bc= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:39 +0100 Subject: [PATCH 17/21] mm/pgtable: optimize pmdp_get() and friends for folded pagetable levels Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-17-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5359; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=7UYhDG8FvnoAk5ImIUgRe9XhRYP6zIOaKvnUSG6ABJs=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1SDGUx6nLBP2PHlkqQ+8YQPh+FyMpTUJuzJ +fXJW3H6CuJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUgAKCRBt1cPRWsUx M62wDADAwg1hY8opnURHDTbmR+179cx+II2vp1HY3eo35AaSKrx1jvffrnZWJqYFfnBzEUSV6OP 5oz6pcOFi8UaycBOhl6+nbv7WYWEKFEMw2nws9PxMsG4TWkOo4vg8lFmAyJfvTcpJ6VpJX8/3bR qA4Bbw3fL6S8GvQCkbFEmlMEiUy7XMqR1Gof6YfRWaRe7MSmI6TC14tG6+tyRaWiv/rJFMQhi5s v9nAqgmlMUK3n3CEwzMBJbncThbAoPLw5JV1klO8AhpvIJELYXRS2lfZYRhIJJ0j4ZVl5j1I49I VGHRhtxgWsDapA6Uyk58HvSQp+OUHXBMA+E7uXiuVwxSbOCCVCs8PhJo4q/Z3XRhc+zurBuQAvF pJrlszQK4neSzr29XYPyO8+s2mYY2IhfI1niO+AYhrf/KNp1UEoD3bqem3YQ0E0ny+ZOuiT4cm6 MMLCksddzOWDUnLePHxOO36Gtb/TZ4KqT0Iz0+W5+PEPoZdrCbcHpRzzYnOc+mNU0An18= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" Using pmdp_get() and friends in common code on a kernel config with folded page tables is suboptimal: they default to a READ_ONCE(), forcing the compiler to actually read that value even though it will not actually be used afterwards. This was recently reported by Christophe Leroy [1] and block conversion of more common code to pmdp_get() and friends. (using pgdp_get() as one example) Most of the code ignores the result from pgdp_get() on configs with folded page tables entirely, as it's hardcoded: pgd_present()=3D=3D1 && pgd_leaf()=3D=3Dfalse Common code will just treat it as a "this is a page table" and call p4d_offset() or p4d_offset_lockless() for the next lower level, where the obtained pgdp_get() result is ignored entirely. So, return a dummy value and avoid any memory reads. There is a catch, though: 1) If code calls pgd_val() and somehow relies on the data, it would now see dummy values. The code really must be aware of folded page table levels. Fortunately, code usually ignores pgd_val() completely for page tables (with ptdump being one exception when calculating effective permissions). it's checked + fixed the x86 ptdump mechanism. 2) If code passes the pgd_t to a function that would work on the result, it would now see dummy values. The only concern is really passing the pgd_t on the stack as a pointer to p4d_offset(). Most code that would do that, should actually use p4d_offset_lockless(), which handles this properly. it's checked + fixed problematic instances. 3) Calling set_pgd() / pgd_page() / pgd_page_vaddr() with a pgd_t obtained = through pgdp_get(). There was once such case in riscv code with set_pgd(), which is fixed. As an example, this is the generated code for perf_get_page_size() with PGTABLE_LEVELS=3D3 on arm64: Before: 00000000000052a0 : ... 52dc: d53b4234 mrs x20, DAIF 52e0: d50343df msr DAIFSet, #0x3 ... 52fc: d35e9a69 ubfx x9, x19, #30, #9 /* pud_offset_lockl= ess() */ 5300: f9403508 ldr x8, [x8, #0x68] 5304: f869790a ldr x10, [x8, x9, lsl #3] /* pudp_get() */ 5308: f90007ea str x10, [sp, #0x8] 530c: f8697908 ldr x8, [x8, x9, lsl #3] /* pudp_get() */ ... 5360: 90000009 adrp x9, 0x5000 5364: 92746908 and x8, x8, #0x7ffffff000 5368: d3557675 ubfx x21, x19, #21, #9 /* pmd_offset_lockl= ess() */ ... 5394: f8757ac8 ldr x8, [x22, x21, lsl #3] /* pmdp_get() */ After: 0000000000052a0 : ... 52dc: d53b4234 mrs x20, DAIF 52e0: d50343df msr DAIFSet, #0x3 ... /* no pud_offset_lo= ckless() and pudp_get() */ 5318: 90000009 adrp x9, 0x5000 531c: 92746908 and x8, x8, #0x7ffffff000 5320: d3557675 ubfx x21, x19, #21, #9 /* pmd_offset_lockl= ess() */ ... 5334: f8757ac8 ldr x8, [x22, x21, lsl #3] /* pmdp_get() */ [1] https://lore.kernel.org/all/0019d675-ce3d-4a5c-89ed-f126c45145c9@kernel= .org/ Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- include/asm-generic/pgtable-nop4d.h | 8 ++++++++ include/asm-generic/pgtable-nopmd.h | 8 ++++++++ include/asm-generic/pgtable-nopud.h | 8 ++++++++ 3 files changed, 24 insertions(+) diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgta= ble-nop4d.h index 019c3f074b771..acd62ee233536 100644 --- a/include/asm-generic/pgtable-nop4d.h +++ b/include/asm-generic/pgtable-nop4d.h @@ -34,6 +34,14 @@ static inline bool pgd_leaf(pgd_t pgd) { return false; } */ #define set_pgd(pgdptr, pgdval) set_p4d((p4d_t *)(pgdptr), (p4d_t) { pgdva= l }) =20 +static inline pgd_t pgdp_get(pgd_t *pgdp) +{ + pgd_t dummy =3D { 0 }; + + return dummy; +} +#define pgdp_get pgdp_get + static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address) { return (p4d_t *)pgd; diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgta= ble-nopmd.h index 1dd5b165234be..9322f07ddf1ef 100644 --- a/include/asm-generic/pgtable-nopmd.h +++ b/include/asm-generic/pgtable-nopmd.h @@ -43,6 +43,14 @@ static inline void pud_clear(pud_t *pud) { } */ #define set_pud(pudptr, pudval) set_pmd((pmd_t *)(pudptr), (pmd_t) { pud= val }) =20 +static inline pud_t pudp_get(pud_t *pudp) +{ + pud_t dummy =3D { 0 }; + + return dummy; +} +#define pudp_get pudp_get + static inline pmd_t * pmd_offset(pud_t * pud, unsigned long address) { return (pmd_t *)pud; diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgta= ble-nopud.h index 5a2b0a81ae197..8f01abbb00503 100644 --- a/include/asm-generic/pgtable-nopud.h +++ b/include/asm-generic/pgtable-nopud.h @@ -41,6 +41,14 @@ static inline bool p4d_leaf(p4d_t p4d) { return false; } */ #define set_p4d(p4dptr, p4dval) set_pud((pud_t *)(p4dptr), (pud_t) { p4dva= l }) =20 +static inline p4d_t p4dp_get(p4d_t *p4dp) +{ + p4d_t dummy =3D { 0 }; + + return dummy; +} +#define p4dp_get p4dp_get + static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address) { return (pud_t *)p4d; --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CA77449365C; Mon, 21 Sep 2026 10:58:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988329; cv=none; b=fsKkrbv0f1iCj5H0VQlILQEVyoeDycrvyJoX5DfOvbLYn5pndwl17hTwvE6UrEnEYdXlRYTumO1TZhKjzIzTXkQEpjPBqvWUA8V8BgaOWvwzH3Lgtd7HTOl8WQyIS5HSsztVzZadBGe2Z7GRubbqperN576HQ1T0vrcFQ1M1JzA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988329; c=relaxed/simple; bh=wV1Rko2jO3CBq2XkkZPZAq0K5FwAUXTua1cF3CtPA0Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XQCMwSSRfoSi7RI9zj1SiQvyWIF9ui23YQ+KXL6RngpHbG7Sya4ygiC1qJKWJP/TDOgjMHVmj3rp8c73scIVFDUNy57uAb98aeFFagCyqOxcR19F8cGLmTmBF/fizNTRclSFb0DfsmQEwYphYpV5h8a2U4AwZ9L7k9mFBFNhVrs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=M69yt9JN; arc=none smtp.client-ip=217.140.110.172 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.b="M69yt9JN" 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 34A151D13; Mon, 21 Sep 2026 03:58:41 -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 97C853F86C; Mon, 21 Sep 2026 03:58:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988324; bh=wV1Rko2jO3CBq2XkkZPZAq0K5FwAUXTua1cF3CtPA0Q=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=M69yt9JNZZOu07m2eMUXUE7kOouVrZ1x/HOoeFBr+noA27ltzymcz/8DIQ6+nWmeA Kl3YQM/RF8UVLyxHtt3QuNclLtl3PDdDABqDQoBAZLOMcsdrQA4rXueqGUmFuELMoB 9zMg9PMSynQbdAYiXfxLlCV+wg7YHxMgGrf3BDy8= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:40 +0100 Subject: [PATCH 18/21] mm/pgtable: catch abuse of folded dummy pgd_t/p4d_t/pud_t Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-18-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5536; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=l+aFtD+gf169DFuCaai5cwdW0dtCP9VrudnD5mceiXU=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1TVJ8WMEBMvMxpLmee8FhBXqTgwIAqkv6F1 pZhimntkJuJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUwAKCRBt1cPRWsUx M4WLC/sEXXfDYkutq+XAp2eq4pnDsW6DCLQnTbXxUpR54sRfzZL7IThTi7dm/8TREnCeAjQzxSb kIEls9cerKZbqCqvoo1jxqfAow3waQ7/FpfR3e0QBaKEGCVcOXbUkfZZWme1N1fIZs/5+T1FMM/ Wmno7S+8Qmijp4q76nSESjDriWdGU45ti1Gddg0VHaL4Ge1gjs2m8fjk8fQ2zm44AYbJF6QQype 07q+r9nZBtf283PQwCq+ujgtbmj0quciFUubtzKIEftdItMvCx4D6aFGlWt+xl7NNnjVXMIoIZM gt3foVK/bmLXFR9La90KMSAFxgXzS9YScthuZoL/8m5YdttG8nj+VUuQLBgZrXRgXiYwY74HCui x4bKpVVRItDotIL4T6torQgNsStmEkdDf8yASZ0OxkhEpIjSDLWHoD83ROEl9Vi5hatDNf6ua9t S2qYUC7sUdkPljmrhJZ3t7h+vrNE+C81GHrh7eq0o3aM1EqMeCg95MTIGsPmP+lkqMc+c= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" Catch and prevent all abuse with dummy values on the stack similar to: pud_t pud =3D pudp_get(pudp); pmd_t *pmdp =3D pud_offset(*pud, addr); While this approach relies on the compiler propagating constants, it should catch most of the issues in practice. It would have caught all the issues were found through manual inspection. To avoid build issues particularly on x86, where pgd_val() might not be around in some inclusion paths, perform the new checks from wrapper macros. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- include/asm-generic/pgtable-nop4d.h | 23 ++++++++++++++++++----- include/asm-generic/pgtable-nopmd.h | 24 ++++++++++++++++++------ include/asm-generic/pgtable-nopud.h | 24 ++++++++++++++++++------ 3 files changed, 54 insertions(+), 17 deletions(-) diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgta= ble-nop4d.h index acd62ee233536..2d86325235da5 100644 --- a/include/asm-generic/pgtable-nop4d.h +++ b/include/asm-generic/pgtable-nop4d.h @@ -34,7 +34,7 @@ static inline bool pgd_leaf(pgd_t pgd) { return false; } */ #define set_pgd(pgdptr, pgdval) set_p4d((p4d_t *)(pgdptr), (p4d_t) { pgdva= l }) =20 -static inline pgd_t pgdp_get(pgd_t *pgdp) +static __always_inline pgd_t pgdp_get(pgd_t *pgdp) { pgd_t dummy =3D { 0 }; =20 @@ -42,17 +42,30 @@ static inline pgd_t pgdp_get(pgd_t *pgdp) } #define pgdp_get pgdp_get =20 -static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address) +#define pgd_check_dummy(pgd) BUILD_BUG_ON(__builtin_constant_p(pgd_val(pgd= ))) + +static __always_inline p4d_t *__p4d_offset(pgd_t *pgdp, unsigned long addr= ess) { - return (p4d_t *)pgd; + return (p4d_t *)pgdp; } =20 -static inline p4d_t *p4d_offset_lockless(pgd_t *pgdp, pgd_t pgd, +#define p4d_offset(pgdp, address) \ +({ \ + pgd_check_dummy(*(pgdp)); \ + __p4d_offset(pgdp, address); \ +}) + +static __always_inline p4d_t *__p4d_offset_lockless(pgd_t *pgdp, pgd_t pgd, unsigned long address) { return (p4d_t *)pgdp; } -#define p4d_offset_lockless p4d_offset_lockless + +#define p4d_offset_lockless(pgdp, pgd, address) \ +({ \ + pgd_check_dummy(*(pgdp)); \ + __p4d_offset_lockless(pgdp, pgd, address); \ +}) =20 #define p4d_val(x) (pgd_val((x).pgd)) #define __p4d(x) ((p4d_t) { __pgd(x) }) diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgta= ble-nopmd.h index 9322f07ddf1ef..bd40d3a5743ff 100644 --- a/include/asm-generic/pgtable-nopmd.h +++ b/include/asm-generic/pgtable-nopmd.h @@ -43,7 +43,7 @@ static inline void pud_clear(pud_t *pud) { } */ #define set_pud(pudptr, pudval) set_pmd((pmd_t *)(pudptr), (pmd_t) { pud= val }) =20 -static inline pud_t pudp_get(pud_t *pudp) +static __always_inline pud_t pudp_get(pud_t *pudp) { pud_t dummy =3D { 0 }; =20 @@ -51,18 +51,30 @@ static inline pud_t pudp_get(pud_t *pudp) } #define pudp_get pudp_get =20 -static inline pmd_t * pmd_offset(pud_t * pud, unsigned long address) +#define pud_check_dummy(pud) BUILD_BUG_ON(__builtin_constant_p(pud_val(pud= ))) + +static __always_inline pmd_t *__pmd_offset(pud_t *pudp, unsigned long addr= ess) { - return (pmd_t *)pud; + return (pmd_t *)pudp; } -#define pmd_offset pmd_offset =20 -static inline pmd_t *pmd_offset_lockless(pud_t *pudp, pud_t pud, +#define pmd_offset(pudp, address) \ +({ \ + pud_check_dummy(*(pudp)); \ + __pmd_offset(pudp, address); \ +}) + +static __always_inline pmd_t *__pmd_offset_lockless(pud_t *pudp, pud_t pud, unsigned long address) { return (pmd_t *)pudp; } -#define pmd_offset_lockless pmd_offset_lockless + +#define pmd_offset_lockless(pudp, pud, address) \ +({ \ + pud_check_dummy(*(pudp)); \ + __pmd_offset_lockless(pudp, pud, address); \ +}) =20 #define pmd_val(x) (pud_val((x).pud)) #define __pmd(x) ((pmd_t) { __pud(x) } ) diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgta= ble-nopud.h index 8f01abbb00503..7475d0bd0f2e0 100644 --- a/include/asm-generic/pgtable-nopud.h +++ b/include/asm-generic/pgtable-nopud.h @@ -41,7 +41,7 @@ static inline bool p4d_leaf(p4d_t p4d) { return false; } */ #define set_p4d(p4dptr, p4dval) set_pud((pud_t *)(p4dptr), (pud_t) { p4dva= l }) =20 -static inline p4d_t p4dp_get(p4d_t *p4dp) +static __always_inline p4d_t p4dp_get(p4d_t *p4dp) { p4d_t dummy =3D { 0 }; =20 @@ -49,18 +49,30 @@ static inline p4d_t p4dp_get(p4d_t *p4dp) } #define p4dp_get p4dp_get =20 -static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address) +#define p4d_check_dummy(p4d) BUILD_BUG_ON(__builtin_constant_p(p4d_val(p4d= ))) + +static __always_inline pud_t *__pud_offset(p4d_t *p4dp, unsigned long addr= ess) { - return (pud_t *)p4d; + return (pud_t *)p4dp; } -#define pud_offset pud_offset =20 -static inline pud_t *pud_offset_lockless(p4d_t *p4dp, p4d_t p4d, +#define pud_offset(p4dp, address) \ +({ \ + p4d_check_dummy(*(p4dp)); \ + __pud_offset(p4dp, address); \ +}) + +static __always_inline pud_t *__pud_offset_lockless(p4d_t *p4dp, p4d_t p4d, unsigned long address) { return (pud_t *)p4dp; } -#define pud_offset_lockless pud_offset_lockless + +#define pud_offset_lockless(p4dp, p4d, address) \ +({ \ + p4d_check_dummy(*(p4dp)); \ + __pud_offset_lockless(p4dp, p4d, address); \ +}) =20 #define pud_val(x) (p4d_val((x).p4d)) #define __pud(x) ((pud_t) { __p4d(x) }) --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 22AFF48CD7C; Mon, 21 Sep 2026 10:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988335; cv=none; b=czFX30iDCB9mQank1VMalcP+Q391ZrGFyc8owfCd0Me1TM0U+gTm9Q6mo9/bEe4ddg+rb+JylVns4/3L/YuwjlxL1bM2JB53a2HlAqzNUmPQqorjHs3LR8BMmE/WWmONMPHgjC2yrcag6f61DEJl4+sswgBVdkp3AyEIBkHvn5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988335; c=relaxed/simple; bh=dSuJLJ9ohCs7txtQHt7hy5Mg9PfzhT9ZTRhsbp3QTUc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uMROaVwgq5+rUqjI4o/+xBj3yf52XWC1QJ1XCbVfaGxbyKSehqfYlcu2+vR3jMWQhrh8HHDuJHMBXuxJp/XdgvBQE2zQ3erxpXazx0fp/PPcy7OyLIcheD/kBpoZKPqIS63DqYPJFgOb9gITJclSFl2GOpzgkHeUAz+OKpheENQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=BThdboLw; arc=none smtp.client-ip=217.140.110.172 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.b="BThdboLw" 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 C57631CE0; Mon, 21 Sep 2026 03:58:48 -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 12E133F86C; Mon, 21 Sep 2026 03:58:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988332; bh=dSuJLJ9ohCs7txtQHt7hy5Mg9PfzhT9ZTRhsbp3QTUc=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=BThdboLwJgWaXYoH9hZWEZBjiZRv2Fu3SH7AMV949zk04FGwQM/S7e44T41HHFqBc ig0U/2EjLwcRsv+kn9RsCmeVGvHrzU+JMOsKwYzE5TaT0Ma5zFoMq0vE69LvCBaH9/ 4ET22UaBocVm3SCd1ar8dSE+dmzg+C2+T55N2vcs= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:41 +0100 Subject: [PATCH 19/21] mm/pgtable: disallow calling (pgd|p4d|pud)_page, pgd_page_vaddr() and (p4d|pud)_pgtable with dummy Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-19-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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=3268; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=VRD/vI2+dr2wFISWOiD6XpoJffv8Fhm2BOtCv803wXw=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1Tk7kRq4iKLtEgxpTwxLYomoYS7bs7Di2hM iOcaArqGTSJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENUwAKCRBt1cPRWsUx M0sKC/9fNwlXps/S5pQLQVmMhjhsVPzMbJGpnIoLHcK+XvcblaBizi3oEaugKCqA4IADURZxi7N zeU9amkUNdxMyAtLqtqsPRdxMSu+j3HYk690xsRuu/io3DcfvB5D0j/q9hCj04SJ9Bh6IUiV17O gNPS5GYZCwInYoilXG5e+HDU5w+XUwHoO+31YrveczOJESkUQ629XwSLUYzTZszK4UTHSe8eHN7 WpArw7F0ghyhriT0dILPWFsphGS9NifdWOc2+ZQ/1vOfre04d8kJHQb36FIwB6SFR7yI/luwSuw 5RS5NpbJ58nx0AUey7RNro8jvW+HJmYnG9NO6ooeCMeXaKWbwC0g4p0lpKTUN6ZFzwon0SGwno3 YUiLEt32U5HAd7gBIVuvVL/IZo0r+8jfF97cQKOV05fH01cS47H2K1DIwwEQt7PMkVszvEnPgEU pitE91INdVgJpvsLhPH3gte8+ox1sUn6LlA7pzFKeTV7DYzVwjulFjYbnWcQM6VW58Nd8= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" These helpers silently fallback to the folded helpers. With e.g., pdgp_get() returning dummy values, pgd_page_vaddr(pgdp_get(pgdp)) will now behave differently than pgd_page_vaddr(*pgdp). Disallow calling (pgd|p4d|pud)_page() entirely, and catch when passing a dummy value to pgd_page_vaddr() and (p4d|pud)_pgtable. This will catch most abuse of dummy pXdp value at compile time -- so far there were none, and it better stay that way. Signed-off-by: David Hildenbrand (Arm) Co-developed-by: Yeoreum Yun Signed-off-by: Yeoreum Yun Tested-by: Muhammad Usama Anjum --- include/asm-generic/pgtable-nop4d.h | 8 ++++++-- include/asm-generic/pgtable-nopmd.h | 8 ++++++-- include/asm-generic/pgtable-nopud.h | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/include/asm-generic/pgtable-nop4d.h b/include/asm-generic/pgta= ble-nop4d.h index 2d86325235da5..d2dccf7542da5 100644 --- a/include/asm-generic/pgtable-nop4d.h +++ b/include/asm-generic/pgtable-nop4d.h @@ -70,8 +70,12 @@ static __always_inline p4d_t *__p4d_offset_lockless(pgd_= t *pgdp, pgd_t pgd, #define p4d_val(x) (pgd_val((x).pgd)) #define __p4d(x) ((p4d_t) { __pgd(x) }) =20 -#define pgd_page(pgd) (p4d_page((p4d_t){ pgd })) -#define pgd_page_vaddr(pgd) ((unsigned long)(p4d_pgtable((p4d_t){ pgd })= )) +#define pgd_page(pgd) ({ BUILD_BUG(); (struct page *)NULL; }) +#define pgd_page_vaddr(pgd) \ +({ \ + pgd_check_dummy(pgd); \ + (unsigned long)p4d_pgtable((p4d_t) { pgd }); \ +}) =20 /* * allocating and freeing a p4d is trivial: the 1-entry p4d is diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgta= ble-nopmd.h index bd40d3a5743ff..2afbf2d8659dc 100644 --- a/include/asm-generic/pgtable-nopmd.h +++ b/include/asm-generic/pgtable-nopmd.h @@ -79,8 +79,12 @@ static __always_inline pmd_t *__pmd_offset_lockless(pud_= t *pudp, pud_t pud, #define pmd_val(x) (pud_val((x).pud)) #define __pmd(x) ((pmd_t) { __pud(x) } ) =20 -#define pud_page(pud) (pmd_page((pmd_t){ pud })) -#define pud_pgtable(pud) ((pmd_t *)(pmd_page_vaddr((pmd_t){ pud }))) +#define pud_page(pud) ({ BUILD_BUG(); (struct page *)NULL; }) +#define pud_pgtable(pud) \ +({ \ + pud_check_dummy(pud); \ + ((pmd_t *)(pmd_page_vaddr((pmd_t) { pud }))); \ +}) =20 /* * allocating and freeing a pmd is trivial: the 1-entry pmd is diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgta= ble-nopud.h index 7475d0bd0f2e0..3264673c0c386 100644 --- a/include/asm-generic/pgtable-nopud.h +++ b/include/asm-generic/pgtable-nopud.h @@ -77,8 +77,12 @@ static __always_inline pud_t *__pud_offset_lockless(p4d_= t *p4dp, p4d_t p4d, #define pud_val(x) (p4d_val((x).p4d)) #define __pud(x) ((pud_t) { __p4d(x) }) =20 -#define p4d_page(p4d) (pud_page((pud_t){ p4d })) -#define p4d_pgtable(p4d) ((pud_t *)(pud_pgtable((pud_t){ p4d }))) +#define p4d_page(p4d) ({ BUILD_BUG(); (struct page *)NULL; }) +#define p4d_pgtable(p4d) \ +({ \ + p4d_check_dummy(p4d); \ + ((pud_t *)(pud_pgtable((pud_t) { p4d }))); \ +}) =20 /* * allocating and freeing a pud is trivial: the 1-entry pud is --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5797E495038; Mon, 21 Sep 2026 10:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988342; cv=none; b=ojWDoqEPRsibakw3a/Jp4cmci/Ufea2GCRHCS9faclSgWgX3Huqh9EKuRco0pzbwD4M66StInUEOcM7lQ8ECNyUi/3vCjs/ur5kuEg4YhIC/BqUJuAIzVyBKJmha2GY+JC8ZuStSjt9MoDTc7Dh+d6QxrYuL8I+HTI8bFLhDInU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988342; c=relaxed/simple; bh=Q9JupG6Ga9Yd5poWoXsf1ojyKybY/JhVHRMS9+yuENk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b7Svs+A0FL1XkJu5RkNxHjZ5YSS2TgsQQdKWYs0jx3Pkt8IId7ofeNAtlzHEtQ2ygc5ydxziQyRLHlnhnwnNfPBBXq64lJ3J34cDmDnhGjrhoqeNT8qaCHuGhQWN5GQA+HHkgPODsH4NIAkVJNJVsVD4NL/Kw1MRrdIdF2lnj7A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=kmjhOZGe; arc=none smtp.client-ip=217.140.110.172 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.b="kmjhOZGe" 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 62E391CE0; Mon, 21 Sep 2026 03:58:56 -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 A293E3F86C; Mon, 21 Sep 2026 03:58:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988339; bh=Q9JupG6Ga9Yd5poWoXsf1ojyKybY/JhVHRMS9+yuENk=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kmjhOZGe+rvAPdtHgOvZ8+JXt0CRvIYWoLtj8YaQaF0AkkC4mYVfO9EPYYfzbkXIl 6tQP27Sypv/SsUcb0h6O79QmKuhdb/AB7Dc1Az8zsHHG1G0Hek65AToTqhTykZhAWQ g9rIbsE9klE6+jtdIrSRugu76i8wias9USMHeLT8= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:42 +0100 Subject: [PATCH 20/21] mm/pgtable: disallow calling folded set_pgd/set_p4d/set_pud with dummy Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-20-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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=3423; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=wn+xbNqkdezctD1uOfR77s9+bFTC1HhX6zz+en43LNA=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1UuhWv4I3FDWdg/j+kldAjB8reMz42JzLq7 0YDZbKbMleJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENVAAKCRBt1cPRWsUx M6vtDACSfqly9thwjD7kl8mtPM+GTHEk5P3hm5m3IcHM/yuady/yC8uUCYqEGqoqo0+xVZg5dgc DittGiSonPPEQke2O5H2aGKT7mRrcR7TcXtn312UQhs/CXyL6IytQkZSPwYBo+4XndAU67RxoqN Cbsb2z1qPHth4uMqDPK0ebT4y8OryhIDkXSGTvJPERdR6MDhQVkGseyybG2Mk2Ba9mBzPj+/EOe M61uV5vI5bCjaQGTix6ZM+pGrQfDWmTcNYaiK88gLoLnHbs2067hK4HrTuFOSYvs+elrKeXkg6X +eGlZclNAyJaHSTztQxSdmDlcYZMkFDaIbj3QcEmslWhN2UJGwcz23nYG4e4X4Z0TSSGKhoFWM4 508raZYgajEUFud/R93/AmlmYmuBoZ2zSp+pZtkt7f2JgxqjyQ0/oDk7EsKaVz8Nf3HQCxEIu7A GuAMHSv7/yJ6SXa9h7ifoRm+G9lXvGUSHQEFgv689N84mIZhD8joOcXHWX0dJvUOyz0WU= 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 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 Tested-by: Muhammad Usama Anjum --- 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/pgta= ble-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;= } =20 #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) { pgdva= l }) + +#define set_pgd(pgdptr, pgdval) \ +({ \ + pgd_check_dummy(pgdval); \ + set_p4d((p4d_t *)(pgdptr), (p4d_t) { pgdval }); \ +}) =20 static __always_inline pgd_t pgdp_get(pgd_t *pgdp) { diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgta= ble-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) { } =20 #define pud_populate(mm, pmd, pte) do { } while (0) =20 -/* - * (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) { pud= val }) +#define set_pud(pudptr, pudval) \ +({ \ + pud_check_dummy(pudval); \ + set_pmd((pmd_t *)(pudptr), (pmd_t) { pudval }); \ +}) =20 static __always_inline pud_t pudp_get(pud_t *pudp) { diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgta= ble-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;= } =20 #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) { p4dva= l }) + +#define set_p4d(p4dptr, p4dval) \ +({ \ + p4d_check_dummy(p4dval); \ + set_pud((pud_t *)(p4dptr), (pud_t) { p4dval }); \ +}) + =20 static __always_inline p4d_t p4dp_get(p4d_t *p4dp) { --=20 2.43.0 From nobody Thu Sep 24 20:03:25 2026 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EBCA8499F3D; Mon, 21 Sep 2026 10:59:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988350; cv=none; b=nFJJ2SO5CTPA+LIm6UfMJ9+ly7mKyhBzDWgLMIrRxYpNgeqdj5tNsII8LO9H1Z3UZHfsb78TdFdo9YUkbfFlA6Vb9dykOfoewhj4gJvbCd84Gs5geRlHngHpYwUVhkfCnh/XI5oE3dhpo+gVP9CbfY77/UyyK463Icqv/Ltg6Jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789988350; c=relaxed/simple; bh=Or+pfL3PXEcPJdOW4W+xPfx8ylyd8tpn0CA0i+cQDx8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=X54mlD/38lpOMYdu0BpI9LhOd0xDK7SutXpuTB5vuF98TwKNoGCiwwQXzRWj8n+Ud4O/JQYQQwTfnq1992LLI7tAEW68PJjux+Qw8N4zLUAMbU7q2hOOpkQO+WoRI8Bx9KilKKxYfAzYSe2yp2rK4kqXjridRx+nCkgOkplIei8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.b=OTPGWQ3V; arc=none smtp.client-ip=217.140.110.172 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.b="OTPGWQ3V" 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 D0D821CE0; Mon, 21 Sep 2026 03:59:03 -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 3E11E3F86C; Mon, 21 Sep 2026 03:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1789988347; bh=Or+pfL3PXEcPJdOW4W+xPfx8ylyd8tpn0CA0i+cQDx8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OTPGWQ3V/YIEMLtO7u2Mynqz++o5RPwLMFLlzIT4rgUlbfJz02BoKMgw4RXvRuSNj deUYqvEpMQchecaubbKtyAiqcrqDJ3rG98HSWlUBFWHIGiqs9ocWbZVbfPkkrmm/D7 ncRtII6dpeDQJvydmvJhhhL2Snuaf1u6HEPcx7TY= From: Yeoreum Yun Date: Mon, 21 Sep 2026 11:55:43 +0100 Subject: [PATCH 21/21] Documentation: mm: clarify behaviour of compile-time folded page tables Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260921-dummy_ptxp3-v1-21-cd40cf68242e@arm.com> References: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@arm.com> In-Reply-To: <20260921-dummy_ptxp3-v1-0-cd40cf68242e@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 X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=5249; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=WkUI9iV+4tWIf8gUL0eT1d3WqVW3xHozxqWVF9c3f4k=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBqsQ1UvQaI/DbnQhSon1cfVb2lmVIAgB8pZa9xc x4itcv3wn+JAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCarENVAAKCRBt1cPRWsUx M3wVC/9HHxJ8te9GEbS6FYmVPJFsAKbIOicXI24Ln9gqlvTZxuy4kNJc4ab1vnjPxk64m8Rg+x2 Mge3H0r3HnaL+quWGc5hhXjVijIFzCG8gpQvS3TAos58QC0AOllXSljJJW+I6bPGRHEfZbrplmH MSpeBY8ZsvhMVxoa7rzCNDxLL9FQI0Cc3PXqn84Rx9aaobgkmEtYiN7CNHsRZU3ng64fu67dco/ 9XO55oYTMY5NC0dEQSGNn31KsfpblVBRsW5um+k73FHlpD7vrNWPHSDKjsItM4o3qlBwTsCwCl1 Z7zy/Eg/ZygXnmH8QOhMc7fglKOXMvcG/maDLM9eOF/8KD3LCcwyTzCpuv5EoxT7vOhxogj2kut s/VQGR4ui3uesYjCw/PuXgA7Ampck2ZMBsmMmPI1k93NpLLOG4Y529M4WW6uqqGb5xddwPmnW5l apVpiy9rUjEUxGjRGHepEQpg+BUzcWhj6iVaP8sd5tNs9WaHGtTaNtG9oqCr4rfrjLXkY= X-Developer-Key: i=yeoreum.yun@arm.com; a=openpgp; fpr=2D83E092DD0533B85875A49D6DD5C3D15AC53133 From: "David Hildenbrand (Arm)" Compile-time folded page tables are not necessarily easy to understand, and= even people the were once familiar with the concept might need to refresh their = memory. Add proper documentation, including a nice diagram, for the current design. Mention details about dummy functions, including the recently changed pXdp_= get() helpers. Signed-off-by: David Hildenbrand (Arm) Tested-by: Muhammad Usama Anjum --- Documentation/mm/page_tables.rst | 84 +++++++++++++++++++++++++++++++++++-= ---- 1 file changed, 75 insertions(+), 9 deletions(-) diff --git a/Documentation/mm/page_tables.rst b/Documentation/mm/page_table= s.rst index 126c876282509..84f2715c7de0a 100644 --- a/Documentation/mm/page_tables.rst +++ b/Documentation/mm/page_tables.rst @@ -143,15 +143,81 @@ pointers on each level is architecture-defined.:: Page Table Folding =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -If the architecture does not use all the page table levels, they can be *f= olded* -which means skipped, and all operations performed on page tables will be -compile-time augmented to just skip a level when accessing the next lower -level. - -Page table handling code that wishes to be architecture-neutral, such as t= he -virtual memory manager, will need to be written so that it traverses all o= f the -currently five levels. This style should also be preferred for -architecture-specific code, so as to be robust to future changes. +Not all architectures support 5-level page tables; while for some of them +the exact number of supported page table levels is known at compile time, +others can determine the number of page table levels at runtime based on +hardware support and address space sizes. + +Generic page table walking code always assumes that 5 levels of page table +exist. To make page table walking code not have to worry about that, +`compile-time folding` and `runtime folding` of page tables are used. +Compile-time folding is mostly handled in common code, whereas runtime fol= ding +is exclusively handled in architecture code. + +This description focuses on generic compile-time folded page tables; for +architecture-specific variants, some details can vary, however, without +affecting common page table walkers. + +When walking folded page tables, all upper page table levels up to the sup= ported +level are skipped in page table walkers: this is achieved by (a) treating +entries in upper page table levels as present and pointing at a page table= ; and +(b) having page table walkers cast the entry pointer to the next-level ent= ry +instead of dereferencing that table. From the perspective of a page table +walker, the entry points at itself. + +Assuming compile-time folded 4-level page tables, to achieve (a), pgd_pres= ent() +and pgd_leaf() are hard-coded to indicate a present page table entry that +points at a page table, and to achieve (b) p4d_offset() and +p4d_offset_lockless() simply cast the page table entry pointer to the next +lower level. + +In the current design, this is further modeled by having the P4D have a +single page table entry:: + + PGD + --> +------+ NOP4D + | ptr0 |-------> +------+ PUD + | ptr1 |- | ptr0 |-------> +-----+ + | ptr2 | \ +------+ | ptr |-------> ... + | ptr3 | \ | ptr | + ... \ .. + \ NOP4D + +----> +------+ PUD + | ptr1 |-------> +-----+ + +------+ | ptr |-------> ... + | ptr | + ... + +Note that the arrows from PGD to NOP4D represent page-table-walker +transitions, not pointers stored in the pgd entries. + +Using p4d as an example, `nop4d`/`p4d folded` translates to the following: + +- p4d is considered folded into pgd; both are operating on the same page + table. + +- Most pgd_* helpers are hard-coded dummy functions that ignore the passed + pgd_t values entirely. Exceptions are pgd_val() and low-level helpers + set_pgd() + pgd_page_vaddr(), which effectively translate to set_p4d()/ + p4d_pgtable() to keep existing arch code working. + + Architectures must provide p4d_* helpers (unless further common + compile-time folding applies). + +- PTRS_PER_P4D is hard-coded to 1. Architectures must define PTRS_PER_PGD. + +To avoid reading a value that will never be used but cannot be entirely +optimized out, compile-time folded page table code also makes pXdp_get() +return a constant dummy value. + +In common code, this only affects pXd_val() when used for printing page +table entries for debugging purposes. As we don't want architecture code +that uses set_pXd(), pgd_page_vaddr() or pXd_pgtable() to accidentally +operate on dummy values, the compiler will error out if it detects that the +helpers are used with dummy values. For a folded level, pXd_page() must not +be used and unconditionally triggers a compiler error. Architecture code m= ust +instead call the helpers on the proper first page table level: e.g., set_p= 4d() +instead of set_pgd(). =20 =20 MMU, TLB, and Page Faults --=20 2.43.0