From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4143EC19F2C for ; Mon, 1 Aug 2022 10:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231441AbiHAKls (ORCPT ); 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 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