Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp11697imm; Fri, 21 Sep 2018 09:29:50 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZZ6lFDL/mAbnnbVSbDadE0LlRXYduBFktlIWja0jopCN5Lr48H1iUYFRvoju7+RmiGLEm8 X-Received: by 2002:a62:868b:: with SMTP id x133-v6mr47567842pfd.252.1537547390016; Fri, 21 Sep 2018 09:29:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537547389; cv=none; d=google.com; s=arc-20160816; b=ENVNSqq3q5j0bTnzIrc1Qed9PGVWjKeCMz+CthUmdmf2EJlJARbWDOhvVuqeQro/5z R/4YgqapKFyLQjhYwYRng3UOFNFV+mO59SiLO8hdNrya1ZRZ4yDCgbQsYuBBIkKbDcDX MCsdzPECgQ6p07peDO4naR0PmhV6iBsnQZ0G71//bWT067DLiT6fksRk5Shv0InwFHxS PnCLJtfu19q35x/icOyM2/+kj3a8pUWcbBsjzNMXZmvLFDqWFR9hO+oxMWpiT2xDaCbg hgkZ2E97dU5Sxl0vV/IrC5gQ9NeJ90k2B34ZJqyoPon+BZBjIs5ltSpSbj2SzSSQq2sa IaIA== 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=KfMgBTAiikeLS4UMOVsKNbkuRGim7g93fkFtNITs0CY=; b=TA3kjBnpGByrwwrsUV2SnLqVjqj5T6nQWlVE4zUfNUNgtCDUkCVWI736ae6rVxvxEI 88ZP54pZJUy8ZnQVBT4or1SucC6xTIMC67k+brnhjzeJIxL+toHTaZguM7XqzF18D319 EPpO2k5nkqjVR2I1m2XLDRhjIitSMUz+3fZ5r5xo0ngMwZTiuUKVs2BQXaZwcmY0k3c8 FqfIXJI7k+xf6ZKEA2nfiAE3vmnoDno1nP3weruuGF0fGH7pT72Tq8ECpOLZomy4a3s2 GcHNO3oLI/2hVA3MBeLPOf3aubS3lzO9hdTJwqMvFUDhdWMPr+80j6RM8sYCCfb4NBvg nrug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b="q5Np1/Hj"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id r20-v6si22397363pgk.207.2018.09.21.09.29.33; Fri, 21 Sep 2018 09:29:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b="q5Np1/Hj"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S2390405AbeIUWTF (ORCPT + 99 others); Fri, 21 Sep 2018 18:19:05 -0400 Received: from mail.efficios.com ([167.114.142.138]:54304 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389545AbeIUWTF (ORCPT ); Fri, 21 Sep 2018 18:19:05 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 76E532408DA; Fri, 21 Sep 2018 12:29:25 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id 6VevwSoySJ-r; Fri, 21 Sep 2018 12:29:24 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 8B8862408D3; Fri, 21 Sep 2018 12:29:24 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 8B8862408D3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1537547364; bh=KfMgBTAiikeLS4UMOVsKNbkuRGim7g93fkFtNITs0CY=; h=Date:From:To:Message-ID:MIME-Version; b=q5Np1/Hj4OHfvYPlfBoiOtQKdxKrFK3RAlVSCXOPY2CWtWF2mkRoXUIk2N9sKd6no QvdBDE/k8tRo+bnIWipldIi/JbzWqQUbNDkl4PeQg7AbrUWsBMbr0djtVPYTVbJV8q FhwMZAbFyvKUAk3NYJn0Kn0VK4Tu6lHC7eONYFYbGXMVzCTXjXD8xXrfzIdp+nLkaf RCBi1Fy+c9Fc0ulPoJA/pe8Z3LFrFJooNGyxXpSsAcclUfztCsG0olTZfnxerjJvAR 3lZdQvghuAkLkGfHHK/XpFDftD2YwkyYhZq8IptwJkWawGxyw4gVoh7RZRMX38xJnX cCZpwBcbbuAxg== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10026) with ESMTP id uW-upZBmzasc; Fri, 21 Sep 2018 12:29:24 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 728BF2408CA; Fri, 21 Sep 2018 12:29:24 -0400 (EDT) Date: Fri, 21 Sep 2018 12:29:24 -0400 (EDT) From: Mathieu Desnoyers To: Joseph Myers Cc: carlos , Florian Weimer , Thomas Gleixner , Ben Maurer , Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Will Deacon , Dave Watson , Paul Turner , libc-alpha , linux-kernel , linux-api Message-ID: <1370210961.9271.1537547364295.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20180919144438.1066-1-mathieu.desnoyers@efficios.com> <67473000.8399.1537375994645.JavaMail.zimbra@efficios.com> <1619649568.9014.1537474457166.JavaMail.zimbra@efficios.com> Subject: Re: [RFC PATCH] glibc: Perform rseq(2) registration at nptl init and thread creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.138] X-Mailer: Zimbra 8.8.9_GA_3019 (ZimbraWebClient - FF52 (Linux)/8.8.9_GA_3019) Thread-Topic: glibc: Perform rseq(2) registration at nptl init and thread creation Thread-Index: yIFg5vgy/fXCjSInfG+u1JXvEBmAUg== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Sep 20, 2018, at 4:20 PM, Joseph Myers joseph@codesourcery.com wrote: > On Thu, 20 Sep 2018, Mathieu Desnoyers wrote: > >> Are you saying glibc has an explicit check for the kernel version visible >> from /proc before using specific features ? If so, how can this work with >> the variety of feature backports we find in the distribution kernels out >> there ? > > See sysdeps/unix/sysv/linux/dl-sysdep.c and > sysdeps/unix/sysv/linux/dl-osinfo.h. As I said, Carlos has proposed > removing that check. For the system calls I implement and maintain, I typically ensure there is a set of parameters that can be used when issuing the system call so it can either succeed or fail with ENOSYS without having side-effects. It's specifically meant to be used for feature discovery in a library initialization phase. It's especially useful if the application needs to keep state around related to the system call across its execution, e.g. robust futexes. > >> For too-old headers at compile time, one possibility is that we don't event >> expose the __rseq_abi TLS symbol. OTOH, if we need to keep exposing it anyway >> for ABI consistency purposes, then we'd leave its cpu_id field at the initial >> value (-1). But that would require that we copy linux/rseq.h into the glibc >> source tree. > > The ABI needs to be independent of the kernel headers used. I don't think > you need to copy linux/rseq.h; all you should need is to e.g. define an > array of suitable size and alignment with the relevant member initialized > and a suitable explanatory comment. In that case, I'm thinking declaring a minimal structure in glibc code may be clearer than the array, e.g.: [pthreadP.h] enum libc_rseq_cpu_id_state { LIBC_RSEQ_CPU_ID_UNINITIALIZED = -1, LIBC_RSEQ_CPU_ID_REGISTRATION_FAILED = -2, }; /* linux/rseq.h defines struct rseq as aligned on 32 bytes. The kernel ABI size is 20 bytes. For support of multiple rseq users within a process, user-space defines an extra 4 bytes field as a reference count, for a total of 24 bytes. */ struct libc_rseq { /* kernel-userspace ABI. */ uint32_t cpu_id_start; uint32_t cpu_id; uint64_t rseq_cs; uint32_t flags; /* user-space ABI. */ uint32_t refcount; } __attribute__((aligned(4 * sizeof(uint64_t)))); [pthread_create.h] __thread volatile struct libc_rseq __rseq_abi = { .cpu_id = LIBC_RSEQ_CPU_ID_UNINITIALIZED, }; Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com