From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B3A483858413 for ; Fri, 7 Jan 2022 11:59:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B3A483858413 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-91-y1rRmAF2NRqjFvf-0M4Kcw-1; Fri, 07 Jan 2022 06:59:06 -0500 X-MC-Unique: y1rRmAF2NRqjFvf-0M4Kcw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E1A2A18B9EC3; Fri, 7 Jan 2022 11:59:04 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.102]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E2F077B6F1; Fri, 7 Jan 2022 11:59:03 +0000 (UTC) From: Florian Weimer To: Szabolcs Nagy Cc: libc-alpha@sourceware.org, Tulio Magno Quites Machado Filho Subject: Re: [PATCH] elf: Fix fences in _dl_find_object_update (bug 28745) References: <87tueie1lf.fsf@oldenburg.str.redhat.com> <20220105184954.GP3294453@arm.com> Date: Fri, 07 Jan 2022 12:59:01 +0100 In-Reply-To: <20220105184954.GP3294453@arm.com> (Szabolcs Nagy's message of "Wed, 5 Jan 2022 18:49:54 +0000") Message-ID: <87o84n4v0a.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 07 Jan 2022 11:59:08 -0000 * Szabolcs Nagy: > The 01/05/2022 14:47, Florian Weimer wrote: >> As explained in Hans Boehm, Can Seqlocks Get Along with Programming >> Language Memory Models?, an acquire fence is needed in >> _dlfo_read_success. The lack of a fence was >> >> The fence in _dlfo_mappings_begin_update has been reordered, turning >> the fence/store sequence into a release MO store equivalent. >> > > now i don't fully understand why we need the +2 then +1 trick. > > the writer is like > > v = load (&ver); > i = v & 1; > fence (); > fetch_add (&ver, 2); > update (!i); > fence (); > fetch_add (&ver, 1); > > why not > > v = load (&ver); > i = v & 1; > fence (); > update (!i); > fence (); > store (&ver, v+1); > > i.e. i'd expect readers to only need to detect an interleaving > "commit" operation (final store to ver). for which we need > > 1) updates are not visible too early (before previous commit) > 2) updates are visible after commit. > > and i think two release fences can take care of this (even > with relaxed store). > > i think on cppmem 1) can be modelled as > > int main() { > atomic_int v=0; > atomic_int x=0; > {{{ { > v.store(1,mo_relaxed); // prev commit > atomic_thread_fence(mo_release); > x.store(1,mo_relaxed); > } ||| { > v.load(mo_acquire).readsvalue(0); > x.load(mo_relaxed).readsvalue(1); > atomic_thread_fence(mo_acquire); > v.load(mo_relaxed).readsvalue(0); > } }}} > return 0; > } > > while 2) can be modelled as > > int main() { > atomic_int v=0; > atomic_int x=0; > {{{ { > x.store(1,mo_relaxed); > atomic_thread_fence(mo_release); > v.store(1,mo_relaxed); > } ||| { > v.load(mo_acquire).readsvalue(1); > x.load(mo_relaxed).readsvalue(0); > atomic_thread_fence(mo_acquire); > v.load(mo_relaxed).readsvalue(1); > } }}} > return 0; > } I think you are right. I want to make this change in a separate commit. The present patch already lumps together unrelated changes (the new fence, the reordering of one of the existing fences, and the relaxed MO loads/stores for the TM data). Thanks, Florian