From patchwork Fri Jan 10 06:00:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13933691 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 A5EEFE7719C for ; Fri, 10 Jan 2025 06:01:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32E6B6B0099; Fri, 10 Jan 2025 01:01:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 305A56B009A; Fri, 10 Jan 2025 01:01:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BBBD6B009B; Fri, 10 Jan 2025 01:01:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id D5BFA6B0099 for ; Fri, 10 Jan 2025 01:01:58 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 8A0D0A0865 for ; Fri, 10 Jan 2025 06:01:58 +0000 (UTC) X-FDA: 82990496316.30.CCE480D Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2062.outbound.protection.outlook.com [40.107.236.62]) by imf06.hostedemail.com (Postfix) with ESMTP id BE56A18000E for ; Fri, 10 Jan 2025 06:01:55 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Ki2exUkX; spf=pass (imf06.hostedemail.com: domain of apopple@nvidia.com designates 40.107.236.62 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=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=1736488915; 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=v+5E4H/DuQ0pAoXXKbxaYAoc2WqaY+EzxUHO8qCAqb8=; b=xFx1HzoXFlmdkmKxK9mgh7AVDUqNhkmIqqBRKEb6X0ZjTKw7OpLensJGGIq6xMf3avu/oP kWOXrmnP32lnHioMm5aIYgLS91catrxcoN+zg/YC7puK3NoqE6aYZ9OHS4ieGcRwYdLX4V QwGv2+VyW6wJUr31mv2zOcbn7pvKaac= ARC-Authentication-Results: i=2; imf06.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=Ki2exUkX; spf=pass (imf06.hostedemail.com: domain of apopple@nvidia.com designates 40.107.236.62 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736488915; a=rsa-sha256; cv=pass; b=M82P2SaFCPsDGGYDRUrqgk/b81T+7f7zzfb0S9KGQD5JfE7OoZEtFCmhtT3gN5DXHW7Glg jmyKUvsvuLhH2AKzigX8Y006etP3G67O+FVyudLccBbMSsPnS5H0zAy2N6pdDQBUMx5rEF CkM6dS1fnf4P1qQCKpXmtCcom4UUPh4= ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=i61thtl+sa3BxgzzLz937/Nxu0bfaKEwi5T2sXoCHJg0lHYnINtSl0gIc5gV8FsCC7rQ5MZBf9WjpDC1+aHP1QJR+PCEf1nvmMK6mA40wzHkfrt/7C9WHjMytSsf57keL7dg9BUiDOjmfCHOFHbL40KYsDc382B0wps9siLLwR5C9ilJu9WrsGW8ohxXHDu6/OtPNk//pK1ISuJtCwZ4D87vMS/Xo2LPlQGkHXeVRUB3c9t/QCS162e295onQ7hOXAmheR84/2FhhMzkp90Xzj2lQ+OTK4j9cmdTrdqTOfqL2YgDAybdM9GwEVy7Xo6V0JTN94+K/uu2OUBRFwhAKA== 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=v+5E4H/DuQ0pAoXXKbxaYAoc2WqaY+EzxUHO8qCAqb8=; b=UxvF7QSspfZcjWcJQb3us4Pvrc/0dThIPo5LNr24XoUW9PNBMvC6brqssudi0BbhNyeCIVmkulQf6IYt4GDEWW/u1qpXZXGdZU8e5coKYrkwCk61KavbvOukpvjJUUuRYCMEeQv+GeVrE3EdezfzmzKdt0sVlsH+J99N1jhVSN1+jpA3t5fF5bgJWxp7ENwLPbYPaJMKsp/vdYnAe+F6UmmiEtXu5Vfpfb/j/pZzdD5eKPhBHh4RsyXQWcyGyW53tUMbf6iEeuGlsY5oKjEcUR59dNCoPpyEhypog7fPUkNIwnP8h1s8EN+qJeraQHv4HsiMluzXgBgP3vQ8BjIZzA== 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=v+5E4H/DuQ0pAoXXKbxaYAoc2WqaY+EzxUHO8qCAqb8=; b=Ki2exUkXCnQcWQYv/ijoWWndA44Shn2xqspHqYTqKR2jwPUsjqQYjPuLff4dnmOjb9amKUWmLSBTpo+CQQbZTDGwzd3FPl8TU3ZS62/SIq5b9zfA30XUIyjsQv0A43/g0lgc3TK3N5mgSiCKAFInpARWx6JJ2E18ZWD17NO43mNpASvhDpM6TSG6TghK9UF7Xq46UG6SBotAlHUoc+kk5MwAsSIfxPSHfJufGS1sqfCAzen4bnJwmDF00kf5b3TwENRmrPo9D6XIKll5+dvCH7rnF4uimm3BUM8qxi/O2YgHgq8LJ2Fp+3HHz4NL2xpDrFK1P9BtxinJHcMdsPApyg== 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:53 +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:53 +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 Subject: [PATCH v6 06/26] fs/dax: Always remove DAX page-cache entries when breaking layouts Date: Fri, 10 Jan 2025 17:00:34 +1100 Message-ID: <47bef43b54474a8ba7f266b9b5fc68ed91b1d7b8.1736488799.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY5P300CA0021.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:1ff::9) 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: 67ac2924-3e27-432c-c614-08dd313c47cb 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: Sh2VSoZUpO6jStPWLaekWTDgE/jLZBXVBpJeckqen9QoTvRdTaHthUDjt/w95jgakRHaMxvUs5T68+Y0oTjXs4vLswl7RaigPdLPxMxSxQeFUVVBGmj7SLVV1nv25OhOJUGhSfMW5EjTogKrsJzz24RZ55t041VT17UGunw6Gsg71HAuBCPZN8S+tthP6M6JWwKG1hUAFJ2LkfAthd9hxYKGAmgparUaXoZi0vODf49sWsCXkItiQgfDjvFlC0ELd+dGFSWHwJ5LfNDPaqaeGDqdQSvwykS7AnP9185Qg08yQbDI1A0UShApVuBTg6Q9QgzfRwlzQeWecjsiNn3ovKE6M9oP0ukD2TucoJFLlkfItFIuiZlJ/Y2qp8dTwqKASGOe2oVAhviL/IefeIPce0znJ6BjGBXgP/ddq168wfZxo1Meqh2xZ7i6FMXnoPfJQrFOWr7S4UttJfUt6XbWJmIoznhZ1H98xPdq2KRBtKortvcGGjuroo4s9ZQgO1+PQaNyF5AVp4zMQahnU0/A1Ol3hHuuQDT8mz8wYltEJd7HW+un479mPYhjHJmqGCkoltf8s5tm+OmmnVP3zrUiaHK03ydOvbXUZRI5pVGIgGxa2N/kfVKgjXwPMZjTo/VuWbG/o9IALKAgNwbENKISuhSzSw8d5YKcCzyIVihB7ysFDzEXnaU1o6OY8N548nrzuOx89PfC8DrGsqCgLxPP/wBMlVo+JK/SlZCYyAw2Un2vICud1YcGd4QMrTOhPTNBbAqSlaF/SxsUtnbeYpNhWdHOfpwiFEOOF054P/XCbag+CuGQqI3Eg1oKh5AyGV5t2605M7bIcXKQ1Ufz7LH3eoap5fQ0ATZoWJugLNE6xqaQIfzgulrEmpjVdPFnalgv82oIGWVPc750bLZarzTg9ic924Mb6cXrW9U7oddB7npUofdy/vDPipKW/BmsPADh9iT+AxUSdKUOheCkHNFF/ifWIgpGA0Mq3EAKPxUgFereSR1lhcGdY/6TLDzW0mfIlMYwIVilUv7Uk81ucemwsD1E9jHHxnxVK2srsEAOjOwYST5bFSXtqPXnsAAM2HJUPtcNc4FaXnHPhKMVqjBGdS+E58bgCxZ2rh0ARcd0fS5b9UCt9TuNZRkGEPKl2vuKkYZOwmG2RaIqevNRG6Z9MQY4fzL4usVMm/4jy9A0+AbQ6YFsrgiLXHKTpDEGKJiGtD3vlfOfUGWFvaJDMfkJqQ1KR9Rm4VjJ5XELPVC8IIWlI1+cESHBDAQPHAO+vB9DT2Ya+j1K6hs40WERCcZzY8sT1VIzm6tjSYpoKVqq96DRUMbevLIZWlAOtRHLX19+7XCg1zV41hMRruY+nV4OKyI/Apu21JUEQuPJdsmjZ4yiVXjLo5UorcXRHKBqbfdh 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-Ch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M+UvBV9ml36NWiTrhqBOEixjINWHSxx1g0gAbp19D6rwRAI8y4q2x/j2BdVtY7k1WYfwXdr+GZq6anpJ3IEsnNPZjatzV9Q/o4AIyELfUwpNCrJuWvnAZIxNPQB1rXIofHnQGEQZnG6OzRn1eXPXo0bB9QH9Ge/38mMF3U4YIxbo8UjCLx5YkbJSKJZMSbWFVfu2FFjKT+vWgQkF+ll3uNPVFEMzfoXd2o+dc+g6KSmSDtEieLYViTirl1kQSnBFoj1sdE9Pk1vFIfZ6IFnNqDyEntGlhc/cyLtl84lF1ERgLfIHDmvizHi3KWgtAbRTlzef7tVEGGXVrMeyTbjU6Xc2AnbgHs6fQ0incR9FgqJVaqtZYJK/C6fgef6g+md4Yr3sCs+hyNUbyevvwOXDD5vdxSNQt96/O1GTFrDiXXlBfj77Ep2aHwpYZTuh/NUHEC0+bm78gnGrpBfjtPi5kxAq/riSkuToBCL2uHxYplbLtOJUZfgVPq3izJm9xqt3HkVBbMRRgn6T30JUoipXs6B5P3H1A1cdXzCB2OadhFgxRDL X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 67ac2924-3e27-432c-c614-08dd313c47cb X-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:53.1849 (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: 28x45XP53E/wqjGddiWRG8HHGf8+mfhFHUe4dhTmreN+VhavB+ZRxlMSeflyyonmYAVx3amfX0w9w3DhV3phBQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4132 X-Rspamd-Server: rspam05 X-Stat-Signature: rctmy9x5g7t6g7bai3hm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hOkW24eaNp24whqJOCRMoqRpW1VSeivE1M7uKSUHF2aj7Stg6tbwSxVV5TbU2MBvt1FafUjF4W5XOSkwlp6XXXsDcG89+aouvgF4A4beQBHYlHQgbyf5Gp6uMlv8/tsy2R9/C9p6+7nQBS0ECRwqe8ds9LlGx4r4bqsgDkBH1CkE81Z3ohds0FYQNTLEVNcnKk9Jsru7QrDPE0UtgMy5GTMZkr8asQaH7AHc2tkvNXllcLkYjco/SaWWPcpjTN2uOo2iS7nhoM6VBfLU20Mno8DTyedlDOABp0BR82YAu1M1KAtaEFGvOIshtFZjQ6io58rWyWpmVFj9G2nzzB2vE3Adf9T0YG8y7UoigiUvMZmrrqNrxI3Tx4141AdGw8VTWZZnHLg/oCHXsAyxHrde8elyKf2vL8gLZZG7UZXx+G2Lk2qLipKHJzHYpeBLftfCkutEvbbGIE6RGTZSU= 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 9c3bd07..7008a73 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) @@ -874,6 +904,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; }