From patchwork Fri Jun 9 17:41:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9778981 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 13B3560318 for ; Fri, 9 Jun 2017 17:43:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00304286E0 for ; Fri, 9 Jun 2017 17:43:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9283286E7; Fri, 9 Jun 2017 17:43:50 +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 745B2286E2 for ; Fri, 9 Jun 2017 17:43:49 +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 1dJNvC-0003kr-E0; Fri, 09 Jun 2017 17:42:06 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJNvB-0003id-P8 for xen-devel@lists.xenproject.org; Fri, 09 Jun 2017 17:42:05 +0000 Received: from [193.109.254.147] by server-3.bemta-6.messagelabs.com id BE/20-03058-DEDDA395; Fri, 09 Jun 2017 17:42:05 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTffNXat Ig4mb5Sy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyP936xFbyQqDjX+papgfGkcBcjF4eQwGZG iW/3O9khnOWMEnf2/QFyODnYBHQldtx8zQxiiwiESjxd8J0ZpIhZ4DqjxOkd89lAEsICLhLv5 /9gBbFZBFQl7h6/BNTMwcErYC0x74QrSFhCQE6i4fx9sDmcQOFte9aCtQoJWEm0HLrMPoGRew EjwypGjeLUorLUIl1jI72kosz0jJLcxMwcXUMDM73c1OLixPTUnMSkYr3k/NxNjEAPMwDBDsb T6wIPMUpyMCmJ8k4rsIoU4kvKT6nMSCzOiC8qzUktPsQow8GhJMHbcwcoJ1iUmp5akZaZAww1 mLQEB4+SCO+Lk0Bp3uKCxNzizHSI1ClGRSlxXkuQPgGQREZpHlwbLLwvMcpKCfMyAh0ixFOQW pSbWYIq/4pRnINRSZh3F8gUnsy8Erjpr4AWMwEtXvLOAmRxSSJCSqqB0fSf7uJz/F5/1CQfHz b2d5mw4c+Rj7Vf5k78cbV358vsphL5wMRH2wNUIp680H/iqnBZWW/V6/2qS02jfixjkU+aElH QPTGzwDrgZfrW/QfKm7W5vs4VmKd77fhfpYU9F+adj+6MWKUZvfB76ZzVDLJ7/Scemncl96vJ iZL6RQu+6Iv8//ar9JwSS3FGoqEWc1FxIgAk1PF3agIAAA== X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-7.tower-27.messagelabs.com!1497030124!102356273!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 2711 invoked from network); 9 Jun 2017 17:42:04 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-7.tower-27.messagelabs.com with SMTP; 9 Jun 2017 17:42:04 -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 BE0DA1596; Fri, 9 Jun 2017 10:42:03 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 753433F578; Fri, 9 Jun 2017 10:42:02 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Fri, 9 Jun 2017 18:41:23 +0100 Message-Id: <20170609174141.5068-17-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170609174141.5068-1-andre.przywara@arm.com> References: <20170609174141.5068-1-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Vijaya Kumar K , Vijay Kilari , Shanker Donthineni , Manish Jaggi Subject: [Xen-devel] [PATCH v11 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 546f412..9bfe8cb 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -637,6 +638,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 07b56dc..02732db 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -315,6 +315,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,