From patchwork Mon Mar 6 11:34:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9605841 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 2D9BC602B4 for ; Mon, 6 Mar 2017 11:43:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0746428236 for ; Mon, 6 Mar 2017 11:43:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFCB128305; Mon, 6 Mar 2017 11:43:43 +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 6F73428236 for ; Mon, 6 Mar 2017 11:43:43 +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=bgWx3ViUZdS1kUVXcCED8Yq+wYd8Rr5UOjvvlqd2ZxA=; b=VByh/DSR8NCBvBD3BCNTolTGuS cyNUQccKatbFt9ifkA7ZvfHclNax4PEQoMw/C4YcgVMKiQFKQaMSWDkUaGKWrn85z+p/MMmwtTCar pwk5UdOr37tsmyzjVVvVq5NJegSqClprVoRYZ+IhUZqUSqbaBNN5ejp0FtcU5nyGon3cWsoYey/S6 C9acZNSWDTVg1j56yEjLuD8TkeNIQDgFh1LqswlOC9pdYAdxQOS8/ngciDMCGsMvNA9t+2Ir3XIsS d1kG1oRe9eIhdE8dRJeGagFWjk4Jp4Pa5pOuveiN5nWiojBDvnki5Y0TAbwEjN3Dc9ctoiznIe8ZB +RIcKLMw==; 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 1ckr3F-0000uu-3e; Mon, 06 Mar 2017 11:43:41 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckr2f-0000A4-Ma for linux-arm-kernel@bombadil.infradead.org; Mon, 06 Mar 2017 11:43:05 +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=ywKi2bRf+oJ26Xh+PloTFZ4TwG/BbKkM+SF2nURVBhs=; b=j8eBN5KVHWSY17CYXH63agjj8 x0G3y4y54Q5yNa9HrhxmpCT8MYte0fYvu32l/1Qe0pQqpyRxVVvkup7fua7A0rdUYq7UHiwyy97Aa r8JF+cHfBnbOqkQTBj2fkTHVxwal6okXj67dgmWIOKkuNPDrXXkWYLgmyFBBRLQwOCijA+uBxS524 Dk3/HFxJOw3vDJ6ESt1FRptSOnGl5kHR17y7en04mls6Y5Io9gB2CUlOINeD/+cL1qSazINzUAeBo lO5QPocs8I9wHA9/3RChYeJch9PM7MtJj0RsQVTTETh29zMYBjaqcB3Y92p8Zk69LMb513UpmbR1+ K7gI8x7Yw==; Received: from mx1.redhat.com ([209.132.183.28]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckqw0-0003OS-FX for linux-arm-kernel@lists.infradead.org; Mon, 06 Mar 2017 11:36:16 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0705564DA2; Mon, 6 Mar 2017 11:35:32 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-100.ams2.redhat.com [10.36.116.100]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v26BYbnb002618; Mon, 6 Mar 2017 06:35:28 -0500 From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, marc.zyngier@arm.com, christoffer.dall@linaro.org, vijayak@caviumnetworks.com, Vijaya.Kumar@cavium.com, peter.maydell@linaro.org, linux-arm-kernel@lists.infradead.org, drjones@redhat.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH v3 12/19] KVM: arm64: ITS: vgic_its_alloc_ite/device Date: Mon, 6 Mar 2017 12:34:27 +0100 Message-Id: <1488800074-21991-13-git-send-email-eric.auger@redhat.com> In-Reply-To: <1488800074-21991-1-git-send-email-eric.auger@redhat.com> References: <1488800074-21991-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 06 Mar 2017 11:35:32 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170306_113612_787189_736BED5C X-CRM114-Status: GOOD ( 15.22 ) 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: andre.przywara@arm.com, pbonzini@redhat.com, dgilbert@redhat.com, quintela@redhat.com, Prasun.Kapoor@cavium.com 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 Add two new helpers to allocate an its ite and an its device. This will avoid duplication on restore path. Signed-off-by: Eric Auger --- v1 -> v2: - report itt_size fix and remove ITE_SIZE - s/itte/ite/g --- virt/kvm/arm/vgic/vgic-its.c | 70 +++++++++++++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index dd7545a..9792110 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -734,6 +734,26 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id) kfree(collection); } +static int vgic_its_alloc_ite(struct its_device *device, + struct its_ite **itep, + struct its_collection *collection, + u32 lpi_id, u32 event_id) +{ + struct its_ite *ite; + + ite = kzalloc(sizeof(ite), GFP_KERNEL); + if (!ite) + return -ENOMEM; + + ite->event_id = event_id; + ite->collection = collection; + ite->lpi = lpi_id; + + list_add_tail(&ite->ite_list, &device->itt_head); + *itep = ite; + return 0; +} + /* * The MAPTI and MAPI commands map LPIs to ITTEs. * Must be called with its_lock mutex held. @@ -747,7 +767,7 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, struct its_ite *ite; struct its_device *device; struct its_collection *collection, *new_coll = NULL; - int lpi_nr; + int lpi_nr, ret; struct vgic_irq *irq; device = find_its_device(its, device_id); @@ -777,19 +797,13 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, new_coll = collection; } - ite = kzalloc(sizeof(struct its_ite), GFP_KERNEL); - if (!ite) { + ret = vgic_its_alloc_ite(device, &ite, collection, lpi_nr, event_id); + if (ret) { if (new_coll) vgic_its_free_collection(its, coll_id); - return -ENOMEM; + return ret; } - ite->event_id = event_id; - list_add_tail(&ite->ite_list, &device->itt_head); - - ite->collection = collection; - ite->lpi = lpi_nr; - irq = vgic_add_lpi(kvm, lpi_nr); if (IS_ERR(irq)) { if (new_coll) @@ -828,6 +842,28 @@ static void vgic_its_unmap_device(struct kvm *kvm, struct its_device *device) kfree(device); } +static int vgic_its_alloc_device(struct vgic_its *its, + struct its_device **devp, + u32 device_id, gpa_t itt_addr_field, + size_t size_field) +{ + struct its_device *device; + + device = kzalloc(sizeof(*device), GFP_KERNEL); + if (!device) + return -ENOMEM; + + device->device_id = device_id; + device->itt_addr = itt_addr_field << 8; + device->nb_eventid_bits = size_field + 1; + INIT_LIST_HEAD(&device->itt_head); + + list_add_tail(&device->dev_list, &its->device_list); + *devp = device; + + return 0; +} + /* * MAPD maps or unmaps a device ID to Interrupt Translation Tables (ITTs). * Must be called with the its_lock mutex held. @@ -864,19 +900,7 @@ static int vgic_its_cmd_handle_mapd(struct kvm *kvm, struct vgic_its *its, if (!valid) return 0; - device = kzalloc(sizeof(struct its_device), GFP_KERNEL); - if (!device) - return -ENOMEM; - - device->device_id = device_id; - device->itt_addr = itt_addr << 8; - device->nb_eventid_bits = size + 1; - - INIT_LIST_HEAD(&device->itt_head); - - list_add_tail(&device->dev_list, &its->device_list); - - return 0; + return vgic_its_alloc_device(its, &device, device_id, itt_addr, size); } /*