Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2048859imn; Mon, 1 Aug 2022 09:15:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u593eIvhRWjnpmTbQs/lELPBIvVjVg7QmZoVe47ZDVYPammcUw61qrSnu1N6OZ26Vjww3a X-Received: by 2002:a17:907:728f:b0:72f:1d6e:87e with SMTP id dt15-20020a170907728f00b0072f1d6e087emr13668323ejc.704.1659370525001; Mon, 01 Aug 2022 09:15:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659370524; cv=none; d=google.com; s=arc-20160816; b=aYWrh92aOJkN6HqC9pBanR1fSkx4S0WSYbDpUe/z9mPfFLs6uhPIDTKumqbwyv4ka2 EvA049Kjbw8/0CUAet/Oh3G8/GehSBux1LIxZm8lCAskl4ZKtUpKdRj1ITHSIRuJsICu +qLsQpGespvHLB2ooVpx+Tg7TlFz3rSI13VPtLFrxtFHWceWTyxZ1/r/MJa4N2Jo8oop 1rLqzcCm2vTqMy/pbP69CQV6mVCEQhBD7xHMoRAqihZTxrvUnXeXMC82QpEpUXfeI/mC 2ZzqZyiXT1dpp8cd+pCyOB53ZSQwqn4k7e7abYWj9q7PF6wIbv2FhmIS0BDAkjfkTbf8 w3RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:message-id :in-reply-to:subject:cc:to:from:date:dkim-signature; bh=vJUjThABraUhNy6LWcAMkngL85HJMPWyf0Ew8APs7Fo=; b=A91l6jp+QyUp5lHLt+os8Xl6aljjZOJNwmrYFoL1dNzeXgTjOSF8vQDt7+kKy9Lfbm oixTGHrvZppChFUFCTof4AMCcATHct0YyiMGdkNNTxbipsVbSUK8hSLrwObKupdBI21e 1U3wSmqq7jgOzFhFCnmQfo9yRseE4tVEQwHsrTD3LKjpA/IWtb+auZjofpJytMh+PeXj 5jZD18+vevoTIzY3kuBAI3g8f+a47sAeBIszY+CncrI9B6xXzFYY9ux5dnrzH5ZpcLOL hrgUaFZGwpailxayKK1h5L7YkCbjev5rkeXb/5PJm9cJV8g0CDZ9EfEAIbs6HGdT463I hyfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Dr3mHzqw; 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=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jg35-20020a170907972300b0072b44c95da6si11164533ejc.1002.2022.08.01.09.15.00; Mon, 01 Aug 2022 09:15:24 -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=@redhat.com header.s=mimecast20190719 header.b=Dr3mHzqw; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232691AbiHAQNF (ORCPT + 99 others); Mon, 1 Aug 2022 12:13:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232607AbiHAQNA (ORCPT ); Mon, 1 Aug 2022 12:13:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 53923220D3 for ; Mon, 1 Aug 2022 09:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659370378; h=from:from:reply-to:subject:subject: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=vJUjThABraUhNy6LWcAMkngL85HJMPWyf0Ew8APs7Fo=; b=Dr3mHzqw6KbvQLX610MiTmMxVDyvomBMs96Wbu5sv4IgBiROv6P5jpJHYNtO0u0nPPPDIK pIJlPnXYFBBvbdE7TG1wMXWJwJHWokM8iHx7rSE8GwRV8uCEUbgDYUU29milXZcE7U+Vm9 6pNRICvh7SIzCbNKLeIX7IS8DU04a4o= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-317-7QkM_1D2Mlui_BZok73Ckg-1; Mon, 01 Aug 2022 12:12:50 -0400 X-MC-Unique: 7QkM_1D2Mlui_BZok73Ckg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 383333C0CD56; Mon, 1 Aug 2022 16:12:48 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (file01.intranet.prod.int.rdu2.redhat.com [10.11.5.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C47CD90A11; Mon, 1 Aug 2022 16:12:47 +0000 (UTC) Received: from file01.intranet.prod.int.rdu2.redhat.com (localhost [127.0.0.1]) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4) with ESMTP id 271GClpF032719; Mon, 1 Aug 2022 12:12:47 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 271GClqI032715; Mon, 1 Aug 2022 12:12:47 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Mon, 1 Aug 2022 12:12:47 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Will Deacon 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 In-Reply-To: <20220801155421.GB26280@willie-the-truck> Message-ID: References: <20220801155421.GB26280@willie-the-truck> User-Agent: Alpine 2.02 (LRH 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=unavailable 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, 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. > > 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. > Will Mikulas