public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: VMX: Make setup_vmcs_config() preemption disabled
@ 2023-03-01 10:54 Kai Huang
  2023-03-02  5:36 ` Chao Gao
  0 siblings, 1 reply; 7+ messages in thread
From: Kai Huang @ 2023-03-01 10:54 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, seanjc, linux-kernel, Kai Huang

Make setup_vmcs_config() preemption disabled so it always performs on
the same local cpu.

During module loading time, KVM intends to call setup_vmcs_config() to
set up the global VMCS configurations on _one_ cpu in hardware_setup(),
and then calls setup_vmcs_config() on all other online cpus via sending
IPI to perform VMX compatibility check.  Further more, KVM has CPU
hotplug callback to call setup_vmcs_config() to do compatibility check
on the "new-online" cpu to make sure it is compatible too.

setup_vmcs_config() is supposed to be done on the same cpu.  This is
true in the compatibility check code path as setup_vmcs_config() is
called either via IPI or in per-cpu CPU hotplug thread.  However, the
first call from hardware_setup() isn't as it is called when preemption
is enabled.

Change the existing setup_vmcs_config() to __setup_vmcs_config() and
call the latter directly in the compatibility check code path.  Change
setup_vmcs_config() to call __setup_vmcs_config() with preemption
disabled so __setup_vmcs_config() is always done on the same cpu.

Signed-off-by: Kai Huang <kai.huang@intel.com>
---
 arch/x86/kvm/vmx/vmx.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 33614ee2cd67..dfbc0e9095ec 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -2578,8 +2578,8 @@ static u64 adjust_vmx_controls64(u64 ctl_opt, u32 msr)
 	return  ctl_opt & allowed;
 }
 
-static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
-			     struct vmx_capability *vmx_cap)
+static int __setup_vmcs_config(struct vmcs_config *vmcs_conf,
+			       struct vmx_capability *vmx_cap)
 {
 	u32 vmx_msr_low, vmx_msr_high;
 	u32 _pin_based_exec_control = 0;
@@ -2745,6 +2745,18 @@ static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
 	return 0;
 }
 
+static int setup_vmcs_config(struct vmcs_config *vmcs_conf,
+			     struct vmx_capability *vmx_cap)
+{
+	int ret;
+
+	preempt_disable();
+	ret = __setup_vmcs_config(vmcs_conf, vmx_cap);
+	preempt_enable();
+
+	return ret;
+}
+
 static bool kvm_is_vmx_supported(void)
 {
 	int cpu = raw_smp_processor_id();
@@ -2772,7 +2784,7 @@ static int vmx_check_processor_compat(void)
 	if (!kvm_is_vmx_supported())
 		return -EIO;
 
-	if (setup_vmcs_config(&vmcs_conf, &vmx_cap) < 0) {
+	if (__setup_vmcs_config(&vmcs_conf, &vmx_cap) < 0) {
 		pr_err("Failed to setup VMCS config on CPU %d\n", cpu);
 		return -EIO;
 	}

base-commit: 93827a0a36396f2fd6368a54a020f420c8916e9b
-- 
2.39.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-09  2:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-01 10:54 [PATCH] KVM: VMX: Make setup_vmcs_config() preemption disabled Kai Huang
2023-03-02  5:36 ` Chao Gao
2023-03-02  8:39   ` Huang, Kai
2023-03-07 17:17     ` Sean Christopherson
2023-03-08  1:20       ` Huang, Kai
2023-03-08 21:03         ` Sean Christopherson
2023-03-09  2:11           ` Huang, Kai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox