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]
Date:	Wed,  5 Aug 2015 15:21:16 +0200
From:	Radim Krčmář <rkrcmar@...hat.com>
To:	linux-kernel@...r.kernel.org
Cc:	kvm@...r.kernel.org, Paolo Bonzini <pbonzini@...hat.com>
Subject: [PATCH 4/5] KVM: optimize common cases in KVM_USER_EXIT

VCPU with vcpu->vcpu_id has highest probability of being stored in
kvm->vcpus[vcpu->vcpu_id].  Other common case, sparse sequential
vcpu_id, is more likely to find a match downwards from vcpu->vcpu_id.

Random distribution does not matter so we first search slots
[vcpu->vcpu_id..0] and then slots (vcpu->vcpu_id..kvm->online_vcpus).

If we value cycles over memory, a direct map between vcpu_id and
vcpu->vcpu_id would be better.

(Like kvm_for_each_vcpu, the code avoid the kvm->lock by presuming that
 kvm->online_vcpus doesn't shrink and that the vcpu pointer is set up
 before incrementing.  kvm_free_vcpus() breaks that presumption, but vm
 is destroyed only after the fd has been released.)

Signed-off-by: Radim Krčmář <rkrcmar@...hat.com>
---
 virt/kvm/kvm_main.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 024428b64812..7d532591d5af 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2650,7 +2650,7 @@ int kvm_vm_ioctl_user_exit(struct kvm *kvm, struct kvm_user_exit *info)
 	 * KVM_CREATE_VCPU, where we cast from unsigned long.
 	 */
 	int vcpu_id = info->vcpu_id;
-	int idx;
+	int idx, first;
 	struct kvm_vcpu *vcpu;
 	const struct kvm_user_exit valid = {.vcpu_id = info->vcpu_id};
 
@@ -2659,7 +2659,11 @@ int kvm_vm_ioctl_user_exit(struct kvm *kvm, struct kvm_user_exit *info)
 	if (memcmp(info, &valid, sizeof(valid)))
 		return -EINVAL;
 
-	kvm_for_each_vcpu(idx, vcpu, kvm)
+	for (idx = first = min(vcpu_id, atomic_read(&kvm->online_vcpus) - 1);
+	     idx >= 0 ? (vcpu = kvm_get_vcpu(kvm, idx)) != NULL
+	              : ++first < atomic_read(&kvm->online_vcpus) &&
+	                     (vcpu = kvm_get_vcpu(kvm, first)) != NULL;
+	     idx--)
 		if (vcpu->vcpu_id == vcpu_id) {
 			kvm_make_request(KVM_REQ_EXIT, vcpu);
 			kvm_vcpu_kick(vcpu);
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ