Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2064321iob; Fri, 20 May 2022 00:36:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxtfNkqX73EW5HlJ8mvITSWVL3JzWjzqeHIGYIRgL8w1Dd2nxlMnw21r9frXb6t6GqIL8Oo X-Received: by 2002:a17:903:240f:b0:156:8e81:a0a3 with SMTP id e15-20020a170903240f00b001568e81a0a3mr8236627plo.13.1653032194942; Fri, 20 May 2022 00:36:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653032194; cv=none; d=google.com; s=arc-20160816; b=J3IcfAug7GRmyMvrjGwc7zY5dJbHiue+xuXERXFgBUyMvitdvPtATUeWtfCB5Ygyrq zeQi2bblCEIMmZ8BbSj3weqOkAQ834SqMPaFEG5SAWjtpZ+k/3w0bfiZw7z3UVYv5O5k n8CthwwdyqHUPbqfutSDW7D+y/fTwlaPFz7XBcD8KdaTdVabzxJ7XJBXm8/udJ7eMKU1 jfPNHAeoL/xn4XccmZZzQz/02z9BdMVrjhNm51ivFRHccgIsLvhHO6iTnFQbjAgdH1iK TB5Cy3ZceUOMBrwEjnCwGYVm2EgwfI/N/kpJJGudlNxkJJY/qumd1a/GgSRFlodmJ4jc shBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=/Pi+8cfH6DfsGEdcum04TfEtI+zPbFA5e5bZDARN49U=; b=pu/K5WlCRdehSgyn/WgOpfnuHSAosExCKsILDqz9xv7f4LiZfX2HNvlfTgqXwdiWA/ rN8uujtGXCk6u+VlbfbGa3QOZi+EYzTF5eJl0t7On2BvpX1CpI+ddhtk7ad0RnUMV9gn 6LPTQKLcZBXRYKRjhZ49WPYFktwIws+D3iSgAuBizOYnY+1pyQ01Fe/3AiG6eSU4C7SF +93EZAgzFyFdGopczWlWhiVRlINDvd2ynbf1+1YI+8hlyC0I+Z/Eu+m/JTgNu536oZL/ 3PdQiG/9ToBlJ+DgF7ywhz5D1RC78iK262mEMIA3c5+thALLMLGw/hC1vOcEaMfQw8KM 3TXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=XT7M+hbh; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i28-20020a63541c000000b003c5f0bd31d1si9516751pgb.178.2022.05.20.00.36.15; Fri, 20 May 2022 00:36:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@gmail.com header.s=20210112 header.b=XT7M+hbh; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243006AbiETEYM (ORCPT + 99 others); Fri, 20 May 2022 00:24:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242612AbiETEYL (ORCPT ); Fri, 20 May 2022 00:24:11 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0926F146775 for ; Thu, 19 May 2022 21:24:11 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id u15so6738072pfi.3 for ; Thu, 19 May 2022 21:24:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/Pi+8cfH6DfsGEdcum04TfEtI+zPbFA5e5bZDARN49U=; b=XT7M+hbhbVT8LLYnLtiurNtqa3Cw5FmvF0lYvklLwy6rC3qS4suvilT8yExDqKcy2R nBGgdKmDuKfkzGzGiQ+qFDzEirpXGm/OeqOCvyjzmh1ulT17RgGZ2uQGuc+0It50xvoo Xz+DB2fgRn1Ir0VeT41lKHz0V80H5b5k4Y6BBF0X6BynvIK6wqSJWaA3yHpdUmkxbN+K jR1H8qnl13/cQv0snptAPy0S3f1QxlFHZOR0ZsIYFWipCI9orejGfon58t2oggYQGJ2K DPyTwDXGb1Yu5BouiKLwYAQ1VHGD+Hczhs0KIYVF0M6c4lGlTG/WrSA+h8KWZGohgnOx ySgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/Pi+8cfH6DfsGEdcum04TfEtI+zPbFA5e5bZDARN49U=; b=MjIkMKNifwmVY+QKslwJILV1LFhjWKEyFNbtByRX+DweirOtYe4ITqacOg9c3UCJ37 Dq4T0XvY8FlyMcIlRLPUDFou1osZP+MaIRWkAGy5KYzSzd/CBoEU10vV32P66m8E+z+w OMzi83gnmceFiM1EhGEnkusFFKhyyfptGtX7qYkpnEVR/u1hyErgpKe2AG9jPZTgcxiC ZWzTMWccVwbqsSHgF8Upu00CnlMe9DtyFctt95Dvdjn66vFDeDD/NX5xDOThTaqO091J bLY6UHGaS9HZF4YtyYH0NPhknvU5Ul7WNhS1hYxqdoaquz8NN0U2pLGjeRe60Y5/odA+ JBrw== X-Gm-Message-State: AOAM5300I/RMbRZlfkoBMZZWHaykXoT2egigAExugj4QMWt3BvVfuq9L KGMQfmrj4tc+W2W2RNhcN4c= X-Received: by 2002:a65:6205:0:b0:3f5:d436:5446 with SMTP id d5-20020a656205000000b003f5d4365446mr6694645pgv.532.1653020650414; Thu, 19 May 2022 21:24:10 -0700 (PDT) Received: from localhost ([2406:7400:63:532d:c4bb:97f7:b03d:2c53]) by smtp.gmail.com with ESMTPSA id b67-20020a636746000000b003f5eb31fc4bsm4321585pgc.11.2022.05.19.21.24.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 May 2022 21:24:10 -0700 (PDT) Date: Fri, 20 May 2022 09:54:05 +0530 From: Ritesh Harjani To: Zhang Yi Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yukuai3@huawei.com Subject: Re: [PATCH v2] ext4: fix warning when submitting superblock in ext4_commit_super() Message-ID: <20220520042405.xncu55ceekgrzhyu@riteshh-domain> References: <20220520023216.3065073-1-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220520023216.3065073-1-yi.zhang@huawei.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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-ext4@vger.kernel.org On 22/05/20 10:32AM, Zhang Yi wrote: > We have already check the io_error and uptodate flag before submitting > the superblock buffer, and re-set the uptodate flag if it has been > failed to write out. But it was lockless and could be raced by another > ext4_commit_super(), and finally trigger '!uptodate' WARNING when > marking buffer dirty. Fix it by submit buffer directly. > > Reported-by: Hulk Robot > Signed-off-by: Zhang Yi > --- > v2->v1: > - Add clear_buffer_dirty() before submit_bh(). Thanks for the patch. Reviewed lock_buffer()/unlock_buffer(), get_bh/put_bh() and other possible error paths, looks good to me. Feel free to add - Reviewed-by: Ritesh Harjani -ritesh > > fs/ext4/super.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) > > diff --git a/fs/ext4/super.c b/fs/ext4/super.c > index 1466fbdbc8e3..9f6892665be4 100644 > --- a/fs/ext4/super.c > +++ b/fs/ext4/super.c > @@ -6002,7 +6002,6 @@ static void ext4_update_super(struct super_block *sb) > static int ext4_commit_super(struct super_block *sb) > { > struct buffer_head *sbh = EXT4_SB(sb)->s_sbh; > - int error = 0; > > if (!sbh) > return -EINVAL; > @@ -6011,6 +6010,13 @@ static int ext4_commit_super(struct super_block *sb) > > ext4_update_super(sb); > > + lock_buffer(sbh); > + /* Buffer got discarded which means block device got invalidated */ > + if (!buffer_mapped(sbh)) { > + unlock_buffer(sbh); > + return -EIO; > + } > + > if (buffer_write_io_error(sbh) || !buffer_uptodate(sbh)) { > /* > * Oh, dear. A previous attempt to write the > @@ -6025,17 +6031,21 @@ static int ext4_commit_super(struct super_block *sb) > clear_buffer_write_io_error(sbh); > set_buffer_uptodate(sbh); > } > - BUFFER_TRACE(sbh, "marking dirty"); > - mark_buffer_dirty(sbh); > - error = __sync_dirty_buffer(sbh, > - REQ_SYNC | (test_opt(sb, BARRIER) ? REQ_FUA : 0)); > + get_bh(sbh); > + /* Clear potential dirty bit if it was journalled update */ > + clear_buffer_dirty(sbh); > + sbh->b_end_io = end_buffer_write_sync; > + submit_bh(REQ_OP_WRITE, > + REQ_SYNC | (test_opt(sb, BARRIER) ? REQ_FUA : 0), sbh); > + wait_on_buffer(sbh); > if (buffer_write_io_error(sbh)) { > ext4_msg(sb, KERN_ERR, "I/O error while writing " > "superblock"); > clear_buffer_write_io_error(sbh); > set_buffer_uptodate(sbh); > + return -EIO; > } > - return error; > + return 0; > } > > /* > -- > 2.31.1 >