From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by sourceware.org (Postfix) with ESMTPS id D85623898529 for ; Thu, 30 Apr 2020 16:55:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org D85623898529 Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 7276B29019A; Thu, 30 Apr 2020 12:55:55 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id R5cw2QtpS93e; Thu, 30 Apr 2020 12:55:55 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 23F64290199; Thu, 30 Apr 2020 12:55:55 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 23F64290199 X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id GXJtEnICMaN0; Thu, 30 Apr 2020 12:55:55 -0400 (EDT) Received: from mail03.efficios.com (mail03.efficios.com [167.114.26.124]) by mail.efficios.com (Postfix) with ESMTP id 0F11629021D; Thu, 30 Apr 2020 12:55:55 -0400 (EDT) Date: Thu, 30 Apr 2020 12:55:54 -0400 (EDT) From: Mathieu Desnoyers To: Florian Weimer Cc: carlos , Joseph Myers , Szabolcs Nagy , libc-alpha , Thomas Gleixner , Ben Maurer , Peter Zijlstra , Paul , Boqun Feng , Will Deacon , Dave Watson , Paul Turner , Rich Felker , linux-kernel , linux-api Message-ID: <1972833271.77975.1588265754974.JavaMail.zimbra@efficios.com> In-Reply-To: <878sidkk0z.fsf@oldenburg2.str.redhat.com> References: <20200428171513.22926-1-mathieu.desnoyers@efficios.com> <875zdhmaft.fsf@oldenburg2.str.redhat.com> <1287616647.77866.1588263099045.JavaMail.zimbra@efficios.com> <878sidkk0z.fsf@oldenburg2.str.redhat.com> Subject: Re: [RFC PATCH glibc 1/3] glibc: Perform rseq(2) registration at C startup and thread creation (v18) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.26.124] X-Mailer: Zimbra 8.8.15_GA_3918 (ZimbraWebClient - FF75 (Linux)/8.8.15_GA_3895) Thread-Topic: glibc: Perform rseq(2) registration at C startup and thread creation (v18) Thread-Index: vkaNGJYbQ5to7FGk5na6JixiLNcPYQ== X-Spam-Status: No, score=-15.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Thu, 30 Apr 2020 16:55:57 -0000 ----- On Apr 30, 2020, at 12:36 PM, Florian Weimer fweimer@redhat.com wrote: > * Mathieu Desnoyers: > [...] > >>>> + 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. If we go this way, I'd also recommend to treat any situation where __rseq_abi.cpu_id is already initialized as a fatal error. Does the code below seem OK to you ? static inline void rseq_register_current_thread (void) { int ret; if (__rseq_abi.cpu_id != RSEQ_CPU_ID_UNINITIALIZED) __libc_fatal ("rseq already initialized for this thread\n"); ret = INTERNAL_SYSCALL_CALL (rseq, &__rseq_abi, sizeof (struct rseq), 0, RSEQ_SIG); if (INTERNAL_SYSCALL_ERROR_P (ret)) { if (INTERNAL_SYSCALL_ERRNO (ret) == EBUSY) __libc_fatal ("rseq already registered for this thread\n"); __rseq_abi.cpu_id = RSEQ_CPU_ID_REGISTRATION_FAILED; } } Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com