Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1687155pxb; Fri, 20 Aug 2021 11:20:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwAqd279rkK8IjK+XOf+QFd7WLEgsA9iLqIrtj8DjNqkeQIWwyhmWXcuB+B0CwT3XDjV6my X-Received: by 2002:a6b:b883:: with SMTP id i125mr16568969iof.144.1629483626865; Fri, 20 Aug 2021 11:20:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629483626; cv=none; d=google.com; s=arc-20160816; b=Uc/QFFVq2c/iYCNsm33+ta+bXTx9JLhJgxvfiS5K1oW5ycUb2RFtjDovjyOsvCqXiq HXmBo+8D6eMWh2sOjd1O6kWMnFZJ83V+yDmNWTuvb3l1GefdyFvP5UPyzID2G5foWeZf 69zN8x9blHe9tsuI65ePdF9MgniIEYMumVRTf1w6A2t8oVUfC+9Cz6BnAslUE1UwD87E 5xUmIaUZa6bQ9izMpB9HMjlfa8LJlSrkt7TUYz20LO1JQhZmZocQxkxGzdyOwpDiybWo voPqOlkt7/9rp2HYppjZQJq4TddJlvsTptdL9phltitx58POtI1x33DXdupHNeSgUnMG Peow== 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; bh=eZXum/nrtoAyXRtJUdH+PSi0BrUMMwOtqPCawoNtR9g=; b=XoFVvWAD/30JiGzTWPKZYNPHbFTrtmIsxVp3r/VI7beUh3SL/edLXvgr7zNto0EHLP /zmiIGCIbxS90KCk2Ae4MgjvpEti++bbiNyyZM/Qb0jlsZY1jMxZtVEIQAf0yNIAT5x+ AOW59Q58EWQm9tznV9PKFNPXHKnAlLgaUJbHmAWqj6f8BykJTyUbehWKFc97jkbn5FwD FPitHDcIAH6m09nX3EJ07TvaylHeuo3JXeOn/F0pz89DIeiG+csltp2FSU69djBEutyp b4m2n+EJRv6KahnKaY2Vnnw5KrYGAda3ljQ6hSUWIvbyda7cDTdp8XWpKiugpNPti2TJ VaDw== 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 a7si7230708ilr.103.2021.08.20.11.20.15; Fri, 20 Aug 2021 11:20:26 -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 S236103AbhHTST7 (ORCPT + 99 others); Fri, 20 Aug 2021 14:19:59 -0400 Received: from mga05.intel.com ([192.55.52.43]:22426 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236037AbhHTSTY (ORCPT ); Fri, 20 Aug 2021 14:19:24 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10082"; a="302407784" X-IronPort-AV: E=Sophos;i="5.84,338,1620716400"; d="scan'208";a="302407784" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 11:18:44 -0700 X-IronPort-AV: E=Sophos;i="5.84,338,1620716400"; d="scan'208";a="533074678" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by fmsmga002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Aug 2021 11:18:44 -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" , Dave Martin , Weijiang Yang , Pengfei Xu , Haitao Huang , Rick P Edgecombe Cc: Yu-cheng Yu Subject: [PATCH v29 04/32] x86/cpufeatures: Introduce CPU setup and option parsing for CET Date: Fri, 20 Aug 2021 11:11:33 -0700 Message-Id: <20210820181201.31490-5-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210820181201.31490-1-yu-cheng.yu@intel.com> References: <20210820181201.31490-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 Introduce CPU setup and boot option parsing for CET features. Signed-off-by: Yu-cheng Yu Cc: Kees Cook --- v25: - Remove software-defined X86_FEATURE_CET. v24: - Update #ifdef placement to reflect Kconfig changes of splitting shadow stack and ibt. --- arch/x86/include/uapi/asm/processor-flags.h | 2 ++ arch/x86/kernel/cpu/common.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/x86/include/uapi/asm/processor-flags.h b/arch/x86/include/uapi/asm/processor-flags.h index bcba3c643e63..a8df907e8017 100644 --- a/arch/x86/include/uapi/asm/processor-flags.h +++ b/arch/x86/include/uapi/asm/processor-flags.h @@ -130,6 +130,8 @@ #define X86_CR4_SMAP _BITUL(X86_CR4_SMAP_BIT) #define X86_CR4_PKE_BIT 22 /* enable Protection Keys support */ #define X86_CR4_PKE _BITUL(X86_CR4_PKE_BIT) +#define X86_CR4_CET_BIT 23 /* enable Control-flow Enforcement */ +#define X86_CR4_CET _BITUL(X86_CR4_CET_BIT) /* * x86-64 Task Priority Register, CR8 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 64b805bd6a54..714dd97870ba 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -505,6 +505,14 @@ static __init int setup_disable_pku(char *arg) __setup("nopku", setup_disable_pku); #endif /* CONFIG_X86_64 */ +static __always_inline void setup_cet(struct cpuinfo_x86 *c) +{ + if (!cpu_feature_enabled(X86_FEATURE_SHSTK)) + return; + + cr4_set_bits(X86_CR4_CET); +} + /* * Some CPU features depend on higher CPUID levels, which may not always * be available due to CPUID level capping or broken virtualization @@ -1249,6 +1257,11 @@ static void __init cpu_parse_early_param(void) if (cmdline_find_option_bool(boot_command_line, "noxsaves")) setup_clear_cpu_cap(X86_FEATURE_XSAVES); + if (cmdline_find_option_bool(boot_command_line, "no_user_shstk")) + setup_clear_cpu_cap(X86_FEATURE_SHSTK); + if (cmdline_find_option_bool(boot_command_line, "no_user_ibt")) + setup_clear_cpu_cap(X86_FEATURE_IBT); + arglen = cmdline_find_option(boot_command_line, "clearcpuid", arg, sizeof(arg)); if (arglen <= 0) return; @@ -1590,6 +1603,7 @@ static void identify_cpu(struct cpuinfo_x86 *c) x86_init_rdrand(c); setup_pku(c); + setup_cet(c); /* * Clear/Set all flags overridden by options, need do it -- 2.21.0