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: 857040 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 79E6E1FA251; Mon, 13 Jan 2025 23:16:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736810205; cv=fail; b=de3rbh+SPdO6SzAVZZif+CtJBDJZf2WpeHtbtp8SQaFybxfec76AcdDg90J8m+zTxLYU+5HRQH6MiLQZoMEAFvkn1dbLXxZau5kK9csxod7cteWgTuUEdbUffBeIg7XO1yZgro3sPqrE9WWbgd8GwAjm1Vx2184hLqK6M1cydjg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736810205; c=relaxed/simple; bh=RTB8An/nJBE4QuuPaAhFkp0LD16ubYszjvp4eqYT/Do=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=RHFFan5VrwqQLMnK4azH/b+IaJqimMKCs1ZRpjCvZpYfEtuPJZd0Tg6mT1aa6fJFzJ0C3uk3w6ijc50ts9xdJhVxv5LwBgZ8UYYLZwfVGKq1ZQumyMBHfe92C8UM4VqKanFlTqOOkJ/+EODhHfgDFtdpWrG/vZfxSYHZrQMI9iU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=NOFVwKA8; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=eGo1sW2k; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="NOFVwKA8"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="eGo1sW2k" 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) Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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+QmhzOino2U9UgXLXCMWakzObwKVhVv8X7/PfIGhPiZwFC8WZZRKMTdKsimwduYlVawx0zn81f9g7XIXR7+jx/ySJ9rP7cRC4f2I0GG1NMP/0T9m7NGwYRxb9s0zygAxpG9wqjhOMK1zuB7KP0J89tFoZiu3W9FgTXEFF7KhXK4TSRV0wcr0nQHtq4afWLxpwhoN/aPk51H7wbBQlXGxJSKHDXinWryu2w4vKfhDcREIoq3Z2N/2aoyoJaS6b5QCjE9ivBq5GKDei922TtPuZjJbJKSbmgLUaiRFdVlxJjA3P7NN3ca39GAUEPslu4tYLiQIGWQxwqqGQzapsFaSK/rcv96xFOWlAwGVacrXh7s4UWsC3D0qg0IXWae/ywa7FY1fxqIpstmpApGwYE3bgrhtswje9Gi3Hxo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ook.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/Mb5Cm0bu+JnP4PF40bURRvySZTKNFfYDuRKfaSJv+zDyAuJOnIaA9vLNrFew+RwyENq/GIMpBwyKOQGGrlR7Mc402EoyJGgsSRwdC0Tek9zJYIYlsxJnHf+OWNEdJBogsK1fVS2k+jLYctVnXSHBX7ZLEGCjv0DEWZw7vlzVb5Vk6+BbrRPzXiEx2NTWF6I36KDvN+27FOvAaEnwfoZHXGrfhhZS+mSwMIcVQlBMmOEG7WHNXkM+bEBM9O6ACVOElUWvPslptnYkUgz+8QDBbO9B66jV6g/fCo69gBNu73ZSqP7doJ3yPi1nXrdJRwhUrqT6h5gUYy8RuMiAY+v7cD0fX5S2YROHvNm1TTnGJD8xtkTF0prk2lgZSF4pHoHqmGs2o676D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HKs/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 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: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: 857039 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (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 005681FBCAE; Mon, 13 Jan 2025 23:16:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736810210; cv=fail; b=F9uRPm6iZNUY4olSCpLTN9O1kCm82Cit6RG06M12jlgR+qrmWbDP2X+p6j2BvX9vfLfV6kTmfHwkY2gF9TqaPFRSVgO3J6TiJMEBmII0wMwZ1uezxIhjh9tsSxPWVKiWbNbpeh/FnIYqpdZyqKS6nF82ZgraMnpl+BAMUsuiSEk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736810210; c=relaxed/simple; bh=BINz8wPKC2xOUtEX5tHJFJHlV/5fqlXEhjdp5oKnF4A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=ShXtf/TYXNL48Z9hIERyGb2B//tudlDzz4K8eRe4cIdzqTqE7lEWuoqNiCb0hUnWmxTeFgSeQr00eJetzjUahbSjKP2SpOdJiDe9a13Mv+SCyfQLuWK0UDMYbxYCPOb7376rg7/+CeiAIl3ixVar+pyZCterQVy5f5UQG+9bM5U= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=MihEW+mt; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=RVp2zc9Q; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="MihEW+mt"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="RVp2zc9Q" 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) Precedence: bulk X-Mailing-List: linux-fbdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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:13230040|366016|376014|1800799024|7416014; X-Microsoft-Antispam-Message-Info: 7VBgbXd5AhUA1rkqOptH6NETl8cZzytWkfPvWFZsHTXGJy14QvCS6cjOSLXYZYQ0HIYWd/QXDNLT3mgRIRsnniQMInK4WXQKNWldIq+msJa3ym4ir50JRl8o/TxKg1ODnOq1N0PtwP9BP1Plw8CLne5EJVtxV6z7dDrT38Hx4bCKLUIXD8o+N7pJuq5Z7H6/LE91Rta2Kt5S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K59Ewa5ksUM0ELOfTGxGC0i53gUphBAzfVv4W+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/sZkKStjgZ16ppR8qUEMyB+IiofmJwt/qaKAaJzpA41HJLARWL9/eSMU9MJIb2UgTBQ/7Qu/KOTSjmbqjqTiUbN9Kti5F/gopCh2DMLa/0yFB3je5PaJD+k+WXxXL22NsO9JjAk9bRlb9MCefdQ389VedLxqjff9f0Jp4tjdkuQTHUqU3v9panTVbkQK33lwxeMXfFZnFpqSKCLu3dAvK+Drd1A733gb8IOLkkwAxS0sasvW+HWEgg6PsmFL+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JNErsMNTzH6NyI+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 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);