Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp308697rdb; Mon, 18 Sep 2023 16:17:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGIdrAjNoq3ub99MUzHMLHMGI8DzR9bD6LH+serBDPPoKO4YqglY6X/iYQZ+T5AvUAfl/Ev X-Received: by 2002:a17:903:1c8:b0:1c3:9544:cf63 with SMTP id e8-20020a17090301c800b001c39544cf63mr12000477plh.23.1695079044435; Mon, 18 Sep 2023 16:17:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695079044; cv=none; d=google.com; s=arc-20160816; b=SPeJgrLmCEJ2nxk25rF1BPYP2kHSMipJdH0a74gXfX1pdtYJaIkpZ8s96LH0rsWg+0 uCvnTwmgjm6trHjfIkf1Y/G0wyXjBX1aza6m/yT6szTRBfEaYU1TIEjsfsCtfylxVwjS 22BjXJeYIwvjpRhW2Vjzf3zRcze61g9SV870OKoHAd0QNe8GwdMNbhcktGwYkrTXYEFH nJpeNQ6WZ4Q1N7hbgZD68yDMrpUCoOob7dkhaSq0v+PzjZvI6eK2EiDqrdhHT7TlUL9U 5QE9obyB6+9LlplZtsK+DI6FZN4kRuYzvxlg21XeuRIkhiGspzJJ+mPMN8m7HRzPSR+s tc1Q== 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=7Pyv4oO8rrHEd4wiz5Er/b8SPSG4uhIlASx2HO5yMlQ=; fh=vOrB+ng56urRlZvxzM/P+hZ3jw50sr7pjKla16B/wDg=; b=sGbfiiU7U5UXnEnTBJq7iMSlSof1n1lmQAS89112LyiB3hajrvyR/sWpxyKK4BnXbi b8vhfWYN9qL0ehjolx1rfcHv+0WyJIPd35h1KC+YPbzT98IJfTiVvdixm+QPJaAz4tJq Myr7SmEt5c7UrYu2QHp2tWu901UPcXlXLTkKCU/DtU+C73Z8cPDxDgHy6wJ+x5GklYl/ Epo5LQs9vLuFo1HJiB29wyUBj27MM8hmkahEjCI8Yr2A5LyYoCPQoltfeR9nOcrzenUJ /VAZbaiRJgIR75rAg6KuGxa347tJytoYHDB3KZjqkEy6sIP1gA9A8IxDixpGR4i9smj6 wGlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fiAIwzno; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id z12-20020a1709027e8c00b001c45291b6ebsi4947029pla.272.2023.09.18.16.17.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 16:17:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=fiAIwzno; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B1754813CD8D; Mon, 18 Sep 2023 08:34:56 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229451AbjIRPeS (ORCPT + 99 others); Mon, 18 Sep 2023 11:34:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229822AbjIRPeE (ORCPT ); Mon, 18 Sep 2023 11:34:04 -0400 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D5F0CF8; Mon, 18 Sep 2023 08:29:53 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-59c0d002081so30586957b3.2; Mon, 18 Sep 2023 08:29:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695050777; x=1695655577; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=7Pyv4oO8rrHEd4wiz5Er/b8SPSG4uhIlASx2HO5yMlQ=; b=fiAIwznoeOaPa8f54jwL7chi2HiACFejgzjdsMYYCi287WDijxzyWrr6GJVNcAOz3s pvyB0kL9KQ72Ggx08iaGDxrhoopTh6Mf0lfBlt11FkGQHwbXg16U2SbOWt6oOh1jk8FL l+OUfcIZ6LRxdkgkptqJ3nLkuYvmciJH9ve7clBSx5DtNgCB9nyqrtK9nmeT7LTetVWx sRDqJPHlNKykyb1Y9+ReoxumSVUbrZBD0iZXm0C0+2Sx778am2/KjuRhDGPRRiS1HLOH DCnsRtRofIulQz1MXV/ySRftWxXyJ6OX4UHiADJjXk5psCZT8+qE2CESeDYQfaGQINGf viVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695050777; x=1695655577; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=7Pyv4oO8rrHEd4wiz5Er/b8SPSG4uhIlASx2HO5yMlQ=; b=h11kBMIM/fRe8oEg8XofbJahS8BaRSKYzvy8oK4mZlE3FhOzFO9JmoZNAKzmfRSNGv jJTIoaOtg0NAFvtQGqBOM6aUTdMLOmlMfwQmSLuEk6yRsbd5bgBR6i9bj3IxZ7+ctU7e lQwxfH6j4GNIu7CcSGT6oU1Q5meMdS5lLucehpUyaGvvXh7NwdrWOFk5dSp8O6jMVjT5 7Vyxxl8L4cZxHU2xO+D3k6Jxr8YC/o++jolF1KB0rAtPfKnG+fR5hHNfEhERYwcEe7An DJU8qk4sa6rKjfkIk0cz1UWp7bX9mbw8U9eZnrR3Ey0vo75PmARZBwepcdVQq51Oxhii RLGQ== X-Gm-Message-State: AOJu0YyTKNCvZky/k0nFGMxCDS5Xz3OwHnFX9ax/YFJwzuk4/P5kAYiu OecL5AKc1d24k/qvps5ECgL3uAhbQxo= X-Received: by 2002:a6b:dc0c:0:b0:795:13ea:477a with SMTP id s12-20020a6bdc0c000000b0079513ea477amr11908098ioc.8.1695049290863; Mon, 18 Sep 2023 08:01:30 -0700 (PDT) Received: from localhost ([216.228.127.130]) by smtp.gmail.com with ESMTPSA id h2-20020a6b7a02000000b00786aa1eb582sm2818737iom.31.2023.09.18.08.01.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Sep 2023 08:01:29 -0700 (PDT) Date: Mon, 18 Sep 2023 07:59:03 -0700 From: Yury Norov To: Mirsad Todorovac Cc: Jan Kara , Philipp Stanner , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Matthew Wilcox , 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 18 Sep 2023 08:34:56 -0700 (PDT) On Mon, Sep 18, 2023 at 02:46:02PM +0200, Mirsad Todorovac wrote: ... > Ah, I see. This is definitely not good. But I managed to fix and test the find_next_bit() > family, but this seems that simply > > ------------------------------------------- > include/linux/xarray.h | 8 -------- > 1 file changed, 8 deletions(-) > > diff --git a/include/linux/xarray.h b/include/linux/xarray.h > index 1715fd322d62..89918b65b00d 100644 > --- a/include/linux/xarray.h > +++ b/include/linux/xarray.h > @@ -1718,14 +1718,6 @@ static inline unsigned int xas_find_chunk(struct xa_state *xas, bool advance, > if (advance) > offset++; > - if (XA_CHUNK_SIZE == BITS_PER_LONG) { > - if (offset < XA_CHUNK_SIZE) { > - unsigned long data = READ_ONCE(*addr) & (~0UL << offset); > - if (data) > - return __ffs(data); > - } > - return XA_CHUNK_SIZE; > - } > return find_next_bit(addr, XA_CHUNK_SIZE, offset); > } This looks correct. As per my understanding, the removed part is the 1-word bitmap optimization for find_next_bit. If so, it's not needed because find_next_bit() bears this optimization itself. ... > -------------------------------------------------------- > lib/find_bit.c | 33 +++++++++++++++++---------------- > 1 file changed, 17 insertions(+), 16 deletions(-) > > diff --git a/lib/find_bit.c b/lib/find_bit.c > index 32f99e9a670e..56244e4f744e 100644 > --- a/lib/find_bit.c > +++ b/lib/find_bit.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > /* > * Common helper for find_bit() function family > @@ -98,7 +99,7 @@ out: \ > */ > unsigned long _find_first_bit(const unsigned long *addr, unsigned long size) > { > - return FIND_FIRST_BIT(addr[idx], /* nop */, size); > + return FIND_FIRST_BIT(READ_ONCE(addr[idx]), /* nop */, size); > } > EXPORT_SYMBOL(_find_first_bit); > #endif ... That doesn't look correct. READ_ONCE() implies that there's another thread modifying the bitmap concurrently. This is not the true for vast majority of bitmap API users, and I expect that forcing READ_ONCE() would affect performance for them. Bitmap functions, with a few rare exceptions like set_bit(), are not thread-safe and require users to perform locking/synchronization where needed. If you really need READ_ONCE, I think it's better to implement a new flavor of the function(s) separately, like: find_first_bit_read_once() Thanks, Yury