Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2632513rwa; Mon, 22 Aug 2022 10:47:13 -0700 (PDT) X-Google-Smtp-Source: AA6agR4B/Z9kUB/zBgfZrh8jJkUDH4AwffMQBKqKOOWPnMzJ8Q+CxmNLugUYUByveAI3wmaOa9Zj X-Received: by 2002:a17:90a:5a84:b0:1f7:ffb5:4adb with SMTP id n4-20020a17090a5a8400b001f7ffb54adbmr23804079pji.20.1661190432957; Mon, 22 Aug 2022 10:47:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661190432; cv=none; d=google.com; s=arc-20160816; b=BzuVcwKGe93m50CjZeFho7DJUlB/URcYD2XVAdcembZ1ymbm0gWPut+aV48ZJSHd3C aLxA4E/kvmID4vj+6jnsMsY8usTMonX0pbo/Fn2VCBESDpnic8BPl2+bTaKtrhyHusda XzCfWKyKmDTq3yjloHXhUQZBlkrlVJzRx5UvTJWQR1vb5OwkMyoPpZXGO/aWmIBmEoDh Pqu+zGOWmIgp3sK7r2BwqeUVTP27pOk3IheYIIUjPilN4Aj5sYqcXV07PI9W3MZ09RvH XBidAAHBqnqr8ly9YttFmiTJ9xHcy0X2u7CrFKEjD33WAfFmUznWbmx1bKN5mBo1jkDp vuFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=YETYSBdZGbHL0Tg4tG/TWQHUhawdSjZCU30HLw/bqZQ=; b=kr9UwLCUYbupWgdaqcXmWOlZwl3zyOn2nya0r+rbk+uBjE4ahPH/d1EnFYOHcAtDPu HZaUGlioUrengad+oGgY9UXUCyyZ/aBjDZ9h7IfAZI6q04nNM+rSDnYv+fELhSf+eSPj F8DbG1ex/18qxeKexVY68qOkG5rGaep/FYScFgkOFoksn+8FQONtgTgWnMpKtxSUXfi8 GC2yEVWu2FMRFU5girA6dzESheWp38N+uaX/nqB2wngf4KRVKXEGLj1WLcOGz1IGIKDW xw7Y/x2ExpTod5OgBPlzOIGldN/kwG0/Mskp95KisimN/oz9aoMW87qEcqG45RMX6gZm uvKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=fulab83o; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r2-20020a632b02000000b0042a77ec2435si7207902pgr.287.2022.08.22.10.47.01; Mon, 22 Aug 2022 10:47:12 -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=@linux-foundation.org header.s=google header.b=fulab83o; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235815AbiHVRjk (ORCPT + 99 others); Mon, 22 Aug 2022 13:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236608AbiHVRjj (ORCPT ); Mon, 22 Aug 2022 13:39:39 -0400 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E96553F332 for ; Mon, 22 Aug 2022 10:39:37 -0700 (PDT) Received: by mail-ed1-x52f.google.com with SMTP id z2so14913454edc.1 for ; Mon, 22 Aug 2022 10:39:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc; bh=YETYSBdZGbHL0Tg4tG/TWQHUhawdSjZCU30HLw/bqZQ=; b=fulab83oMTsxW7dccBev0p+7W/JBtblNus6/b6WUjgoN5VyafMscsPXwGVYeMsounJ lEFO63eSxG8frytNPBzG4RgXoD/rrgVP5ESe2yR8VUYSaht5/TKg5qfWl14CgWTAO4iC giT/EN094TdnbvBlJOLD83hL2ktihC1451bGE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc; bh=YETYSBdZGbHL0Tg4tG/TWQHUhawdSjZCU30HLw/bqZQ=; b=dzoap8eORU4EQG28fLdQfZVWAmoQSC8KcsID8uV2+hWyPamkTR+56p7UavWutRFHh5 zigbjww+CbetEwillBPZ/IZjWnJq0Cw7HbBnwyBTpbzBupAKgabtSF6O/nCU5yEHD0yG Ok/dSGHOY3eqa9212S0gQUIxW/Q7e4NjBYuMRaZd4NQzTue6OWvsh6Rg7Athr43PikLs 42pNhZ2DahIplGW0WT2J9L4q1nUiZGAq9AnhSW+KmIQucY37ajIPpuSjT1AbNOKkncjy hYlhOcuSuSaGzdw0SBkf/8rrjvGL4iBe1ZJZkjcukzItif7IIEUc0a6VPxXFYDuMZHHa Aavg== X-Gm-Message-State: ACgBeo3Yvh5v6PL10zAzd3041AFF7l6ufXTazPwKToq8Tjl1oKs5gQDN h3fLEshJpAIFROp+AfgryKaoWNDF+E9WaaPB X-Received: by 2002:a05:6402:350b:b0:43e:f4be:c447 with SMTP id b11-20020a056402350b00b0043ef4bec447mr197663edd.427.1661189976517; Mon, 22 Aug 2022 10:39:36 -0700 (PDT) Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com. [209.85.221.50]) by smtp.gmail.com with ESMTPSA id bv19-20020a170906b1d300b0073923a68974sm6409941ejb.206.2022.08.22.10.39.34 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Aug 2022 10:39:35 -0700 (PDT) Received: by mail-wr1-f50.google.com with SMTP id r16so14123958wrm.6 for ; Mon, 22 Aug 2022 10:39:34 -0700 (PDT) X-Received: by 2002:adf:e843:0:b0:225:221f:262 with SMTP id d3-20020adfe843000000b00225221f0262mr11599499wrn.193.1661189974089; Mon, 22 Aug 2022 10:39:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Mon, 22 Aug 2022 10:39:17 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] wait_on_bit: add an acquire memory barrier To: Mikulas Patocka Cc: Alan Stern , Andrea Parri , Will Deacon , Peter Zijlstra , Boqun Feng , Nicholas Piggin , David Howells , Jade Alglave , Luc Maranget , "Paul E. McKenney" , Akira Yokosawa , Daniel Lustig , Joel Fernandes , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org Content-Type: multipart/mixed; boundary="0000000000004fa1b205e6d7ee0b" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 --0000000000004fa1b205e6d7ee0b Content-Type: text/plain; charset="UTF-8" On Mon, Aug 22, 2022 at 10:08 AM Linus Torvalds wrote: > > So why don't we just create a "test_bit_acquire()" and be done with > it? We literally created clear_bit_unlock() for the opposite reason, > and your comments about the new barrier hack even point to it. Here's a patch that is (a) almost entirely untested (I checked that one single case builds and seems to generate the expected code) (b) needs some more loving but seems to superficially work. At a minimum this needs to be split into two (so the bitop and the wait_on_bit parts split up), and that whole placement of and generic_bit_test_acquire() need at least some thinking about, but on the whole it seems reasonable. For example, it would make more sense to have this in , but not all architectures include that, and some do their own version. I didn't want to mess with architecture-specific headers, so this illogically just uses generic-non-atomic.h. Maybe just put it in directly? So I'm not at all claiming that this is a great patch. It definitely needs more work, and a lot more testing. But I think this is at least the right _direction_ to take here. And yes, I think it also would have been better if "clear_bit_unlock()" would have been called "clear_bit_release()", and we'd have more consistent naming with our ordered atomics. But it's probably not worth changing. Linus --0000000000004fa1b205e6d7ee0b Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_l751lwl30 IGluY2x1ZGUvYXNtLWdlbmVyaWMvYml0b3BzL2dlbmVyaWMtbm9uLWF0b21pYy5oIHwgOSArKysr KysrKysKIGluY2x1ZGUvYXNtLWdlbmVyaWMvYml0b3BzL25vbi1hdG9taWMuaCAgICAgICAgIHwg MSArCiBpbmNsdWRlL2xpbnV4L2JpdG9wcy5oICAgICAgICAgICAgICAgICAgICAgICAgICB8IDIg Ky0KIGluY2x1ZGUvbGludXgvd2FpdF9iaXQuaCAgICAgICAgICAgICAgICAgICAgICAgIHwgOCAr KysrLS0tLQoga2VybmVsL3NjaGVkL3dhaXRfYml0LmMgICAgICAgICAgICAgICAgICAgICAgICAg fCAyICstCiA1IGZpbGVzIGNoYW5nZWQsIDE2IGluc2VydGlvbnMoKyksIDYgZGVsZXRpb25zKC0p CgpkaWZmIC0tZ2l0IGEvaW5jbHVkZS9hc20tZ2VuZXJpYy9iaXRvcHMvZ2VuZXJpYy1ub24tYXRv bWljLmggYi9pbmNsdWRlL2FzbS1nZW5lcmljL2JpdG9wcy9nZW5lcmljLW5vbi1hdG9taWMuaApp bmRleCAzZDVlYmQyNDY1MmIuLmY1NmEyNTJkYjllOCAxMDA2NDQKLS0tIGEvaW5jbHVkZS9hc20t Z2VuZXJpYy9iaXRvcHMvZ2VuZXJpYy1ub24tYXRvbWljLmgKKysrIGIvaW5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