From patchwork Fri Apr 14 10:15: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: 9681115 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 2752760326 for ; Fri, 14 Apr 2017 10:44:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CF4F28673 for ; Fri, 14 Apr 2017 10:44:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 003D72867A; Fri, 14 Apr 2017 10:44:18 +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 9932E28673 for ; Fri, 14 Apr 2017 10:44:18 +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=JtWpqZIJ57V/jC9LX0MKarUWf+DDSvSZvZ3qFFuN0iI=; b=RXD0QMIhCxGYIp2076LEX4B73G CRycuD2HIw+uP3d0M3jR0KwJ9g7zsd9ADBeIg4JKFqz814jREpzIuvTdV9woqVG6mQacXQhsn2HDt ZSXTKZfOrQSj7kBWhI7kjbjLWtwc+8mg0lgYj3HWegSIHGLCE0rqvRnxnb88OuLE5z845393CGd4i lH908xgFgEryLpazTGUGAIMt2F9iyeO537SseBcRIvj8nKW+9shsdX1mmcnMie2Wup1/HZ4coKGL0 bkepLC0UvDVzW+8wPlhqTnBW3/l3raoQOXwu6nAVbQkTqr6UYN9VxqDMxbkOZOfxsss0rgplO86SS N/RjvXrw==; 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 1cyyi8-00063y-CH; Fri, 14 Apr 2017 10:44:16 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cyyi6-000634-HF for linux-arm-kernel@bombadil.infradead.org; Fri, 14 Apr 2017 10:44:14 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=LTbtwGfMfuupUTR4IosNFY+Emla28tAUjEEA0ZDGKXc=; b=ImawojOHrSTMMplj/ehHFQ2Qx HLTmEOhjNdez2/+Wqb/1f+XZLzyu4E5v/1ky+wZLcK/TdVH690TZVzUHdPv3R44AvXeyNrUQ5IkAJ ikKVLzuxDt49VxK+m0yyrLtTDgQnbVgUqFUrWLeUc0IrH8CmOXvKcPbyE3LIJAKL7RZX5wATs60+O Tr32PorS7+zTEEl8xfoZFhskGVfTeY5xajH+sr4Ftp9yA+Ap9YHsPQhIUt1AF7cCt4tiG6QwBlDNF CnybGrQFo5WeSvZVH2MDCUpE9U3RrMmAiQGmlxqLr9NqOOwyJB5zVfMkw0HqAP5rxeWxi5ij3ITkd jvC5s/ENQ==; Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cyyQC-0005np-Mp for linux-arm-kernel@lists.infradead.org; Fri, 14 Apr 2017 10:25:46 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 93C2F80475; Fri, 14 Apr 2017 10:17:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 93C2F80475 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eric.auger@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 93C2F80475 Received: from localhost.localdomain.com (ovpn-117-27.ams2.redhat.com [10.36.117.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id 00DCB18214; Fri, 14 Apr 2017 10:17:09 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, marc.zyngier@arm.com, christoffer.dall@linaro.org, andre.przywara@arm.com, vijayak@caviumnetworks.com, Vijaya.Kumar@cavium.com, peter.maydell@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Subject: [PATCH v5 15/22] KVM: arm64: vgic-its: vgic_its_alloc_ite/device Date: Fri, 14 Apr 2017 12:15:27 +0200 Message-Id: <1492164934-988-16-git-send-email-eric.auger@redhat.com> In-Reply-To: <1492164934-988-1-git-send-email-eric.auger@redhat.com> References: <1492164934-988-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Fri, 14 Apr 2017 10:17:13 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170414_062544_945663_7DA19ADF X-CRM114-Status: GOOD ( 15.16 ) 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: Prasun.Kapoor@cavium.com, drjones@redhat.com, quintela@redhat.com, dgilbert@redhat.com, pbonzini@redhat.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 Acked-by: Marc Zyngier Tested-by: Prakash, Brahmajyosyula --- v4 -> v5: - add Marc's A-b v3 -> v4: - fix allocation - add comment about its_lock mutex hold v1 -> v2: - report itt_size fix and remove ITE_SIZE - s/itte/ite/g --- virt/kvm/arm/vgic/vgic-its.c | 73 ++++++++++++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 23 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 55267ab..56c5123 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -742,6 +742,27 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id) kfree(collection); } +/* Must be called with its_lock mutex held */ +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. @@ -755,7 +776,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); @@ -785,19 +806,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) @@ -836,6 +851,29 @@ static void vgic_its_unmap_device(struct kvm *kvm, struct its_device *device) kfree(device); } +/* Must be called with its_lock mutex held */ +static int vgic_its_alloc_device(struct vgic_its *its, + struct its_device **devp, + u32 device_id, gpa_t itt_addr, + u8 nb_eventid_bits) +{ + struct its_device *device; + + device = kzalloc(sizeof(*device), GFP_KERNEL); + if (!device) + return -ENOMEM; + + device->device_id = device_id; + device->itt_addr = itt_addr; + device->nb_eventid_bits = nb_eventid_bits; + 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. @@ -872,19 +910,8 @@ 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->nb_eventid_bits = nb_eventid_bits; - device->itt_addr = itt_addr; - - 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, nb_eventid_bits); } /*