Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp2401672imn; Tue, 2 Aug 2022 01:04:07 -0700 (PDT) X-Google-Smtp-Source: AA6agR5rxapMngltIf+BoBf+pzoRH3pMG5ylMWAcHwfx95CFcUBQkRcHl7gtxjKM+D/RVQSJFBbI X-Received: by 2002:a17:907:8a0a:b0:730:a118:75de with SMTP id sc10-20020a1709078a0a00b00730a11875demr1435429ejc.189.1659427446906; Tue, 02 Aug 2022 01:04:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659427446; cv=none; d=google.com; s=arc-20160816; b=p/OmXe/tPbuPnE6Ffl2JyWzE96qXWSRWu1b8iYV3STC+EySyEEraN46W//F5OKSebJ 3p4isVQeCy+gfsSQCQERBKHcmU4RauThE7/UWAKM/UCzZefBmc1VO+nZN9WkQ82nXipe U8Zta0xIEKMx2cutrq0yHNvQ3pV+g/SHkUskzBJPm+R/Wjvu4dsufYlhMbKZIy8MQ/a4 ycj+sCH2O9cSZUfQamZwnT60WAVrT+ZF3Y51jngt+pNfVyZvNQdj2FcaUwzmm7cHOJ1W Wo+ybburmkYZjpj9gFWidcl9Qnvw11a4Iyc/qb+1wRZt51iS/I4wVNUhD8D2gGwUIkE3 n/jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :mime-version:accept-language:in-reply-to:references:message-id:date :thread-index:thread-topic:subject:cc:to:from; bh=erjT6jLq9HXMRxYcTIJ0q4xB718aVvy0LNx84SS0y+g=; b=pxsWM30Vhl02edFrtlLjLCi/mYJUqlL6ZGmNWqpRFRL68orh+kkWt7RmUwRQqZUVwk /Mw9TeaZWMV/AOENnmaJA6VwOheI1vbBd85u7+kwgzncvOmKkMRZ3BiJLTefM/F1B4p2 83tGEJOHXaDkwnRPHP0tgEChstNmmu7yA4XMhei5cYIiEHY+iKzrTI3A4iHiX5ADkFAD TR/PCrQ+UhuOiZwN4okUinHLqb4WA7TcQE2DyLJOSCZV/C/lfkp4ZmxOVg+nvBFZ90Uv T3hc8ORtD4XaQRCvhXIWQlVdZIjTBZwvUVNgWYTYE2H3o5jvVTMgXGbNPpUQyahY0Ys6 HTIg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nd30-20020a170907629e00b0072a7a097e3csi5077741ejc.464.2022.08.02.01.03.42; Tue, 02 Aug 2022 01:04:06 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=aculab.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233598AbiHBIA5 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 2 Aug 2022 04:00:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231804AbiHBIAy (ORCPT ); Tue, 2 Aug 2022 04:00:54 -0400 Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [185.58.85.151]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2EDB62BFB for ; Tue, 2 Aug 2022 01:00:53 -0700 (PDT) Received: from AcuMS.aculab.com (156.67.243.121 [156.67.243.121]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id uk-mta-308-TQG7PYX_M7ubdYwPcl-8wA-1; Tue, 02 Aug 2022 09:00:50 +0100 X-MC-Unique: TQG7PYX_M7ubdYwPcl-8wA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) by AcuMS.aculab.com (fd9f:af1c:a25b:0:994c:f5c2:35d6:9b65) with Microsoft SMTP Server (TLS) id 15.0.1497.36; Tue, 2 Aug 2022 09:00:48 +0100 Received: from AcuMS.Aculab.com ([fe80::994c:f5c2:35d6:9b65]) by AcuMS.aculab.com ([fe80::994c:f5c2:35d6:9b65%12]) with mapi id 15.00.1497.036; Tue, 2 Aug 2022 09:00:48 +0100 From: David Laight To: 'Boqun Feng' , Mikulas Patocka CC: Will Deacon , Linus Torvalds , "Paul E. McKenney" , "Ard Biesheuvel" , Alexander Viro , "Alan Stern" , Andrea Parri , Peter Zijlstra , 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 Thread-Topic: [PATCH v4 1/2] introduce test_bit_acquire and use it in wait_on_bit Thread-Index: AQHYpdMdL3R9dRhMTUG852+RirbLDa2bPhCA Date: Tue, 2 Aug 2022 08:00:48 +0000 Message-ID: <31eb3681cfcf4b238a12a82c175457bc@AcuMS.aculab.com> References: <20220801155421.GB26280@willie-the-truck> In-Reply-To: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, 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 From: Boqun Feng > Sent: 01 August 2022 19:17 > > 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. > > > > Better to have a constant_test_bit_acquire()? I don't think all > test_bit() call sites need the ordering? It is also unlikely that the compiler will 'usefully' move a read across the test_bit() call - which is likely to be in a conditional. So barrier() is unlikely to significantly affect the generated code. Indeed, perhaps test_bit() should always enforce read ordering even one weakly ordered cpu? It is used with set_bit() and clear_bit() which are expensive locked operations - so a slightly more expensive test_bit() probably doesn't matter. Remember these aren't functions to replace &= and |=. (In spite of some code paths.) David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)