Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3112973imu; Fri, 23 Nov 2018 21:52:50 -0800 (PST) X-Google-Smtp-Source: AFSGD/VQlXY0t8Q1aOWJ47AfjVuoFTwJbBRtHHoMU/5RGadPRZVP9R0S27d+TfsaodM17K4qrwW2 X-Received: by 2002:a65:47ca:: with SMTP id f10mr17225309pgs.166.1543038770203; Fri, 23 Nov 2018 21:52:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543038770; cv=none; d=google.com; s=arc-20160816; b=UPkOpcdd5mZaQovDpptzYDlKkGOOkBPJ3rJn/dL/iNDeN74cFnMmNWgCVNX4WEectb pEZ1qVBGN+BhGYlID61On8Bp2CWSVE6TnOj7T+7rXoXiSWrGWB0rI6rYnO5kXbBz8Ngc NH3jiHDTymTqet+00c1A0GmH3hBet0p3XzDuhyevOL46sFpzdTek1lSYS+NIRmv/i2Ob vAgRFJuACLbgrXKivGdq58yRRL0iBDTGZMvaI4um+6YT/R8bHIR2ROzDtxC5ayNchJ4p 8RA3fxQRl9LEVYczLTXeGcJPHXW5HDuT6iSJqWwPW1loI62AGSwqNd1LcwJokxxklKQN kAJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :in-reply-to:date:references:subject:cc:to:from; bh=jXHPh2RG1kEtnNbXjZTuPlO9l272AsRFe2Gzo0ix4iE=; b=pGCbLPzWEjiE+rtje/lPKeg6MtzGqQ9XabK5er0GaSrCs0tOXgRJz9C4LN+6tU3q0f kzmh2MbRHdffgZtX7tSwVh68MNGaCq2YHCgp8DLyRVWJfGUbmkqUPgUSx1WeC1qALj/M 8tJY7p0tUlQ8OW8fxsvqmrrbBqKlT550lkPDY9zcTC+9ZrNsmA95fj0R+TeqFG/Upr5S WfjVn74voh8STeVjcKh4tDsrbmjBSvga+2JjuGncAh77CKw+SYMKlhYwuqv4EP92xeQk Aqdz+TUxgCaMXuY08h69xh/FDmvR5HiN63/19gAJj2FNqTRe83/kbua0HgjFN4sqygY2 DESA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q14si54782943pgg.433.2018.11.23.21.51.42; Fri, 23 Nov 2018 21:52:50 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438155AbeKWDJD (ORCPT + 99 others); Thu, 22 Nov 2018 22:09:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42790 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389228AbeKWDJB (ORCPT ); Thu, 22 Nov 2018 22:09:01 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8680530001E5; Thu, 22 Nov 2018 16:28:56 +0000 (UTC) Received: from oldenburg.str.redhat.com (ovpn-116-170.ams2.redhat.com [10.36.116.170]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0E8E8413B; Thu, 22 Nov 2018 16:28:49 +0000 (UTC) From: Florian Weimer To: Mathieu Desnoyers Cc: Rich Felker , carlos , Joseph Myers , Szabolcs Nagy , libc-alpha , Thomas Gleixner , Ben Maurer , Peter Zijlstra , "Paul E. McKenney" , Boqun Feng , Will Deacon , Dave Watson , Paul Turner , linux-kernel , linux-api Subject: Re: [RFC PATCH v4 1/5] glibc: Perform rseq(2) registration at nptl init and thread creation References: <20181121183936.8176-1-mathieu.desnoyers@efficios.com> <20181122143603.GD23599@brightrain.aerifal.cx> <782067422.9852.1542899056778.JavaMail.zimbra@efficios.com> <20181122151444.GE23599@brightrain.aerifal.cx> <686626451.10113.1542901620250.JavaMail.zimbra@efficios.com> Date: Thu, 22 Nov 2018 17:28:42 +0100 In-Reply-To: <686626451.10113.1542901620250.JavaMail.zimbra@efficios.com> (Mathieu Desnoyers's message of "Thu, 22 Nov 2018 10:47:00 -0500 (EST)") Message-ID: <87wop5xeit.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 22 Nov 2018 16:28:56 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Mathieu Desnoyers: > Here is one scenario: we have 2 early adopter libraries using rseq which > are deployed in an environment with an older glibc (which does not > support rseq). > > Of course, none of those libraries can be dlclose'd unless they somehow > track all registered threads. Well, you can always make them NODELETE so that dlclose is not an issue. If the library is small enough, that shouldn't be a problem. > But let's focus on how exactly those libraries can handle lazily > registering rseq. They can use pthread_key, and pthread_setspecific on > first use by the thread to setup a destructor function to be invoked > at thread exit. But each early adopter library is unaware of the > other, so if we just use a "is_initialized" flag, the first destructor > to run will unregister rseq while the second library may still be > using it. I don't think you need unregistering if the memory is initial-exec TLS memory. Initial-exec TLS memory is tied directly to the TCB and cannot be freed while the thread is running, so it should be safe to put the rseq area there even if glibc knows nothing about it. Then you'll only need a mechanism to find the address of the actually active rseq area (which you probably have to store in a TLS variable for performance reasons). And that part you need whether you have reference counter or not. > The same problem arises if we have an application early adopter which > explicitly deal with rseq, with a library early adopter. The issue is > similar, except that the application will explicitly want to unregister > rseq before exiting the thread, which leaves a race window where rseq > is unregistered, but the library may still need to use it. > > The reference counter solves this: only the last rseq user for a thread > performs unregistration. If you do explicit unregistration, you will run into issues related to destructor ordering. You should really find a way to avoid that. Thanks, Florian