lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210526133727.42339-2-m.misono760@gmail.com>
Date:   Wed, 26 May 2021 22:37:27 +0900
From:   Masanori Misono <m.misono760@...il.com>
To:     David Woodhouse <dwmw@...zon.co.uk>,
        Paolo Bonzini <pbonzini@...hat.com>,
        Peter Zijlstra <peterz@...radead.org>,
        Rohit Jain <rohit.k.jain@...cle.com>
Cc:     Ingo Molnar <mingo@...hat.com>, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org,
        Masanori Misono <m.misono760@...il.com>
Subject: [PATCH RFC 1/1] KVM: x86: Don't set preempted when vCPU does HLT VMEXIT

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@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ