From nobody Fri Dec 19 19:02:33 2025 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 63EDB2E0926 for ; Thu, 18 Dec 2025 17:11:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766077892; cv=none; b=GLJ03a8a+qqWoEPtJDRXk+EfmUHngSqGlcnHgTZqKrhRwZYU5LfmGmjSG5tcTT5jZfHXlG9eRW51w/hlfR5N8dkXOIznaNMWz+YIYECBA0YNKzrLOgLPLp5koaKsQVolMrw4eoQvuFH94uO+MqJOJp/WGm0EoFopZSi3+EW0824= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766077892; c=relaxed/simple; bh=RPdIrNgJhBeFh7UG7EHFbHbSmAriyi4ORt8IIrHdykM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QwswDpLTFERbC6Lv7wLGNG+6oDm+7b37Q2DFS2D2QnRbaP+0WDADJ/u45x4RGXlUJphDlm4RM1bXhKTFlhNMQix8Vo/lEVXGuDMr1hiPLwzAzkIsFpnZWToRhMHPN5FY16mYAAu3d7b8cg2jnbFj9o+l7Jrn6vEGRB8U7MfFFQQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=BAtA8hst; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="BAtA8hst" Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5BIEZNPe030256; Thu, 18 Dec 2025 17:11:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=HWoSo1 eEUGDSVrfx/RVD+AA0KOYlwKtsf+dOKVvgUjY=; b=BAtA8hstEV+vhLnEeZtm5C cumh0zYIFPPX7q5JRUaMApFmWtgmFYYcX37tzM49kwJrJMHj6bRR1y9uHY04FEdp dimAvAoUeUTmYR0xWGsy0keXd0aF6VhRcJH/HxwGl7LeJWh7CIg7nefLAb4CyMHH 3XfUcBBsIlV0FzXMIKgfvZWW++0Oz5j+oNlJyzWYFVyzLHuYCn9rwKZixcIPfdDc FaDbS8X7TrmdKRmXQ6xmGKiyOwgQYjRGxyuzIrwgJKovKc0uPTEiQZIK65Uy7Qin YPjMqwSwHUW6f741g/VJkj/BfsU01NoWc1cjiQqpULUr0VEd7qvhGlU8gg9iWH2A == Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4b0yt1tvae-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Dec 2025 17:11:08 +0000 (GMT) Received: from m0360072.ppops.net (m0360072.ppops.net [127.0.0.1]) by pps.reinject (8.18.1.12/8.18.0.8) with ESMTP id 5BIGsabe010964; Thu, 18 Dec 2025 17:11:08 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4b0yt1tvac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Dec 2025 17:11:08 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 5BIGexh5012806; Thu, 18 Dec 2025 17:11:07 GMT Received: from smtprelay07.wdc07v.mail.ibm.com ([172.16.1.74]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4b1juyhqxc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 18 Dec 2025 17:11:07 +0000 Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay07.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 5BIHB56W12976720 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 18 Dec 2025 17:11:06 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9CE458056; Thu, 18 Dec 2025 17:11:05 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA9305803F; Thu, 18 Dec 2025 17:10:58 +0000 (GMT) Received: from jarvis.ozlabs.ibm.com (unknown [9.36.16.51]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 18 Dec 2025 17:10:58 +0000 (GMT) From: Andrew Donnellan Date: Fri, 19 Dec 2025 04:09:42 +1100 Subject: [PATCH v18 10/12] powerpc/mm: Implement *_user_accessible_page() for ptes 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: <20251219-pgtable_check_v18rebase-v18-10-755bc151a50b@linux.ibm.com> References: <20251219-pgtable_check_v18rebase-v18-0-755bc151a50b@linux.ibm.com> In-Reply-To: <20251219-pgtable_check_v18rebase-v18-0-755bc151a50b@linux.ibm.com> To: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, Pasha Tatashin , Andrew Morton , Madhavan Srinivasan , Nicholas Piggin , Rohan McLure , Christophe Leroy Cc: Alexandre Ghiti , x86@kernel.org, Nicholas Miehlbradt , Sweet Tea Dorminy , Andrew Donnellan , Srish Srinivasan , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org X-Mailer: b4 0.14.2 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DI82VlKJCDmN1Pd4VpqGnuQlvP3qGltY X-Proofpoint-ORIG-GUID: r_gWxBg_IDqgKdohby3DDkIG-C4KF7Pp X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMjEzMDAyMyBTYWx0ZWRfX0L6BzOFOvPkV pUcjgPm04/hQlmp9r+tqBO7ugQwhcatqTUtFl+aTeQdk3yNfO+6sxXLmigbUlp0rr+C1ZT06/fU PltWgHhDAbjNOShp126JpSRadKmjQIexb61YQS30wrzuKuVRIrDTZLqS7UP1ypk6eFeeyBbDMRB JDgQXwMQUFmG4j/B37ub+goon3C4nTBCK6n6hDqzSVk9/STEktNfCJ9kCuRPYuIRp7Wi6jhlr8e iclP0EU0IIkMijaM00RNgsNdjmejnG2MTV8idNS4Aw1cpe6YAdFvE2VFYBc8I4YwnQdu1oAqTeA 6GYMRKQydRMpm/87juq75wjE5caTrypRHd2oMs4jh2UhoXG2RRGiVtoK+Ha/7gazu6RckexubBj sWMNW6VXdcbAucslSkKz6fwgD5xyUA== X-Authority-Analysis: v=2.4 cv=L/MQguT8 c=1 sm=1 tr=0 ts=694435ac cx=c_pps a=5BHTudwdYE3Te8bg5FgnPg==:117 a=5BHTudwdYE3Te8bg5FgnPg==:17 a=IkcTkHD0fZMA:10 a=wP3pNCr1ah4A:10 a=VkNPw1HP01LnGYTKEx00:22 a=VnNF1IyMAAAA:8 a=7ipKWUHlAAAA:8 a=wHxssy8_SbW45gVFdfIA:9 a=QEXdDO2ut3YA:10 a=gpc5p9EgBqZVLdJeV_V1:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-12-18_02,2025-12-17_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 phishscore=0 malwarescore=0 adultscore=0 priorityscore=1501 clxscore=1015 lowpriorityscore=0 bulkscore=0 spamscore=0 suspectscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2510240000 definitions=main-2512130023 From: Rohan McLure Page table checking depends on architectures providing an implementation of p{te,md,ud}_user_accessible_page. With refactorisations made on powerpc/mm, the pte_access_permitted() and similar methods verify whether a userland page is accessible with the required permissions. Since page table checking is the only user of p{te,md,ud}_user_accessible_page(), implement these for all platforms, using some of the same preliminary checks taken by pte_access_permitted() on that platform. Since commit 8e9bd41e4ce1 ("powerpc/nohash: Replace pte_user() by pte_read(= )") pte_user() is no longer required to be present on all platforms as it may be equivalent to or implied by pte_read(). Hence implementations of pte_user_accessible_page() are specialised. [ajd@linux.ibm.com: rebase and clean up] Signed-off-by: Rohan McLure Reviewed-by: Pasha Tatashin Signed-off-by: Andrew Donnellan Acked-by: Madhavan Srinivasan --- v18: move the definitions of p{m,u}d_user_accessible_page() to be next to p{m,u}d_access_permitted() --- arch/powerpc/include/asm/book3s/32/pgtable.h | 5 +++++ arch/powerpc/include/asm/book3s/64/pgtable.h | 17 +++++++++++++++++ arch/powerpc/include/asm/nohash/pgtable.h | 5 +++++ arch/powerpc/include/asm/pgtable.h | 8 ++++++++ 4 files changed, 35 insertions(+) diff --git a/arch/powerpc/include/asm/book3s/32/pgtable.h b/arch/powerpc/in= clude/asm/book3s/32/pgtable.h index 87dcca962be7864be3da1e7aad0992d2bc4581cf..2edca1068b6f31e64ddc4f39f59= 4bb3ac27a8435 100644 --- a/arch/powerpc/include/asm/book3s/32/pgtable.h +++ b/arch/powerpc/include/asm/book3s/32/pgtable.h @@ -437,6 +437,11 @@ static inline bool pte_access_permitted(pte_t pte, boo= l write) return true; } =20 +static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) +{ + return pte_present(pte) && !is_kernel_addr(addr); +} + /* Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to. * diff --git a/arch/powerpc/include/asm/book3s/64/pgtable.h b/arch/powerpc/in= clude/asm/book3s/64/pgtable.h index aac8ce30cd3b39ae184a69879a57ce8d6698fff5..2d69a827594f3c8593283fa11ac= d4750577e71a7 100644 --- a/arch/powerpc/include/asm/book3s/64/pgtable.h +++ b/arch/powerpc/include/asm/book3s/64/pgtable.h @@ -539,6 +539,11 @@ static inline bool pte_access_permitted(pte_t pte, boo= l write) return arch_pte_access_permitted(pte_val(pte), write, 0); } =20 +static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) +{ + return pte_present(pte) && pte_user(pte); +} + /* * Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to. @@ -909,6 +914,12 @@ static inline bool pud_access_permitted(pud_t pud, boo= l write) return pte_access_permitted(pud_pte(pud), write); } =20 +#define pud_user_accessible_page pud_user_accessible_page +static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr) +{ + return pud_leaf(pud) && pte_user_accessible_page(pud_pte(pud), addr); +} + #define __p4d_raw(x) ((p4d_t) { __pgd_raw(x) }) static inline __be64 p4d_raw(p4d_t x) { @@ -1074,6 +1085,12 @@ static inline bool pmd_access_permitted(pmd_t pmd, b= ool write) return pte_access_permitted(pmd_pte(pmd), write); } =20 +#define pmd_user_accessible_page pmd_user_accessible_page +static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr) +{ + return pmd_leaf(pmd) && pte_user_accessible_page(pmd_pte(pmd), addr); +} + #ifdef CONFIG_TRANSPARENT_HUGEPAGE extern pmd_t pfn_pmd(unsigned long pfn, pgprot_t pgprot); extern pud_t pfn_pud(unsigned long pfn, pgprot_t pgprot); diff --git a/arch/powerpc/include/asm/nohash/pgtable.h b/arch/powerpc/inclu= de/asm/nohash/pgtable.h index 5af168b7f292415c5896a5c63bd78641d9a2c2a6..9bf3e40f27b645da660cbeeb561= f08eeef180b1b 100644 --- a/arch/powerpc/include/asm/nohash/pgtable.h +++ b/arch/powerpc/include/asm/nohash/pgtable.h @@ -243,6 +243,11 @@ static inline bool pte_access_permitted(pte_t pte, boo= l write) return true; } =20 +static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) +{ + return pte_present(pte) && !is_kernel_addr(addr); +} + /* Conversion functions: convert a page and protection to a page entry, * and a page entry and page directory to the page they refer to. * diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/= pgtable.h index 17fd7ff6e535b6d2b320fc8c292b7eb964fa0ef2..859cdbaa54a7fa159d5bbd4653f= 7871381f4910f 100644 --- a/arch/powerpc/include/asm/pgtable.h +++ b/arch/powerpc/include/asm/pgtable.h @@ -202,6 +202,14 @@ static inline bool arch_supports_memmap_on_memory(unsi= gned long vmemmap_size) =20 #endif /* CONFIG_PPC64 */ =20 +#ifndef pmd_user_accessible_page +#define pmd_user_accessible_page(pmd, addr) false +#endif + +#ifndef pud_user_accessible_page +#define pud_user_accessible_page(pud, addr) false +#endif + #endif /* __ASSEMBLER__ */ =20 #endif /* _ASM_POWERPC_PGTABLE_H */ --=20 2.52.0