Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp3087843ybt; Mon, 29 Jun 2020 15:02:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJweQyTDZTVTnMNI1Mh0MgasHcxr1hRZEhrBJNltobiNl7Me/wnnAOBkp+dZVLZeK2hOtm+z X-Received: by 2002:a17:906:3ac4:: with SMTP id z4mr14097379ejd.65.1593468178119; Mon, 29 Jun 2020 15:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593468178; cv=none; d=google.com; s=arc-20160816; b=SUS70tLfkXDBuX3iStySLt3VL5wC3vR4BAR9qjXqkRDSGlNbPGKqzhtMPZ15lRkv7t E/kzuUGYTWAvr/gF1nGJRlepFoG4rgW7RUj3ADkgWAMukc4tnUZwBXeT05hgbiAekywM PVyWawGHY/4GKqRmRVzGqC3TKUEwN5GExyPVsJihx1ItzPaa3kAOElRNVzIuf51K05Aq oSuDuP8mCQakwOIYSmwunqOsptw6tXsx0URJvnb6nAtAnvcCZ5+gbnEMysuRewZDISoe 7mqa7YQ8Ujm4Xf+nVnewZRYPc4SK+lcHz+HjbUaab02FfelvimZoGUaHC517Q/VS5AEY dzUQ== 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 :dkim-signature; bh=B71wppCrxvMnp7PlQ6wRBh8adxaEqzudkETbW5Hpc/c=; b=BHnjOqN9kWFLw6ZQ3jeT2NNCze3Vf2nZYAQpNhi4WgMBg0I/cK+7lqyaaVzG7+YZyu cx0SPtYV46PezVGekpDTtdRBOm+x4MEHWYOUI6Mkaop+FRY1A3Ba0FR2PmmBcDoS3/oM /1SyDkV5tv4Axq1DuV9ocTrIhCCoYcPLNN7djXY0w7gbepKZJXogZahsWD2naswUqAh5 gjO1h3/v4XLALThSHm3J30wlFfEJRqTdypyavx9a5GwGZFMyISmURaSGnhlpY/OhKffP NhQEpBLkeTzS5bou7QjCvPV03NTKyjGpNsFC9CLRfC6BRsxvq9wmEjoX02zJK5DhmntV GfqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=j2YMD96J; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id cw21si435029edb.600.2020.06.29.15.02.34; Mon, 29 Jun 2020 15:02: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; dkim=pass header.i=@kernel.org header.s=default header.b=j2YMD96J; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404519AbgF2WA6 (ORCPT + 99 others); Mon, 29 Jun 2020 18:00:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:56886 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726301AbgF2SfY (ORCPT ); Mon, 29 Jun 2020 14:35:24 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B8CD247A1; Mon, 29 Jun 2020 15:21:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1593444109; bh=jtQ9krYpw0F1Pk4uWyQOXj1u1Ae2KuvA8Ghy1N/XZJQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j2YMD96Jd6Md7ies4Y/qzqLqjImq0bTdOxBToPh4rPcxRVHbT9v9VLLNQJ0gVB99+ TpvevKXhgAxgGlpQOTisMEZuKFd0gPnXGuzJ9rNgRjBgB0YCVDATtBOFWmK5ItRE33 O2Qyd6SaI6/gv0bawDh44Z+ue+EQb3kxHF8QqEgA= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Sean Christopherson , Brad Campbell , Borislav Petkov , Liam Merwick , Maxim Levitsky , Greg Kroah-Hartman Subject: [PATCH 5.7 220/265] x86/cpu: Reinitialize IA32_FEAT_CTL MSR on BSP during wakeup Date: Mon, 29 Jun 2020 11:17:33 -0400 Message-Id: <20200629151818.2493727-221-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200629151818.2493727-1-sashal@kernel.org> References: <20200629151818.2493727-1-sashal@kernel.org> MIME-Version: 1.0 X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v5.x/stable-review/patch-5.7.7-rc1.gz X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git X-KernelTest-Branch: linux-5.7.y X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git X-KernelTest-Version: 5.7.7-rc1 X-KernelTest-Deadline: 2020-07-01T15:14+00:00 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson commit 5d5103595e9e53048bb7e70ee2673c897ab38300 upstream. Reinitialize IA32_FEAT_CTL on the BSP during wakeup to handle the case where firmware doesn't initialize or save/restore across S3. This fixes a bug where IA32_FEAT_CTL is left uninitialized and results in VMXON taking a #GP due to VMX not being fully enabled, i.e. breaks KVM. Use init_ia32_feat_ctl() to "restore" IA32_FEAT_CTL as it already deals with the case where the MSR is locked, and because APs already redo init_ia32_feat_ctl() during suspend by virtue of the SMP boot flow being used to reinitialize APs upon wakeup. Do the call in the early wakeup flow to avoid dependencies in the syscore_ops chain, e.g. simply adding a resume hook is not guaranteed to work, as KVM does VMXON in its own resume hook, kvm_resume(), when KVM has active guests. Fixes: 21bd3467a58e ("KVM: VMX: Drop initialization of IA32_FEAT_CTL MSR") Reported-by: Brad Campbell Signed-off-by: Sean Christopherson Signed-off-by: Borislav Petkov Reviewed-by: Liam Merwick Reviewed-by: Maxim Levitsky Tested-by: Brad Campbell Cc: stable@vger.kernel.org # v5.6 Link: https://lkml.kernel.org/r/20200608174134.11157-1-sean.j.christopherson@intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/cpu.h | 5 +++++ arch/x86/kernel/cpu/centaur.c | 1 + arch/x86/kernel/cpu/cpu.h | 4 ---- arch/x86/kernel/cpu/zhaoxin.c | 1 + arch/x86/power/cpu.c | 6 ++++++ 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index dd17c2da1af5f..da78ccbd493b7 100644 --- a/arch/x86/include/asm/cpu.h +++ b/arch/x86/include/asm/cpu.h @@ -58,4 +58,9 @@ static inline bool handle_guest_split_lock(unsigned long ip) return false; } #endif +#ifdef CONFIG_IA32_FEAT_CTL +void init_ia32_feat_ctl(struct cpuinfo_x86 *c); +#else +static inline void init_ia32_feat_ctl(struct cpuinfo_x86 *c) {} +#endif #endif /* _ASM_X86_CPU_H */ diff --git a/arch/x86/kernel/cpu/centaur.c b/arch/x86/kernel/cpu/centaur.c index 426792565d864..c5cf336e50776 100644 --- a/arch/x86/kernel/cpu/centaur.c +++ b/arch/x86/kernel/cpu/centaur.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/arch/x86/kernel/cpu/cpu.h b/arch/x86/kernel/cpu/cpu.h index fb538fccd24c0..9d033693519aa 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -81,8 +81,4 @@ extern void update_srbds_msr(void); extern u64 x86_read_arch_cap_msr(void); -#ifdef CONFIG_IA32_FEAT_CTL -void init_ia32_feat_ctl(struct cpuinfo_x86 *c); -#endif - #endif /* ARCH_X86_CPU_H */ diff --git a/arch/x86/kernel/cpu/zhaoxin.c b/arch/x86/kernel/cpu/zhaoxin.c index df1358ba622bd..05fa4ef634902 100644 --- a/arch/x86/kernel/cpu/zhaoxin.c +++ b/arch/x86/kernel/cpu/zhaoxin.c @@ -2,6 +2,7 @@ #include #include +#include #include #include "cpu.h" diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c index aaff9ed7ff45c..b0d3c5ca6d807 100644 --- a/arch/x86/power/cpu.c +++ b/arch/x86/power/cpu.c @@ -193,6 +193,8 @@ static void fix_processor_context(void) */ static void notrace __restore_processor_state(struct saved_context *ctxt) { + struct cpuinfo_x86 *c; + if (ctxt->misc_enable_saved) wrmsrl(MSR_IA32_MISC_ENABLE, ctxt->misc_enable); /* @@ -263,6 +265,10 @@ static void notrace __restore_processor_state(struct saved_context *ctxt) mtrr_bp_restore(); perf_restore_debug_store(); msr_restore_context(ctxt); + + c = &cpu_data(smp_processor_id()); + if (cpu_has(c, X86_FEATURE_MSR_IA32_FEAT_CTL)) + init_ia32_feat_ctl(c); } /* Needed by apm.c */ -- 2.25.1