Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp2408822ybg; Fri, 5 Jun 2020 13:11:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx2Bp4K6scInYHVe3ZL2JCBz5HQVCs28blSKxN+0Z7lq2NLYjlJ0Pw77h+O+bwhlu+mH3jE X-Received: by 2002:aa7:db51:: with SMTP id n17mr10566125edt.241.1591387904599; Fri, 05 Jun 2020 13:11:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591387904; cv=none; d=google.com; s=arc-20160816; b=UEloTgxByjTK5pNW0XuZXS5edNrSu805TNaPSUgqquLdu96mnMNh6uGqEK7wIug/v1 tX7F5K/iIQzkVOu/CxuHLPELPrdTik3EgD7Rm4Z0gNc6sFj1plbObiqIRw2HLNqJN3x/ 1ZFz08cjJJYMP6eIUBArizV3HFheWVZsrwklUOvooyX5jOggBEj0Pd0Xu7bCcWciSpx5 SIyXecUIbx8MwNWRSnNLBz0+8Fh0RGKtmaC9IhjUcTCuSFVczikcX3wm8C8lXdHJ5R1T NHy636y4alt51wJ7VcMjVw/7h/nLCDI3S3cFZqh6IYmcddFU9XPlcCxTyjwMCI7RaHzK 2Pcg== 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 :message-id:date:subject:cc:to:from:ironport-sdr:ironport-sdr; bh=UbXyeb8bXzCwnFLgVTei+Vx8ovjJ+84VSh2WYdUCIXk=; b=LppxeGJfN7YU86zRmckKVGh7R/s5Wvzo6eayR5iu4yuA1vzASl08Q+vFP2ZWm5YekY lvx18SMko858gH2pw4O9PuFXWyIhtrIhKLw+yXidx3VZHM6cHuT496V4hPh6lWpGDhX3 CvxjcYI0sMuZka5GWTOtHeM80Nxc6/Mb6MnsYTqva9cWlp9wRBvwGNT7ssucbLeZ8du+ QyVt0fOJSe8xKKA9sTbk/QtYpge85LEffnTUjoFZKDuf0NsDF/P8t1RGujr62nNe99K2 BJQYFjyCrWTIF1bySCJufevMCyRl4VGPKXfa140VKvZ9ebOLpYOUZi5YQu7fqVoo5cxg KNeQ== 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 cd26si4036009ejb.136.2020.06.05.13.11.21; Fri, 05 Jun 2020 13:11:44 -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 S1728214AbgFEUHb (ORCPT + 99 others); Fri, 5 Jun 2020 16:07:31 -0400 Received: from mga06.intel.com ([134.134.136.31]:29603 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727863AbgFEUHb (ORCPT ); Fri, 5 Jun 2020 16:07:31 -0400 IronPort-SDR: 9+/foVPL4zKWpLFPjcMZ5jOulC2NGrrkaSmrW0fmrRkxCSZDxFduUa77/GlPCsfV9GwjecvihX ZFVqsJkSugug== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2020 13:07:30 -0700 IronPort-SDR: isHsEJJwy5bDEQA3VzN4WLRvdBKo8wguUddVPlTivtJSK5oLw205TZHHBA1nmxfFh3FXYe6Yxy 6rJTfRuXs+0g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,477,1583222400"; d="scan'208";a="305171032" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.152]) by fmsmga002.fm.intel.com with ESMTP; 05 Jun 2020 13:07:29 -0700 From: Sean Christopherson To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "Rafael J. Wysocki" , Pavel Machek Cc: "H. Peter Anvin" , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Brad Campbell , Maxim Levitsky , Paolo Bonzini , kvm@vger.kernel.org, Sean Christopherson Subject: [PATCH] x86/cpu: Reinitialize IA32_FEAT_CTL MSR on BSP during wakeup Date: Fri, 5 Jun 2020 13:07:28 -0700 Message-Id: <20200605200728.10145-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.26.0 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 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. Reported-by: Brad Campbell Cc: Maxim Levitsky Cc: Paolo Bonzini Cc: kvm@vger.kernel.org Fixes: 21bd3467a58e ("KVM: VMX: Drop initialization of IA32_FEAT_CTL MSR") Signed-off-by: Sean Christopherson --- arch/x86/include/asm/cpu.h | 5 +++++ arch/x86/kernel/cpu/cpu.h | 4 ---- arch/x86/power/cpu.c | 6 ++++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/cpu.h b/arch/x86/include/asm/cpu.h index dd17c2da1af5..da78ccbd493b 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/cpu.h b/arch/x86/kernel/cpu/cpu.h index 37fdefd14f28..38ab6e115eac 100644 --- a/arch/x86/kernel/cpu/cpu.h +++ b/arch/x86/kernel/cpu/cpu.h @@ -80,8 +80,4 @@ extern void x86_spec_ctrl_setup_ap(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/power/cpu.c b/arch/x86/power/cpu.c index aaff9ed7ff45..b0d3c5ca6d80 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.26.0