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 20958 invoked from network); 29 Mar 2022 11:55:19 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 29 Mar 2022 11:55:19 -0000 Received: (qmail 14030 invoked by uid 550); 29 Mar 2022 11:55:14 -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 13883 invoked from network); 29 Mar 2022 11:55:13 -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=Oz9+pYLudX4hEkWhCdxERqjLYgwWGjZrci03xz9IVqU=; b=DEB/sgVl+NgbI7ypl37YEiLmYWXBAGmu2J7J/4yhWz9VqXDZqsdn4uWQebePibY+OL /3ZLrNJQ3LtUXKrc+PG2OTo+zLOFfgBQemfz/zX0q90VUiuc9qr13J/SSfb8EhawdZcf F0GgXHK1e9E7rsfdkq+Usaa/mOJsFWmKANPrrctjfXtGCz6iqOoiUWM1kkCUj3V2tDDX mCwzV2JALkw9XanWhS+wZwdosKAmAWYYugHw0C77CkCcWYu7jnw9epwjTxWseZ8ZR+0E U1G6Ygbr92slJ6QtGWLZfpHGDwaHIQRg5kjm+1m2sDOyy+lnRn0fCa9mHGyIryuQgc5p NaQg== 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=Oz9+pYLudX4hEkWhCdxERqjLYgwWGjZrci03xz9IVqU=; b=SXn0tZFWqvj8+zlYTuBigHpnBbg+ukDUNgG6aVKqcG1VI8EWX/vtvhguKZ0li1RupU 5pXF7SrmL1v/HBxHirWcPYxV5QhZGfJ/dtXIfMQr+ibDmmdKHfye2UAC9e7H+nqNqHYp KQoLoachzjWrITNc9jOIWmaV4zcn1g3DQLSdX5M4SYhMhTw22iUdqX3sg+w2jxbaafVK G/bIV2dNhAg/uYJ8iSJDpRkCGxeaNzzz6AA4GOaY5Gh8s3RYTIIKjflQgTcOiG8oCc9j kSCZZgNmyKJa42DBnckfhRSxDE9+SuQB6Id4xZAkGJNSl3OzLpRVIgEwzBuUEdDjfjHa tOUQ== X-Gm-Message-State: AOAM530pZWOzqsqPBbGeOE1BlsV/4XqSQdPgXnofJYJNS3EDLM/bGpcc ZMcGX16eqOGpWYrEYOUagJNK+aFEYHesADB3 X-Google-Smtp-Source: ABdhPJwAAnqgOlkDfL2N3bVlJQg1l9GnZDhM41ahcRBwET08fMFtv2vVVYetdrOIvCTpuqbzHdw9cg== X-Received: by 2002:a05:6402:27d2:b0:419:1a3d:442b with SMTP id c18-20020a05640227d200b004191a3d442bmr3899443ede.409.1648554901973; Tue, 29 Mar 2022 04:55:01 -0700 (PDT) From: Harald Hoyer To: musl@lists.openwall.com Cc: Harald Hoyer Date: Tue, 29 Mar 2022 13:54:33 +0200 Message-Id: <20220329115433.918346-2-harald@profian.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220329115433.918346-1-harald@profian.com> References: <20220329114257.914392-1-harald@profian.com> <20220329115433.918346-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..804d41fa --- /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]