From patchwork Wed Apr 12 00:44:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9676291 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 6D0F360383 for ; Wed, 12 Apr 2017 00:49:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53BAC2856B for ; Wed, 12 Apr 2017 00:49:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 481C72857B; Wed, 12 Apr 2017 00:49:04 +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 A7BC428587 for ; Wed, 12 Apr 2017 00:49:03 +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 1cy6QO-0000Ts-GI; Wed, 12 Apr 2017 00:46:20 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cy6QM-0000RY-Fa for xen-devel@lists.xenproject.org; Wed, 12 Apr 2017 00:46:18 +0000 Received: from [85.158.137.68] by server-13.bemta-3.messagelabs.com id 91/8E-05091-9D87DE85; Wed, 12 Apr 2017 00:46:17 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTfdmxds IgzczRCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1owF63pZChokKv4+PMPawPhIqIuRi0NIYBOj xIxl/UwQzl5GidlnZ7J0MXJysAnoSuy4+ZoZxBYRCJWY8/MRM0gRs8AaRon2T09ZQRLCAs4S3 VNXs4PYLAKqEpv/7wazeQXcJFp2/gKaysEhISAnceVfAkiYU8BdYvvuiWCtQkAlW6ctZp7AyL 2AkWEVo0ZxalFZapGukYFeUlFmekZJbmJmjq6hgbFebmpxcWJ6ak5iUrFecn7uJkagh+sZGBh 3MDaf8DvEKMnBpCTKe1nhbYQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd5r5UA5waLU9NSKtMwc YKjBpCU4eJREeBVB0rzFBYm5xZnpEKlTjIpS4rz3QBICIImM0jy4Nlh4X2KUlRLmZWRgYBDiK Ugtys0sQZV/xSjOwagkzDsTZApPZl4J3PRXQIuZgBaf2fUSZHFJIkJKqoFR99qfg0VbWbd5rd x0tiWrckXe/c+XNr++xHT/oec5P17Ro+/KOP9MzOoXlK615e2aLuxtxfCmqcpkuf2HB93iAZK rTq11fegav91xxZEYT8kV7zp9CwRYeh/Wv7snL/ihY1ki++NrM07bPJ/drCguFLYrnO3c94+7 JCfd/pKwiofz8pO1GQIvlFiKMxINtZiLihMBwH6pB2oCAAA= X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-16.tower-31.messagelabs.com!1491957976!87772397!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 57320 invoked from network); 12 Apr 2017 00:46:17 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-16.tower-31.messagelabs.com with SMTP; 12 Apr 2017 00:46:17 -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 867E8CFC; Tue, 11 Apr 2017 17:46:16 -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 E62253F575; Tue, 11 Apr 2017 17:46:14 -0700 (PDT) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Wed, 12 Apr 2017 01:44:15 +0100 Message-Id: <1491957874-31600-9-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1491957874-31600-1-git-send-email-andre.przywara@arm.com> References: <1491957874-31600-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 v8 08/27] 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 | 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 b6fe34f..e385b43 100644 --- a/xen/arch/arm/vgic.c +++ b/xen/arch/arm/vgic.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -602,6 +603,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; + p2m_type_t p2mt; + int ret = 0; + 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) ) + { + if ( is_write ) + memcpy(p + offset, buf, size); + else + memcpy(buf, p + offset, size); + } + else + ret = -ENOSPC; + + unmap_domain_page(p); + put_page(page); + + return ret; +} + +/* * 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,