Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp4410052ybv; Tue, 25 Feb 2020 19:39:22 -0800 (PST) X-Google-Smtp-Source: APXvYqwov9qNYB+IfVuhoSSYsKbHkOcfO9WoQ0y74lkKfmCzSvTKhJMxz9GTKwzLHKtUc9QgOq3o X-Received: by 2002:a05:6808:346:: with SMTP id j6mr1640322oie.47.1582688362188; Tue, 25 Feb 2020 19:39:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582688362; cv=none; d=google.com; s=arc-20160816; b=sg0SZmbyw2P7bNPaKyReaesF96gvu4LIUmB/I7G1A/t5hyd7OU0WBts47DTmmWekdy JfBMBwEO3iybq5SHCnDu/4WgvWgHcZ75yTJSTgmWlM/LsIktJIpZpg01p9bT+3fTqrZF sqSz1SPns+Zgm+Sj8sQwPvX6qq1Mc//ZdzanARq1AcKkbSJRxmDcUlkyDK7nNdcC33pa iecK+orLbYva4JEDkQQII8AM2rqJQcFJgQnu5oQQnAVt+9Djns2vmjFm9p7v4Vm4/Go8 023SLkHEXgELbUjOXghmsF06Wti8UzpdxiCgRXWIxPyRSEk8iGhotTMiEg62EA7QOKZG bbKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=MUhme0us7XCJPh4wc0WtPdoMxGC3Hr7PgG+Bm4j+hk0=; b=L4eTtrBHsU94aIGXNzUI0g1Guy86fYF28/1zbBJn5P6ye5BJ387ZzTulx1L08DPV2O rVUlf77v3v2yJBZzpHk+eRBFJdnawoBtFoaX55gH/AFeFpjS0AolJBEssP/Jq+LBl4K/ XfYl0FLB5tTE0V4k09zgUG4ImEh5MrLxTc2z2xACH7tytrHZyJ7u0GBNahPbRujJYnP2 L/53vj1cm48qTwnpp8D0NgeyMpx+Mn/xcZB5XRrly9ovuFCNLx37KIeXGef1CvjMM8CU UYazhKSs7iz0HaCtmfzv9WkgJLE/wZpbWxYje/njUlUktWysaHTW0OIHQ712jOlVtoZW DogQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Nl+fis2g; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si423461oid.150.2020.02.25.19.39.09; Tue, 25 Feb 2020 19:39:22 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=Nl+fis2g; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726417AbgBZDiv (ORCPT + 99 others); Tue, 25 Feb 2020 22:38:51 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:37317 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbgBZDiu (ORCPT ); Tue, 25 Feb 2020 22:38:50 -0500 Received: by mail-wr1-f66.google.com with SMTP id l5so1187723wrx.4 for ; Tue, 25 Feb 2020 19:38:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=MUhme0us7XCJPh4wc0WtPdoMxGC3Hr7PgG+Bm4j+hk0=; b=Nl+fis2gOaoRx3SrTeUUI8sONp5Gdnq27Eg2dVwY/dTetlfPvUy434M2LBm9eRA8K3 vcshKxtpCxmJzId+GiDLWBG8skdcwoK8I6TLRDcTXAnqHIsH48tqooV9HxLglGu/6OxE peayvXv5V0qpu2GZHAB5CLyYfuV5OQ1P7uOE7PpTC6nlIMj1V3vtmqXpQG9iZzUlPPgz iwIoyMUcdZRljpIfSfp/JG/eUBZTQPetkwlWv0qVBsgD3zBFUCgneDl24XzI6elAhBva DqeTdJx7ozOW3ODjFz8JX1VIUTnNq+CgQI0bWQvPdOCWCJthOAs9s/UZ53AH2s3mEXLS iSgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=MUhme0us7XCJPh4wc0WtPdoMxGC3Hr7PgG+Bm4j+hk0=; b=iZq1BNdTBWpIbSABUsBYDItF0Qxw1DXzEZUa6nJpIfPvLxhxVN4yyVF8KFOCa2NMkE T00XjnsTS/9212jbGDB8KN7P3fo3kDZOtMw6QaMkeDiFP7sFaQ0KMrYyvMoa895bLZVl 9ZWazI23zQLq/0eL5quxb7FK9R/8e6m6aiuqgGPK/vt16GB8B8TKwVKoUKbHqD+spcc/ BAuZpyU/xwmv+9VonAKBaHDt6rZg6flxrzTwqPDWIQW5jIRyYl2EI6gXqP8vaSJXaO9v dsxUOcaA1NSaNS00JGaUHO/R7sOLidM2UMHC2yVlHrYmH81MlB7x7DC/d3bts6snXaM8 zB2Q== X-Gm-Message-State: APjAAAVIGmwUm0x+x9VlZx1hPqYCK/BzhoeJFJT+hW4aLjbnt5FY4iAn VbW5vqUqlJ3Y8XaoFrKU/UZxrkZ6QxLXnIlqKtUeDw== X-Received: by 2002:adf:e40f:: with SMTP id g15mr2574118wrm.223.1582688328104; Tue, 25 Feb 2020 19:38:48 -0800 (PST) MIME-Version: 1.0 References: <1503467992.2999.1582234410317.JavaMail.zimbra@efficios.com> <20200221154923.GC194360@google.com> <1683022606.3452.1582301632640.JavaMail.zimbra@efficios.com> In-Reply-To: From: Chris Kennelly Date: Tue, 25 Feb 2020 22:38:37 -0500 Message-ID: Subject: Re: Rseq registration: Google tcmalloc vs glibc To: Joel Fernandes Cc: Mathieu Desnoyers , Paul Turner , Florian Weimer , "Carlos O'Donell" , libc-alpha , linux-kernel , Peter Zijlstra , paulmck , Boqun Feng , Brian Geffon Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 25, 2020 at 10:25 PM Joel Fernandes wrote: > > On Fri, Feb 21, 2020 at 11:13 AM Mathieu Desnoyers > wrote: > > > > ----- On Feb 21, 2020, at 10:49 AM, Joel Fernandes, Google joel@joelfernandes.org wrote: > > > > [...] > > >> > > >> 3) Use the __rseq_abi TLS cpu_id field to know whether Rseq has been > > >> registered. > > >> > > >> - Current protocol in the most recent glibc integration patch set. > > >> - Not supported yet by Linux kernel rseq selftests, > > >> - Not supported yet by tcmalloc, > > >> > > >> Use the per-thread state to figure out whether each thread need to register > > >> Rseq individually. > > >> > > >> Works for integration between a library which exists for the entire lifetime > > >> of the executable (e.g. glibc) and other libraries. However, it does not > > >> allow a set of libraries which are dlopen'd/dlclose'd to co-exist without > > >> having a library like glibc handling the registration present. > > > > > > Mathieu, could you share more details about why during dlopen/close > > > libraries we cannot use the same __rseq_abi TLS to detect that rseq was > > > registered? > > > > Sure, > > > > A library which is only loaded and never closed during the execution of the > > program can let the kernel implicitly unregister rseq at thread exit. For > > the dlopen/dlclose use-case, we need to be able to explicitly unregister > > each thread's __rseq_abi which sit in a library which is going to be > > dlclose'd. > > Mathieu, Thanks a lot for the explanation, it makes complete sense. It > sounds from Chris's reply that tcmalloc already checks > __rseq_abi.cpu_id and is not dlopened/closed. Considering these, it > seems to already handle things properly - CMIIW. I'll make a note about this, since we can probably benefit from some more comments about the assumptions/invariants the fastpath uses. > Chris, Brian, is there any other concern to upgrading of tcmalloc > version in ChromeOS? I believe there was some concern about detection > of rseq kernel support. A quick look at tcmalloc shows it does not do > such detection, but I can stand corrected. The build time configuration is because we need to have an assembly implementation of the restartable sequence (example: x86_64 [https://github.com/google/tcmalloc/blob/master/tcmalloc/internal/percpu_rseq_x86_64.S]), although I've been moving these to inline assembly recently. If we have build time support for the code path, we'll try to invoke the rseq() call and see if registration succeeds: https://github.com/google/tcmalloc/blob/master/tcmalloc/internal/percpu.cc#L85-L107 > One more thing, currently > tcmalloc does not use rseq on ARM. If I recall, ARM does have rseq > support as well. So we ought to enable it for that arch as well if > possible. Why not enable it on all arches and then dynamically detect > at runtime if needed support is available? As far as ARM support goes for TCMalloc's per-CPU/rseq path, I haven't had the bandwidth to write an assembly implementation (although I'd welcome one). Thanks, Chris Kennelly