Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp4831248pxy; Tue, 27 Apr 2021 13:45:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAbSUz43kLnIMD+mz3nCYZ3Tr2DplD4uTmq+mKgfX0sXllECbGj4evo4ZkOT1oZk9e7lZT X-Received: by 2002:a17:90a:4290:: with SMTP id p16mr166069pjg.120.1619556336255; Tue, 27 Apr 2021 13:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619556336; cv=none; d=google.com; s=arc-20160816; b=CsHPIAv8veA7w6YHmzM5KDHAXL1Sy0I129iScTXOMvKuZagvmhtL9XW5FG/2+KkHPe zBOCYIGjk9lkeJoaalZa7I2pXPWB43HVvPi25E+FlP08zOrZ000Xl84FCDPPTw4+Wbl8 0wrez2YPkqOyVGWoaKMsioDY2GlRrhuQyKlvfUkXkkec9v4laL2Ow1AST25BYBR6hh3n QWDYR77nahTg4EU+ThG73bsQFm/kjEKLnVP/GlySdP4AusHkuSXQgBRn0gXkpyGXfmrL m/7db/qA2jzv6QNzuqpayqjuewMTPusH77T2Q+ugNXD3YAR/pJz/9CGcaCYn0r84h66c fupA== 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=r4wY4SR0hFTSzA/ydxmGbGowcqRTUDjJVmbA0ujOl98=; b=S92TtuN6/1Zzjwk8MQUgf8tKS3hOoAKSGKxyY4xvEuLAdwonrdnsZVqxfHcxdD9IyN OG1/RiOWxUerq/kailqWtMnz7mIqpwZ7l4JvtJ+xDJplMLm7UpTjvatzEAOpoUxFkLk4 HG35tZfbydGYge/gAiSUxqKc0PmuC64H3gQYJ+WHXHuKwm/VxfPdghffcM6LeAGlB/ew 99kUBF1epFYDSkg817ifMnYkXvV60Bb+Cnm7578P20LRj+V5b0nLCbQkXYh6Xjn5L7ww pOvjB3uTD1pzRQ4jZIQjndnilyS+VOZn5gDDINY0yd9bcYravU0Uy/GAgPewte1NFhMA dhXg== 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 m9si948246pgp.302.2021.04.27.13.45.22; Tue, 27 Apr 2021 13:45:36 -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 S239114AbhD0UpK (ORCPT + 99 others); Tue, 27 Apr 2021 16:45:10 -0400 Received: from mga05.intel.com ([192.55.52.43]:31780 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235416AbhD0UpA (ORCPT ); Tue, 27 Apr 2021 16:45:00 -0400 IronPort-SDR: I57lO1CfP4ghGBwyHvx8pDO50yTcJG+djc0a8LhKH6nQR0apqkcqJ68NqcvuVcgz0DeUrP1dv0 sua5sVSIikhQ== X-IronPort-AV: E=McAfee;i="6200,9189,9967"; a="281922452" X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="281922452" 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: +tXvO61IkH4zH7pJV2sVpNWnofhwenRDVDS/7i0ig/pVnhV9EyAHWTpko3HUu3GazYRoxKx7IE tHDu0dZ9obWw== X-IronPort-AV: E=Sophos;i="5.82,255,1613462400"; d="scan'208";a="465623436" 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:08 -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 04/30] x86/cpufeatures: Introduce CPU setup and option parsing for CET Date: Tue, 27 Apr 2021 13:42:49 -0700 Message-Id: <20210427204315.24153-5-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 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 ab640abe26b6..b6eeb5f2ae4d 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -510,6 +510,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 @@ -1255,6 +1263,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; @@ -1594,6 +1607,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