From patchwork Tue Dec 17 05:12:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13911023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DCD0E7716A for ; Tue, 17 Dec 2024 05:15:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90A586B0092; Tue, 17 Dec 2024 00:15:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8B7EE6B0093; Tue, 17 Dec 2024 00:15:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70A5F6B0095; Tue, 17 Dec 2024 00:15:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 510616B0092 for ; Tue, 17 Dec 2024 00:15:10 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id D6E86160478 for ; Tue, 17 Dec 2024 05:15:09 +0000 (UTC) X-FDA: 82903286592.04.FA68C73 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2045.outbound.protection.outlook.com [40.107.220.45]) by imf30.hostedemail.com (Postfix) with ESMTP id 731BB80008 for ; Tue, 17 Dec 2024 05:14:09 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=MoEJwevM; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf30.hostedemail.com: domain of apopple@nvidia.com designates 40.107.220.45 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734412493; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Dt16aTHQWa/9x7dM8NaNzVhZVxyBkJOcFpMjfFKYq5Q=; b=e4a6Vsbe/3y7OeXZeowEKeR9c7udm1hpOBjB2Y2Aa8DW5OvhnCrc0JxkfrDxrgrKYIGlD5 j+5PJd/Cv/EhxZlP1/0n7tlAXylzAKycdh59i7silWkwsAv9eVEu+5aFrsh6T7y6Xm8Rcx e6jLxcXHiE19Ne8qvFXFcF/f3PlADLE= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1734412493; a=rsa-sha256; cv=pass; b=ydiJftGUsex00R8XOMp5C/3IV9L+CLDkREgwyZzn9qgfWzIlj20o/zcuYSzQYqQ2HJhpOW JWrxutyY/ti0yjzsdiPyHHtDXJtqvVOKS6LZsAlbX1jtdXJaYECnwk7l6MzyVfgwriLs/3 4Kg1DZl//O7thohJIfT+tiNl8/9Ew3A= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=MoEJwevM; dmarc=pass (policy=reject) header.from=nvidia.com; spf=pass (imf30.hostedemail.com: domain of apopple@nvidia.com designates 40.107.220.45 as permitted sender) smtp.mailfrom=apopple@nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=r7UbssMyxrkp6dlor1G9yJWYPlfVNGnEfPHuv9cbhuJGpITF19pRBMu42wgabztFIJYsbu2XwhlU5u635L4t5mm6pdkZW9ubSRQI/L0p0dN25nvUuiqVUh8phcoEzJSUoF7/9jDfpELaWouAf4ZyoaxkJxZw4WOh5F5taqy1rORjNkLioTsgubpooNHvvgm5g2yjdUEwrrxh01qfI1HxTH9jCURbZziWSZCf86EXDlO4BHFgzVvNnWrBt2s/txsGKQXYGzKlnKp+XRsACc+jLuceNJOpu1POOvHPjEzj51R9bHoZbxuh2EGqRA+QOT94BC2iBHXzpfz3sPucu4WT5g== 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=Dt16aTHQWa/9x7dM8NaNzVhZVxyBkJOcFpMjfFKYq5Q=; b=i1+KdwK+geXm14vWQfURYu2oM+Mix51funTBDLeOmFua2+qpNC/DPOyLjY72EPWILMWGylQHWsI0Vv82hX3L4Nv22hdMWMW531kFbhsO2KpYi5hwKJmk4veBpOBMdX8L8Qh2WREzondG65pDZfuXyGfPVtDGdqmdItqDoElPvwhHfcuikccwhH0kHtsNeQvNG0CMDZ1X8NOoe9CyiaZPeLijGBCXhCB6T5JAnzL0H1EQDWno0lclTZUC5JBcDiE4kLJKcGC/MaCB8b6jMC0V+XxtYNLH8zECYO9tOHzZdbmhVlMvrCESBl47ei202CVEHMOfi8Yv3WQ3gkieC0k1bw== 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=Dt16aTHQWa/9x7dM8NaNzVhZVxyBkJOcFpMjfFKYq5Q=; b=MoEJwevMEMZLA4cUJ6B5q4gOtWRs7dveFE3lRGXDbvb1pPu6//+0lOAXbl6VZzlNSrDdpQBMRWXlJO33RpXm8floW4plRUVa1Xeu8+QuCA82bmv+Heaa3WC1FQsa3OFAUUpOUrQk6lCysGvrgQFdIjYjWz4KzBo53lUx6PXYhd8MnOlf4UVyOa9gPTxUgOKPF+XmMH+H+qAsNC8YZSsKkAAPLZX4irhtIYEK59nYeZtHBMX6LmRjk6zMcFlMMhsw0wTrBMJ0b/vCnv3VAP6MnHVVhlpqrRREEJR2I9iOSjwO7hXf0zPCsI5SEM8bA3Lzxsvt2pb/f3RAw5GG7GUUuw== Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by CH3PR12MB8936.namprd12.prod.outlook.com (2603:10b6:610:179::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8251.22; Tue, 17 Dec 2024 05:13:59 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%4]) with mapi id 15.20.8251.015; Tue, 17 Dec 2024 05:13:59 +0000 From: Alistair Popple To: akpm@linux-foundation.org, dan.j.williams@intel.com, linux-mm@kvack.org Cc: Alistair Popple , lina@asahilina.net, zhang.lyra@gmail.com, gerald.schaefer@linux.ibm.com, vishal.l.verma@intel.com, dave.jiang@intel.com, logang@deltatee.com, bhelgaas@google.com, jack@suse.cz, jgg@ziepe.ca, catalin.marinas@arm.com, will@kernel.org, mpe@ellerman.id.au, npiggin@gmail.com, dave.hansen@linux.intel.com, ira.weiny@intel.com, willy@infradead.org, djwong@kernel.org, tytso@mit.edu, linmiaohe@huawei.com, david@redhat.com, peterx@redhat.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, jhubbard@nvidia.com, hch@lst.de, david@fromorbit.com Subject: [PATCH v4 06/25] fs/dax: Always remove DAX page-cache entries when breaking layouts Date: Tue, 17 Dec 2024 16:12:49 +1100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY6PR01CA0056.ausprd01.prod.outlook.com (2603:10c6:10:ea::7) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|CH3PR12MB8936:EE_ X-MS-Office365-Filtering-Correlation-Id: 8c042e64-ca26-4b0c-ba6b-08dd1e599cc8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|7416014|366016; X-Microsoft-Antispam-Message-Info: vOezp3DYsZnu8ke8eB03nSukQUlqBelVOOOUBC6egyP6zgbMomeZ0QSS3VNCpfIWSTDfQoSkXhNu3g+PimbNYPBdT9QgOC6CWTVGw/97l+Y5MsDlQVBHtvleTO3WVHA9fdBFRuiROm0mVuFoRkakK/Dbj0ahnXDWyP7zl1a2uLd6tJu0c114RGTghmJcV9EeWZDgBNZJGYw6rPLPyR9wShvlCeScblQ5647HxzWE9dgo0/bkhF0c6BtuEqn0qD2qcl8DQx1l0S5bBawPd6pJ7rstybfQo1eyn3RMKw6t8X6lkOw3FY5qcavLiAR6sQb/ypLzEa0bWkXg9i/juyIRmvhXHiHwl9gU/Ww0sdH9adNssuTjD1huatM3Q0bhtrGMt7clRDqP92uiDOqPYR8j1dA+V3gWA2s6X4PzuccSY2n6Clu7FWDqb3Ez7NZe8/BM7mUG48IaiDre3zMoAoGA8qvS4pwwWCuYruuW79AYqP4Nlx9hRA2VStZVTP5VKXV+I456fK/5ap9qOuYmJAVgGlBzsyD28HOjZzc8trHhte4LogK6cG/wCtkfRO9yTOlV6JMTElXGNFZoGW80TYC0aRG2KP3pHH1j2L3MtwanU9apEhN3/uYd3GiuVMPZe8GKqMub+Fse+diia/ez/9xWcahEl2+nT5CdcHgpaD5T9kIcZ90sEEF35aWqsjfehQoi7ihcvup10McfIDKaVL//5J/oRjN+qm8CgNaJgBoydUzH7a8C8MhFU9ETF9BXa+GufaNk3zLjHD3d2XR/NebvEgB+JLkCNKACIcfUsa5MiawuAE4OzY77hEULO3WtnxDj3dQH3Gp2+CMAD+hdBB5GjeDA8Is7spqRKSxBVj5y1aCrW+Xwp+4iQ4VHkm6m+203Z2ZIfIY/kJ12RDyQ7sITLAcqwlS9SFlH1PAfoX59/zpy0fFjwaCAgbCf5xhkqXD6huGnz1MQeLlOIp9dGO00HxSzM7BHENM8aqrmjxTYM5zPrjL6OPRCJJS4C0U5SRNBpcy0w3udXLg2+nCixqEAuJ2zHr2lxMHUR8ZudMd3VqUG9jFDeg0bUfiy6TeYlhamPk6BDEZWbIrJmSJzw39fYXaJ9JXD0t7Z/fAwwG8LJ6Ozy8kAeqGsF15u2Ev7ZqWJRwVRrdFwy6z2/JA5kVBEVDXUl7yjDF61uN7azeNHt+CvjYamNnlwvXc73taaStuznq8kq7x8wZnZMYqq99CRIBE9kvELgT8c0GYd3SQX9XSSMTk2vPZsdVZKbpoxjBrOAFJYLFOkdKWYeq2IbVZZV8OJq1Z2yN2L61WvmNChtKXhC8n/dQz1ZgMFqCDjrU+3oGsjLRvEb5aeV9mVPNC/H0f0LHsdl4Vm7AYEkUFcfzjfTr9aRzCjj3UsMd+43957 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DS0PR12MB7726.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8gVl47iUmFUPwo0eqPLmxy28OhBtI2zEwTG+riiycA9fcyENWelBdSCtcdekcspcgFrPNWSG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CFZWhRj+duvGi8VSNGrMqRLCZPcBocuwF5bA3Q/O90CEAq2OeVMuYAGgppcAY/ZGKzABKBKd+8b+UUn3ptqzGBpcbQ517jlfSeyu8aiSUSCp6Slqenrbm/b9B+LMEtCSg/V+PYYVEEfFlbrU20n/1n+pcZA54Eqe7a+sd/papF1kOCH//QC9ZNrRmn3FcsihMNWSSnxM1ImqeHfA+1I9GGDwbyka8qB0clEnpFG2LLNeljFs+byascYGN3T9zJ3Gqtcv0CPO58RKZT8KxktZQ5tbTUIjHqWXh00LfxeDmj9fT+4JEl7UykzlL9pPsNxToFdoC4cVyNnmwTPSwk1VhH29+XuC+MjjJj4MzPSWGr8bI/K9tzaIzLvtmnz0krdNRcEHFh+5eREM2pOlQ4bRAzwk5RFG0Q3aox/iBMO+90q17N9rU7Rho4ricRbduNFv X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8c042e64-ca26-4b0c-ba6b-08dd1e599cc8 X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2024 05:13:58.9699 (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: UhftufAN+wx2FiE+2lnoGrR1ceyzuPxl4QBEQjMt+WzXfdhrVAPJhwCUGWpLrsJNYOBdrdiupC81SxlPikQvDQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB8936 X-Stat-Signature: hwz8pgahgwtj7wd4mfanu9e3oayun8en X-Rspamd-Queue-Id: 731BB80008 X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1734412449-814397 X-HE-Meta: U2FsdGVkX18mgomoMM9adaBU4k1htGdxcI5RQWgbl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O21t/8QPUtFM7veNE6RfDL2vz2Z3f8aiTtzkjf7IqdHgVWFH+FFMQ9QrkfEh//SvZDfU3iUgJi5Yl0VazxsUpDe//lXIlnVFGKXJk/1zbSy5KnqQnBwWMEh8ATdZx3SCeXzdE5ynhGVI7e1+0TKU3I/ViE40i2kmQ1ZZZAIgW1gyeN/ThLuVGcV+gTDmYe7FAKphj3ws5hLXAqC33b0lM4sZph0aOPAZpb2/z8tDcLaHuuFZzyEaA0fht76KJ9/X06od+E7pNlK61Vp2UcLgTtoCMet X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Prior to any truncation operations file systems call dax_break_mapping() to ensure pages in the range are not under going DMA. Later DAX page-cache entries will be removed by truncate_folio_batch_exceptionals() in the generic page-cache code. However this makes it possible for folios to be removed from the page-cache even though they are still DMA busy if the file-system hasn't called dax_break_mapping(). It also means they can never be waited on in future because FS DAX will lose track of them once the page-cache entry has been deleted. Instead it is better to delete the FS DAX entry when the file-system calls dax_break_mapping() as part of it's truncate operation. This ensures only idle pages can be removed from the FS DAX page-cache and makes it easy to detect if a file-system hasn't called dax_break_mapping() prior to a truncate operation. Signed-off-by: Alistair Popple --- Ideally I think we would move the whole wait-for-idle logic directly into the truncate paths. However this is difficult for a few reasons. Each filesystem needs it's own wait callback, although a new address space operation could address that. More problematic is that the wait-for-idle can fail as the wait is TASK_INTERRUPTIBLE, but none of the generic truncate paths allow for failure. So it ends up being easier to continue to let file systems call this and check that they behave as expected. --- fs/dax.c | 33 +++++++++++++++++++++++++++++++++ fs/xfs/xfs_inode.c | 6 ++++++ include/linux/dax.h | 2 ++ mm/truncate.c | 16 +++++++++++++++- 4 files changed, 56 insertions(+), 1 deletion(-) diff --git a/fs/dax.c b/fs/dax.c index 5462d9d..cd6cca8 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -845,6 +845,36 @@ int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index) return ret; } +void dax_delete_mapping_range(struct address_space *mapping, + loff_t start, loff_t end) +{ + void *entry; + pgoff_t start_idx = start >> PAGE_SHIFT; + pgoff_t end_idx; + XA_STATE(xas, &mapping->i_pages, start_idx); + + /* If end == LLONG_MAX, all pages from start to till end of file */ + if (end == LLONG_MAX) + end_idx = ULONG_MAX; + else + end_idx = end >> PAGE_SHIFT; + + xas_lock_irq(&xas); + xas_for_each(&xas, entry, end_idx) { + if (!xa_is_value(entry)) + continue; + entry = wait_entry_unlocked_exclusive(&xas, entry); + if (!entry) + continue; + dax_disassociate_entry(entry, mapping, true); + xas_store(&xas, NULL); + mapping->nrpages -= 1UL << dax_entry_order(entry); + put_unlocked_entry(&xas, entry, WAKE_ALL); + } + xas_unlock_irq(&xas); +} +EXPORT_SYMBOL_GPL(dax_delete_mapping_range); + static int wait_page_idle(struct page *page, void (cb)(struct inode *), struct inode *inode) @@ -871,6 +901,9 @@ int dax_break_mapping(struct inode *inode, loff_t start, loff_t end, error = wait_page_idle(page, cb, inode); } while (error == 0); + if (!page) + dax_delete_mapping_range(inode->i_mapping, start, end); + return error; } EXPORT_SYMBOL_GPL(dax_break_mapping); diff --git a/fs/xfs/xfs_inode.c b/fs/xfs/xfs_inode.c index 295730a..4410b42 100644 --- a/fs/xfs/xfs_inode.c +++ b/fs/xfs/xfs_inode.c @@ -2746,6 +2746,12 @@ xfs_mmaplock_two_inodes_and_break_dax_layout( goto again; } + /* + * Normally xfs_break_dax_layouts() would delete the mapping entries as well so + * do that here. + */ + dax_delete_mapping_range(VFS_I(ip2)->i_mapping, 0, LLONG_MAX); + return 0; } diff --git a/include/linux/dax.h b/include/linux/dax.h index f6583d3..ef9e02c 100644 --- a/include/linux/dax.h +++ b/include/linux/dax.h @@ -263,6 +263,8 @@ vm_fault_t dax_iomap_fault(struct vm_fault *vmf, unsigned int order, vm_fault_t dax_finish_sync_fault(struct vm_fault *vmf, unsigned int order, pfn_t pfn); int dax_delete_mapping_entry(struct address_space *mapping, pgoff_t index); +void dax_delete_mapping_range(struct address_space *mapping, + loff_t start, loff_t end); int dax_invalidate_mapping_entry_sync(struct address_space *mapping, pgoff_t index); int __must_check dax_break_mapping(struct inode *inode, loff_t start, diff --git a/mm/truncate.c b/mm/truncate.c index 7c304d2..b7f51a6 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -78,8 +78,22 @@ static void truncate_folio_batch_exceptionals(struct address_space *mapping, if (dax_mapping(mapping)) { for (i = j; i < nr; i++) { - if (xa_is_value(fbatch->folios[i])) + if (xa_is_value(fbatch->folios[i])) { + /* + * File systems should already have called + * dax_break_mapping_entry() to remove all DAX + * entries while holding a lock to prevent + * establishing new entries. Therefore we + * shouldn't find any here. + */ + WARN_ON_ONCE(1); + + /* + * Delete the mapping so truncate_pagecache() + * doesn't loop forever. + */ dax_delete_mapping_entry(mapping, indices[i]); + } } goto out; }