From patchwork Thu May 11 17:53:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9722673 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 E51BD60236 for ; Thu, 11 May 2017 17:54:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E4B14286D0 for ; Thu, 11 May 2017 17:54:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D991B286E5; Thu, 11 May 2017 17:54:06 +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 6EC0D286D9 for ; Thu, 11 May 2017 17:54:06 +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 1d8sFW-0000Nn-Qs; Thu, 11 May 2017 17:51:38 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d8sFV-0000Lb-Ip for xen-devel@lists.xenproject.org; Thu, 11 May 2017 17:51:37 +0000 Received: from [193.109.254.147] by server-8.bemta-6.messagelabs.com id 65/D3-03696-8A4A4195; Thu, 11 May 2017 17:51:36 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTXfFEpF Ig91/FC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyLM7+wFeyUqLj0/jprA+M84S5GTg4hgc2M EhfvVHYxcgHZyxklHnxZywaSYBPQldhx8zUziC0iECrxdMF3ZpAiZoE1jBLnFv0EKxIWcJaYe e8bK4jNIqAqse/dKrAGXgEriVN7Z4LVSAjISTScvw8W5xSwllgyfRYLxGYriV27T7NOYORewM iwilGjOLWoLLVI19BCL6koMz2jJDcxM0fX0MBMLze1uDgxPTUnMalYLzk/dxMj0MMMQLCD8eb GgEOMkhxMSqK8jBNFIoX4kvJTKjMSizPii0pzUosPMcpwcChJ8EYuBsoJFqWmp1akZeYAQw0m LcHBoyTCex8kzVtckJhbnJkOkTrFqCglztsOkhAASWSU5sG1wcL7EqOslDAvI9AhQjwFqUW5m SWo8q8YxTkYlYR5d4JM4cnMK4Gb/gpoMRPQ4v4/wiCLSxIRUlINjA3ZaxfqGMY/k4jY/DnR/u U6oeY7h6uE70vMT78p5XlA67Go6u/jDOf8jy0SuDl5l8RxhciPkTMXeFg56U3/JMQTzLvP1Lt A+4/KO8dHOoVn/ULEZTy6im9/C9M0kFfc8H6r+xZh4xtKx3a3vWK0quPz65ea09hpd7d61pV0 rr0Wl5ZzKfPmKrEUZyQaajEXFScCAJEs3z9qAgAA X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-16.tower-27.messagelabs.com!1494525096!101336686!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.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 58070 invoked from network); 11 May 2017 17:51:36 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-16.tower-27.messagelabs.com with SMTP; 11 May 2017 17:51:36 -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 D2D3816A3; Thu, 11 May 2017 10:51:35 -0700 (PDT) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id AD0E73F4FF; Thu, 11 May 2017 10:51:34 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Thu, 11 May 2017 18:53:20 +0100 Message-Id: <20170511175340.8448-9-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170511175340.8448-1-andre.przywara@arm.com> References: <20170511175340.8448-1-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Vijaya Kumar K , Vijay Kilari , Shanker Donthineni Subject: [Xen-devel] [PATCH v9 08/28] 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 c29ad5e..66adeb4 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -620,6 +621,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_t 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 7efa164..6b17802 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -313,6 +313,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,