From: Kai Huang <kai.huang@intel.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, seanjc@google.com,
linux-kernel@vger.kernel.org, Kai Huang <kai.huang@intel.com>
Subject: [PATCH] KVM: VMX: Make setup_vmcs_config() preemption disabled
Date: Wed, 1 Mar 2023 23:54:38 +1300 [thread overview]
Message-ID: <20230301105438.599196-1-kai.huang@intel.com> (raw)
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
next reply other threads:[~2023-03-01 10:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-01 10:54 Kai Huang [this message]
2023-03-02 5:36 ` [PATCH] KVM: VMX: Make setup_vmcs_config() preemption disabled 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230301105438.599196-1-kai.huang@intel.com \
--to=kai.huang@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=seanjc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox