From patchwork Thu Jul 14 10:34:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shiyang Ruan X-Patchwork-Id: 12917685 Received: from esa6.fujitsucc.c3s2.iphmx.com (esa6.fujitsucc.c3s2.iphmx.com [68.232.159.83]) (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 19D7429A1 for ; Thu, 14 Jul 2022 10:35:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj1; t=1657794945; x=1689330945; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-transfer-encoding:mime-version; bh=AL+n3rpchvxeHAWcuSYVma9eU5v5v5BPE5FiFPQHoIU=; b=hYuYvYdWiO8CizSAI945BxEa2RjWOZ1cBbJODsx+J7vUiX5CM86rle84 AjL8BUPYTclXAc8vnf7/mwaNV/k7+ssGEdwBQCDycxyPPxuLEMccWRrJj 27LuiIAtittePtE+eaUeAD0DPE0OlvbgjqY+tV6eGlMugUYbtA1U2TB+e tj6o4NB+oAo9Ek+UX88J7kHnX6GGLJhqxhDU8qSIqorv+TljmXiHo80Ck om60HhLA8O9F1sU1UpNh5XLFJDaUwpE1GSbaPwLARZuuB//II5ouBX8wH wQuf5UsDHPsV3L+wyTFos8qpxAzm2GvDZnLObGSkWc8g/XXw9vYiCR+ef Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10407"; a="60417266" X-IronPort-AV: E=Sophos;i="5.92,271,1650898800"; d="scan'208";a="60417266" Received: from mail-tycjpn01lp2169.outbound.protection.outlook.com (HELO JPN01-TYC-obe.outbound.protection.outlook.com) ([104.47.23.169]) by ob1.fujitsucc.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2022 19:34:32 +0900 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FjUFhrpCqarok3ie7/+fD7Vo6opIEFTIZf56oTn3cFUmySm7Zl03B7OgnXmy5NoSRdaswX6OJ4TY4OszHxTncueq+RgLU19SiTpEBXYltNgQOZHMT7ZQFci4nuNkMEd5fQsQSL3f4/i3OxPjpy4q0uBaqgGv8Ge5+kN7zwzmvRdw2SnX1iVRCmIqpMhFbVa1/LEjW5zleOinz7n/hLF5H4MThfe2X86STkzb1XZc6SC3l7qWKJ2wQFmUIxegh29AHJb36T1Nx0dpwoIZEZRJXZdoCghZLLp0Q6Qi0zkeTeZEP9dAHn7IPKHcb8jMhnFm/1QgePHs0jR+Q0GNhhCrwQ== 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=AL+n3rpchvxeHAWcuSYVma9eU5v5v5BPE5FiFPQHoIU=; b=dxWP6uxOt29RUZn+tu2l3j+DysWUqoUz5yQXsTUVW568Q+ekgsP2stn7SgcwLdtXTo17JQ5NbCan1A7NooMQQGRDy1ryJN0obLg/8KVt2sH2ANyvaQPz2Z5wvyGx7U8jjSQF6+1cUygEGgzlaN5SxR/jhygafoGLI8xnrNHdaRd+7za2oj9GRL8Az9jv6tZOLMBCj9fx0lk2okI9iGhdne1HNFYzNj69SHiXiUdwTSCleNsGUqnXzbsWe/HG6ZL2/NVQ14u98VZVbsQphb7tKoIM5iymfRC09XpjVmaKxP4Kpvu/4EmYZihVxhOuhQm3PbHQ2AinGF4UgARVVLEurA== 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=AL+n3rpchvxeHAWcuSYVma9eU5v5v5BPE5FiFPQHoIU=; b=Qe8S/WS5o3Fb/9HkduE1qYOxTHisUXiLlYcAeJ8fFhj/WM6pXG1mb+EZcS9i45TBjbsK+noECuocEj6LYrx6AEOscTrrWTmEsCMYWhSpM2fTV+L6ijn6EZGPwhV//LbYtBHLdpL+p4icvtyBpkqvj9j3p+Ljb4W+be4zAFFr2iA= Received: from OSBPR01MB2920.jpnprd01.prod.outlook.com (2603:1096:604:18::16) by OS3PR01MB5685.jpnprd01.prod.outlook.com (2603:1096:604:c2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.20; Thu, 14 Jul 2022 10:34:29 +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.5417.026; Thu, 14 Jul 2022 10:34:29 +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 v6] mm, pmem, xfs: Introduce MF_MEM_REMOVE for unbind Thread-Topic: [RFC PATCH v6] mm, pmem, xfs: Introduce MF_MEM_REMOVE for unbind Thread-Index: AQHYl21MSZyYmdiLqka88bTs8k0Skg== Date: Thu, 14 Jul 2022 10:34:29 +0000 Message-ID: <20220714103421.1988696-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: de819951-3121-4655-86c7-08da65846ee8 x-ms-traffictypediagnostic: OS3PR01MB5685:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: QRmZNgku170Y7u2dqsntP+u4RY/lCvWSdExR3U25yfupzjunPl2h1fCxMTnCllHPRZzZQjMH+r2zkzoKntqfmEXtN5JcAd9zj1ZknZqlAlZs3z/ppORRUWMAmhiIKkAhX4wEw1AiHfrTCu5o5od+HFmdXRvvBtbN1sdrKhol2wFMyU4jX0tOFpWWp2c40PJaXqf0FEDLH9XUD4uk5KFaChUoRCASn9jibAD/RApltLCACfSC/iC1hRCbi80V4nIVkbIdTKuodQ8CepBin9/uUjFy4m5LcE0H56LHbMjFoYlfs0KWkmc+0olzPlVzVdyS6ZHovHafYI/NGJK4zdBwZ1wLYATMH0/XRL3znfRTrqIGsZ7sRBrdhsEYghQ+D0FTgSo/da7ceJbqURzo2PidQgR7Ef6Bf2ohYbtRBW9PtwbZ62TZfMUFMadNWC0mloHFo9l6qachvTOtybI2ZdYKD/jxMU2y1fl2nQp27SIjbbVNsYiXTdwCDolPau/HPrQhDfXstw/lrNZqYtACtyofhfa8aPYIggNbinfRGgTmL/Oc7uMjznxGvBRt4KS3hxtGdWmujgxoi3ejwQPsadFrfLMLEHi95NhkFezXmb4l8vTxLmFwrFxp4N2ODBSyydskAP8uKoBk9ken4twfnrdoV0/u6LfVLiarsmHu9r/3YeSqSa7t9nqH0Vi7sZt5O6ofNbtkQAm3D+H3oVuIA+vaMbkBHHIW10VyudKjXAMzmFyThytaencIdn7iuBqR72/OH/zmfeEgNEdagmzZsL1kzXD9dIfMzq3TIeRkO0DnvzFk2G4IpjlqPhsKYGTnGK/IKpexoa5lItx47B4884F7RBgfYIWgm1KfIHZqiUJYJIo= 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)(346002)(39860400002)(136003)(396003)(366004)(376002)(66446008)(1076003)(66946007)(4326008)(66556008)(8676002)(66476007)(91956017)(6512007)(83380400001)(36756003)(2906002)(5660300002)(186003)(85182001)(76116006)(7416002)(8936002)(64756008)(26005)(71200400001)(54906003)(110136005)(86362001)(82960400001)(478600001)(38070700005)(966005)(316002)(6506007)(41300700001)(6486002)(2616005)(38100700002)(122000001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?eucgb2312_cn?b?TXVTZXBsZjhKZnp6bHAvV1hJ?= =?eucgb2312_cn?b?bDhqV2d4OCtWb3Q3a3hlUzRiUjZjbTUwODhpLzVyOGtBTjZZRnpqeHhmTFJMZWRP?= =?eucgb2312_cn?b?dDBVRk4zREVsd2VwTnIvaVZDbTdkN2tPczNPSktWeTNDbTNFckZvWTBVU1pyUVRa?= =?eucgb2312_cn?b?cGhQN2tsZFRjOFYwanFNMngzdVI2aS9MQmcxclVsNjhSYWM5UndZdGJrM3NaNXBJ?= =?eucgb2312_cn?b?M3ZteTVxVlFUMGgyVnIvU3dCNldTMHQ0b2ttWWZZL1Z2T3U0NW1NM2RXZ0orS0Fq?= =?eucgb2312_cn?b?ZzhNcmxaLzFtQzJFWnVuUzNxT2RUQ0UvTUdmMU5valN0Ym1mNHlwOFlWM1k5Q3NR?= =?eucgb2312_cn?b?U0s4akwxbHBBS2pjcjBxR1Y0b0RQQmRWZ01JQjE2MlE1aysrTkpKTXE4MVNrM3p6?= =?eucgb2312_cn?b?aU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zd1N25tSGxHMGxjaTVGaUYyOElTNTVBVE5pYmVaMWJTaHM0?= =?eucgb2312_cn?b?bUgrVGJJOXVPNGQ5Z0dIMDJPdVE9PQ==?= 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: de819951-3121-4655-86c7-08da65846ee8 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jul 2022 10:34:29.6542 (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: 0Th+v/LRBfwuyWvqBebMp4QnqeCgGkhWgcYYjFDUpHi05+7kznkeCeXyxdTIsZ+4pGWH2gQACTrXK9K+tFrfiQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: OS3PR01MB5685 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. == Changes since v5: 1. Renamed MF_MEM_REMOVE to MF_MEM_PRE_REMOVE 2. hold s_umount before sync_filesystem() 3. move sync_filesystem() after SB_BORN check 4. Rebased on next-20220714 Changes since v4: 1. sync_filesystem() at the beginning when MF_MEM_REMOVE 2. Rebased on next-20220706 [1]: https://lore.kernel.org/linux-mm/161604050314.1463742.14151665140035795571.stgit@dwillia2-desk3.amr.corp.intel.com/ Signed-off-by: Shiyang Ruan Reviewed-by: Darrick J. Wong --- drivers/dax/super.c | 3 ++- fs/xfs/xfs_notify_failure.c | 15 +++++++++++++++ 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..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 69d9c83ea4b2..6da6747435eb 100644 --- a/fs/xfs/xfs_notify_failure.c +++ b/fs/xfs/xfs_notify_failure.c @@ -76,6 +76,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))) { + /* Do not shutdown so early when device is to be removed */ + if (notify->mf_flags & MF_MEM_PRE_REMOVE) + return 0; xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_ONDISK); return -EFSCORRUPTED; } @@ -174,12 +177,22 @@ xfs_dax_notify_failure( struct xfs_mount *mp = dax_holder(dax_dev); u64 ddev_start; u64 ddev_end; + int error; if (!(mp->m_sb.sb_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); + 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_warn(mp, "notify_failure() not supported on realtime device!"); @@ -188,6 +201,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; diff --git a/include/linux/mm.h b/include/linux/mm.h index 4287bec50c28..2ddfb76c8a83 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3188,6 +3188,7 @@ enum mf_flags { MF_SOFT_OFFLINE = 1 << 3, MF_UNPOISON = 1 << 4, MF_SW_SIMULATED = 1 << 5, + MF_MEM_PRE_REMOVE = 1 << 6, }; int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index, unsigned long count, int mf_flags);