Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp335878pxf; Wed, 7 Apr 2021 00:13:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzivGA8B3/lpvhiJkQMD8uLpAHF5jUzopp4Em7fz+QHtolLN833YDfLzurGQMJTpOYMrnOH X-Received: by 2002:a17:906:8a61:: with SMTP id hy1mr2075763ejc.59.1617779607099; Wed, 07 Apr 2021 00:13:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617779607; cv=none; d=google.com; s=arc-20160816; b=o5CNcphb+0xMHc/RSWxyxoHIz8xMMLMPRVPX0Dci1rCIurG6r6r2eAFoZbxEZhl0WP lte+h+Zu9DX21ai6dRyc3lupwcWplVruqox+B4A8iAq5AZCY+Zgm9BTYooiCd2J7YNL9 3+a1IJlBZClV0a+mWI42B5tizmbuOp7OvtgnamkCeP1Gfac/SYlv6x8Tnm69h15abw/M 9WmAfSlMAsr7tx2dLBkL4MPBDsEWFFFjzHNzTbQhysUUbWD3V/9Na4eFkZU9qCT5BRwf sAA1O91+tD0j2qRIBmE1r+adTYHhp3xP76P01ak5xwpzeElGpt1046lFmxgtbOgQnI3w PhVA== 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=CoxH6BucWGM3qyU7cf4IBcCH/3LSnE8bGhW7OGfHyf4=; b=CFXwoleRpBwY7CV7pJ6JUWw+1uXxdQFqcF4HH1vXdn4EUrHjUb/jjzh087qvl4Iejb VHlGsp4y/alBMdPvY5SYmXlIOdxhSscESHzzaJM2qYWR9VX0tu17jMygLUsiTgJncfoq aAmjBWLFA9Ep1RJGTStpj9Xk0SDPycX24ZaQZnEIXxi4/XCs8Z+Iu6mzHGtT8uplWpOc 016+5HJmAcYTZxMx/PGnwqdrEtm79nsstzIxKwEKfZbTwA7j0avgyQN9M1f4Da8dpG6j X3RICi/+HhReSv4ZewxA/3jpsEsEqbIeX37UevnPnOQzGMTqF8UoJBCcCjyfHl50kh8F SQCA== 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 j3si4760510edn.352.2021.04.07.00.13.03; Wed, 07 Apr 2021 00:13:27 -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 S234032AbhDFQSP (ORCPT + 99 others); Tue, 6 Apr 2021 12:18:15 -0400 Received: from mx2.suse.de ([195.135.220.15]:44606 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234686AbhDFQSN (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 30A8DB262; Tue, 6 Apr 2021 16:18:05 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id EDFC81F2B6A; Tue, 6 Apr 2021 18:18:04 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , Jan Kara , syzbot+30774a6acf6a2cf6d535@syzkaller.appspotmail.com Subject: [PATCH 1/2] ext4: Annotate data race in start_this_handle() Date: Tue, 6 Apr 2021 18:17:59 +0200 Message-Id: <20210406161804.20150-1-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 Access to journal->j_running_transaction is not protected by appropriate lock and thus is racy. We are well aware of that and the code handles the race properly. Just add a comment and data_race() annotation. Reported-by: syzbot+30774a6acf6a2cf6d535@syzkaller.appspotmail.com Signed-off-by: Jan Kara --- fs/jbd2/transaction.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c index 9396666b7314..398d1d9209e2 100644 --- a/fs/jbd2/transaction.c +++ b/fs/jbd2/transaction.c @@ -349,7 +349,12 @@ static int start_this_handle(journal_t *journal, handle_t *handle, } alloc_transaction: - if (!journal->j_running_transaction) { + /* + * This check is racy but it is just an optimization of allocating new + * transaction early if there are high chances we'll need it. If we + * guess wrong, we'll retry or free unused transaction. + */ + if (!data_race(journal->j_running_transaction)) { /* * If __GFP_FS is not present, then we may be being called from * inside the fs writeback layer, so we MUST NOT fail. -- 2.26.2