From patchwork Thu Mar 9 18:26:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 66181 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 579C13858281 for ; Thu, 9 Mar 2023 18:26:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 579C13858281 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1678386389; bh=+VEBM3yAbmHsoWQG4E1XpimhhGWpoh8A+iJWKc6rAws=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=FdNe8osyuui5qYm4uYE6RJKMVf2Ef2gqlmlKUFb9qs7tqzSJ4FD7YR+8EY9RQ+vyo 1OVBtV2sK2SkwLE1F5w7tT/vWs9a+VWlAC6LG2vD4Y0k+0ihLhPce/ha1VNMXXJTbW 73nLDiUn81P8HIiM4g3vRHfH6h3zKwXZnY84fvr0= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id A4C003857C71 for ; Thu, 9 Mar 2023 18:26:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4C003857C71 Received: by mail-pl1-x62a.google.com with SMTP id i3so2936071plg.6 for ; Thu, 09 Mar 2023 10:26:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678386365; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+VEBM3yAbmHsoWQG4E1XpimhhGWpoh8A+iJWKc6rAws=; b=XsC3dKk85sRcTfC0pOtB5mtwMBghzPcEEbjdxBiPo35qBkfIdbWjEeaUcyl1xI4FcE DzQtTSuZPqlTybYSMqVV4h+8on5VH/d8K9ayk5O2Y+ex/pENHhjAkrBG7aA7c9MzrCZd KXXYDXt0GA0SfD6DldwkL1LO+2Ldv4yTfa2Y/E54ZpHSY0R8ca07k+Jp2nUwcVCMEfCV rbZKVCnkiDI+rBQL7eb+gRcBdgZeDN3dXrptTNgiJES7gLIAWqjFSba2mkvALqdR7HbW zk57tpBNztrdP03VgJuPFtJ+xFo0eGb4wG6lorLr7M9BymZhgkbaMuGO23H16OzH/P22 ip1Q== X-Gm-Message-State: AO0yUKVHS1MfoLfmMDISPFJsYe3U6BSF3DX9zRiJWt6CEuaH66G0A1uU 6hjY/WVz8F3+9qSPu9ATgNMWbCAbrXo= X-Google-Smtp-Source: AK7set9osAdHP5Qmq8Osv96qkERR0zOn0n6c1wqZ4D0ry7EMdszYnjpc60qoNGx8WezNQyXIOxt7vA== X-Received: by 2002:a05:6a20:7d9d:b0:cd:91bc:a9af with SMTP id v29-20020a056a207d9d00b000cd91bca9afmr24710650pzj.58.1678386365506; Thu, 09 Mar 2023 10:26:05 -0800 (PST) Received: from gnu-cfl-3.localdomain ([172.59.161.113]) by smtp.gmail.com with ESMTPSA id v24-20020a62a518000000b005dca6f0046dsm11871425pfm.12.2023.03.09.10.26.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Mar 2023 10:26:05 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id F0B9D740146; Thu, 9 Mar 2023 10:26:03 -0800 (PST) To: libc-alpha@sourceware.org Cc: Florian Weimer Subject: [PATCH] x86: Set FSGSBASE to active if enabled by kernel Date: Thu, 9 Mar 2023 10:26:03 -0800 Message-Id: <20230309182603.205394-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3025.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Libc-alpha" From: "H.J. Lu" Reply-To: "H.J. Lu" Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Linux kernel uses AT_HWCAP2 to indicate if FSGSBASE instructions are enabled. If the HWCAP2_FSGSBASE bit in AT_HWCAP2 is set, FSGSBASE instructions can be used in user space. Define dl_check_hwcap2 to set the FSGSBASE feature to active on Linux when the HWCAP2_FSGSBASE bit is set. --- sysdeps/unix/sysv/linux/x86/dl-hwcap2.h | 27 +++++++++++++++++++++++++ sysdeps/x86/cpu-features.c | 3 +++ sysdeps/x86/dl-hwcap2.h | 21 +++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/x86/dl-hwcap2.h create mode 100644 sysdeps/x86/dl-hwcap2.h diff --git a/sysdeps/unix/sysv/linux/x86/dl-hwcap2.h b/sysdeps/unix/sysv/linux/x86/dl-hwcap2.h new file mode 100644 index 0000000000..28f38ea510 --- /dev/null +++ b/sysdeps/unix/sysv/linux/x86/dl-hwcap2.h @@ -0,0 +1,27 @@ +/* Handle AT_HWCAP2. Linux/x86 version. + Copyright (C) 2023 Free Software Foundation, Inc. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* The following must match the kernel's . */ +#define HWCAP2_RING3MWAIT (1 << 0) +#define HWCAP2_FSGSBASE (1 << 1) + +static inline void +dl_check_hwcap2 (struct cpu_features *cpu_features) +{ + if ((GLRO(dl_hwcap2) & HWCAP2_FSGSBASE) != 0) + CPU_FEATURE_SET_ACTIVE (cpu_features, FSGSBASE); +} diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c index 822688e21f..05f966ea64 100644 --- a/sysdeps/x86/cpu-features.c +++ b/sysdeps/x86/cpu-features.c @@ -22,6 +22,7 @@ #include #include #include +#include #if HAVE_TUNABLES extern void TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *) @@ -303,6 +304,8 @@ update_active (struct cpu_features *cpu_features) CPU_FEATURE_SET_ACTIVE (cpu_features, WIDE_KL); } + dl_check_hwcap2 (cpu_features); + cpu_features->isa_1 = get_isa_level (cpu_features); } diff --git a/sysdeps/x86/dl-hwcap2.h b/sysdeps/x86/dl-hwcap2.h new file mode 100644 index 0000000000..73cd6cc37d --- /dev/null +++ b/sysdeps/x86/dl-hwcap2.h @@ -0,0 +1,21 @@ +/* Handle AT_HWCAP2. Generic x86 version. + Copyright (C) 2023 Free Software Foundation, Inc. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +static inline void +dl_check_hwcap2 (struct cpu_features *cpu_features) +{ +}