From patchwork Mon Mar 27 09:31:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9646301 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 47837602BF for ; Mon, 27 Mar 2017 10:08:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F53F228C9 for ; Mon, 27 Mar 2017 10:08:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 229AD28364; Mon, 27 Mar 2017 10:08:20 +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 C55B1228C9 for ; Mon, 27 Mar 2017 10:08:19 +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=PedLB0SfJU1NXr3ClIUHXfyMNtySYOs4X/Mrxv9NprY=; b=FIxEUvHxoSPXCWx9Op0sh3cJFl 34S3ljVYYG/9P9YiALAppn86bv9BpJnFKVC8Q73E+PpqaLnBlkdz9YKnY20I7r0ldCAp4WzhJSVyf 3Y+NrxTVwfJ9zrP6CTRRUzI/uC/v/YsRhrhQYQkFTggQlHjWGuGzhq0UNVy2nM/vBhVGfk4a0ksEs UfdlF4qQ4Dqnt/Ex/JIWpHjWUjvjqVXaiFaRojoR7NoR0TbX2OX84pxUpBznmAwoNL4qlnccyj1pF d0dhY1Jvo28Abdm9a0rSPviXIvjHELrJTo7fbWvyJgSc7mzRe3Pz7VlJrM/PlicEEhnIa3ybst+lj OnhlaltA==; 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 1csRZT-0006lN-2D; Mon, 27 Mar 2017 10:08:19 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1csRVo-0002YK-LH for linux-arm-kernel@bombadil.infradead.org; Mon, 27 Mar 2017 10:04:32 +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=QotG3qpd+4ZB+uSORMMMYgVXwzFJVpPbIjGtoXoeUnM=; b=hhr7KJObYJM6ksCg73J6I/tax zhdKiQzZnbuuruXlef/PrCg1grcHe1qnTluKsq4Iy8azz8SuDMxoUC2FQfSLrkIErP7ox+vJUbEzM djQjWdiXXtXf3eqlh8ClMb1MsKqnMx/8/uoY7i87BKvjZjrFy4YGJM4W9T1pFaHXYELy0w2KGjSyi ISDmFI1JHSk4+NRNTmta+/tUWywtlWDOlPDpVqaDWgD2T5U2EUIoP218yzYLzWIIoYiW3oLoq53rk JqckK+d54ISrANxYGfBCy23LFFBNHDUqi86q8ff2Lw8sBSmKSf0tLmEaRp330XXVaniRgvGBxHBRa eh7/FUPFw==; Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1csR1R-0006sp-6b for linux-arm-kernel@lists.infradead.org; Mon, 27 Mar 2017 09:33:10 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6B75BC073D63; Mon, 27 Mar 2017 09:32:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6B75BC073D63 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=eric.auger@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 6B75BC073D63 Received: from localhost.localdomain.com (ovpn-117-27.ams2.redhat.com [10.36.117.27]) by smtp.corp.redhat.com (Postfix) with ESMTP id B3DD317C46; Mon, 27 Mar 2017 09:32:46 +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 v4 18/22] KVM: arm64: ITS: Collection table save/restore Date: Mon, 27 Mar 2017 11:31:08 +0200 Message-Id: <1490607072-21610-19-git-send-email-eric.auger@redhat.com> In-Reply-To: <1490607072-21610-1-git-send-email-eric.auger@redhat.com> References: <1490607072-21610-1-git-send-email-eric.auger@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 27 Mar 2017 09:32:50 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170327_053309_379519_7FEEB12F X-CRM114-Status: GOOD ( 17.25 ) 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 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 --- v3 -> v4: - replaced u64 *ptr by gpa_t gpa - check the collection does not exist before allocating it 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 | 99 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 8eaeba4..df984b6 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1828,13 +1828,89 @@ 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, gpa_t gpa) +{ + 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, &val, 8); + return ret; +} + +static int vgic_its_restore_cte(struct vgic_its *its, gpa_t gpa, 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, &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; + + collection = find_collection(its, coll_id); + if (collection) + return -EEXIST; + 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; + gpa_t gpa; + size_t max_size, filled = 0; + int ret; + + gpa = BASER_ADDRESS(its->baser_coll_table); + if (!gpa) + 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, gpa); + if (ret) + return ret; + gpa += 8; + 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, &val, 8); + return ret; } /** @@ -1844,7 +1920,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; + gpa_t gpa; + int ret; + + gpa = BASER_ADDRESS(its->baser_coll_table); + if (!gpa) + 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, gpa, &valid); + if (!valid || ret) + break; + gpa += 8; + read += 8; + } + return ret; } /**