From nobody Fri Apr 29 20:55:15 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id CCB85199540A; Fri, 29 Apr 2022 20:55:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Kql9w1sn9z3FFZ; Fri, 29 Apr 2022 20:55:16 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651265716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=a4p/V56KDeP0gd2wSNT8Opy3TM6+PE5/xflrWim+4RI=; b=kryEfDJ2i6W3kumu8OzQVO+sZZEKOtVVsu0kOkz/2QEEFnxIrSgNJ/BUdGr9OsYcB6CT54 fD0aPXLdsf0SmldPdcQYgahsrH7JX9EFOzzHkh8vUiUNbObeY2yxoQzE+FLgAtZKMvm/D2 FFriR00h9ufTLtrnuFiYa/kYen4LN9NjTMW3vJ88/r9RWxS/RPnudE0YetCI10FvUR2YkT AGYwUIJXi015TDSL31VepLnYyyegtZxUhUmg1THCr3mF6Z3Lo39eJ+KWiqHs2NArWtKvo/ C7AfvISDpGWkXruCp0Netva8E1c83UMRp0YM11lcFqMLkEBpadfUy1bvzUGrQg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EADA9140D8; Fri, 29 Apr 2022 20:55:15 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 23TKtF3C055416; Fri, 29 Apr 2022 20:55:15 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 23TKtF6K055415; Fri, 29 Apr 2022 20:55:15 GMT (envelope-from git) Date: Fri, 29 Apr 2022 20:55:15 GMT Message-Id: <202204292055.23TKtF6K055415@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: John Baldwin Subject: git: 34e70df37ae7 - stable/13 - libthr: Use for most MD TLS details. List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhb X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 34e70df37ae70c54d9f87ce1267da0c9a72e662c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1651265716; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=a4p/V56KDeP0gd2wSNT8Opy3TM6+PE5/xflrWim+4RI=; b=SZ2ipm2nPjzqh9pIN/gfxmXZAHvtDKoMcd2G5GzoDyCCJv2IFyVYg376czQ4LlupUBLXet YWow/sI4vX1GTWiLhc4pPwKFC48XaEx43ge4GGxgAqSop0Ut68DMJcP0vI5M80K+nyhTyj AZ6KMTnrcKRUiO8DIlCKtOeR8q5yS7r2T1evlWISHIzl0Xt3YxGgK1h4nxZqsFnw8bLC9I ghsh+KL+n2wdk1xUAxVe3iXpL3mH96bMPf0sNT7GKh71uT6n1vlcYn6KGh84f4967nra8u 27rUUM1t7+DyE1ZLMa+dAfltKp18aHQazWMVOQcwbfYpbNUaB2Ex27cCAI4L+g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1651265716; a=rsa-sha256; cv=none; b=HorwhTonSjRwgifZisXp34IcL/GZKXlRRFbdIq2B4U4pjUvPFncOrg7LKy+rrgvPiw75Aw EffI60WFLshb2xbQ8l3SqiqxgpBIrab/7CSStcjxP2qoZjSC8lUUkm8ya/pwqmwX8zGRy9 MYJQ4u24Xm3uRakYh2+H+ijloCNK7HUYJb6Lobt3WdzrvZ4nIV4b05juq4PrmRQf03/5aV 8UVm94RXjr7+KRoXxT7nBLqaNR7yfsyqslBajuP4vwPRNGARftzwBx/W1e+iqL9/t5O3Q2 CH/AhPjV218vIsqRke2T9OipWOw62hldMSy0PJHbyOGkUwzzIuRVfzJHTq8u/Q== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=34e70df37ae70c54d9f87ce1267da0c9a72e662c commit 34e70df37ae70c54d9f87ce1267da0c9a72e662c Author: John Baldwin AuthorDate: 2021-12-09 21:17:41 +0000 Commit: John Baldwin CommitDate: 2022-04-29 20:50:05 +0000 libthr: Use for most MD TLS details. Note that on amd64 this effectively removes the unused tcb_spare field from the end of struct tcb since the definition of struct tcb in does not include that field. Reviewed by: kib, jrtc27 Sponsored by: The University of Cambridge, Google Inc. Differential Revision: https://reviews.freebsd.org/D33352 (cherry picked from commit 75395023ff1edaf4832389716338b1ba12121ffe) --- lib/libthr/arch/aarch64/include/pthread_md.h | 31 +---------- lib/libthr/arch/amd64/include/pthread_md.h | 56 +++---------------- lib/libthr/arch/arm/include/pthread_md.h | 39 +------------- lib/libthr/arch/i386/include/pthread_md.h | 58 +++----------------- lib/libthr/arch/mips/include/pthread_md.h | 80 ---------------------------- lib/libthr/arch/powerpc/include/pthread_md.h | 43 +-------------- lib/libthr/arch/riscv/include/pthread_md.h | 32 +---------- 7 files changed, 16 insertions(+), 323 deletions(-) diff --git a/lib/libthr/arch/aarch64/include/pthread_md.h b/lib/libthr/arch/aarch64/include/pthread_md.h index 3209a2cbe7e2..f3ce2d0bdbce 100644 --- a/lib/libthr/arch/aarch64/include/pthread_md.h +++ b/lib/libthr/arch/aarch64/include/pthread_md.h @@ -37,39 +37,10 @@ #define _PTHREAD_MD_H_ #include -#include +#include #define CPU_SPINWAIT -/* - * Variant I tcb. The structure layout is fixed, don't blindly - * change it. - */ -struct tcb { - void *tcb_dtv; - struct pthread *tcb_thread; -}; - -/* Called from the thread to set its private data. */ -static __inline void -_tcb_set(struct tcb *tcb) -{ - - __asm __volatile("msr tpidr_el0, %x0" :: "r" (tcb)); -} - -/* - * Get the current tcb. - */ -static __inline struct tcb * -_tcb_get(void) -{ - struct tcb *tcb; - - __asm __volatile("mrs %x0, tpidr_el0" : "=r" (tcb)); - return (tcb); -} - static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/amd64/include/pthread_md.h b/lib/libthr/arch/amd64/include/pthread_md.h index b3367e85ee65..d7bf5d5e5753 100644 --- a/lib/libthr/arch/amd64/include/pthread_md.h +++ b/lib/libthr/arch/amd64/include/pthread_md.h @@ -37,62 +37,18 @@ #include #include -#include +#include #define CPU_SPINWAIT __asm __volatile("pause") -/* - * Variant II tcb, first two members are required by rtld, - * %fs points to the structure. - */ -struct tcb { - struct tcb *tcb_self; /* required by rtld */ - void *tcb_dtv; /* required by rtld */ - struct pthread *tcb_thread; - void *tcb_spare[1]; -}; - -/* - * Evaluates to the byte offset of the per-tcb variable name. - */ -#define __tcb_offset(name) __offsetof(struct tcb, name) - -/* - * Evaluates to the type of the per-tcb variable name. - */ -#define __tcb_type(name) __typeof(((struct tcb *)0)->name) - -/* - * Evaluates to the value of the per-tcb variable name. - */ -#define TCB_GET64(name) ({ \ - __tcb_type(name) __result; \ - \ - u_long __i; \ - __asm __volatile("movq %%fs:%1, %0" \ - : "=r" (__i) \ - : "m" (*(volatile u_long *)(__tcb_offset(name)))); \ - __result = (__tcb_type(name))__i; \ - \ - __result; \ -}) - -static __inline void -_tcb_set(struct tcb *tcb) -{ - amd64_set_fsbase(tcb); -} - -static __inline struct tcb * -_tcb_get(void) -{ - return (TCB_GET64(tcb_self)); -} - static __inline struct pthread * _get_curthread(void) { - return (TCB_GET64(tcb_thread)); + struct pthread *thr; + + __asm __volatile("movq %%fs:%1, %0" : "=r" (thr) + : "m" (*(volatile u_long *)offsetof(struct tcb, tcb_thread))); + return (thr); } #define HAS__UMTX_OP_ERR 1 diff --git a/lib/libthr/arch/arm/include/pthread_md.h b/lib/libthr/arch/arm/include/pthread_md.h index d1fce8551b2e..75570337c627 100644 --- a/lib/libthr/arch/arm/include/pthread_md.h +++ b/lib/libthr/arch/arm/include/pthread_md.h @@ -35,47 +35,10 @@ #define _PTHREAD_MD_H_ #include -#include +#include #define CPU_SPINWAIT -/* - * Variant I tcb. The structure layout is fixed, don't blindly - * change it. - */ -struct tcb { - void *tcb_dtv; /* required by rtld */ - struct pthread *tcb_thread; /* our hook */ -}; - -/* Called from the thread to set its private data. */ -static __inline void -_tcb_set(struct tcb *tcb) -{ -#ifdef ARM_TP_ADDRESS - *((struct tcb **)ARM_TP_ADDRESS) = tcb; /* avoids a system call */ -#else - sysarch(ARM_SET_TP, tcb); -#endif -} - -/* - * Get the current tcb. - */ -static __inline struct tcb * -_tcb_get(void) -{ -#ifdef ARM_TP_ADDRESS - return (*((struct tcb **)ARM_TP_ADDRESS)); -#else - struct tcb *tcb; - - __asm __volatile("mrc p15, 0, %0, c13, c0, 3" \ - : "=r" (tcb)); - return (tcb); -#endif -} - static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/i386/include/pthread_md.h b/lib/libthr/arch/i386/include/pthread_md.h index 48374480d207..525a9c4368a3 100644 --- a/lib/libthr/arch/i386/include/pthread_md.h +++ b/lib/libthr/arch/i386/include/pthread_md.h @@ -37,64 +37,18 @@ #include #include -#include +#include #define CPU_SPINWAIT __asm __volatile("pause") -/* - * Variant II tcb, first two members are required by rtld, - * %gs points to the structure. - */ -struct tcb { - struct tcb *tcb_self; /* required by rtld */ - void *tcb_dtv; /* required by rtld */ - struct pthread *tcb_thread; -}; - -/* - * Evaluates to the byte offset of the per-tcb variable name. - */ -#define __tcb_offset(name) __offsetof(struct tcb, name) - -/* - * Evaluates to the type of the per-tcb variable name. - */ -#define __tcb_type(name) __typeof(((struct tcb *)0)->name) - -/* - * Evaluates to the value of the per-tcb variable name. - */ -#define TCB_GET32(name) ({ \ - __tcb_type(name) __result; \ - \ - u_int __i; \ - __asm __volatile("movl %%gs:%1, %0" \ - : "=r" (__i) \ - : "m" (*(volatile u_int *)(__tcb_offset(name)))); \ - __result = (__tcb_type(name))__i; \ - \ - __result; \ -}) - -/* Called from the thread to set its private data. */ -static __inline void -_tcb_set(struct tcb *tcb) -{ - i386_set_gsbase(tcb); -} - -/* Get the current kcb. */ -static __inline struct tcb * -_tcb_get(void) -{ - return (TCB_GET32(tcb_self)); -} - -/* Get the current thread. */ static __inline struct pthread * _get_curthread(void) { - return (TCB_GET32(tcb_thread)); + struct pthread *thr; + + __asm __volatile("movl %%gs:%1, %0" : "=r" (thr) + : "m" (*(volatile u_int *)offsetof(struct tcb, tcb_thread))); + return (thr); } #define HAS__UMTX_OP_ERR 1 diff --git a/lib/libthr/arch/mips/include/pthread_md.h b/lib/libthr/arch/mips/include/pthread_md.h index 2a29e6717abe..2fc39aff7e7b 100644 --- a/lib/libthr/arch/mips/include/pthread_md.h +++ b/lib/libthr/arch/mips/include/pthread_md.h @@ -36,90 +36,10 @@ #define _PTHREAD_MD_H_ #include -#include #include #define CPU_SPINWAIT -/* - * Variant I tcb. The structure layout is fixed, don't blindly - * change it! - */ -struct tcb { - void *tcb_dtv; - struct pthread *tcb_thread; -}; - -/* Called from the thread to set its private data. */ -static __inline void -_tcb_set(struct tcb *tcb) -{ - - sysarch(MIPS_SET_TLS, tcb); -} - -/* - * Get the current tcb. - */ -#ifdef TLS_USE_SYSARCH -static __inline struct tcb * -_tcb_get(void) -{ - struct tcb *tcb; - - sysarch(MIPS_GET_TLS, &tcb); - return tcb; -} - -#else /* ! TLS_USE_SYSARCH */ - -# if defined(__mips_n64) -static __inline struct tcb * -_tcb_get(void) -{ - uint64_t _rv; - - __asm__ __volatile__ ( - ".set\tpush\n\t" - ".set\tmips64r2\n\t" - "rdhwr\t%0, $29\n\t" - ".set\tpop" - : "=r" (_rv)); - - /* - * XXXSS See 'git show c6be4f4d2d1b71c04de5d3bbb6933ce2dbcdb317' - * - * Remove the offset since this really a request to get the TLS - * pointer via sysarch() (in theory). Of course, this may go away - * once the TLS code is rewritten. - */ - return (struct tcb *)(_rv - TLS_TP_OFFSET - TLS_TCB_SIZE); -} -# else /* mips 32 */ -static __inline struct tcb * -_tcb_get(void) -{ - uint32_t _rv; - - __asm__ __volatile__ ( - ".set\tpush\n\t" - ".set\tmips32r2\n\t" - "rdhwr\t%0, $29\n\t" - ".set\tpop" - : "=r" (_rv)); - - /* - * XXXSS See 'git show c6be4f4d2d1b71c04de5d3bbb6933ce2dbcdb317' - * - * Remove the offset since this really a request to get the TLS - * pointer via sysarch() (in theory). Of course, this may go away - * once the TLS code is rewritten. - */ - return (struct tcb *)(_rv - TLS_TP_OFFSET - TLS_TCB_SIZE); -} -# endif /* ! __mips_n64 */ -#endif /* ! TLS_USE_SYSARCH */ - static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/powerpc/include/pthread_md.h b/lib/libthr/arch/powerpc/include/pthread_md.h index 3fcf8c3245da..10c787ae189a 100644 --- a/lib/libthr/arch/powerpc/include/pthread_md.h +++ b/lib/libthr/arch/powerpc/include/pthread_md.h @@ -36,51 +36,10 @@ #define _PTHREAD_MD_H_ #include +#include #define CPU_SPINWAIT -#ifdef __powerpc64__ -#define TP_OFFSET 0x7010 -#else -#define TP_OFFSET 0x7008 -#endif - -/* - * Variant I tcb. The structure layout is fixed, don't blindly - * change it. - * %r2 (32-bit) or %r13 (64-bit) points to end of the structure. - */ -struct tcb { - void *tcb_dtv; - struct pthread *tcb_thread; -}; - -static __inline void -_tcb_set(struct tcb *tcb) -{ -#ifdef __powerpc64__ - __asm __volatile("mr 13,%0" :: - "r"((uint8_t *)tcb + TP_OFFSET)); -#else - __asm __volatile("mr 2,%0" :: - "r"((uint8_t *)tcb + TP_OFFSET)); -#endif -} - -static __inline struct tcb * -_tcb_get(void) -{ - register struct tcb *tcb; - -#ifdef __powerpc64__ - __asm __volatile("addi %0,13,%1" : "=r"(tcb) : "i"(-TP_OFFSET)); -#else - __asm __volatile("addi %0,2,%1" : "=r"(tcb) : "i"(-TP_OFFSET)); -#endif - - return (tcb); -} - static __inline struct pthread * _get_curthread(void) { diff --git a/lib/libthr/arch/riscv/include/pthread_md.h b/lib/libthr/arch/riscv/include/pthread_md.h index 1cdc8a12be95..092d40266e1c 100644 --- a/lib/libthr/arch/riscv/include/pthread_md.h +++ b/lib/libthr/arch/riscv/include/pthread_md.h @@ -42,39 +42,9 @@ #define _PTHREAD_MD_H_ #include +#include #define CPU_SPINWAIT -#define TP_OFFSET sizeof(struct tcb) - -/* - * Variant I tcb. The structure layout is fixed, don't blindly - * change it! - */ -struct tcb { - void *tcb_dtv; - struct pthread *tcb_thread; -}; - -/* Called from the thread to set its private data. */ -static __inline void -_tcb_set(struct tcb *tcb) -{ - - __asm __volatile("addi tp, %0, %1" :: "r"(tcb), "I"(TP_OFFSET)); -} - -/* - * Get the current tcb. - */ -static __inline struct tcb * -_tcb_get(void) -{ - struct tcb *_tcb; - - __asm __volatile("addi %0, tp, %1" : "=r"(_tcb) : "I"(-TP_OFFSET)); - - return (_tcb); -} static __inline struct pthread * _get_curthread(void)