From patchwork Wed Jan 8 16:18:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13931273 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 DD9BAE77199 for ; Wed, 8 Jan 2025 16:19:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DA55C10EBF6; Wed, 8 Jan 2025 16:19:14 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="RWnyotQE"; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="Eq23ICEQ"; dkim-atps=neutral Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB15410EBFA for ; Wed, 8 Jan 2025 16:19:11 +0000 (UTC) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 508FNI5V017695; Wed, 8 Jan 2025 16:19:02 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=TeW/+yJcrglGhUjMtcHmixJQKg4v6rstkAUVUeseIlM=; b= RWnyotQEMtOTg1BGQnAEk/X+3ocXuzxIT1Vys/Gx/Fn5HjbrxWHpx7k7LyieuhZC X2P/VQsxK7cYYdE4aGAPEmtnd6Bm7IXOLNINtfJO3syjUQZBlR4S30sAwyvrkwyW 4xmj6NyKJO4ldMUzrV/vHtt7dcEZMF0wWRglU9+ApceqRxqRqAgsIMgeggZrD00s UhfTGwgYN2hw3pAmOXSN5NZV91vCBgrqyY8IqLqSfzscVI9f5wM9kBP3JhKERiBp 7uEs1RV+cNnrprM8dDBPxqKGdhXNBKq1D1iyhVhloKbRJfwL5AfeRnxW//QMvb7s nrQDc3iisEmc/gbJ9SX2gA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 43xus2f7td-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Jan 2025 16:19:02 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 508F5tOj011115; Wed, 8 Jan 2025 16:19:01 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2048.outbound.protection.outlook.com [104.47.66.48]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 43xue9s9ps-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Jan 2025 16:19:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=W4gdT+7hwaGcSn/vCeI6geDWnpxrlmiQJeVaVUFccnEOtI86i2J82RY8lzCZZJtFhGZxLys09m5fLb+rBPgIIdjdDUSgVU21yIE5Sr0SWWuHIMHVJodUm1ivzcRvyCUvsWa5Osa8rVocffUfoSGmYzQbf/IcJp1LxQKjy7tGNKX0ZoeMHqFheFJjsMtu/qNe6HfLvLzSx/Xgy1/5BOqCtuBtcnSMRBnIq7k/ylMy4mnzMTG9BTCP7T1a6QUADvKPRHbFe9gS6DkMydxvyUqrntPDbAMiPiE2faixdlg002mVP/oOvxVWeFowJoV64hfPh2BFGVv12rUS8sgfLPeyrw== 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=TeW/+yJcrglGhUjMtcHmixJQKg4v6rstkAUVUeseIlM=; b=WOv/8cTdQTCMh9/qyQJcjNy2e5HqNBnIO3pHxq3qMDMhhuhR7d+PuzeS7S6PZD+VHfoqrNmVXtu8OFwryGwrNh2byOzu4IdVmmQFO+YNiEzklj+VCUr+4piWDVD2IKIJ8tqf2+WIM5nR5EO++2drNHtwXTlra47nXQviXYxk5rjjjg7bOB1PcrlErn10gT2HRkRDfS8GZrhIL854EO/g6IAPb7guGusE+x55cDnYFylJq0sUGwwF2SD8eju6wOxylf6oKCHGNzDeT84iEcBwpTrtxfA8L8+WvOLuLPSI7XNY5WGSorqK2BNU6NcD/s9zJn/3hJW7gSb5hZYOspcg8w== 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=TeW/+yJcrglGhUjMtcHmixJQKg4v6rstkAUVUeseIlM=; b=Eq23ICEQuhM7omv1xTKjHAdBW3ZSAKOti/bdCVNa2tZDXhi6agPlUOx61hxzJV/F3OqHXSxvd3mlAopf7Et0uA8qWudNU6Ce/V2oK3SrBWuGKRpwm9TTn7iQJuC6G6oT+x7KRO04CMuQJuUxKGaWvW2m+L9BgT6dcMKkFg7n3Ms= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by CY5PR10MB6046.namprd10.prod.outlook.com (2603:10b6:930:3d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.11; Wed, 8 Jan 2025 16:18:59 +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.010; Wed, 8 Jan 2025 16:18:59 +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 1/3] mm: refactor rmap_walk_file() to separate out traversal logic Date: Wed, 8 Jan 2025 16:18:40 +0000 Message-ID: <0c53589f34a6195938eeb58c3a88594fa30cc90a.1736352361.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0063.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2af::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_|CY5PR10MB6046:EE_ X-MS-Office365-Filtering-Correlation-Id: cfc8154b-c2a1-4298-b3ec-08dd300027fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|7416014|1800799024; X-Microsoft-Antispam-Message-Info: 3ahoROuAXolnvzPpI35353fLbrlSN6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wGgczJFSNpscP5SBSUiJH4utNXDzWf/VSPk1NxB7DDw4qCrO/UrCfTSpHJJCLrY7smVRob7Vefpi9+iOo7EnYXolVF+viA8i3fELr93pJhunzRmuQD9EzSIfDRfB0kJD39ViZESFylm1znsoo+/XmKUSZAqekZubFs8uX/dAzLcmMw63IyJu1NwAqpy+GIadD7da3rP96kqUa1metQ6DdgsGLNfA3BiNGdkTFP5OfsjEgfCVt2UkQZRxkryO0VIvpGLwKn8sEQVMZI2n645JSCgWWBFLwmbHfhDsQG 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)(7416014)(1800799024); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ucPBUDtYS6gcp0bQdME2RKnSpyz5JPYE+2hdOcVtN9qLiOJjU2URUvPE/x4CNOlzsiezjdJ0Dgxc9W7UMzKtLUeAVlaZtx6FWWTGqYlOrTrWhyj/PpwL5JBFBosi1sbi5CKMSBg/MNDOxQvCv/za1pvovhwxHFU1XpADIkU2usSRGVu/cIT5QOCA4flE9Y7qxe0o1nETpie9hJkdoMhjSY9mk3n5St4VQrNDDtK/2ejG/8v10zfXmela7AFt4JUBnIbUXGcQNAPVXRqA2QZ6z2ZUT08akr+715SgKJEuAaQTjbpBf7OGPYSFYyODK/+Yt9+pKlLKxBcjrQ4lDTInd0YSxVNsyvw3hwls9GLbgmMGnahXZ1vqqZ4OOpVCgGghsfvKPPqGPu+QSnWkHXklzrWrYSXFZ72Y9WXbGbTwYRdX3kHIc2iTFq1AuiArW+dghD+u/lsifsHiDj5gY2rOhfB/jDj9g0brbAZvXzpJMGuecm6IWFdoABrJuLNw45gjm9VbT29gYxfUoEQZ3AFe6K36YRcALEwcDiylsRLF6VUjyPlu8cOvtWRCypq729rb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Count: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: IJ/CAscFtguQFP2nBpc53aGHAdz1SldeIUsowPzXeisjamDPPbefK1/Ggq2D5Y71rP/7Ex5WX0ug78bwafdeh20n8XMZCXBW2Fd87LgMNtWCQH8CyIKGsjHfNGquiQuxwSOHbwhy8zUs6aY2m6XbMVujZAtpx9fsRa+bXmlwv7011m0sFQ3KRk4bmH4rGQt9S2P+EvQpdqPj8WAUEXIk9SUVD2a2g+t1TN4UV/DH6t3Yen7p/20nMMbGc7DQ8OEEKrjgCMyaEm6d+QiZAa5MXtqCcK5NSHYC6j+H7xEDlyZoOfel/6+caTXs0UmRGo3sYNqvcnnKqYYapnffmAVm8l9vX4CX9ctdH7QlLZoFV9gVGyyxdfEURdahebKnj6SPLCDv6+k3llsFyLPntsdvqmOMkZeeDTGVx4ZVZO5tuvn7Sla9yNohsRuKBDrqStywospuJFnOGX+521AtvRfll93GfjnRc68meyvDi6PYIx/kGKc8EkMYUGz+f3MRDfi9jthBVi9mc8L6KaQekyOTFh1erzVn4hYRIGdjEkcoSdS1a3Bq2Op9b2bwWuZ+KNVRIPp+HG1bHPzLe+mhUTta98gnhtl7K0gnN5Yr+hCbmr0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cfc8154b-c2a1-4298-b3ec-08dd300027fe X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2025 16:18:59.1281 (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: GP4RvtXxEuGeEXJhRK7KmiMRiYscA+4+/GLZv0JaHeKK9kgLVfmgimlQSqBG2/fJq21g59bVn40hTQIcEm6bJcE5OjJOJ+CTO6R0b4M6Cc8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR10MB6046 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-08_04,2025-01-08_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 adultscore=0 mlxscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501080135 X-Proofpoint-ORIG-GUID: csesqimgMFh39tn_UcBcPEE2_sOHbexQ X-Proofpoint-GUID: csesqimgMFh39tn_UcBcPEE2_sOHbexQ 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 | 81 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/mm/rmap.c b/mm/rmap.c index 227c60e38261..effafdb44365 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -2710,35 +2710,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); + 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); - if (!mapping) - return; - - pgoff_start = folio_pgoff(folio); - pgoff_end = pgoff_start + folio_nr_pages(folio) - 1; if (!locked) { if (i_mmap_trylock_read(mapping)) goto lookup; @@ -2753,8 +2755,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(); @@ -2767,12 +2768,40 @@ 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) +{ + struct address_space *mapping = folio_mapping(folio); + + /* + * 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; + + __rmap_walk_file(folio, mapping, folio_pgoff(folio), + 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 Wed Jan 8 16:18:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13931274 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 735D2E7719A for ; Wed, 8 Jan 2025 16:19:23 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E954B10E42E; Wed, 8 Jan 2025 16:19:22 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="IsaNJz5Z"; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="MwWIGJx8"; 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 B4F7410EC00 for ; Wed, 8 Jan 2025 16:19:21 +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 508FMioG028814; Wed, 8 Jan 2025 16:19:10 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=SClICP+IPp8rcmeGP9luWaP5TU7uyj37cIwbWaQCxoM=; b= IsaNJz5ZE+su+/USzj2szuSFJBpoicYYJUz9k3/AG8+InCXQ0fX8wlER/w1okVec lZV9yWGRGZobuZVHpUptjmB8ugKBAR5s2EtAoAFcCNnol9YcyMH/Upjd5YSiG3Od m7z7WjjpEcD/orzc/naZaJHaZ2EC/nvtvUD0gyIiu5TCixTQs4/P62CRlNxZAsBS DLVbc+LxYpi98gGWzN68Q4hDpGHXlvfnUbC+yjFzBf4cy6RRfrNuYuJi5ey5oji7 TYHBnvbR/rWsjb3YxiA0CtiZoe8/v4NZ1ywsQAcdoCODu1T+7FIpHSMQvmaZ1C0t tRm3trzWFkNql3Sk+uTVtQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 43xwhspy3e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Jan 2025 16:19:10 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 508G9Ogj010953; Wed, 8 Jan 2025 16:19:08 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 43xue9sh23-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Jan 2025 16:19:08 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ttmO+GLK4lQHcf0Nxbw2JqcIws8Mors+imC1uHhZl2qx/4nKfGWYMD4r4OWs18T1If/7uMRyzOcaRv7NzDxHVXFgfW6XMnhisftZJRH5iD0rrGSy3x23B+hZ7mgUFrr/JW6f2ASvOg6nIEa0BoHUCVGiOQvjjJ/ogFzf/s52GawRV3O3Py36/E4CGOYWRh78TEf+GsQVpjjDEUBVJyFhj9b1+oWJ9dh9zqKDCB9n6KpVnvBNWIIXrydFJTTSdCEhLrUZyL827l6SQjVeaQu6qwdpE6//hzvlpnX8Kf2Azyv5bfy+46dsM+zTdG6o+tSmpIL1idocLIL/OqIZhsiyQg== 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=SClICP+IPp8rcmeGP9luWaP5TU7uyj37cIwbWaQCxoM=; b=ybEmdCoEaBnMURJxKWviYkg+2vxxl2uGswSWxorGUSRhE8Qw9n/xgHlUFrsbpxXsVn1gUfMBskZC0lshX+f9EcWw54+tEeslZjnKtVxU8dZuSgjyL9Lqcrptmu/0SjqWRhRuCKdLd7l6QEbEeHZDyWzHSCyZigxmK0FJ7vreDtB7ADy5aOyFzmOuABycYVCK6+aV503ZHQTY8rJDzD0L1qGSlFUsl1zB+XtnCj9a7wRqjkncTy/JivcAh0zqT7kEs7vZXYbo4umeZ8WWNvUYTqP5eT9jBIikxFuTiE8t1U9cDhwbneonp5hYjfakBc5NXXxWChYevWG0kPxDNxTFTQ== 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=SClICP+IPp8rcmeGP9luWaP5TU7uyj37cIwbWaQCxoM=; b=MwWIGJx8LjM9egpssUdwVIEuiYoSxNRrKTnLWpW4aBb+Fhi2pWDxhSnNIDquPITCPREuQ3blkN29JL5APMD+zd9OnU0/wnYnk49oPZMOgUPQG7t6Hzk4GbMFwTdPyYq6tirS1fywE0ldjUAspzjAMTEsrumrUTX8Njv336LEtdg= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SA6PR10MB8134.namprd10.prod.outlook.com (2603:10b6:806:443::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Wed, 8 Jan 2025 16:19:02 +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.010; Wed, 8 Jan 2025 16:19:02 +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 2/3] mm: provide rmap_wrprotect_file_page() function Date: Wed, 8 Jan 2025 16:18:41 +0000 Message-ID: <701a67692d5bf9c8424cdbda103c988bbb278e38.1736352361.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0241.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a7::12) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SA6PR10MB8134:EE_ X-MS-Office365-Filtering-Correlation-Id: 516a9acd-fcf5-44b7-f98f-08dd30002a21 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: NR7c02bK5HI2CTSD2rMxeCpwYCOZPtqg09IYGBBaC0KS/97ATZYKkfcBmBoGwYaNBCEc+b8y4DyQxklUCL/etziDer4xIofHPQPnw/v7u8+OQctJppnkmzx9An1OYZ7SZkv2B8yGcjGiHJ/fuR58KTjVx7iFX2ZHRaGv/b+7g5R4FBZ/zAlteZp5v3UOcSWeLN2pZvdqkd1OUA6t5d9AEAV8xpm5k/TbRnrW393mRv+E6QVw/uAsGlF1s50zaTaalRZtY58ecM+TGCHULLDhNMcp4vomya8ybyJPD7pw3mXrGI1EGteNuxrsx3FpQtpckYj1cj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MU 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)(1800799024)(366016)(376014)(7416014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: pPJh7cbMkqmAVJlsuZwd6jkwgpBo3+IdRgXdLNwy65laFgucIwILa9FNyZIqMH4pp8ChfeQYV4uX9XSIgMhtHY0Cs5DLDXAJp9hZ1/g/WexN4DKQczhIKVkbKRq+5hu1wr05C0jeVczykfA8XPqx5oEdKmg8lTic1Zf+2MLscF4Qs92R0JPSTnfLI0XWqS43molxBOeJRD7/xW98lH2uVGB9hsgZDHnv0yT5F3s4oTJCpmMvLwRgxGjUsR3UE0G4HdVdZcGosLDzFUy4gnHyju5Rmjs2vewJZpyOptsIZFunr2HZgrCZZEbpYDz14mbSVaVkJS6eEnc5yBGMqWRC6ArN4YBTK+IVf+Qfl/decjrNjwkgyYeaTyAQW2JutiFGVTgohTvEAWqsQOJrBs+1cjS2WF1gJfe9bCN7aJ/S/rzQPXOf7gZtS1/BqBjm1N/p6iEuqZ53x8nWHw6TRCE+8+KEnQWmJ8lsj5/FmwUTG9Y9p3GPHEfs3V4KJ4erUkztFoYe/l5CP8XZs91RlI7lQV1okPHnTdIl//XvEvinut+hLEhdeaL86h8uLUDQyQ1r3Upf1mnU0SzLtttEHFjACc2O85TL09ll4oGFU7wClyp5PRcdKxdwa9ouMuLpxj1T9ERcXlFHPBdSnc4MKjcIw17MQWJfQmyeIryfqwEUDgVp1kliTKfXwz9RBBlM3wKwvpCvDWUsVmbyzoybmG9D6sJS3Bh5tFycKEtW7CQxfDR3Lr2t7DCQS5F341d+Sv4z5RdQN1N1S7xta1Gs85EJtVaLw21gdLYc5pryua4vJql+0CV4asxRIHxt1X4qocWurLEi05/DDc0hhejBQP3UwNUndLe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6Bz60ng6V8Bfz34IPHEa/2208P1u7GHnt+vCgXbtCt3K3nHxdMpfcgsCDhs6XrzH13m8BWQmMLfZgslUQWfcNqXChr0QNDZ2ZWE+G/ra6nvw6NVS94lOnIUlURxVFF4891XKmze4o961O0MJ26kMwW+l1KtS30H5f6o16h2Hauiyu2ljL5itM9H7mrCa1wHKSMJYNhMD2UqNTAtYKKLG54/HZkKvylPpPgmrwjtzdkCWozh4I1qO6SQpliYz4zsWhsC7WevNnnaaVJVPxJS1or9sndjmt8OIGMELkSsT4AK6+HfkNucMSREm1i6V1EqoIZM3+m32wOEwChX9MIlVYG5+o7HldNRPLoLJV/PMqUQDy1Ljim5v942glb7yD7I= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 516a9acd-fcf5-44b7-f98f-08dd30002a21 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2025 16:19:02.3962 (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: wj9+j7AMv6hQo0yMNjQ3L4KarQR6DJ2tJfy/qSXzieEBSDvN2GJswL5qcHv1OnxMAowa0lrCxXwne07AonFMTpmkUGAS5PynYGNSd0w0rz8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA6PR10MB8134 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-08_04,2025-01-08_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501080135 X-Proofpoint-GUID: 02cpufoxGwLD41JEmM6zpB5ynB3c1xOL X-Proofpoint-ORIG-GUID: 02cpufoxGwLD41JEmM6zpB5ynB3c1xOL 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 - rmap_wrprotect_file_page() allows for this operation to be performed for a specified address_space, offset and PFN, 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 | 20 ++++++++++++++++ mm/rmap.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/include/linux/rmap.h b/include/linux/rmap.h index 4509a43fe59f..9d80b09e58ae 100644 --- a/include/linux/rmap.h +++ b/include/linux/rmap.h @@ -754,6 +754,26 @@ unsigned long page_address_in_vma(const struct folio *folio, */ int folio_mkclean(struct folio *); +/** + * rmap_wrprotect_file_page() - Traverses the reverse mapping, finding all VMAs + * which contain a shared mapping of the single page at PFN @pfn in @mapping at + * offset @pgoff and write-protecting the mappings. + * + * The PFN mapped 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 + * PFN maps to a folio with a valid mapping or index field, rather these are + * specified in @mapping and @pgoff. + * + * @mapping: The mapping whose reverse mapping should be traversed. + * @pgoff: The page offset at which @pfn is mapped within @mapping. + * @nr_pages: The number of physically contiguous base pages spanned. + * @pfn: The PFN of the memory mapped in @mapping at @pgoff. + * + * Return the number of write-protected PTEs, or an error. + */ +int rmap_wrprotect_file_page(struct address_space *mapping, pgoff_t pgoff, + unsigned long nr_pages, unsigned long pfn); + 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 effafdb44365..46474343116c 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -1127,6 +1127,60 @@ 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 rmap_wrprotect_file_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); + +int rmap_wrprotect_file_page(struct address_space *mapping, pgoff_t pgoff, + unsigned long nr_pages, unsigned long pfn) +{ + struct wrprotect_file_state state = { + .cleaned = 0, + .pgoff = pgoff, + .pfn = pfn, + .nr_pages = nr_pages, + }; + struct rmap_walk_control rwc = { + .arg = (void *)&state, + .rmap_one = rmap_wrprotect_file_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(rmap_wrprotect_file_page); + /** * pfn_mkclean_range - Cleans the PTEs (including PMDs) mapped with range of * [@pfn, @pfn + @nr_pages) at the specific offset (@pgoff) From patchwork Wed Jan 8 16:18:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13931306 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 B16A1E77188 for ; Wed, 8 Jan 2025 16:19:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 340C010EBFA; Wed, 8 Jan 2025 16:19:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="PSdiB9Zc"; dkim=pass (1024-bit key; unprotected) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="UrTsPANr"; 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 B30CD10EBFA for ; Wed, 8 Jan 2025 16:19:25 +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 508FMj3r026596; Wed, 8 Jan 2025 16:19:15 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=TZu/uuSjUZ8ICVP4x5tQiNhJPu19wiRwvpNOeMnqToY=; b= PSdiB9ZcxXpIlzQHzQKGgkf7Fvz15jlhXcND1JXFswx6n5m/3vipieRX8apUaqex tjqQA3uuJK7gdullAxpKb0+HjQ270jrbkjfz6HyibnRHrjVuBn0h0eRz08nrDWZS OuKCZ/9xKVglLPO2q+EMaTuNxtbv4rR2LcW9cdW5rm9OBhJ+yI0VDN5ZW2f2kXeo ZN1bfr6KrwjykJOfZLHxG56IBywQBS7oOGoMrwLq8sest9DSRi0/3qblqeT4W1XD OurggX4kMYSUYTke9uXmAVJqtC970e+NYJd/lKmCRI70Hr/t5yW3CqH4ZJ20pH3g cxIM+3TThVqaqXm44sXlrg== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 43xuwb76xq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Jan 2025 16:19:14 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 508FOTvw011977; Wed, 8 Jan 2025 16:19:13 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2168.outbound.protection.outlook.com [104.47.59.168]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 43xue9sh65-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Jan 2025 16:19:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=filFXLRxUw9cuDhR0XNsfFu0rkVDW809OS2OC3EAzOHi0T/9pg81x65UfOkDoxgiSJHzlTL+fi7CAn5+osaA8rkFib7thqRKY/+71bnDPNNBkRO+S/EGcgcnJdP3r3cW+KUaxIjXCKHW7SzUZU4Co45Y0OS4zOY5FbrctBRigWmp0F2LidmIxnEPwrr89dcsN/NmjeVcnedaIQ/1SrpEBBVp5iIJ3LtSbwNyw4ZoiFW4crgy+168UVmXYHBjJ0zAzCtZzEGVe5TPHpPl4cGAbscnbnFTVREgCtbW226ouFLLeEy26AzKvtvAYPjhPi2k13rlZOu9OfeJ1IHK5exKFw== 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=TZu/uuSjUZ8ICVP4x5tQiNhJPu19wiRwvpNOeMnqToY=; b=aWq8PgBwHj2GRkMc7nscYcyZKwkhZFLYe7laZxIR2L1FUhU6KT/l3cpWl1Clok0mvfT80LFxABuzmnpthmnv2CsXYOoVBtoPvCQiOC/095Nvp2NiakviqATAENj/4fO8EdwWNwqVGXKqax7AYQBlHau6kgnCg/UlAHBVk1nn9An+dDfgLg7EG/r8MNX5tdrNBZ2MhuQbDI/AtRVBrJDrpMsQArZAEx4Na/irXvCVZbOgjGUhnn+n/93CKzdjr/U/LkxTZ6/Azbzjc66IL5FVV4tPDuFv7oMkccYaVDBw4V+BzolHUyMzuOmUkXdoAEK3PN9wEs65/n0L+RWF+7G5yg== 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=TZu/uuSjUZ8ICVP4x5tQiNhJPu19wiRwvpNOeMnqToY=; b=UrTsPANrgUMEYVTbY81uE2hqF7Jym1YfQglVSdY7lg5kUyqjfdPbwxyLSfWIh+lRPnhWMTS82gggVxwEHFY9F56Z0+ElzBcYF7YCS04WE8AVMWS3adz5Gs2nfGd+C2o4SwYSFsBqCxkTUnLcRXMJIDxRJpT+Tx3kl3nNFQsCktU= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SA6PR10MB8134.namprd10.prod.outlook.com (2603:10b6:806:443::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.17; Wed, 8 Jan 2025 16:19:07 +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.010; Wed, 8 Jan 2025 16:19:07 +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 3/3] fb_defio: do not use deprecated page->mapping, index fields Date: Wed, 8 Jan 2025 16:18:42 +0000 Message-ID: <1e452b5b65f15a9a5d0c2ed3f5f812fdd1367603.1736352361.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0055.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2af::11) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SA6PR10MB8134:EE_ X-MS-Office365-Filtering-Correlation-Id: b9814441-dd7c-47cb-d632-08dd30002cb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|376014|7416014; X-Microsoft-Antispam-Message-Info: r6M51isgq8+SSsiJciCfzEWBK+d61yjMUO0frPzjbB5aRjrumlBVUOUKa+CETEsBiYaBOJDLiqz+qzQgDesb9LtH5rC9r73ftsF4dwIqn4GsqXXSe+HvQv6H+ycLWulBptNgUvi5F2Eri/mrssQiuLI8oSghkWmHKdhGUfQjuJ6MAt9kMRZPl2P7GWu1NwuHZzPknUBJQVtgBlg8QnXmWQ2q0U2TU5J0iLi+poDuTD4DBYzIAC/6j2IYY40j0BegRPJ6XtFDnD8rSZwwh11e76wo/GHBqIFZMOLQh1Vd1uwJpzFFVVDnKlsAkrGxP/VAO8ZYj2xcK0gbApis//COWJXBXDAwo5k6HHKXs2EQV5baPinkU3QBV9t6cN7ylxIeK7TCsNz5Q3I8nqgBnE5OxkHOBeDCButTQCihRiEDQRrwGE67+TYWiqHfEi1JtotpizVT0hhQDQcQ56Yslaw4RPQ9/G8es895DFczh8rd0dlzki8KRJxQLGupUAxqn9IxJmzgXtvapXRyTSjThBW3dIQ19b1xYzwvqGA7F4nCB97argbdEgqVWck2BLkCVc2YLcUMBQQtOqJJyY9Nwyju+w9smvCpuZ3NoVJ/m2PX2Y1qoXp5z2PYYrSjLt1BaOXdJiH7waIK15Wqdim54woZJ9nEsmWoztb5DGJJRCJNAjTp59yrCAtoKCJ5d8HqaKKhL4QC2op4wQ2PApoLXwOzFH+gzPMRMvQp+PNqXCWS3gKXmbWG87kr0wPBfE7o33C8ruCN9k10O5vusK5h8KKGhT4kZT4zH4G+zYIZHHdSToHGWjTymO8iSq2DnsKHjBLvSzCbNGXmUL1qkx9G+CtvvI3atEUqcxxEe/Jzb54rThjZgNqlPWu6TiGhlVv2FOeK+rTo+v7ySXaft2JUBkXO+e0dwRPd3AA4vscmquKkNywowfPplMfRy39PxUgMEYMW7Oq3Qvjp1jCCqdnc4aj0WtfuGhXjx1P4ikpnp4RpE77r283V+dKs7ANyGVMIcV0EprE91jENpXwrQE67QCwaxZN07DszcwHInfknTH3XMPMrN4vrp/BmaPTKQnC7MpPVkX/O2MUPhTppCfQGBLN0tIXWVF2edfyVauSb4lZ6SD0SWlufYpZzITKTIjZNsV2z8+IhcK/xnhWztGP1MahP1gaxbG7Z+WEdKdnJ5H6hjq5plo+tefMryT4cDEnBYLZGdQrdKCzVPuOCDECjdd7EToUzp6JFqXpKCDIUKXtt67BkgX9YvqJkp8fRaKJqUXN2+Fg03MY/3kvk7zg4p1zAwjvGD4ahNgXbhe/ErRAciiinv7Gp3hMOvzcxuCpeSK0LeSVuGEwQOm5RkCZb2ghU60z0oZD8XgCMB16P680j6UU8ArLoV8rCLx0Rm8QHST57 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)(1800799024)(366016)(376014)(7416014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bh7iueFRoytr/2fEmzAead2h4aOrKZQuOlD8QoOh2SgNE5uuJjNTRxspAzPu42TCLAC1YqctH+77gU2Xasm5IbJ0lpt59iBlon8asQfrhgJGILR+xjDI5ZBArS8AZIRZ+sGWl7En26jE30tpUvMyWpT39I24nug4I/com4ZeC9mI9XYf6wDcQwgXcExwE+PLp51etO5DtlgG4Ocsz137YAT7Ys8PQZte67JSAEmD7gvScYlVbCnPPzmoQ1sILXKsa2b5qAOZlbT09i/+K5Yyy9dRr1ehMWzwbD+okvqtvD3eUSqtNFZpYSCrhM50Onq8yWGGebhUCe9Up1c53tK6hPScdrjr+UnI+lih8JMO4Ce/aaDn+NYLNlWeIdZNk/s5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6bJhwAhTlTnfjYMi+YGagyG2jh1oNPY7tch/4FLcPuw8iL0HbuLy0aXqZP+ms/ia7QExEm3TOtDFAgnlVVunbsdJ0BSHjUKgcCVt/G+ooUjR6QRExj+GuTqUNeZfsWa59n65V3sQz6D1M1jnbMJnF4v/OBn+0ZQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: FwaBRbP3iYacfQIeGBssGkTIpy4BcYpybhJMscNh1xuj3pex/JmgzDA3mJn4qdlJEh9mgPGV1OTNAVqhQNXtDBauajplq3xrv/eI6a8piuCLP0zuNSL7Ftr6iLtVBqsqmahVpm0dMdQiNfoVINrd8CHbrGia6MZPx5MuGdUHaSjzJtZGy8gbi7oMKy0TuQ9hkhC5gRmuJJNhRw9LyyLQQpHxV7RjlxUF64DpC9Pj2ZPU4ZR4qjVM0NSm22jcJnbpvqbieizYTQ5IAmiIvW11MxLH0Ca1sygFN5UNiL4Ow716mV688eKCOZqqr3dSrkyO5Cc/OtbWEl7J5KNzBbHvbjehg+SQakZJnfdP9B2Napx0F5S8Fii5L4KdIDUOajDqLsSwyGFVCpf7twFCzv6/k5GEJ6ujSHFqG3HJveVOcv5/tFBcyu8jjAdaphfcismWRTHeo1nrE9AOyP+xn0sIE/9/AXMH1G1OV8x9vfVl/jnpRgXuM1z5YXWLkwNlTTlhGyOX5Mcv84qTmIaIt0IFTRpuPnpgWUeBMVCzFWGaCDf6DumB9zAJ+nhZHM4dZDGvfCxM8axkhOWQNC2VFMoo0hjdkK0ks+md3miFcAJkNF0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9814441-dd7c-47cb-d632-08dd30002cb1 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jan 2025 16:19:07.7273 (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: HmDADrbMWwNeL1cgWrmKQTF83EgMQzX11yVmy6h1G66yGbeY4Sof6n9P1fQld3JHATAW1DHmstywIFP5kKNAB3NAYskz+TSvHFFyGToJjdI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA6PR10MB8134 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-08_04,2025-01-08_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 malwarescore=0 adultscore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2501080135 X-Proofpoint-GUID: 8pu8T_vnCHIWtyj-NsAbCUIFtiogF7hE X-Proofpoint-ORIG-GUID: 8pu8T_vnCHIWtyj-NsAbCUIFtiogF7hE 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 rmap_wrprotect_file_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 | 34 ++++++++++------------------- include/linux/fb.h | 1 + 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c index 65363df8e81b..186ff902da5f 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 rmap_wrprotect_file_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. */ @@ -280,7 +269,10 @@ static void fb_deferred_io_work(struct work_struct *work) struct folio *folio = page_folio(pageref->page); folio_lock(folio); - folio_mkclean(folio); + rmap_wrprotect_file_page(fbdefio->mapping, + pageref->offset >> PAGE_SHIFT, + compound_nr(pageref->page), + page_to_pfn(pageref->page)); folio_unlock(folio); } @@ -337,6 +329,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 +337,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 +357,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);