From patchwork Fri Apr 7 22:08:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9670569 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 1EB58602A0 for ; Fri, 7 Apr 2017 22:12:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 104C82860E for ; Fri, 7 Apr 2017 22:12:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04DD628663; Fri, 7 Apr 2017 22:12:28 +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 5061A2860E for ; Fri, 7 Apr 2017 22:12:27 +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 1cwc5H-0000JK-TH; Fri, 07 Apr 2017 22:10:23 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cwc5G-0000G6-Rp for xen-devel@lists.xenproject.org; Fri, 07 Apr 2017 22:10:22 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id 0A/35-02138-E4E08E85; Fri, 07 Apr 2017 22:10:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRWlGSWpSXmKPExsVysyfVTdeL70W EwcJduhbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8b9SbfZCi6KV7Qd2M3WwHhdqIuRi0NIYBOj xJ5zrxkhnL2MEn9m/WHuYuTkYBPQldhx8zWYLSIQKjHn5yNmkCJmgTWMEu2fnrJ2MXJwCAs4S 7T81gSpYRFQlbj2dCE7iM0r4C7xZsV3NpASCQE5iSv/EkDCnEDhQ1OWsYHYQgJuEjfaV7FMYO RewMiwilGjOLWoLLVI19BIL6koMz2jJDcxM0fX0MBULze1uDgxPTUnMalYLzk/dxMj0L8MQLC DsW+W8yFGSQ4mJVFeBZ8nEUJ8SfkplRmJxRnxRaU5qcWHGGU4OJQkeN/zvIgQEixKTU+tSMvM AQYaTFqCg0dJhDcRJM1bXJCYW5yZDpE6xagoJc4byAuUEABJZJTmwbXBgvsSo6yUMC8j0CFCP AWpRbmZJajyrxjFORiVhHlFQKbwZOaVwE1/BbSYCWixz62nIItLEhFSUg2MFs8jUrafbO6awv uk6t8yNhf9bS8KXC/emJTcISvB68+uMulOa9rralNmuysKFZoruJ9dyyte/+Nu9Ta/nDrGCuu t6mI/tbdPXhBR8/HYZ8G7e1+nXS23/bLkV8P9ig0bA4oKzxtxFd57wWV34Hb+w78Fn4XZ12pL ZAt/vmch3L1PKzRGRfmrEktxRqKhFnNRcSIAokJnQmkCAAA= X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-9.tower-206.messagelabs.com!1491603018!92612873!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 13751 invoked from network); 7 Apr 2017 22:10:18 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-9.tower-206.messagelabs.com with SMTP; 7 Apr 2017 22:10:18 -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 F03F280D; Fri, 7 Apr 2017 15:10:17 -0700 (PDT) Received: from slackpad.lan (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5D4743F3E1; Fri, 7 Apr 2017 15:10:16 -0700 (PDT) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Fri, 7 Apr 2017 23:08:07 +0100 Message-Id: <1491602906-10587-16-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1491602906-10587-1-git-send-email-andre.przywara@arm.com> References: <1491602906-10587-1-git-send-email-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Vijaya Kumar K , Vijay Kilari , Shanker Donthineni Subject: [Xen-devel] [PATCH v7 15/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 --- xen/arch/arm/vgic.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/vgic.h | 3 +++ 2 files changed, 50 insertions(+) diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index e6c97b2..5c68fe7 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -598,6 +599,52 @@ 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; + p2m_type_t p2mt; + void *p; + + 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); + /* Offset within the mapped page */ + offset = gpa & ~PAGE_MASK; + /* Do not cross a page boundary. */ + if ( size > (PAGE_SIZE - offset) ) + size = PAGE_SIZE - offset; + + 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 b43bd95..6cab6ca 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,