From patchwork Thu May 18 09:47:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9733089 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 CBB47601A1 for ; Thu, 18 May 2017 09:48:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B70C6285F7 for ; Thu, 18 May 2017 09:48:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABBD72860A; Thu, 18 May 2017 09:48:28 +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=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A8D8285F7 for ; Thu, 18 May 2017 09:48:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755316AbdERJs0 (ORCPT ); Thu, 18 May 2017 05:48:26 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:33449 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755279AbdERJsG (ORCPT ); Thu, 18 May 2017 05:48:06 -0400 Received: by mail-wm0-f46.google.com with SMTP id v15so10329893wmv.0 for ; Thu, 18 May 2017 02:48:06 -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=FgxUTJi43qB2Bf8h15KE5LlgRF5+a1+GDCLYXh25/Q4=; b=hRYS4CxTu0h7/US8Q33dpe7oJqA0uiNGCPcDV0iTLkR4U5j8318l7lk4tLvASCB4TS evUtvKRRV9Imtdn1MersfitUUUbR2bVyKcrSoSz2ytAdInP7FAtqRtAVPNezD3buNHxK PPXCqbW9Be8J3OnN7BaeYTcmoI7J/Y0ZfrHX8= 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:in-reply-to :references; bh=FgxUTJi43qB2Bf8h15KE5LlgRF5+a1+GDCLYXh25/Q4=; b=r1cZm/Tiglf5pol8eu1da9JBXzk113fieNc7C9MDByRM8sG5WeeQWCCA5Y8O+kABpt lKh9jb3RWD90oINtR7lE+rVnEe+pNZ9Abp7YXl6w9qeRLfbo1eDorS6Nl48AyvauOWLX SlWhg76SCEb2H433Y05JiOTWX9JG5aCWSHxVweWSUTqu/QGaWWOJedV0xj6NEOUMit+L TDf6S6NsvpPzw/dp1KHVj9SZEuGOh/H8Vqjr8FuYoxEP0fyDpoU743DIpmV83e7gtzvJ kicW5f80LasdSf0V9lJNIMDZ0UgNJuUekqthtrYoitvPhVV+7eSStR/dbmeanXJqOYSi pSyQ== X-Gm-Message-State: AODbwcDP/tJMqQiQM1L5S3cUfxacn+sE7qjd6LuONajzdIjmBGrhoItg MuSqHbR6wqL+Mxgg X-Received: by 10.80.131.67 with SMTP id 61mr2629899edh.21.1495100870161; Thu, 18 May 2017 02:47:50 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id w15sm2377437edw.27.2017.05.18.02.47.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 May 2017 02:47:49 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Cc: Marc Zyngier , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Christoffer Dall Subject: [PULL 13/13] KVM: arm/arm64: Hold slots_lock when unregistering kvm io bus devices Date: Thu, 18 May 2017 11:47:22 +0200 Message-Id: <20170518094722.9926-14-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170518094722.9926-1-cdall@linaro.org> References: <20170518094722.9926-1-cdall@linaro.org> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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 diligence. 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;