From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=217.140.110.172 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796059177; b=5VmR6dTVOFg/Q6flodoZXyu5MoeFldY9lZYTPLPBqgfk9J5MBHj/j4wG2c/JWjSmX+V6 YvqfBR4JaR+uXxrJeV3ndKoo9kfBlVdUcoICs2ydkoJ9HQJoBcN5kS4l2/jGLs4WZ7o81 5lpkofOy3H/pF3cKC1MF+OxT5v3/gSBb8/sXPeT1rbvXbJdXNAeCzIEyR0eH4DKUIch7S dVdVvGMpnAEHT7J9TDJIdOxpoVG//H4tLx193g4KbwyVFKAy1fvawyZ1XppiRBt9cK6oj BUIHDyTKueQK7P+kkwZhKc3JShFXQdbsLD27NzA88u8k0JONPUHpJzyRQoWhz3iDjMA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796059177; h=DMARC-Filter:Received:Received:DKIM-Signature:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=PaFeIcY8jJTZJxwBJzZhsFjZVAt2jLUrBOdIwSqkawg=; b=jCEfHFK8PIxjNPxrqPw6YWiDUAVdiJdMi/7aU6jys+2qV8VUkIREYPVslE9rGYhr1FTs X9/m7dxoOnPJN5njArNsBh5rqS2DwfLmUA8J/vOCAqVjv1Q7RaxJYJw2D+xrUV0YIL6st dTDXgvT5HRefphGhZvmpzEG4OHAMuaT59XpmAK3ynaJd2COQJOipGTKfaNtJdbGy5tVOA dHrnX6FIsu1IJkSWxLi+L497r5G7+bA/KNGwv4DIS7Nkp++d7Tr1PWuqFEnHelRFaTB05 9cq5V9xYqn7QwRWY71pPevk8Buea5w7xy1FSWuIbQM8Bcjn2YDbe6i2aK2oErraQ52A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=arm.com; spf=pass smtp.mailfrom=arm.com; dkim=pass header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=IG47OP8r; arc=none smtp.remote-ip=217.140.110.172 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DAAC0606A681; Mon, 30 Nov 2026 17:19:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DAAC0606A681 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=arm.com header.i=@arm.com header.a=rsa-sha256 header.s=foss header.b=IG47OP8r 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 6C2E91655; Mon, 30 Nov 2026 09:19:33 -0800 (PST) Received: from e129823.arm.com (e129823.arm.com [10.2.213.3]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 122D83F86F; Mon, 30 Nov 2026 09:19:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=arm.com; s=foss; t=1796059175; bh=quNX9zIoFfJw3bVRc20VYYhiQejsxvmjFN2Os/gJcwA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IG47OP8rcxStYY2UHcWe39RqRZa9HrHwBcTGGes8VVqJz0jfRdPeKaCToCo6Y0L+y /TzC97sqLoScn9q5pWwXKfWPhUUkn4BnrQ+7jU2+6A+vGKKTpMkna0pEsebRSMM54h OXD3tDymzxFQqalM4FLdmnsBv0jjQXqBQ72hsIHE= From: Yeoreum Yun Date: Mon, 30 Nov 2026 17:18:34 +0000 Subject: [PATCH v3 01/20] mm/pgtable: define (pgd|p4d|pud)_offset_lockless() for folded page tables X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261130-dummy_ptxp3-v3-1-456081a8ed0e@arm.com> References: <20261130-dummy_ptxp3-v3-0-456081a8ed0e@arm.com> In-Reply-To: <20261130-dummy_ptxp3-v3-0-456081a8ed0e@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, stable@vger.kernel.org X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4675; i=yeoreum.yun@arm.com; h=from:subject:message-id; bh=m11hv1qaiaXC7qE0WzoPRrJrh+dOgnPkeuL8YOQBUcY=; b=owEB7QES/pANAwAKAW3Vw9FaxTEzAcsmYgBrDa/1A+QKELcvJwtrFvsXG81fXNk6tg86jlsEO sVWAzWpYQKJAbMEAAEKAB0WIQQtg+CS3QUzuFh1pJ1t1cPRWsUxMwUCaw2v9QAKCRBt1cPRWsUx M8d5DACFujWFIIIkyFZ0yIoZJdLDOBQG3vNpCOfnoy6rphrk224PVoWTfk6m87AWhwHtG5zC1ke qc/P9stHcIVlxBN7euSiZBP09gjIWcyaj1eGWrIhjlaR3ZxDUzWvunCQ9LY8SGcB5WE26HCLll6 L2EGurLTd2rc3Wn3ZyGNd9p7kmUwohduBnuiE3RbzC3T3claQr7bs2w7XT2TSAZRDV7e0u/dm4A OFeGR+diS2jg0dKS48yp7erbXz6FOqpSNuaOd0FfpmvFrnnpr5Dq9AFotQoA5A+DBvLz1UIKr+7 W3ebVN5jzzbL2qIygQccffWS52TIUr7iD0oYjUWSiBQ44XWdPVOo1OV4GiRdEBjAxZizkQY0qsT xAooVwlkw5WiXl6noxFt5XIG/W5yP20MYwr1lzhOPin18L1zHyV6vnNytpvI5jjPz5L1Lc34MTz zLgPeideWGTJ6lfVuZyqcsjNIh8sZiYW2aLO8FENKuiSHXJGC/GEnwuejqF8f1dI6twQw= 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 documents: 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. Also, this patch fixes the pXd leaf recheck in fast GUP to read the live entry rather than a stack copy, ensuring that concurrent mapping changes are detected when the pXd level is folded. Fixes: Fixes: d3f7b1bb2049 ("mm/gup: fix gup_fast with dynamic page table folding") Cc: Signed-off-by: David Hildenbrand (Arm) --- 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/pgtable.h index a474c9fb485ad..4ed6c2cd91b30 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1141,29 +1141,6 @@ static inline bool pgtable_l5_enabled(void) { return false; } #define p4d_clear_fixmap() #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 addr) -{ - /* - * 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 */ #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/pgtable-nop4d.h index 1cf739ee38aa1..9a912545a7b92 100644 --- a/include/asm-generic/pgtable-nop4d.h +++ b/include/asm-generic/pgtable-nop4d.h @@ -36,6 +36,13 @@ static inline p4d_t *p4d_offset(pgd_t *pgd, unsigned long address) return (p4d_t *)pgd; } +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) }) diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h index ff4235cf84d77..be7f6599d24e0 100644 --- a/include/asm-generic/pgtable-nopmd.h +++ b/include/asm-generic/pgtable-nopmd.h @@ -48,6 +48,13 @@ static inline pmd_t * pmd_offset(pud_t * pud, unsigned long address) } #define pmd_offset pmd_offset +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) } ) diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h index eedee8e3ad68f..68df1a06b570c 100644 --- a/include/asm-generic/pgtable-nopud.h +++ b/include/asm-generic/pgtable-nopud.h @@ -44,6 +44,13 @@ static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address) } #define pud_offset pud_offset +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) }) -- 2.43.0