public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: paulmck <paulmck@kernel.org>,  Boqun Feng <boqun.feng@gmail.com>,
	 Peter Zijlstra <peterz@infradead.org>,
	 libc-alpha <libc-alpha@sourceware.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/5] nptl: Add rseq registration
Date: Mon, 06 Dec 2021 20:03:26 +0100	[thread overview]
Message-ID: <87ilw1mu81.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <1614144911.15213.1638816753026.JavaMail.zimbra@efficios.com> (Mathieu Desnoyers's message of "Mon, 6 Dec 2021 13:52:33 -0500 (EST)")

* Mathieu Desnoyers:

> [ Adding other kernel rseq maintainers in CC. ]
>
> ----- On Dec 6, 2021, at 12:14 PM, Florian Weimer fweimer@redhat.com wrote:
>
>> * Mathieu Desnoyers:
>> 
>>> ----- On Dec 6, 2021, at 8:46 AM, Florian Weimer fweimer@redhat.com wrote:
>>> [...]
>>>> @@ -406,6 +407,9 @@ struct pthread
>>>>   /* Used on strsignal.  */
>>>>   struct tls_internal_t tls_state;
>>>> 
>>>> +  /* rseq area registered with the kernel.  */
>>>> +  struct rseq rseq_area;
>>>
>>> The rseq UAPI requires that the fields within the rseq_area
>>> are read-written with single-copy atomicity semantics.
>>>
>>> So either we define a "volatile struct rseq" here, or we'll need
>>> to wrap all accesses with the proper volatile casts, or use the
>>> relaxed_mo atomic accesses.
>> 
>> Under the C memory model, neither volatile nor relaxed MO result in
>> single-copy atomicity semantics.  So I'm not sure what to make of this.
>> Surely switching to inline assembly on all targets is over the top.
>> 
>> I think we can rely on a plain read doing the right thing for us.
>
> AFAIU, the plain read does not prevent the compiler from re-loading the
> value in case of high register pressure.
>
> Accesses to rseq fields such as cpu_id need to be done as if those were
> concurrently modified by a signal handler nesting on top of the user-space
> code, with the particular twist that blocking signals has no effect on
> concurrent updates.
>
> I do not think we need to do the load in assembly. I was under the impression
> that both volatile load and relaxed MO result in single-copy atomicity
> semantics for an aligned pointer. Perhaps Paul, Peter, Boqun have something
> to add here ?

The C memory model is broken and does not prevent out-of-thin-air
values.  As far as I know, this breaks single-copy atomicity.  In
practice, compilers will not exercise the latitude offered by the memory
model.  volatile does not ensure absence of data races.

Using atomics or volatile would require us to materialize the thread
pointer, given the current internal interfaces we have, and I don't want
to do this because this is supposed to be performance-critical code.
The compiler barrier inherent to the function call will have to be
enough.  I can add a comment to this effect:

  /* This load has single-copy atomicity semantics (as required for
     rseq) because the function call implies a compiler barrier.  */

Thanks,
Florian


  reply	other threads:[~2021-12-06 19:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 13:45 [PATCH 0/5] Extensible rseq support for glibc Florian Weimer
2021-12-06 13:46 ` [PATCH 1/5] nptl: Add <thread_pointer.h> for defining __thread_pointer Florian Weimer
2021-12-06 16:44   ` Mathieu Desnoyers
2021-12-06 17:01     ` Florian Weimer
2021-12-06 19:55       ` Florian Weimer
2021-12-06 13:46 ` [PATCH 2/5] nptl: Add rseq registration Florian Weimer
2021-12-06 16:53   ` Mathieu Desnoyers
2021-12-06 17:10     ` Florian Weimer
2021-12-06 16:59   ` Mathieu Desnoyers
2021-12-06 17:14     ` Florian Weimer
2021-12-06 18:52       ` Mathieu Desnoyers
2021-12-06 19:03         ` Florian Weimer [this message]
2021-12-06 20:11           ` Paul E. McKenney
2021-12-06 20:26             ` Florian Weimer
2021-12-06 21:08               ` Paul E. McKenney
2021-12-06 13:46 ` [PATCH 3/5] Linux: Use rseq to accelerate sched_getcpu Florian Weimer
2021-12-06 16:50   ` Szabolcs Nagy
2021-12-06 17:06     ` Florian Weimer
2021-12-06 17:45       ` Szabolcs Nagy
2021-12-07 15:48         ` Florian Weimer
2021-12-06 13:46 ` [PATCH 4/5] nptl: Add glibc.pthread.rseq tunable to control rseq registration Florian Weimer
2021-12-06 13:53 ` [PATCH 5/5] nptl: Add public rseq symbols and <sys/rseq.h> Florian Weimer
2021-12-07 11:01   ` Szabolcs Nagy
2021-12-07 11:28     ` Florian Weimer
2021-12-06 16:13 ` [PATCH 0/5] Extensible rseq support for glibc Mathieu Desnoyers

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=87ilw1mu81.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=boqun.feng@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    /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).