From patchwork Wed May 17 19:18:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9731805 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2D6A960138 for ; Wed, 17 May 2017 19:18:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04109287E0 for ; Wed, 17 May 2017 19:18:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECE2E287E5; Wed, 17 May 2017 19:18:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 74984287E0 for ; Wed, 17 May 2017 19:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=3qXw+8wxK5HJ38kBKn0Nw0EDEGUCL8VzzF16vlsUiXk=; b=VUy HVHM/iw5yubJ84T8RTkmNOLgarexY8i9qJ6LP/FGi6cDUeBcV2Rz+SaZW/fFD2a8Wj6omOjK4yprG EW6DQ9FQ1vChiga8V5h56eVaZpbjR/5eoS2hN33iCehn8gm0qz9VRrBFmSENrTlBEWXTQ0GQRgD9h dUWb1f+Q89oCjjOjF3AnlEpHX+b3yRlliNreiLIxZJJZdBWcohq+zDpbmxst3EC9Jjvrsukg0s5aw zZFqosjnVoB9Mv76FwJGPUk8wEV4UN5j/aAZwx7SbQl1Sal4petrrkzhGmhFQ50SWmuYqWm6yeA3z WQhLipiVkb1prPHawTio9Q2+mKQVj0A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dB4T5-0008D2-Tu; Wed, 17 May 2017 19:18:43 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dB4T2-00085i-6y for linux-arm-kernel@lists.infradead.org; Wed, 17 May 2017 19:18:42 +0000 Received: by mail-wm0-x236.google.com with SMTP id d127so27394734wmf.0 for ; Wed, 17 May 2017 12:18:19 -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; bh=85RjnCo+uxdWqPZXrHyczXugZ/aTkNM6kXtL7R8tC4s=; b=kZry6799YNl+lKHLUuUDhOL3O/7rLc2gd06W6L2uvw07+aEP62SsbpeougjtuGHAR4 uzjb01tTO6PY3srDcp5RjcXo2wcRKeujMv/rk4P4QVhjq/dNVEPCYmwECsAEKIy80cR0 sJkhLDr4vU3DiKKTA8ekiCxsWLUkkUWr2zqEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=85RjnCo+uxdWqPZXrHyczXugZ/aTkNM6kXtL7R8tC4s=; b=bmwQAfoDCzAeVE4OX2vCPpELvB1+uw9iZfN81L1b3NSftIXdS7N08lF1UvnAIZrxsM S57iFT0UjzgmA3N7GqgHpt/KTViIvs7rtjyS+cYieoeG92JXlQyZvUK8XGxh51cPcCWj zOVv25QnJau6bnz4kiXOwF2VysGcazJHC5mIS6HqYJdaAo162bt9FiflWNIYHp+4IUHi qqk0sPj7wxg3w2R7T/zAG1z/YH1+LE6EOPbsklF+b+8YEZ8ID9WLQaW3oPAYyJFCcimG zuIYeJGt1rUOg4KB7xUS7bT1Gsbz2FYeBJcKSbJTvSVnFGJm7dKBhSXDqxq3L/Tj23c5 R45w== X-Gm-Message-State: AODbwcCPQgRsbcpKDI6yCCDsC+rCSHUUascurTTMRlBMZHoQdeXzICOP A/Inv4hcQh6kaUvH X-Received: by 10.80.178.131 with SMTP id p3mr252216edd.96.1495048698132; Wed, 17 May 2017 12:18:18 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id b30sm1636446edd.6.2017.05.17.12.18.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 May 2017 12:18:17 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH] KVM: arm/arm64: Hold slots_lock when unregisering kvm io bus devices Date: Wed, 17 May 2017 21:18:06 +0200 Message-Id: <20170517191806.3978-1-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170517_121840_515792_33D6F253 X-CRM114-Status: GOOD ( 11.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , Eric Auger , Christoffer Dall MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We were not holding the kvm->slots_lock as required when calling kvm_io_bus_unregister_dev() as required. This only affects the error path, but still, let's do our due dilligence. Reported by: Eric Auger Signed-off-by: Christoffer Dall Reviewed-by: Eric Auger --- virt/kvm/arm/vgic/vgic-mmio-v3.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-mmio-v3.c b/virt/kvm/arm/vgic/vgic-mmio-v3.c index 9b0f681..201d5e2 100644 --- a/virt/kvm/arm/vgic/vgic-mmio-v3.c +++ b/virt/kvm/arm/vgic/vgic-mmio-v3.c @@ -614,15 +614,16 @@ int vgic_register_redist_iodev(struct kvm_vcpu *vcpu) mutex_lock(&kvm->slots_lock); ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, sgi_base, SZ_64K, &sgi_dev->dev); - mutex_unlock(&kvm->slots_lock); if (ret) { kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &rd_dev->dev); - return ret; + goto out; } vgic->vgic_redist_free_offset += 2 * SZ_64K; - return 0; +out: + mutex_unlock(&kvm->slots_lock); + return ret; } static void vgic_unregister_redist_iodev(struct kvm_vcpu *vcpu) @@ -647,10 +648,12 @@ static int vgic_register_all_redist_iodevs(struct kvm *kvm) if (ret) { /* The current c failed, so we start with the previous one. */ + mutex_lock(&kvm->slots_lock); for (c--; c >= 0; c--) { vcpu = kvm_get_vcpu(kvm, c); vgic_unregister_redist_iodev(vcpu); } + mutex_unlock(&kvm->slots_lock); } return ret;