From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id EADC93945C30 for ; Fri, 17 Jul 2020 20:07:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org EADC93945C30 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06HK4aUw090561 for ; Fri, 17 Jul 2020 16:07:58 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 32b8k39pwb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 17 Jul 2020 16:07:58 -0400 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 06HK4mgQ091683 for ; Fri, 17 Jul 2020 16:07:57 -0400 Received: from ppma04wdc.us.ibm.com (1a.90.2fa9.ip4.static.sl-reverse.com [169.47.144.26]) by mx0a-001b2d01.pphosted.com with ESMTP id 32b8k39pw1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 16:07:57 -0400 Received: from pps.filterd (ppma04wdc.us.ibm.com [127.0.0.1]) by ppma04wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06HK5GI4012984; Fri, 17 Jul 2020 20:07:56 GMT Received: from b03cxnp08027.gho.boulder.ibm.com (b03cxnp08027.gho.boulder.ibm.com [9.17.130.19]) by ppma04wdc.us.ibm.com with ESMTP id 327529kh1u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 20:07:56 +0000 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 06HK7rQL28377810 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jul 2020 20:07:53 GMT Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A239FC605B; Fri, 17 Jul 2020 20:07:55 +0000 (GMT) Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5999FC6059; Fri, 17 Jul 2020 20:07:54 +0000 (GMT) Received: from localhost.localdomain (unknown [9.160.98.244]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 17 Jul 2020 20:07:53 +0000 (GMT) Subject: Re: [PATCH v2] elf: Change TLS static surplus default back to 1664 To: Florian Weimer , libc-alpha@sourceware.org References: <87eepaqsgk.fsf@oldenburg2.str.redhat.com> From: Matheus Castanho Message-ID: <0b9d66d1-0f8b-3baf-4764-c996f56ca797@linux.ibm.com> Date: Fri, 17 Jul 2020 17:07:47 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 In-Reply-To: <87eepaqsgk.fsf@oldenburg2.str.redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-07-17_09:2020-07-17, 2020-07-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 impostorscore=0 bulkscore=0 clxscore=1015 priorityscore=1501 phishscore=0 malwarescore=0 lowpriorityscore=0 suspectscore=0 adultscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007170136 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 17 Jul 2020 20:08:00 -0000 Hi Florian, Thank you for taking a look at this. I confirm this patch fixes the issues on powerpc, powerpc64 and powerpc64le. -- Matheus Castanho On 7/17/20 8:41 AM, Florian Weimer via Libc-alpha wrote: > Make the computation in elf/dl-tls.c more transparent, and add > an explicit test for the historic value. > > --- > elf/Makefile | 4 +++- > elf/dl-tls.c | 37 ++++++++++++++++++++++++++++++------- > elf/tst-tls-surplus.c | 42 ++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 75 insertions(+), 8 deletions(-) > > diff --git a/elf/Makefile b/elf/Makefile > index a2c3b12007..0b78721848 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -216,7 +216,7 @@ tests-internal += loadtest unload unload2 circleload1 \ > neededtest neededtest2 neededtest3 neededtest4 \ > tst-tls3 tst-tls6 tst-tls7 tst-tls8 tst-dlmopen2 \ > tst-ptrguard1 tst-stackguard1 tst-libc_dlvsym \ > - tst-create_format1 > + tst-create_format1 tst-tls-surplus > tests-container += tst-pldd tst-dlopen-tlsmodid-container \ > tst-dlopen-self-container > test-srcs = tst-pathopt > @@ -1794,3 +1794,5 @@ $(objpfx)tst-tls-ie-dlmopen.out: \ > $(objpfx)tst-tls-ie-mod4.so \ > $(objpfx)tst-tls-ie-mod5.so \ > $(objpfx)tst-tls-ie-mod6.so > + > +$(objpfx)tst-tls-surplus: $(libdl) > diff --git a/elf/dl-tls.c b/elf/dl-tls.c > index 9a17427047..9fa62f5d22 100644 > --- a/elf/dl-tls.c > +++ b/elf/dl-tls.c > @@ -54,13 +54,37 @@ > Audit modules use their own namespaces, they are not included in rtld.nns, > but come on top when computing the number of namespaces. */ > > -/* Size of initial-exec TLS in libc.so. */ > -#define LIBC_IE_TLS 160 > +/* Size of initial-exec TLS in libc.so. This should be the maximum of > + observed PT_GNU_TLS sizes across all architectures. Some > + architectures have lower values due to differences in type sizes > + and link editor capabilities. */ > +#define LIBC_IE_TLS 144 > + > /* Size of initial-exec TLS in libraries other than libc.so. > This should be large enough to cover runtime libraries of the > compiler such as libgomp and libraries in libc other than libc.so. */ > #define OTHER_IE_TLS 144 > > +/* Default number of namespaces. */ > +#define DEFAULT_NNS 4 > + > +/* Default for dl_tls_static_optional. */ > +#define OPTIONAL_TLS 512 > + > +/* Compute the static TLS surplus based on the namespace count and the > + TLS space that can be used for optimizations. */ > +static inline int > +tls_static_surplus (int nns, int opt_tls) > +{ > + return (nns - 1) * LIBC_IE_TLS + nns * OTHER_IE_TLS + opt_tls; > +} > + > +/* This value is chosen so that with default values for the tunables, > + the computation of dl_tls_static_surplus in > + _dl_tls_static_surplus_init yields the historic value 1664, for > + backwards compatibility. */ > +#define LEGACY_TLS (1664 - tls_static_surplus (DEFAULT_NNS, OPTIONAL_TLS)) > + > /* Calculate the size of the static TLS surplus, when the given > number of audit modules are loaded. Must be called after the > number of audit modules is known and before static TLS allocation. */ > @@ -74,8 +98,8 @@ _dl_tls_static_surplus_init (size_t naudit) > opt_tls = TUNABLE_GET (optional_static_tls, size_t, NULL); > #else > /* Default values of the tunables. */ > - nns = 4; > - opt_tls = 512; > + nns = DEFAULT_NNS; > + opt_tls = OPTIONAL_TLS; > #endif > if (nns > DL_NNS) > nns = DL_NNS; > @@ -85,9 +109,8 @@ _dl_tls_static_surplus_init (size_t naudit) > nns += naudit; > > GL(dl_tls_static_optional) = opt_tls; > - GLRO(dl_tls_static_surplus) = ((nns - 1) * LIBC_IE_TLS > - + nns * OTHER_IE_TLS > - + opt_tls); > + assert (LEGACY_TLS >= 0); > + GLRO(dl_tls_static_surplus) = tls_static_surplus (nns, opt_tls) + LEGACY_TLS; > } > > /* Out-of-memory handler. */ > diff --git a/elf/tst-tls-surplus.c b/elf/tst-tls-surplus.c > new file mode 100644 > index 0000000000..b0dea0b5ee > --- /dev/null > +++ b/elf/tst-tls-surplus.c > @@ -0,0 +1,42 @@ > +/* Test size of the static TLS surplus reservation for backwards compatibility. > + Copyright (C) 2020 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > +#include > + > +static int do_test (void); > +#include > + > +/* This hack results in a definition of struct rtld_global_ro. Do > + this after all the other header inclusions, to minimize the > + impact. */ > +#define SHARED > +#include > + > +static > +int do_test (void) > +{ > + /* Avoid introducing a copy relocation due to the hidden alias in > + ld.so. */ > + struct rtld_global_ro *glro = xdlsym (NULL, "_rtld_global_ro"); > + printf ("info: _dl_tls_static_surplus: %zu\n", glro->_dl_tls_static_surplus); > + /* Hisoric value: 16 * 100 + 64. */ > + TEST_VERIFY (glro->_dl_tls_static_surplus >= 1664); > + return 0; > +} >