public inbox for kvmarm@lists.cs.columbia.edu
 help / color / mirror / Atom feed
* [PATCH] KVM: vgic: Use warpper function to lock/unlock all vcpus in kvm_vgic_create()
@ 2019-11-28  3:09 linmiaohe
  2019-11-28  9:07 ` Auger Eric
  0 siblings, 1 reply; 3+ messages in thread
From: linmiaohe @ 2019-11-28  3:09 UTC (permalink / raw)
  To: maz, pbonzini, rkrcmar, james.morse, julien.thierry.kdev,
	suzuki.poulose, christoffer.dall, catalin.marinas, eric.auger,
	gregkh, will, andre.przywara, tglx
  Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel

From: Miaohe Lin <linmiaohe@huawei.com>

Use warpper function lock_all_vcpus()/unlock_all_vcpus()
in kvm_vgic_create() to remove duplicated code dealing
with locking and unlocking all vcpus in a vm.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 virt/kvm/arm/vgic/vgic-init.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c
index b3c5de48064c..53e3969dfb52 100644
--- a/virt/kvm/arm/vgic/vgic-init.c
+++ b/virt/kvm/arm/vgic/vgic-init.c
@@ -70,7 +70,7 @@ void kvm_vgic_early_init(struct kvm *kvm)
  */
 int kvm_vgic_create(struct kvm *kvm, u32 type)
 {
-	int i, vcpu_lock_idx = -1, ret;
+	int i, ret;
 	struct kvm_vcpu *vcpu;
 
 	if (irqchip_in_kernel(kvm))
@@ -92,11 +92,8 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
 	 * that no other VCPUs are run while we create the vgic.
 	 */
 	ret = -EBUSY;
-	kvm_for_each_vcpu(i, vcpu, kvm) {
-		if (!mutex_trylock(&vcpu->mutex))
-			goto out_unlock;
-		vcpu_lock_idx = i;
-	}
+	if (!lock_all_vcpus(kvm))
+		return ret;
 
 	kvm_for_each_vcpu(i, vcpu, kvm) {
 		if (vcpu->arch.has_run_once)
@@ -125,10 +122,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
 		INIT_LIST_HEAD(&kvm->arch.vgic.rd_regions);
 
 out_unlock:
-	for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
-		vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
-		mutex_unlock(&vcpu->mutex);
-	}
+	unlock_all_vcpus(kvm);
 	return ret;
 }
 
-- 
2.19.1

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: vgic: Use warpper function to lock/unlock all vcpus in kvm_vgic_create()
  2019-11-28  3:09 linmiaohe
@ 2019-11-28  9:07 ` Auger Eric
  0 siblings, 0 replies; 3+ messages in thread
From: Auger Eric @ 2019-11-28  9:07 UTC (permalink / raw)
  To: linmiaohe, maz, pbonzini, rkrcmar, james.morse,
	julien.thierry.kdev, suzuki.poulose, christoffer.dall,
	catalin.marinas, gregkh, will, andre.przywara, tglx
  Cc: kvm, kvmarm, linux-arm-kernel, linux-kernel

Hi,

On 11/28/19 4:09 AM, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
> 
> Use warpper function lock_all_vcpus()/unlock_all_vcpus()
s/warpper/wrapper and also in the title.
> in kvm_vgic_create() to remove duplicated code dealing
> with locking and unlocking all vcpus in a vm.
> 
> Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
> ---
>  virt/kvm/arm/vgic/vgic-init.c | 14 ++++----------
>  1 file changed, 4 insertions(+), 10 deletions(-)
> 
> diff --git a/virt/kvm/arm/vgic/vgic-init.c b/virt/kvm/arm/vgic/vgic-init.c
> index b3c5de48064c..53e3969dfb52 100644
> --- a/virt/kvm/arm/vgic/vgic-init.c
> +++ b/virt/kvm/arm/vgic/vgic-init.c
> @@ -70,7 +70,7 @@ void kvm_vgic_early_init(struct kvm *kvm)
>   */
>  int kvm_vgic_create(struct kvm *kvm, u32 type)
>  {
> -	int i, vcpu_lock_idx = -1, ret;
> +	int i, ret;
>  	struct kvm_vcpu *vcpu;
>  
>  	if (irqchip_in_kernel(kvm))
> @@ -92,11 +92,8 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
>  	 * that no other VCPUs are run while we create the vgic.
>  	 */
>  	ret = -EBUSY;
> -	kvm_for_each_vcpu(i, vcpu, kvm) {
> -		if (!mutex_trylock(&vcpu->mutex))
> -			goto out_unlock;
> -		vcpu_lock_idx = i;
> -	}
> +	if (!lock_all_vcpus(kvm))
> +		return ret;
>  
>  	kvm_for_each_vcpu(i, vcpu, kvm) {
>  		if (vcpu->arch.has_run_once)
> @@ -125,10 +122,7 @@ int kvm_vgic_create(struct kvm *kvm, u32 type)
>  		INIT_LIST_HEAD(&kvm->arch.vgic.rd_regions);
>  
>  out_unlock:
> -	for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) {
> -		vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx);
> -		mutex_unlock(&vcpu->mutex);
> -	}
> +	unlock_all_vcpus(kvm);
>  	return ret;
>  }
>  
> 
Besides, looks good to me
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Thanks

Eric

_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: vgic: Use warpper function to lock/unlock all vcpus in kvm_vgic_create()
@ 2019-11-28  9:20 linmiaohe
  0 siblings, 0 replies; 3+ messages in thread
From: linmiaohe @ 2019-11-28  9:20 UTC (permalink / raw)
  To: Auger Eric, maz@kernel.org, pbonzini@redhat.com,
	rkrcmar@redhat.com, james.morse@arm.com,
	julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com,
	christoffer.dall@arm.com, catalin.marinas@arm.com,
	gregkh@linuxfoundation.org, will@kernel.org,
	andre.przywara@arm.com, tglx@linutronix.de
  Cc: kvm@vger.kernel.org, kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org

Eric wrote:
>> From: Miaohe Lin <linmiaohe@huawei.com>
>> 
>> Use warpper function lock_all_vcpus()/unlock_all_vcpus()
> s/warpper/wrapper and also in the title.

Hi, Eric:
Many thanks for your review. I would fix this and send a patch v2.
Thanks again.
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-28  9:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-11-28  9:20 [PATCH] KVM: vgic: Use warpper function to lock/unlock all vcpus in kvm_vgic_create() linmiaohe
  -- strict thread matches above, loose matches on Subject: below --
2019-11-28  3:09 linmiaohe
2019-11-28  9:07 ` Auger Eric

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox