From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.201.55 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796250695; b=fZfi2DIcDP2Ls3QTipPHvXElw9Z0eC7jw1Um1MshsZwRl8jzbAgsQwMBhu/xuFLrjsFO MsaDfZVsQxgQZWgktAptw5rmCiWlfAiDFLkgm5ipeEFH7WyWq+Cu2cacWVmD+PCeFkRkl ypF1/j3C62JGxlWRH1xmxO/SVVO2EMUXLtUEZPWWC70WjjDIhQ/zjYMJkIKuweARDbz3e 6q/ugL1rm2CGGF77sN6QUmsZp4BZ6YZzePX6/+5hRuKPEaDX099MeGZnfrnlieIFC2AZ1 Z5w3yDu+WlxtQqUq81YurXrhKK9xHqSIHEv4wPnJ+HV8IJMXuZ2nhOgRspDyIk1cJ3g== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796250695; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:Content-Type:Content-Disposition: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=v7Tfs6YStkUs854cqU9BstCnUQfnK0xU9mIZy90RGlE=; b=HyvmZOFna489+ghvu0if66DIFGvZHXs5pdBYyLREOoSVDiJX1uW3C4/SggwSIfHg6Rm/ 6uKVu7I3fZrAt7k2r7uItP+eYn1I6p42xFyqw38NaGiw8JvIYOvPxSSYF1UQC0gquZrZ5 VXPR8oCV/WtFWqWqysVynlDf2VzPX/t4n2TM31k7d2ZCLVv6HsPfKSkQ0JAsTK0+YivlE DDGZi0vyShtkza+drv4ujxwaq+eSARlHWkBYeMFQ+CQRf5ADtjSiWJ9xXAp3FQ7ANC4+S ij54kNlsnyxvSemwQJbqY9P205nr0xU1tvDR3jJ4NI4q+VYwi57xso5qwqmarteyooA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=UNEVi54c; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.201.55 Received: from CH4PR04CU002.outbound.protection.outlook.com (mail-northcentralusazon11013055.outbound.protection.outlook.com [40.107.201.55]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F4030606A333 for ; Wed, 2 Dec 2026 22:31:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F4030606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=Nvidia.com header.i=@Nvidia.com header.a=rsa-sha256 header.s=selector2 header.b=UNEVi54c ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mKJegblisBx9uF+Rk83NTexV32AcZl/m8SXLTqLBc4eiG6Jq/iP9Ug7kAfdyXwAq4GuNhJJlJL3+CC1pxU4dN1pF1hCAXjzRDvp4DVETiPCh3Wwo+McTF46OO4VyuSQmcAWRjNG515opj8nk13Ase/sqi+R1DKWkUxETc6ecfP+MgvuPR2easRlZRu8snD4IETA8/czGMizXkrhl4Ti5SXD3JvXT3M6KIJPR4kKnm+luH6MYzmJlH22oKhUzlL76gaHtiUpMO2UltfVO9C8xh9CgT1Y/R6MDvEMlzhnn4Aey8YGPX26NbqrC8JoPFNFa8975rbbBay8ZV/q6U8oDZw== 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=v7Tfs6YStkUs854cqU9BstCnUQfnK0xU9mIZy90RGlE=; b=CBR4wDVDL10Shuai36I3+sEfU7Pwpc3fv6qgrc6UEhBDizcuTwJ0N3a2z9yxFlLMnr7WiVCzjKAdt52EjcGTY0+mJOrZ6ihk3slq0Oa45fuLQ6mA3J3vGa3fvuU8tXCXG+PaogZY7uajIbA98izb/yBtHTmd62fZ5Bj0iHzKqbbJJrPTZQDWqQS/F+RJ7jEyVl8MhyRoPeNHTva86/Xak5GNUGrI3lPfDoedUWtD48TJ+5/b/oBlQjDAkeX1XCgfULEetWOfX7iWvkRllB/duWHKFWAX1qMNxsyn20n1SvuvXx3JLdUVQZzRwUXFffL+C48RoJ1Ei6TENa5cgkiK8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=v7Tfs6YStkUs854cqU9BstCnUQfnK0xU9mIZy90RGlE=; b=UNEVi54c2Qsp12GNMW/9amoEYdlJRrkD3b2tpdCTsOT1u5FqSNIEeDTuHX1Jh+baBZX6pGNr7EYLXm7yTq44TQb0Xg+5rbzYbPqI1n3VJVs4U2dj+o7Dwm9MNcAh5Uj6WxmgZ5Ud1kbut34z3VUyI06NWfLfq+sW3zczhHnUeDEyDeAL8Dc4kX2sI2IjvzBjo1rNc7bvkT7dI/9ZVzKh9qojsafHUxrTi3ZLqIxnjPb11vW2UR53bI+7m9XD2mc4k6ynFFuOztWGi4moqMYBq6+CaXo86HrFu8YDLo+cVYMb3WqcOp0BBLkGWv/nYsTTYuovJItw/Q74DDqHg4hqbg== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SA3PR12MB598757.namprd12.prod.outlook.com (2603:10b6:806:52d::14) by DS0PR12MB7583.namprd12.prod.outlook.com (2603:10b6:8:13f::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 22:31:14 +0000 Received: from SA3PR12MB598757.namprd12.prod.outlook.com ([fe80::e206:100:5946:a777]) by SA3PR12MB598757.namprd12.prod.outlook.com ([fe80::e206:100:5946:a777%5]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 22:31:14 +0000 Date: Thu, 3 Dec 2026 09:31:08 +1100 From: Alistair Popple To: "David Hildenbrand (Arm)" Cc: Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , stable@vger.kernel.org, Chris Mason Subject: Re: [PATCH 21/32] mm/migrate_device: mark folios leaving device memory dirty Message-ID: References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> <20261129-fixes_core_3-v1-21-f66094116801@kernel.org> <2a677bfa-6800-4c83-a5dc-bc791cdbb24a@kernel.org> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2a677bfa-6800-4c83-a5dc-bc791cdbb24a@kernel.org> X-ClientProxiedBy: SY5P282CA0031.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:206::6) To SA3PR12MB598757.namprd12.prod.outlook.com (2603:10b6:806:52d::14) X-Mailing-List: linux-rt-devel@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SA3PR12MB598757:EE_|DS0PR12MB7583:EE_ X-MS-Office365-Filtering-Correlation-Id: dbd3cd8c-94b6-4267-ad0a-08df50c3f93b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|23010399003|1800799024|7416014|376014|366016|4143699003|18002099003|22082099003|3023799007|56012099006|10067099003|11063799006|261026121527099003|261028144727099003|261026140227099003|261021121427099003|261022105027099003|261102123227099003; X-Microsoft-Antispam-Message-Info: t591q6VoOnrOabouov5mJunloolRGE+qzx4zk9l7Y3+6EdyAdWP4AZcFHM6Hbdy87vBRTUxTEVD0JNLrSmUZAa3nKDR8eZBcQYB9a0i2qh5qlJ/X92mLkbmRI6D46ij8VxkEjsubfPNfWpLZhtHGoAWsiLsjmPENLLdkmJA/Q4TgnrooQcQMhlLkw5CBgZW+QBPOpA/AyuLCNcgMX28wk6qitzS3ZnpgpphuHqClYrqYK79rO3zeLxIzy3KU3QQR80XtUajNUBW+iXWh980n94lSUQ8pVa9zsA1MRcNMQCbMturnXlU9ccuov1Mk57xfBzhbn69P795Xk+YsxCdzX07JYlms3w73cFC1wrqZwMAPkw9Fl7YDoEu/HIRaj8ZKwZniDUrOdM+WlKWI+k85bKfy7Mbe9VNsFu+IxtqIq7C9BFzd9e7TkQcv+G6TsnR+KQ/gYk1zHM/Tkdq2wXAJjh8eqjepTRJrh+k7CsllEEnHKxdESrowvnhQxSnlBBBGSsQZdsLhyge1XDp6PKuDxyOOpghubKk9OxMdx0StABuyG2ENMXsvoYJuNHR682JHimyv93meo3vdzBVvdryH8TiBoRoT9JpioNnSxS9uv6ccDxlxzwFb/2EFILYeV0Dr++/jRysaOAVVIV05u7dP5AyQTgAvxdyHQnBcUISIjZ8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SA3PR12MB598757.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(23010399003)(1800799024)(7416014)(376014)(366016)(4143699003)(18002099003)(22082099003)(3023799007)(56012099006)(10067099003)(11063799006)(261026121527099003)(261028144727099003)(261026140227099003)(261021121427099003)(261022105027099003)(261102123227099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?zBWWM5SLuEm4ktICECWIkz75kkDgagwbL0FlXSFKVpMUmsX2RlhNSeX24vck?= =?us-ascii?Q?m6WkUc5qleGiT7t3E9r39dNjR921Z8OnX6S5+p63dYFuKL10ylGE2AIg+JvW?= =?us-ascii?Q?WGdspqiE3l31ttsEYrf+7w4jRu8bkpdZUdwY7JCLjXskwameTMdhI1HNAUKc?= =?us-ascii?Q?Q8cXtmaBW1mNpHXsHcXqBbuZB4I6Kgs7ehz76Uei77i+R5Z+aS7OKdPOmtUo?= =?us-ascii?Q?gnsp3TEumchbW63IPDUpIC0wd5uUWUMSIXXeBACK1j0W9SFYg9UUNG/aks6p?= =?us-ascii?Q?yxVQpEMy0NJ6M8RT2s7ADuRbDYxYsziJWPf6oVVhSc4olKqm93igKy+kAOI2?= =?us-ascii?Q?WPu8GsR4BUUFM79krCI4NoiK+G/0h8Iq4MJ3rWNS9jms++irJrZKxyOIKh1E?= =?us-ascii?Q?kxpaSnSQmSK5YgSkGmsZPsMTrZdIrwpyL6oC1z6uOBwJG0grptPVM4qnU3+N?= =?us-ascii?Q?xtd1SklbCT/iwW2NAeodbsVMUlQbqxiAD77Bhah0yoqmqH3Re+rbamhzTxc/?= =?us-ascii?Q?++kwCzWAXGyxf3mG7RrT7iOPYZkaW6/yxRB/1ETPwIVHs9m9SfWQWieybkP/?= =?us-ascii?Q?CNJrrvX4k4pQHgJNk+s21r9Xt6M/wa4OOQs/Fml6hW1MD1m2CxqBfoFz0eVQ?= =?us-ascii?Q?VE9jpRdtY8ocAcgH+0IehD3+7yieWDKXmIYr/I9jqwIvJm1Do+KVlCywZ7gd?= =?us-ascii?Q?Vnginp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6DcmElawefzcgb2Y?= =?us-ascii?Q?4defduPap0HcaA95gjsQi6BYUYVA6FMNY6hFBkbokWgRM6y8VKyaU6TVOR3a?= =?us-ascii?Q?MWqEkQqG8giwgrIexJVPRVQhs74sNhcJouNyNdw/Fs0QW93IKV0TNgpXsMQH?= =?us-ascii?Q?VMGx09kx/A=3D=3D?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: dbd3cd8c-94b6-4267-ad0a-08df50c3f93b X-MS-Exchange-CrossTenant-AuthSource: SA3PR12MB598757.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 22:31:14.2694 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: n/JAkga4bxD9Ynyry9NRnSAIFYuUrPm2eR8yiwtMjKogjspO6IHT79D5vkF+9tmOhUbffTSPWPCXzTpQorzB5w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB7583 On 2026-12-03 at 02:34 +1100, "David Hildenbrand (Arm)" wrote... > On 12/2/26 05:15, Alistair Popple wrote: > > On 2026-11-29 at 21:06 +1100, "David Hildenbrand (Arm)" wrote... > >> Device-private page table entries are weird: they are non-present page > >> table entries, and the device can write to the memory without the CPU > >> noticing or the CPU page tables reflecting it. > > > > However the device itself could know. > > Right. > > > > >> So there is no dirty bit on the PTE we could sync to the folio. And > >> usually, nobody cares about the dirty bit for these folios, as these > >> folios are not on the LRU. Device-coherent memory has the same problem: > >> it is mapped through present PTEs, but the device writes through its own > >> page tables and does not set the PTE dirty bit. > >> > >> There is one problem, though: when we migrate such a clean folio back > >> to system RAM, the new folio will be clean, and will be mapped through > >> clean PTEs. > > > > Unless the driver marks it dirty before finalizing migration. So this could > > be part of the driver contract - it has to copy a dirty flag into the folio if > > the page might be dirty. Of course no driver I looked at actually does that, so > > until such a driver comes along I think this fix is fine. > > Yeah. But the question is also what it buys us. ZONE_DEVICE doesn't really need > the dirty flag. It's only relevant once we move back to anon memory ... so any > such change would need a proper motivation in why we should care. Agreed. The only case I can think of is if the anon memory still existed in swap and subsequently needed to be reclaimed. With this everything ever migrated to ZONE_DEVICE would need to get written back. I doubt that's a common or important use case though. If it was presumably someone would have noticed this bug sooner :-) If we ever support migrating non-anon pages it could become more of an issue, but that doesn't seem like something anyone wants either so I don't think we should care. - Alistair > Thanks a lot for the review! > > -- > Cheers, > > David