From patchwork Mon Mar 6 11:34:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 9605845 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 0AA58602B4 for ; Mon, 6 Mar 2017 11:44:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D709428236 for ; Mon, 6 Mar 2017 11:44:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9D8A28305; Mon, 6 Mar 2017 11:44:40 +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 43AC528236 for ; Mon, 6 Mar 2017 11:44:40 +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=jyLQA9kHbG52AQP3OSCPAqp9ZaXGtCE6g7lbTsvPToM=; b=Qxun1p9qpkl1sYNsvRS3erQUvx 34exlMM+WWlBlF/DKuAvH+hBzO7reNaYdnzYGmHVacd624Fnn53I2FMxFpha/EyBpsBXQTvIkYFE1 BwwYvprzedIOMugtNgkflnUydgPGUdC5ueIW8Xff4PtVSmNDaYDKFGOT3lLvGoxwKWlD8pPPDMaxP TKi3Mtqs/sSsheCQwdUOOZvSqN778u4JoRMgwP38FJWhPA+Pyj2XCHrLTZ+tRPEPZHqsC1FWRnKjF 7eoBFNvRKMbx+B6pYih1NzBCNHUQoI773Mm9TlzrcylNIBMT2t6uvelV3yQNlD2H5wDzCK08nYEMw XL7QbYiQ==; 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 1ckr44-0001Eo-78; Mon, 06 Mar 2017 11:44:32 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckr2g-0000Af-5s for linux-arm-kernel@bombadil.infradead.org; Mon, 06 Mar 2017 11:43:06 +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=CwU3g1HahvNnoBve5Hq1AIFDgnbr5oQxr8mFrm3soAI=; b=U+QzxYyu3GW0SwZwmmYU2Ku5+ NBQEabLsJKIsNojFiMK7WOGyTUIXTbIQdivVwoiPMW76hgdVO2SXp7a5bjCKnNICA4PtGOMskBKWJ 4ahCFa8HOGeX0JoBgiRHQxd6dH/Xo4tv5OYOdG9RydWPqpILQOHYIV11DlYkvl0Uhu+yFJFfhCRg8 cC/I597l+Ny0gR3TnGsd6nhwZofeODek6EjTnwEzJ5tyk8beTkh1qZyPc2dpSAZVMtp0aDUOxHnx1 zOH7/vlBftLpWkf8UqxLxHCztfFIKnJi567EBOYKuLxB1Bb5zeeppv9t8rYl3ZCuqf3rqk+kpqnW5 AHmqOx1YA==; Received: from mx1.redhat.com ([209.132.183.28]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ckqvv-0003Np-FV for linux-arm-kernel@lists.infradead.org; Mon, 06 Mar 2017 11:36:12 +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 3611C42BCC; Mon, 6 Mar 2017 11:35:28 +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 v26BYbna002618; Mon, 6 Mar 2017 06:35:24 -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 11/19] KVM: arm64: ITS: KVM_DEV_ARM_VGIC_GRP_ITS_TABLES group Date: Mon, 6 Mar 2017 12:34:26 +0100 Message-Id: <1488800074-21991-12-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:29 +0000 (UTC) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170306_113607_854886_572CD943 X-CRM114-Status: GOOD ( 21.82 ) 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 Introduce a new group aiming at saving/restoring the ITS tables to/from the guest memory. We hold the its lock during the save and restore to prevent any command from being executed. This also garantees the LPI list is not going to change and no MSI injection can happen during the operation. At this stage the functionality is not yet implemented. Only the skeleton is put in place. Signed-off-by: Eric Auger --- v1 -> v2: - remove useless kvm parameter At the end of the restore I trigger a map_resources. This aims at accomodating the virtio-net-pci guest use case. On restore I can see the virtio-net-pci device sends MSI before the first VCPU run. The fact we are not able to handle MSIs at that stage stalls the virtio-net-pci device. We may fix this issue at QEMU level instead. --- arch/arm/include/uapi/asm/kvm.h | 1 + arch/arm64/include/uapi/asm/kvm.h | 1 + virt/kvm/arm/vgic/vgic-its.c | 115 +++++++++++++++++++++++++++++++++++++- 3 files changed, 116 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h index 4beb83b..7b165e9 100644 --- a/arch/arm/include/uapi/asm/kvm.h +++ b/arch/arm/include/uapi/asm/kvm.h @@ -193,6 +193,7 @@ struct kvm_arch_memory_slot { #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 +#define KVM_DEV_ARM_VGIC_GRP_ITS_TABLES 9 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index 7e8dd69..166df68 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -213,6 +213,7 @@ struct kvm_arch_memory_slot { #define KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS 6 #define KVM_DEV_ARM_VGIC_GRP_LEVEL_INFO 7 #define KVM_DEV_ARM_VGIC_GRP_ITS_REGS 8 +#define KVM_DEV_ARM_VGIC_GRP_ITS_TABLES 9 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT 10 #define KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_MASK \ (0x3fffffULL << KVM_DEV_ARM_VGIC_LINE_LEVEL_INFO_SHIFT) diff --git a/virt/kvm/arm/vgic/vgic-its.c b/virt/kvm/arm/vgic/vgic-its.c index 322e370..dd7545a 100644 --- a/virt/kvm/arm/vgic/vgic-its.c +++ b/virt/kvm/arm/vgic/vgic-its.c @@ -1551,6 +1551,112 @@ int vgic_its_attr_regs_access(struct kvm_device *dev, return 0; } +/** + * vgic_its_flush_pending_tables - Flush the pending tables into guest RAM + */ +static int vgic_its_flush_pending_tables(struct vgic_its *its) +{ + return -ENXIO; +} + +/** + * vgic_its_restore_pending_tables - Restore the pending tables from guest + * RAM to internal data structs + */ +static int vgic_its_restore_pending_tables(struct vgic_its *its) +{ + return -ENXIO; +} + +/** + * 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; +} + +/** + * vgic_its_restore_device_tables - restore the device table and all ITT + * from guest RAM to internal data structs + */ +static int vgic_its_restore_device_tables(struct vgic_its *its) +{ + return -ENXIO; +} + +/** + * 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; +} + +/** + * vgic_its_restore_collection_table - reads the collection table + * in guest memory and restores the ITS internal state. Requires the + * BASER registers to be restored before. + */ +static int vgic_its_restore_collection_table(struct vgic_its *its) +{ + return -ENXIO; +} + +/** + * vgic_its_table_flush - Flush all the tables into guest RAM + */ +static int vgic_its_table_flush(struct vgic_its *its) +{ + int ret; + + mutex_lock(&its->its_lock); + + ret = vgic_its_flush_pending_tables(its); + if (ret) + goto out; + ret = vgic_its_flush_device_tables(its); + if (ret) + goto out; + + ret = vgic_its_flush_collection_table(its); +out: + mutex_unlock(&its->its_lock); + return ret; +} + +/** + * vgic_its_table_restore - Restore all tables from guest RAM to internal + * data structs + */ +static int vgic_its_table_restore(struct vgic_its *its) +{ + int ret; + + mutex_lock(&its->its_lock); + ret = vgic_its_restore_collection_table(its); + if (ret) + goto out; + + ret = vgic_its_restore_device_tables(its); + if (ret) + goto out; + + ret = vgic_its_restore_pending_tables(its); +out: + mutex_unlock(&its->its_lock); + + /** + * In real use case we observe MSI injection before + * the first CPU run. This is likely to stall virtio-net-pci + * for instance + */ + ret = kvm_vgic_map_resources(its->dev->kvm); + return ret; +} + static int vgic_its_has_attr(struct kvm_device *dev, struct kvm_device_attr *attr) { @@ -1569,6 +1675,8 @@ static int vgic_its_has_attr(struct kvm_device *dev, break; case KVM_DEV_ARM_VGIC_GRP_ITS_REGS: return vgic_its_has_attr_regs(dev, attr); + case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES: + return 0; } return -ENXIO; } @@ -1617,6 +1725,8 @@ static int vgic_its_set_attr(struct kvm_device *dev, return vgic_its_attr_regs_access(dev, attr, ®, true); } + case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES: + return vgic_its_table_restore(its); } return -ENXIO; } @@ -1624,9 +1734,10 @@ static int vgic_its_set_attr(struct kvm_device *dev, static int vgic_its_get_attr(struct kvm_device *dev, struct kvm_device_attr *attr) { + struct vgic_its *its = dev->private; + switch (attr->group) { case KVM_DEV_ARM_VGIC_GRP_ADDR: { - struct vgic_its *its = dev->private; u64 addr = its->vgic_its_base; u64 __user *uaddr = (u64 __user *)(long)attr->addr; unsigned long type = (unsigned long)attr->attr; @@ -1647,6 +1758,8 @@ static int vgic_its_get_attr(struct kvm_device *dev, if (ret) return ret; return put_user(reg, uaddr); + case KVM_DEV_ARM_VGIC_GRP_ITS_TABLES: + return vgic_its_table_flush(its); } default: return -ENXIO;