From patchwork Sun Sep 25 13:33:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang Ruan X-Patchwork-Id: 12987987 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 21000C6FA82 for ; Sun, 25 Sep 2022 13:33:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7A118D0006; Sun, 25 Sep 2022 09:33:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2ADE8D0001; Sun, 25 Sep 2022 09:33:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 87CBD8D0006; Sun, 25 Sep 2022 09:33:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 79C978D0001 for ; Sun, 25 Sep 2022 09:33:46 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 575241A0A6F for ; Sun, 25 Sep 2022 13:33:46 +0000 (UTC) X-FDA: 79950700452.18.8A7A3FF Received: from mail1.bemta32.messagelabs.com (mail1.bemta32.messagelabs.com [195.245.230.2]) by imf02.hostedemail.com (Postfix) with ESMTP id CD50180002 for ; Sun, 25 Sep 2022 13:33:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1664112824; i=@fujitsu.com; bh=RdaWcPr3gci1Vc3szH+WaTgenDw7Cl3lU3kCYuJ1P+s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=j8263QtK0f5wm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ZeSVw+14BncIEdIodnz7IKSWJCCmpBiaOA/pZz7f/D Iv6Fr7g8HIBh6TXK6faKgkdniolFCUtvOmRWtjb3pj0aoH7alKzGO6oCXgd3NfZKmDgfrPn8K WM9R9r06p5bVf9821weHDNyuGkVpl4y4U/R7V+T1zQvMkl0+9X1/a+gMff95mEPmueYLFJzsF gxQ/bna8XrLtUNvlTjzrfUsFZUjXbZ1b82vaDJVZ7ilOY6s/T28rCn7XX26+PyQ3O2vx9e27x v7bVHG8stXc/83mjbr8jxsa5oZnZr3Pj6QXnO5oC7vZMfvvH1mZe1pGSSA5m84laCnc4V5+7P Vt4/t//lkschA7O/pG8+VtxMMedVI6EiBulAgV9ty0W3nx0ZsrqeftLpASUWIozEg21mIuKEw E7hM7ssgMAAA== X-Env-Sender: ruansy.fnst@fujitsu.com X-Msg-Ref: server-21.tower-591.messagelabs.com!1664112822!124698!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 24092 invoked from network); 25 Sep 2022 13:33:42 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-21.tower-591.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 25 Sep 2022 13:33:42 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id 470F5100194; Sun, 25 Sep 2022 14:33:42 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTPS id 3A53610018D; Sun, 25 Sep 2022 14:33:42 +0100 (BST) Received: from localhost.localdomain (10.167.225.141) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sun, 25 Sep 2022 14:33:38 +0100 From: Shiyang Ruan To: , , , , CC: , , , Subject: [PATCH 1/3] xfs: fix the calculation of length and end Date: Sun, 25 Sep 2022 13:33:21 +0000 Message-ID: <1664112803-57-2-git-send-email-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1664112803-57-1-git-send-email-ruansy.fnst@fujitsu.com> References: <1664112803-57-1-git-send-email-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.141] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: ClamAV using ClamSMTP ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664112826; a=rsa-sha256; cv=none; b=FKn9vf5icdexAPYDxXIalg9zxNMm1KF5P9KRtZ1hodP7fVqZIpzq+3k33IKZmbmLOMN6wb Xpz5pRa8ZGwTOo4Tgzt62eFP95PA3xw++Aw4w48bH2v5txFVm4V0csakt1a/mXapyZ5Ll5 y3WhbnEzOsVDGDuaagcIw+QqZp8hpRg= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=170520fj header.b=j8263QtK; spf=pass (imf02.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 195.245.230.2 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com; dmarc=pass (policy=none) header.from=fujitsu.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664112826; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=RdaWcPr3gci1Vc3szH+WaTgenDw7Cl3lU3kCYuJ1P+s=; b=8ntC6wUKIHrXyIcPboWBXXin0bmOg76eseCVQ1nJktuvzQRry1GcOcqsc7EqX2JvQ7Jb3C OJ87JG2r6grRpUv+V3a0G30bNTTrzKotVIwUfw+rYj/Alrw62SnOs2S03uI2VpLatfA04Y tuoWWQixtnDa44mIpxkEo0tALNTOFlo= X-Stat-Signature: kzbhxh7rwmyrqsd6zjjt9wqj3durfdda X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=170520fj header.b=j8263QtK; spf=pass (imf02.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 195.245.230.2 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com; dmarc=pass (policy=none) header.from=fujitsu.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: CD50180002 X-HE-Tag: 1664112825-521762 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: The end should be start + length - 1. Also fix the calculation of the length when seeking for intersection of notify range and device. Signed-off-by: Shiyang Ruan Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_notify_failure.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_notify_failure.c b/fs/xfs/xfs_notify_failure.c index c4078d0ec108..3830f908e215 100644 --- a/fs/xfs/xfs_notify_failure.c +++ b/fs/xfs/xfs_notify_failure.c @@ -114,7 +114,7 @@ xfs_dax_notify_ddev_failure( int error = 0; xfs_fsblock_t fsbno = XFS_DADDR_TO_FSB(mp, daddr); xfs_agnumber_t agno = XFS_FSB_TO_AGNO(mp, fsbno); - xfs_fsblock_t end_fsbno = XFS_DADDR_TO_FSB(mp, daddr + bblen); + xfs_fsblock_t end_fsbno = XFS_DADDR_TO_FSB(mp, daddr + bblen - 1); xfs_agnumber_t end_agno = XFS_FSB_TO_AGNO(mp, end_fsbno); error = xfs_trans_alloc_empty(mp, &tp); @@ -210,7 +210,7 @@ xfs_dax_notify_failure( ddev_end = ddev_start + bdev_nr_bytes(mp->m_ddev_targp->bt_bdev) - 1; /* Ignore the range out of filesystem area */ - if (offset + len < ddev_start) + if (offset + len - 1 < ddev_start) return -ENXIO; if (offset > ddev_end) return -ENXIO; @@ -222,8 +222,8 @@ xfs_dax_notify_failure( len -= ddev_start - offset; offset = 0; } - if (offset + len > ddev_end) - len -= ddev_end - offset; + if (offset + len - 1 > ddev_end) + len -= offset + len - 1 - ddev_end; return xfs_dax_notify_ddev_failure(mp, BTOBB(offset), BTOBB(len), mf_flags); From patchwork Sun Sep 25 13:33:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang Ruan X-Patchwork-Id: 12987988 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 5993FC6FA82 for ; Sun, 25 Sep 2022 13:33:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AC8158D0007; Sun, 25 Sep 2022 09:33:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A77A08D0001; Sun, 25 Sep 2022 09:33:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F1338D0007; Sun, 25 Sep 2022 09:33:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 807848D0001 for ; Sun, 25 Sep 2022 09:33:50 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 58A711A053B for ; Sun, 25 Sep 2022 13:33:50 +0000 (UTC) X-FDA: 79950700620.13.4CD3405 Received: from mail1.bemta34.messagelabs.com (mail1.bemta34.messagelabs.com [195.245.231.4]) by imf11.hostedemail.com (Postfix) with ESMTP id E356740006 for ; Sun, 25 Sep 2022 13:33:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1664112828; i=@fujitsu.com; bh=SZUJGTcMKpqGq9npE5T8kI7qy3nqdqQWNC5ACNp0d8I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=xOqdKexDDYdt+OsxJXVNnXnmbEowAzlmUEQpayA/fr5pvMMsqnP3W8yI7JyrvS8IL ma616tT4/ggyw7jjcDn9O24XXc71uWFrWgy7dgdoFbBqHeZ7kkQUE61faaCgzTejRC ijt8c4pTVMGliK6jYi7wkFaGPAp4d4+qt4J6IWii6C4QKfxZqqxIt2zt4zlq2ngcD6 6RxG+rpZl04Axcuw43fLngtc+uPQ4PXIM/AljXljZQmnfNpHOjSQvEw4VWk5KXlKtr dxdP0bsb5IwYag2MYxphFi2dafsK/4AUhiausemXjiEluXmysM6ZqCCQaKM4uRLo8O B1AqDppntcb2w== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprFKsWRWlGSWpSXmKPExsViZ8OxWXdXhEG ywdEvUhbTp15gtNhy7B6jxeUnfBanJyxistiz9ySLxeVdc9gs7q35z2qx688OdouVP/6wOnB6 nFok4bF5hZbH4j0vmTw2repk89j0aRK7x4vNMxk9Pm+SC2CPYs3MS8qvSGDN2LrhP1tBn1nFl mV3GRsY3+l2MXJxCAlsZJTofLeCBcJZzCSx9O4UdghnL6NEQ/9R1i5GTg42AR2JCwv+soIkRA QmMUocu3GTGSTBLJAg0f7lGhOILSzgLHFzWyM7iM0ioCpx//wTFhCbV8BFYtXPHrB6CQEFiSk P34PZnAKuEkunrALrFQKq6dl7lgmiXlDi5EyIXmYBCYmDL14A1XMA9SpJzOyOhxhTIdE4/RAT hK0mcfXcJuYJjIKzkHTPQtK9gJFpFaN1UlFmekZJbmJmjq6hgYGuoaGprrEFkDLUS6zSTdRLL dUtTy0u0TXSSywv1kstLtYrrsxNzknRy0st2cQIjKaUYrX8HYx/V/7UO8QoycGkJMp71M8gWY gvKT+lMiOxOCO+qDQntfgQowwHh5IE7wE3oJxgUWp6akVaZg4wsmHSEhw8SiK8hSCtvMUFibn FmekQqVOMuhxTZ//bzyzEkpeflyolzrsyHKhIAKQoozQPbgQsyVxilJUS5mVkYGAQ4ilILcrN LEGVf8UozsGoJMzrFgw0hSczrwRu0yugI5iAjrDj0wc5oiQRISXVwMQZpPrfif9d2q6ry6dVB XLslgvPnn75a+OvzNzaG0cCj7//Vs2h/9f52OV7LHFdu5/FHa49OEUi1zr2Ue0/H5kjjf+U6v 9NlVpyZKn0T7YdNnV5q+e+uhOWsnj2rVuxC3y/XI77fiFcxlSiJeCctfAq7X8dbKpcuirdm15 /ZC8TMp3/Ny5qdeqK6nqNO4EdK1fsrji7bGOu00xh95nbLT5/KV/SyXLo8kO1lvqwKi2td/cL V8lbLHioF6qRf6TK9P7sMO8jqxrWKM95y/bzn+r8h7oBh1duXVUn5xt4pU+Zj638Q1Zhn8ND2 /vdjUvKr9xc9UambLa6wU2TD6KnGtLFd1hYbc7xWO0ff/PQewUlluKMREMt5qLiRAAZS3vxrQ MAAA== X-Env-Sender: ruansy.fnst@fujitsu.com X-Msg-Ref: server-4.tower-548.messagelabs.com!1664112826!147209!1 X-Originating-IP: [62.60.8.179] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 26248 invoked from network); 25 Sep 2022 13:33:46 -0000 Received: from unknown (HELO n03ukasimr04.n03.fujitsu.local) (62.60.8.179) by server-4.tower-548.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 25 Sep 2022 13:33:46 -0000 Received: from n03ukasimr04.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTP id 1C837157; Sun, 25 Sep 2022 14:33:46 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTPS id 0CEE873; Sun, 25 Sep 2022 14:33:46 +0100 (BST) Received: from localhost.localdomain (10.167.225.141) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sun, 25 Sep 2022 14:33:42 +0100 From: Shiyang Ruan To: , , , , CC: , , , Subject: [PATCH 2/3] fs: move drop_pagecache_sb() for others to use Date: Sun, 25 Sep 2022 13:33:22 +0000 Message-ID: <1664112803-57-3-git-send-email-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1664112803-57-1-git-send-email-ruansy.fnst@fujitsu.com> References: <1664112803-57-1-git-send-email-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.141] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: ClamAV using ClamSMTP ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664112830; a=rsa-sha256; cv=none; b=Q5wDG4EIIpgXAiPCajNVRhqW7ZrJuBIgQ27FEeW0qMritLrnDp4PlhHDp9QnELdMN9EvuN 2Vrm10afQANTQK3cmnqs+InXXAzxh3vD/JjJr0esMtsEG2A4bA/5A8Mi7R50W6hC5WBdru S4k5KQSA3s+Qosgf8QeDuDIi3EsVoAk= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=170520fj header.b=xOqdKexD; spf=pass (imf11.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 195.245.231.4 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com; dmarc=pass (policy=none) header.from=fujitsu.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664112830; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=SZUJGTcMKpqGq9npE5T8kI7qy3nqdqQWNC5ACNp0d8I=; b=dAHZRoGMr2RKHmGQQnbptTkX0ipWxyHlOySRV2qzJoH5WQQXnK1A4bBq6BhBTq9HwarMQ/ Sq5MzgWHJr4Pc3lo5m1b0beePhfc7JBUR4ZSLN5KQw/bV40kuo5B2ugGX1L0YJNYobSPYl IjESUdWL/rn90vHxruILpubZqa3GMyo= X-Stat-Signature: 7nxhmwhtmxor3zb6qh4ww9kp1jsiogd4 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=170520fj header.b=xOqdKexD; spf=pass (imf11.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 195.245.231.4 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com; dmarc=pass (policy=none) header.from=fujitsu.com X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E356740006 X-HE-Tag: 1664112829-203178 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: xfs_notify_failure.c requires a method to invalidate all dax mappings. drop_pagecache_sb() can do this but it is a static function and only build with CONFIG_SYSCTL. Now, move it to super.c and make it available for others. And use its second argument to choose which invalidate method to use. Signed-off-by: Shiyang Ruan --- fs/drop_caches.c | 35 ++------------------------------- fs/super.c | 43 +++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 1 + include/linux/pagemap.h | 1 + mm/truncate.c | 20 +++++++++++++++++-- 5 files changed, 65 insertions(+), 35 deletions(-) diff --git a/fs/drop_caches.c b/fs/drop_caches.c index e619c31b6bd9..4c9281885077 100644 --- a/fs/drop_caches.c +++ b/fs/drop_caches.c @@ -15,38 +15,6 @@ /* A global variable is a bit ugly, but it keeps the code simple */ int sysctl_drop_caches; -static void drop_pagecache_sb(struct super_block *sb, void *unused) -{ - struct inode *inode, *toput_inode = NULL; - - spin_lock(&sb->s_inode_list_lock); - list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { - spin_lock(&inode->i_lock); - /* - * We must skip inodes in unusual state. We may also skip - * inodes without pages but we deliberately won't in case - * we need to reschedule to avoid softlockups. - */ - if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) || - (mapping_empty(inode->i_mapping) && !need_resched())) { - spin_unlock(&inode->i_lock); - continue; - } - __iget(inode); - spin_unlock(&inode->i_lock); - spin_unlock(&sb->s_inode_list_lock); - - invalidate_mapping_pages(inode->i_mapping, 0, -1); - iput(toput_inode); - toput_inode = inode; - - cond_resched(); - spin_lock(&sb->s_inode_list_lock); - } - spin_unlock(&sb->s_inode_list_lock); - iput(toput_inode); -} - int drop_caches_sysctl_handler(struct ctl_table *table, int write, void *buffer, size_t *length, loff_t *ppos) { @@ -59,7 +27,8 @@ int drop_caches_sysctl_handler(struct ctl_table *table, int write, static int stfu; if (sysctl_drop_caches & 1) { - iterate_supers(drop_pagecache_sb, NULL); + iterate_supers(super_drop_pagecache, + invalidate_inode_pages); count_vm_event(DROP_PAGECACHE); } if (sysctl_drop_caches & 2) { diff --git a/fs/super.c b/fs/super.c index 734ed584a946..7cdbf146bc31 100644 --- a/fs/super.c +++ b/fs/super.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include "internal.h" @@ -677,6 +678,48 @@ void drop_super_exclusive(struct super_block *sb) } EXPORT_SYMBOL(drop_super_exclusive); +/* + * super_drop_pagecache - drop all page caches of a filesystem + * @sb: superblock to invalidate + * @arg: invalidate method, such as invalidate_inode_pages(), + * invalidate_inode_pages2() + * + * Scans the inodes of a filesystem, drop all page caches. + */ +void super_drop_pagecache(struct super_block *sb, void *arg) +{ + struct inode *inode, *toput_inode = NULL; + int (*invalidator)(struct address_space *) = arg; + + spin_lock(&sb->s_inode_list_lock); + list_for_each_entry(inode, &sb->s_inodes, i_sb_list) { + spin_lock(&inode->i_lock); + /* + * We must skip inodes in unusual state. We may also skip + * inodes without pages but we deliberately won't in case + * we need to reschedule to avoid softlockups. + */ + if ((inode->i_state & (I_FREEING|I_WILL_FREE|I_NEW)) || + (mapping_empty(inode->i_mapping) && !need_resched())) { + spin_unlock(&inode->i_lock); + continue; + } + __iget(inode); + spin_unlock(&inode->i_lock); + spin_unlock(&sb->s_inode_list_lock); + + invalidator(inode->i_mapping); + iput(toput_inode); + toput_inode = inode; + + cond_resched(); + spin_lock(&sb->s_inode_list_lock); + } + spin_unlock(&sb->s_inode_list_lock); + iput(toput_inode); +} +EXPORT_SYMBOL(super_drop_pagecache); + static void __iterate_supers(void (*f)(struct super_block *)) { struct super_block *sb, *p = NULL; diff --git a/include/linux/fs.h b/include/linux/fs.h index 9eced4cc286e..0e60c494688e 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3292,6 +3292,7 @@ extern struct super_block *get_super(struct block_device *); extern struct super_block *get_active_super(struct block_device *bdev); extern void drop_super(struct super_block *sb); extern void drop_super_exclusive(struct super_block *sb); +void super_drop_pagecache(struct super_block *sb, void *unused); extern void iterate_supers(void (*)(struct super_block *, void *), void *); extern void iterate_supers_type(struct file_system_type *, void (*)(struct super_block *, void *), void *); diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 0178b2040ea3..8879c141b117 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -27,6 +27,7 @@ static inline void invalidate_remote_inode(struct inode *inode) S_ISLNK(inode->i_mode)) invalidate_mapping_pages(inode->i_mapping, 0, -1); } +int invalidate_inode_pages(struct address_space *mapping); int invalidate_inode_pages2(struct address_space *mapping); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); diff --git a/mm/truncate.c b/mm/truncate.c index 0b0708bf935f..3016258d41e7 100644 --- a/mm/truncate.c +++ b/mm/truncate.c @@ -548,12 +548,13 @@ unsigned long invalidate_mapping_pagevec(struct address_space *mapping, } /** - * invalidate_mapping_pages - Invalidate all clean, unlocked cache of one inode + * invalidate_mapping_pages - Invalidate range of clean, unlocked cache of one + * inode * @mapping: the address_space which holds the cache to invalidate * @start: the offset 'from' which to invalidate * @end: the offset 'to' which to invalidate (inclusive) * - * This function removes pages that are clean, unmapped and unlocked, + * This function removes range of pages that are clean, unmapped and unlocked, * as well as shadow entries. It will not block on IO activity. * * If you want to remove all the pages of one inode, regardless of @@ -568,6 +569,21 @@ unsigned long invalidate_mapping_pages(struct address_space *mapping, } EXPORT_SYMBOL(invalidate_mapping_pages); +/** + * invalidate_inode_pages - Invalidate all clean, unlocked cache of one inode + * @mapping: the address_space which holds the cache to invalidate + * + * This function removes all pages that are clean, unmapped and unlocked, + * as well as shadow entries. It will not block on IO activity. + */ +int invalidate_inode_pages(struct address_space *mapping) +{ + invalidate_mapping_pages(mapping, 0, -1); + + return 0; +} +EXPORT_SYMBOL(invalidate_inode_pages); + /* * This is like invalidate_inode_page(), except it ignores the page's * refcount. We do this because invalidate_inode_pages2() needs stronger From patchwork Sun Sep 25 13:33:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang Ruan X-Patchwork-Id: 12987989 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 4AC64C6FA82 for ; Sun, 25 Sep 2022 13:33:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7A858D0008; Sun, 25 Sep 2022 09:33:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A29A78D0001; Sun, 25 Sep 2022 09:33:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A4198D0008; Sun, 25 Sep 2022 09:33:53 -0400 (EDT) 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 795C88D0001 for ; Sun, 25 Sep 2022 09:33:53 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5C5EF4016B for ; Sun, 25 Sep 2022 13:33:53 +0000 (UTC) X-FDA: 79950700746.06.5AA3FD0 Received: from mail1.bemta32.messagelabs.com (mail1.bemta32.messagelabs.com [195.245.230.66]) by imf12.hostedemail.com (Postfix) with ESMTP id DBD7840002 for ; Sun, 25 Sep 2022 13:33:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1664112831; i=@fujitsu.com; bh=rWTztagXd3ebhKKtakvx6uZbv7eYUy2//ebuLJtL8JA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Lt7Piz77zrIHn3rVDAmF3B3G0FOeODoqbIlHD28UEvd+29YWSJqpUg+03a4asbXw+ /d7eA16vNiYO3mJTph8f7f8QIafRDPFFROTa4fI712OUb/fq2waP2JjdrhTumUZzlF 55sBCYZuizYesn7bCbXonmL8Got4dT8Gcsga2Cs3q0F2KzNgEB27A8OGwkORpzeSSy YRbKgRc8f9znc2KFmd88MS0xq96F5wxWU0foiNcxX0krTrwThqNJ7nOmEn8j04xcE8 2DX3R/gHfXTM3sXqPb4T03hsC4X5rnnO4s9mI/rCfQ1KjQe2vetPygaRY6nU0613tE s7s4o8UeuOllQ== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprPKsWRWlGSWpSXmKPExsViZ8ORpLsvwiD ZYNN8EYvpUy8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W T7+7IDAAA= X-Env-Sender: ruansy.fnst@fujitsu.com X-Msg-Ref: server-4.tower-591.messagelabs.com!1664112830!124372!1 X-Originating-IP: [62.60.8.98] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.87.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27799 invoked from network); 25 Sep 2022 13:33:50 -0000 Received: from unknown (HELO n03ukasimr03.n03.fujitsu.local) (62.60.8.98) by server-4.tower-591.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 25 Sep 2022 13:33:50 -0000 Received: from n03ukasimr03.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr03.n03.fujitsu.local (Postfix) with ESMTP id DAE041AD; Sun, 25 Sep 2022 14:33:49 +0100 (BST) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr03.n03.fujitsu.local (Postfix) with ESMTPS id CEF3D1AC; Sun, 25 Sep 2022 14:33:49 +0100 (BST) Received: from localhost.localdomain (10.167.225.141) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Sun, 25 Sep 2022 14:33:46 +0100 From: Shiyang Ruan To: , , , , CC: , , , Subject: [PATCH 3/3] mm, pmem, xfs: Introduce MF_MEM_REMOVE for unbind Date: Sun, 25 Sep 2022 13:33:23 +0000 Message-ID: <1664112803-57-4-git-send-email-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1664112803-57-1-git-send-email-ruansy.fnst@fujitsu.com> References: <1664112803-57-1-git-send-email-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.225.141] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: ClamAV using ClamSMTP ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664112833; a=rsa-sha256; cv=none; b=EFmu095lgu487RIk+07MoDHoiZcgqCgcSEkvUYiFXnsNAT6us3FFDAnLs0CuwVLedW4SsJ jR9HzIiTCEI7qhfXBRru2BDRvj0ZwLnVq799cGAvS/Uq8MaSzZ92v4WcSYAt+3bNwpFAYv DKInQ9iwifldizeFpcRdOukW84cyEfI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=170520fj header.b=Lt7Piz77; dmarc=pass (policy=none) header.from=fujitsu.com; spf=pass (imf12.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 195.245.230.66 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664112833; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=rWTztagXd3ebhKKtakvx6uZbv7eYUy2//ebuLJtL8JA=; b=tIUEE9HyqE4lZFYQi5puzZ+Vj3ibRVFLpnX9vyCizyFEzBGqzvKunlrCMAMQTcJDV3VWV0 yZ9zOgm8w2qnTCPgll2NW59ZGqEFeP8+87d8ZAE2bpn9kHd6WEes5eHTb5Qkoy6F5cnvhy WVGF6jV3JpP3NNDPISyz2NpQCTB+RDY= X-Rspam-User: X-Rspamd-Queue-Id: DBD7840002 X-Rspamd-Server: rspam08 X-Stat-Signature: chbriachm9hto5nypyyg45htfmwr6izx Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=fujitsu.com header.s=170520fj header.b=Lt7Piz77; dmarc=pass (policy=none) header.from=fujitsu.com; spf=pass (imf12.hostedemail.com: domain of ruansy.fnst@fujitsu.com designates 195.245.230.66 as permitted sender) smtp.mailfrom=ruansy.fnst@fujitsu.com X-HE-Tag: 1664112832-806028 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: This patch is inspired by Dan's "mm, dax, pmem: Introduce dev_pagemap_failure()"[1]. With the help of dax_holder and ->notify_failure() mechanism, the pmem driver is able to ask filesystem (or mapped device) on it to unmap all files in use and notify processes who are using those files. Call trace: trigger unbind -> unbind_store() -> ... (skip) -> devres_release_all() # was pmem driver ->remove() in v1 -> kill_dax() -> dax_holder_notify_failure(dax_dev, 0, U64_MAX, MF_MEM_PRE_REMOVE) -> xfs_dax_notify_failure() Introduce MF_MEM_PRE_REMOVE to let filesystem know this is a remove event. So do not shutdown filesystem directly if something not supported, or if failure range includes metadata area. Make sure all files and processes are handled correctly. [1]: https://lore.kernel.org/linux-mm/161604050314.1463742.14151665140035795571.stgit@dwillia2-desk3.amr.corp.intel.com/ Signed-off-by: Shiyang Ruan --- drivers/dax/super.c | 3 ++- fs/xfs/xfs_notify_failure.c | 28 +++++++++++++++++++++++++++- include/linux/mm.h | 1 + 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/dax/super.c b/drivers/dax/super.c index 9b5e2a5eb0ae..cf9a64563fbe 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -323,7 +323,8 @@ void kill_dax(struct dax_device *dax_dev) return; if (dax_dev->holder_data != NULL) - dax_holder_notify_failure(dax_dev, 0, U64_MAX, 0); + dax_holder_notify_failure(dax_dev, 0, U64_MAX, + MF_MEM_PRE_REMOVE); clear_bit(DAXDEV_ALIVE, &dax_dev->flags); synchronize_srcu(&dax_srcu); diff --git a/fs/xfs/xfs_notify_failure.c b/fs/xfs/xfs_notify_failure.c index 3830f908e215..5c1e678a1285 100644 --- a/fs/xfs/xfs_notify_failure.c +++ b/fs/xfs/xfs_notify_failure.c @@ -22,6 +22,7 @@ #include #include +#include struct xfs_failure_info { xfs_agblock_t startblock; @@ -77,6 +78,9 @@ xfs_dax_failure_fn( if (XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) || (rec->rm_flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK))) { + /* The device is about to be removed. Not a really failure. */ + if (notify->mf_flags & MF_MEM_PRE_REMOVE) + return 0; notify->want_shutdown = true; return 0; } @@ -168,7 +172,9 @@ xfs_dax_notify_ddev_failure( xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_ONDISK); if (!error) error = -EFSCORRUPTED; - } + } else if (mf_flags & MF_MEM_PRE_REMOVE) + xfs_force_shutdown(mp, SHUTDOWN_FORCE_UMOUNT); + return error; } @@ -182,12 +188,24 @@ xfs_dax_notify_failure( struct xfs_mount *mp = dax_holder(dax_dev); u64 ddev_start; u64 ddev_end; + int error; if (!(mp->m_super->s_flags & SB_BORN)) { xfs_warn(mp, "filesystem is not ready for notify_failure()!"); return -EIO; } + if (mf_flags & MF_MEM_PRE_REMOVE) { + xfs_info(mp, "device is about to be removed!"); + down_write(&mp->m_super->s_umount); + error = sync_filesystem(mp->m_super); + /* invalidate_inode_pages2() invalidates dax mapping */ + super_drop_pagecache(mp->m_super, invalidate_inode_pages2); + up_write(&mp->m_super->s_umount); + if (error) + return error; + } + if (mp->m_rtdev_targp && mp->m_rtdev_targp->bt_daxdev == dax_dev) { xfs_debug(mp, "notify_failure() not supported on realtime device!"); @@ -196,6 +214,8 @@ xfs_dax_notify_failure( if (mp->m_logdev_targp && mp->m_logdev_targp->bt_daxdev == dax_dev && mp->m_logdev_targp != mp->m_ddev_targp) { + if (mf_flags & MF_MEM_PRE_REMOVE) + return 0; xfs_err(mp, "ondisk log corrupt, shutting down fs!"); xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_ONDISK); return -EFSCORRUPTED; @@ -209,6 +229,12 @@ xfs_dax_notify_failure( ddev_start = mp->m_ddev_targp->bt_dax_part_off; ddev_end = ddev_start + bdev_nr_bytes(mp->m_ddev_targp->bt_bdev) - 1; + /* Notify failure on the whole device */ + if (offset == 0 && len == U64_MAX) { + offset = ddev_start; + len = bdev_nr_bytes(mp->m_ddev_targp->bt_bdev); + } + /* Ignore the range out of filesystem area */ if (offset + len - 1 < ddev_start) return -ENXIO; diff --git a/include/linux/mm.h b/include/linux/mm.h index 21f8b27bd9fd..9122a1c57dd2 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3183,6 +3183,7 @@ enum mf_flags { MF_UNPOISON = 1 << 4, MF_SW_SIMULATED = 1 << 5, MF_NO_RETRY = 1 << 6, + MF_MEM_PRE_REMOVE = 1 << 7, }; int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index, unsigned long count, int mf_flags);