Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1305852ioo; Sun, 22 May 2022 10:04:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycMukEZpiZGHaV7KR7qDfMZb1UaQoT1eYK/DqES1UBqCYSNHZwW6vCnS9NtvcLkGmy3Xyl X-Received: by 2002:a05:6402:1f07:b0:42a:9efb:71b1 with SMTP id b7-20020a0564021f0700b0042a9efb71b1mr19930220edb.397.1653239059634; Sun, 22 May 2022 10:04:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653239059; cv=none; d=google.com; s=arc-20160816; b=kzCuC4ppQ81UiQ4bxpcsgP+3nldD1cmeunaj3SyMqDKpqJ9k+SAY9qVEXobLV0KGqZ hzSt+6xpLIeOvuWifdQIsMePL7yc/eaT0gbzT5zUDsB4RuZKOB3iabpsai/dO7XbPZKf oCEDoZEKyxNPWWgDTn+7pq45uqfdOl5UGy6P4AxA/A7icza9qSC4A73mdE53zajb58is NUP70fR92lg+EIqPT/PkUUZA8oQrDpqIV4WJWQ1tHpqiegk5eJSu6ioXoj/Oi45R0Iv3 H1vXBHXxXE2DGWhr/IWgTy2eKYcRzpU8UxJDw+NqLNQXt3T6GgY0UWJXV/UPNeJycO5X OAFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-hdrordr:ironport-data; bh=9QklwYZ4KH2JSxdt7TofzWfo8wA9J5YVtDC3wFX7KAw=; b=SmE9h4I9Y0+JtyqUL86SEFuSJGMo8jeU/TInbNEym3BCV7p+SVGBP3Q3ZYnkrJUX5k hVzUrMoI2UsRJZgdqsZDXV3V9TUSp+PTbdO0K+cI7SLyfQUbOBB9WMJEmsCtgHfwlBrr 02MIqjtWUfpo8qsZnSIWPVDsbSTpWfv80XxVxDLhS/2lczphjVIQn9MCIAPirU+XXcnp xIm0IHAy6v5awTv8Ek0Q9Aep3+CXPP9YSrPfWBtSHc2HkKtax7eq5N3zbSgBAIVPnqnk vVra0LrinYzu/Ntvf2iQXtZkCS/Vd6aoQ/o78rMv15Zgm4/e2EgDILL3zj/cx5h6TelS 1MEw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hq26-20020a1709073f1a00b006fee28c47a7si794315ejc.9.2022.05.22.10.03.51; Sun, 22 May 2022 10:04:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=fujitsu.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234968AbiETFhh (ORCPT + 99 others); Fri, 20 May 2022 01:37:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234896AbiETFhc (ORCPT ); Fri, 20 May 2022 01:37:32 -0400 Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5B6CC14AF76; Thu, 19 May 2022 22:37:30 -0700 (PDT) IronPort-Data: =?us-ascii?q?A9a23=3A2Y2wB66t99dSa6y/nxB7CwxRtFPGchMFZxGqfqr?= =?us-ascii?q?LsXjdYENSgzEPx2EfCmuHPfqKM2XxKdhxPojl8RtX6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IronPort-AV: E=Sophos;i="5.88,333,1635177600"; d="scan'208";a="124369726" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 20 May 2022 13:37:29 +0800 Received: from G08CNEXMBPEKD05.g08.fujitsu.local (unknown [10.167.33.204]) by cn.fujitsu.com (Postfix) with ESMTP id F07A44D16FFC; Fri, 20 May 2022 13:37:23 +0800 (CST) Received: from G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) by G08CNEXMBPEKD05.g08.fujitsu.local (10.167.33.204) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 20 May 2022 13:37:25 +0800 Received: from G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) by G08CNEXJMPEKD02.g08.fujitsu.local (10.167.33.202) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 20 May 2022 13:37:24 +0800 Received: from irides.mr.mr (10.167.225.141) by G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.209) with Microsoft SMTP Server id 15.0.1497.23 via Frontend Transport; Fri, 20 May 2022 13:37:23 +0800 From: Shiyang Ruan To: , , , , CC: , , , , Subject: [RFC PATCH v2] mm, pmem, xfs: Introduce MF_MEM_REMOVE for unbind Date: Fri, 20 May 2022 13:37:22 +0800 Message-ID: <20220520053722.2913971-1-ruansy.fnst@fujitsu.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220410171623.3788004-1-ruansy.fnst@fujitsu.com> References: <20220410171623.3788004-1-ruansy.fnst@fujitsu.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-yoursite-MailScanner-ID: F07A44D16FFC.A1592 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: ruansy.fnst@fujitsu.com X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. [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 == Changes since v1: 1. Drop the needless change of moving {kill,put}_dax() 2. Rebased on '[PATCHSETS] v14 fsdax-rmap + v11 fsdax-reflink'[2] --- drivers/dax/super.c | 2 +- fs/xfs/xfs_notify_failure.c | 6 +++++- include/linux/mm.h | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/dax/super.c b/drivers/dax/super.c index 5ddb159c4653..44ca3b488e2a 100644 --- a/drivers/dax/super.c +++ b/drivers/dax/super.c @@ -313,7 +313,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..91d3f05d4241 100644 --- a/fs/xfs/xfs_notify_failure.c +++ b/fs/xfs/xfs_notify_failure.c @@ -73,7 +73,9 @@ xfs_dax_failure_fn( struct failure_info *notify = data; int error = 0; - if (XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) || + /* Do not shutdown so early when device is to be removed */ + if (!(notify->mf_flags & MF_MEM_REMOVE) || + XFS_RMAP_NON_INODE_OWNER(rec->rm_owner) || (rec->rm_flags & (XFS_RMAP_ATTR_FORK | XFS_RMAP_BMBT_BLOCK))) { xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_ONDISK); return -EFSCORRUPTED; @@ -182,6 +184,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_REMOVE) + return -EOPNOTSUPP; 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 e2c0f69f0660..ebcb5a7f3295 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3226,6 +3226,7 @@ enum mf_flags { MF_MUST_KILL = 1 << 2, MF_SOFT_OFFLINE = 1 << 3, MF_UNPOISON = 1 << 4, + MF_MEM_REMOVE = 1 << 5, }; int mf_dax_kill_procs(struct address_space *mapping, pgoff_t index, unsigned long count, int mf_flags); -- 2.35.1