Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1203737imm; Wed, 19 Sep 2018 14:03:22 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbhVHgyT7f8YgfZmqmIPGDTOgeKVBr9+7+97gofNpc1d3OOlMRRJMt52OfEMS43ERod8j7H X-Received: by 2002:a63:1b07:: with SMTP id b7-v6mr34064923pgb.444.1537391002524; Wed, 19 Sep 2018 14:03:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537391002; cv=none; d=google.com; s=arc-20160816; b=ADaTMUEqyPdPmwCBx/8ix8Lz2dDxTWd2qAVd0r0k4WMIKtlPTtttULo4JQdsa28+h1 +iN1GvWZR9FoAvXn3q2cYA3YdfUDlFrJfOClA8thpG8afYKOvoJyvYBhvg60YQKUFs7f yuRwKnCDd1ZZfrKpw2PkxeR/lL5ZephqxcJ9NAK5aAt+ai3o8kOZ+cw4QL85K0eOlYp9 csstXeZKBDIQfRQf/+XIqeBJ2/l0SCoH0yMQ20l7T8hIoyey9rmKpZ1Jr3a0ssRnpakO gUXTRRhj9Rrp6Y5oGlZ4H4gKXJs0+qvtgEUFvoHN4wfJPiuvzA2apw4+88XwFQ/O0Hvh SYcA== 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=PPqi4ua3SQpcWRLkxRbFFLNnhA+VogMRh1uZ5sTFFDA=; b=fowl5xF3IE6A4Vh7KAJQwwc09JtHeGrj4mGHhauyJkQQ1Q7Q/CZsnD2Cy/bWp2UDRt lw3v5WWmXx4jLCcWtiL54BbWoS6ZEOW+KsN3h8cLSXZOLcBMZm2o92LQNSSnsZW1YlXd OY9n3x6i0SVgGhlLqLL05E6YzYDqpKhWLPo5jhz1TYT/KkAHLGxQ+4fqOKDkv0bcxWFy ZS25BoN76yp8JOK1NQJM/YFsGaRA7QVOTRehc4NQZr3uIUt6rd7Qn9fiyPKRPwVzu0g/ 6GEgXovl/w9J20N5AgUNkcC/z0QhTGiuZO5umB2vxaPJ38wWKx0SCuqapWHWN7Ja+UjT d1sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=cpGXzsJS; 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 u11-v6si22230574pgg.683.2018.09.19.14.03.06; Wed, 19 Sep 2018 14:03:22 -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=cpGXzsJS; 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 S1733101AbeITClL (ORCPT + 99 others); Wed, 19 Sep 2018 22:41:11 -0400 Received: from mail.efficios.com ([167.114.142.138]:38846 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727781AbeITClK (ORCPT ); Wed, 19 Sep 2018 22:41:10 -0400 Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id 7D0C923F8E1; Wed, 19 Sep 2018 17:01:27 -0400 (EDT) Received: from mail.efficios.com ([IPv6:::1]) by localhost (mail02.efficios.com [IPv6:::1]) (amavisd-new, port 10032) with ESMTP id LEiAUoBpUIzJ; Wed, 19 Sep 2018 17:01:26 -0400 (EDT) Received: from localhost (ip6-localhost [IPv6:::1]) by mail.efficios.com (Postfix) with ESMTP id AD5BA23F8DE; Wed, 19 Sep 2018 17:01:26 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com AD5BA23F8DE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1537390886; bh=PPqi4ua3SQpcWRLkxRbFFLNnhA+VogMRh1uZ5sTFFDA=; h=Date:From:To:Message-ID:MIME-Version; b=cpGXzsJS9WnXrFeGaA2ZqIKEmo6Xp3E3k1aY9HLDU/LVzmecoIJaDHmpnqF48TVf4 PpMZXSplOlSMeRvUxZ69AY99+cK5uZNL8lGbpzPKRX1xfiMIFiSzsIsVi7OlKDhzAz oFE8zDgqfv0wwtNK/XL7nLRjPXfQneRyWQULuPWsWJgxzlHelw6mLphGV9VpMDZOhe hCupvZ7KV45ex+ILQHlh53GILjwYZ/C0VqVg1hQEc3/7RhBnzCYSyR/t0MagNK54fR FLbW22nRH3q90fuCvzLrmbj/f4NEabJNtVj5/ZJQZEH2AhWkZsZ1W7BNU3oI2rNxla ygWkKSDkMp8aA== 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 2h4-UX_ai-Ot; Wed, 19 Sep 2018 17:01:26 -0400 (EDT) Received: from mail02.efficios.com (mail02.efficios.com [167.114.142.138]) by mail.efficios.com (Postfix) with ESMTP id 95F7B23F8CC; Wed, 19 Sep 2018 17:01:26 -0400 (EDT) Date: Wed, 19 Sep 2018 17:01:26 -0400 (EDT) From: Mathieu Desnoyers To: Szabolcs Nagy Cc: carlos , Florian Weimer , nd , 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: <2052751374.8654.1537390886450.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20180919144438.1066-1-mathieu.desnoyers@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: gM/MBV+hIIWpXNC6c9G2xv/rGbnH9w== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ----- On Sep 19, 2018, at 1:38 PM, Szabolcs Nagy szabolcs.nagy@arm.com wrote: > On 19/09/18 15:44, Mathieu Desnoyers wrote: >> Things to consider: >> >> - Move __rseq_refcount to an extra field at the end of __rseq_abi to >> eliminate one symbol. This would require to wrap struct rseq into >> e.g. struct rseq_lib or such, e.g.: >> >> struct rseq_lib { >> struct rseq kabi; >> int refcount; >> }; >> >> All libraries/programs which try to register rseq (glibc, early-adopter >> applications, early-adopter libraries) should use the rseq refcount. >> It becomes part of the ABI within a user-space process, but it's not >> part of the ABI shared with the kernel per se. >> >> - Restructure how this code is organized so glibc keeps building on >> non-Linux targets. >> >> - We do not need an atomic increment/decrement for the refcount per >> se. Just being atomic with respect to the current thread (and nested >> signals) would be enough. What is the proper API to use there ? >> Should we expose struct rseq_lib in a public glibc header ? Should >> we create a rseq(3) man page ? >> >> - Revisit use of "weak" symbol for __rseq_abi in glibc. Perhaps we >> want a non-weak symbol there ? (and let all other early user >> libraries use weak) >> > > i don't think there is precedent for exposing tls symbol in glibc > (e.g. errno is exposed via __errno_location function) so there > might be issues with this (but i don't have immediate concerns). > >> diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c >> index fe75d04113..20ee197d94 100644 >> --- a/nptl/pthread_create.c >> +++ b/nptl/pthread_create.c >> @@ -52,6 +52,13 @@ static struct pthread *__nptl_last_event __attribute_used__; >> /* Number of threads running. */ >> unsigned int __nptl_nthreads = 1; >> >> +__attribute__((weak, tls_model("initial-exec"))) __thread >> +volatile struct rseq __rseq_abi = { >> + .cpu_id = RSEQ_CPU_ID_UNINITIALIZED, >> +}; >> + >> +__attribute__((weak, tls_model("initial-exec"))) __thread >> +volatile int __rseq_refcount; >> > > note that libpthread.so is built with -ftls-model=initial-exec Which would indeed make these annotations redundant. I'll remove them. > (and if it wasn't then you'd want to put the attribute on the > declaration in the internal header file, not on the definition, > so the actual tls accesses generate the right code) This area is one where I'm still uneasy on my comprehension of the details, especially that it goes in a different direction than what you are recommending. I've read through https://www.akkadia.org/drepper/tls.pdf Section 5 "Linker Optimizations" to try to figure it out, and I end up being under the impression that applying the tls_model("initial-exec") attribute to a symbol declaration in a header file does not have much impact on the accesses that use that variable. Reading through that section, it seems that the variable definition is the one that matters, and then the compiler/linker/loader are tweaking the sites that reference the TLS variable through code rewrite based on the most efficient mechanism that each phase knows can be used at each stage. What am I missing ? Thanks, Mathieu -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com