Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp6767737rwd; Tue, 6 Jun 2023 01:22:23 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ovxZIBrbM5dbrle7OSTRaYhp1BpGxm2Pbl+9zN4nTtH7OCHmK9husxiqj+JOz0w4EKExV X-Received: by 2002:a05:6358:4e11:b0:129:c1c1:c897 with SMTP id cf17-20020a0563584e1100b00129c1c1c897mr1389294rwb.24.1686039743656; Tue, 06 Jun 2023 01:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686039743; cv=none; d=google.com; s=arc-20160816; b=c9WEA6fOplQ3yQOhXlCIHS6Fx9Hi1PpVn7pAEqzs3fUiB7OEroJvaS2kEjvpooExgA glz+v0USlTvW7Cu6TZYy8Zhu5iLIt8IwnRSHEqxEZ8mrGhR2wvUOb7nyJXym79gRPBTw WS5kDX38HyfpjOfUY3wwwEUEZSAHdvdDWBm2YW+cCInvNIJklE6G35VUQaV127NC+q42 CJFhk9yuqDDyp672MIFMvCYQM6m4nA45JxfC84Q4kJ2/DgNnKWUnW6B1eBFcIxyDRmFk cYIVw0QmJOqHO+/DH01/VeJ8w5KisaWbLo5aXXVZNo+cDQBk1VoK3jMxIt1biTb/1Kif gniA== 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 :dkim-signature; bh=S7QocHAeNupt2yfSlCCiT1kcKEGTLlJpepX09+qPGXU=; b=id5P0n+XqxvtKVBnufvdSl3X75OJf9BvFbhh8MwrHFiXuj39FP2NfSczMmMbY9VH8t GuXRgMgcfCkl2SdhrSdd5gpg/bo0ERFHtRXC+JWg31bS7q7etOujQ2JPGF4iiloAatO8 B7B0mgHDfo5nEKxA59Mkii+BTX67xQxM/sdHTOcNiff+TY/gGXVnL1ugKUcMaxvQY1mU ZOBfPvAX3vvqTosNHa3EEOPVtc2cH8f9+gZb0tZiMkDpBJOWX7uHaCqNGqUpYVnd9QgP 4BayyQRu0arUv/9+FX/kKNbzZhKQENaHCr3kiPjoVeTsJxcbB6CQqe1xT714g0iYC7Ud j/Og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=BLzAzfBv; dkim=neutral (no key) header.i=@suse.cz; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hc7-20020a17090b318700b0025066f45e40si6940302pjb.22.2023.06.06.01.22.10; Tue, 06 Jun 2023 01:22:23 -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=@suse.cz header.s=susede2_rsa header.b=BLzAzfBv; dkim=neutral (no key) header.i=@suse.cz; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229880AbjFFICa (ORCPT + 99 others); Tue, 6 Jun 2023 04:02:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233765AbjFFICF (ORCPT ); Tue, 6 Jun 2023 04:02:05 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6EAD19A8 for ; Tue, 6 Jun 2023 00:59:48 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 77A801FD6C; Tue, 6 Jun 2023 07:59:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1686038387; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=S7QocHAeNupt2yfSlCCiT1kcKEGTLlJpepX09+qPGXU=; b=BLzAzfBvtspXmE/khn/0a5yrhHpJR1+nNzaRYIo8FsyxQtmBGSrohv+Go3cdvgl9U34ZUA oJ+aSl+Ry1oIBSYy17y5Tde0CB4Ip6zUIhXj3JoUApygIeYwH/QoHxfMMrU/NdympAQH4y A7cV+ESY4wfYq2Y0qqLGdrE4pyNXJ4c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1686038387; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=S7QocHAeNupt2yfSlCCiT1kcKEGTLlJpepX09+qPGXU=; b=DeBpFB5mRhqBDDEO0tLbvEYMY16DZDQfv+rz97rNVwSWhtVbjGxOMx3H33S4zjQY+qsfi8 X26cyBh+AJU4fRAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6871D13519; Tue, 6 Jun 2023 07:59:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id W4BzGXPnfmQWIAAAMHmgww (envelope-from ); Tue, 06 Jun 2023 07:59:47 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id F120EA0754; Tue, 6 Jun 2023 09:59:46 +0200 (CEST) Date: Tue, 6 Jun 2023 09:59:46 +0200 From: Jan Kara To: Zhang Yi Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yukuai3@huawei.com, chengzhihao1@huawei.com Subject: Re: [PATCH v2 5/6] jbd2: fix a race when checking checkpoint buffer busy Message-ID: <20230606075946.dj3ldknkoehr4agp@quack3> References: <20230606061447.1125036-1-yi.zhang@huaweicloud.com> <20230606061447.1125036-6-yi.zhang@huaweicloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230606061447.1125036-6-yi.zhang@huaweicloud.com> X-Spam-Status: No, score=-3.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Tue 06-06-23 14:14:46, Zhang Yi wrote: > From: Zhang Yi > > Before removing checkpoint buffer from the t_checkpoint_list, we have to > check both BH_Dirty and BH_Lock bits together to distinguish buffers > have not been or were being written back. But __cp_buffer_busy() checks > them separately, it first check lock state and then check dirty, the > window between these two checks could be raced by writing back > procedure, which locks buffer and clears buffer dirty before I/O > completes. So it cannot guarantee checkpointing buffers been written > back to disk if some error happens later. Finally, it may clean > checkpoint transactions and lead to inconsistent filesystem. > > jbd2_journal_forget() and __journal_try_to_free_buffer() also have the > same problem (journal_unmap_buffer() escape from this issue since it's > running under the buffer lock), so fix them through introducing a new > helper to try holding the buffer lock and remove really clean buffer. > > Link: https://bugzilla.kernel.org/show_bug.cgi?id=217490 > Cc: stable@vger.kernel.org > Suggested-by: Jan Kara > Signed-off-by: Zhang Yi Looks good. Feel free to add: Reviewed-by: Jan Kara Just a type correction below: > @@ -615,6 +619,34 @@ int __jbd2_journal_remove_checkpoint(struct journal_head *jh) > return 1; > } > > +/* > + * Check the checkpoint buffer and try to remove it from the checkpoint > + * list if it's clean. Returns -EBUSY if it is not clean, returns 1 if > + * it frees the transaction, 0 otherwise. > + * > + * This function is called with j_list_lock held. > + */ > +int jbd2_journal_try_remove_checkpoint(struct journal_head *jh) > +{ > + struct buffer_head *bh = jh2bh(jh); > + > + if (!trylock_buffer(bh)) > + return -EBUSY; > + if (buffer_dirty(bh)) { > + unlock_buffer(bh); > + return -EBUSY; > + } > + unlock_buffer(bh); > + > + /* > + * Buffer is clean and the IO has finished (we hold the buffer ^^^ held > + * lock) so the checkpoint is done. We can safely remove the > + * buffer from this transaction. > + */ > + JBUFFER_TRACE(jh, "remove from checkpoint list"); > + return __jbd2_journal_remove_checkpoint(jh); > +} Honza -- Jan Kara SUSE Labs, CR