Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp669495rwb; Thu, 18 Aug 2022 10:04:50 -0700 (PDT) X-Google-Smtp-Source: AA6agR6x+/aa9TD8ZQL61nvfjpSEBma65AIBAGVDRxjDMJmz3fN6zWum4VLwGsDohzZb4hPXigoA X-Received: by 2002:a17:90b:180b:b0:1f5:160c:a652 with SMTP id lw11-20020a17090b180b00b001f5160ca652mr3970296pjb.235.1660842290252; Thu, 18 Aug 2022 10:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660842290; cv=none; d=google.com; s=arc-20160816; b=Rpsnq1ht4gThQcmIo8t2SRSCjD+56hvCTefKIkQNW2pK1s0svELaboraM0kZR12b4e jBAjc1XJpJrJpfGuhVOxz2fsMepYqRJ0u0VV7zMCHd2bT36XqLYrC5GFrg9Th0BbNzcC jVKqUnucF0YOTCk36iRiF0VKYeLL62CD08yvFX0NZ6sI52pA74CIxInVsmt/GEvYuEgm 0MQHeRn/zlsKYdOxS8os5GMwoATYUFkKkJthwG2yRA0GrYanNlLLKOxxMms7l396kcFZ iOAIdnhluasuR9d8JLuyk2oTN8HNf/8v7lM/BBZlxzcjPT+T812IKYAMpJHsTECAjllK DGjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=91bZrmSKuVnPZrm6XS4Wd1r5zK1eOA8Sh2Y1J1iI7uk=; b=Rj1PM7rm37TCPGniO1pZAZeP7j48tsTOKzNLLYkdnWTivZ2RrHMAzSUMSXJ7IATVKQ UTAgHEdDbcE5FaGHqL6eZVStixcgwCAPmZUrAsipbCWv14ZhwvQ0gqRxA3AlfetT9Tn6 KEUi6lHf3LVKXv3O835AqC4FkKSJzXpy5gPU0bXYg4oID5R5TN8bMpduK9s/eEGI32gd G80U8TgWewbyesC3y14bHa6OuGDd4+eDh/TMASmesGXRBv5Sd2yflvEkgX9bDAAc1IUx bkOpZdqse4/B20b3e4ltJRGbSdYXduzg9iKpV4EZfonrx6cQMxRc+otyXGkYSD2wnJkO kmGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LAdvY8HW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q5-20020a17090a9f4500b001f588cd3526si1656422pjv.50.2022.08.18.10.04.30; Thu, 18 Aug 2022 10:04:50 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=LAdvY8HW; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345280AbiHRRBL (ORCPT + 99 others); Thu, 18 Aug 2022 13:01:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345321AbiHRRA2 (ORCPT ); Thu, 18 Aug 2022 13:00:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A691C12C0; Thu, 18 Aug 2022 10:00:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5EB546163F; Thu, 18 Aug 2022 17:00:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3C28C43470; Thu, 18 Aug 2022 17:00:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1660842017; bh=4alT+1kcW0AynTw4CzIKjHnkkcstzi9mfOYgPu9672k=; h=Date:From:To:Cc:Subject:From; b=LAdvY8HWNTKDjWAYsDasqK2xyXkUL5AdcRrhffJlzOahe/Nthx9qZv02KrOQhM2F6 BKVXCJusocInSjVo0c2x/ExHLwoJIbWAo31cpvumUUcm2yewTjEjKoSyeW5uLyjMn5 MWxgjt2y0iQWSVQSxl7rA2tnIOs9sk27Q/DhS2L3YG+eCnnUq/nXxVuK9elVqhal0z lGWPg70nVFUqE742DkI6Z4OjizVs+BLISNz8iLdeHVkX0to/b7ad8qyL1kq3DLXtk8 KXSyI0LSHzOzTtnJ7aDzLLTOwPq0l3kNJ7uE6yVCdxXtWyZKGdmguQisnc5feZ3yGw BUngpS41E2yRg== Date: Thu, 18 Aug 2022 10:00:17 -0700 From: "Darrick J. Wong" To: Shiyang Ruan , Dave Chinner Cc: Dan Williams , "linux-kernel@vger.kernel.org" , "linux-xfs@vger.kernel.org" , "nvdimm@lists.linux.dev" , "linux-mm@kvack.org" , "linux-fsdevel@vger.kernel.org" , "david@fromorbit.com" , "hch@infradead.org" , "jane.chu@oracle.com" Subject: [PATCH] xfs: on memory failure, only shut down fs after scanning all mappings Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 From: Darrick J. Wong xfs_dax_failure_fn is used to scan the filesystem during a memory failure event to look for memory mappings to revoke. Unfortunately, if it encounters an rmap record for filesystem metadata, it will shut down the filesystem and the scan immediately. This means that we don't complete the mapping revocation scan and instead leave live mappings to failed memory. Fix the function to defer the shutdown until after we've finished culling mappings. While we're at it, add the usual "xfs_" prefix to struct failure_info, and actually initialize mf_flags. Signed-off-by: Darrick J. Wong --- fs/xfs/xfs_notify_failure.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/fs/xfs/xfs_notify_failure.c b/fs/xfs/xfs_notify_failure.c index 69d9c83ea4b2..65d5eb20878e 100644 --- a/fs/xfs/xfs_notify_failure.c +++ b/fs/xfs/xfs_notify_failure.c @@ -23,17 +23,18 @@ #include #include -struct failure_info { +struct xfs_failure_info { xfs_agblock_t startblock; xfs_extlen_t blockcount; int mf_flags; + bool want_shutdown; }; static pgoff_t xfs_failure_pgoff( struct xfs_mount *mp, const struct xfs_rmap_irec *rec, - const struct failure_info *notify) + const struct xfs_failure_info *notify) { loff_t pos = XFS_FSB_TO_B(mp, rec->rm_offset); @@ -47,7 +48,7 @@ static unsigned long xfs_failure_pgcnt( struct xfs_mount *mp, const struct xfs_rmap_irec *rec, - const struct failure_info *notify) + const struct xfs_failure_info *notify) { xfs_agblock_t end_rec; xfs_agblock_t end_notify; @@ -71,13 +72,13 @@ xfs_dax_failure_fn( { struct xfs_mount *mp = cur->bc_mp; struct xfs_inode *ip; - struct failure_info *notify = data; + struct xfs_failure_info *notify = data; int error = 0; if (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; + notify->want_shutdown = true; + return 0; } /* Get files that incore, filter out others that are not in use. */ @@ -86,8 +87,10 @@ xfs_dax_failure_fn( /* Continue the rmap query if the inode isn't incore */ if (error == -ENODATA) return 0; - if (error) - return error; + if (error) { + notify->want_shutdown = true; + return 0; + } error = mf_dax_kill_procs(VFS_I(ip)->i_mapping, xfs_failure_pgoff(mp, rec, notify), @@ -104,6 +107,7 @@ xfs_dax_notify_ddev_failure( xfs_daddr_t bblen, int mf_flags) { + struct xfs_failure_info notify = { .mf_flags = mf_flags }; struct xfs_trans *tp = NULL; struct xfs_btree_cur *cur = NULL; struct xfs_buf *agf_bp = NULL; @@ -120,7 +124,6 @@ xfs_dax_notify_ddev_failure( for (; agno <= end_agno; agno++) { struct xfs_rmap_irec ri_low = { }; struct xfs_rmap_irec ri_high; - struct failure_info notify; struct xfs_agf *agf; xfs_agblock_t agend; struct xfs_perag *pag; @@ -161,6 +164,11 @@ xfs_dax_notify_ddev_failure( } xfs_trans_cancel(tp); + if (error || notify.want_shutdown) { + xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_ONDISK); + if (!error) + error = -EFSCORRUPTED; + } return error; }