From patchwork Tue May 9 10:44:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9717669 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 AC95160364 for ; Tue, 9 May 2017 11:06:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A022720373 for ; Tue, 9 May 2017 11:06:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 935E1283F2; Tue, 9 May 2017 11:06:56 +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 075D320373 for ; Tue, 9 May 2017 11:06:56 +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=bfJ2Jrv5cIRrMaVgSsOyuicIOFkI7NKMJaUjnqhuayo=; b=DXc16yFzNYJGXTXygRyCq3IhPq YsTi5z36dQK6jUP6WHd/FpKm95oJFELqKy7i0WnAIZ+plOyud3H264QqnO4Aw1SGSF5gIJCQNpX+y gpcmVeoifaf/Ln8fhDGWosy9jdzNl22cWqPOsPXyc2FfAiI9QZie/AnFEW0vGe9+dj1BCkG7iidfg Ig3aqU7OdVce4GucLv7HsLxCnlXmAHjNhfUPEczxGeOPUtQJ+y6VTDXknHfT1SKiZ+TW/cO0AEGsb sfVSLSwB3eKwz3VMCweu/fHZ2znTow7Ea+T4hEurFy90eQxtL27SYto4J2tirrEd7mT6lZ3WKawSx QqZ3e24w==; 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 1d82yj-0004TD-GW; Tue, 09 May 2017 11:06:53 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d82xV-0002pf-HR for linux-arm-kernel@bombadil.infradead.org; Tue, 09 May 2017 11:05:37 +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=mT5wkvsFmHdCo92gmKME9pwLiHUeMMpfwz9iKZMgku8=; b=gyzI9BfZpQhUYwLNWgKjDLBKe UNhxQbd4ZspGBY2hA4bL+vJATVEMGYUXC5oXEIZWcQjKuqJxWb4uNOaxxrauVkN6G79uDSJQ0PjZx OZclBk9/+za/AvUtqDhNrqJUcIpB28ktLDf/JyRS+iS2VE6S7GXBQ4GSBiVCBcOnODoFjn4j21C0X j2XWrgADzPaVtkxqjLCqsJKOmSR3NHIgRpsFLdUG/bmZ8z63r7c+HHa+iBaJGJ4WtfM5HrJZh4Ty+ yQwVRuDn1PFFSyWYONidUYhm3UF41T+wdF7bOf4aFWR4QXD/tlyRnuMC8RFAhVKHyUZBdr/ICg/n9 p6gRWp/kQ==; Received: from mail-qk0-x236.google.com ([2607:f8b0:400d:c09::236]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d82eO-00071M-SG for linux-arm-kernel@lists.infradead.org; Tue, 09 May 2017 10:45:54 +0000 Received: by mail-qk0-x236.google.com with SMTP id u75so75014580qka.3 for ; Tue, 09 May 2017 03:45:31 -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=mT5wkvsFmHdCo92gmKME9pwLiHUeMMpfwz9iKZMgku8=; b=Z/2F8nI5R/Uc16TiwDfzhbgn7tpYZFOLIBKB5LUlss3sILE+DubN71ecLuzP7ag6kI KDdAYn2Cgg2nEQHoAK5NPCmq0csid8PP1QIU1OPcuGeccVXusNRxbVHxeLvo1tHk6coQ pD8POlReetbk5y8keQSQY2LXgQlusljmjrFEk= 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=mT5wkvsFmHdCo92gmKME9pwLiHUeMMpfwz9iKZMgku8=; b=SIsc8s53TSSzzE0uvDOXzpibInbodX3xl2h2/IOSRz3ea06YbLlpG2M2+agrMoMWB4 y2dKlFXvwbJokUTiuhJ/yGBYA+VwA8zeAfYVsRWJ5jryCrFzNyoCQD+yGO44W+ZoWux2 7Y/O64qxCeVGy0wr5qQiqkDAghF4DOa3+C38Ob5OAmB8FlzVxIoRE3fu9ZIW0XLVpwum eIiVGULcXe6A1GIwnkAsvh5XoeStZAeByjRa5f8uxjimedqtBk/xqXT8wVZw5E0f2gQW DzqgDZUuc0QPs76RiCSbojA8r/OXv0fG/qizByc7OuzV/8aqJMj/rJ9ailgwT/807V/l d60Q== X-Gm-Message-State: AN3rC/6YR9xQH8m4maKzMPJ5auP+LkHhZPgJ7LeApwXnuFgW0aHPTKH2 6pPy5nO2nXaz9QJk X-Received: by 10.80.166.197 with SMTP id f5mr45937636edc.144.1494326730836; Tue, 09 May 2017 03:45:30 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id o30sm2331510edc.42.2017.05.09.03.45.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 09 May 2017 03:45:30 -0700 (PDT) From: Christoffer Dall To: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Subject: [PULL 19/37] KVM: arm64: vgic-its: vgic_its_alloc_ite/device Date: Tue, 9 May 2017 12:44:48 +0200 Message-Id: <20170509104506.30929-20-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170509104506.30929-1-cdall@linaro.org> References: <20170509104506.30929-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170509_064553_115612_2FC44F23 X-CRM114-Status: GOOD ( 14.67 ) 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 , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, 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: Eric Auger 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 Reviewed-by: Christoffer Dall Reviewed-by: Marc Zyngier --- virt/kvm/arm/vgic/vgic-its.c | 68 ++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 21 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index cb7ae4c..737ba3c 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -802,6 +802,25 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id) kfree(collection); } +/* Must be called with its_lock mutex held */ +static struct its_ite *vgic_its_alloc_ite(struct its_device *device, + struct its_collection *collection, + u32 lpi_id, u32 event_id) +{ + struct its_ite *ite; + + ite = kzalloc(sizeof(*ite), GFP_KERNEL); + if (!ite) + return ERR_PTR(-ENOMEM); + + ite->event_id = event_id; + ite->collection = collection; + ite->lpi = lpi_id; + + list_add_tail(&ite->ite_list, &device->itt_head); + return ite; +} + /* * The MAPTI and MAPI commands map LPIs to ITTEs. * Must be called with its_lock mutex held. @@ -816,8 +835,8 @@ static int vgic_its_cmd_handle_mapi(struct kvm *kvm, struct vgic_its *its, struct kvm_vcpu *vcpu = NULL; struct its_device *device; struct its_collection *collection, *new_coll = NULL; - int lpi_nr; struct vgic_irq *irq; + int lpi_nr; device = find_its_device(its, device_id); if (!device) @@ -846,19 +865,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) { + ite = vgic_its_alloc_ite(device, collection, lpi_nr, event_id); + if (IS_ERR(ite)) { if (new_coll) vgic_its_free_collection(its, coll_id); - return -ENOMEM; + return PTR_ERR(ite); } - ite->event_id = event_id; - list_add_tail(&ite->ite_list, &device->itt_head); - - ite->collection = collection; - ite->lpi = lpi_nr; - if (its_is_collection_mapped(collection)) vcpu = kvm_get_vcpu(kvm, collection->target_addr); @@ -891,6 +904,26 @@ static void vgic_its_unmap_device(struct kvm *kvm, struct its_device *device) kfree(device); } +/* 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, + u8 num_eventid_bits) +{ + struct its_device *device; + + device = kzalloc(sizeof(*device), GFP_KERNEL); + if (!device) + return ERR_PTR(-ENOMEM); + + device->device_id = device_id; + device->itt_addr = itt_addr; + device->num_eventid_bits = num_eventid_bits; + INIT_LIST_HEAD(&device->itt_head); + + list_add_tail(&device->dev_list, &its->device_list); + return device; +} + /* * MAPD maps or unmaps a device ID to Interrupt Translation Tables (ITTs). * Must be called with the its_lock mutex held. @@ -927,17 +960,10 @@ 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->num_eventid_bits = num_eventid_bits; - device->itt_addr = itt_addr; - - INIT_LIST_HEAD(&device->itt_head); - - list_add_tail(&device->dev_list, &its->device_list); + device = vgic_its_alloc_device(its, device_id, itt_addr, + num_eventid_bits); + if (IS_ERR(device)) + return PTR_ERR(device); return 0; }