[PATCH] KVM: X86: Disable KVM_FEATURE_STEAL_TIME when both delayacct_on added to cmdline and CONFIG_SCHEDSTATS is set
From: Chen Xiao
Date: Tue Jul 31 2018 - 05:08:46 EST
From: Chen Xiao <abigwc@xxxxxxx>
When sched_info_on returns 1ïKVM_FEATURE_STEAL_TIME will be set,
steal% can be seen in the virtual machine.The returned value of
sched_info_on depends on delayacct_on. If nodelayacct is added to
kernel boot cmdline,the KVM_FEATURE_STEAL_TIME will be turned off
by setting delayacct_on to 0.When CONFIG_SCHEDSTATS is set, sched_info_on
always returns 1, and adding nodelayacct to the cmdline cannot turn
off the KVM_FEATURE_STEAL_TIME Sometimes the users do not want the
running state of host to be perceived in the virtual machine, and
intend to turn off KVM_FEATURE_STEAL_TIME. The requirement is not
available, however, when CONFIG_SCHEDSTATS has been set.Modify the
judgment criteria for being set up from KVM_FEATURE_STEAL_TIME, and
it is only be judged by the value of delayacct_on.
Signed-off-by: Chen Xiao <abigwc@xxxxxxxxx>
---
arch/x86/kvm/cpuid.c | 2 +-
arch/x86/kvm/x86.c | 8 ++++----
arch/x86/kvm/x86.h | 10 ++++++++++
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 7e042e3..d38da09 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -623,7 +623,7 @@ static inline int __do_cpuid_ent(struct kvm_cpuid_entry2 *entry, u32 function,
(1 << KVM_FEATURE_PV_TLB_FLUSH) |
(1 << KVM_FEATURE_ASYNC_PF_VMEXIT);
- if (sched_info_on())
+ if (kvm_feature_steal_on())
entry->eax |= (1 << KVM_FEATURE_STEAL_TIME);
entry->ebx = 0;
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 2b812b3..8371d5c 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2424,8 +2424,7 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
return 1;
break;
case MSR_KVM_STEAL_TIME:
-
- if (unlikely(!sched_info_on()))
+ if (unlikely(!kvm_feature_steal_on()))
return 1;
if (data & KVM_STEAL_RESERVED_MASK)
@@ -3101,7 +3100,8 @@ void kvm_arch_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
vcpu->cpu = cpu;
}
- kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu);
+ if (kvm_feature_steal_on())
+ kvm_make_request(KVM_REQ_STEAL_UPDATE, vcpu);
}
static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
@@ -7291,7 +7291,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
r = 1;
goto out;
}
- if (kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))
+ if (kvm_feature_steal_on()
+ && kvm_check_request(KVM_REQ_STEAL_UPDATE, vcpu))
record_steal_time(vcpu);
if (kvm_check_request(KVM_REQ_SMI, vcpu))
process_smi(vcpu);
diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 257f276..9e7c078 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -338,4 +338,14 @@ static inline void kvm_after_interrupt(struct kvm_vcpu *vcpu)
__this_cpu_write(current_vcpu, NULL);
}
+static inline int kvm_feature_steal_on(void)
+{
+#ifdef CONFIG_TASK_DELAY_ACCT
+ extern int delayacct_on;
+ return delayacct_on;
+#else
+ return 0;
+#endif
+}
+
#endif
--
1.8.3.1