Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2415801imn; Tue, 2 Aug 2022 01:48:05 -0700 (PDT) X-Google-Smtp-Source: AA6agR7uVJCY8thRXecmuUP+4isYsyhAWqUTyKfH+r8tGGkOV4M7TK8OmAYf1W5q+bIV8SDCQGWG X-Received: by 2002:a05:6402:3552:b0:43d:a57d:22e9 with SMTP id f18-20020a056402355200b0043da57d22e9mr8567639edd.119.1659430085320; Tue, 02 Aug 2022 01:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659430085; cv=none; d=google.com; s=arc-20160816; b=m7RpRDUY0JPpx9L1yNuI5zRjrXo/qfRPQ+AYzF/GtjGg8fNR+pmD4SzuqHq5OG3MUI WkGqIknRjMjU1HeDHP6kKvuUCQTw3DOdqnEFUG33F1+OS7nuPPlB4q3pLw1YbHVIIEWr /nspVFpiDtyBgc96NlbKHlTXQviZSCDjDELsVtN3YtLnn7xgi73Hq4g6/kiC5zDGqwtf Ytr8MCyyawzRwIZaxhOEGySa5COiJJLuzeD3WqNII1PwF6sTSugUTaptjqpQ4qqeqrW7 G0Pwq4Qe7PGGoN97N3kY3npR8wCv4ehCs65wTzq/xBUe2DO1+aOP9MHlq9rLL7o105VQ 2HnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=XdXyRdLDRgvCD5A19w2gAaDdpb2v1bnWEHS6EhMm4E0=; b=jnUJWq1jBP8wvRXENXgV8BSAVKQ2QTfBSKw0kotwgwkMYB7PDMTCLMppcioCHfvWq8 i0WlqE2ILm6ql0LBTy7wDilUBKUuiCnDF8Gv3vnk2E9WXlbHxcZEVun1neO0u4JMt3l9 +ovYuILcz7NV1r0rdTZrN18ocRBpbMLsDkhlraDpfEbF53qaYZNV0GoJFTKdQE4LTsB2 ibk0dgx5PXEv3AADuf7chHHBsPjySTlfJxnEP/mTLPT6Hd4PvEPQj/f9p5OJHYJfmjTE GV0YTbSCvqVwJP6+2QMVOE4Lm0V6jLANTHlMnNQDRf1F8O8o3lSOL7KdHngtPwmACWhX jgRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FiDO17vW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hg5-20020a1709072cc500b0072af3bdf59esi13648793ejc.3.2022.08.02.01.47.40; Tue, 02 Aug 2022 01:48:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FiDO17vW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236433AbiHBIk2 (ORCPT + 99 others); Tue, 2 Aug 2022 04:40:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233888AbiHBIk0 (ORCPT ); Tue, 2 Aug 2022 04:40:26 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B3AFDF2E; Tue, 2 Aug 2022 01:40:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 643AC60B2F; Tue, 2 Aug 2022 08:40:24 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60EFDC433C1; Tue, 2 Aug 2022 08:40:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659429623; bh=rbPayMUNRP+UW1L0745xa3YzYtRl5oydAMq3hSkE6vw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=FiDO17vWUmS1Z8jtkPzKkyvSaZpJ7ba8MmIocSTM9w2aklYKg5e7Wtw3u7w/f6+VK LIziq0FVkDYgIjPpk94igb3yFJ0bXIrT7HfJwt70GEfDcfHDcHotw+CLO9ersYdL8L mMQzlGBgQUFgV6rO4cfbPvjVWjR6d8wmQ0c4jrTSQl8kjn2SFxRe/DXrJGyGwlOZE8 RuTcY4uuQiERasm7s6MphVD+hXI84He3HRqVjv4qHS3+BKkG0b5+kieiq5/8BRECqW x6os6UN2aF3IM5cfZihjQekTnjpK9VulnTmFrbdhCvGVnyEMAp5hUKPaYqqyP8gx1+ KyNA2GQp+KCRw== Date: Tue, 2 Aug 2022 09:40:16 +0100 From: Will Deacon To: Mikulas Patocka Cc: Linus Torvalds , "Paul E. McKenney" , Ard Biesheuvel , Alexander Viro , Alan Stern , Andrea Parri , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Daniel Lustig , Joel Fernandes , Linux Kernel Mailing List , linux-arch , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v4 1/2] introduce test_bit_acquire and use it in wait_on_bit Message-ID: <20220802084015.GB26962@willie-the-truck> References: <20220801155421.GB26280@willie-the-truck> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Mon, Aug 01, 2022 at 12:12:47PM -0400, Mikulas Patocka wrote: > On Mon, 1 Aug 2022, Will Deacon wrote: > > On Mon, Aug 01, 2022 at 06:42:15AM -0400, Mikulas Patocka wrote: > > > > > Index: linux-2.6/arch/x86/include/asm/bitops.h > > > =================================================================== > > > --- linux-2.6.orig/arch/x86/include/asm/bitops.h 2022-08-01 12:27:43.000000000 +0200 > > > +++ linux-2.6/arch/x86/include/asm/bitops.h 2022-08-01 12:27:43.000000000 +0200 > > > @@ -203,8 +203,10 @@ arch_test_and_change_bit(long nr, volati > > > > > > static __always_inline bool constant_test_bit(long nr, const volatile unsigned long *addr) > > > { > > > - return ((1UL << (nr & (BITS_PER_LONG-1))) & > > > + bool r = ((1UL << (nr & (BITS_PER_LONG-1))) & > > > (addr[nr >> _BITOPS_LONG_SHIFT])) != 0; > > > + barrier(); > > > + return r; > > > > Hmm, I find it a bit weird to have a barrier() here given that 'addr' is > > volatile and we don't need a barrier() like this in the definition of > > READ_ONCE(), for example. > > gcc doesn't reorder two volatile accesses, but it can reorder non-volatile > accesses around volatile accesses. > > The purpose of the compiler barrier is to make sure that the non-volatile > accesses that follow test_bit are not reordered by the compiler before the > volatile access to addr. If we need these accesses to be ordered reliably, then we need a CPU barrier and that will additionally prevent the compiler reordering. So I still don't think we need the barrier() here. > > > Index: linux-2.6/include/linux/wait_bit.h > > > =================================================================== > > > --- linux-2.6.orig/include/linux/wait_bit.h 2022-08-01 12:27:43.000000000 +0200 > > > +++ linux-2.6/include/linux/wait_bit.h 2022-08-01 12:27:43.000000000 +0200 > > > @@ -71,7 +71,7 @@ static inline int > > > wait_on_bit(unsigned long *word, int bit, unsigned mode) > > > { > > > might_sleep(); > > > - if (!test_bit(bit, word)) > > > + if (!test_bit_acquire(bit, word)) > > > return 0; > > > return out_of_line_wait_on_bit(word, bit, > > > bit_wait, > > > > Yet another approach here would be to leave test_bit as-is and add a call to > > smp_acquire__after_ctrl_dep() since that exists already -- I don't have > > strong opinions about it, but it saves you having to add another stub to > > x86. > > It would be the same as my previous patch with smp_rmb() that Linus didn't > like. But I think smp_rmb (or smp_acquire__after_ctrl_dep) would be > correct here. Right, I saw Linus' objection to smp_rmb() and I'm not sure where smp_acquire__after_ctrl_dep() fits in with his line of reasoning. On the one hand, it's talking about acquire ordering, but on the other, it's ugly as sin :) Will