From patchwork Fri Jul 8 05:42: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: 12910592 Received: from esa15.fujitsucc.c3s2.iphmx.com (esa15.fujitsucc.c3s2.iphmx.com [68.232.156.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9270A7E0 for ; Fri, 8 Jul 2022 05:43:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj1; t=1657259020; x=1688795020; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=CZTxoSgJFBkVtxp6cFQFWGhQZC+zfRK1v3455v9X7mo=; b=kxVsfUYb4diXat07nP7gic5oeJQD/d9XotWqIn4tvMiarbN73PrMcArs liqUlsXxVr0V7LblW+3C6Xa3dL+/Ys3BTJi2Xb3qIUqgklLagW3ds5z4E LkTmLA9w15EUf0xTIUdzLlKU2yGBj4ZW3SKYH2GRkWiM1QLc9nrYwDkjI vFjUaqf86qGFAca/2+JTUd9drd3m22IH9Ps50p8CFdsREmEdB38m04Rdf ArxrFK1egB7/1jwefvZGraLkAqzoEgNubuJerp/kf5KZw/tj5ZiiXrgSU ML+g8zC9yek7qZloPW01pwV9x403eLmTAwh0oodBMQBNZomSkdmEaFeBs Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10401"; a="59881658" X-IronPort-AV: E=Sophos;i="5.92,254,1650898800"; d="scan'208";a="59881658" Received: from mail-os0jpn01lp2106.outbound.protection.outlook.com (HELO JPN01-OS0-obe.outbound.protection.outlook.com) ([104.47.23.106]) by ob1.fujitsucc.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2022 14:42:27 +0900 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b1o4wpdctrScbR0k0uL67xMLV2iJdbnXzkfqXhZqhFpGModoA8i9FUcZpA6qvE6PcFed4DcpGU/i3R76n9zIU30IjZuhcA7neiUGeqF5fXqZ1M2czHZ3OEi/6hzQqUAplWlaoWouIWzXnQrc6ea/00xTrmdL3iIz6FrI8lvLRmnU/J10W7VM/65j74Tb8wsOuaxe7EBjhDtBthhdUMfbiKEfKHdHmXqXhc7fZEiLF2gdzG5D/RUazHPnt8y0+dbsdlJHWhB/unRncLgeCoDmML7QydH+b0KOrEwssaEtBweSZbEX2YIzczpviWpHA8Z80lCYetxEvPKX0PVtQelBlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=CZTxoSgJFBkVtxp6cFQFWGhQZC+zfRK1v3455v9X7mo=; b=YsWK8XNaFXZVx/adh6Z9T6efrNu8kGo/xVcdWBZaRz8yPMsD53fna/5vVmBgIKugAqIzTklGK7U7HvX+O2H4DXaI6aE6qXMWqDqaAnnMim5bkldSLLf+FEYj4HrmSz24Mx4gyQjOBduqmmOyF+M+u8+AAuhqIHZgrgLsQ5a+h67/e3wKM+nCRgOztLJZuupcdsMJj1ViQJkMwiXiDCys6m2/cE+91h7RRPh4xNxlcF8TNQGKAvTPqkdvK+LW7sNGJHpEBI1dvu7OxqpHukYdzlJiZ/MGqWj9ZUG183Dm0rOc+saqUe8x+Mc6rCDzAuXQAYcHfntDOydR0zyhx1yUXQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=fujitsu.com; dmarc=pass action=none header.from=fujitsu.com; dkim=pass header.d=fujitsu.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.onmicrosoft.com; s=selector2-fujitsu-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CZTxoSgJFBkVtxp6cFQFWGhQZC+zfRK1v3455v9X7mo=; b=f4bVlxTw66wAbN7SpOI0xl6h+ioQZewZLGKTBW3eyuGd0yfrbHXhjm1lWABY3ha1rhNSGUU/cjWGUC40u+6+jR/TzUB0BwNKmDiwF13xdPS3Gq0gUZvCrTXd5Mm63v5YSDUaCnXGbhBoxhBcFyIZB9vhuKN+ZBnnz93X9qq/IAg= Received: from OSBPR01MB2920.jpnprd01.prod.outlook.com (2603:1096:604:18::16) by OS3PR01MB6152.jpnprd01.prod.outlook.com (2603:1096:604:d6::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.14; Fri, 8 Jul 2022 05:42:23 +0000 Received: from OSBPR01MB2920.jpnprd01.prod.outlook.com ([fe80::ece2:4ee0:93a4:ce47]) by OSBPR01MB2920.jpnprd01.prod.outlook.com ([fe80::ece2:4ee0:93a4:ce47%7]) with mapi id 15.20.5395.021; Fri, 8 Jul 2022 05:42:23 +0000 From: "ruansy.fnst@fujitsu.com" To: "linux-kernel@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "nvdimm@lists.linux.dev" , "linux-mm@kvack.org" , "linux-fsdevel@vger.kernel.org" CC: "djwong@kernel.org" , "dan.j.williams@intel.com" , "david@fromorbit.com" , "hch@infradead.org" , "jane.chu@oracle.com" Subject: [RFC PATCH v5] mm, pmem, xfs: Introduce MF_MEM_REMOVE for unbind Thread-Topic: [RFC PATCH v5] mm, pmem, xfs: Introduce MF_MEM_REMOVE for unbind Thread-Index: AQHYko1/owWb1jmYaUi3ZNl5TxAoJg== Date: Fri, 8 Jul 2022 05:42:22 +0000 Message-ID: <20220708054216.825004-1-ruansy.fnst@fujitsu.com> References: <20220410171623.3788004-1-ruansy.fnst@fujitsu.com> In-Reply-To: <20220410171623.3788004-1-ruansy.fnst@fujitsu.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.37.0 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=fujitsu.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 21b4364b-3b1e-409f-8a79-08da60a4a1c4 x-ms-traffictypediagnostic: OS3PR01MB6152:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Zf7CFnzd1rHgKqtSIDFo/92yrQh3qtU6ODdyzb0L51PX5w3KXzJrVA1HWj5+K6lBdNj1zMZg7t0+cG8pXvT/97t1wt5dyB2DZE+xvKN7JQNfQD0P4yv9na8skfN7aJHGQ24lkec2V8TzEgz+JxinoOPx6zIFzUsMDWMbtJHyBZWwouUIoI3uNeM1Vg1dFx4y4rB/W58Afe3/86xhtkBIf2D9iKbQviLvynZV1GxhXA/+v1kP8R/IcdlNrtAJBsW6njoSRJ7T0qZXPqPir3MVIwW/mV7Bg1SjFDrr6cZriCzx8mLIa0+D/RBpq5l6KW5qKLW4sO7j9gJ5H/en1hRe8iZ0O1mioZJ1ADvqvhbbPIcLZDWZRYM8pbm8h/FjZvwhcCnPS0JU9Gd9bNO4EIX/ak/HRWLIQWF5AUOrU9RW+hhv0SAiKGbNURMWHaMwY6A6Jq0ymB+ji4++tZhNlIFJLar4cqcNnw/r2e5Iagthq036OeNWA7OPLtvnw4/nUEhb6bCIIsOIM3oUsRI1vbS3KaLHaylPtP9t/1tnLjz12ZtQMn6WGLoFFAZG76fyQASJIoAcgRnNyJ5RCO7/T+RjMqqHV8cc0T+d+tgcD7t/YzVI4WozgVngdh7uaLEndcDWWce2qjLcZMl+QFEyIgtTa4R1f9Y9qQZjP8POubYSvJacLHyFlZGIIQ15sh7XCkVkgku5a857qR52HRQKkwQtBdmZgU+YrHaFzq1G4Thkcipmmc1sgYii8fwn8j924b1uBKe2lOKgiIJ9WmZDFQmdTGUa41XhXnFFJ3TH8/Zv42+hrOAv2mZTmUabq20iHreY4LTlwbQfThTm2hKsnJ+SQUil7VqjbAqwwPeofg/IGXOR7/HHrFxhb5tjZVI0Tqe9 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:OSBPR01MB2920.jpnprd01.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(366004)(136003)(346002)(376002)(39860400002)(396003)(8676002)(66946007)(64756008)(66446008)(86362001)(66476007)(91956017)(7416002)(66556008)(8936002)(2906002)(4326008)(76116006)(36756003)(316002)(85182001)(82960400001)(5660300002)(110136005)(6486002)(6506007)(41300700001)(26005)(186003)(38070700005)(54906003)(966005)(71200400001)(6512007)(83380400001)(478600001)(38100700002)(1076003)(122000001)(2616005);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?eucgb2312_cn?b?RElQRU91UzBHdDZWUGVxZzc3?= =?eucgb2312_cn?b?UUphNXJYb056VCtLYktHL3hGWmhCb2IrbVhaZEU1MVJNbCs4NmVFamVJS2JRZ2tl?= =?eucgb2312_cn?b?Y0NpWi9mMGxsQm9DSjUyR0ZuYk1FbTd5clJUSDlnRm81YUNOMll3cmJFREpiY1NW?= =?eucgb2312_cn?b?Y1lsTjR0NW5ZdnRUYlQvZ1o2YXl2aG9qdWNaYjVyV0lGbnNTbTZzUDlqRys0RXU1?= =?eucgb2312_cn?b?NkoyOWwyRndmVWc3elZHREFPc2VtVnFGcDVHVGxkU1BlUG05ekNMMThkc0dMa2NM?= =?eucgb2312_cn?b?Q1R4QVVEUHJlRi93ZjhZSHVVZ1BtWU5Kanp4eUd2MFpFdWNPS1pZWml6NHN5dDhX?= =?eucgb2312_cn?b?dlpma2xjRm9TdlBxNWs5dGpCaTcxekY2L0Rqanlvb0xHb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WtISmJlN2hTenZ1bDJ0L3RQVWpxcEhDbHdTRHBYUEtvcDdkSkJWUEdJT2py?= =?eucgb2312_cn?b?Und1NjNtd2tqSXZqU29QYWJaWmc9PQ==?= Precedence: bulk X-Mailing-List: nvdimm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-OriginatorOrg: fujitsu.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: OSBPR01MB2920.jpnprd01.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21b4364b-3b1e-409f-8a79-08da60a4a1c4 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Jul 2022 05:42:23.0636 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: a19f121d-81e1-4858-a9d8-736e267fd4c7 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ZB9FuYNP+vA/qmhCbLXHjTyxdwVG8tAvrTf9bZYD/hVS2LlWcnVQ78EE3ClEhLFYG9V9KKjodKWC/yTcxscy6g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3PR01MB6152 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_REMOVE) -> xfs_dax_notify_failure() Introduce MF_MEM_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. == Changes since v4: 1. sync_filesystem() at the beginning when MF_MEM_REMOVE 2. Rebased on next-20220706 Changes since v3: 1. Flush dirty files and logs when pmem is about to be removed. 2. Rebased on next-20220701 Changes since v2: 1. Rebased on next-20220615 Changes since v1: 1. Drop the needless change of moving {kill,put}_dax() 2. Rebased on '[PATCHSETS] v14 fsdax-rmap + v11 fsdax-reflink'[2] [1]: https://lore.kernel.org/linux-mm/161604050314.1463742.14151665140035795571.stgit@dwillia2-desk3.amr.corp.intel.com/ [2]: https://lore.kernel.org/linux-xfs/20220508143620.1775214-1-ruansy.fnst@fujitsu.com/ Signed-off-by: Shiyang Ruan --- drivers/dax/super.c | 2 +- fs/xfs/xfs_notify_failure.c | 16 ++++++++++++++++ include/linux/mm.h | 1 + 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/dax/super.c b/drivers/dax/super.c index 9b5e2a5eb0ae..d4bc83159d46 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -323,7 +323,7 @@ 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_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 aa8dc27c599c..728b0c1d0ddf 100644 --- a/fs/xfs/xfs_notify_failure.c +++ b/fs/xfs/xfs_notify_failure.c @@ -18,6 +18,7 @@ #include "xfs_rmap_btree.h" #include "xfs_rtalloc.h" #include "xfs_trans.h" +#include "xfs_log.h" #include #include @@ -75,6 +76,10 @@ xfs_dax_failure_fn( if (XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) || (rec->rm_flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK))) { + /* Do not shutdown so early when device is to be removed */ + if (notify->mf_flags & MF_MEM_REMOVE) { + return 0; + } xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_ONDISK); return -EFSCORRUPTED; } @@ -168,6 +173,14 @@ xfs_dax_notify_failure( struct xfs_mount *mp = dax_holder(dax_dev); u64 ddev_start; u64 ddev_end; + int error; + + if (mf_flags & MF_MEM_REMOVE) { + xfs_info(mp, "device is about to be removed!"); + error = sync_filesystem(mp->m_super); + if (error) + return error; + } if (!(mp->m_sb.sb_flags & SB_BORN)) { xfs_warn(mp, "filesystem is not ready for notify_failure()!"); @@ -182,6 +195,9 @@ 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_REMOVE) { + return 0; + } xfs_err(mp, "ondisk log corrupt, shutting down fs!"); xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_ONDISK); return -EFSCORRUPTED; diff --git a/include/linux/mm.h b/include/linux/mm.h index 794ad19b57f8..3eab2d7ba884 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3240,6 +3240,7 @@ enum mf_flags { MF_UNPOISON = 1 << 4, MF_SW_SIMULATED = 1 << 5, MF_NO_RETRY = 1 << 6, + MF_MEM_REMOVE = 1 << 7, }; int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index, unsigned long count, int mf_flags);