From patchwork Tue May 9 08:56:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9717357 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 B2DB460365 for ; Tue, 9 May 2017 08:59:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A43FA28389 for ; Tue, 9 May 2017 08:59:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 97B24283CA; Tue, 9 May 2017 08:59:06 +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=unavailable 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 298A228389 for ; Tue, 9 May 2017 08:59:06 +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:References: In-Reply-To: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:List-Owner; bh=Ok8U0NsblhFqiVlcMWeDwmBiH0uhjb41jW2cBBer2FI=; b=ZR56NzD+GBXi7oBVUrUO6C9QjJ KnTaaEs+M36vYqz5r8DYzpmbaPdHuGY7Jl0YzVgt2RA+01jAbwuu5XTBO0mwpFcpq5uNm3CDL3u+n vbIfEvyMuquqTo/VEyAfe6KJikbysQ3Zp1CVXguoKAqqP5tthekpUFXWriqFLYh4WboQBXoOeykOn eNrFQJYaBYgsf2K+YCtYNAZz6HN0RIwZ6ZzSGTUKt563SqoF/EpsuVKFSwrm7ydzHnSfJt1nwUQ8G r0ezjGyRdh8vTt1L6v6rDN3ptWqYK0A1Yvq9X1h0zkhbGz5McP3phiNmHW+1UTTpnNIX130ULv21C 2B4UMdOw==; 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 1d80z3-00050V-EG; Tue, 09 May 2017 08:59:05 +0000 Received: from mail-wm0-x22c.google.com ([2a00:1450:400c:c09::22c]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d80wy-0002KD-1c for linux-arm-kernel@lists.infradead.org; Tue, 09 May 2017 08:57:00 +0000 Received: by mail-wm0-x22c.google.com with SMTP id n198so23491361wmg.0 for ; Tue, 09 May 2017 01:56:35 -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=Fb6HZLkEQuDZ1uBHdq/YNN1DF4XPiUem5MS3Wy8rLRo=; b=ULIuOwjGTcKKctoAVy9RNM/w0yM5TKBoh/xaaSIos2/PNWX6L1zGPmsSTV882FMJMr kMFlWOpaImtmdvDzHweC4hy3ZK7iyMqIweaR9XehsK1j8UrAsUUep9WAPe3vlMvBqR9B sgQxtjVll2nmFWKXdHYPd9jCq/R4sTMtBwYT8= 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=Fb6HZLkEQuDZ1uBHdq/YNN1DF4XPiUem5MS3Wy8rLRo=; b=KWAXIyJAZQ66lTxSIVGGYjF+mxGts6bC+jMM1wT2QGB1+qJYgD0KodegLAcVqyDhc5 OVHUNYaTuoiyGH7+7VsmZh3BSpqUUORTDvaAgltfPoRVnI/uc6ZXi2YaoPiKDz6AKr00 ioptJ2+QSc9WSNIwOSzsMGxrfXtLJNffgAuLg4XM8av9buft8Y7eCemuDizmAQp6Oozm PJM6vOjD4t39gkQx/4a3R3JhB8TEed7p0GR+mQDmyO8JUAcdX3yumqwEmoUQDxeLLbIH CQ53rrBIf33UoNKEbtfYDPYE5nHjmTCloJISLctRl7WY8CGQaTzjRoQXdd6hiRSjbbcd rRGA== X-Gm-Message-State: AN3rC/46lKAQcJGwQv/SZL6hoMqOODExCKRUKZhPIDjlFhS+hsKZ+rgp PknBy03nZF8FUzNiyZMXig== X-Received: by 10.80.142.204 with SMTP id x12mr19065907edx.3.1494320194269; Tue, 09 May 2017 01:56:34 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id f40sm8376265edb.7.2017.05.09.01.56.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 May 2017 01:56:33 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 11/11] KVM: arm/arm64: vgic-its: Cleanup after failed ITT restore Date: Tue, 9 May 2017 10:56:18 +0200 Message-Id: <20170509085618.28311-12-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170509085618.28311-1-cdall@linaro.org> References: <20170509085618.28311-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170509_015656_684783_D4D9C382 X-CRM114-Status: GOOD ( 13.66 ) 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 , kvm@vger.kernel.org, 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 When failing to restore the ITT for a DTE, we should remove the failed device entry from the list and free the object. We slightly refactor vgic_its_destroy to be able to reuse the now separate vgic_its_free_dte() function. Signed-off-by: Christoffer Dall Reviewed-by: Eric Auger --- virt/kvm/arm/vgic/vgic-its.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 9aeaff0..2dff288 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1613,13 +1613,20 @@ static int vgic_its_create(struct kvm_device *dev, u32 type) return vgic_its_set_abi(its, NR_ITS_ABIS - 1); } +static void vgic_its_free_device(struct kvm *kvm, struct its_device *dev) +{ + struct its_ite *ite, *tmp; + + list_for_each_entry_safe(ite, tmp, &dev->itt_head, ite_list) + its_free_ite(kvm, ite); + list_del(&dev->dev_list); + kfree(dev); +} + static void vgic_its_destroy(struct kvm_device *kvm_dev) { struct kvm *kvm = kvm_dev->kvm; struct vgic_its *its = kvm_dev->private; - struct its_device *dev; - struct its_ite *ite; - struct list_head *dev_cur, *dev_temp; struct list_head *cur, *temp; /* @@ -1630,19 +1637,19 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev) return; mutex_lock(&its->its_lock); - list_for_each_safe(dev_cur, dev_temp, &its->device_list) { - dev = container_of(dev_cur, struct its_device, dev_list); - list_for_each_safe(cur, temp, &dev->itt_head) { - ite = (container_of(cur, struct its_ite, ite_list)); - its_free_ite(kvm, ite); - } - list_del(dev_cur); - kfree(dev); + list_for_each_safe(cur, temp, &its->device_list) { + struct its_device *dev; + + dev = list_entry(cur, struct its_device, dev_list); + vgic_its_free_device(kvm, dev); } list_for_each_safe(cur, temp, &its->collection_list) { + struct its_collection *coll; + + coll = list_entry(cur, struct its_collection, coll_list); list_del(cur); - kfree(container_of(cur, struct its_collection, coll_list)); + kfree(coll); } mutex_unlock(&its->its_lock); @@ -2012,8 +2019,10 @@ static int vgic_its_restore_dte(struct vgic_its *its, u32 id, return PTR_ERR(dev); ret = vgic_its_restore_itt(its, dev); - if (ret) + if (ret) { + vgic_its_free_device(its->dev->kvm, dev); return ret; + } return offset; }