From patchwork Mon Mar 6 11:34:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9606081 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 15C6C6046A for ; Mon, 6 Mar 2017 13:45:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 02A212723E for ; Mon, 6 Mar 2017 13:45:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EA5AD28418; Mon, 6 Mar 2017 13:45: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=-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 AB5282723E for ; Mon, 6 Mar 2017 13:45:39 +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=CNKWbYdKrUFyBLVXsorQrgq2vw5tMwB1gVEjF2JCBg8=; b=VnGmT6SuF7AXfb75Eaq6zUN14p uRlp3c97xYRAAlqRySuzVwqd91NRNAHZf7RezqU8e3eS80JOe5Q5QygswWFaReTjlou2BEh9M1eXS xvy1MA7MldtfjBA3eHx5JxmzBPPGigxG8ULtBLxROExSH9wB35cfVwoMO+gPWg53XK6hncOdl6Hem JGhrXOSsN//mzfYE9/ymdLFzL7W4+1E3SAY0Ls2sbaxZlCiWHknUaWTooJvsvRh8MJOBkFcAcn5gc QMdFlsvSoS6xtn1qZPIzNb2QkIkB9M84ZUhkVyhCtEJLEyORh3T9Etc3Y/nkKPlJ4NDOlYjGxkcaP 2CrD9mUA==; 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 1cksxC-0008AE-Sv; Mon, 06 Mar 2017 13:45:34 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cksvl-0006Ab-1b for linux-arm-kernel@bombadil.infradead.org; Mon, 06 Mar 2017 13:44:05 +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=RTvlFmzHwSXuBJAZMgZ4SCSuaJVaRSRkDwW54UNAXio=; b=2yf85l6HpXdKBHWljfljmYHzp LpXN9SslRjRSfKl+tHvq8jFXNzpQAP9MpQc423Hd1VQrmD0sBaKj9VyZoZgXKy8QNewZEBtH9H71Z XS15qKOXflPWPGsBrLi9Bt/FLpOSWhGYL6f1HI+LsY8tYhhWB9nShqVYWVitVkd2V0sWJ2dlGfDrj TzSxBoztFi6J1Cz9UuJYBzhYieeFldkWuy5HISf+8LvZfGK6Qajiu3bHyxabEW4u83M4I7aFF9+WP k4vUV9NZvO9DJIVIF1kZzM1S8fztN7reh/0kmoBfUge2olLhZS3gygKfEIYlAhHqbC8NPvrzwIeBi 5L2sBYS4g==; Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckqw3-0005F6-VS 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 CF85F3B70C; Mon, 6 Mar 2017 11:35:35 +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 v26BYbnc002618; Mon, 6 Mar 2017 06:35:32 -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 13/19] KVM: arm64: ITS: Sort the device and ITE lists Date: Mon, 6 Mar 2017 12:34:28 +0100 Message-Id: <1488800074-21991-14-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.30]); Mon, 06 Mar 2017 11:35:35 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170306_063616_111882_FF9ACE36 X-CRM114-Status: GOOD ( 13.40 ) 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 Natively sort the device and ITE lists in ascending deviceId/eventid order. This paves the way to optimized DTE and ITE scan in guest RAM table where entries are chained together using a next ID offset. Signed-off-by: Eric Auger Reviewed-by: Andre Przywara --- virt/kvm/arm/vgic/vgic-its.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 9792110..1cd6ae6 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -734,6 +734,21 @@ static void vgic_its_free_collection(struct vgic_its *its, u32 coll_id) kfree(collection); } +static void ite_list_insert_sorted(struct list_head *h, struct its_ite *ite) +{ + struct list_head *pos = h->next; + u32 id = ite->event_id; + + while (pos != h) { + struct its_ite *iter = + list_entry(pos, struct its_ite, ite_list); + if (id < iter->event_id) + break; + pos = pos->next; + } + list_add_tail(&ite->ite_list, pos); +} + static int vgic_its_alloc_ite(struct its_device *device, struct its_ite **itep, struct its_collection *collection, @@ -749,7 +764,7 @@ static int vgic_its_alloc_ite(struct its_device *device, ite->collection = collection; ite->lpi = lpi_id; - list_add_tail(&ite->ite_list, &device->itt_head); + ite_list_insert_sorted(&device->itt_head, ite); *itep = ite; return 0; } @@ -842,6 +857,22 @@ static void vgic_its_unmap_device(struct kvm *kvm, struct its_device *device) kfree(device); } +static void device_list_insert_sorted(struct list_head *h, + struct its_device *dev) +{ + struct list_head *pos = h->next; + u32 id = dev->device_id; + + while (pos != h) { + struct its_device *iter = + list_entry(pos, struct its_device, dev_list); + if (id < iter->device_id) + break; + pos = pos->next; + } + list_add_tail(&dev->dev_list, pos); +} + static int vgic_its_alloc_device(struct vgic_its *its, struct its_device **devp, u32 device_id, gpa_t itt_addr_field, @@ -858,7 +889,8 @@ static int vgic_its_alloc_device(struct vgic_its *its, device->nb_eventid_bits = size_field + 1; INIT_LIST_HEAD(&device->itt_head); - list_add_tail(&device->dev_list, &its->device_list); + device_list_insert_sorted(&its->device_list, device); + *devp = device; return 0;