From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2047.outbound.protection.outlook.com [40.107.21.47]) by sourceware.org (Postfix) with ESMTPS id B34D53858D20 for ; Tue, 29 Aug 2023 14:10:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B34D53858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2xQcY0BA1isdTeBrbPTzweXyIYhcLu6MiIoWlvR62w4=; b=beRbDHEy+vNHHfG4wCNdvokhrqcB9IcbtmhW99gIzd7q3/n/5+3f/g5J1Gxc383NsBeSgNHqMpYZUk4M5wKow+uXcpMue2e8LWIcn44tHWohpvhUBv6U9Z0XnnNTCRDOzxRLhQ4r799vLXEApNcuWLDIcspK6D4xYJVNs4Bgx5Q= Received: from DB3PR08CA0008.eurprd08.prod.outlook.com (2603:10a6:8::21) by DB9PR08MB8580.eurprd08.prod.outlook.com (2603:10a6:10:3d3::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.34; Tue, 29 Aug 2023 14:10:11 +0000 Received: from DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com (2603:10a6:8:0:cafe::23) by DB3PR08CA0008.outlook.office365.com (2603:10a6:8::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.35 via Frontend Transport; Tue, 29 Aug 2023 14:10:11 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 63.35.35.123) smtp.mailfrom=arm.com; dkim=pass (signature was verified) header.d=armh.onmicrosoft.com;dmarc=pass action=none header.from=arm.com; Received-SPF: Pass (protection.outlook.com: domain of arm.com designates 63.35.35.123 as permitted sender) receiver=protection.outlook.com; client-ip=63.35.35.123; helo=64aa7808-outbound-1.mta.getcheckrecipient.com; pr=C Received: from 64aa7808-outbound-1.mta.getcheckrecipient.com (63.35.35.123) by DBAEUR03FT008.mail.protection.outlook.com (100.127.142.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.20 via Frontend Transport; Tue, 29 Aug 2023 14:10:11 +0000 Received: ("Tessian outbound 1eb4e931b055:v175"); Tue, 29 Aug 2023 14:10:11 +0000 X-CheckRecipientChecked: true X-CR-MTA-CID: 790ad149ddff0ab6 X-CR-MTA-TID: 64aa7808 Received: from c6920fb8b782.1 by 64aa7808-outbound-1.mta.getcheckrecipient.com id C0B5B5BD-030C-403C-BD92-652E0326B30F.1; Tue, 29 Aug 2023 14:10:05 +0000 Received: from EUR05-AM6-obe.outbound.protection.outlook.com by 64aa7808-outbound-1.mta.getcheckrecipient.com with ESMTPS id c6920fb8b782.1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384); Tue, 29 Aug 2023 14:10:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YcuMijUXAalpSSLjLiZcgQPVCMCoI8Me+iAVoeMSSnBafoCzacgjod45qQpUPO3+sr7BpJKhFBeNxklmNnHtVrxf2iixGnkafGBdu3BD3r0R5NYCqoeIjeTCLzv9fG0Od+5vKeAzPajbvd/hTy/E1RDn7CAN9i9cb9/4IaW1UMGHEjnyjwtLZQcKnLeqG0UUO+2WtLv3OsOIYrdeVbODW6wIXAO9mw+eCw+W0r31EtFdTQ48BLeMlZRYuPKNzn1HeQBpTzGKAREXmXxobzi5w/uEqnpdzExUsnMaB1cRteAvuoQJFhShTfJzb9bQh5raC0RLgd3Ix9rOCUq3hx02TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=2xQcY0BA1isdTeBrbPTzweXyIYhcLu6MiIoWlvR62w4=; b=n7bwCEV/Tp8lRfVCwM3i4bk5QEMN+DycTTEqLG3ByfJh8+4K5A2Eyv1qEB6Yh7wYQuDgMcSzIbXjCSxlvVRefmAFkY6Cg7k6kXU1L75cI6FwAOWu5ujr587J3ku9Sw3HXFVakN6sJwZgEplUV9r/Bfpicm89m0XZxNbFda5rW15+m7ZvV7RiFWepFQHtYNPcrcM7mfoT2quCVZclEFk2AhuY1AOzYHI4P/AQyWPuvxokYPS+FdHY4Hfgm2YzKHnJnQx5D5j/Pq8aiTHoLlB4RKPi/Pn/GNqmwN7JoFUg7SHnWfZ/fojbzrG24/DR3RMteleXAF7yORXah0kphdHyGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=2xQcY0BA1isdTeBrbPTzweXyIYhcLu6MiIoWlvR62w4=; b=beRbDHEy+vNHHfG4wCNdvokhrqcB9IcbtmhW99gIzd7q3/n/5+3f/g5J1Gxc383NsBeSgNHqMpYZUk4M5wKow+uXcpMue2e8LWIcn44tHWohpvhUBv6U9Z0XnnNTCRDOzxRLhQ4r799vLXEApNcuWLDIcspK6D4xYJVNs4Bgx5Q= Authentication-Results-Original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; Received: from DB9PR08MB7179.eurprd08.prod.outlook.com (2603:10a6:10:2cc::19) by DB4PR08MB9261.eurprd08.prod.outlook.com (2603:10a6:10:3fa::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6699.34; Tue, 29 Aug 2023 14:10:03 +0000 Received: from DB9PR08MB7179.eurprd08.prod.outlook.com ([fe80::adb0:61cb:8733:6db2]) by DB9PR08MB7179.eurprd08.prod.outlook.com ([fe80::adb0:61cb:8733:6db2%7]) with mapi id 15.20.6699.034; Tue, 29 Aug 2023 14:10:03 +0000 Date: Tue, 29 Aug 2023 15:09:48 +0100 From: Szabolcs Nagy To: Adhemerval Zanella Netto , libc-alpha@sourceware.org, Paul Zimmermann Subject: Re: [PATCH v3] elf: Fix slow tls access after dlopen [BZ #19924] Message-ID: References: <20230106185250.2936935-1-szabolcs.nagy@arm.com> <087abdd6-0db7-102c-6fdf-8a6c968f8371@linaro.org> Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <087abdd6-0db7-102c-6fdf-8a6c968f8371@linaro.org> X-ClientProxiedBy: LO2P265CA0212.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:9e::32) To DB9PR08MB7179.eurprd08.prod.outlook.com (2603:10a6:10:2cc::19) MIME-Version: 1.0 X-MS-TrafficTypeDiagnostic: DB9PR08MB7179:EE_|DB4PR08MB9261:EE_|DBAEUR03FT008:EE_|DB9PR08MB8580:EE_ X-MS-Office365-Filtering-Correlation-Id: a61402ca-bea9-4c8a-9d8e-08dba899a894 x-checkrecipientrouted: true NoDisclaimer: true X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam-Untrusted: BCL:0; X-Microsoft-Antispam-Message-Info-Original: RRuvmnTbURZMTQDrvlz8+A+PthOnItFBnh4DoQZTE/+RQ18BKr7S/rumwqkF6wlHUFI3v5soz3xlglcmywbRFJxlXDou2xouUTU9qhteeoX9mX9B7xejTk5eNngb8xv5U9g+CAqLqVzLwPN/7Vl4mC8te2CHZY44uAd/a7qyyaTQFvVgij6EedsqLYPk/lbPGFdFsAF9WKheCYXCZPVey7doZxdxAD3rBM01WJuXaBoBXy56YJyKD/G3UU8n6etHwATIM0lHp0kB+9EvBwBXFSDouPNjkuoz3KlBPO16XK7y4y5DpMq1NIRoPKC1K2l/+dr9VlLkrRTrnpnLfZwvBsDtt/DiUb85lAWaE2Dv3u0dkKRBEuJV8nPg7cfIATZ/N2pTAN2uUQDhZ1PCr/T4+VhH9RQU4d7J7R4//5AMRtjUEhcrLraAy+DVLR8ykeB7K4+z02f35/bx4f2WxNnyfjS9bd390Kh3TCE+46u1pAgG6wok5YTvfXsC/DvnVhpX8X3Y8oSy388K5ewamrqfjsUG29ZWqbuQ3nb/wgoAdNHJ6ATKf5b+jUUmP13JU3qK X-Forefront-Antispam-Report-Untrusted: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR08MB7179.eurprd08.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(346002)(39860400002)(396003)(376002)(136003)(366004)(451199024)(1800799009)(186009)(6486002)(6506007)(6512007)(6666004)(478600001)(26005)(83380400001)(2616005)(2906002)(316002)(66556008)(66476007)(66946007)(110136005)(41300700001)(44832011)(5660300002)(8676002)(8936002)(36756003)(38100700002)(86362001);DIR:OUT;SFP:1101; X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB4PR08MB9261 Original-Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com; X-EOPAttributedMessage: 0 X-MS-Exchange-Transport-CrossTenantHeadersStripped: DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id-Prvs: b6f60832-51d3-4890-3a12-08dba899a36a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tdKcGptu2AtpNG0RvfB0WikcpD6m9V9SYl+jhR/vr0dv3j5OPe6ucbI+Qfh9eBPsPp3t27czJQ+e8foiPCUH/N7qh5/kJWfVSm1KXkwTa4EJsn6KCJBa0Jhk888tnoOYdl2/0obyUGM7Yh7rQiIIb9w/qA6Yf+LniiPkkVmBipKpd7nsTYR0AKK4nor+7e6Untu4SUCeVd4R6INffM/6hKDj0DMQ4QP/SzxuKNA6mqgV2Pxq43BqkgVCsKQVDNOuaTP5g8gF4XeQKBYau1N9806yxp80SjDo9VF7qsGMPdYNlNWp82+dw4BbJdQGRJOdgmHrA0X3mBw63jKTafwyKFEVDP+IbcYQ4+3PhWOv+ry6NyL3iygUVSpjOonTi4I95WhSo12bMKAv7aPGQaZct2iKSmgH9YTsm0W872KPJYJXvBU350RmlxcW4P0jylGyXi94EP4lmqvnM4iX/zQaimIXbOI5Y8tn8bLl+FPvaHjtzULAn4X+4Ua7hxelpCbP3g1qq8SsAotGjrAuT76JWT0vTV+xijJYnxEwr6UKA0KKp3Pq+c2ntAMHXeVUnPZkwJZ9Oo8x7FafoORW+N03jjYoz9wTvgp7lcDlWunpe6utxQsbMgJY3GISZHCqntGMopv2i4YnBSJsPlhoxKuG1BtsXnLif96ZdiAtCm1xEQAbEATp2CwL4Fyi5KnHmEnHcKAbamN5h0rAbd5dk3W1JbXJLbEkRIoXVJmLy7H6kwTqiWSzCpeX5sukIcAcXSXy X-Forefront-Antispam-Report: CIP:63.35.35.123;CTRY:IE;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:64aa7808-outbound-1.mta.getcheckrecipient.com;PTR:ec2-63-35-35-123.eu-west-1.compute.amazonaws.com;CAT:NONE;SFS:(13230031)(4636009)(39860400002)(376002)(136003)(346002)(396003)(82310400011)(1800799009)(451199024)(186009)(46966006)(36840700001)(40470700004)(40460700003)(6512007)(316002)(41300700001)(336012)(2906002)(83380400001)(86362001)(2616005)(47076005)(26005)(36756003)(5660300002)(44832011)(8676002)(40480700001)(36860700001)(8936002)(6666004)(81166007)(356005)(82740400003)(6506007)(6486002)(70586007)(70206006)(110136005)(478600001);DIR:OUT;SFP:1101; X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Aug 2023 14:10:11.4831 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a61402ca-bea9-4c8a-9d8e-08dba899a894 X-MS-Exchange-CrossTenant-Id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=f34e5979-57d9-4aaa-ad4d-b122a662184d;Ip=[63.35.35.123];Helo=[64aa7808-outbound-1.mta.getcheckrecipient.com] X-MS-Exchange-CrossTenant-AuthSource: DBAEUR03FT008.eop-EUR03.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR08MB8580 X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,FORGED_SPF_HELO,KAM_DMARC_NONE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE,TXREP,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: The 08/23/2023 16:06, Adhemerval Zanella Netto wrote: > The fix sound reasonable, and I did not see any regression on some different > architectures (aarch64, powerpc, sparc, x86). However I am not sure how > compreensible our own regression tests are for this issue, since afaik > there is no concurrent tests that stress concurrent dlopen module and > TLS access. It also does fix the performance issue from bug report. > > Below some minor comments. ... > > --- a/elf/dl-reloc.c > > +++ b/elf/dl-reloc.c > > @@ -114,9 +114,7 @@ _dl_try_allocate_static_tls (struct link_map *map, bool optional) > > #ifdef SHARED > > if (__builtin_expect (THREAD_DTV()[0].counter != GL(dl_tls_generation), > > 0)) > > - /* Update the slot information data for at least the generation of > > - the DSO we are allocating data for. */ > > - (void) _dl_update_slotinfo (map->l_tls_modid); > > + (void) _dl_update_slotinfo (map->l_tls_modid, GL(dl_tls_generation)); > > Shouldn't it use atomic_load_relaxed on GL(dl_tls_generation) for consistency? _dl_try_allocate_static_tls is called during tlsdesc reloc processing. relocation processing always runs with the GL(dl_load_lock) held and then no concurrent write to the gen count is possible. loads outside the lock have to use atomics to sync with the atomic store under the lock, loads under the lock can be normal loads. > > struct link_map * > > -_dl_update_slotinfo (unsigned long int req_modid) > > +_dl_update_slotinfo (unsigned long int req_modid, size_t new_gen) > > { > > struct link_map *the_map = NULL; > > dtv_t *dtv = THREAD_DTV (); > > > > - /* The global dl_tls_dtv_slotinfo array contains for each module > > - index the generation counter current when the entry was created. > > + /* CONCURRENCY NOTES: > > + > > + The global dl_tls_dtv_slotinfo array contains for each module > > Maybe use the correct name, dl_tls_dtv_slotinfo_list, so it is easier > to reference on the code. ok. (it was this way in the orig comment, but using the full identifier is probably better) > > > + index the generation counter current when that entry was updated. > > This array never shrinks so that all module indices which were > > I think it should 'that' here (it specifies the module indices and there > is no comma). what do you mean? > > > - valid at some time can be used to access it. Before the first > > - use of a new module index in this function the array was extended > > - appropriately. Access also does not have to be guarded against > > - modifications of the array. It is assumed that pointer-size > > - values can be read atomically even in SMP environments. It is > > - possible that other threads at the same time dynamically load > > - code and therefore add to the slotinfo list. This is a problem > > - since we must not pick up any information about incomplete work. > > - The solution to this is to ignore all dtv slots which were > > - created after the one we are currently interested. We know that > > - dynamic loading for this module is completed and this is the last > > - load operation we know finished. */ > > - unsigned long int idx = req_modid; > > + valid at some time can be used to access it. Concurrent loading > > + and unloading of modules can update slotinfo entries or extend > > + the array. The updates happen under the GL(dl_load_tls_lock) and > > + finish with the release store of the generation counter to > > + GL(dl_tls_generation) which is synchronized with the load of > > + new_gen in the caller. So updates up to new_gen are synchronized > > + but updates for later generations may not be. > > + > > + Here we update the thread dtv from old_gen (== dtv[0].counter) to > > + new_gen generation. For this each dtv[i] entry is either set to > > Maybe a comma after 'For this'. ok > > + an unallocated state (set), or left unmodified (nop). Where (set) > > + may resize the dtv first if modid i >= dtv[-1].counter. The rules > > + for the decision between (set) and (nop) are > > + > > + (1) If slotinfo entry i is concurrently updated then either (set) > > + or (nop) is valid: TLS access cannot use dtv[i] unless it is > > + synchronized with a generation > new_gen. > > + > > + Otherwise if the generation of slotinfo entry i is gen and the > > Maybe a comma after 'Otherwise'. ok