From patchwork Wed Jun 14 16:52:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9786931 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 83B4560325 for ; Wed, 14 Jun 2017 16:54:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 758051FF15 for ; Wed, 14 Jun 2017 16:54:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A42E28618; Wed, 14 Jun 2017 16:54: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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4F7871FF15 for ; Wed, 14 Jun 2017 16:54:19 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLBX8-0006f2-B1; Wed, 14 Jun 2017 16:52:42 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dLBX7-0006dA-3e for xen-devel@lists.xenproject.org; Wed, 14 Jun 2017 16:52:41 +0000 Received: from [85.158.137.68] by server-3.bemta-3.messagelabs.com id 67/98-01985-8D961495; Wed, 14 Jun 2017 16:52:40 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsVysyfVTfd6pmO kQUevscX3LZOZHBg9Dn+4whLAGMWamZeUX5HAmvH2/0TmghcSFY/nfWNvYDwp3MXIySEksJlR 4vOPcAh7OaPE1N9OIDabgK7EjpuvmUFsEYFQiacLvgPZXBzMAtcZJU7vmM8GkhAWcJGYte8pC 4jNIqAq8a/nAyOIzStgLbFmz1p2EFtCQE6i4fx9sEGcQPGp2yczdTFyAC2zkri5Qn8CI/cCRo ZVjOrFqUVlqUW65npJRZnpGSW5iZk5uoYGxnq5qcXFiempOYlJxXrJ+bmbGIG+ZQCCHYyN350 OMUpyMCmJ8k4VdIwU4kvKT6nMSCzOiC8qzUktPsQow8GhJMF7OAMoJ1iUmp5akZaZAwwymLQE B4+SCO/WVKA0b3FBYm5xZjpE6hSjopQ471mQPgGQREZpHlwbLLAvMcpKCfMyAh0ixFOQWpSbW YIq/4pRnINRSZi3LB1oCk9mXgnc9FdAi5mAFgddcABZXJKIkJJqYIwqfmq95v58ndV8P1y7Jx Y8aZm8WaZC69+Bx5GzQ7/OPfcpPva1+dtFqYk+QUKPXYPVuY6/XnV5tX6sl8G3Nwu3CXPZxV4 zte9rtFq31PLzyRPpXz9UHVuqxMPfMCextOJuyrsbh4rmyGT/DlVpWhqQsMfsVkTOd6W1pbcv XV93sbfn8asILSslluKMREMt5qLiRADUR3pGZwIAAA== X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-10.tower-31.messagelabs.com!1497459159!104963761!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 29527 invoked from network); 14 Jun 2017 16:52:39 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-10.tower-31.messagelabs.com with SMTP; 14 Jun 2017 16:52:39 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0DB4815A2; Wed, 14 Jun 2017 09:52:39 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B32363F3E1; Wed, 14 Jun 2017 09:52:37 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Wed, 14 Jun 2017 17:52:05 +0100 Message-Id: <20170614165223.7543-17-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170614165223.7543-1-andre.przywara@arm.com> References: <20170614165223.7543-1-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Vijaya Kumar K , Vijay Kilari , Shanker Donthineni , Manish Jaggi Subject: [Xen-devel] [PATCH v12 16/34] ARM: introduce vgic_access_guest_memory() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Vijaya Kumar K This function allows to copy a chunk of data from and to guest physical memory. It looks up the associated page from the guest's p2m tree and maps this page temporarily for the time of the access. This function was originally written by Vijaya as part of an earlier series: https://patchwork.kernel.org/patch/8177251 Signed-off-by: Vijaya Kumar K Signed-off-by: Andre Przywara Reviewed-by: Julien Grall --- xen/arch/arm/vgic.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vgic.h | 3 +++ 2 files changed, 53 insertions(+) diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index c097bd4..789c58b 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -636,6 +637,55 @@ void vgic_free_virq(struct domain *d, unsigned int virq) } /* + * Temporarily map one physical guest page and copy data to or from it. + * The data to be copied cannot cross a page boundary. + */ +int vgic_access_guest_memory(struct domain *d, paddr_t gpa, void *buf, + uint32_t size, bool is_write) +{ + struct page_info *page; + uint64_t offset = gpa & ~PAGE_MASK; /* Offset within the mapped page */ + p2m_type_t p2mt; + void *p; + + /* Do not cross a page boundary. */ + if ( size > (PAGE_SIZE - offset) ) + { + printk(XENLOG_G_ERR "d%d: vITS: memory access would cross page boundary\n", + d->domain_id); + return -EINVAL; + } + + page = get_page_from_gfn(d, paddr_to_pfn(gpa), &p2mt, P2M_ALLOC); + if ( !page ) + { + printk(XENLOG_G_ERR "d%d: vITS: Failed to get table entry\n", + d->domain_id); + return -EINVAL; + } + + if ( !p2m_is_ram(p2mt) ) + { + put_page(page); + printk(XENLOG_G_ERR "d%d: vITS: memory used by the ITS should be RAM.", + d->domain_id); + return -EINVAL; + } + + p = __map_domain_page(page); + + if ( is_write ) + memcpy(p + offset, buf, size); + else + memcpy(buf, p + offset, size); + + unmap_domain_page(p); + put_page(page); + + return 0; +} + +/* * Local variables: * mode: C * c-file-style: "BSD" diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index 33b2fb5..6a23249 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -320,6 +320,9 @@ extern void register_vgic_ops(struct domain *d, const struct vgic_ops *ops); int vgic_v2_init(struct domain *d, int *mmio_count); int vgic_v3_init(struct domain *d, int *mmio_count); +int vgic_access_guest_memory(struct domain *d, paddr_t gpa, void *buf, + uint32_t size, bool_t is_write); + extern int domain_vgic_register(struct domain *d, int *mmio_count); extern int vcpu_vgic_free(struct vcpu *v); extern bool vgic_to_sgi(struct vcpu *v, register_t sgir,