Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp476992pxf; Thu, 11 Mar 2021 07:56:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmO28zS4emtAQOxRlq5z/f5f73X7QDIyBEly2zmYXueNW9FmiNMoxzDPSgGghEouOHMPqO X-Received: by 2002:aa7:cd54:: with SMTP id v20mr9311233edw.80.1615478180772; Thu, 11 Mar 2021 07:56:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615478180; cv=none; d=google.com; s=arc-20160816; b=OCWqXwMxQfGxjMGJs1HHUhpqje/DFPle8LcsyJeIlukM00amqNy/Acfna55CNcLcMk 8iMeIRg1UbEpoyS2Bp5UmxsMT37i5jObgugGkCGp2W2s7cWXaTxXC+c+sj+qhc+8PXRM HG49wdenPPlsU7iY6D8eNXO5p2hOg80jLQ3EHDezJBaE/55uUfMzLOI7AAYieXmTw7vR Y9fO6yEfU22UMzutmYAxnRHnYVGBMKjzvst2CjhjC4cYtK61zB728Z7qZqHxK+oDGcjs hx/e5Zw6WwQkU6+0Ss3ljc/I3RZKG0q09DBRTp2YxZzUNs2xqpU8oMmMNZtTE2Tt/Q6/ roIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=yALvACLbG4vrfUUx3qZqeyzSfVcl9s+hAiG4U+bMuHc=; b=QRWKznr9wK0h7e53GbbNQKcH65n/bx/Oxc6D14KjZmqlMAqqM+tJfGluHwjsFkpCk5 8mfk664sXsBfsH69aCsq9dadm8OqKbYv5EGvr4tWNLhxbgeNtKiGBmGAEUS1Ozusp8Ic B+2HO5SZWet3hb5IczZ0QmE78B+3tXvhlQxDn3e367gqJaLAi7jo5iuKvbvK6VZx1Jbg P3M73+szToB7dVkGoHj4MNyHWZSIbzoA9XTTnhFgRfSwyo8wPBfWG5Rjy3xcueRm63Xd uE68Adxp4uwQAUR98mSprkrescBsPlYOr2aJxtkbYjQAYRG/NSh92o40IXHCYzVr2Is8 wpcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=swKJ+cXt; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k13si1883209ejc.452.2021.03.11.07.55.56; Thu, 11 Mar 2021 07:56:20 -0800 (PST) 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; dkim=pass header.i=@google.com header.s=20161025 header.b=swKJ+cXt; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234329AbhCKPzH (ORCPT + 99 others); Thu, 11 Mar 2021 10:55:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234383AbhCKPy5 (ORCPT ); Thu, 11 Mar 2021 10:54:57 -0500 Received: from mail-ot1-x32c.google.com (mail-ot1-x32c.google.com [IPv6:2607:f8b0:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E73C3C061760 for ; Thu, 11 Mar 2021 07:54:56 -0800 (PST) Received: by mail-ot1-x32c.google.com with SMTP id f8so1883227otp.8 for ; Thu, 11 Mar 2021 07:54:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=yALvACLbG4vrfUUx3qZqeyzSfVcl9s+hAiG4U+bMuHc=; b=swKJ+cXtjqjUiqBziIbCvK1W0Jqtxsmb0JtDejFHsmeoRUzMlbqcwAtEhWCA1WLZsZ RH60dBjjXVu4l8heRsjnmMDBjVX7KwWd73gdXeI+E9lbeYSp1mXN+DZ4BaslqifvVqZR w6nemR8fVkgXXZCOKjQhlcE9GrZ/vDcRzDoCQI8h9GZKjcUgLTQSODn9Gd8+bVdJs3F4 b0kGBA9E4OBgzpT+84Cdm1hSQPvG70L6Mj4R8kka8qPEXqwEV2+P10wQf4TimR+WDVvE UpbaJ4tyuuxVXSmhtK0mpHTxJQAUydEl4PcdWheT6xpmjJK8WnDias+aZNUktH/L1RPV Z94w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=yALvACLbG4vrfUUx3qZqeyzSfVcl9s+hAiG4U+bMuHc=; b=diIHc3HDthRmiB5Gnn6QUcgpDnphTLUUcZMOnFKpE5m1IR7o8EsN670nu64zidlxch gpF+SDJY/764y9xAF6Leey+muVOiyxRX571/gT7FNVJdpXTrweHSIlNZigXUGEXx31jv 3qTQJi3reDdw4SgnGZQUycaclRWCdA0CyUXLwHZWfgdqaiK12p5LTqrtoGZdGkqBeOAb depnIMlPCMvjStNAx94mrE66xOelFuedGVX9I3D46Se7Gq+iAVLi9mw33KoYqA+1j8LJ 4MeT3qXdkVkHgbZeBdzzhYbTaFb9Gv/UQU7LXxYvXfcdEAbdAH/CwG/2thVnJ+6SE9qL CI9A== X-Gm-Message-State: AOAM531S1aN239+DoQInxV2KvJsNDaaB2yxAzNfnfZwHgLr2055a9Xxi hpj9VDcAmQ0cybvsCB0ZWV5nfzgOshSWR45Xa9z1kQ== X-Received: by 2002:a9d:644a:: with SMTP id m10mr7632608otl.233.1615478096124; Thu, 11 Mar 2021 07:54:56 -0800 (PST) MIME-Version: 1.0 References: <0000000000008de88005bd40ac36@google.com> <20210311142503.GA31816@quack2.suse.cz> In-Reply-To: From: Marco Elver Date: Thu, 11 Mar 2021 16:54:43 +0100 Message-ID: Subject: Re: [syzbot] KCSAN: data-race in start_this_handle / start_this_handle To: "Theodore Ts'o" Cc: Dmitry Vyukov , Jan Kara , Tetsuo Handa , syzbot , Jan Kara , linux-ext4@vger.kernel.org, LKML , syzkaller-bugs , "Paul E. McKenney" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org +Cc Paul On Thu, 11 Mar 2021 at 16:30, Theodore Ts'o wrote: > > On Thu, Mar 11, 2021 at 04:08:30PM +0100, Marco Elver wrote: > > If the outcome of the check does not affect correctness and the code is > > entirely fault tolerant to the precise value being read, then a > > data_race(!journal->j_running_transaction) marking here would be fine. > > So a very common coding pattern is to check a value w/o the lock, and > if it looks like we might need to check *with* a lock, we'll grab the > lock and recheck. Does KCSAN understand that this sort of thing is > safe automatically? It doesn't -- these are concurrency patterns that go way beyond the scope of a data race detector. The main problem, as always with such patterns, is that in one case it seems fine, yet in the next it isn't. > In thie particular case, it's a bit more complicated than that; we're > checking a value, and then allocating memory, grabbing the spin lock, > and then re-checking the value, so we don't have to drop the spinlock, > allocate the memory, grab the lock again, and then rechecking the > value. So even if KCSAN catches the simpler case as described above, > we still might need to explicitly mark the data_race explicitly. This seems like a variation of double-checked locking. > But the more we could have the compiler automatically figure out > things without needing an explicit tag, it would seem to me that this > would be better, since manual tagging is going to be more error-prone. What you're alluding to here would go much further than a data race detector ("data race" is still just defined by the memory model). The wish that there was a static analysis tool that would automatically understand the "concurrency semantics as intended by the developer" is something that'd be nice to have, but just doesn't seem realistic. Because how can a tool tell what the developer intended, without input from that developer? If there's worry marking accesses is error-prone, then that might be a signal that the concurrency design is too complex (or the developer hasn't considered all cases). For that reason, we need to mark accesses to tell the compiler and tooling where to expect concurrency, so that 1) the compiler generates correct code, and 2) tooling such as KCSAN can double-check what the developer intended is actually what's happening. Thanks, -- Marco