Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1465770pxj; Fri, 21 May 2021 15:16:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPleQItakuDwHV1uME3qtUE4hbdCX7Lz/48XjBUTmu7UF6N7LacAOaUnyI9FybgNzpdmNZ X-Received: by 2002:a17:906:a18e:: with SMTP id s14mr11854967ejy.311.1621635418900; Fri, 21 May 2021 15:16:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621635418; cv=none; d=google.com; s=arc-20160816; b=N6Sr4vAztBIxIZk0lC2OXpAWT6USPJVrJfMR0Ujsc1KZIvxWpfT7Vyd8lek7AGeFvc 89PzqTT6UKNuPRVzfySjC8+OjtNY90QW87wR9/jLFMlOcg3dTIws20SjSJfnuwb3dlvx scm8Cq9jlBJYFy1LLm5UK7us61P+No/hc1coOdHHlq5oiqYDV6+jNVwlbLMsYFnKhXcL GjsHydVlFNL3uJkgmrcbQ9fUSm3b9j+QTFkTCvh/sUjrKDZSGDIBjx2qyQl5J7oMMg6Z f1cH9q/JZr3K0UrxAtD+9bt2uIq+06woE3F0CvKkMrafn8T8w/YJahYXy0ERyV97Doc6 axcA== 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=YipKwnd9VpHAUV5/24NRWKO0lnKAFWhLNR01wE6cSMQ=; b=syP0VNyB5MvSFwhz2IS3rB9L/HFM80h24EXMbjTNfNIxWI6Jskt1szM6j8R0XOPVpX UxORgvrlFrMgqUpbAHaNLK3gTDjYXOndYtRNjrOyi2IHiT6NxxdxwhhrmEPx+qhiUYZc h99A5KrfI1SjgEqUNLct/db6rihBw1OMWBCx37hEsmae8E07vBZEwsccUjroPk2Tfod/ uMgH7BWWFK5udkWT0aftgjBk8qVnkIHZtifHvOOs9sHuMTeRwGJT+IMHKtBKPkoYHe5a qHF3N0wHKIQgtAw5JpiH6kByIbcYAi8DRfmfcUhqDmTYWDKsbBUmxbumQxA4mNtFV4Hj 6eQg== 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 x10si3706322ejb.330.2021.05.21.15.16.35; Fri, 21 May 2021 15:16:58 -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 S230115AbhEUWOm (ORCPT + 99 others); Fri, 21 May 2021 18:14:42 -0400 Received: from mga17.intel.com ([192.55.52.151]:65511 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229676AbhEUWOb (ORCPT ); Fri, 21 May 2021 18:14:31 -0400 IronPort-SDR: KRM6kyzetRlR1QqjkmNzXLKhCRpwTTTPwLztYk9A+g6zvS7vYnAdAvVJvLQpZEJr/xeBmK+Jml gEtURByG6abg== X-IronPort-AV: E=McAfee;i="6200,9189,9991"; a="181874381" X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="181874381" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2021 15:13:06 -0700 IronPort-SDR: cRMRLuF1oPEbeod78Vu2IkkjDxUO3/6r6iKHR/GdU0RnKfF1j5wf1QdlRXfhiUU4cRzM7O5cDy 8NqWJhp4jcgQ== X-IronPort-AV: E=Sophos;i="5.82,319,1613462400"; d="scan'208";a="441116115" Received: from yyu32-desk.sc.intel.com ([143.183.136.146]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2021 15:13:06 -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 v27 04/31] x86/cpufeatures: Introduce CPU setup and option parsing for CET Date: Fri, 21 May 2021 15:11:44 -0700 Message-Id: <20210521221211.29077-5-yu-cheng.yu@intel.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210521221211.29077-1-yu-cheng.yu@intel.com> References: <20210521221211.29077-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 a1b756c49a93..2612499b739e 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -509,6 +509,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 @@ -1253,6 +1261,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; @@ -1592,6 +1605,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