Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp684785pxb; Wed, 3 Feb 2021 15:20:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJw+OBlsMjPCET2tZvPke0tI1jw/CN6ehIFqWLAvkUNtCBUdx2HbxX1as1RfP8ZHIktL/4tB X-Received: by 2002:a05:6402:2c5:: with SMTP id b5mr5657608edx.258.1612394427718; Wed, 03 Feb 2021 15:20:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612394427; cv=none; d=google.com; s=arc-20160816; b=R5CQkfONO0lAVSye2nsxaBQDhAlUPjdZvXwQRu6Ymbo9dW/QLeSSD6dzU29dIZA5va nuT/hGWTXgjh57iYYyj5fClS3iVw8yXFqreg2X5NmNFVHkDi3xKipz20W6GUuSe/K+3r ij0Rj2O7wzRhAIjPCa3nrm555U1v+9MTci75nBx/2XjVroGsflxX7NSJUkLpp5Ar1SOy nsqPWse4cmA62tGU1rXuchH0QgbtVq7QX+a3L5ehxj43fyOr/azcUTSrm5a61hrQrijs l+o0noBTq8RrcsW4EJsHZtoe+pWOr7AQOuyyiZl8IGH9ZmY9Eendw0FSxbXGUPWMu89I UaOQ== 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=V4PH2SGAWEhygWfUYKgGfYPI4ADRTPZYK40NSAHRwSQ=; b=t77mY/9DBz9NA30qEmojWKdSLYjsVmAyk6fes1dhDQi1R2yCTp41wKdUP5ngn539wK wfKXxXfhYEhKKxiJj5eN18sNkoHOjwIpdhnNHlDe4pSekHrUYzNopOhF6kOKXYoS9L0d idb4RsGanZ5lT1Ru9gjZCNoDin+aCRpCU2+qm64gB9aAWdARRTSHZa/it7NwN3Ayug8m spUYBZgikF78N+mJc+dA9HZZLEO0lmswzEJ1Xsqid+o6vxDlZxGy5/feexuiBTzuEBMm hXHW0x9xa1HVPQfFnZmJ2qjOfEEiyJLppwze1cXmgFU2jio1vgeSWIgVYOXScKO4OwzS Xv5w== 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 c95si2979951edf.605.2021.02.03.15.20.03; Wed, 03 Feb 2021 15:20:27 -0800 (PST) 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 S233019AbhBCW5E (ORCPT + 99 others); Wed, 3 Feb 2021 17:57:04 -0500 Received: from mga06.intel.com ([134.134.136.31]:30209 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232867AbhBCW5D (ORCPT ); Wed, 3 Feb 2021 17:57:03 -0500 IronPort-SDR: Ni/F9M3wU5WiBOFENdpqlyFnVeQbhznkm4ZuAOj8G5UyY+Vq6M3yPu3guRjFvenLAWg5XfYy+k MjxvXuokEX+A== X-IronPort-AV: E=McAfee;i="6000,8403,9884"; a="242642346" X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="242642346" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 14:56:21 -0800 IronPort-SDR: yOgTmwwF+VBVInVTzo9DS/ZHpr+IqAsrsxyhfO4VmsnizxpRISWautvZTWaby2OUP3IwXnzl/k 2EHj+i4QBlBg== X-IronPort-AV: E=Sophos;i="5.79,399,1602572400"; d="scan'208";a="507921063" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Feb 2021 14:56:21 -0800 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 Cc: Yu-cheng Yu Subject: [PATCH v19 03/25] x86/cpufeatures: Add CET CPU feature flags for Control-flow Enforcement Technology (CET) Date: Wed, 3 Feb 2021 14:55:25 -0800 Message-Id: <20210203225547.32221-4-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210203225547.32221-1-yu-cheng.yu@intel.com> References: <20210203225547.32221-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 --- arch/x86/include/asm/cpufeatures.h | 2 ++ arch/x86/include/asm/disabled-features.h | 12 ++++++++++-- arch/x86/kernel/cpu/cpuid-deps.c | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 84b887825f12..292fe87b26b3 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 7947cb1782da..a66e7f34b788 100644 --- a/arch/x86/include/asm/disabled-features.h +++ b/arch/x86/include/asm/disabled-features.h @@ -68,6 +68,14 @@ # define DISABLE_SGX (1 << (X86_FEATURE_SGX & 31)) #endif +#ifdef CONFIG_X86_CET +#define DISABLE_SHSTK 0 +#define DISABLE_IBT 0 +#else +#define DISABLE_SHSTK (1 << (X86_FEATURE_SHSTK & 31)) +#define DISABLE_IBT (1 << (X86_FEATURE_IBT & 31)) +#endif + /* * Make sure to add features to the correct mask */ @@ -88,9 +96,9 @@ #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_MASK18 (DISABLE_IBT) #define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 19) #endif /* _ASM_X86_DISABLED_FEATURES_H */ diff --git a/arch/x86/kernel/cpu/cpuid-deps.c b/arch/x86/kernel/cpu/cpuid-deps.c index 42af31b64c2c..52d9a682a0e6 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_XSAVES }, {} }; -- 2.21.0