From patchwork Wed Aug 9 08:20:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergej Proskurin X-Patchwork-Id: 9889821 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 2F67660384 for ; Wed, 9 Aug 2017 08:23:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E63928A30 for ; Wed, 9 Aug 2017 08:23:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 133D328A37; Wed, 9 Aug 2017 08:23:33 +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 8D70F28A30 for ; Wed, 9 Aug 2017 08:23:32 +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 1dfMEz-0006NH-Ki; Wed, 09 Aug 2017 08:21:21 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfMEy-0006LV-G8 for xen-devel@lists.xenproject.org; Wed, 09 Aug 2017 08:21:20 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id 10/F7-03937-FF5CA895; Wed, 09 Aug 2017 08:21:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCLMWRWlGSWpSXmKPExsXSPJ+BQ/f/0a5 IgyOTuCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oyWJQ+YCl7oVsy92crUwPhOuYuRi0NIYCOj xOG3FxghnE2MEicX32bvYuTkYBMwkJjyeiUriC0ioCRxb9VkJpAiZoEmRol7jQ/YQBLCAtESH +6AdHNysAioShzZ0cQEYvMKWEts334NbJCEgLzExN5pYDWcAjYSO+5A2EJANdOOnWOewMi9gJ FhFaNGcWpRWWqRrpGxXlJRZnpGSW5iZo6uoYGZXm5qcXFiempOYlKxXnJ+7iZGoI8ZgGAH45/ 5gYcYJTmYlER5N2l3RgrxJeWnVGYkFmfEF5XmpBYfYpTh4FCS4J10pCtSSLAoNT21Ii0zBxhs MGkJDh4lEV41kDRvcUFibnFmOkTqFKMux6sJ/78xCbHk5eelSonzWoAUCYAUZZTmwY2ABf4lR lkpYV5GoKOEeApSi3IzS1DlXzGKczAqCfNygEzhycwrgdv0CugIJqAjInw7QY4oSURISTUwTr rwNE3hyTu9abf+C7loK2gZVDYfPptz/UDYgbe6RhInXzrLPE4LcfCtlfRlcNt7fqGJtUv3lO8 /vu0vErr4sy9knvDPwvUFejfSXtzXv3193bRTSZ1thUWruPYvX3wzUqPjZ19MydK4NZNMDhTe PnHwjq3GoYK4YxUztrXbXBa9dOzvhoOFgkosxRmJhlrMRcWJAHtxRK93AgAA X-Env-Sender: proskurin@sec.in.tum.de X-Msg-Ref: server-8.tower-27.messagelabs.com!1502266878!100076716!1 X-Originating-IP: [131.159.0.8] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 60848 invoked from network); 9 Aug 2017 08:21:19 -0000 Received: from mail-out1.informatik.tu-muenchen.de (HELO mail-out1.informatik.tu-muenchen.de) (131.159.0.8) by server-8.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 9 Aug 2017 08:21:19 -0000 Received: from files.sec.in.tum.de (files.sec.in.tum.de [131.159.50.1]) by services.sec.in.tum.de (Postfix) with ESMTP id 185AA10DD29F3; Wed, 9 Aug 2017 10:21:07 +0200 (CEST) Received: from thanatos.sec.in.tum.de (thanatos.sec.in.tum.de [131.159.50.57]) by files.sec.in.tum.de (Postfix) with ESMTP id 098A51F048; Wed, 9 Aug 2017 10:21:07 +0200 (CEST) From: Sergej Proskurin To: xen-devel@lists.xenproject.org Date: Wed, 9 Aug 2017 10:20:33 +0200 Message-Id: <20170809082038.3236-9-proskurin@sec.in.tum.de> X-Mailer: git-send-email 2.13.3 In-Reply-To: <20170809082038.3236-1-proskurin@sec.in.tum.de> References: <20170809082038.3236-1-proskurin@sec.in.tum.de> Cc: Sergej Proskurin , Julien Grall , Stefano Stabellini Subject: [Xen-devel] [PATCH v8 08/13] arm/guest_access: Move vgic_access_guest_memory to guest_access.h 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 This commit moves the function vgic_access_guest_memory to guestcopy.c and the header asm/guest_access.h. No functional changes are made. Please note that the function will be renamed in the following commit. Signed-off-by: Sergej Proskurin Acked-by: Julien Grall --- Cc: Stefano Stabellini Cc: Julien Grall --- v6: We added this patch to our patch series. v7: Add Acked-by Julien Grall. --- xen/arch/arm/guestcopy.c | 50 ++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic-v3-its.c | 1 + xen/arch/arm/vgic.c | 49 ------------------------------------- xen/include/asm-arm/guest_access.h | 3 +++ xen/include/asm-arm/vgic.h | 3 --- 5 files changed, 54 insertions(+), 52 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 413125f02b..938ffe2668 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -118,6 +118,56 @@ unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned le } return 0; } + +/* + * 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 diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c index 9ef792f479..1af6820cab 100644 --- a/xen/arch/arm/vgic-v3-its.c +++ b/xen/arch/arm/vgic-v3-its.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include diff --git a/xen/arch/arm/vgic.c b/xen/arch/arm/vgic.c index 1e5107b9f8..7a4e3cdc88 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -638,55 +638,6 @@ 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/guest_access.h b/xen/include/asm-arm/guest_access.h index 251e935597..49716501a4 100644 --- a/xen/include/asm-arm/guest_access.h +++ b/xen/include/asm-arm/guest_access.h @@ -10,6 +10,9 @@ unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from, unsigned long raw_copy_from_guest(void *to, const void *from, unsigned len); unsigned long raw_clear_guest(void *to, unsigned len); +int vgic_access_guest_memory(struct domain *d, paddr_t gpa, void *buf, + uint32_t size, bool_t is_write); + #define __raw_copy_to_guest raw_copy_to_guest #define __raw_copy_from_guest raw_copy_from_guest #define __raw_clear_guest raw_clear_guest diff --git a/xen/include/asm-arm/vgic.h b/xen/include/asm-arm/vgic.h index d4ed23df28..e489d0bf21 100644 --- a/xen/include/asm-arm/vgic.h +++ b/xen/include/asm-arm/vgic.h @@ -217,9 +217,6 @@ 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,