From patchwork Wed Aug 10 10:39:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 73622 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp332809qga; Wed, 10 Aug 2016 03:39:36 -0700 (PDT) X-Received: by 10.66.32.131 with SMTP id j3mr5954333pai.58.1470825576568; Wed, 10 Aug 2016 03:39:36 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id yp6si36335994pac.253.2016.08.10.03.39.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Aug 2016 03:39:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bXQtW-0004jy-0s; Wed, 10 Aug 2016 10:37:54 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bXQtQ-0004jD-Hj for linux-arm-kernel@lists.infradead.org; Wed, 10 Aug 2016 10:37:50 +0000 Received: by mail-wm0-x22b.google.com with SMTP id i5so94280639wmg.0 for ; Wed, 10 Aug 2016 03:37:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jcj4nMjSWbMEjHpgf9PjAkpM+D5doDh2hPBWRC32REA=; b=h9o27uIbX0uLRcRqLlMhlsI9GoE5zd2aONGeTOGsv9IQSDhdCHcSNMMHnEo6OmBsft KGuPhkN5zw/AjCRXiGLXzMjeSmv2D8R8q0573k/G5i+WnGgKqgpFeTIRVDs8+4t2AV+8 wqcxXIJLNcQWQ/ZNoxt20EHwtrZjt/Mk9pc3A= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jcj4nMjSWbMEjHpgf9PjAkpM+D5doDh2hPBWRC32REA=; b=mWBE+6Iux+mF40ZXBZDcNHAu3oMOR/1Rtvo2KTq7xQ12t02EZ5QQfvryctBOzcNrqF NtkElY/VHcA+Uu23BYjXDwxidA8jhq7Y1spPS+JPyNvbd4ucgTPZ+6JvxaiPE1kyfhJj rIPAe1X9nr6dgBEhSFjC8ws2JdxEjfYPF+rflUV7KVpaWyg4CRCER7iNZ8xi206hRas8 1KwuWoZ11OBCW1M821vRBgxAdjvw97rnkwuhkecZijsc9Jmif9m36hTi0M3eXtohwu93 J2F2YRnrtQ/AlMxVG4XxfSB8ZZ9y9IFIflNhrjV0Styv1du1kQtXNG2XOY3aEnIeqsmC QZow== X-Gm-Message-State: AEkoouvhVmCdfYLbt0Su8VDhg4Rd4L+tz4ONHEw+dYrz9Nm11am7vcVfWS803Wj4hWu1RReq X-Received: by 10.194.15.130 with SMTP id x2mr3271905wjc.122.1470825446099; Wed, 10 Aug 2016 03:37:26 -0700 (PDT) Received: from localhost.localdomain ([94.18.191.146]) by smtp.gmail.com with ESMTPSA id a2sm42347359wjg.46.2016.08.10.03.37.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Aug 2016 03:37:25 -0700 (PDT) From: Christoffer Dall To: Andre Przywara Subject: [PATCH] KVM: arm64: vgic-its: Grab kvm->lock when reading kvm->devices Date: Wed, 10 Aug 2016 12:39:14 +0200 Message-Id: <20160810103914.30322-1-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20160808154543.23463-1-andre.przywara@arm.com> References: <20160808154543.23463-1-andre.przywara@arm.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160810_033748_981250_4B178D2C X-CRM114-Status: GOOD ( 12.96 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:22b listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , kvm@vger.kernel.org, Eric Auger , Marc Zyngier , Christoffer Dall , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org Since we are about to synchronize all accesses to kvm->devices using the kvm->lock mutex, we should hold this mutex while iterating over the list of devices in the ITS code. Also move the vgic_register_its_iodev function to where it's called and rename it to register_its_iodev to avoid having two almost identially named functions. Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-its.c | 64 +++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 30 deletions(-) -- 2.9.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 1cf9f59..4e76877 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1319,32 +1319,6 @@ void vgic_enable_lpis(struct kvm_vcpu *vcpu) its_sync_lpi_pending_table(vcpu); } -static int vgic_register_its_iodev(struct kvm *kvm, struct vgic_its *its) -{ - struct vgic_io_device *iodev = &its->iodev; - int ret; - - if (!its->initialized) - return -EBUSY; - - if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base)) - return -ENXIO; - - iodev->regions = its_registers; - iodev->nr_regions = ARRAY_SIZE(its_registers); - kvm_iodevice_init(&iodev->dev, &kvm_io_gic_ops); - - iodev->base_addr = its->vgic_its_base; - iodev->iodev_type = IODEV_ITS; - iodev->its = its; - mutex_lock(&kvm->slots_lock); - ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, iodev->base_addr, - KVM_VGIC_V3_ITS_SIZE, &iodev->dev); - mutex_unlock(&kvm->slots_lock); - - return ret; -} - #define INITIAL_BASER_VALUE \ (GIC_BASER_CACHEABILITY(GITS_BASER, INNER, RaWb) | \ GIC_BASER_CACHEABILITY(GITS_BASER, OUTER, SameAsInner) | \ @@ -1526,6 +1500,32 @@ int kvm_vgic_register_its_device(void) KVM_DEV_TYPE_ARM_VGIC_ITS); } +static int register_its_iodev(struct kvm *kvm, struct vgic_its *its) +{ + struct vgic_io_device *iodev = &its->iodev; + int ret; + + if (!its->initialized) + return -EBUSY; + + if (IS_VGIC_ADDR_UNDEF(its->vgic_its_base)) + return -ENXIO; + + iodev->regions = its_registers; + iodev->nr_regions = ARRAY_SIZE(its_registers); + kvm_iodevice_init(&iodev->dev, &kvm_io_gic_ops); + + iodev->base_addr = its->vgic_its_base; + iodev->iodev_type = IODEV_ITS; + iodev->its = its; + mutex_lock(&kvm->slots_lock); + ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, iodev->base_addr, + KVM_VGIC_V3_ITS_SIZE, &iodev->dev); + mutex_unlock(&kvm->slots_lock); + + return ret; +} + /* * Registers all ITSes with the kvm_io_bus framework. * To follow the existing VGIC initialization sequence, this has to be @@ -1536,19 +1536,23 @@ int vgic_register_its_iodevs(struct kvm *kvm) struct kvm_device *dev; int ret = 0; + mutex_lock(&kvm->lock); list_for_each_entry(dev, &kvm->devices, vm_node) { if (dev->ops != &kvm_arm_vgic_its_ops) continue; - ret = vgic_register_its_iodev(kvm, dev->private); + ret = register_its_iodev(kvm, dev->private); if (ret) - return ret; + goto out; + /* * We don't need to care about tearing down previously - * registered ITSes, as the kvm_io_bus framework removes - * them for us if the VM gets destroyed. + * registered ITSes on error, as the kvm_io_bus framework + * removes them for us if the VM gets destroyed. */ } +out: + mutex_unlock(&kvm->lock); return ret; }