Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3992913ybl; Fri, 20 Dec 2019 20:49:26 -0800 (PST) X-Google-Smtp-Source: APXvYqzPYaQFrQaMH4l9CU8+lhWHFuDIcNIXYK/9M/41WC9K6fIHRE5sqp3GMeKUbXIugOry4kZt X-Received: by 2002:a9d:470a:: with SMTP id a10mr19431063otf.370.1576903766668; Fri, 20 Dec 2019 20:49:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576903766; cv=none; d=google.com; s=arc-20160816; b=J5KdsgnA9kjpR3dAgFBnXX1eeip/rPW8mMGESiH03E1RVkI8pQeZvt3xxiLQcH5lTo +V4jPC/pKVmLRqFZi0v60PgIte7TAnN4N0ZVs2hhG48m3ny7fLa9nxn4yjtHlBYoYwIW xK7OoH98Myj+3VR8jUw43R8i+c9u3OskCyPnhZ/FlUUhOyvshgoPFhq+44/ZGL95MrpR mb1P0BmyRJ5cTRy4vRHKcO5W8PsR9EVuYfMnEuJ5pC7mIVOFqFrO1zAN/3/ZRGXxCybs z1dkwhdv2tN/frSnJcwx41t6LFJ4dVQj9Jih4TV2+di99KfdbkH8wmt18vZRfo/SMt7Y /mTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=jePgda003OIXStcbXsyQJ4THQvj3c3Cp9X5OUh+wLF0=; b=zq9A26P3F+cVxI3YhhNiEoddXHczu849pm2UTRXAdVBQ8I8htU87/Tkg1vuqBDFDGC g7YCtpxGgGOf6WTK1uDk7RcbeIm1zonc+kj8sOvo1R6j51ZocDfGFkO+aT+L9F5ppVaY D5kcnykC3zp1xy3LO+gMrwekmIa8y6Ga6y23gt7BpHdTJb6Xo7RgY76TF4R75hUWJg+A M3wf8bXKhSzh1fn/CoiJU0rEi01dpDvwy6S3I4UgqlS1sRvhfNpaR8hOiw9kZiJac5zy /8A023HFmJ8HZRFUqs/xSrwkbZ2Ew0i3qP8XHokvMmzSsFKFuaZnEWD6Mul6htdmUfdX IDRg== 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 r132si5307626oig.263.2019.12.20.20.48.37; Fri, 20 Dec 2019 20:49:26 -0800 (PST) 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 S1727535AbfLUEqu (ORCPT + 99 others); Fri, 20 Dec 2019 23:46:50 -0500 Received: from mga03.intel.com ([134.134.136.65]:31837 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727175AbfLUEqE (ORCPT ); Fri, 20 Dec 2019 23:46:04 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Dec 2019 20:46:02 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,338,1571727600"; d="scan'208";a="222620115" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.202]) by fmsmga001.fm.intel.com with ESMTP; 20 Dec 2019 20:46:02 -0800 From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org Cc: "H. Peter Anvin" , Peter Zijlstra , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Tony Luck , Tony W Wang-oc , Jacob Pan , Len Brown , Shuah Khan , linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-edac@vger.kernel.org, linux-pm@vger.kernel.org, linux-kselftest@vger.kernel.org, Borislav Petkov , Jarkko Sakkinen Subject: [PATCH v5 13/19] x86/cpufeatures: Add flag to track whether MSR IA32_FEAT_CTL is configured Date: Fri, 20 Dec 2019 20:45:07 -0800 Message-Id: <20191221044513.21680-14-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191221044513.21680-1-sean.j.christopherson@intel.com> References: <20191221044513.21680-1-sean.j.christopherson@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a new feature flag, X86_FEATURE_MSR_IA32_FEAT_CTL, to track whether IA32_FEAT_CTL has been initialized. This will allow KVM, and any future subsystems that depend on IA32_FEAT_CTL, to rely purely on cpufeatures to query platform support, e.g. allows a future patch to remove KVM's manual IA32_FEAT_CTL MSR checks. Various features (on platforms that support IA32_FEAT_CTL) are dependent on IA32_FEAT_CTL being configured and locked, e.g. VMX and LMCE. The MSR is always configured during boot, but only if the CPU vendor is recognized by the kernel. Because CPUID doesn't incorporate the current IA32_FEAT_CTL value in its reporting of relevant features, it's possible for a feature to be reported as supported in cpufeatures but not truly enabled, e.g. if the CPU supports VMX but the kernel doesn't recognize the CPU. As a result, without the flag, KVM would see VMX as supported even if IA32_FEAT_CTL hasn't been initialized, and so would need to manually read the MSR and check the various enabling bits to avoid taking an unexpected #GP on VMXON. Signed-off-by: Sean Christopherson --- arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/kernel/cpu/feat_ctl.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index e9b62498fe75..67d21b25ff78 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -220,6 +220,7 @@ #define X86_FEATURE_ZEN ( 7*32+28) /* "" CPU is AMD family 0x17 (Zen) */ #define X86_FEATURE_L1TF_PTEINV ( 7*32+29) /* "" L1TF workaround PTE inversion */ #define X86_FEATURE_IBRS_ENHANCED ( 7*32+30) /* Enhanced IBRS */ +#define X86_FEATURE_MSR_IA32_FEAT_CTL ( 7*32+31) /* "" MSR IA32_FEAT_CTL configured */ /* Virtualization flags: Linux defined, word 8 */ #define X86_FEATURE_TPR_SHADOW ( 8*32+ 0) /* Intel TPR Shadow */ diff --git a/arch/x86/kernel/cpu/feat_ctl.c b/arch/x86/kernel/cpu/feat_ctl.c index fcbb35533cef..24a4fdc1ab51 100644 --- a/arch/x86/kernel/cpu/feat_ctl.c +++ b/arch/x86/kernel/cpu/feat_ctl.c @@ -126,6 +126,8 @@ void init_ia32_feat_ctl(struct cpuinfo_x86 *c) wrmsrl(MSR_IA32_FEAT_CTL, msr); update_caps: + set_cpu_cap(c, X86_FEATURE_MSR_IA32_FEAT_CTL); + if (!cpu_has(c, X86_FEATURE_VMX)) return; -- 2.24.1