From patchwork Tue Nov 7 10:47: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: 10046499 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 80D256031B for ; Tue, 7 Nov 2017 11:25:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6C39729BDE for ; Tue, 7 Nov 2017 11:25:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6087529C30; Tue, 7 Nov 2017 11:25:39 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED 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 E43C529BDE for ; Tue, 7 Nov 2017 11:25:38 +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=O7ivsZ38xJM6DmCD7DqwbR57GfE9xdSYDsC/UVbkTKg=; b=XWB+sHWyAJ/rvA2dcBRoXJqzq4 x9wSGDC4PpA1ZwB+Ar27jxsN3vZZ8LMmwJrg2qQ+R/qY0u7KUU9oxN+b6fyDqRrxuu4FF+i03G2PQ 4f3i1eUwbJJjfMY7bPJ1UwVsnOzBDZelvQaw4uHSJPqgXxxEKqygLyvSuqASqdiHXTzRlfSeB80gJ nmFiVYgmtRwpFB9C4/jOutLEtpyJOUmgDtPEmEvE132HgQRDwefk4u9/TF8AdsvZPSAE/lhR5hU12 W8Ekt4ST1HY2QFhXUOsWTeWWpMZOOssznRjarLGV2hVPswgp9XsGPxy0gW0vhxsI2llkyLClaW+py w9/xz+bQ==; 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 1eC20b-0005LT-Jx; Tue, 07 Nov 2017 11:25:33 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eC1zv-0002JX-La for linux-arm-kernel@bombadil.infradead.org; Tue, 07 Nov 2017 11:24:51 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=CGlvTqi+8FWFa/NNYp8IsDn2xEdE7e3YC/3a1qWv7Jg=; b=b2cbGNQLOgRwtA33v21xNcmwR EEESZT3L0/mjApgG5pFicu320cySX97IjtFEZnufOwh3mVxphu97clW9M3PwNTuMJSjR90vZ1PsCe 90ZkN6CAP3zJKq9sNjZgIZDnQyAKks/V3v+vzC8pcatd8te3xNUzq4yYMSL9j7UBjGJEt6NzZJtDz GRNOkwk1CjeORupd7Nt3Tl14xRL/OlLiKNDOlTRrxsMihNCmB6GiG2HBgG+/R5CiRyeaRKIDUSLWZ oMvuRgQH3DMXMUfdXC9a7tuIwpDwgtB4Mr+sdzYA2s3PVhcDdutUasaVXK3Grh7+C/Sar8BUmK0cc fuvxK8+Wg==; Received: from mail-wm0-x243.google.com ([2a00:1450:400c:c09::243]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eC1RF-00059H-KC for linux-arm-kernel@lists.infradead.org; Tue, 07 Nov 2017 10:49:05 +0000 Received: by mail-wm0-x243.google.com with SMTP id p75so2739170wmg.3 for ; Tue, 07 Nov 2017 02:48:43 -0800 (PST) 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=CGlvTqi+8FWFa/NNYp8IsDn2xEdE7e3YC/3a1qWv7Jg=; b=UX/SpMRkY4/lRtWI46/kJb2Pu0WBuFtmEXy1yF661Pn/E5UWQmEUVpiuQf60yYCVMu ljyrOD0wdIPOvCeV/udMKUDjKPtmaSxWCLr9hLZYL21ZYJyjid/XI+tpHfX+Hj+AOwiN zIF9Wz4gogskV5VLjUKhRnm2U/e5wUIDp88x4= 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=CGlvTqi+8FWFa/NNYp8IsDn2xEdE7e3YC/3a1qWv7Jg=; b=mzmYL+Oy398IblnNk95ccuXuBhpaqjzVXtvHfCirkkcQMbrsm0zTD+5nwUWGuGo3tc rwfwO4BeX9rW1CCx5pNrzJo/ozy5ofn22z2wcIWkkij5pd3OFoEDjTx9oX3EtU0kKG4I NJ+YNXgmvpOet989XJu7N2RlRzf7+R8WnTL0z2M4g0I/kA8sDPjl39I/JQHTnPg82Qw4 owcFnth/M7j4nmC/2pCpEDkbf2Mro4Nx1rlzYIlAD4kNOVelfyTLTDs8PKfLoYap8uF+ Gu5XBedJzPRQ+Q4ly6UmU83dFar7Zh9UT0d5RNplUyFrhWqICV+RW8zvEpgj2YI64+O5 iA5g== X-Gm-Message-State: AMCzsaUzLzl5xkyDrkUHRAJpUsGudcUgvPiDqNzMYVoXa+Fq7uVR44qn xbGbxKiyVLXzoK+FHKUD3l7dbA== X-Google-Smtp-Source: ABhQp+SydoxGJAgqcAC0A/mu4aZ06lLx8ofNrd9eutJUZV4EED0tzx5obrk4OtxpRcEW/sE6RunWCg== X-Received: by 10.80.144.4 with SMTP id b4mr23947316eda.127.1510051720948; Tue, 07 Nov 2017 02:48:40 -0800 (PST) Received: from localhost.localdomain (xd93dd96b.cust.hiper.dk. [217.61.217.107]) by smtp.gmail.com with ESMTPSA id q12sm1044958edj.29.2017.11.07.02.48.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 Nov 2017 02:48:40 -0800 (PST) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 21/26] KVM: arm/arm64: vgic-its: New helper functions to free the caches Date: Tue, 7 Nov 2017 11:47:54 +0100 Message-Id: <20171107104800.30021-22-christoffer.dall@linaro.org> X-Mailer: git-send-email 2.14.2 In-Reply-To: <20171107104800.30021-1-christoffer.dall@linaro.org> References: <20171107104800.30021-1-christoffer.dall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171107_104901_677840_D9CB30B1 X-CRM114-Status: GOOD ( 15.79 ) 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: kvm@vger.kernel.org, Marc Zyngier , Eric Auger , Christoffer Dall , wanghaibin , 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+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: wanghaibin We create two new functions that free the device and collection lists. They are currently called by vgic_its_destroy() and other callers will be added in subsequent patches. We also remove the check on its->device_list.next. Lists are initialized in vgic_create_its() and the device is added to the device list only if this latter succeeds. vgic_its_destroy is the device destroy ops. This latter is called by kvm_destroy_devices() which loops on all created devices. So at this point the list is initialized. Acked-by: Marc Zyngier Signed-off-by: wanghaibin Signed-off-by: Eric Auger Signed-off-by: Christoffer Dall --- virt/kvm/arm/vgic/vgic-its.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 75c18183eee3..d46256c07ba5 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -913,6 +913,24 @@ static void vgic_its_free_device(struct kvm *kvm, struct its_device *device) kfree(device); } +/* its lock must be held */ +static void vgic_its_free_device_list(struct kvm *kvm, struct vgic_its *its) +{ + struct its_device *cur, *temp; + + list_for_each_entry_safe(cur, temp, &its->device_list, dev_list) + vgic_its_free_device(kvm, cur); +} + +/* its lock must be held */ +static void vgic_its_free_collection_list(struct kvm *kvm, struct vgic_its *its) +{ + struct its_collection *cur, *temp; + + list_for_each_entry_safe(cur, temp, &its->collection_list, coll_list) + vgic_its_free_collection(its, cur->collection_id); +} + /* Must be called with its_lock mutex held */ static struct its_device *vgic_its_alloc_device(struct vgic_its *its, u32 device_id, gpa_t itt_addr, @@ -1619,32 +1637,13 @@ static void vgic_its_destroy(struct kvm_device *kvm_dev) { struct kvm *kvm = kvm_dev->kvm; struct vgic_its *its = kvm_dev->private; - struct list_head *cur, *temp; - - /* - * We may end up here without the lists ever having been initialized. - * Check this and bail out early to avoid dereferencing a NULL pointer. - */ - if (!its->device_list.next) - return; mutex_lock(&its->its_lock); - 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; + vgic_its_free_device_list(kvm, its); + vgic_its_free_collection_list(kvm, its); - coll = list_entry(cur, struct its_collection, coll_list); - list_del(cur); - kfree(coll); - } mutex_unlock(&its->its_lock); - kfree(its); }