From patchwork Tue Jan 7 03:42:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Popple X-Patchwork-Id: 13928051 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 53606E77197 for ; Tue, 7 Jan 2025 03:43:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E113C6B0096; Mon, 6 Jan 2025 22:43:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DC15A6B0098; Mon, 6 Jan 2025 22:43:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC4AC6B0099; Mon, 6 Jan 2025 22:43:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9B9146B0096 for ; Mon, 6 Jan 2025 22:43:22 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 5A2AE140668 for ; Tue, 7 Jan 2025 03:43:22 +0000 (UTC) X-FDA: 82979260644.03.F500673 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2068.outbound.protection.outlook.com [40.107.236.68]) by imf09.hostedemail.com (Postfix) with ESMTP id A1B54140008 for ; Tue, 7 Jan 2025 03:43:19 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=GynSl6C3; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.236.68 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736221399; 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=bE5P8XNU3ah4J/7ozO76nVLgHi9O2KTRIMaPoDiVlsY=; b=qUugeqYS1tjT6u7mF4T3EY0QmOfSHFE+hv66210YfZ/SZ+xhwCkEnZNDYW1n0LwYaRlUOJ XE4HAjpupmRyFdx0vV1s/VpPUfbTTKuMwetGR/tYg7gSrgxd+GkOabau7NZL4MJvVLjG5v JjlOxEH7gtB5LbC1KohQAUYaZpRGw6c= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736221399; a=rsa-sha256; cv=pass; b=0d10cdMKUb3NUg31fLVELm+qMhOg+G0EAVGcx57qqTKWJmAlYSYwROnNiWKDrW0JzfgIJq RfBKBQ/9M8DgRWGreCEu1Fy0RmQYPmi0waOucGtqOWaX/iKdZnbVFlJ6z0n0Y58PTCk+fZ mQqle+TDSBPNufvy54/kr+0XCwYfeEA= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=Nvidia.com header.s=selector2 header.b=GynSl6C3; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of apopple@nvidia.com designates 40.107.236.68 as permitted sender) smtp.mailfrom=apopple@nvidia.com; dmarc=pass (policy=reject) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ln4sNNUTGCA9J2EOtq4mcutSy/Ay7L5dj66cP+a7OvVi00pw5sVWlLJ66fGQkyS6HD1iK7513JZrOnqACXTaASnSOQLmgjqOZPGS8JKdcH9CJgYufmgJqm1ngdSYMhATANid8iYmOBn3epZHMF33t8J9XqhcL/MWBhfB5s7NSnCiuXbyshkNC2DDKFVPH9oL8a5f0Ry+ASM4VZ8xmf57iE3jae9++/Cxqnhvl6X6GtoooaEmFI6EX2Lm6FmRC9zOIMexYctMyuJ9Emnc7WGGewMxKq2nMO1cafQlt+WpxVDh27cNpmvYIcCxozgpDldIuSNnoSvJjMCypHKA0NzvNA== 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=bE5P8XNU3ah4J/7ozO76nVLgHi9O2KTRIMaPoDiVlsY=; b=j2iH164Nz/wkKe30QWQeWznQpJFpR/TMl2ap9bE8K4sqoUTmaDwHARk938W1NCNGP/Gp5gHjEbfS/64IGJA15c/+cbhx12Ge8sfWHVm/uzFfrrOeq+S3jWDYyedAJ9w8cpgzIySUri6LGqAi3IGW9hWStJFnJpTE+t3T+dtiMB54R0IS8ANhHirWj7oqxxUIcX0IQoVkIUxl26x7yEaCLy3LyN3wr4J7m1ogn0DUyh8PmrtrCG3kwfV+hLLzywvWXkAdtiFUmVS4v4ykRxNF5EVjoSR3fjv36TL1doRRJ6B34pDDh7g4jdaLqt+WSj3yYPfwIRMC/6Li686BajxEiA== 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=bE5P8XNU3ah4J/7ozO76nVLgHi9O2KTRIMaPoDiVlsY=; b=GynSl6C3Pfk/xtOKFZbGFv7F/92kO3YghALqGRuFuii8TMQ99ALVQystKcbSEzH7pdcf/ZGEtxiCIAmU9pet/1i7+V0P9IOQT7nP4hDTvjBEIKFPuY+eufgYNSGNPhTEd8SvwXl+TtW5BY+93SN8VqtEKLHbd8UgksR/AZV9+SD7Lb+8IarX3e5WHJ/eBGf+qOkRKNVnY/qtrM4sEuArTBsQ1X3FmN4+uoyibgbBMctJZzuMfGJAutZ1NivQCzgnQuVZ23cbFegEFpk4uG2cG5uzU2m3oAxe/gNqprHVrxgnAx+tPbpQasv1o5qwsUxBY6ZHJeNtGs0CUJEbdAWWJQ== Received: from DS0PR12MB7726.namprd12.prod.outlook.com (2603:10b6:8:130::6) by CY5PR12MB6129.namprd12.prod.outlook.com (2603:10b6:930:27::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8314.15; Tue, 7 Jan 2025 03:43:12 +0000 Received: from DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe]) by DS0PR12MB7726.namprd12.prod.outlook.com ([fe80::953f:2f80:90c5:67fe%6]) with mapi id 15.20.8314.015; Tue, 7 Jan 2025 03:43:12 +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 v5 03/25] fs/dax: Don't skip locked entries when scanning entries Date: Tue, 7 Jan 2025 14:42:19 +1100 Message-ID: <6d25aaaadc853ffb759d538392ff48ed108e3d50.1736221254.git-series.apopple@nvidia.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: References: X-ClientProxiedBy: SY5P282CA0041.AUSP282.PROD.OUTLOOK.COM (2603:10c6:10:206::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_|CY5PR12MB6129:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d4f795f-6edb-4ed8-e0b3-08dd2ecd68cf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: euVjFz4+bXH+q9euWir23blYX7UZfry1zSRyUGfKlmrZslWVKDBLhoubf5HgpWCrax6BjbqyZr5VJXKj0GvLrP/CCzIchGKuhW1MjKMva7nBCPMjrzrc2lSZdQc25ktuQ9tziyXz1/4gHjji+jFPqvZF135I6HSC5F5HLI8xts64mzPX0v4o9ICsVMZzPXW5Zh6rMegxIA/p2Nj1l0I6AVRvljnLjLTy6vArNI5NhlH9KnuvsozgprDaIbm1Hdw5V7Mx7fc4uGleglxeP0tpZiWjc/sbK5KP8nuVDDdz6MDSyFdLJHrxLCVCz+OB3BR7mct2Erl9pG2vVo6I+00wFNUnF7/fpU4yhXRq4dsb/KEKrpCbjVfOVqALQ3UCjUs2lIC7OKEnampfBkERYRi55lSUOIUEchYmA9tHkm0e+gYpqH0DFEBZDet1mfBrOsm/zbw3rYxscTlGN1Mw/f++wIStmlRencYNfA2RCNI8s3ncdlthyXuLBNC5xjzPNroh51XCeM7slQmJNab19NTDxZx994l8+/chLXzIgR5fmtU7OgHWPg+oSoVRYzkEgszXZ0n/8D2NMQV8ZCUDBXuL8MMkU/ikfuiITWUlGs5BakFplWJXHE3EV3sYiQbV7S/lwEkDQ2oaxiVRhMbnIi1rDRIrI38QQmw+0uVOFp187llOg/Z9ouNMIcgOCQFIMd7ciPXWTBRr6AWhTJ9+AmO6cNBp5YwYjfQ9xVD98ta3hhc3KG/UWZ7KyskrDfrp/p9Kdb1KFl7q4DheusE/O7LqXy2ccHYP9Qa1hYGJXUuVmQM52ve+zkCA8IVk0vJXf8YoQcJgkMyK+a6JgDtGCp10KtulIh7ha+Be+Az2CXoXHfDnfXKGqLzr0YDRTzuZ5zV50sVJsj/Iy2y4hpGhhJVHydQK5VqsL7j07tNKDXKEnsETI7bheUt/pTEhrS1EFsPsv8Ff7tDwIOAizfixuX/q2tBhzH8U46N8/VxZBOoLbtZdz1QY1AMLL0lS1LAYX6bgbG/gNNveWI7ZV2WGVLvzXtIS0D6a6tL22SGBqO47YM2q12p6AcUKbEc2JrnJYqy80AHmlhXsAfSDcJ1Omv8B8yvxI+gRTZbLob2TK5HbVyu0DdnCLqsk1vTY84MFxpX5U6ui4eejUuWPEulSuR9qq0oGU7/cXyl7bIO9RSXKKSROoZ+qV5yVrE4o47NGgu103ICebvC7/Dq2mi5jo6NE96DgoWyQN+ad05h9aIWE6M/K7FRLmwzcBtJDdzoxyMtJbdOH1Lp8rbSECkjVvkZkoC6VIneTFsMd25gFL442kLOfK7j+Wm4wVf+WkyIBLZo+KpWXs3R2I6GVpf8W4RmRyCEOQ7qCeR1EflRz6amtn/5kaFFkykopAQGuD+3/RUZv 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)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vj5t65XOdK8u4JFMkhrpJ/R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UG7jvkyKr6Qo0QA04m/jx1aeJUobe5vEP7rGSCl0PSFc1VuqvUUOXoNyn4r/isDVqYe8nKp2WJb2B7S0v3+18GcJv0dPC/BOBoam/L+J9/+uotiS+lAWvD7xaVh5sgnRmBB4g3+Mv9nM0X2C5qjip1xBmxnqbqiXZ3qHBDnA/E9I8x+8JqswK1/SXvf2A4XNr0mlLAzlOwJvvrNIsMebIpgZjf4Efzn60ltmIu83xY6v8VfuQonC3h6vM2S7pYTFeMfW4otdO0iOuvxz1fnAMGDg8Ldes8HYaYVdtsZrMOTbzUq3BrSNIdWsBfsLl89Zcl4y0SpYRKqhpk0yPsUIjnLRo3kaa/CaIzp4q15AJOptY90GypnlTsSOZu6g6pDaMGp+cXvWi0IMYB9lyz/rU30nxHcuccfiO4UKfPoeeqaZ4GAuToG+IAw1QaElDJWZC4IVXen34iM/84OTcblZWUiGyqRi73ejKxIwcWWtNM9InUaz4vu X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d4f795f-6edb-4ed8-e0b3-08dd2ecd68cf X-MS-Exchange-CrossTenant-AuthSource: DS0PR12MB7726.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Jan 2025 03:43:12.0055 (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: 3FweUgPhNCalKMpRdpLYKr1g5oXzGjHp3pRCY0489Hn5N7EOVpZ90jWueP8F+eDaIWvOU9oyngKKB1utDrqf0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY5PR12MB6129 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: A1B54140008 X-Stat-Signature: xhhjkygqe7j31pq19547ocdw1eh73h86 X-Rspam-User: X-HE-Tag: 1736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LCVeLlcvz1Dw2XY0ii5QfYEJKcsR4FDr/FjVEsvsZ/phc3RsLxONNPuakVmx3+r06Fl5HzY9CVA70xH2ZrzrxNjba6rZLnLrS5kA487N0RJ5Hqx1kmi2VR6C1WHLf3aGxrddhre+FPEestwYnuHGUk+X6yw/xW0yrkr9A5BLUKvHZpEQKAS8JmxWwfjzPGpYh65PiAxVQUShgKYtTOf535G9DC5DK3jIl3cOQsXLYa+wUvmn4xRILb5E+bZnqYb3G1OhSroRdCv2aenQ5E9fRlKkT49SGhHtCB4jJm0uijoo5+LXjd8lpKrXRWW/IfJK 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: Several functions internal to FS DAX use the following pattern when trying to obtain an unlocked entry: xas_for_each(&xas, entry, end_idx) { if (dax_is_locked(entry)) entry = get_unlocked_entry(&xas, 0); This is problematic because get_unlocked_entry() will get the next present entry in the range, and the next entry may not be locked. Therefore any processing of the original locked entry will be skipped. This can cause dax_layout_busy_page_range() to miss DMA-busy pages in the range, leading file systems to free blocks whilst DMA operations are ongoing which can lead to file system corruption. Instead callers from within a xas_for_each() loop should be waiting for the current entry to be unlocked without advancing the XArray state so a new function is introduced to wait. Also while we are here rename get_unlocked_entry() to get_next_unlocked_entry() to make it clear that it may advance the iterator state. Signed-off-by: Alistair Popple Reviewed-by: Dan Williams --- fs/dax.c | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) diff --git a/fs/dax.c b/fs/dax.c index 5133568..d010c10 100644 --- a/fs/dax.c +++ b/fs/dax.c @@ -206,7 +206,7 @@ static void dax_wake_entry(struct xa_state *xas, void *entry, * * Must be called with the i_pages lock held. */ -static void *get_unlocked_entry(struct xa_state *xas, unsigned int order) +static void *get_next_unlocked_entry(struct xa_state *xas, unsigned int order) { void *entry; struct wait_exceptional_entry_queue ewait; @@ -236,6 +236,37 @@ static void *get_unlocked_entry(struct xa_state *xas, unsigned int order) } /* + * Wait for the given entry to become unlocked. Caller must hold the i_pages + * lock and call either put_unlocked_entry() if it did not lock the entry or + * dax_unlock_entry() if it did. Returns an unlocked entry if still present. + */ +static void *wait_entry_unlocked_exclusive(struct xa_state *xas, void *entry) +{ + struct wait_exceptional_entry_queue ewait; + wait_queue_head_t *wq; + + init_wait(&ewait.wait); + ewait.wait.func = wake_exceptional_entry_func; + + while (unlikely(dax_is_locked(entry))) { + wq = dax_entry_waitqueue(xas, entry, &ewait.key); + prepare_to_wait_exclusive(wq, &ewait.wait, + TASK_UNINTERRUPTIBLE); + xas_pause(xas); + xas_unlock_irq(xas); + schedule(); + finish_wait(wq, &ewait.wait); + xas_lock_irq(xas); + entry = xas_load(xas); + } + + if (xa_is_internal(entry)) + return NULL; + + return entry; +} + +/* * The only thing keeping the address space around is the i_pages lock * (it's cycled in clear_inode() after removing the entries from i_pages) * After we call xas_unlock_irq(), we cannot touch xas->xa. @@ -250,7 +281,7 @@ static void wait_entry_unlocked(struct xa_state *xas, void *entry) wq = dax_entry_waitqueue(xas, entry, &ewait.key); /* - * Unlike get_unlocked_entry() there is no guarantee that this + * Unlike get_next_unlocked_entry() there is no guarantee that this * path ever successfully retrieves an unlocked entry before an * inode dies. Perform a non-exclusive wait in case this path * never successfully performs its own wake up. @@ -580,7 +611,7 @@ static void *grab_mapping_entry(struct xa_state *xas, retry: pmd_downgrade = false; xas_lock_irq(xas); - entry = get_unlocked_entry(xas, order); + entry = get_next_unlocked_entry(xas, order); if (entry) { if (dax_is_conflict(entry)) @@ -716,8 +747,7 @@ struct page *dax_layout_busy_page_range(struct address_space *mapping, xas_for_each(&xas, entry, end_idx) { if (WARN_ON_ONCE(!xa_is_value(entry))) continue; - if (unlikely(dax_is_locked(entry))) - entry = get_unlocked_entry(&xas, 0); + entry = wait_entry_unlocked_exclusive(&xas, entry); if (entry) page = dax_busy_page(entry); put_unlocked_entry(&xas, entry, WAKE_NEXT); @@ -750,7 +780,7 @@ static int __dax_invalidate_entry(struct address_space *mapping, void *entry; xas_lock_irq(&xas); - entry = get_unlocked_entry(&xas, 0); + entry = get_next_unlocked_entry(&xas, 0); if (!entry || WARN_ON_ONCE(!xa_is_value(entry))) goto out; if (!trunc && @@ -776,7 +806,9 @@ static int __dax_clear_dirty_range(struct address_space *mapping, xas_lock_irq(&xas); xas_for_each(&xas, entry, end) { - entry = get_unlocked_entry(&xas, 0); + entry = wait_entry_unlocked_exclusive(&xas, entry); + if (!entry) + continue; xas_clear_mark(&xas, PAGECACHE_TAG_DIRTY); xas_clear_mark(&xas, PAGECACHE_TAG_TOWRITE); put_unlocked_entry(&xas, entry, WAKE_NEXT); @@ -940,7 +972,7 @@ static int dax_writeback_one(struct xa_state *xas, struct dax_device *dax_dev, if (unlikely(dax_is_locked(entry))) { void *old_entry = entry; - entry = get_unlocked_entry(xas, 0); + entry = get_next_unlocked_entry(xas, 0); /* Entry got punched out / reallocated? */ if (!entry || WARN_ON_ONCE(!xa_is_value(entry))) @@ -1949,7 +1981,7 @@ dax_insert_pfn_mkwrite(struct vm_fault *vmf, pfn_t pfn, unsigned int order) vm_fault_t ret; xas_lock_irq(&xas); - entry = get_unlocked_entry(&xas, order); + entry = get_next_unlocked_entry(&xas, order); /* Did we race with someone splitting entry or so? */ if (!entry || dax_is_conflict(entry) || (order == 0 && !dax_is_pte_entry(entry))) {