Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2533761imn; Tue, 2 Aug 2022 06:39:01 -0700 (PDT) X-Google-Smtp-Source: AA6agR7gWVBzIeQn2IoCnkpc+cq2sV+BJudnoesboKStPyURiXLdLtf9CzjBDMjLyk85bBAqWfyu X-Received: by 2002:a17:90b:3ec5:b0:1f0:500d:60c3 with SMTP id rm5-20020a17090b3ec500b001f0500d60c3mr24604730pjb.183.1659447540780; Tue, 02 Aug 2022 06:39:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659447540; cv=none; d=google.com; s=arc-20160816; b=hQ7SvjQUU80ucooJElrTuisauzIcZy6EcjPGRyXV1Tsf+YKwk7NVKh/aRpdu2lvqFd 2yoDGihWVOqtavZj7lttH3SUJW5Hr5feDdhzdDZAZvhoQS4QvXcmWiRvqN6nKR3xY/zw CmAtiAjBdEbnTo6pQfvFNcG4KP0Rxv8B1NpBM2/TQLXPI79rGK0saL0utwIUxJ8jLnT7 KdPfUxSndOwKnuSzzt9DdkJ4JYLgrrVvxT4nUYqmZfVBQE9PDU0P61IjUqQifV0VzmqY IzMGz1KY5PlCoUuZx13Zv9Me/QP3LOcKmEL6i44Y8fF905GeCiDj4A1d5u/GzOXnZTMK KTYw== 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=MrVkc7xLo7lMbz3wMM6olyLSkEIyUIEC5NO9QcYm+aM=; b=tzFTJvBQI/uxw2sxKVRptSofUDJ7ayy9yVel0EdfpEnn47nuZDKXKQzXS4eU/FXw5F IxnBnJtdFAC3L1p0c56SZqxA5U4q/Qb2JOPfFFpBQCS2c5zU4h/kstBm65hs6Tw8Zi02 nxnXZY3L3+UzKScJHIZverbR749AJ2KUC/I28Y1f3cJ6tQkPpS/F8p+M/4mAAOcLyZ3u A8YvMmmGP1dgOoDPQXLaXWGNqY2P9x0VkodLiw3qzdn3f3iehWt+S/fbC2jM/olyy3vJ bnkCc97yClu7KOhmkaIJfX9GXJhdk5Vz0m8xUv3mAS5F+hFb58hV3eqZwadAOzUqkMeI np4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kSBbnspv; 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 pc8-20020a17090b3b8800b001f225001ee1si16979604pjb.121.2022.08.02.06.38.46; Tue, 02 Aug 2022 06:39:00 -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=kSBbnspv; 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 S236902AbiHBNhI (ORCPT + 99 others); Tue, 2 Aug 2022 09:37:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236860AbiHBNhD (ORCPT ); Tue, 2 Aug 2022 09:37:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C20811FCE8; Tue, 2 Aug 2022 06:37:01 -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 5CBEC61386; Tue, 2 Aug 2022 13:37:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F27EC433C1; Tue, 2 Aug 2022 13:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1659447420; bh=ZlMhRfPhc4uGPBAikMBqcUj88XgI6PHU0uG5CpAx4/g=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=kSBbnspvYPUyDRKaaXWUC0c7X1DnR9vrhVLe+9f5G9nrQHMFGFWYqZjDnLXVKWI4W YopJcceW7IVAxkeDprutNuwpypkV0FVVsKACSY+FUBoXFDU+baAXPaYLvaNTNuj7QI Ot6YJzqkSVy246b8+6lga4qN5U1YXVOSeK506OUZmmWzDXDDfuNZKDOQ0me7iGII+R 8H1YdtRAwYHBYbbuJOpHsH0KIuXT1tapPMcuqF1gLED2GXctT72YSQzg0J3ysoRO1w lr8NahCmGGd07RqP13zCDCeNPV48GrCXnFkJesdGQe1mCDtCCffg0aYVEfeyOb5lo9 i005K8+IhtFGg== Date: Tue, 2 Aug 2022 14:36:53 +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: <20220802133652.GA27253@willie-the-truck> References: <20220801155421.GB26280@willie-the-truck> <20220802084015.GB26962@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 Tue, Aug 02, 2022 at 07:38:17AM -0400, Mikulas Patocka wrote: > > > On Tue, 2 Aug 2022, Will Deacon wrote: > > > 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. > > This is x86-specific code. x86 has strong memory ordering, so we only care > about compiler reordering. Indeed, but what I'm trying to say is that the _caller_ would have a memory barrier in this case, and so there's no need for one in here. test_bit() does not have ordering semantics. Will