Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp1462441imn; Sun, 31 Jul 2022 07:56:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR4MCTJ6SJVu5d3ojMrMtGO7hCgTl0oCTrrRHWFXGTIJjfIwAFwMLptHvSseBsfhJTbuwk7h X-Received: by 2002:a17:90b:1110:b0:1f4:fc9a:be2d with SMTP id gi16-20020a17090b111000b001f4fc9abe2dmr1475892pjb.41.1659279370231; Sun, 31 Jul 2022 07:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659279370; cv=none; d=google.com; s=arc-20160816; b=RRlUhp4f4XSQUU+qcQ9VZweH9tDnKihRI53iAJfP6Fyq3iY3HHVykNeni9QWPybYCE S+Nh7foJ1STi1JjJaslsQju+ziVs32e/69XONr08vFGJkjdxCs5jj0bHF9jn2BUn/MQj 4fUvYEatWcRMEF7uriVpLR9nNwKO8lRxceNXzjxE0yAeawOvRxJ24LrQZJCXI0/rViRm lJ+jSI1UyCp5BBUuZU+ckEaXBaSUsZI486XVEtSTecjZF4SxvTuElEue8mQdwLJwqegB CzFDd4FPMLp933/wygK6qNFtC7pHkNA9zy25AlDgStR1kMmrmKkT/wftZhk/VDIwjg1M 0cyg== 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=SWo/FoD4QM1KXB5H5atBkQnHX7hzvCdJbAxzr/wiEMY=; b=QfXdKq9/aGA0aK8mszObYf9eeFVe5Arppr+dgnUe+8EjHvMA5I5Wx1VC4I3/Z4oruX 7dZnmIGH1SRdNPShNul69x+C1cTCSAv9u4PzmsQXthcMtuT8C759TK1ctExicIw8ctMC bwMORSXeYz3gPIQilhLZ8SmQ1+q/v9IKMsTlz3809AxRxgLUA4Y6aMiR+4DDqQTBsXda aAYUqzWvxyAKHQQxMQv8GkLFxG8Pt2ixrhATvcQW1AtppPSi1gTMvxd2N1TjddQ5SPJG 2vTMWeD7nwrtHDwmc1OxOyoTXYf9aM3Jm8fJylUESggIHT1R7NV5KgUENxyN/N/xo4xX Mt8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UGzWtQJe; 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 x22-20020a63cc16000000b0040d5dc5b896si8963807pgf.519.2022.07.31.07.55.55; Sun, 31 Jul 2022 07:56:10 -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=UGzWtQJe; 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 S237124AbiGaNlM (ORCPT + 99 others); Sun, 31 Jul 2022 09:41:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230436AbiGaNlL (ORCPT ); Sun, 31 Jul 2022 09:41:11 -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 24656CE1A for ; Sun, 31 Jul 2022 06:41:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1659274869; 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=SWo/FoD4QM1KXB5H5atBkQnHX7hzvCdJbAxzr/wiEMY=; b=UGzWtQJe7g1OEZmzW9itVsDGzCTAfFI5FvntEk7QgzOqBY1h9CLOL+hDvfjw/3JQ1L+IPD kAK9xhhfU6jnpsSXSP4XIHVQzauNwS3nl34EhR2eICq1EArtdo6tZXAy5e2aBBMP3EFQyO mSUDqm4HHdNc6cg063ThOuR86UtTxwg= 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-79-oXmXFGOKNDy0l_ivd3DbPQ-1; Sun, 31 Jul 2022 09:41:04 -0400 X-MC-Unique: oXmXFGOKNDy0l_ivd3DbPQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BFF8D801585; Sun, 31 Jul 2022 13:41:03 +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 92C6D1121314; Sun, 31 Jul 2022 13:41:03 +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 26VDf3iN009354; Sun, 31 Jul 2022 09:41:03 -0400 Received: from localhost (mpatocka@localhost) by file01.intranet.prod.int.rdu2.redhat.com (8.14.4/8.14.4/Submit) with ESMTP id 26VDf2oa009349; Sun, 31 Jul 2022 09:41:02 -0400 X-Authentication-Warning: file01.intranet.prod.int.rdu2.redhat.com: mpatocka owned process doing -bs Date: Sun, 31 Jul 2022 09:41:02 -0400 (EDT) From: Mikulas Patocka X-X-Sender: mpatocka@file01.intranet.prod.int.rdu2.redhat.com To: Ard Biesheuvel cc: Linus Torvalds , Alexander Viro , 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 Mailing List , linux-arch , linux-fsdevel@vger.kernel.org Subject: Re: [PATCH] Add a read memory barrier to wait_on_buffer 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.3 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=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 On Sun, 31 Jul 2022, Ard Biesheuvel wrote: > This has little to do with speculation, so better to drop this S bomb > from your commit message. This is about concurrency and weak memory > ordering. Yes. > This doesn't seem like a very robust fix to me, tbh - I suppose this > makes the symptom you encountered go away, but the underlying issue > remains afaict. > > Given that the lock and uptodate fields etc are just bits in a > bitfield, wouldn't it be better to use cmpxchg() with acquire/release > semantics (as appropriate) to manage these bits? The kernel already uses clear_bit_unlock, test_and_set_bit_lock and wait_on_bit_lock_io to manage the BH_Lock bit - and they have acquire/release semantics. The only problem is that test_bit doesn't provide any memory barriers. Should we add the barrier to buffer_locked() instead of wait_on_buffer()? Perhaps it would fix more bugs - in reiserfs, there's this piece of code: if (buffer_locked(bh)) { spin_unlock(lock); wait_on_buffer(bh); spin_lock(lock); } if (!buffer_uptodate(bh)) { ret = -EIO; } or this: if (buffer_locked(bh)) { int depth; PROC_INFO_INC(sb, scan_bitmap.wait); depth = reiserfs_write_unlock_nested(sb); __wait_on_buffer(bh); reiserfs_write_lock_nested(sb, depth); } BUG_ON(!buffer_uptodate(bh)); BUG_ON(atomic_read(&bh->b_count) == 0); That assumes that buffer_locked provides a barrier. Mikulas