lkml.org 
[lkml]   [2019]   [Nov]   [28]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH v2] KVM: vgic: Use wrapper function to lock/unlock all vcpus in kvm_vgic_create()
From
Date
On 28/11/2019 09:26, linmiaohe wrote:
> From: Miaohe Lin <linmiaohe@huawei.com>
>
> Use wrapper 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>
> ---
> -v2:
> Fix some spelling mistake in patch title and commit log.
> ---
> 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)
Extra context:

/*
* Any time a vcpu is run, vcpu_load is called which tries to grab the
* vcpu->mutex. By grabbing the vcpu->mutex of all VCPUs we ensure
> * that no other VCPUs are run while we create the vgic.
> */

That comment no longer makes sense here - there's a very similar one already
in lock_all_vcpus(). With that removed:

Reviewed-by: Steven Price <steven.price@arm.com>

> 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;
> }
>
>

\
 
 \ /
  Last update: 2019-11-28 12:05    [W:0.019 / U:0.528 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site