All of lore.kernel.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: carlos <carlos@redhat.com>,
	Joseph Myers <joseph@codesourcery.com>,
	Szabolcs Nagy <szabolcs.nagy@arm.com>,
	libc-alpha <libc-alpha@sourceware.org>,
	Thomas Gleixner <tglx@linutronix.de>, Ben Maurer <bmaurer@fb.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Paul <paulmck@linux.vnet.ibm.com>,
	Boqun Feng <boqun.feng@gmail.com>,
	Will Deacon <will.deacon@arm.com>,
	Dave Watson <davejwatson@fb.com>, Paul Turner <pjt@google.com>,
	Rich Felker <dalias@libc.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	linux-api <linux-api@vger.kernel.org>
Subject: Re: [RFC PATCH glibc 1/3] glibc: Perform rseq(2) registration at C startup and thread creation (v18)
Date: Thu, 30 Apr 2020 18:36:44 +0200	[thread overview]
Message-ID: <878sidkk0z.fsf@oldenburg2.str.redhat.com> (raw)
In-Reply-To: <1287616647.77866.1588263099045.JavaMail.zimbra@efficios.com> (Mathieu Desnoyers's message of "Thu, 30 Apr 2020 12:11:39 -0400 (EDT)")

* Mathieu Desnoyers:

> @deftypevar {struct rseq} __rseq_abi
> @standards{Linux, sys/rseq.h}
> @Theglibc{} implements a @code{__rseq_abi} TLS symbol to interact with the
> Restartable Sequences system call (Linux-specific).  The layout of this
> structure is defined by the @file{sys/rseq.h} header.  Registration of each
> thread's @code{__rseq_abi} is performed by @theglibc{} at libc library
> initialization and thread creation.

s/libc library/library/

> The main executable and shared libraries may either have an undefined
> @code{__rseq_abi} TLS symbol, or define their own, with the same
> declaration as the one present in @file{sys/rseq.h}.  The dynamic linker
> will ensure that only one of those available symbols will be used at
> runtime across the process.
>
> If the main executable or shared libraries observe an uninitialized
> @code{__rseq_abi.cpu_id} field (value @code{RSEQ_CPU_ID_UNINITIALIZED}), they
> may perform rseq registration to the kernel: this means either glibc was
> prevented from doing the registration, or an older glibc version, which does
> not include rseq support, is in use.  When the main executable or a library
> thus takes ownership of the registration, the memory used to hold the
> @code{__rseq_abi} TLS variable must stay allocated, and is not re-used, until
> the very end of the thread lifetime or until an explicit rseq unregistration
> for that thread is performed.  It is not recommended to dlclose() libraries
> owning the @code{__rseq_abi} TLS variable.

s/dlclose()/@code{dlclose}/ (no parentheses)

Rest looks okay.

>>> +  if (__rseq_abi.cpu_id == RSEQ_CPU_ID_REGISTRATION_FAILED)
>>> +    return;
>>> +  ret = INTERNAL_SYSCALL_CALL (rseq, &__rseq_abi, sizeof (struct rseq),
>>> +                              0, RSEQ_SIG);
>>> +  if (INTERNAL_SYSCALL_ERROR_P (ret) &&
>>> +      INTERNAL_SYSCALL_ERRNO (ret) != EBUSY)
>>> +    __rseq_abi.cpu_id = RSEQ_CPU_ID_REGISTRATION_FAILED;
>> 
>> Sorry, I forgot: Please add a comment that the EBUSY error is ignored
>> because registration may have already happened in a legacy library.
>
> Considering that we now disable signals across thread creation, and that
> glibc's initialization happens before other libraries' constructors
> (as far as I remember even before LD_PRELOADed library constructors),
> in which scenario can we expect to have EBUSY here ?

That's a good point.

> Not setting __rseq_abi.cpu_id to RSEQ_CPU_ID_REGISTRATION_FAILED in case
> of EBUSY is more a way to handle "unforeseen" scenarios where somehow the
> registration would already be done. But I cannot find an "expected"
> scenario which would lead to this now.
>
> So if EBUSY really is unexpected, how should we treat that ? I don't think
> setting REGISTRATION_FAILED would be appropriate, because then it would
> break assumption of the prior successful registration that have already
> been done by this thread.

You could call __libc_fatal with an error message.  ENOSYS is definitely
an expected error code here, and EPERM (and perhaps EACCES) can happen
with seccomp filters.

Thanks,
Florian


  reply	other threads:[~2020-04-30 16:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28 17:15 [RFC PATCH glibc 1/3] glibc: Perform rseq(2) registration at C startup and thread creation (v18) Mathieu Desnoyers
2020-04-28 17:15 ` [RFC PATCH glibc 2/3] glibc: sched_getcpu(): use rseq cpu_id TLS on Linux (v7) Mathieu Desnoyers
2020-04-30 12:20 ` [RFC PATCH glibc 1/3] glibc: Perform rseq(2) registration at C startup and thread creation (v18) Florian Weimer
2020-04-30 16:11   ` Mathieu Desnoyers
2020-04-30 16:36     ` Florian Weimer [this message]
2020-04-30 16:55       ` Mathieu Desnoyers
2020-04-30 17:07         ` Florian Weimer
2020-04-30 17:20           ` 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=878sidkk0z.fsf@oldenburg2.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=bmaurer@fb.com \
    --cc=boqun.feng@gmail.com \
    --cc=carlos@redhat.com \
    --cc=dalias@libc.org \
    --cc=davejwatson@fb.com \
    --cc=joseph@codesourcery.com \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=peterz@infradead.org \
    --cc=pjt@google.com \
    --cc=szabolcs.nagy@arm.com \
    --cc=tglx@linutronix.de \
    --cc=will.deacon@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.