From patchwork Tue Aug 8 19:24:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 799420 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-82893-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="YdkePIno"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xRkrv529kz9s71 for ; Wed, 9 Aug 2017 05:25:51 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; q=dns; s=default; b=BErA/YI2F91KeMIN AwKV1Y2Yu/Ds6lZ3cyIznJF08Pt+6oFjGBZNgp5Iu3Rh8M69RFCubfCB0Bge8tDj PHbmeZZogKcAgqc/N3vDF+X/VWNBImefd4MBVKWKsuKlbdaZLbmUhVMA0Vn8Wo8+ LExtFEQGaW5tdhpoM5nvFLXKgE0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:reply-to :mime-version:content-type; s=default; bh=K3/K9hYZDiMlFaawzazJh7 71KLQ=; b=YdkePInod5Cyh8uvbqc4KA+3qwXckqUqnMGjGwHK/1XRiVSlJLEqc+ mqzAzsi6qqRNnQAv2Fg4BbxIhxif0U7pnsaxWBm+UoXWp2YCEs19RX7jxKDyi1pe ZEvSGx61Jrf/m6q+j00F8KwufAC/qGbhc71H/+tMV9N7Pj1JkEhcs= Received: (qmail 126647 invoked by alias); 8 Aug 2017 19:25:36 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 126410 invoked by uid 89); 8 Aug 2017 19:25:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, NO_DNS_FOR_FROM, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: mga07.intel.com X-ExtLoop1: 1 Date: Tue, 8 Aug 2017 12:24:54 -0700 From: "H.J. Lu" To: GNU C Library Subject: [PATCH] x86: Add IBT/SHSTK bits to cpu-features Message-ID: <20170808192454.GA32301@gmail.com> Reply-To: "H.J. Lu" MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.3 (2017-05-23) Add IBT/SHSTK bits to cpu-features for Shadow Stack in Intel Control-flow Enforcement Technology (CET) instructions: https://software.intel.com/sites/default/files/managed/4d/2a/control-flow-enforcement-technology-preview.pdf Any comments or objections? H.J. --- * sysdeps/x86/cpu-features.h (bit_cpu_BIT): New. (bit_cpu_SHSTK): Likewise. (index_cpu_IBT): Likewise. (index_cpu_SHSTK): Likewise. (reg_IBT): Likewise. (reg_SHSTK): Likewise. * sysdeps/x86/cpu-tunables.c (TUNABLE_CALLBACK (set_hwcaps)): Handle index_cpu_IBT and index_cpu_SHSTK. --- sysdeps/x86/cpu-features.h | 8 ++++++++ sysdeps/x86/cpu-tunables.c | 2 ++ 2 files changed, 10 insertions(+) diff --git a/sysdeps/x86/cpu-features.h b/sysdeps/x86/cpu-features.h index af52689123..9733e6ee66 100644 --- a/sysdeps/x86/cpu-features.h +++ b/sysdeps/x86/cpu-features.h @@ -74,6 +74,8 @@ #define bit_cpu_AVX512CD (1 << 28) #define bit_cpu_AVX512BW (1 << 30) #define bit_cpu_AVX512VL (1u << 31) +#define bit_cpu_IBT (1u << 20) +#define bit_cpu_SHSTK (1u << 7) /* XCR0 Feature flags. */ #define bit_XMM_state (1 << 1) @@ -103,6 +105,8 @@ # define index_cpu_AVX2 COMMON_CPUID_INDEX_7*CPUID_SIZE+CPUID_EBX_OFFSET # define index_cpu_ERMS COMMON_CPUID_INDEX_7*CPUID_SIZE+CPUID_EBX_OFFSET # define index_cpu_MOVBE COMMON_CPUID_INDEX_1*CPUID_SIZE+CPUID_ECX_OFFSET +# define index_cpu_IBT COMMON_CPUID_INDEX_7*CPUID_SIZE+CPUID_EDX_OFFSET +# define index_cpu_SHSTK COMMON_CPUID_INDEX_7*CPUID_SIZE+CPUID_ECX_OFFSET # define index_arch_Fast_Rep_String FEATURE_INDEX_1*FEATURE_SIZE # define index_arch_Fast_Copy_Backward FEATURE_INDEX_1*FEATURE_SIZE @@ -220,6 +224,8 @@ extern const struct cpu_features *__get_cpu_features (void) # define index_cpu_LZCNT COMMON_CPUID_INDEX_1 # define index_cpu_MOVBE COMMON_CPUID_INDEX_1 # define index_cpu_POPCNT COMMON_CPUID_INDEX_1 +# define index_cpu_IBT COMMON_CPUID_INDEX_7 +# define index_cpu_SHSTK COMMON_CPUID_INDEX_7 # define reg_CX8 edx # define reg_CMOV edx @@ -249,6 +255,8 @@ extern const struct cpu_features *__get_cpu_features (void) # define reg_LZCNT ecx # define reg_MOVBE ecx # define reg_POPCNT ecx +# define reg_IBT edx +# define reg_SHSTK ecx # define index_arch_Fast_Rep_String FEATURE_INDEX_1 # define index_arch_Fast_Copy_Backward FEATURE_INDEX_1 diff --git a/sysdeps/x86/cpu-tunables.c b/sysdeps/x86/cpu-tunables.c index 872dd1267f..0ab708cca8 100644 --- a/sysdeps/x86/cpu-tunables.c +++ b/sysdeps/x86/cpu-tunables.c @@ -164,6 +164,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp) CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, CX8, 3); CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, FMA, 3); CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, HTT, 3); + CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, IBT, 3); CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, RTM, 3); } break; @@ -186,6 +187,7 @@ TUNABLE_CALLBACK (set_hwcaps) (tunable_val_t *valp) { CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, LZCNT, 5); CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, MOVBE, 5); + CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SHSTK, 5); CHECK_GLIBC_IFUNC_CPU_OFF (n, cpu_features, SSSE3, 5); } break;