From patchwork Tue Feb 11 16:13:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Donnellan X-Patchwork-Id: 13969561 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 CAA94C0219E for ; Tue, 11 Feb 2025 16:14:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 427CB6B0089; Tue, 11 Feb 2025 11:14:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3D716280001; Tue, 11 Feb 2025 11:14:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 29F146B008C; Tue, 11 Feb 2025 11:14:41 -0500 (EST) 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 0C43D6B0089 for ; Tue, 11 Feb 2025 11:14:41 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B7ECF1205E1 for ; Tue, 11 Feb 2025 16:14:40 +0000 (UTC) X-FDA: 83108161920.20.BD9C0A8 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by imf25.hostedemail.com (Postfix) with ESMTP id 689F9A001C for ; Tue, 11 Feb 2025 16:14:38 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=GM33nSBP; spf=pass (imf25.hostedemail.com: domain of ajd@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=ajd@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1739290478; a=rsa-sha256; cv=none; b=7f/VfP8WA/rVJCG4JZNo1InDaPaz+1C3cfkR6iUwZl/pBKTYc/cxTvns93sqxdnoKkleGx VpT4IRaTKfTA3faskKXsDOb70FcbsvOSF9bU1p9W3eUsSfcora5LGJpJI0dlIBzpCjGe46 0MqWG/4P/e02wtxuAHvu2FGNj8a1sKg= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=ibm.com header.s=pp1 header.b=GM33nSBP; spf=pass (imf25.hostedemail.com: domain of ajd@linux.ibm.com designates 148.163.156.1 as permitted sender) smtp.mailfrom=ajd@linux.ibm.com; dmarc=pass (policy=none) header.from=ibm.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1739290478; 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:references:dkim-signature; bh=0xdreWwVnxuyL481YPDSF8wHYJ0Nb52Yq9rjkbtqthM=; b=XLC/pB3AeLgjgDCao0RVrEjGcukPqU2BFx/gqp0b1FUosLPpqu0nPimPoz/7UPfISvfgBd HgaUT7YZHX31CUZwp+fCA0/L1zB4h7XdYo/ZkfRwd3C5ZfCOMUGYhh0IafqTaJLqN1FCcE VswSAulwgTMNGih9IIRXUwpWPl6b9xo= Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51BDbuna008118; Tue, 11 Feb 2025 16:14:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=0xdreWwVnxuyL481YPDSF8wHYJ0Nb52Yq9rjkbtqt hM=; b=GM33nSBPY+V8zuX/Vo6qsCvkrDYPevGhB7ydkWhlr/shFpwW6uboK0eQW cCcXWSOmYWeKG5zIgPxmHnkAOup926KlLs1tKeSrA25EaUkJQ2N41UPcf5VUaMvW ExzrWi7H34nJEiWCxU/+dugPTV602w0ZNTHvbTmXFTDs0B/3rHjuHxMw1Gn9Z9zt yQON1fWg1UnuiUtL1c/V2DZOTL8ylbTqxL6cHurb1sqyTpE0W/QMvRN2mc2psqeo HySaowWNgnnxMJTmEA+fSU0v3woDWrH/c93rXcS1hsHOkYMEZMWeqnBcwIcE4h+R O7O6tj/KZI714xY5AbtCPmzuAR2nQ== Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 44qvma3p6t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Feb 2025 16:14:34 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 51BFHMYa028721; Tue, 11 Feb 2025 16:14:33 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 44pma1kprm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 11 Feb 2025 16:14:33 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 51BGEWA654788394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 11 Feb 2025 16:14:32 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 09DA42004E; Tue, 11 Feb 2025 16:14:32 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30F9420043; Tue, 11 Feb 2025 16:14:31 +0000 (GMT) Received: from ozlabs.au.ibm.com (unknown [9.63.197.14]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 11 Feb 2025 16:14:31 +0000 (GMT) Received: from jarvis.ozlabs.ibm.com.com (unknown [9.150.7.124]) (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 DEB55600AE; Wed, 12 Feb 2025 03:14:24 +1100 (AEDT) From: Andrew Donnellan To: linuxppc-dev@lists.ozlabs.org Cc: x86@kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, pasha.tatashin@soleen.com, sweettea-kernel@dorminy.me Subject: [PATCH v13 00/11] Support page table check on PowerPC Date: Wed, 12 Feb 2025 03:13:53 +1100 Message-ID: <20250211161404.850215-1-ajd@linux.ibm.com> X-Mailer: git-send-email 2.48.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: QPmKXD5gPUpVSUuCIRBS05bl4oO8-nRA X-Proofpoint-ORIG-GUID: QPmKXD5gPUpVSUuCIRBS05bl4oO8-nRA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-11_07,2025-02-11_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 malwarescore=0 clxscore=1011 lowpriorityscore=0 priorityscore=1501 impostorscore=0 adultscore=0 mlxlogscore=999 spamscore=0 suspectscore=0 bulkscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502110106 X-Rspamd-Queue-Id: 689F9A001C X-Stat-Signature: am6enphf6fxmmwjiuskty11nqo7dit33 X-Rspam-User: X-R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0MSowTHVOQ0NbM931O6yq1a35bZjAdscb+d8fFKBzI61BBJu8KSkYvSy12InEu4O0PCkdG+9D5Amd2EdIWLJJUY0OJLGrsaM6kO2rMRsq2EXkJlwNLLxD4MJlcMvnMtY6lysVejb35Njmn5iHamO+WFwLBlI4BBynlWpjrPim1T3w107bzyiZON3xD9/B1K4rnd4Fp9Lj3PheYvVoq/mXSVqXl+pXnyPl+y5FLcP7niWBP+z2V4sIvGZhu854kc/j0MPxKpQ7XVHFbpIiiJGGbPr98YP5Q/QDXHeKDYXjxI 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: Support page table check on all PowerPC platforms. This works by serialising assignments, reassignments and clears of page table entries at each level in order to ensure that anonymous mappings have at most one writable consumer, and likewise that file-backed mappings are not simultaneously also anonymous mappings. In order to support this infrastructure, a number of stubs must be defined for all powerpc platforms. Additionally, seperate set_pte_at() and set_pte_at_unchecked(), to allow for internal, uninstrumented mappings. (This series was written by Rohan McLure, who has left IBM and is no longer working on powerpc - I've taken far too long to pick this up and finally send it.) v13: * Rebase on mainline * Don't use set_pte_at_unchecked() for early boot purposes (Pasha) v12: * Rename commits that revert changes to instead reflect that we are reinstating old behaviour due to it providing more flexibility * Add return line to pud_pfn() stub * Instrument ptep_get_and_clear() for nohash Link: https://lore.kernel.org/linuxppc-dev/20240402051154.476244-1-rmclure@linux.ibm.com/ v11: * The pud_pfn() stub, which previously had no legitimate users on any powerpc platform, now has users in Book3s64 with transparent pages. Include a stub of the same name for each platform that does not define their own. * Drop patch that standardised use of p*d_leaf(), as already included upstream in v6.9. * Provide fallback definitions of p{m,u}d_user_accessible_page() that do not reference p*d_leaf(), p*d_pte(), as they are defined after powerpc/mm headers by linux/mm headers. * Ensure that set_pte_at_unchecked() has the same checks as set_pte_at(). Link: https://lore.kernel.org/linuxppc-dev/20240328045535.194800-14-rmclure@linux.ibm.com/ v10: * Revert patches that removed address and mm parameters from page table check routines, including consuming code from arm64, x86_64 and riscv. * Implement *_user_accessible_page() routines in terms of pte_user() where available (64-bit, book3s) but otherwise by checking the address (on platforms where the pte does not imply whether the mapping is for user or kernel) * Internal set_pte_at() calls replaced with set_pte_at_unchecked(), which is identical, but prevents double instrumentation. Link: https://lore.kernel.org/linuxppc-dev/20240313042118.230397-9-rmclure@linux.ibm.com/T/ v9: * Adapt to using the set_ptes() API, using __set_pte_at() where we need must avoid instrumentation. * Use the logic of *_access_permitted() for implementing *_user_accessible_page(), which are required routines for page table check. * Even though we no longer need p{m,u,4}d_leaf(), still default implement these to assist in refactoring out extant p{m,u,4}_is_leaf(). * Add p{m,u}_pte() stubs where asm-generic does not provide them, as page table check wants all *user_accessible_page() variants, and we would like to default implement the variants in terms of pte_user_accessible_page(). * Avoid the ugly pmdp_collapse_flush() macro nonsense! Just instrument its constituent calls instead for radix and hash. Link: https://lore.kernel.org/linuxppc-dev/20231130025404.37179-2-rmclure@linux.ibm.com/ v8: * Fix linux/page_table_check.h include in asm/pgtable.h breaking 32-bit. Link: https://lore.kernel.org/linuxppc-dev/20230215231153.2147454-1-rmclure@linux.ibm.com/ v7: * Remove use of extern in set_pte prototypes * Clean up pmdp_collapse_flush macro * Replace set_pte_at with static inline function * Fix commit message for patch 7 Link: https://lore.kernel.org/linuxppc-dev/20230215020155.1969194-1-rmclure@linux.ibm.com/ v6: * Support huge pages and p{m,u}d accounting. * Remove instrumentation from set_pte from kernel internal pages. * 64s: Implement pmdp_collapse_flush in terms of __pmdp_collapse_flush as access to the mm_struct * is required. Link: https://lore.kernel.org/linuxppc-dev/20230214015939.1853438-1-rmclure@linux.ibm.com/ v5: Link: https://lore.kernel.org/linuxppc-dev/20221118002146.25979-1-rmclure@linux.ibm.com/ Rohan McLure (11): mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud_set() mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd_set() mm/page_table_check: Provide addr parameter to page_table_check_pte_set() mm/page_table_check: Reinstate address parameter in [__]page_table_check_pud_clear() mm/page_table_check: Reinstate address parameter in [__]page_table_check_pmd_clear() mm/page_table_check: Reinstate address parameter in [__]page_table_check_pte_clear() mm: Provide address parameter to p{te,md,ud}_user_accessible_page() powerpc: mm: Add pud_pfn() stub powerpc: mm: Implement *_user_accessible_page() for ptes powerpc: mm: Use set_pte_at_unchecked() for internal usages powerpc: mm: Support page table check arch/arm64/include/asm/pgtable.h | 18 +++--- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/book3s/32/pgtable.h | 12 +++- arch/powerpc/include/asm/book3s/64/pgtable.h | 62 +++++++++++++++--- arch/powerpc/include/asm/nohash/pgtable.h | 13 +++- arch/powerpc/include/asm/pgtable.h | 19 ++++++ arch/powerpc/mm/book3s64/hash_pgtable.c | 4 ++ arch/powerpc/mm/book3s64/pgtable.c | 17 +++-- arch/powerpc/mm/book3s64/radix_pgtable.c | 9 ++- arch/powerpc/mm/pgtable.c | 12 ++++ arch/riscv/include/asm/pgtable.h | 18 +++--- arch/x86/include/asm/pgtable.h | 20 +++--- include/linux/page_table_check.h | 67 ++++++++++++-------- include/linux/pgtable.h | 10 +-- mm/page_table_check.c | 39 +++++++----- 15 files changed, 225 insertions(+), 96 deletions(-)