From patchwork Tue Apr 2 05:11:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohan McLure X-Patchwork-Id: 13613345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B9E9CD1284 for ; Tue, 2 Apr 2024 05:13:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8DF106B0093; Tue, 2 Apr 2024 01:13:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 88EFA6B0095; Tue, 2 Apr 2024 01:13:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 730526B0098; Tue, 2 Apr 2024 01:13:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 52F6A6B0093 for ; Tue, 2 Apr 2024 01:13:27 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 14CF51A0974 for ; Tue, 2 Apr 2024 05:13:27 +0000 (UTC) X-FDA: 81963423654.22.F806398 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf25.hostedemail.com (Postfix) with ESMTP id CD6BAA0002 for ; Tue, 2 Apr 2024 05:13:24 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=eLZit5Xz; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf25.hostedemail.com: domain of rmclure@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=rmclure@linux.ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712034805; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=l64yPSCJgp+48IGOZHO1jI/AZ1J5HFNmmvqOu9zpdzY=; b=eK7Anyi/o+GEi4gt1Q12kg2ZSoWFafkkswxsaA41bwmkdILds4oT0CGxocXdt2qLEMiSi6 maBVq4KOUg86FmYcygQhb2LKe0QiscnR9DEqam0XB9PWvOeFZ/OkkfWloD5b7b3OPDn5Gw yjiFe9HT22fz00OgKD9dWnj6G2jiBF0= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=eLZit5Xz; dmarc=pass (policy=none) header.from=ibm.com; spf=pass (imf25.hostedemail.com: domain of rmclure@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=rmclure@linux.ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712034805; a=rsa-sha256; cv=none; b=fY4YfDNAS6X2Ups6z8NhbLqDauX3QuVVJGny0gHDSZEChjIlGQh+DI3+7IVfToIwVv834q c3HJXecfJKPCkclC8YNFaR8tJ/flrKL+CIbSLeUX/X4fFZb5bhBf4wETFxy8mlfwxpJFgy 5E+c7esXh/0QIeT8V+T/SNf0MnNbhWM= Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 43250XeW023780; Tue, 2 Apr 2024 05:13:17 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=l64yPSCJgp+48IGOZHO1jI/AZ1J5HFNmmvqOu9zpdzY=; b=eLZit5Xz1abJw+49nek6PSQdUCPJAYkT9bX7/6b3MJx8wujY32n/UJe/4wL/LiZrKXlx OU6yxBlgmfIZE7AV8Gn6IwJPg47mhRaUSaa3R/Ru0rPhs5pwAbTivNxZCzmhQGXWybsQ 6ozARNTQ4WX92oO5lwPIkS+R22AAph0OpJoT32sW5mDOeg1cDpYiEuSqOr4A7XHKo6/O 5eueFrCQjvcSKj/eyi26wFdsdBmSPpG+xG/y01vLgoPCK3BJLugADVTb7ywXcopviarP X/i1c2pGnGXEmMvYB/7lYnWHHOjIjWj8kTr+UIb34uXbw6FNDBgnmyEm5+qaoP2DVQOW Dg== 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 3x8beq8118-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Apr 2024 05:13:16 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 4323JlSh027126; Tue, 2 Apr 2024 05:13:15 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3x6wf04p3p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Apr 2024 05:13:15 +0000 Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 4325DBmB55378404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 2 Apr 2024 05:13:13 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 16F0820065; Tue, 2 Apr 2024 05:13:11 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 48B442004D; Tue, 2 Apr 2024 05:13:09 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.192.253.14]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 2 Apr 2024 05:13:09 +0000 (GMT) Received: from socotra.ibm.com (unknown [9.69.87.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 303A560442; Tue, 2 Apr 2024 16:13:03 +1100 (AEDT) From: Rohan McLure To: linuxppc-dev@lists.ozlabs.org Cc: Rohan McLure , mpe@ellerman.id.au, christophe.leroy@csgroup.eu, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org Subject: [PATCH v12 07/11] mm: Provide address parameter to p{te,md,ud}_user_accessible_page() Date: Tue, 2 Apr 2024 16:11:47 +1100 Message-ID: <20240402051154.476244-8-rmclure@linux.ibm.com> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240402051154.476244-1-rmclure@linux.ibm.com> References: <20240402051154.476244-1-rmclure@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: DHxauK0Mq3ujQSZLMsUJbV8c803p7Tjj X-Proofpoint-GUID: DHxauK0Mq3ujQSZLMsUJbV8c803p7Tjj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-04-02_02,2024-04-01_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 phishscore=0 priorityscore=1501 bulkscore=0 impostorscore=0 suspectscore=0 malwarescore=0 adultscore=0 clxscore=1015 mlxlogscore=939 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2403210000 definitions=main-2404020035 X-Rspamd-Queue-Id: CD6BAA0002 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: zg7r37ergmxe8h5hez3fnp1jpwnaaoui X-HE-Tag: 1712034804-958492 X-HE-Meta: U2FsdGVkX1/hGzJ1I5xa4r2odrUe+9aOxR5tXlxCpQASSInL2rzVj5w3cUSUwg4LiFXceapsAFM9FpSOV3fkZjlwxBUmnGab1I6z9cNyomA9VBxHpSgCn8oyqTqmtBi31XLPvuGRC6QvWZJe+2PvVylWGulq+FUB1z7QljgypWjuf4pr0c/0bu/uNYIL8Scl9HlYBbuCwLakyUVk0yG6BHgvEtUhx7AhiC6M7tpZM8rslpivQuaN/fBGoXgkTnz59S5S6SAmo/BdmkfYHxAohZzk5ekLvFFK1pbG3ke//X6afhdDv1u+YFXB0ty0JuMngirRMBLn5EIiFITRZzrvISIhJvJVIaPWHMWbSBPMjjSZQYIzkpEBIUJFdbG8bPedd/ZJ2fyIjWHsfnCYkZ7AqVOUVAov01eeHfAkujCi2otX0M5xZug4WfmFwcrhqLE5apsqVOAjKZ0u2prf9/gIr6ahfudhWVu9KKP3Nlc1zz/7PvKWaH2p8S1qZo4FG1a6WwHwMGBz0phLB8oEmuDRtBQYAzvzN6MAgDXWaqa0rgQ3zRNZ8ZIhZpgXiKMjdGX4mb/jSZiopuTz0rlho8m9sLlRNnXVB5jl8jXW2T4OmTqRskt5QNmDO8gCNmFHk/plDqM69ox0ohZ5X+KEG80LL9UELP5WPjEOS+bb3ZEddVhwn6/nqgvTCOtEiYfUir+PfaaSrKFRFLy4k+mR8hk+tRLIj27j6vpAzM4uE6W61jm1gpzeUK03zUdKcC+WU1vfj0/go4nm6XFPrsGvi8SPO5wkTWMZczhmSlvJuJpln6st+fbYT04kuyseLws9FRTByD3bTj2z167UNKhY1rPOCvW0kEIr9CudKSeV7G9RkT9h9Z0Pzw/WQN7JzMXga8ZMPHVrfsbFDxLbB2Y7qcK98wi7ygAz5jT55M0UlaCtE3iFGHhZjeOFt5rtEgJCFw4vUJFk1NOGPTE/+41NXVX 9W9ZbopD WFjo+6bsh6BcBxQpqkocoLanJE6UWVxjvmtrJfJDiEj9xo3ufnvcAtF9FPq1U+ziYYwawEFwuLP3Pt8r25bx84so7tlwSv8sBZUpa6IutdooffMb7gXlTcBU386DMOVTL6VPhmEFGS2iX0AXW0/2OPfQGQlsVrja3P8hYznFZydO6QeJhjbGymDP3uEZxzsgnDom75MxQEQ3ulUoLhjGYg7T8xmr4sN3Ma+oazKs7rPm833ctZKpHgqgxL/tq77K8uicphgbrnZmvARM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On several powerpc platforms, a page table entry may not imply whether the relevant mapping is for userspace or kernelspace. Instead, such platforms infer this by the address which is being accessed. Add an additional address argument to each of these routines in order to provide support for page table check on powerpc. Signed-off-by: Rohan McLure Reviewed-by: Pasha Tatashin --- arch/arm64/include/asm/pgtable.h | 6 +++--- arch/riscv/include/asm/pgtable.h | 6 +++--- arch/x86/include/asm/pgtable.h | 6 +++--- mm/page_table_check.c | 12 ++++++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index 040c2e664cff..f698b30463f3 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -1074,17 +1074,17 @@ static inline int pgd_devmap(pgd_t pgd) #endif #ifdef CONFIG_PAGE_TABLE_CHECK -static inline bool pte_user_accessible_page(pte_t pte) +static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) { return pte_present(pte) && (pte_user(pte) || pte_user_exec(pte)); } -static inline bool pmd_user_accessible_page(pmd_t pmd) +static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr) { return pmd_leaf(pmd) && !pmd_present_invalid(pmd) && (pmd_user(pmd) || pmd_user_exec(pmd)); } -static inline bool pud_user_accessible_page(pud_t pud) +static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr) { return pud_leaf(pud) && (pud_user(pud) || pud_user_exec(pud)); } diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 92bf5c309055..b9663e03475b 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -724,17 +724,17 @@ static inline void set_pud_at(struct mm_struct *mm, unsigned long addr, } #ifdef CONFIG_PAGE_TABLE_CHECK -static inline bool pte_user_accessible_page(pte_t pte) +static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) { return pte_present(pte) && pte_user(pte); } -static inline bool pmd_user_accessible_page(pmd_t pmd) +static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr) { return pmd_leaf(pmd) && pmd_user(pmd); } -static inline bool pud_user_accessible_page(pud_t pud) +static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr) { return pud_leaf(pud) && pud_user(pud); } diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h index b2b3902f8df4..e898813fce01 100644 --- a/arch/x86/include/asm/pgtable.h +++ b/arch/x86/include/asm/pgtable.h @@ -1688,17 +1688,17 @@ static inline bool arch_has_hw_nonleaf_pmd_young(void) #endif #ifdef CONFIG_PAGE_TABLE_CHECK -static inline bool pte_user_accessible_page(pte_t pte) +static inline bool pte_user_accessible_page(pte_t pte, unsigned long addr) { return (pte_val(pte) & _PAGE_PRESENT) && (pte_val(pte) & _PAGE_USER); } -static inline bool pmd_user_accessible_page(pmd_t pmd) +static inline bool pmd_user_accessible_page(pmd_t pmd, unsigned long addr) { return pmd_leaf(pmd) && (pmd_val(pmd) & _PAGE_PRESENT) && (pmd_val(pmd) & _PAGE_USER); } -static inline bool pud_user_accessible_page(pud_t pud) +static inline bool pud_user_accessible_page(pud_t pud, unsigned long addr) { return pud_leaf(pud) && (pud_val(pud) & _PAGE_PRESENT) && (pud_val(pud) & _PAGE_USER); } diff --git a/mm/page_table_check.c b/mm/page_table_check.c index 98cccee74b02..aa5e16c8328e 100644 --- a/mm/page_table_check.c +++ b/mm/page_table_check.c @@ -155,7 +155,7 @@ void __page_table_check_pte_clear(struct mm_struct *mm, unsigned long addr, if (&init_mm == mm) return; - if (pte_user_accessible_page(pte)) { + if (pte_user_accessible_page(pte, addr)) { page_table_check_clear(pte_pfn(pte), PAGE_SIZE >> PAGE_SHIFT); } } @@ -167,7 +167,7 @@ void __page_table_check_pmd_clear(struct mm_struct *mm, unsigned long addr, if (&init_mm == mm) return; - if (pmd_user_accessible_page(pmd)) { + if (pmd_user_accessible_page(pmd, addr)) { page_table_check_clear(pmd_pfn(pmd), PMD_SIZE >> PAGE_SHIFT); } } @@ -179,7 +179,7 @@ void __page_table_check_pud_clear(struct mm_struct *mm, unsigned long addr, if (&init_mm == mm) return; - if (pud_user_accessible_page(pud)) { + if (pud_user_accessible_page(pud, addr)) { page_table_check_clear(pud_pfn(pud), PUD_SIZE >> PAGE_SHIFT); } } @@ -195,7 +195,7 @@ void __page_table_check_ptes_set(struct mm_struct *mm, unsigned long addr, for (i = 0; i < nr; i++) __page_table_check_pte_clear(mm, addr, ptep_get(ptep + i)); - if (pte_user_accessible_page(pte)) + if (pte_user_accessible_page(pte, addr)) page_table_check_set(pte_pfn(pte), nr, pte_write(pte)); } EXPORT_SYMBOL(__page_table_check_ptes_set); @@ -207,7 +207,7 @@ void __page_table_check_pmd_set(struct mm_struct *mm, unsigned long addr, return; __page_table_check_pmd_clear(mm, addr, *pmdp); - if (pmd_user_accessible_page(pmd)) { + if (pmd_user_accessible_page(pmd, addr)) { page_table_check_set(pmd_pfn(pmd), PMD_SIZE >> PAGE_SHIFT, pmd_write(pmd)); } @@ -221,7 +221,7 @@ void __page_table_check_pud_set(struct mm_struct *mm, unsigned long addr, return; __page_table_check_pud_clear(mm, addr, *pudp); - if (pud_user_accessible_page(pud)) { + if (pud_user_accessible_page(pud, addr)) { page_table_check_set(pud_pfn(pud), PUD_SIZE >> PAGE_SHIFT, pud_write(pud)); }