lkml.org 
[lkml]   [2021]   [May]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH RFC 1/1] KVM: x86: Don't set preempted when vCPU does HLT VMEXIT
Date
Change kvm_arch_cpu_put() so that it does not set st->preempted as 1
when a vCPU does HLT VMEXIT. As a result, is_vcpu_preempted(vCPU) becomes
0, and the vCPU becomes a candidate for CFS load balancing.

Signed-off-by: Masanori Misono <m.misono760@gmail.com>
---
arch/x86/kvm/x86.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index bbc4e04e67ad..b3f50b9f2e96 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4170,19 +4170,26 @@ static void kvm_steal_time_set_preempted(struct kvm_vcpu *vcpu)
void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
{
int idx;
+ bool hlt;

if (vcpu->preempted && !vcpu->arch.guest_state_protected)
vcpu->arch.preempted_in_kernel = !static_call(kvm_x86_get_cpl)(vcpu);

+ hlt = lapic_in_kernel(vcpu) ?
+ vcpu->arch.mp_state == KVM_MP_STATE_HALTED :
+ vcpu->run->exit_reason == KVM_EXIT_HLT;
+
/*
* Take the srcu lock as memslots will be accessed to check the gfn
* cache generation against the memslots generation.
*/
idx = srcu_read_lock(&vcpu->kvm->srcu);
- if (kvm_xen_msr_enabled(vcpu->kvm))
- kvm_xen_runstate_set_preempted(vcpu);
- else
- kvm_steal_time_set_preempted(vcpu);
+ if (!hlt) {
+ if (kvm_xen_msr_enabled(vcpu->kvm))
+ kvm_xen_runstate_set_preempted(vcpu);
+ else
+ kvm_steal_time_set_preempted(vcpu);
+ }
srcu_read_unlock(&vcpu->kvm->srcu, idx);

static_call(kvm_x86_vcpu_put)(vcpu);
--
2.31.1
\
 
 \ /
  Last update: 2021-05-26 15:39    [W:0.075 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site