From patchwork Mon Mar 6 11:34:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9605839 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 4FB6E602B4 for ; Mon, 6 Mar 2017 11:43:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 296DB281C3 for ; Mon, 6 Mar 2017 11:43:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E5BA28249; Mon, 6 Mar 2017 11:43: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=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 AD8F4281C3 for ; Mon, 6 Mar 2017 11:43:17 +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=Rgts3OYlTVvFdsevZc9LlmXbUmvzSz8nBEEZqFeh7jM=; b=gYH+4MaMstQwlJK9QcgW1OrOEK DOkDPrW7A8PfTAFfiShv7wpVDZV3SJTn5kE+PKNPwnkGmkHy4gklJMlZrVmTM6CY50WVyt/PrE9kQ ymPtH9ujVSS3EjbX6F2pIvR3YUTqDoFaZJWJAHRBWBX3oIp2cqcgg5EQi9Rjc+SP7Fmqs73kqsE/L gzNXJkZ6k/jtNtLrwW59LRG+eZrZ/HAgdmKKWLd0SBz4tdgJdqLHyi1bHztcnq1sTBusc7NLHSVf5 cu5KKSoxLeogVxAqK6g6Nv5+M+c3JpzBj83z5p2v5fAIWYAoVg85Yio5GT9X0Q5/eoEp4+Qw/IPhc hKIA+6cA==; 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 1ckr2l-0000Rx-4v; Mon, 06 Mar 2017 11:43:11 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckr2e-00009b-Pk 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=7OhUI7bWCx+NI7ZZdVOVsunKKVLUVDRXvvvW+Wro+5Q=; b=Ng7MwP8GKktQkLjUWaXNIPLl5 0ZP6XF7X8tsc6YbrdvrBiRWHiEw7bqGcsf4TxZEd+b8dj7pEBLYU1/CxyTHdkC4bYmPTAY7kXNuFB vCs8V+E5Zh3OPY1IP7Go1Kh5QmSICLBvx6kliggWVdCB7nssHMM2OvsqRIDHZW8/Nureni2wob5+P sIDGdT0AlDzaJPfVsrHT8Y5F+cg0A9P58VHHwBGFW9kehknUwlAOW9wW0iiMwGxHOMlIJqsdKSx5h 4jz9sldwFh/NLfbMmZyfIbsJF8p7ysUJ7lRDxk+wSEU77pWrZKjJYdOkSFPX48jfSQrrZ9kqtZKXW GUOwwUT4Q==; Received: from mx1.redhat.com ([209.132.183.28]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckqwA-0003QP-Fa for linux-arm-kernel@lists.infradead.org; Mon, 06 Mar 2017 11:36:24 +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 5AB8261D1E; Mon, 6 Mar 2017 11:35:43 +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 v26BYbne002618; Mon, 6 Mar 2017 06:35:39 -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 15/19] KVM: arm64: ITS: Collection table save/restore Date: Mon, 6 Mar 2017 12:34:30 +0100 Message-Id: <1488800074-21991-16-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.39]); Mon, 06 Mar 2017 11:35:43 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170306_113622_785025_C5774219 X-CRM114-Status: GOOD ( 17.43 ) 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 The flush path copies the collection entries into guest RAM at the GPA specified in the BASER register. This obviously requires the BASER to be set. The last written element is a dummy collection table entry. We do not index by collection ID as the collection entry can fit into 8 bytes while containing the collection ID. On restore path we re-allocate the collection objects. Signed-off-by: Eric Auger --- v1 -> v2: - reword commit message and directly use 8 as entry size - no kvm parameter anymore - add helper for flush/restore cte - table size computed here - add le64/cpu conversions --- virt/kvm/arm/vgic/vgic-its.c | 94 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 92 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index cf04776..ad67759 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1761,13 +1761,84 @@ static int vgic_its_restore_device_tables(struct vgic_its *its) return -ENXIO; } +static int vgic_its_flush_cte(struct vgic_its *its, + struct its_collection *collection, u64 *ptr) +{ + u64 val; + int ret; + + val = ((u64)1 << 63 | ((u64)collection->target_addr << 16) | + collection->collection_id); + val = cpu_to_le64(val); + ret = kvm_write_guest(its->dev->kvm, (gpa_t)ptr, &val, 8); + return ret; +} + +static int vgic_its_restore_cte(struct vgic_its *its, u64 *ptr, bool *valid) +{ + struct its_collection *collection; + u32 target_addr; + u32 coll_id; + u64 val; + int ret; + + *valid = false; + + ret = kvm_read_guest(its->dev->kvm, (gpa_t)ptr, &val, 8); + if (ret) + return ret; + val = le64_to_cpu(val); + *valid = val & BIT_ULL(63); + + if (!*valid) + return 0; + + target_addr = (u32)(val >> 16); + coll_id = val & 0xFFFF; + ret = vgic_its_alloc_collection(its, &collection, coll_id); + if (ret) + return ret; + collection->target_addr = target_addr; + return 0; +} + /** * vgic_its_flush_collection_table - flush the collection table into * guest RAM */ static int vgic_its_flush_collection_table(struct vgic_its *its) { - return -ENXIO; + struct its_collection *collection; + u64 val, *ptr; + size_t max_size, filled = 0; + int ret; + + ptr = (u64 *)(BASER_ADDRESS(its->baser_coll_table)); + if (!ptr) + return 0; + + max_size = GITS_BASER_NR_PAGES(its->baser_coll_table) * SZ_64K; + + list_for_each_entry(collection, &its->collection_list, coll_list) { + if (filled == max_size) + return -ENOSPC; + ret = vgic_its_flush_cte(its, collection, ptr); + if (ret) + return ret; + ptr++; + filled += 8; + } + + if (filled == max_size) + return 0; + + /* + * table is not fully filled, add a last dummy element + * with valid bit unset + */ + val = 0; + ret = kvm_write_guest(its->dev->kvm, (gpa_t)ptr, &val, 8); + return ret; } /** @@ -1777,7 +1848,26 @@ static int vgic_its_flush_collection_table(struct vgic_its *its) */ static int vgic_its_restore_collection_table(struct vgic_its *its) { - return -ENXIO; + size_t max_size, read = 0; + u64 *ptr; + int ret; + + ptr = (u64 *)(BASER_ADDRESS(its->baser_coll_table)); + if (!ptr) + return 0; + + max_size = GITS_BASER_NR_PAGES(its->baser_coll_table) * SZ_64K; + + while (read < max_size) { + bool valid; + + ret = vgic_its_restore_cte(its, ptr, &valid); + if (!valid || ret) + break; + ptr++; + read += 8; + } + return ret; } /**