Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp1228621ybp; Fri, 4 Oct 2019 11:22:04 -0700 (PDT) X-Google-Smtp-Source: APXvYqydQpVfDSVQIMGh68bNpaXVT4pR8c5YSCR0mIiKrqvkA7gK1Fp27kmeYUFVxnM3usa8Zwyq X-Received: by 2002:aa7:cf81:: with SMTP id z1mr16797389edx.224.1570213324621; Fri, 04 Oct 2019 11:22:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570213324; cv=none; d=google.com; s=arc-20160816; b=IOUfobm2EX1vRb/YojzcL54w9pRIppBhkyVuTHkIv2AqBVSY2IPSDh14PpYrbnVhuG OU1ZJOF1n7iMyH4+LQQSedZSs478tfrCUcU9nQ7PO53KlgxJKUX5O9FNCCtut5b4+78j oOJMqJNPdVQE8tGTLyO5csD7bBKXkSr1GF3wwQiUJkyARy9XIZ8PW+P1ulpznhBOgqkq fqBYvPPrHAtuoSQzyXEP/aHFY64Imacz+7pKWiQzNqgf94hc6HU+0dwZjuiXNplYuc2y vHpHgomXvyE6OLX7zAwi1VvnGqTMXdK2f6iW43nID5hYUfRS24WcH9iMVpMwd6RbArSJ FEtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=341L08r7MTrx/Vmn4mToxnM4Tgvk3Qb0jQ1ogUQz4tI=; b=iu13JLe/Du8JSQfuzEgzKUPzxTMB1YaarRIB+bk0mc1TId7zOWiPglyv8257MmcEYa q4a9j0yCtSZ1BtlCfCbObcL3Eof2kd9IoN0e6rdDH5Lt50Onfclo+t9fOc1QdduaD2Wz WntBUL2e2Opcfx2lGejX3sHv79YEV/6QIOnex6ZDZ/lpu19Mzuc4AaiqVO93wvXboYFn xC+NBaMp7RkzNduMhcEP9ob70aKz/mJr0ip9/sg09dNVh3dRWdbpHeE20xETCPgWV5kU kMpsOJLSAT31FRAqhtDU/3E9GM4Tbtl4CiHCRu8p7KPMztAI2AiYCyqebHCTceNyW5k3 F//A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id 96si4060727edq.24.2019.10.04.11.21.40; Fri, 04 Oct 2019 11:22:04 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1730627AbfJDSRw (ORCPT + 99 others); Fri, 4 Oct 2019 14:17:52 -0400 Received: from mga07.intel.com ([134.134.136.100]:15508 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730454AbfJDSRA (ORCPT ); Fri, 4 Oct 2019 14:17:00 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Oct 2019 11:16:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.67,257,1566889200"; d="scan'208";a="204394753" Received: from chang-linux-3.sc.intel.com ([172.25.66.185]) by orsmga002.jf.intel.com with ESMTP; 04 Oct 2019 11:16:59 -0700 From: "Chang S. Bae" To: linux-kernel@vger.kernel.org, tglx@linutronix.de, bp@alien8.de, luto@kernel.org Cc: hpa@zytor.com, dave.hansen@intel.com, tony.luck@intel.com, ak@linux.intel.com, ravi.v.shankar@intel.com, chang.seok.bae@intel.com Subject: [PATCH v9 03/17] x86/cpu: Add 'unsafe_fsgsbase' to enable CR4.FSGSBASE Date: Fri, 4 Oct 2019 11:15:55 -0700 Message-Id: <1570212969-21888-4-git-send-email-chang.seok.bae@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1570212969-21888-1-git-send-email-chang.seok.bae@intel.com> References: <1570212969-21888-1-git-send-email-chang.seok.bae@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andy Lutomirski This is temporary. It will allow the next few patches to be tested incrementally. Setting unsafe_fsgsbase is a root hole. Don't do it. Signed-off-by: Andy Lutomirski Signed-off-by: Chang S. Bae Reviewed-by: Tony Luck Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Andy Lutomirski Cc: H. Peter Anvin Cc: Dave Hansen Cc: Tony Luck Cc: Andi Kleen --- Changes from v8: none Changes from v7: none --- Documentation/admin-guide/kernel-parameters.txt | 3 +++ arch/x86/kernel/cpu/common.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt index c7ac2f3..eb9a491 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -2899,6 +2899,9 @@ no5lvl [X86-64] Disable 5-level paging mode. Forces kernel to use 4-level paging instead. + unsafe_fsgsbase [X86] Allow FSGSBASE instructions. This will be + replaced with a nofsgsbase flag. + no_console_suspend [HW] Never suspend the console Disable suspending of consoles during suspend and diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 9ae7d1b..9f57fb0 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -438,6 +438,22 @@ static void __init setup_cr_pinning(void) } /* + * Temporary hack: FSGSBASE is unsafe until a few kernel code paths are + * updated. This allows us to get the kernel ready incrementally. + * + * Once all the pieces are in place, these will go away and be replaced with + * a nofsgsbase chicken flag. + */ +static bool unsafe_fsgsbase; + +static __init int setup_unsafe_fsgsbase(char *arg) +{ + unsafe_fsgsbase = true; + return 1; +} +__setup("unsafe_fsgsbase", setup_unsafe_fsgsbase); + +/* * Protection Keys are not available in 32-bit mode. */ static bool pku_disabled; @@ -1455,6 +1471,14 @@ static void identify_cpu(struct cpuinfo_x86 *c) setup_smap(c); setup_umip(c); + /* Enable FSGSBASE instructions if available. */ + if (cpu_has(c, X86_FEATURE_FSGSBASE)) { + if (unsafe_fsgsbase) + cr4_set_bits(X86_CR4_FSGSBASE); + else + clear_cpu_cap(c, X86_FEATURE_FSGSBASE); + } + /* * The vendor-specific functions might have changed features. * Now we do "generic changes." -- 2.7.4