Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1881932imn; Mon, 1 Aug 2022 03:49:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR74R8+qF8W4Oc2R8HkdrA6wxBBRZ5QZhTOaru93j33c6xETbVXusnmXFWs8UFZxkVjB6AdO X-Received: by 2002:a17:90b:180f:b0:1f5:160c:a656 with SMTP id lw15-20020a17090b180f00b001f5160ca656mr678696pjb.193.1659350960768; Mon, 01 Aug 2022 03:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659350960; cv=none; d=google.com; s=arc-20160816; b=SlEVDtlcc52AmXfmLfj5X9Ck53/5OaDL7T36er+A483f/opxxHNgeGmD1n9u5jF15T Pztpx34VzCTDqbM6b2YMrXnJm3/ykF3ojMtiXEzIxbx3KgC1tgvqTkR7Joz9msP1p7he igpGqSJUObA1lS9zIc0TvvunxzUqdyUPqMxfjZ50G8H83e86ORI2s4OlnAfe1VZWqhYM VIQof7Ln4Pf2E2bRfPjhphZAb2ULxNkyaC/hpy3JMGbKirGEyDeA0GC15VpO+owPIn8h Lgk3g89cUkDk+tNzlfz2AyqC2ubtODDvARDeYfE/yJ6arG1+kmY8LuyfMsM50lXX/BO5 Bh7Q== 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=K0pg1pNXoU6pWG/EuOJ54ozk230Lew/YsdWyQJDodl0=; b=Z956uOVWk+Ig9QQO+2l0ih9UQ9VZ7MYHCSUZ/472nA+QyGTFopgU3Moaacy7FC05wq nafFuJzkuaCQaJtkMVdq69WN6SadhszLulxFIhn7kWwEBeiDqx87ZffurntgL/qLByZc FGdeXyADAHGvp8ZEF5oInIlSiXEffJPBCleb5dpZ67hOlw4jR1p5fN1i4cMrVcfw6IIP uw255jqw722vStIRIPcMEub4pvBiD6YaQaB3H5hU/dMgcOl2b2O5WKEfIVLT7sJBaekg v5DmfkO1lahfAHJqTRI3zBrHUPPWH6VIdjx3XWy6SinnxVI9dNm7mK3O6aLWSkQp+RKO 3QAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DY33ksYG; 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 lw6-20020a17090b180600b001f3008d8b27si13465715pjb.131.2022.08.01.03.49.05; Mon, 01 Aug 2022 03:49:20 -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=DY33ksYG; 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 S231411AbiHAKls (ORCPT + 99 others); Mon, 1 Aug 2022 06:41:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231408AbiHAKlc (ORCPT ); Mon, 1 Aug 2022 06:41:32 -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 E5DE53C179 for ; Mon, 1 Aug 2022 03:40:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659350429; 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=K0pg1pNXoU6pWG/EuOJ54ozk230Lew/YsdWyQJDodl0=; b=DY33ksYGXV9tIu1k/WJnYj5mZ566tyS3FpRFWG9lqkRZjv/cHR9V+Njj0GnTbTjVIkKNis UyiPzZdJJ/ZTOAocTaVUvOPbnHl9q8J6oAY+LAoc/s/oO7rH6pNjq92b/zZXUBzRJQDHmA Aq/1b6lmFeMjdqLqK5+yDB6OBQui7do= 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-43-OKuQnlXvOx6ANtAWw-AEEg-1; Mon, 01 Aug 2022 06:40:22 -0400 X-MC-Unique: OKuQnlXvOx6ANtAWw-AEEg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AB6482802284; Mon, 1 Aug 2022 10:40:21 +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 7C8A22026D64; Mon, 1 Aug 2022 10:40:21 +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 271AeLfe024152; Mon, 1 Aug 2022 06:40:21 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 271AeKqK024148; Mon, 1 Aug 2022 06:40:20 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Mon, 1 Aug 2022 06:40:20 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Linus Torvalds cc: Will Deacon , "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 v3 1/2] wait_bit: do read barrier after testing a bit In-Reply-To: Message-ID: References: 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.78 on 10.11.54.4 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 Sun, 31 Jul 2022, Linus Torvalds wrote: > On Sun, Jul 31, 2022 at 1:41 PM Mikulas Patocka wrote: > > > > - if (!test_bit(bit, word)) > > + if (!test_bit(bit, word)) { > > + smp_rmb(); > > Logically, I don't think that makes sense. > > Maybe you're checking the buffer being up-to-date before you *write* to it? None of the CPUs have speculative writes - so the write can't be moved before the "test_bit" function. So, we are only concerned about reads. > So smp_rmb() seems entirely wrong. > > I think it should consistently aim for just doing > > unsigned long state = smp_read_acquire(word); > if (!(state & (1 << bit))) > return 0; > > or whatever. > > We should strive to *not* add new uses of the legacy memory barriers. > They are garbage from last century when people didn't know better. > > Then people learnt to use acquire and release, and things improved. > Let's live in that improved world. > > Linus OK - I'm sending new patches that introduce the function test_bit_acquire. Mikulas