From patchwork Mon Jan 13 23:15:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13938232 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8D32AC02180 for ; Mon, 13 Jan 2025 23:16:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0C3FB10E440; Mon, 13 Jan 2025 23:16:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="NOFVwKA8"; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="eGo1sW2k"; dkim-atps=neutral Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3723910E43C for ; Mon, 13 Jan 2025 23:16:38 +0000 (UTC) Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50DMB6jd029204; Mon, 13 Jan 2025 23:16:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=niydGLW+l3VrHLpFvGOHQzZpg4pJZgSXGKNXTIzGj7Q=; b= NOFVwKA8NvKQR77PTuwEdYpqv1VoDewvDuClaj8Hp11IUu59UvSzFf9YRGyxzwF9 rEhY8dGhYH46+b3nc0EPCOdLPIqA/b7gxGqRxPNWQy9KrjWcUr/ncNU/MNqYyKWc FZLbJ9MH4IpCt6MQf6LD8uLzDv9ylXn8pWbeGdRRN+SdjEdV6RVgXsWJGRGEdVtY OtZ2WgY+1tvFokeu/70KFYHyGL21hsutVZjPHp6gAgujeBw/pwDPvXmh8QJJtHVb k9uHapmQ30p7rfOW4R+eQ7MAbMANTzStEYoR17JSwFheyWmvJyHGNvc+XyQiBxXq xFINhn9pY/8fjRJqcAivYg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 443gh8vm5w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 23:16:26 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50DMWY3A038746; Mon, 13 Jan 2025 23:16:26 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 443f37kang-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 23:16:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=TJ6ZEUgcQatkNGOCjttxWRIp2cgUM/SHCWBaMSO1IuGc79C1pnIKbO3F39ELtMTqeGavcR7IrF4xUUjK8R0ubOrL7r306WaMGXmTbS4qZXY1RWYRPq9e0dKzGONNFgg20ldDAInMYQ4Jve49De4Io9qD9Z03ml3MrIUFkufW0ETTosAnQiYkiKwikMrWWnN/fQPETqysu0ZV0dy7GGYeqJoPSeaz/XQs23WUvrKd9QHB9bBZnwlcASZcX/W+RzTR8H5XkzCFSmoGLw60MGwAW3RN+FrqJLj3Q8Me/b9ycew07WXvinJILo4H/ZDmT4/bE+4BgIhL+W6XhV8pISyf1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=niydGLW+l3VrHLpFvGOHQzZpg4pJZgSXGKNXTIzGj7Q=; b=gUW/K3nDYhBQYpo60OVDi9aI1bxGvd2WynA/mrBBW3WeRYdDFmVE4aeFylq016DwBRUnC0IFT2g60LiqBCuAOPj+7oN1F0b9QKEAANLaVg9uBrFbEaRrzBKaa2pb1g9zyIyfdP7zFp9HikahUmdhfm3mg5xIY9BjL27Of7iepV2EaNbJh7YgKyw3E3iFixhSytEECetFIzDSi45EZKbXgIa0RFDNn1mw4GaHLe6bT03LACIyvgQx3UM6s04wkbwC00q2LZozRktbcdWSgGfa4bq9uiulGaHAR8j5z8xYjyJwk1RfmNtH2NTgOtOpjkG7kkpB8k1TBh0SGF46zGte8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=niydGLW+l3VrHLpFvGOHQzZpg4pJZgSXGKNXTIzGj7Q=; b=eGo1sW2k6sER6cIJlgqzX8kKbdjTcLShfiC3sNzHXBzio+xGstQxlffIN23OLLQA449A/jTJE53rM/drQ5la6or1/wiS17PS8LBc8Y78hNF6xnxeh4ezzrogamz5WfNY4Vw7TlKRSRgCRMQNysA0mrothYkPdwp6/GBPmehmThA= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by DS0PR10MB6848.namprd10.prod.outlook.com (2603:10b6:8:11f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.17; Mon, 13 Jan 2025 23:16:24 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%4]) with mapi id 15.20.8335.017; Mon, 13 Jan 2025 23:16:24 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jaya Kumar , Simona Vetter , Helge Deller , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox , David Hildenbrand Subject: [RFC PATCH v2 1/3] mm: refactor rmap_walk_file() to separate out traversal logic Date: Mon, 13 Jan 2025 23:15:46 +0000 Message-ID: <9406e61c80f86aa642958bf8d468491bfef6a336.1736809898.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0063.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:153::14) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|DS0PR10MB6848:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b559997-bf63-4609-685f-08dd34284c55 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024|7416014; X-Microsoft-Antispam-Message-Info: eMwY2sBcoqhK/cC7Yb+QmhzOino2U9UgXLXCMWakzObwKVh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lbp7xrf8e9VXJfCgJ7ImcBz4KWhkIAB+kmHNL4YaOuFQpQnBXbguR/3OHcGenqDNyHuSwy/gIL0Ua/xqdhOOq+oU+y3cUdMHZ/Ii5nCTYAjtbHb5QPlnenNUzY8Cbk/XkkxNzyOKrfUHrmXagHDjfxv9XPg2wfAjOCdENFh+DPqETGXIQq0gn/l+bxg6ykKkMn6+y4XyYNxJ80tfE5NjGSia7BBa2dZ5yX0NDL5odh+gwp+wBVZgO3TwfYiqQNP4+6hGZvx9hdJiFZdrnLr8u2P5o X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3366.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(7416014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Mcs8ly/PPphN5RjDESZAOmQsSMA0mvdQird/c+q17wLvFzMGt652C6DZYG4sCLZ6w8JJXomomoHYasPiNjqvBclllcNH3cTJthlQb604CpfnHJJCaW7Swq4JWzApXcbep3RhsZEd46kiVYSUpUavlhn15MPmeXMOScpYvlj8j14MqpOkwmdvRXiTdIir47OdyJi8VPHq3uJE7nR6KH1mt7Fr/7xLjwHFt4O3RXSzjoH0tO1YaaE9Bm13l2BI0gFK+D+K0K8fIpVGVAZQC1/OTXh6Rar7FMOp4L0NVf0qIpmLmFBuY3W92Ztn2tFMYcLRlyd4qAjhjAMqrbRzu5zhf5FbGjv4jY2AIrocYD5XhuBeXoyIdeDyeAeY4hV1sgvFxt4HXkuWugELu/F4eIqFOYTljWP2yVQW1kx0oeWz341zYIrAEgNuEEZAcbWBNIfnE/BxTQRPVJf7MAQ6CPkftoKcqmpVqdfTPdzz1z8d2fV2D6jquMTraJhlFX2qubixcMoDE+ZRzGrK5+OmNJbHmGFiScV6DmPnPhbUatIrQAyRl0MP79/Mb5Cm0b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ternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: JSwIRezVZp+e1sNZlZoOoaOAgiKgOR87M64i7yUHcOOdj6zUy38rDLML4TW1oO/2oW/d39qyYOlYuc4PnBvE0KQIk5gcYzQk3Lx++9UPHf2jd7Mnz3Aaghc5Eg0sHKuk2YCUVoA2abSjDYWrdL4k0pZ9Fni5s5Sx+Tq4rD+y47xzqWotrJYY+/KUf8UM7c0hbY+xRanzT0NMpqlu4vDrcJ5FI/V+VqAbpHVEPoQgbnlejQCJ+XIqj8OwofjIHjuZ/YA/nasdujXq1bfMd25f43gBgBHOcnqEH2j5IaIuh5PBqzxPkvIBKor3O+li1hPC3EKGTnaBHKs/FnhLw1f1Nj3xCvTW6KYmCF0I15jcIczUmGjdm909HXA5zYT7J/YSN8TMCjz3WX9G1TWjwMuR/uyncGwlvHsdwy140iowL8+zu/YayJ+7SlMZEKbMsIdC+bDBYMf2epdOOkOHVMg4pFFLcL3tpn4Bo9iVIQVKceMiLnVSixwJ1f7clOofSgoXGmdhcSWb+9YxFTkWSM0QgWCJgZB7G7CUFlohNS5b2EG8WulTUrybjKiTbF3j5OUJUYP80i+QQugNCiuAU5kJuLqzniJnDVwrkjXmygAaR7M= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b559997-bf63-4609-685f-08dd34284c55 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2025 23:16:24.1388 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: nL5z+fikOA4xukntHQ5byYfP1GTY5gOZ291Q3LksN+nFgMsQ33Dt3NSJ5OOiSZYVBm1fusyQ03KIflb+PBlGwKcoXXr7L/zk2J9UGh5QTk8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6848 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-01-13_09,2025-01-13_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 phishscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501130183 X-Proofpoint-GUID: J4mqIu4rvUmTGVu7f9gYK83duefwHmsI X-Proofpoint-ORIG-GUID: J4mqIu4rvUmTGVu7f9gYK83duefwHmsI X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In order to permit the traversal of the reverse mapping at a specified mapping and offset rather than those specified by an input folio, we need to separate out the portion of the rmap file logic which deals with this traversal from those parts of the logic which interact with the folio. This patch achieves this by adding a new static __rmap_walk_file() function which rmap_walk_file() invokes. This function permits the ability to pass NULL folio, on the assumption that the caller has provided for this correctly in the callbacks specified in the rmap_walk_control object. Though it provides for this, and adds debug asserts to ensure that, should a folio be specified, these are equal to the mapping and offset specified in the folio, there should be no functional change as a result of this patch. The reason for adding this is to enable for future changes to permit users to be able to traverse mappings of userland-mapped kernel memory, write-protecting those mappings to enable page_mkwrite() or pfn_mkwrite() fault handlers to be retriggered on subsequent dirty. Signed-off-by: Lorenzo Stoakes --- mm/rmap.c | 79 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 26 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index c6c4d4ea29a7..a2ff20c2eccd 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2653,35 +2653,37 @@ static void rmap_walk_anon(struct folio *folio, anon_vma_unlock_read(anon_vma); } -/* - * rmap_walk_file - do something to file page using the object-based rmap method - * @folio: the folio to be handled - * @rwc: control variable according to each walk type - * @locked: caller holds relevant rmap lock +/** + * __rmap_walk_file() - Traverse the reverse mapping for a file-backed mapping + * of a page mapped within a specified page cache object at a specified offset. * - * Find all the mappings of a folio using the mapping pointer and the vma chains - * contained in the address_space struct it points to. + * @folio: Either the folio whose mappings to traverse, or if NULL, + * the callbacks specified in @rwc will be configured such + * as to be able to look up mappings correctly. + * @mapping: The page cache object whose mapping VMAs we intend to + * traverse. If @folio is non-NULL, this should be equal to + * folio_mapping(folio). + * @pgoff_start: The offset within @mapping of the page which we are + * looking up. If @folio is non-NULL, this should be equal + * to folio_pgoff(folio). + * @nr_pages: The number of pages mapped by the mapping. If @folio is + * non-NULL, this should be equal to folio_nr_pages(folio). + * @rwc: The reverse mapping walk control object describing how + * the traversal should proceed. + * @locked: Is the @mapping already locked? If not, we acquire the + * lock. */ -static void rmap_walk_file(struct folio *folio, - struct rmap_walk_control *rwc, bool locked) +static void __rmap_walk_file(struct folio *folio, struct address_space *mapping, + pgoff_t pgoff_start, unsigned long nr_pages, + struct rmap_walk_control *rwc, bool locked) { - struct address_space *mapping = folio_mapping(folio); - pgoff_t pgoff_start, pgoff_end; + pgoff_t pgoff_end = pgoff_start + nr_pages - 1; struct vm_area_struct *vma; - /* - * The page lock not only makes sure that page->mapping cannot - * suddenly be NULLified by truncation, it makes sure that the - * structure at mapping cannot be freed and reused yet, - * so we can safely take mapping->i_mmap_rwsem. - */ - VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); - - if (!mapping) - return; + VM_WARN_ON_FOLIO(folio && mapping != folio_mapping(folio), folio); + VM_WARN_ON_FOLIO(folio && pgoff_start != folio_pgoff(folio), folio); + VM_WARN_ON_FOLIO(folio && nr_pages != folio_nr_pages(folio), folio); - pgoff_start = folio_pgoff(folio); - pgoff_end = pgoff_start + folio_nr_pages(folio) - 1; if (!locked) { if (i_mmap_trylock_read(mapping)) goto lookup; @@ -2696,8 +2698,7 @@ static void rmap_walk_file(struct folio *folio, lookup: vma_interval_tree_foreach(vma, &mapping->i_mmap, pgoff_start, pgoff_end) { - unsigned long address = vma_address(vma, pgoff_start, - folio_nr_pages(folio)); + unsigned long address = vma_address(vma, pgoff_start, nr_pages); VM_BUG_ON_VMA(address == -EFAULT, vma); cond_resched(); @@ -2710,12 +2711,38 @@ static void rmap_walk_file(struct folio *folio, if (rwc->done && rwc->done(folio)) goto done; } - done: if (!locked) i_mmap_unlock_read(mapping); } +/* + * rmap_walk_file - do something to file page using the object-based rmap method + * @folio: the folio to be handled + * @rwc: control variable according to each walk type + * @locked: caller holds relevant rmap lock + * + * Find all the mappings of a folio using the mapping pointer and the vma chains + * contained in the address_space struct it points to. + */ +static void rmap_walk_file(struct folio *folio, + struct rmap_walk_control *rwc, bool locked) +{ + /* + * The folio lock not only makes sure that folio->mapping cannot + * suddenly be NULLified by truncation, it makes sure that the structure + * at mapping cannot be freed and reused yet, so we can safely take + * mapping->i_mmap_rwsem. + */ + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); + + if (!folio->mapping) + return; + + __rmap_walk_file(folio, folio->mapping, folio->index, + folio_nr_pages(folio), rwc, locked); +} + void rmap_walk(struct folio *folio, struct rmap_walk_control *rwc) { if (unlikely(folio_test_ksm(folio))) From patchwork Mon Jan 13 23:15:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13938233 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 298EEC02184 for ; Mon, 13 Jan 2025 23:16:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A580D10E441; Mon, 13 Jan 2025 23:16:43 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="hALdWMGR"; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="hqe6Jz/f"; dkim-atps=neutral Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8FBF110E443 for ; Mon, 13 Jan 2025 23:16:42 +0000 (UTC) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50DMB67R003306; Mon, 13 Jan 2025 23:16:32 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=9cVkdFbW0ldWkTYMrnicBgqjz5m0gvOcJPGn45IZ5Eg=; b= hALdWMGRKdjBcHXQYpjMkIyA5R33MW9+sgOwix2jf3azumcYowahHkxETfkKWMJ5 9O2iT6PMJ7OWggFppSleW5iFvEe0PuCMnm0eu5/aBcNyPp6GU+29X6GnzvlyGkYu 17cOThRfiGF46hoFORndIfKPQGVrybk7RYMSal7vfkaOSG/gIbGpCRqEida3f/pO owNDlJR4UYIw+oNtMRRJDmFDWp4HFIwCp98V+6Nsm2AW4L+P37CDWH8rf+53/Csn PBpe6kHGCbUkvyX+RhXOrrmbXeqmhwCRs/1G8HCKz1wCJ0k1x2SeHqXnDsZ/8t6I DlfrONBEqsrS9oETEv3AxQ== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 443fjamr65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 23:16:32 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50DMoBWR020422; Mon, 13 Jan 2025 23:16:31 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2172.outbound.protection.outlook.com [104.47.56.172]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 443f3dvht8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 23:16:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xijWW6Dq0Y99raPPOQfj8dO5vNTm/DVv7rwVFKv5Xhfg2d4eZOcspZhSpxiojL6Zczwpf/eWSC0t2Aqqy7HbUQmnzmLF747E1tXhba4GukkLYl+3Yev1wqHDWIh0OfRZCkP6Z3ZW1GzCJOEwLYPBFJouQTrWdjeiygCSnMvvZXdS4Ub+IDMBczbAnf1UWq568x5lK67S3jGOjpWcGR2D/9zYurSX21PFMnYfTVZB5x+ArPCRyptp3TEDm3Ovt5hPkaQ4dRpH3RpwxzYJ+eNHACFxFY/cyj78xZi8Vuv3f2ewuCl2VHgO2+3xljBOsENX/wvUVSvGry9OqGecMUS1mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9cVkdFbW0ldWkTYMrnicBgqjz5m0gvOcJPGn45IZ5Eg=; b=vSWseVqQPZwyhq2kiqcUoXwGwlJiMZvBLEvv8muXhynZ3SHhcWFyMcwOYuU4A979mGjanrIaGEHSCrr0bjV6mRKe/464MafG6y1fLcWJkfxkrHyII1b4ULB5tQW7l3xCUZ6vJhqdXLtBmBc1ytxvM3Mz01R+fPvxU11EJBXBSN2AP+2nkAcWQB1sS3f9+ciIkTd8ULO57x4zTQhA0sni7kKz/EshI52eIBtqSubROU9HE7hKCO4iEANNGFi8iZZbgkRn6qRjst63DuGzsbyj9mr8KpuGE1HlEylcNWxi1aE6B3z6/yY4zxK78U5Qmsqw0Zm8WrGgYgAzTqoA4l/bdg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9cVkdFbW0ldWkTYMrnicBgqjz5m0gvOcJPGn45IZ5Eg=; b=hqe6Jz/fGXH+kFbrTv7M+xwkk7VOVHvZXgUdv/GOYiDWlsDmv5d2x7Y52lOsA7MkDE5eFSTakrwJ2d36iBt+Nbs9/KU7Vxrz9VNAdXwkhGlGvfIBl1lV/IsfpFkxcYhOQey+jc43XlQQN4EtHoD4Gr+gwpY/E7pGx+0c1/uNHbs= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by DS0PR10MB6848.namprd10.prod.outlook.com (2603:10b6:8:11f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.17; Mon, 13 Jan 2025 23:16:27 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%4]) with mapi id 15.20.8335.017; Mon, 13 Jan 2025 23:16:27 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jaya Kumar , Simona Vetter , Helge Deller , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox , David Hildenbrand Subject: [RFC PATCH v2 2/3] mm: provide mapping_wrprotect_page() function Date: Mon, 13 Jan 2025 23:15:47 +0000 Message-ID: X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0616.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:314::16) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|DS0PR10MB6848:EE_ X-MS-Office365-Filtering-Correlation-Id: 69ab98c6-5bea-49d0-a4d8-08dd34284e4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024|7416014; X-Microsoft-Antispam-Message-Info: FNTeDJiUYFdPyneQVc69aONxNtyEV/Y+omCfQqpNmwBYUTv7Npzg2zW2zNBz6Dq6eYXuEfurRlnkd8aDCnx6t6+kFcNnna6lJakEVkTHcCh2L1Ksut3KnuWJjoj+eIFfatXNs7m+Esad14b5DSDiZWC9P/6884viXTm4oUJpaCruqSZ3yNkTT/IVH6TisS2ZEbT8SwdP2oZAK+yaRol676ZRBL1IgRx/zgyZz77kdvoTi++VaZK2nkur6I5HuTWJcimJa5nSUM9wP5+7cnEiVxik1/kNG24Gz9B/rzU3XFOc42w+wJQSPq/4823AOrT3CdnUQ29J0ilKcxj1UOcCgOIYdxyIKkVSMGCsLMBv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RV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3366.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(7416014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8+IIzqWdTwMG82gubErpcQH5CY9z3veehdqajSCL4BFFHN+Q1npVx96UgzrgRcnLS4v1p5RhSF6VuJyPRGzQovxACoUXBjs2CwTzeZgS89yvjIteZHgJ2PsL/Rs2Gfv6ci3I7VSMo2WxVxgakKXfja+kX+4edIU7xNTkk0oZ6BsaRGPqGRQmTQrDHGIIsUc9+U41b4t/fmrgolg2qp0leNfYsB3C9KJEoEPciOjSqZ5vqXf4qgmzUZc/CUvLJoA609HqwLjR9V8NozuTgFRYooI98uDmMp+TDnFfR/H1RRIId9Su7b36+5nx1HHFynoWiVrb9wtCGpoIx2+qRyrDYpjcLHvpHpNFv6HImEJSS9VKsBj3TxljfFkfKUaJwSWF1r+qauUDb/vWMi+orL3Q2ddVbbfJY4UxSvA4cxFfzRT2ejPG25x/qNUEtGh+Kh8fVzfZvktBb73QaCY1Qmp78XT40boHYrBrQeel3Om47C+9PGsdg+0EBtTdYfupMYXFXa/Mp0DxrJrVNCVV5VmFnnNtUn3XKQAZn46cZGSM/YKK8ylMSWM10VhWKBhEkbuubYUQTVBS8dyc8rvDGEJyISZBUJ/kXuNWavJOrmO5H6298X1XCFfcUqoNv4OutL3xK6K/34oE8O3xuFYcjjkF1B2hjXRuq5mgGhPwthZI3+tvgjNyIGBqoaze3HwCycnIFa6zOBPzoJ4rJXdYNbUXbaHonnAYm/ZQVO2FhbXMjgyLr8IXauJhJZzL3zUM3TboBF9a9xtN4IiJWjpG5nawRzCZmbnNgLhAW+J2+Q1XJRdofSUGdR7G0xCYhSUBYl9/ixTLUgLKthXOq0ZbbZXsal6iBepGw369QQPcoAs87fhMFotGXwTTlB1PRgvJ6zSB9mIjrmB4NwTYxfb9+4eSj86d9onWdocwZ+eUz8UkzC5Zg0Cpr1/UFR7z+exFN+ThIJLHMgUvut3ElbnOT4/KwOjHnmULgNPrQDW4FPg055LdT36C1Aahi9kEl81ljfbjl2XBMLQH+esKj/md6iIRx3ax/jVNQVRozThZWJwL75RQi//uOpTvqEUPv/lsFxHJg5+8GRk5IIi//qThvaGUvSh9fMh5Tsn0QXxAcFN9DQr8GN57IbydjlhXV8uk/EKNHbo031UPUHGo5gd/L7jHA3eyVKtM/IyJcTWBPCGFXFpYl477hwgwbaElMAcnmiU6QEyEirTdeRiSI00jhNin5XGvv7JsciX2YumLfqDUA0X+huOFpDXDfvd6Z3h5RqJ2VmhBclviVuXjZZeVCpnmzvp6XSe9QvNQKnMOCEY1Ocl70PvjlNt8dqEmt+tTWOT8B+/81UHECtRE+wty71hcHOUb8gDyGNjsSr6+nvDC/6iCUeTBcNOW+lgLHCCEtL+fi9BFx7Yog2Nk0oCLuIdtytHigsZmnTFvcDdqBH0n+h3wVvlWe7dmhfJ8RS+51S+4wKW//gb7Mq+05GZingSyM7F0D5hcvVkeVXW/nuTlfO9ItMLOssnJDgp86CPq7sMU94U7Sh2tWHsprx+T0Qz/gt3AJkGJUN7T275sRWwo0vMCG8cIyMIHKH7gXvkkhDzqxInrf1l0D/vmKnoNc89s/Q== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 35iifpHSGRcwT6cgAnJuCJk8kAoJkgt5HdGySCLw31cSeZPYaxoSPUBFPdxuvgC/elGw8JwAnpoNEpt4R6kSCA5iEZtfEQwpVdyHblM+Pqh0zpZpdni3YmJtbh76xik3FijwbC63JLnAuAu1lFs0rnmFSYu5bknxT1kmPWpyzX2Glh46z6zCRo1NG42TRHhdTvH604dDiOvwqQGbF4rI2H0GFkZE7y4/+u/F11GqFox/vSlr7lJCLNJnx4JqG4KELTNzpKojMJ04NQCR64XfngP338RYrONzDIN7mi5AfA1ReYPM7tyKf42ALGmXjEujR+DE/aVujcjJ+McgDxlDRqAIRBoWsqukQYe8cHXbvww16DS2dfhatsLBMtI45RaCi5K4u7oP35bQLMDm1CHGpVeBARwQlZ/U469wMaR2ZZkIgy/WgUIGjiducPGA8X4lvh5hzKL7VZyoPFxAUg4JkbPMiKqh2HNJqUkE7SfNOCvIcKvtfF0hhZZsmXotX78cFsEOE3Wq/BwWEY7I0uLtxis95lxiSzjmVLPUqn6UH1eGrbyJkyyYj2u5L1hKjih8ordBuxXswF4aCqy74oMS8xptDVtbb4yV8T8OkZ4APkg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69ab98c6-5bea-49d0-a4d8-08dd34284e4d X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2025 23:16:27.5789 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CZJh1ZmzKzhVTkjySLuo486HHoBXGLQ6ztClb29/gPQjGD9iDvvX5NZenfpHLbNeG9mvqkcQNF1sRxBkyeixf16vooaq8rV/zJCJEYiEHOI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6848 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-01-13_09,2025-01-13_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501130183 X-Proofpoint-GUID: _vvhkrjxFXlqNdPBF0Tp0ZmkLXC2f1gV X-Proofpoint-ORIG-GUID: _vvhkrjxFXlqNdPBF0Tp0ZmkLXC2f1gV X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" in the fb_defio video driver, page dirty state is used to determine when frame buffer pages have been changed, allowing for batched, deferred I/O to be performed for efficiency. This implementation had only one means of doing so effectively - the use of the folio_mkclean() function. However, this use of the function is inappropriate, as the fb_defio implementation allocates kernel memory to back the framebuffer, and then is forced to specified page->index, mapping fields in order to permit the folio_mkclean() rmap traversal to proceed correctly. It is not correct to specify these fields on kernel-allocated memory, and moreover since these are not folios, page->index, mapping are deprecated fields, soon to be removed. We therefore need to provide a means by which we can correctly traverse the reverse mapping and write-protect mappings for a page backing an address_space page cache object at a given offset. This patch provides this - mapping_wrprotect_page() allows for this operation to be performed for a specified address_space, offset and page, without requiring a folio nor, of course, an inappropriate use of page->index, mapping. With this provided, we can subequently adjust the fb_defio implementation to make use of this function and avoid incorrect invocation of folio_mkclean() and more importantly, incorrect manipulation of page->index, mapping fields. Signed-off-by: Lorenzo Stoakes --- include/linux/rmap.h | 3 ++ mm/rmap.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 683a04088f3f..0bf5f64884df 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -739,6 +739,9 @@ unsigned long page_address_in_vma(const struct folio *folio, */ int folio_mkclean(struct folio *); +int mapping_wrprotect_page(struct address_space *mapping, pgoff_t pgoff, + unsigned long nr_pages, struct page *page); + int pfn_mkclean_range(unsigned long pfn, unsigned long nr_pages, pgoff_t pgoff, struct vm_area_struct *vma); diff --git a/mm/rmap.c b/mm/rmap.c index a2ff20c2eccd..bb5a42d95c48 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1127,6 +1127,79 @@ int folio_mkclean(struct folio *folio) } EXPORT_SYMBOL_GPL(folio_mkclean); +struct wrprotect_file_state { + int cleaned; + pgoff_t pgoff; + unsigned long pfn; + unsigned long nr_pages; +}; + +static bool mapping_wrprotect_page_one(struct folio *folio, + struct vm_area_struct *vma, unsigned long address, void *arg) +{ + struct wrprotect_file_state *state = (struct wrprotect_file_state *)arg; + struct page_vma_mapped_walk pvmw = { + .pfn = state->pfn, + .nr_pages = state->nr_pages, + .pgoff = state->pgoff, + .vma = vma, + .address = address, + .flags = PVMW_SYNC, + }; + + state->cleaned += page_vma_mkclean_one(&pvmw); + + return true; +} + +static void __rmap_walk_file(struct folio *folio, struct address_space *mapping, + pgoff_t pgoff_start, unsigned long nr_pages, + struct rmap_walk_control *rwc, bool locked); + +/** + * mapping_wrprotect_page() - Write protect all mappings of this page. + * + * @mapping: The mapping whose reverse mapping should be traversed. + * @pgoff: The page offset at which @page is mapped within @mapping. + * @nr_pages: The number of physically contiguous base pages spanned. + * @page: The page mapped in @mapping at @pgoff. + * + * Traverses the reverse mapping, finding all VMAs which contain a shared + * mapping of the single @page in @mapping at offset @pgoff and write-protecting + * the mappings. + * + * The page does not have to be a folio, but rather can be a kernel allocation + * that is mapped into userland. We therefore do not require that the page maps + * to a folio with a valid mapping or index field, rather these are specified in + * @mapping and @pgoff. + * + * Return: the number of write-protected PTEs, or an error. + */ +int mapping_wrprotect_page(struct address_space *mapping, pgoff_t pgoff, + unsigned long nr_pages, struct page *page) +{ + struct wrprotect_file_state state = { + .cleaned = 0, + .pgoff = pgoff, + .pfn = page_to_pfn(page), + .nr_pages = nr_pages, + }; + struct rmap_walk_control rwc = { + .arg = (void *)&state, + .rmap_one = mapping_wrprotect_page_one, + .invalid_vma = invalid_mkclean_vma, + }; + + if (!mapping) + return 0; + + __rmap_walk_file(/* folio = */NULL, mapping, pgoff, nr_pages, &rwc, + /* locked = */false); + + return state.cleaned; +} +EXPORT_SYMBOL_GPL(mapping_wrprotect_page); + /** * pfn_mkclean_range - Cleans the PTEs (including PMDs) mapped with range of * [@pfn, @pfn + @nr_pages) at the specific offset (@pgoff) From patchwork Mon Jan 13 23:15:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13938234 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F8ABC02184 for ; Mon, 13 Jan 2025 23:16:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B3BB910E443; Mon, 13 Jan 2025 23:16:47 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="MihEW+mt"; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="RVp2zc9Q"; dkim-atps=neutral Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by gabe.freedesktop.org (Postfix) with ESMTPS id B19A710E443 for ; Mon, 13 Jan 2025 23:16:46 +0000 (UTC) Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 50DMB5xH014402; Mon, 13 Jan 2025 23:16:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=YRhGkW/RMOMZr3nKHZ1tr1jk5DUOwJF185zsr/vzBac=; b= MihEW+mtd/DHxo/cdvSvL1rsNZSUosWXjmQHFaciu3Qpd9GuopgphhyJH/Tj10BV bAzZPvpNfXxMwK7AQnpVzryNHqlVvT2MOCjNvDSwHvNvDA4JBsiTtWlfKCOfs8vl QrH6AkVl9wSWJdcKyYIgThckdN5c13xbtGRHyKt5niz7FB9b/CJG60I9mP0075R6 2i4kaVEjJq0eE7I2fNEndAiLht6VqF8R1x7Z4mCMErJvusl06W+TmkyKNQWeMgnq +KPgGZMRe6AICBcls6qTRg/WblNuSkvbMxwzZPHsLx7w34OBRxNdELL7BzsmqCjT g3EgIOt0P3b/v7ela/sQAg== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 443h6svp29-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 23:16:36 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 50DLHuAR020352; Mon, 13 Jan 2025 23:16:35 GMT Received: from nam11-bn8-obe.outbound.protection.outlook.com (mail-bn8nam11lp2177.outbound.protection.outlook.com [104.47.58.177]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 443f3dvhum-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 13 Jan 2025 23:16:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zLCFkN5iL8+5sncEjnX9pXjeZA6HmKHpeFVcdmYqE9e9DtAvZudVm1leq1oW8BHGncQBs3K7jGEpnkQoibCqTpKukHEN/mBFtbkiba6fCfR9ZA7W4oHx3BVjJwPebLkcOl2SMv+MrdyvUD2JS+P4kc+0AY9HTvolL+pllxltYMlKfDRTPkw9Ux+MPg5ESJ1Gw4eWUIDVqyBuz/wqKeoPP1+ORZjj4ytkUzURZliUxzsZVmmLfm1gZQ5yB0+DhNwzWs0ZKtUHGvXANHnc/m1lJRRYzwrexgkscd0I3SRgHdOO6uEq7DS3fTDkbpuFU8fjjqCvJStxsdomGCG7zeo1nA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=YRhGkW/RMOMZr3nKHZ1tr1jk5DUOwJF185zsr/vzBac=; b=xawtR/P4znMQcmkwMATEtyjaGJ1T66zTeFiCmHU5+/Hs9zwB9O22GHbDosxQxcDvVA7eLjmBEoLOoewrDrtjp74zAV5tiuWtRGRPwgMz9lSWvYa2yntM/OPhjuO1ZIztc09i3nhj8VWBrmfrM6F6juZ6Ty5ePBKwWRJHm/2ZudvRxAv5KQi9PCV4SzPlsT+H0QSxrkcjWVWSBTwo2Ord9WrBRElYK3pXnsjZbde9otoRoAiOsAz8MEPiWWVc3FJ9TzWYdVtGp5NLnbnX1Y6c9xp1nELB5xdcapLs4yX1mGvz4k3PwzcQlCAoz3d0m4VH79y0gCnc8LPPU6cTNC+MDw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=YRhGkW/RMOMZr3nKHZ1tr1jk5DUOwJF185zsr/vzBac=; b=RVp2zc9QGPc5nPmsAEChM7NWb3idj3nMJVfU3ttXlNC1E1OzKodcP6nGUrxKVKBDNIw0xLnuTqIg4JX+8/fT/rkVxC4Z37pp8tCFN9t95ct9OzD3fIi+V8We1CdgNBZcBIIvpxuj/YzthFp/HJWFcLQ9oenKNP7HeARUxnhNzPg= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by DS0PR10MB6848.namprd10.prod.outlook.com (2603:10b6:8:11f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.17; Mon, 13 Jan 2025 23:16:32 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%4]) with mapi id 15.20.8335.017; Mon, 13 Jan 2025 23:16:32 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jaya Kumar , Simona Vetter , Helge Deller , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Matthew Wilcox , David Hildenbrand Subject: [RFC PATCH v2 3/3] fb_defio: do not use deprecated page->mapping, index fields Date: Mon, 13 Jan 2025 23:15:48 +0000 Message-ID: X-Mailer: git-send-email 2.48.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0174.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18a::17) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|DS0PR10MB6848:EE_ X-MS-Office365-Filtering-Correlation-Id: f6353302-fe9a-487f-dd37-08dd3428515d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13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yd6QK8uvjocJ4lK3S5VUJZdgE5Tn47Vf4yMjh8fBMJQsIu82rVj+kH1flFkbTgyqkId7sUDVvubO8qnO6mludJ90IOuFsjrd/9yCtwgXeZAefxqn+QmCJpKgpC5l0mc8gOrgri76fIDZ6c3dV6Pw/ffkbDc9E7imG0tsZqjLpJu6A5S5gOZFPzmUgSOV9LlatnuvIM9HKwAac5JOMegZ1Tr494rZnqVsQkrsbw58eo7nOhLW33xY8mK59Ewa5ksUM0ELOfTGxGC0i53gUphBAzfVv4W+t5Z7H3k0lcmKRujIqIEV20Aqp3tycx2H+IWfJcZYK4Kla4K4OH9mYsxVMWLMvD91hETVGGAlwGQDl9LcV6dMhH X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3366.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(1800799024)(7416014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JKTGSRsX0Lsu99XkbZZaoSu/z7UAwRY7FgHggYAr0lxPdZ5yGUG7jbm1DnkaW8IOSlpUSBNAg3XBd2PXx3dB5Q1MN7sVyHOX0a/jrXyjNCwZad7jhrTsSXhQ0agkXpJfoBGj2uljPf+ZGAgBlaFkpMEHQRklMSYqgIjQgGyDWmzWcTk5jZCZkpg61YZ19GgwM42g2SwJuxFg6xK8cFe8hs8Uo0+zhusY7+9Q7ggeL3FaCwVVE0QAd4/bySbZ7jG8Y/k54wIe5EuNho0SwmAFA8Xnxc0KpPxoN3uF17i8gO3WNbds3l7MespgnHnyRwhholgeXZn+8xpe0wjJ8lU2hIomRADJmqBlnBCKQpdvuY01n9vP0WhoJLP8aR3+cUeg4hdNRPC/pUuTDK7L9SI5Lkd/uycos2LhEqkNRGoGgvBY440HMG/Cu5blYu3ZqMI8qz6aVHVwtffohPHBj478tDzQM6jb/sZkK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ZeAp8N8E6aeA+BSnmzyyQxHYIticP188R/tePZvG/jvAZZljBV2l75qn0ceedr3m+w== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: bv1MID7OAeCdBEyJduPRLPDz6i72yA237Gs7aaKz0qQyHv7I1lv3aqUQ/iRwc22c04tyr7AcbKoeki09BM6aG2Bm+CN9+O/V/SKJzt9ZXEnHqeJNErsMNTzH6NyI+IH1nT6g0710rAza//Y6mvRLrd8g8g39RS+Zn4uE9PlJMa6wv/us/4vh+y/EUBuhGtNoREfmtM+zOkbypIf5cG2KKk1n1Uj4kyYYqCzVSonhR3e4ELZufcQzILFyegXOCSP4h3+OtTxzQwRD50y8Ybu3KU3ju4aSOZbWT66ZoOzcOmeunzR0vqV8hVn1SSE2AaHYAe5UvUQhc4+6VvYWm1dOCogFz6iPLxMqLAEITvY8QjYyYPIA78giWZiJXCgdxlRLzkR3OV0K+gGJN394O7Zut9QJWxUFdQ7DbiBnyX7+8K0o+MYgtUPoMwBNYIm9o3ND7AzSsuCay35yCHCY3dI0cEwLlgFVkoQN7zfJs1EIYlTmfyRsuqSEPQt/TtL+NC02kr92lNZUMcAHmI3+eSZ38v69xhWk/f4USjk66DvSUy+Yl+5Z12lr3V3zPRU4RZcXfSIzOzInr4HlccmozlTdJANAwXiW7UVhoR4drKpLWSU= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f6353302-fe9a-487f-dd37-08dd3428515d X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2025 23:16:32.7171 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: BNEzdE14QLiDuB5/vAaE69E0PlGkRUZySlyfR5T0CIObaiViFSw/q8Tmibd50c2xeycVju640vKH28L/T7tLTODpgUOKJbl47NJARzl5tWM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB6848 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-01-13_09,2025-01-13_02,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501130183 X-Proofpoint-GUID: VeH9-9-P1IzmfA-d7n0lhtUQZ-j38-0J X-Proofpoint-ORIG-GUID: VeH9-9-P1IzmfA-d7n0lhtUQZ-j38-0J X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" With the introduction of mapping_wrprotect_page() there is no need to use folio_mkclean() in order to write-protect mappings of frame buffer pages, and therefore no need to inappropriately set kernel-allocated page->index, mapping fields to permit this operation. Instead, store the pointer to the page cache object for the mapped driver in the fb_deferred_io object, and use the already stored page offset from the pageref object to look up mappings in order to write-protect them. This is justified, as for the page objects to store a mapping pointer at the point of assignment of pages, they must all reference the same underlying address_space object. Since the life time of the pagerefs is also the lifetime of the fb_deferred_io object, storing the pointer here makes snese. This eliminates the need for all of the logic around setting and maintaining page->index,mapping which we remove. This eliminates the use of folio_mkclean() entirely but otherwise should have no functional change. Signed-off-by: Lorenzo Stoakes --- drivers/video/fbdev/core/fb_defio.c | 38 +++++++++-------------------- include/linux/fb.h | 1 + 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c index 65363df8e81b..b9bab27a8c0f 100644 --- a/drivers/video/fbdev/core/fb_defio.c +++ b/drivers/video/fbdev/core/fb_defio.c @@ -69,14 +69,6 @@ static struct fb_deferred_io_pageref *fb_deferred_io_pageref_lookup(struct fb_in return pageref; } -static void fb_deferred_io_pageref_clear(struct fb_deferred_io_pageref *pageref) -{ - struct page *page = pageref->page; - - if (page) - page->mapping = NULL; -} - static struct fb_deferred_io_pageref *fb_deferred_io_pageref_get(struct fb_info *info, unsigned long offset, struct page *page) @@ -140,13 +132,10 @@ static vm_fault_t fb_deferred_io_fault(struct vm_fault *vmf) if (!page) return VM_FAULT_SIGBUS; - if (vmf->vma->vm_file) - page->mapping = vmf->vma->vm_file->f_mapping; - else + if (!vmf->vma->vm_file) printk(KERN_ERR "no mapping available\n"); - BUG_ON(!page->mapping); - page->index = vmf->pgoff; /* for folio_mkclean() */ + BUG_ON(!info->fbdefio->mapping); vmf->page = page; return 0; @@ -194,9 +183,9 @@ static vm_fault_t fb_deferred_io_track_page(struct fb_info *info, unsigned long /* * We want the page to remain locked from ->page_mkwrite until - * the PTE is marked dirty to avoid folio_mkclean() being called - * before the PTE is updated, which would leave the page ignored - * by defio. + * the PTE is marked dirty to avoid mapping_wrprotect_page() + * being called before the PTE is updated, which would leave + * the page ignored by defio. * Do this by locking the page here and informing the caller * about it with VM_FAULT_LOCKED. */ @@ -274,14 +263,13 @@ static void fb_deferred_io_work(struct work_struct *work) struct fb_deferred_io_pageref *pageref, *next; struct fb_deferred_io *fbdefio = info->fbdefio; - /* here we mkclean the pages, then do all deferred IO */ + /* here we wrprotect the page's mappings, then do all deferred IO. */ mutex_lock(&fbdefio->lock); list_for_each_entry(pageref, &fbdefio->pagereflist, list) { - struct folio *folio = page_folio(pageref->page); + struct page *page = pageref->page; + pgoff_t pgoff = pageref->offset >> PAGE_SHIFT; - folio_lock(folio); - folio_mkclean(folio); - folio_unlock(folio); + mapping_wrprotect_page(fbdefio->mapping, pgoff, 1, page); } /* driver's callback with pagereflist */ @@ -337,6 +325,7 @@ void fb_deferred_io_open(struct fb_info *info, { struct fb_deferred_io *fbdefio = info->fbdefio; + fbdefio->mapping = file->f_mapping; file->f_mapping->a_ops = &fb_deferred_io_aops; fbdefio->open_count++; } @@ -344,13 +333,7 @@ EXPORT_SYMBOL_GPL(fb_deferred_io_open); static void fb_deferred_io_lastclose(struct fb_info *info) { - unsigned long i; - flush_delayed_work(&info->deferred_work); - - /* clear out the mapping that we setup */ - for (i = 0; i < info->npagerefs; ++i) - fb_deferred_io_pageref_clear(&info->pagerefs[i]); } void fb_deferred_io_release(struct fb_info *info) @@ -370,5 +353,6 @@ void fb_deferred_io_cleanup(struct fb_info *info) kvfree(info->pagerefs); mutex_destroy(&fbdefio->lock); + fbdefio->mapping = NULL; } EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup); diff --git a/include/linux/fb.h b/include/linux/fb.h index 5ba187e08cf7..cd653862ab99 100644 --- a/include/linux/fb.h +++ b/include/linux/fb.h @@ -225,6 +225,7 @@ struct fb_deferred_io { int open_count; /* number of opened files; protected by fb_info lock */ struct mutex lock; /* mutex that protects the pageref list */ struct list_head pagereflist; /* list of pagerefs for touched pages */ + struct address_space *mapping; /* page cache object for fb device */ /* callback */ struct page *(*get_page)(struct fb_info *info, unsigned long offset); void (*deferred_io)(struct fb_info *info, struct list_head *pagelist);