Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1599690imn; Sun, 31 Jul 2022 13:44:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uuknuj5eR4xIyea93eUiNlNMHoPyMzZ8bHN8cEXyDugJ5N2yjsiV+umyM9Aq2xhrnWAXHa X-Received: by 2002:a05:6402:189:b0:437:8a8a:d08a with SMTP id r9-20020a056402018900b004378a8ad08amr12561757edv.241.1659300281206; Sun, 31 Jul 2022 13:44:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659300281; cv=none; d=google.com; s=arc-20160816; b=03PhxG2Ah4tdz1uB1/2MlRy0skrsDKPLxj5rjbIj+hektmB96eYwTE4oQBgk9gNuE3 AMvkhNN/Zs/oD4G74weIv2tUvd4TqugMfEZVQJSH7vwrjfEX4Ad0lYuUhTkaDaX+Eamz GsJ9kmYPHdn/VI+sG6JwBvCuU9B1FChnd/PrHpPGraX2ByRtsMPE6zZjdKQggof9C7QT TwIHECEhDDiN0SF8cX0BEM+vDtBBJEFsqm4j62GeJB0Hee7WMmUbOikJMVu5Bx+rddfz p9gbzAryg4jaS6vDZnNTk52zEolbt3YyrVKLROEWJanvvzRuiz2Tp4+hTzhfrJV88Ij3 ewKg== 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=r8N6mOR4eh4HYhZleYP/ElZD6zJ57nbHlhorHDpdL2o=; b=gnkQ8/adSov44TGCCkQTMPqvIerLgg0SaxEvK9jeumdZVmbBry8fTbYoSYYxhHe3Hf +pevrbx2vdaw6CuM/DNX2NexsGUCy42LF8EyQ0YfnKTM2jDv7ROfqPa45CavtW3de8XE 2B4B5pTXJgSKCF/+PT+ukM8X4wbyPkTmfOiO8aV2xihMacUMagAHcIfx6rF/8z8o12q5 sm/dDYXJ0TffZ8TOiPjVydFTTyZ6ZBHguGb0u8fqUWW0LmBT3rTHYyqwWEbwIAtiPgIP zdvcz0ZAKarSgH67SmFsgE/iFcqyhk/l6psycvWm1AK7fsHSJnTvuwuagqzDGy06iTY7 qbcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HPQuR1f6; 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 z5-20020a05640240c500b0043bc8f2015esi8749583edb.603.2022.07.31.13.44.16; Sun, 31 Jul 2022 13:44:41 -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=HPQuR1f6; 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 S238314AbiGaUjj (ORCPT + 99 others); Sun, 31 Jul 2022 16:39:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238200AbiGaUjg (ORCPT ); Sun, 31 Jul 2022 16:39:36 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 12FF8A468 for ; Sun, 31 Jul 2022 13:39:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659299975; 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=r8N6mOR4eh4HYhZleYP/ElZD6zJ57nbHlhorHDpdL2o=; b=HPQuR1f67Xxzb2vnYovm1AKwmrjZ4cuOW0xp3/O4YhKXlLbuZm+x1rB3ufZOcPokJsAcee yghmHPLCqPZitYoj3Eo3PDioYXskUzQnK8vw/Sf17KN/z0RQ4GkR0bhvGdl8mdX4y9tW2o VT29OCLkEpVkuqc1BIR3Ul9v2GRZsS8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-28-h-HHsLhWPmufZYIPa7O8ZA-1; Sun, 31 Jul 2022 16:39:28 -0400 X-MC-Unique: h-HHsLhWPmufZYIPa7O8ZA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 48C2285A581; Sun, 31 Jul 2022 20:39:27 +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 15871492C3B; Sun, 31 Jul 2022 20:39:27 +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 26VKdRbp006781; Sun, 31 Jul 2022 16:39:27 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 26VKdQgX006778; Sun, 31 Jul 2022 16:39:26 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Sun, 31 Jul 2022 16:39:26 -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 v2] make buffer_locked provide an acquire semantics 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.85 on 10.11.54.10 X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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: > [ Will and Paul, question for you below ] > > On Sun, Jul 31, 2022 at 8:08 AM Mikulas Patocka wrote: > > > > Also, there is this pattern present several times: > > wait_on_buffer(bh); > > if (!buffer_uptodate(bh)) > > err = -EIO; > > It may be possible that buffer_uptodate is executed before wait_on_buffer > > and it may return spurious error. > > I'm not convinced that's actually valid. > > They are testing the same memory location, and I don't think our > memory ordering model allows for _that_ to be out-of-order. Memory > barriers are for accesses to different memory locations. You are right. And the bit tests are volatile, so the compiler can't reorder them. But the compiler can reorder non-volatile accesses around volatile accesses (gcc does this, clang afaik doesn't), so the bit tests need at least a compiler barrier after them. > But the patch looks fine, though I agree that the ordering in > __wait_on_buffer should probably be moved into > wait_on_bit/wait_on_bit_io. Yes, there are more bugs where the code does wait_on_bit and then reads some data without any barrier. Adding the barrier to wait_on_bit fixes that. I'll send two patches, one for wait_on_bit and the other for buffer_locked. Do you think that wait_event also needs a read memory barrier? It is defined as: #define wait_event(wq_head, condition) \ do { \ might_sleep(); \ if (condition) \ break; \ __wait_event(wq_head, condition); \ } while (0) Mikulas > And would we perhaps want the bitops to have the different ordering > versions? Like "set_bit_release()" and "test_bit_acquire()"? That > would seem to be (a) cleaner and (b) possibly generate better code for > architectures where that makes a difference? > > Linus >