Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp471654rdb; Tue, 19 Sep 2023 00:25:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG5fWEJKPjOR7AtnrWpJUvH7hf0p9huGtwaJqXmKB7j5HRe9lwfc6Q36lsdilW9RP9t8CEF X-Received: by 2002:a05:6870:7a9:b0:1bc:3ca:f653 with SMTP id en41-20020a05687007a900b001bc03caf653mr14530364oab.45.1695108344462; Tue, 19 Sep 2023 00:25:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695108344; cv=none; d=google.com; s=arc-20160816; b=l6ZSaZflId4ivPT5PfClQ0UrTLePyFIQkj3/BwbUy6bElAAi+UzaN79FMKYp/OtCF7 84WRcaiu7EeIK+Hvzg5+RLGkg/u1Dqf7w745AEwEP3x74sYMtO7an2bHLlGOrhA2COFI u3ic/4xI7JhcWHkvy24YNSEy7WJDhl6diQ69cgCuSNRxfLauFkO9R5NTKa1ppzAfBOQt +VLFbBe4Va974qI2hZX/nO94V2O2TND0qmVrKxkDhSIwygHZx7HaRXej1Hce85Q/o+ag xusULQN5/NXeEQC6AoxLMx+sSAWio14ASbbwV44iRjlSLXLRT/+dl1YODSK3xfT6DPQH skkg== 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=rkouqG7ezneLR9fXmWK2z8oVOJc/7J+HE9nJ0wqC52Y=; fh=nxjE6nsLN0yJKFe8Gv3S9WhQQNKYO8XrNXNYMk/dI4k=; b=CNhwb8NQgl7eZjGC7YbkrtpIIpw3si48gpzTA6Zy5x+/M7RqF6Iz8gaGcEbtCbzau/ kDqbLdGgwrZLBgxAvaS9HS9fD9sRLSiLBRq0CH5Mq3KXHi08+4Eev5a6dQRLE234BM8w DWDhDqjHIn+SHWWEs+GJDFzFUZVsGy95j2THMau7T8rsI/hjRpCAQMhQiHHHLg4JuQeT p3UzYDsxBUqGGa44wmeeQ/fOOGLaozgQLsGkCvfFwE095iDiAz3llb2k2eF2AaeAn4G6 0Z/Se7l50Kh13Qbcne4IlEo37HxBb03clQ0eWBt5/ZX0dXLmHyzUPqlIlPO2uY5QJYNC Xm4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=plJiV8FD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id d185-20020a6336c2000000b00574006acf67si9375316pga.17.2023.09.19.00.25.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 00:25:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=plJiV8FD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 085B2823F50E; Mon, 18 Sep 2023 21:20:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231358AbjISEUc (ORCPT + 99 others); Tue, 19 Sep 2023 00:20:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231135AbjISEUa (ORCPT ); Tue, 19 Sep 2023 00:20:30 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 760558F; Mon, 18 Sep 2023 21:20:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=rkouqG7ezneLR9fXmWK2z8oVOJc/7J+HE9nJ0wqC52Y=; b=plJiV8FDPUDBI4qF+NloBKEGkW sjP88Q+Je4DqE07zwn4QkJTvUIW2BTfWyUsIlTh72QHODMmxjmJhITZPCtOE4E9iLra/UiKRYpdX7 FVDc3aUxetTxkSiJF0WfxpVr7bg1Ki8cFYt6qtZ1OWGKp589GCmw4YBFSaYs7KTT+PkbyytSgdb8s 4QbdhLWcjJxfuLepxUEy+ci9po9r0SAaqWcYRzVVBFaNj6TKS5iPgLFKybZ3cz3THYkWOE58WRv0N J1Ytx/vzXVxEty3t7Eq2ZySvC4nZKI9hI9Yhtj8B0QISswaK7uD6bAGKQHInb1uGnRYWcYJiB2S1D KN0/6UTA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qiSDh-00F5MH-Ue; Tue, 19 Sep 2023 04:20:18 +0000 Date: Tue, 19 Sep 2023 05:20:17 +0100 From: Matthew Wilcox To: Yury Norov Cc: Mirsad Todorovac , Jan Kara , Philipp Stanner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Mason , Andrew Morton , Josef Bacik , David Sterba , linux-btrfs@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v1 1/1] xarray: fix the data-race in xas_find_chunk() by using READ_ONCE() Message-ID: References: <20230918044739.29782-1-mirsad.todorovac@alu.unizg.hr> <20230918094116.2mgquyxhnxcawxfu@quack3> <22ca3ad4-42ef-43bc-51d0-78aaf274977b@alu.unizg.hr> <20230918113840.h3mmnuyer44e5bc5@quack3> <20230918155403.ylhfdbscgw6yek6p@quack3> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Mon, 18 Sep 2023 21:20:46 -0700 (PDT) On Mon, Sep 18, 2023 at 11:56:36AM -0700, Yury Norov wrote: > Guys, I lost the track of the conversation. In the other email Mirsad > said: > Which was the basic reason in the first place for all this, because something changed > data from underneath our fingers .. > > It sounds clearly to me that this is a bug in xarray, *revealed* by > find_next_bit() function. But later in discussion you're trying to 'fix' > find_*_bit(), like if find_bit() corrupted the bitmap, but it's not. No, you're really confused. That happens. KCSAN is looking for concurrency bugs. That is, does another thread mutate the data "while" we're reading it. It does that by reading the data, delaying for a few instructions and reading it again. If it changed, clearly there's a race. That does not mean there's a bug! Some races are innocuous. Many races are innocuous! The problem is that compilers sometimes get overly clever and don't do the obvious thing you ask them to do. READ_ONCE() serves two functions here; one is that it tells the compiler not to try anything fancy, and the other is that it tells KCSAN to not bother instrumenting this load; no load-delay-reload. > In previous email Jan said: > for any sane compiler the generated assembly with & without READ_ONCE() > will be exactly the same. > > If the code generated with and without READ_ONCE() is the same, the > behavior would be the same, right? If you see the difference, the code > should differ. Hopefully now you understand why this argument is wrong ... > You say that READ_ONCE() in find_bit() 'fixes' 200 KCSAN BUG warnings. To > me it sounds like hiding the problems instead of fixing. If there's a race > between writing and reading bitmaps, it should be fixed properly by > adding an appropriate serialization mechanism. Shutting Kcsan up with > READ_ONCE() here and there is exactly the opposite path to the right direction. Counterpoint: generally bitmaps are modified with set_bit() which actually is atomic. We define so many bitmap things as being atomic already, it doesn't feel like making find_bit() "must be protected" as a useful use of time. But hey, maybe I'm wrong. Mirsad, can you send Yury the bug reports for find_bit and friends, and Yury can take the time to dig through them and see if there are any real races in that mess? > Every READ_ONCE must be paired with WRITE_ONCE, just like atomic > reads/writes or spin locks/unlocks. Having that in mind, adding > READ_ONCE() in find_bit() requires adding it to every bitmap function > out there. And this is, as I said before, would be an overhead for > most users. I don't believe you. Telling the compiler to stop trying to be clever rarely results in a performance loss.