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-next>] [day] [month] [year] [list]
Message-ID: <546376F7.90502@gmail.com>
Date:	Wed, 12 Nov 2014 23:04:23 +0800
From:	Chen Gang <gang.chen.5i5j@...il.com>
To:	christoffer.dall@...aro.org, marc.zyngier@....com, gleb@...nel.org,
	Paolo Bonzini <pbonzini@...hat.com>
CC:	"linux-arm-kernel@...ts.infradead.org" 
	<linux-arm-kernel@...ts.infradead.org>,
	kvmarm@...ts.cs.columbia.edu, kvm@...r.kernel.org,
	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>
Subject: [PATCH] virt: kvm: arm: vgic: Return failure code '-EBUSY' when mutex_trylock()
 fails

When mutex_trylock() fails, kvm_vgic_create() will not create 'vgic', so
it need return failure code '-EBUSY' instead of '0' to let outside know
about it.

Also simplify the code within kvm_vgic_create():

 - kvm_for_each_vcpu() scanning once is enough for current case.

 - Remove redundant variable 'vcpu_lock_idx'.


Signed-off-by: Chen Gang <gang.chen.5i5j@...il.com>
---
 virt/kvm/arm/vgic.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c
index 3aaca49..5846725 100644
--- a/virt/kvm/arm/vgic.c
+++ b/virt/kvm/arm/vgic.c
@@ -1933,7 +1933,7 @@ out:
 
 int kvm_vgic_create(struct kvm *kvm)
 {
-	int i, vcpu_lock_idx = -1, ret = 0;
+	int i, ret = 0;
 	struct kvm_vcpu *vcpu;
 
 	mutex_lock(&kvm->lock);
@@ -1949,13 +1949,12 @@ int kvm_vgic_create(struct kvm *kvm)
 	 * that no other VCPUs are run while we create the vgic.
 	 */
 	kvm_for_each_vcpu(i, vcpu, kvm) {
-		if (!mutex_trylock(&vcpu->mutex))
+		if (!mutex_trylock(&vcpu->mutex)) {
+			ret = -EBUSY;
 			goto out_unlock;
-		vcpu_lock_idx = i;
-	}
-
-	kvm_for_each_vcpu(i, vcpu, kvm) {
+		}
 		if (vcpu->arch.has_run_once) {
+			mutex_unlock(&vcpu->mutex);
 			ret = -EBUSY;
 			goto out_unlock;
 		}
@@ -1968,8 +1967,8 @@ int kvm_vgic_create(struct kvm *kvm)
 	kvm->arch.vgic.vgic_cpu_base = VGIC_ADDR_UNDEF;
 
 out_unlock:
-	for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
-		vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
+	while (i-- > 0) {
+		vcpu = kvm_get_vcpu(kvm, i);
 		mutex_unlock(&vcpu->mutex);
 	}
 
-- 
1.9.3
--
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