From patchwork Mon Mar 6 11:34:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9606065 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 D5F2A6046A for ; Mon, 6 Mar 2017 13:44:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C47AB2723E for ; Mon, 6 Mar 2017 13:44:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8D7828418; Mon, 6 Mar 2017 13:44:44 +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 209BE2723E for ; Mon, 6 Mar 2017 13:44:44 +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=E6Ihw6OirPzSKmYATY3VIX/QfNxzXmzSz9DimJgW+ao=; b=nmJ0KnJQ3oXMtews9vAo5z16sh bYGUAeQZ6zrkB1dlAEwilgJrZKKWbwoAvYraa4qD/kHqLuFCj8yMCV7y1ZY/63F2ZlWwK2T1KeH8M E54scyeTb73Tx7xHfUnVp2tk1h4jguxCD0TdRFS0rBibnlJFx+QzoLIJesX5moXj7SsPov9IBg/pE Yz2ObjbiRdxxN9YcUxSe6bnKLCXzAbOSHtinoDAgJo7GWbS1AmSf5Bs6TTPgneJK7NNPCXPhYgmkY OSz7iRfMSVHejdhgxHlFVpz1L2WqGRknmS+jR4e7Tu4ExzkqjEqJPt4gut/qHw9f1qKH7eFwnaL74 Zxq/6bSQ==; 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 1ckswJ-0006cJ-5d; Mon, 06 Mar 2017 13:44:39 +0000 Received: from merlin.infradead.org ([2001:4978:20e::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cksvk-0006Ab-CL for linux-arm-kernel@bombadil.infradead.org; Mon, 06 Mar 2017 13:44:04 +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=JBW5sC3bl1wdUYpZM5tYIV4XiX2sL7d2Tw7BRSsf3JI=; b=NUIRDLe6ktpXBVWpyccm5/qpT DEJwHUufool+8YJet086TrEHA573nglw6JDrJ3xL+Jk/kYrgMhSQHYBGUsFzA/NE1HyLJZyeYHEM+ mtq8VO6hBpQsEBJJE79mLUxmE+mqQ87U8h86hEk+Y+vuFp4jDz8SdIjE6MCp+vXZ6Q8rU83bDKSm1 kR8jNTLv08Uw6RwPJnF3CXRk04WoCQ1JEj8ibMydHwWbckaDsg8UeeUjg4nXrOVfTEoUW1yJLicPb n1dVn/l02J/B8kLRmL4EL7yOq+oZgiTg/Jqjh2zUD+Yh98KC3CNBJlA8h/E8wNcw7afOeKplE9aSv kpfGHUh4g==; Received: from mx1.redhat.com ([209.132.183.28]) by merlin.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckqwN-0005GP-VR for linux-arm-kernel@lists.infradead.org; Mon, 06 Mar 2017 11:36:36 +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 726AC6196E; Mon, 6 Mar 2017 11:35:56 +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 v26BYbnh002618; Mon, 6 Mar 2017 06:35:51 -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 18/19] KVM: arm64: ITS: Device table save/restore Date: Mon, 6 Mar 2017 12:34:33 +0100 Message-Id: <1488800074-21991-19-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.38]); Mon, 06 Mar 2017 11:35:56 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170306_063636_171093_585C1BA4 X-CRM114-Status: GOOD ( 20.33 ) 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 This patch flushes the device table entries into guest RAM. Both flat table and 2 stage tables are supported. DeviceId indexing is used. For each device listed in the device table, we also flush the translation table using the vgic_its_flush/restore_itt routines. On restore, devices are re-allocated and their itte are re-built. Signed-off-by: Eric Auger --- v2 -> v3: - fix itt_addr bitmask in vgic_its_restore_dte - addition of return 0 in vgic_its_restore_ite moved to the ITE related patch v1 -> v2: - use 8 byte format for DTE and ITE - support 2 stage format - remove kvm parameter - ITT flush/restore moved in a separate patch - use deviceid indexing --- virt/kvm/arm/vgic/vgic-its.c | 144 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 142 insertions(+), 2 deletions(-) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index a216849..27ebabd 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1849,12 +1849,137 @@ static int vgic_its_restore_itt(struct vgic_its *its, } /** + * vgic_its_flush_dte - Flush a device table entry at a given GPA + * + * @its: ITS handle + * @dev: ITS device + * @ptr: GPA + */ +static int vgic_its_flush_dte(struct vgic_its *its, + struct its_device *dev, gpa_t ptr) +{ + struct kvm *kvm = its->dev->kvm; + u64 val, itt_addr_field; + int ret; + u32 next_offset; + + itt_addr_field = dev->itt_addr >> 8; + next_offset = compute_next_devid_offset(&its->device_list, dev); + val = (((u64)next_offset << 45) | (itt_addr_field << 5) | + (dev->nb_eventid_bits - 1)); + val = cpu_to_le64(val); + ret = kvm_write_guest(kvm, ptr, &val, 8); + return ret; +} + +/** + * vgic_its_restore_dte - restore a device table entry + * + * @its: its handle + * @id: device id the DTE corresponds to + * @ptr: kernel VA where the 8 byte DTE is located + * @opaque: unused + * @next: offset to the next valid device id + * + * Return: < 0 on error, 0 otherwise + */ +static int vgic_its_restore_dte(struct vgic_its *its, u32 id, + void *ptr, void *opaque, u32 *next) +{ + struct its_device *dev; + gpa_t itt_addr; + size_t size; + u64 val, *p = (u64 *)ptr; + int ret; + + val = *p; + val = le64_to_cpu(val); + + size = val & GENMASK_ULL(4, 0); + itt_addr = (val & GENMASK_ULL(44, 5)) >> 5; + *next = 1; + + if (!itt_addr) + return 0; + + /* dte entry is valid */ + *next = (val & GENMASK_ULL(63, 45)) >> 45; + + ret = vgic_its_alloc_device(its, &dev, id, + itt_addr, size); + if (ret) + return ret; + ret = vgic_its_restore_itt(its, dev); + + return ret; +} + +/** * vgic_its_flush_device_tables - flush the device table and all ITT * into guest RAM */ static int vgic_its_flush_device_tables(struct vgic_its *its) { - return -ENXIO; + struct its_device *dev; + u64 baser; + + baser = its->baser_device_table; + + list_for_each_entry(dev, &its->device_list, dev_list) { + int ret; + gpa_t eaddr; + + if (!vgic_its_check_id(its, baser, + dev->device_id, &eaddr)) + return -EINVAL; + + ret = vgic_its_flush_itt(its, dev); + if (ret) + return ret; + + ret = vgic_its_flush_dte(its, dev, eaddr); + if (ret) + return ret; + } + return 0; +} + +/** + * handle_l1_entry - callback used for L1 entries (2 stage case) + * + * @its: its handle + * @id: id + * @addr: kernel VA + * @opaque: unused + * @next_offset: offset to the next L1 entry: 0 if the last element + * was found, 1 otherwise + */ +static int handle_l1_entry(struct vgic_its *its, u32 id, void *addr, + void *opaque, u32 *next_offset) +{ + u64 *pe = addr; + gpa_t gpa; + int l2_start_id = id * (SZ_64K / 8); + int ret; + + *pe = le64_to_cpu(*pe); + *next_offset = 1; + + if (!(*pe & BIT_ULL(63))) + return 0; + + gpa = *pe & GENMASK_ULL(51, 16); + + ret = lookup_table(its, gpa, SZ_64K, 8, + l2_start_id, vgic_its_restore_dte, NULL); + + if (ret == 1) { + /* last entry was found in this L2 table */ + *next_offset = 0; + ret = 0; + } + + return ret; } /** @@ -1863,7 +1988,22 @@ static int vgic_its_flush_device_tables(struct vgic_its *its) */ static int vgic_its_restore_device_tables(struct vgic_its *its) { - return -ENXIO; + u64 baser = its->baser_device_table; + int l1_tbl_size = GITS_BASER_NR_PAGES(baser) * SZ_64K; + int l1_esz = GITS_BASER_ENTRY_SIZE(baser); + gpa_t l1_gpa; + + l1_gpa = BASER_ADDRESS(baser); + if (!l1_gpa) + return 0; + + if (!(baser & GITS_BASER_INDIRECT)) + return lookup_table(its, l1_gpa, l1_tbl_size, l1_esz, + 0, vgic_its_restore_dte, NULL); + + /* two stage table */ + return lookup_table(its, l1_gpa, l1_tbl_size, 8, 0, + handle_l1_entry, NULL); } static int vgic_its_flush_cte(struct vgic_its *its,