Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1794415rdb; Mon, 9 Oct 2023 03:16:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYGTEM1MmLm2vTAhzjpcC4CsdJbP7T99z2ebfobrU/ZnrBRXgoMAMD+dJsFc57f5Dtw3/b X-Received: by 2002:a05:6830:4b2:b0:6c0:7bab:28ed with SMTP id l18-20020a05683004b200b006c07bab28edmr17019233otd.16.1696846578782; Mon, 09 Oct 2023 03:16:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696846578; cv=none; d=google.com; s=arc-20160816; b=j7qHZrLT5BX2RyzV8Vz6eyglg6Q5GFBxg8LrIgkRE/KIPA/Kta1O1BhWQMnKdtRMwm gmq2zZ32Y05rDFaepKRedEiFULuuqysfGfR5c1y/2ct6apVhkuDqFTxixeduST4C+nbd Jke8gZxUGJOc8AwGMpKtfWm82sliZzTaepMgb9wxmB+S3R18rBgmhWvA59FIAOCrdKKc AV0y2fh0YBays+kdW4fEmyexazB5PLxiOmnSbwOD5szIXE1yxW8bh959FYX4rEJMb4Gd 9s4GXNVdRMnFbyjfmnVg+VUJNJ4niOKrD8a1ngAQGEtGCQRivTUFaX2Dkvkng8EaC31m XUgQ== 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=9aFHFIVYD+PckYoucQFFA7Q682WFJMhzaZvRQ/S9EPY=; fh=IhHVPIuFZerWU/stTGttKTDgIEoKagnr+kKLwv2w63I=; b=blp36V7lYScB0Yo287IMqiNllBi9IWaBZs5oQumcWvx4lM98Rx6gmU+i7yjcV/4c5y aDWl59IvbF6QtDHEYncgYPjYFnd6VVNf7o1MWBf6g46DeEWnExC7zYb1GEw/sjQKtxIV OHNsS/PD114yHkFLJ7RlIhoO+IdebrrTimhH2oEudCGNAO53vtTPm/IRKOzRZBvKTsp0 EKQ+U1E5tytyDx6QoxEZuknxo39M+QFnCAzmeOigTc/jpubM4CoX4/F4ntOlPV+NJDfU PH7Ira5uGomS1maBef73rUnTGSOEa6XExcYMZ/DRlM8HSwzwzcP9j4S0j+1Sc/T9Nuz9 scLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=gsQYRTEb; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=qGEvzez2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id k187-20020a6324c4000000b00578b21f1890si9391589pgk.294.2023.10.09.03.16.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 03:16:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=gsQYRTEb; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=qGEvzez2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 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 howler.vger.email (Postfix) with ESMTP id 05CC680439A5; Mon, 9 Oct 2023 03:16:16 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346118AbjJIKP4 (ORCPT + 99 others); Mon, 9 Oct 2023 06:15:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346061AbjJIKPy (ORCPT ); Mon, 9 Oct 2023 06:15:54 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31A7D9F; Mon, 9 Oct 2023 03:15:52 -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-out1.suse.de (Postfix) with ESMTPS id D093C210EA; Mon, 9 Oct 2023 10:15:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1696846550; 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=9aFHFIVYD+PckYoucQFFA7Q682WFJMhzaZvRQ/S9EPY=; b=gsQYRTEb0njWM9TpyXer3r9WyXV9IEVCnaR6yBLYDXzmPah64iYyEWy0schTQL56j382wU ebeI+dR4WlXBngIzleMTZ6eFCtrOhabfilROoT2ZMSGNUw7hTXLu57wireUa9RtvXxxSBk IXpMHR1y6fiWpE3v0Rh2Thpix3jr7T8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1696846550; 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=9aFHFIVYD+PckYoucQFFA7Q682WFJMhzaZvRQ/S9EPY=; b=qGEvzez2mF/FkU4Ol42KQIlRTDDiii7TYnAWg2gFBLvMprviOvhVfjy0GNDwi4Ha8aMADD fayHZjqOhIiP06DQ== 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 BE1B413905; Mon, 9 Oct 2023 10:15:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b4xZLtbSI2WNeQAAMHmgww (envelope-from ); Mon, 09 Oct 2023 10:15:50 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 29F17A04B2; Mon, 9 Oct 2023 12:15:50 +0200 (CEST) Date: Mon, 9 Oct 2023 12:15:50 +0200 From: Jan Kara To: Mirsad Todorovac Cc: Matthew Wilcox , Yury Norov , 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: <20231009101550.pqnkrp5cp5zbr3lr@quack3> References: <20230918094116.2mgquyxhnxcawxfu@quack3> <22ca3ad4-42ef-43bc-51d0-78aaf274977b@alu.unizg.hr> <20230918113840.h3mmnuyer44e5bc5@quack3> <20230918155403.ylhfdbscgw6yek6p@quack3> <2c7f2acd-ef37-4504-a0e3-f74b66c455ec@alu.unizg.hr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2c7f2acd-ef37-4504-a0e3-f74b66c455ec@alu.unizg.hr> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Mon, 09 Oct 2023 03:16:16 -0700 (PDT) X-Spam-Level: ** On Fri 06-10-23 16:39:54, Mirsad Todorovac wrote: > On 9/19/2023 6:20 AM, Matthew Wilcox wrote: > > 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. > > Hi Mr. Wilcox, > > Do you think we should submit a formal patch for this data-race? So I did some benchmarking with various GCC versions and the truth is that READ_ONCE() does affect code generation a bit (although the original code does not refetch the value from memory). As a result my benchmarks show the bit searching functions are about 2% slower. This is not much but it is stupid to cause a performance regression due to non-issue. I'm trying to get some compiler guys look into this whether we can improve it somehow... Honza -- Jan Kara SUSE Labs, CR