From patchwork Fri Jan 10 06:00:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13933801 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 AB64EE7719C for ; Fri, 10 Jan 2025 06:05:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-Type: Content-Transfer-Encoding:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LbBcp8B+/Sn0jziT5hc2amOpZmSK5V3jlPqrQF2ZsC4=; b=SH9r79ny8+tv0c3nR2MqfxyZlg 0IrDltwAOwxcsV04lZ6DlhIk/bEV0+2T8mMVXekmmT7flnJnQlcZ6kC8GqLYSCFbv557Fa5PtgeHO tfjg0uPFUVMMa8Ue1m9J7aoV7fib6h2vfLcvkFwMjqj5onwd5kBuYaAkF7VQTK4nY6UukVi5Oi6Nh BdS3ovP4zcqyjeu/ZJrq8i6wG0wOSXE2a3GGOuRWdBuLk4JthS6ITNsWEu3pd5AzxjpWCY6H16Hl8 Td3bf7ngaklnNi4djPUky200xdgI0cBCoEJA+32rVusMGlsyvD7p4gVHNJufZIknDPFrEhZtBTth2 J/7Ji1mw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tW88Z-0000000EAJi-23sR; Fri, 10 Jan 2025 06:04:51 +0000 Received: from mail-bn8nam11on2062f.outbound.protection.outlook.com ([2a01:111:f403:2414::62f] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tW85G-0000000E8Mj-2xwM for linux-arm-kernel@lists.infradead.org; Fri, 10 Jan 2025 06:01:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=U5GZBIzNet1G4cQFRU+Q54xBT5t5qrRgDTv5jA5pTLG3nya+VeqCpzi32GtMqwHaqzMjNu/y0QWwSvcJtcKgwmyj3a4fnUbijiANwCqqhWzGUHzvC8BpNpiKKysUC0hZo0ZT4Ym9P1hRuH3twz/WYnUbg+XBXOzBJ6JYJoVQJxKo3ODpwHlUxqVZE9vGdwMNJB2BdoOxsV50TC6wrdixQ269yH4IYSbpkzTm/tjvCsxiFRVt8+klO/J1aQvGo6OUkNyjqYkp1jtJlTURkBAXy9k2orscRnCGAsyKTT/IL6mFkO1/gXOKxNERvphpQNi163/BVmStsl6ICgNDvLHJjw== 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=LbBcp8B+/Sn0jziT5hc2amOpZmSK5V3jlPqrQF2ZsC4=; b=Ix+ieebpZGBChCvt0i49n+lUM4YRIcOZJCF5TSNbeYyEt0/7B0Oq+EPr4tdFbpjkTgaXxuA+7J+8jgsffcHIv19SC0xiBRDfdAd9olJGxBQDn4Av2dNZh+IBNcaIQVTuNkvHQWkkPEONsHdOJEttj5T7kmZ5lbEeH3mRJkM/TfVFdVflFwt0XIj9OjGEeQ6lkDdW7g3QLYrGMfdmVbgla9o/eFPCHzuMgJQbOujyxPmDwycJUYezZiIoFPbTPRqiYWiv0A+6A/P2Wqv5JAdA/JYq6k83UReoWCNTowAQ1VijtGwcgIgYsscv8ngNn2ZWbFKXfTrl+he8pRXPD9DXrw== 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=LbBcp8B+/Sn0jziT5hc2amOpZmSK5V3jlPqrQF2ZsC4=; b=mf3LZHqKIAUnFplAYMAuYYYfszMf2Uc3vP0gadUYGUhugrNWO4u0844JDCgyvNdu3x8pgkgO7K4PogfXqOYOk15R5ljKoVW0oaSitmgLdtS/MHkxVHMMsG/oGr5FeZ+eOWVyLh84N5b8N+cI9gR4K2gEnDRy1H2yimYTr7h22HVMTSplgCnh5gtcJda7HmAMW0dm/t0Uy4hPhQrbU0Jg4RXpBKiEo5WG054ryCQ8RMY8Yb1xHqwnXHlOTC7/hK5dp4Z6sFU6zRptkfyDTcutG2XnmPFrHHe7yjByiWDxBcQTmry6FFmhgcuGDvknp6HA4XRgmMDpOMpBZZw1OPzxUw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by BY5PR12MB4132.namprd12.prod.outlook.com (2603:10b6:a03:209::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8335.10; Fri, 10 Jan 2025 06:01:23 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%7]) with mapi id 15.20.8335.011; Fri, 10 Jan 2025 06:01:23 +0000 From: Alistair Popple To: akpm@linux-foundation.org, dan.j.williams@intel.com, linux-mm@kvack.org Cc: alison.schofield@intel.com, 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, chenhuacai@kernel.org, kernel@xen0n.name, loongarch@lists.linux.dev, Vivek Goyal Subject: [PATCH v6 01/26] fuse: Fix dax truncate/punch_hole fault path Date: Fri, 10 Jan 2025 17:00:29 +1100 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY6PR01CA0102.ausprd01.prod.outlook.com (2603:10c6:10:111::17) To DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS0PR12MB7726:EE_|BY5PR12MB4132:EE_ X-MS-Office365-Filtering-Correlation-Id: 7415fded-2293-4465-edb8-08dd313c35ab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|7416014|366016; X-Microsoft-Antispam-Message-Info: iUiea6TcIoFaGltYHqp4MCOBxiDcafpaNHe3Va/E4WoJj2inejH6vz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w95WF8xLLxfBFSrdLIN+al2IGgPDR0A9GRSe/5IBZibfKpNYO8skpvVdlsP6+eMLBKwBeV0EO1l55GwX8iXBbOHUiataVQ094e5JWhIi9t07Ni9figZ+FsWipZ8uaZaCLLvWziuQEL8/aeLB5b1Tu59nk3JZ2Jdu6nTwcUX+qoO6hnxIAJYk5aceJ7ILZ97cw6fZ/1N2NyX+MW+CngLIDoLF7R3+u0k0uZ0a+B1+IzYahQg9altLFJrAWBQEqc3QITago+C4aGBZG/RZgqh7M 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)(1800799024)(376014)(7416014)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: q3WholDKedmVRDQSIdDEqbsTSX+QtxlNOzU8klTKMUAoO8pcfltOLqWeBycuK86n69nSLq0Y+oaIy4tSYoO4opXy0nNhtwpycVXqJCzHL1XO6WuYfp9ODXmeoVuurBlx2A90d98TxlGWCkRNWTnW+ycSr0UYBdhRwnl7g1XQdQB2CQL3bvwvly4HNzRCSFasFMaWMMBPilYPTJFqNcyhum/MAvkehnhAAftxTk6QJCuE7CG3BRqc6/vsaVGeZtIZ/nyhdm4UOC61xjbkP52/XOopAsBfQSPI1WPXmWaDNSRB51jWrHzS6wljLHGtLGUgxgT6Gqm0c7SHG5YdCorgWdxcz6o4cND9X1clAIeYlAeXYWrgxBDITrWKvv/eLlwuaVSDfFLTum4j5pXJJnYrr1w2hPKvPiI76XAoCy7JjCbIqYAhNsp3y8Ov8rcpNDx0QnffAlI6jkii04PcJblgmDO/hyEZnf8X9fURHtsYR3XexbCynYVGfcYYA/jBw6IxvO+lNaMzwmkcPlPL//nTBMnDM8fjvDJOQUPhBScVurKsa0xZmXjOueeiaxWPVnBbb4UII6H161mhX5zXPz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MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jan 2025 06:01:22.7610 (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: htroSdF/dxS3nzKIpqIjntV3q4KRTiTTAbDZsGM2Eik3FUjh4pHnShiH+zMQv3HN3QbULE+UgyXuEwMBIg5CQw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4132 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250109_220126_740892_F5DBC1F8 X-CRM114-Status: GOOD ( 16.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org FS DAX requires file systems to call into the DAX layout prior to unlinking inodes to ensure there is no ongoing DMA or other remote access to the direct mapped page. The fuse file system implements fuse_dax_break_layouts() to do this which includes a comment indicating that passing dmap_end == 0 leads to unmapping of the whole file. However this is not true - passing dmap_end == 0 will not unmap anything before dmap_start, and further more dax_layout_busy_page_range() will not scan any of the range to see if there maybe ongoing DMA access to the range. Fix this by passing -1 for dmap_end to fuse_dax_break_layouts() which will invalidate the entire file range to dax_layout_busy_page_range(). Signed-off-by: Alistair Popple Co-developed-by: Dan Williams Signed-off-by: Dan Williams Fixes: 6ae330cad6ef ("virtiofs: serialize truncate/punch_hole and dax fault path") Cc: Vivek Goyal --- Changes for v6: - Original patch had a misplaced hunk due to a bad rebase. - Reworked fix based on Dan's comments. --- fs/fuse/dax.c | 1 - fs/fuse/dir.c | 2 +- fs/fuse/file.c | 4 ++-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/fs/fuse/dax.c b/fs/fuse/dax.c index 9abbc2f..455c4a1 100644 --- a/fs/fuse/dax.c +++ b/fs/fuse/dax.c @@ -681,7 +681,6 @@ static int __fuse_dax_break_layouts(struct inode *inode, bool *retry, 0, 0, fuse_wait_dax_page(inode)); } -/* dmap_end == 0 leads to unmapping of whole file */ int fuse_dax_break_layouts(struct inode *inode, u64 dmap_start, u64 dmap_end) { diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 0b2f856..bc6c893 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c @@ -1936,7 +1936,7 @@ int fuse_do_setattr(struct mnt_idmap *idmap, struct dentry *dentry, if (FUSE_IS_DAX(inode) && is_truncate) { filemap_invalidate_lock(mapping); fault_blocked = true; - err = fuse_dax_break_layouts(inode, 0, 0); + err = fuse_dax_break_layouts(inode, 0, -1); if (err) { filemap_invalidate_unlock(mapping); return err; diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 082ee37..cef7a8f 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -253,7 +253,7 @@ static int fuse_open(struct inode *inode, struct file *file) if (dax_truncate) { filemap_invalidate_lock(inode->i_mapping); - err = fuse_dax_break_layouts(inode, 0, 0); + err = fuse_dax_break_layouts(inode, 0, -1); if (err) goto out_inode_unlock; } @@ -2890,7 +2890,7 @@ static long fuse_file_fallocate(struct file *file, int mode, loff_t offset, inode_lock(inode); if (block_faults) { filemap_invalidate_lock(inode->i_mapping); - err = fuse_dax_break_layouts(inode, 0, 0); + err = fuse_dax_break_layouts(inode, 0, -1); if (err) goto out; }