From patchwork Thu Nov 21 19:08:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Jeanson X-Patchwork-Id: 57746 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 478793857BBA for ; Thu, 21 Nov 2024 19:18:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 478793857BBA Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=efficios.com header.i=@efficios.com header.a=rsa-sha256 header.s=smtpout1 header.b=Sl7aOLrO X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from smtpout.efficios.com (smtpout.efficios.com [IPv6:2607:5300:203:b2ee::31e5]) by sourceware.org (Postfix) with ESMTPS id 4D0483857C7A for ; Thu, 21 Nov 2024 19:09:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D0483857C7A Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=efficios.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=efficios.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4D0483857C7A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:5300:203:b2ee::31e5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732216176; cv=none; b=I0VHGq+KiqekLD7q0m03dSAeWJ2UWiDyvmnIrDqhkcA9Ceu1OV3IiTscYNCKqIXsKy1YS9yQtAKvuneXXXNz0qCN9MR3XCh04EhAlLYKspDqFtpb07ztrwPcvpIiEbjz13NtELgWrIhdU3qaXfYQtBZyIwV3soE48BY6cuFpVDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1732216176; c=relaxed/simple; bh=2nilNZRFESX3PNhBecTZ0F/LjCOur8VpdV66DkSyQ3E=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nkSjV78N0/lJWT2MNnxd+o/e6qHrGi+YvUT2qyOghO9G1sgwzrii+zRcbNC0KbMTNTU3CbNclT/MnQOy1F3hcCA8dq8pUa9AOgZ9BwFhM3E5oiyv3z5st/LYceENa/B+jzuo6cz0qEwwSZcGaYFVxm0yyg81o9rK6092XyAn3aA= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4D0483857C7A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1732216174; bh=2nilNZRFESX3PNhBecTZ0F/LjCOur8VpdV66DkSyQ3E=; h=From:To:Cc:Subject:Date:From; b=Sl7aOLrOUmWTyS4aWVIrCjs148a6MYVnhqXmRGueRxM/gr/5ApRnC6AV3bbAB0O3d 1edzE3rgTbH3QgRGX8Cf7p3l4tOxWUVij6guDdENRZjFLKhKvIK2BfY0PYSVG9/lDe q/qh3OQgh3vO1E84khzJVu4R0CB0Lcb8uu6nzkTj5uj4twxKuONLsvohGSxTp7iWHk 01OUS1eCxV+ntjqgKusIh9SMy1gqzch0VObUhkG8/l6qoIYVtdUpGQ3Lgp9995Dnww bxcS1jaQf5puAKq7tBG7IVw2W+kV5tNXwOEqLldTFbJ7pP54H/ucxe4uF5xzzjuxIC +BXuagh+X4oFg== Received: from laptop-mjeanson.internal.efficios.com (96-127-217-162.qc.cable.ebox.net [96.127.217.162]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4XvSTV5T1pz13nc; Thu, 21 Nov 2024 14:09:34 -0500 (EST) From: Michael Jeanson To: libc-alpha@sourceware.org Cc: Michael Jeanson , Florian Weimer , Carlos O'Donell , DJ Delorie , Mathieu Desnoyers Subject: [PATCH v14 0/9] Add rseq extensible ABI support Date: Thu, 21 Nov 2024 14:08:50 -0500 Message-ID: <20241121190924.837446-1-mjeanson@efficios.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org Introduced in Linux v6.3 the rseq extensible ABI [1] will allow adding rseq features past the initial 32 bytes of the original ABI. While the rseq features in the latest kernel still fit within the original ABI size, there are currently only 4 bytes left. It would thus be a good time to add support for the extensible ABI so that when new features are added, they are immediately available to GNU libc users. We use the ELF auxiliary vector to query the kernel for the size and alignment of the rseq area, if this fails we default to the original fixed size and alignment of '32' which the kernel will accept as a compatibility mode with the original ABI. This makes the size of the rseq area variable and thus requires to relocate it out of 'struct pthread'. We chose to move it after (in block allocation order) the last TLS block inside the static TLS block allocation. It required a fairly small modification to the TLS block allocator and did not interfere with the main executable TLS block which must always be the first block relative to the thread pointer. [1] https://lore.kernel.org/all/20221122203932.231377-4-mathieu.desnoyers@efficios.com/ Cc: Florian Weimer Cc: Carlos O'Donell Cc: DJ Delorie Cc: Mathieu Desnoyers --- Changes since v13: - Ensure that the VOLATILE variants of the RSEQ_ accessors static asserts on 64bit types on 32bit architectures - Move rtld_hidden_proto rseq symbols to a separate patch Changes since v12: - Set _rseq_size to 0 on registration failure - Split RSEQ_SET/GETMEM from THREAD_SET/GETMEM - Rename rseq_get_area() to RSEQ_SELF() - Add rtld_hidden_proto to __rseq_size and __rseq_offset - Add comment and variable array member to 'struct rseq_area' - Style nits Changes since v11: - Removed _dl_rseq_feature_size, use __rseq_size instead - Replace GLRO(dl_rseq_align) with a hidden global variable _rseq_align - __rseq_size is now set directly in _dl_parse_auxv, set it to 0 when the main thread registration fails or is disabled by tunable Changes since v10: - Split the patchset in smaller patches - Rebased on 'Make __rseq_size useful for feature detection' - Remove 'rseq' from the generic TLS code, add 'extra TLS' - Add thread_pointer.h for all Linux architectures - Fix build on the Hurd Changes since v8: - Fix copyright year in sysdeps/generic/dl-rseq.h - Clarify the the tcb math comments - Add a comment to clarify what enforces the aligment requirements of a pointer calculated from the rseq_offset - Remove nonsensical test in tst-rseq-disable - Add comments to clarify why the rseq size is 0 when registration fails or is disabled - Add comments to explain why whe allocate and rseq area block even when the registration is disabled by tunable - Rename 'rseq_size' -> 'rseq_alloc_size' and 'dl_tls_rseq_size' -> 'dl_tls_rseq_alloc_size' to clarify the distinction between the allocated rseq size and the size reported to application code in '__rseq_size' Changes since v6: - Fix tst-rseq for feature size over 32 bytes - Rebased on 'nptl: fix potential merge of __rseq_* relro symbols' Changes since v5: - Fix TLS_DTV_AT_TP rseq offset with statically linked executables Changes since RFC v4: - Move dynamic linker defines to a header file - Fix alignment when tls block align is smaller than rseq align with statically linked executables - Add statically linked rseq tests - Revert: Set __rseq_size even when the registration fails - Use minimum size when rseq is disabled by tunable Changes since RFC v3: - Fix RSEQ_SETMEM for rseq disabled - Replace sys/auxv.h usage with dl-parse_auxv.h - Fix offset for TLS_TCB_AT_TP with statically linked executables - Zero the rseq area before registration Changes since RFC v2: - Set __rseq_size even when the registration fails - Adjust rseq tests to the new ABI - Added support for statically linked executables Changes since RFC v1: - Insert the rseq area after the last TLS block - Add proper support for TLS_TCB_AT_TP variant --- Michael Jeanson (9): nptl: initialize cpu_id_start prior to rseq registration nptl: Add rseq auxvals Add generic 'extra TLS' Add Linux 'extra TLS' nptl: add rtld_hidden_proto to __rseq_size and __rseq_offset nptl: Introduce for RSEQ_* accessors nptl: Move the rseq area to the 'extra TLS' block nptl: Remove the rseq area from 'struct pthread' Linux: Update internal copy of '' csu/libc-tls.c | 59 +++++++++-- elf/dl-tls.c | 59 +++++++++++ nptl/descr.h | 22 +---- nptl/pthread_create.c | 2 +- sysdeps/generic/dl-extra_tls.h | 45 +++++++++ sysdeps/i386/nptl/rseq-access.h | 98 +++++++++++++++++++ sysdeps/nptl/dl-tls_init_tp.c | 23 ++--- sysdeps/nptl/rseq-access.h | 58 +++++++++++ sysdeps/unix/sysv/linux/Makefile | 10 ++ sysdeps/unix/sysv/linux/dl-extra_tls.h | 70 +++++++++++++ sysdeps/unix/sysv/linux/dl-parse_auxv.h | 7 ++ sysdeps/unix/sysv/linux/dl-rseq-symbols.S | 27 +++-- sysdeps/unix/sysv/linux/rseq-internal.h | 94 ++++++++++++++---- sysdeps/unix/sysv/linux/sched_getcpu.c | 3 +- sysdeps/unix/sysv/linux/sys/rseq.h | 11 +++ .../unix/sysv/linux/tst-rseq-disable-static.c | 1 + sysdeps/unix/sysv/linux/tst-rseq-disable.c | 64 ++++++++++-- .../unix/sysv/linux/tst-rseq-nptl-static.c | 1 + sysdeps/unix/sysv/linux/tst-rseq-static.c | 1 + sysdeps/unix/sysv/linux/tst-rseq.c | 84 +++++++++++++--- sysdeps/unix/sysv/linux/tst-rseq.h | 3 +- sysdeps/x86_64/nptl/rseq-access.h | 79 +++++++++++++++ 22 files changed, 725 insertions(+), 96 deletions(-) create mode 100644 sysdeps/generic/dl-extra_tls.h create mode 100644 sysdeps/i386/nptl/rseq-access.h create mode 100644 sysdeps/nptl/rseq-access.h create mode 100644 sysdeps/unix/sysv/linux/dl-extra_tls.h create mode 100644 sysdeps/unix/sysv/linux/tst-rseq-disable-static.c create mode 100644 sysdeps/unix/sysv/linux/tst-rseq-nptl-static.c create mode 100644 sysdeps/unix/sysv/linux/tst-rseq-static.c create mode 100644 sysdeps/x86_64/nptl/rseq-access.h