From: Florian Weimer <fweimer@redhat.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: libc-alpha@sourceware.org,
Tulio Magno Quites Machado Filho <tuliom@linux.vnet.ibm.com>
Subject: Re: [PATCH] elf: Fix fences in _dl_find_object_update (bug 28745)
Date: Fri, 07 Jan 2022 12:59:01 +0100 [thread overview]
Message-ID: <87o84n4v0a.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20220105184954.GP3294453@arm.com> (Szabolcs Nagy's message of "Wed, 5 Jan 2022 18:49:54 +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
next prev parent reply other threads:[~2022-01-07 11:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-05 13:47 Florian Weimer
2022-01-05 14:00 ` Andreas Schwab
2022-01-05 14:03 ` Florian Weimer
2022-01-05 18:49 ` Szabolcs Nagy
2022-01-07 11:59 ` Florian Weimer [this message]
2022-01-06 22:13 ` Tulio Magno Quites Machado Filho
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87o84n4v0a.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=szabolcs.nagy@arm.com \
--cc=tuliom@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).