[RFC: timer passthrough 6/9] KVM: vmx: check enable_timer_passth strictly

From: Zhimin Feng
Date: Fri Feb 05 2021 - 19:49:04 EST


preemption timer is default disabled
timer passthrough is default enabled

Signed-off-by: Zhimin Feng <fengzhimin@xxxxxxxxxxxxx>
---
arch/x86/kvm/vmx/vmx.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 44b2fd59587e..a12da3cef86d 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -126,12 +126,12 @@ module_param(dump_invalid_vmcs, bool, 0644);

/* Guest_tsc -> host_tsc conversion requires 64-bit division. */
static int __read_mostly cpu_preemption_timer_multi;
-static bool __read_mostly enable_preemption_timer = 1;
+static bool __read_mostly enable_preemption_timer;
#ifdef CONFIG_X86_64
module_param_named(preemption_timer, enable_preemption_timer, bool, S_IRUGO);
#endif

-static bool __read_mostly enable_timer_passth;
+static bool __read_mostly enable_timer_passth = 1;
#ifdef CONFIG_X86_64
module_param_named(timer_passth, enable_timer_passth, bool, 0444);
#endif
@@ -8108,12 +8108,17 @@ static __init int hardware_setup(void)
enable_preemption_timer = false;
}

- if (!enable_preemption_timer) {
+ if (!enable_preemption_timer || enable_timer_passth) {
vmx_x86_ops.set_hv_timer = NULL;
vmx_x86_ops.cancel_hv_timer = NULL;
vmx_x86_ops.request_immediate_exit = __kvm_request_immediate_exit;
}

+ if (enable_preemption_timer && enable_timer_passth) {
+ pr_err("cannot enable timer passthrough and preemption timer same timer\n");
+ return -EINVAL;
+ }
+
kvm_set_posted_intr_wakeup_handler(pi_wakeup_handler);

kvm_mce_cap_supported |= MCG_LMCE_P;
--
2.11.0