From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 24741 invoked from network); 29 Mar 2022 12:24:49 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 29 Mar 2022 12:24:49 -0000 Received: (qmail 23848 invoked by uid 550); 29 Mar 2022 12:24:39 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 23745 invoked from network); 29 Mar 2022 12:24:38 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profian-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MaPY688JkQnl3hWsINvWR0V9qKV7Gl7lwKqnGR6fYrQ=; b=09CS+UB14ixgWjPcxkBly2K1eXY6AL5/rdr58lRts1A9lxnJ8spG3Ic5nwHsgsKBBq 66oQ5/bjq3rTwkkZVcmnYv/1VDCw/NEHGIZ3Sny3itx4X0oTVSL8L0SkS5I7xvu2TrxI hcDoRcrQc16GVa/0VjqPQmNNV2/uz5YlO38GGlHr4aLyKyhEyN1vcLPjmNg2g4N6BNz5 nkGf12XodgBHPVXjaKqXME811xqUy/4A2xId/3LgvIey+lARh14D6PGSRh7+RuhKva/q TPy01noUDV0a9g/X2xtsANA10lQAD9DY0ytxU0sKk497nmpRGme/y0gEpHAhFMncpBU0 mwVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MaPY688JkQnl3hWsINvWR0V9qKV7Gl7lwKqnGR6fYrQ=; b=VcQOvzkyEFebH3Gw/WRMoytU0ejJMX3eqLngZkm5a+9HXEuj9q0DD12hBBZxsIZt6i 20vQKWTIct+syhvXtq0NG2ENaIaeLJTQVfngOVatoJyaKnF1j1wzRAsncEHo4FldJ2Fv lOrNQBTSwEbtZoMWwAHXrNwnKoiECMbJUZ7A57QK2JoH6f89R7stKxl1yX1vbzIET+Qx q5Yn38l8dLBSR90G1CZqwvqdRlV+eMlTBWnBr+JcriL+mavi7nN3/otryRZrqtGWWgmb nYeIrC1BFhl3sRldW4yReMB/0pesFTSWxpz/xCYneieMuGfJArLTFwvaF65maQw9yHdw SgRg== X-Gm-Message-State: AOAM532hNOWvaWPvcvOQ3j95MlqEXXVug8Zx8l9jBeSpdnV6udqqP5nm 06MESYCSMTCft6nTRx8ZJMhF/vhVD2INAbDN X-Google-Smtp-Source: ABdhPJyT1pyH9aT2hTRfdha4LrDJo4ncOCMNFLsEyCjBt2OnZ1yDqH03cI6xIzNCEGOirm2/AlnC6Q== X-Received: by 2002:a05:6402:40c9:b0:419:4b81:162e with SMTP id z9-20020a05640240c900b004194b81162emr4270936edb.380.1648556667231; Tue, 29 Mar 2022 05:24:27 -0700 (PDT) From: Harald Hoyer To: musl@lists.openwall.com Cc: Harald Hoyer Date: Tue, 29 Mar 2022 14:24:16 +0200 Message-Id: <20220329122416.925516-2-harald@profian.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220329122416.925516-1-harald@profian.com> References: <20220329122416.925516-1-harald@profian.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH 1/1] feat(x86_64): use wrfsbase if AT_HWCAP2 allows usage If `AT_HWCAP2` has `HWCAP2_FSGSBASE` set, then instead of calling `arch_prctl()`, the `wrfsbase` instruction will be used. This is helpful in SGX contexts, where inside the enclave no other mechanism is possible. Tested against `libc-test`. Signed-off-by: Harald Hoyer --- arch/x86_64/bits/hwcap.h | 2 ++ ldso/dynlink.c | 1 + src/env/__libc_start_main.c | 1 + src/internal/libc.c | 1 + src/internal/libc.h | 1 + src/thread/x86_64/__set_thread_area.c | 14 ++++++++++++++ src/thread/x86_64/__set_thread_area.s | 11 ----------- 7 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 arch/x86_64/bits/hwcap.h create mode 100644 src/thread/x86_64/__set_thread_area.c delete mode 100644 src/thread/x86_64/__set_thread_area.s diff --git a/arch/x86_64/bits/hwcap.h b/arch/x86_64/bits/hwcap.h new file mode 100644 index 00000000..eb962bce --- /dev/null +++ b/arch/x86_64/bits/hwcap.h @@ -0,0 +1,2 @@ +#define HWCAP2_RING3MWAIT (1 << 0) +#define HWCAP2_FSGSBASE (1 << 1) diff --git a/ldso/dynlink.c b/ldso/dynlink.c index 5b9c8be4..2d38ec63 100644 --- a/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -1710,6 +1710,7 @@ void __dls2b(size_t *sp, size_t *auxv) * use during dynamic linking. If possible it will also serve as the * thread pointer at runtime. */ search_vec(auxv, &__hwcap, AT_HWCAP); + search_vec(auxv, &__hwcap2, AT_HWCAP2); libc.auxv = auxv; libc.tls_size = sizeof builtin_tls; libc.tls_align = tls_align; diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c index c5b277bd..38772bdb 100644 --- a/src/env/__libc_start_main.c +++ b/src/env/__libc_start_main.c @@ -28,6 +28,7 @@ void __init_libc(char **envp, char *pn) libc.auxv = auxv = (void *)(envp+i+1); for (i=0; auxv[i]; i+=2) if (auxv[i]