From patchwork Mon May 8 11:54:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9716131 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 A907160234 for ; Mon, 8 May 2017 11:55:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8FB9D223C7 for ; Mon, 8 May 2017 11:55:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8323B268AE; Mon, 8 May 2017 11:55:34 +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 2F75D223C7 for ; Mon, 8 May 2017 11:55:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754598AbdEHLz1 (ORCPT ); Mon, 8 May 2017 07:55:27 -0400 Received: from mail-wm0-f41.google.com ([74.125.82.41]:36324 "EHLO mail-wm0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754530AbdEHLzO (ORCPT ); Mon, 8 May 2017 07:55:14 -0400 Received: by mail-wm0-f41.google.com with SMTP id u65so81768268wmu.1 for ; Mon, 08 May 2017 04:55:08 -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=CX8ykkjX8HjecRRvv6/XbiOcxMNjPv2PrV7AqrWu548=; b=W1Owd0IwcNvhMX60kmdR18loFB+FWNo5Ni1fAgiE10SGDZAzdd3KgFfpJM4u1M5I7p 8QSFIYHPSnOg1knwwm6JkwP9H/YD+oOwz9/VnXPMNxz7jHZpqhQmO/gkcOzQwzh90vpK niijv8BiRCxX19zSFKrEmGL87td/3ey4L5vjQ= 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=CX8ykkjX8HjecRRvv6/XbiOcxMNjPv2PrV7AqrWu548=; b=Qyo+kECZj4efecHm/KCz/wMoYWCXJZX/yBAMEnMehfv8+8JLklU1WiVXc0sJZSxy88 bOty4asjYRCioEfS2Zszxqsj6od0KT3ClGqGjbCWF+37gljaPLCIo1HcBuQaZA8qV5Oz RNHfUqGBOUjzk0TYGjhdwPWxAWvuxwntgjqGsVO7Fa3iz+G8yMh4Qv7MOzdnO5eLPYeV MmSQiRPbGNoxL1RuFEXMSsdcS4vTGBwvn97dkkJRHe49gfXq1PPZEzC05KwTR6XSdfEF nn7F1Gsv7lE7J2WS5ZfkoHE1pcocwR+87eCv6UcrrK/ix/JTasbmUt6jCBaaic7m/O5U OvUg== X-Gm-Message-State: AN3rC/4Q9Y7tBp9nlny0Q7ORIWzd+eUaLIZAdo4wJMjjhcg6RKzhLunB xG+TO2PFMa0Po+5KCSqdMw== X-Received: by 10.80.140.164 with SMTP id q33mr37736401edq.77.1494244507757; Mon, 08 May 2017 04:55:07 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id k43sm3483411ede.1.2017.05.08.04.55.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 May 2017 04:55:07 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, Marc Zyngier , Eric Auger , Christoffer Dall Subject: [PATCH 8/8] KVM: arm/arm64: vgic-its: Cleanup after failed ITT restore Date: Mon, 8 May 2017 13:54:54 +0200 Message-Id: <20170508115454.5075-9-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170508115454.5075-1-cdall@linaro.org> References: <20170508115454.5075-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 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 375c503..00f2990 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1612,13 +1612,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_dte(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; /* @@ -1629,19 +1636,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_dte(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); @@ -2011,8 +2018,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_dte(its->dev->kvm, dev); return ret; + } return offset; }