Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4831114pxy; Tue, 27 Apr 2021 13:45:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjavi1EdFLmdihucM9CNhax8lvLH2Kx7MIyBQoV8/nsjbRC+macnH5ltnDAvcl2iPMGmS6 X-Received: by 2002:a17:902:bd8b:b029:ec:7e58:a544 with SMTP id q11-20020a170902bd8bb02900ec7e58a544mr26413216pls.26.1619556321001; Tue, 27 Apr 2021 13:45:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619556320; cv=none; d=google.com; s=arc-20160816; b=c5cLJMKpc44Tgon6muEhyivgeRQqrJxyOIiSqePWMFYzcRIXaBiVsb8k1+j4/4oxcG 0nMKSBgh3xhxv/0kNIoPD/fGPv6OMfugH/swoqx3Xit/E86ESj/XxCJb7ZtNwpd8l5ee 1iDr3G63s+6PrTOU1aUsSQZd8kdeOd4C/HSFUW3OAPgb4ZaLFrIrona1eA5hgs9Q9QuY w0JaKvyntrQQWQO5vAqttdBigPXx5aQhFVRL6Vs75vBDsUO0hSsjvYbmRlTB1L0OtrkG a+GdmLZl6U8rXkkw4XS1f86YwQ08izbN7j4wnN0CPPMhWwyIOYjwVYvumfHXplmnCFYD 7eiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=Dk39Ws9ktAQI4X/Z/2BnnRc19vW5cqOJZbvYi0iUo2g=; b=VkU2Tl0xRbsW/q5PVku5FAHS2Vw/os0CjMu4lKo6CJrwulgpQVVDCB6OEqq6VkfByf qHSX8G6M1Pgkyuncs9Lozn4gubFdCg3YBQFAZU9mmksjjTMpeUjABAOboSlJsPCsXqoA qO8Jhuf0B240Q0AS3aa2CU7Vhw6E6RBZDB/ETsRkd2csfWnKMpG87CjK89yELCaukzjn e1dmQThcCMCJhatdMuFsc6auSnTEu8eRnsUdhTD/aT7mrbNvofdiXekkdRj47yHczjUT MK+7HhU4P9tvG7E1FiUrXsM5qjDy7K54Rsjf1CdrCf9dj4KT2L6OV0cjjzBYN2KcoMHq UyGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si4434014pjn.117.2021.04.27.13.45.07; Tue, 27 Apr 2021 13:45:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239101AbhD0UpF (ORCPT + 99 others); Tue, 27 Apr 2021 16:45:05 -0400 Received: from mga05.intel.com ([192.55.52.43]:31782 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239054AbhD0Uow (ORCPT ); Tue, 27 Apr 2021 16:44:52 -0400 IronPort-SDR: 1yqH3xB3bAh5Se+pC6iAkwvyxaHyK3jspmhSxgYg8SvViAqk8c6ob+ThW1yr4LSly55drCy2lE paYOWONbx/tA== X-IronPort-AV: E=McAfee;i="6200,9189,9967"; a="281922450" X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="281922450" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2021 13:44:08 -0700 IronPort-SDR: Bcd+EzFtUu7eKQIVxc54Wc1U0Fn8Bqa4xygyz/f6h4gezmT1DKRP6bbgibVqaSXDjPGhB+z9jg 5r6ZcRHMSd/Q== X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="465623432" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Apr 2021 13:44:07 -0700 From: Yu-cheng Yu To: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang Cc: Yu-cheng Yu Subject: [PATCH v26 03/30] x86/cpufeatures: Add CET CPU feature flags for Control-flow Enforcement Technology (CET) Date: Tue, 27 Apr 2021 13:42:48 -0700 Message-Id: <20210427204315.24153-4-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210427204315.24153-1-yu-cheng.yu@intel.com> References: <20210427204315.24153-1-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add CPU feature flags for Control-flow Enforcement Technology (CET). CPUID.(EAX=7,ECX=0):ECX[bit 7] Shadow stack CPUID.(EAX=7,ECX=0):EDX[bit 20] Indirect Branch Tracking Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Make X86_FEATURE_IBT depend on X86_FEATURE_SHSTK. v24: - Update for splitting CONFIG_X86_CET to CONFIG_X86_SHADOW_STACK and CONFIG_X86_IBT. - Move DISABLE_IBT definition to the IBT series. arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/disabled-features.h | 8 +++++++- arch/x86/kernel/cpu/cpuid-deps.c | 2 ++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index cc96e26d69f7..bf861fc89fef 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -345,6 +345,7 @@ #define X86_FEATURE_OSPKE (16*32+ 4) /* OS Protection Keys Enable */ #define X86_FEATURE_WAITPKG (16*32+ 5) /* UMONITOR/UMWAIT/TPAUSE Instructions */ #define X86_FEATURE_AVX512_VBMI2 (16*32+ 6) /* Additional AVX512 Vector Bit Manipulation Instructions */ +#define X86_FEATURE_SHSTK (16*32+ 7) /* Shadow Stack */ #define X86_FEATURE_GFNI (16*32+ 8) /* Galois Field New Instructions */ #define X86_FEATURE_VAES (16*32+ 9) /* Vector AES */ #define X86_FEATURE_VPCLMULQDQ (16*32+10) /* Carry-Less Multiplication Double Quadword */ @@ -377,6 +378,7 @@ #define X86_FEATURE_TSXLDTRK (18*32+16) /* TSX Suspend Load Address Tracking */ #define X86_FEATURE_PCONFIG (18*32+18) /* Intel PCONFIG */ #define X86_FEATURE_ARCH_LBR (18*32+19) /* Intel ARCH LBR */ +#define X86_FEATURE_IBT (18*32+20) /* Indirect Branch Tracking */ #define X86_FEATURE_AVX512_FP16 (18*32+23) /* AVX512 FP16 */ #define X86_FEATURE_SPEC_CTRL (18*32+26) /* "" Speculation Control (IBRS + IBPB) */ #define X86_FEATURE_INTEL_STIBP (18*32+27) /* "" Single Thread Indirect Branch Predictors */ diff --git a/arch/x86/include/asm/disabled-features.h b/arch/x86/include/asm/disabled-features.h index b7dd944dc867..e5c6ed9373e8 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -68,6 +68,12 @@ # define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31)) #endif +#ifdef CONFIG_X86_SHADOW_STACK +#define DISABLE_SHSTK 0 +#else +#define DISABLE_SHSTK (1 << (X86_FEATURE_SHSTK & 31)) +#endif + /* * Make sure to add features to the correct mask */ @@ -88,7 +94,7 @@ #define DISABLED_MASK14 0 #define DISABLED_MASK15 0 #define DISABLED_MASK16 (DISABLE_PKU|DISABLE_OSPKE|DISABLE_LA57|DISABLE_UMIP| \ - DISABLE_ENQCMD) + DISABLE_ENQCMD|DISABLE_SHSTK) #define DISABLED_MASK17 0 #define DISABLED_MASK18 0 #define DISABLED_MASK19 0 diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index 42af31b64c2c..c88b7e0ebf6d 100644 --- a/arch/x86/kernel/cpu/cpuid-deps.c +++ b/arch/x86/kernel/cpu/cpuid-deps.c @@ -72,6 +72,8 @@ static const struct cpuid_dep cpuid_deps[] = { { X86_FEATURE_AVX512_FP16, X86_FEATURE_AVX512BW }, { X86_FEATURE_ENQCMD, X86_FEATURE_XSAVES }, { X86_FEATURE_PER_THREAD_MBA, X86_FEATURE_MBA }, + { X86_FEATURE_SHSTK, X86_FEATURE_XSAVES }, + { X86_FEATURE_IBT, X86_FEATURE_SHSTK }, {} }; -- 2.21.0