Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp335614pxf; Wed, 7 Apr 2021 00:13:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyx/COBJtMh7pfVVHUyuAcLAevoNYwG/PtbJoGTychXkt2nZiwc7GugTlI/CfCoaJIcfSxN X-Received: by 2002:a05:6402:40c9:: with SMTP id z9mr2744321edb.24.1617779580209; Wed, 07 Apr 2021 00:13:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617779580; cv=none; d=google.com; s=arc-20160816; b=VdNKoYxNpkKyifC3++mHLv+wZP2/C7m49HTnf/DAHaKWia1lXObDvgKjDcIdm1CuE/ +z9xMefufPaD189mxDfJK91azRUWlqG66uorOgO3pnvwRsgOWi4ACu/MhQpM5kMZbm9H Oo/BVtSRtoBrc60CZQKXG/XmaGGcUcTmb+GYrY3B5WzlszqYaZE8tjuzRv/dLSl2jweG /NshOeqL7VuKgx5DIgfDb32BfDyzYwiAuyZejGo9GMEpKWALgiH8+qQFDXmHE96vo/DM COJBYNy6TfE26HkvvKVlhMSuu07W+nGVuwwy3vWATpMt+bfyww9wRd8JRRjpCR1aaxyQ XisA== 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; bh=r+atWqlBJ8kv/uNZ9bULm657330Jf0SD+vT09VrYLDE=; b=WkjGaw0WKnx8M5C+g3oH2hVZEAlkmpbTfsYXmFYvx1QwPEVlcfMBTERXJlANw5TJFU wdJhDbSyW/Msl9utkgmrddsQK97H+WUmnBEhhDGKOPXn1BMXauox0sjAHxNA7Vbf4x1s Xve6YNGrkjoDhtMgJW6TQunu9BGPo3QznT+Jnu4GcXUbokS2ykbtnodpcypDOtuPrww2 8TiXRynn8uA/SZHVMNEbvyjEsL/Xym8rgnRjAeO7wrIwrAK2K4G1g5ZV1e9MZoUaJ9cG vhESQyXQZa7vFu8XRK5nOI0dZ/czUi77mDIIbcIDmwrMV+UtUcwooyBYRR85yvF7NNI6 2NDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cb25si8539686edb.246.2021.04.07.00.12.35; Wed, 07 Apr 2021 00:13:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233688AbhDFQSO (ORCPT + 99 others); Tue, 6 Apr 2021 12:18:14 -0400 Received: from mx2.suse.de ([195.135.220.15]:44598 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234032AbhDFQSN (ORCPT ); Tue, 6 Apr 2021 12:18:13 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 2E370B21D; Tue, 6 Apr 2021 16:18:05 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id EFED81F2C52; Tue, 6 Apr 2021 18:18:04 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , Jan Kara , Hao Sun Subject: [PATCH 2/2] ext4: Annotate data race in jbd2_journal_dirty_metadata() Date: Tue, 6 Apr 2021 18:18:00 +0200 Message-Id: <20210406161804.20150-2-jack@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210406161605.2504-1-jack@suse.cz> References: <20210406161605.2504-1-jack@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Assertion checks in jbd2_journal_dirty_metadata() are known to be racy but we don't want to be grabbing locks just for them. We thus recheck them under b_state_lock only if it looks like they would fail. Annotate the checks with data_race(). Reported-by: Hao Sun Signed-off-by: Jan Kara --- fs/jbd2/transaction.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 398d1d9209e2..e8fc45fd751f 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -1479,8 +1479,8 @@ int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh) * crucial to catch bugs so let's do a reliable check until the * lockless handling is fully proven. */ - if (jh->b_transaction != transaction && - jh->b_next_transaction != transaction) { + if (data_race(jh->b_transaction != transaction && + jh->b_next_transaction != transaction)) { spin_lock(&jh->b_state_lock); J_ASSERT_JH(jh, jh->b_transaction == transaction || jh->b_next_transaction == transaction); @@ -1488,8 +1488,8 @@ int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh) } if (jh->b_modified == 1) { /* If it's in our transaction it must be in BJ_Metadata list. */ - if (jh->b_transaction == transaction && - jh->b_jlist != BJ_Metadata) { + if (data_race(jh->b_transaction == transaction && + jh->b_jlist != BJ_Metadata)) { spin_lock(&jh->b_state_lock); if (jh->b_transaction == transaction && jh->b_jlist != BJ_Metadata) -- 2.26.2