Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp6289726ybc; Wed, 27 Nov 2019 19:10:55 -0800 (PST) X-Google-Smtp-Source: APXvYqyHDuYZp/uDNGq7FUZmYmLmvQK/2f2ldw99/jAkezo6GY4ml3btpDvodCiASDOpN8hka0wl X-Received: by 2002:a17:906:af62:: with SMTP id os2mr53668889ejb.105.1574910655829; Wed, 27 Nov 2019 19:10:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574910655; cv=none; d=google.com; s=arc-20160816; b=1Gw4IVDWoy5R7VKlSAd3w02app6mm9BfabxaxJx7zjZg8r+lRSGsmHOynVJ1nJYw1o wusDQm8oLYoLbZOEfbXesO6dWH7VoCnPfsgAy6bXMeLgVULLUP58m/4a0NQEpqGIkqoc EI2iJslKUZwDL6uUL8+Z7UWHca5nkfFqT5eq9DWWZ2ahewa54Nah0RuH4lYqBS7oUa09 3z4BJuqakSAu68vsOyNtc3TbcCXVMtZdbbSqeAz7PHoQJjz9iLbR+z3O4Kskf9qRf7ar pq52vPFomwnubDbE8PTLou1116VBuFi9SBAqAYFEI3eiq3eIyzu7L830Uxt8Jko9XEOO /jvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=20wYvBzRuhoqFASj2POErA0YIvelyDDIPuuN2v9DH24=; b=uNbx8XH2ls0VMNaTANXXj9qiVJIyW4m86+4jU+XTFoj+gqXOkV7JHEwduhnecf9WBM VHt6j/soudP4vGM2W8VrMG2LY6FCkVx29WQTG9oKg+cH0kjIOtyXzG1gDWIWWoh0Enyz D/PVEvhez6MWYxgWMAWNqagjJPYQarITbiIrZg8vuOoR2BtymM4Y3up6HaSDLFJdSFbe W6eu4kBUOXPSN6Vl0QMu/wRAINKhi/Kxp50IFyRqXsG0S8Qp47pZKqyc+zh2x1DWzaCY 9ImsVsV3ZiA5wymRN++LxiAtjqaI0AeweeR4ud6oBy0xZDnhJl773W3YUklJ3QQBMK3v iF+Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j20si10357496ejm.348.2019.11.27.19.10.31; Wed, 27 Nov 2019 19:10:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727480AbfK1DJV (ORCPT + 99 others); Wed, 27 Nov 2019 22:09:21 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:52262 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727088AbfK1DJV (ORCPT ); Wed, 27 Nov 2019 22:09:21 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id CCF043E07834170A7368; Thu, 28 Nov 2019 11:09:18 +0800 (CST) Received: from huawei.com (10.175.105.18) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.439.0; Thu, 28 Nov 2019 11:09:08 +0800 From: linmiaohe To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH] KVM: vgic: Use warpper function to lock/unlock all vcpus in kvm_vgic_create() Date: Thu, 28 Nov 2019 11:09:11 +0800 Message-ID: <1574910551-14351-1-git-send-email-linmiaohe@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.105.18] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Miaohe Lin 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 --- 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