Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp2049767ybz; Thu, 30 Apr 2020 09:58:36 -0700 (PDT) X-Google-Smtp-Source: APiQypLA/PwWLVeL57GFxp9lBbEwhGQ/lJCp1e9E5ufJd5TjlOMZCvnOIzGcSOgBZhBFrjHVPJ4T X-Received: by 2002:a50:bb6b:: with SMTP id y98mr3504028ede.296.1588265916188; Thu, 30 Apr 2020 09:58:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588265916; cv=none; d=google.com; s=arc-20160816; b=uj32Y+21B1R7e+8T7J2YW9IUVFSijLzlgTnsaPVMHEuut9xyK+fj0kYwZbj/sCIHi5 6obRmNk2mcdL1NQcrHoFf1dpB+H4VagzXCkptTRiMbjtMzmkXspo3BepPbYYRiZDz5OR w95mwBjOiifSd1sJFI7eJfcNTbhajrfZljoWewcWFCAwXUcp50xO5FU8UZ+l+ZIMUqla nGMlQbCu6frzK18sQ8c0wS33596XvyZRU0j4/gQC2jyMiDf1amy4Ie8Q+trU9rJVVUXl blNrUqmJJxOHyUlBYjj1urwvSUCa6Vb0/pN1JoT4lNav3D1vI3L3laRtS7o2BuBPJL6O XwPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature:dkim-filter; bh=Mp2N6YTybV9Yy+BQgTJKnPNXrZLjJEVr2GwPlCCPe5c=; b=AKjye+8pfaRe4UrDN/baWW/bEVGw4ZVTtp0u6TMwhfjKuTZZrJk4cPFHujfyHWKVHx ys9PRL9+Km0gTN4m4lbhTdKKaYA5QXPcAMVvZICtol1UdBzuJTIUI7sowLMBLcl8EB2d v32TuSyO3Wxkx+yno++3zd4d1jMyNQ/+/2ctCSi+bycNqKeZ1auBFVBXfgu5uAxl6TCk 0VsP1N/Tx8Y2kgPuOSEe5sZsdT3m2VdovH0G2G18ufrIQF+VG2Uyn9OUzUGMs+fA1XX6 Lifnw41pArrWyfYJsrwhb2kj+vI1TqfB3NQddpIo6BbPu0pOZVeNMxUvKyA13RpdjmRp Wa4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=P6ml2Iwz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si84558edc.351.2020.04.30.09.58.11; Thu, 30 Apr 2020 09:58:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=P6ml2Iwz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726515AbgD3Qz5 (ORCPT + 99 others); Thu, 30 Apr 2020 12:55:57 -0400 Received: from mail.efficios.com ([167.114.26.124]:49564 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726272AbgD3Qz4 (ORCPT ); Thu, 30 Apr 2020 12:55:56 -0400 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1588265755; bh=Mp2N6YTybV9Yy+BQgTJKnPNXrZLjJEVr2GwPlCCPe5c=; h=Date:From:To:Message-ID:MIME-Version; b=P6ml2Iwzx7dNVYFLxrkWSsVQThYw2dO3hAxklBIuoMnX1mQB+Y+TkBHjCIh/KOIiK 9BF34ObzvD7EE0Hr81wiv7OtYPzdGzJXdgqrla23Pz5l57swsihELEvq3+YXRQClmD 81+/l/Fs9ulbqJ73MQSBGcwOfmUe8AbfDdOMlfyXDnaSuFW047vhG9fsmbW+mLtMbc NtgKvA+1/SvxFlG9EBw4mryfTapc5isfKLWecPHz2sww9O0bRpma0OU09IM+lhT1/j ubLuTCXPy4/5jJfn2l/haVyrwneiGLCkA4es97pCEgtPeQk9956ziSJ7+Ktofw3NOA x0OenWRJfbIvw== 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== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- 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