From patchwork Thu Nov 23 18:32:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 119537 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp1173048edl; Thu, 23 Nov 2017 10:34:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMbpKKBv7/mkU/LZi6Hm0Db8miyomUH4Wr4ftTZF0u28o5l4WU1U10CpotyX1ERYbcaJsfEl X-Received: by 10.107.6.81 with SMTP id 78mr28180299iog.204.1511462058548; Thu, 23 Nov 2017 10:34:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511462058; cv=none; d=google.com; s=arc-20160816; b=POJTNLXBh2XgAjEDwMp0UGfLTh7u6HY1+HlXXPnHzKM9m10YMesYqIStBwR29dC2nd H8Ida4zES3ow1nyqTn+U+JdKjBRE+o78oWaRJaPGXncQrlsxmOaf36zeXgIqwkVMJCV3 /yyWD6uah9qx5/oTBYolMHGEr0d1nhcXp642oZII61T+qHg7smrXRDgz0BUfkNe2nSNT FkiSua4Oq2T2DBqbBssj5euT590Gee2WliQ3Oh1avO2+DeY3v8P1s5sTEo0C9z5uZCla E1eMbrUZ1u8QHv3s2WAyfkVCou7YwUivEz9kx3jcBVCrmwlxWi+Wt4GvcAaX+XDZZTOM vORw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=uVSxMaT4MupCfzfA7UCFQxE799q9MjPSvEpxktaITSE=; b=kRXRZKXZUNzJA2mIUzUVFVXicoxELGi0A+rCQYvxCNcj6QXbHEFG97/2HmHEPWESe1 z4oA9V++elvWcX+CQE8VoQMyY1PMV0zrVYwgMYsR0nl7HHGHFfNcIgK3VBg8zWuebE83 ykyLltVvajMYZWhYmEqzGZ5dQ7i1Tq/SrF8DegrnXpHpVOp68+gZc0h1eOHF/6Wvbplg Cg8sQQjcZ6nqPTZExbYAbCwfnjOtMRN4MQfO00ZOH5OuSYQNlg+O5seIEIciowxwh+aO 6ej/YfvD4Cu+hrjWd3zUPx5cuIXlN4YTUIIdKLoq1wpcKEE14o8TzqfdWmis3v3Q4MEF +ALg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=V+6Ou5gj; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id v86si13338879iov.15.2017.11.23.10.34.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 10:34:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=V+6Ou5gj; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHwIS-0005E4-GV; Thu, 23 Nov 2017 18:32:24 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHwIQ-0005BD-TM for xen-devel@lists.xen.org; Thu, 23 Nov 2017 18:32:22 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id DA/38-16045-634171A5; Thu, 23 Nov 2017 18:32:22 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrCIsWRWlGSWpSXmKPExsXiVRvkqGsqIh5 l0DtVw2LJx8UsDoweR3f/ZgpgjGLNzEvKr0hgzZhwdy1jwQWNihfHv7E3MB6T7WLk4hASmMQo Mbn9ACuIwyIwj1li2vKJbF2MnBwSAv2sEv9XCUHYeRLtPedZIew0iUNXNjF1MXIA2RUSnfdTQ UwhATWJNW+iIGb2MUk8Wj6VGSTOJqAjsW5GLUiniIC0xLXPlxlBbGaBeInHU6+DbRIWyJf4+6 ofbDqLgKrEyQ+t7CA2r4CNRHfbDhaIrfISu9ougtVwCthKHD3wgRlirY3E58+KExgFFzAyrGL UKE4tKkst0jU000sqykzPKMlNzMzRNTQw08tNLS5OTE/NSUwq1kvOz93ECAw1BiDYwXh/Y8Ah RkkOJiVRXplfYlFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHhvColHCQkWpaanVqRl5gCDHiYtw cGjJMK7HSTNW1yQmFucmQ6ROsVoybFvz60/TBzPZr5uYOaYdrW1iVmIJS8/L1VKnNdTGKhBAK QhozQPbhwsMi8xykoJ8zICHSjEU5BalJtZgir/ilGcg1FJmPctyFqezLwSuK2vgA5iAjro53F hkINKEhFSUg2MIsEVxj9DOT+fncSUGLiA6ZfwXc0Zsy6Y1BVwmG12FNVcIMzAP/ugwtflISF6 M+sfCt8+fT7WPbTf4BzH5N//f1QwHr0SzTnTQ+K5aX9DVsRPjjqb+KWSFQpzPqjN0RJ5oXL70 aUFU07WHDDnkW7dwD9/V8eZCRl/lG8kh9+NUp1jlfox40ukEktxRqKhFnNRcSIAFn7Q7scCAA A= X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-9.tower-21.messagelabs.com!1511461941!83248014!1 X-Originating-IP: [74.125.82.65] 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 40148 invoked from network); 23 Nov 2017 18:32:21 -0000 Received: from mail-wm0-f65.google.com (HELO mail-wm0-f65.google.com) (74.125.82.65) by server-9.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 23 Nov 2017 18:32:21 -0000 Received: by mail-wm0-f65.google.com with SMTP id g130so18043590wme.0 for ; Thu, 23 Nov 2017 10:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=uN9SPlsMnyA58zYTd8x8DOAsv2jQYD12n8QFkobcRKs=; b=V+6Ou5gjcEkBRA6jDKdeQkeoC8KZ26NB3Vc31xx6BGR4OjvqZL7iT8EEE4SInRQhRA 7cs/QfXXG5mup99C9SH8bgeCRQ0Xv6C5NjeupNifMNWXa0jyFJyjnRbsj+ES5zDyK4kb ICKQ9+90GUVpTxODHGfhKxxCIX6X3ejBAG2I4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=uN9SPlsMnyA58zYTd8x8DOAsv2jQYD12n8QFkobcRKs=; b=bzx/F/sWNYNe+hPHcjlOHANVergsAmN4riEWiMdt9ZgcQO7076i20naEG+EfBTLTnq n+XZiv9i4tUDX35JGOujO99TN2qHCgV69hsJ61zxHbV/BYiri6jz0GaWkccKxuOc4P1H Ofpyv8J7aYlRQIgmNkr3dXLJheRgb1rqYFA8omPkGBiW9U90rYVjbC0esWxUKUR4Lz5P eI4D5Qap/L5eVC0OIcpHGg6Iy4RWDrWPSoBeRd3q/H0rVQcKiTGtDmwENuozTk8CnCh1 lmVAmcOjkB6K01fvDM8iJGTulDsS3x4hxwoNvcudnJnx+V0oW+x2QNc8g3ProuCJHXru pKlw== X-Gm-Message-State: AJaThX7LOkEo9cavejxRfQXSLZoNvIlZlStCEI8LWO3UXqoSCE7Nec2M yvSKQWgUqUVUaqWigZcNJTLdDjFr4bQ= X-Received: by 10.28.168.88 with SMTP id r85mr8624231wme.63.1511461940994; Thu, 23 Nov 2017 10:32:20 -0800 (PST) Received: from e108454-lin.cambridge.arm.com ([2001:41d0:1:6c23::1]) by smtp.gmail.com with ESMTPSA id n32sm41412950wrb.62.2017.11.23.10.32.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 10:32:20 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 23 Nov 2017 18:32:00 +0000 Message-Id: <20171123183210.12045-7-julien.grall@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171123183210.12045-1-julien.grall@linaro.org> References: <20171123183210.12045-1-julien.grall@linaro.org> Cc: sstabellini@kernel.org, Julien Grall , andre.przywara@linaro.org Subject: [Xen-devel] [PATCH for-next 06/16] xen/arm: Extend copy_to_guest to support copying from/to guest physical address X-BeenThere: xen-devel@lists.xenproject.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.xenproject.org Sender: "Xen-devel" The only differences between copy_to_guest and access_guest_memory_by_ipa are: - The latter does not support copying data crossing page boundary - The former is copying from/to guest VA whilst the latter from guest PA copy_to_guest can easily be extended to support copying from/to guest physical address. For that a new bit is used to tell whether linear address or ipa is been used. Lastly access_guest_memory_by_ipa is reimplemented using copy_to_guest. This also has the benefits to extend the use of it, it is now possible to copy data crossing page boundary. Signed-off-by: Julien Grall --- xen/arch/arm/guestcopy.c | 86 ++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 47 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 487f5ab82d..be53bee559 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -8,6 +8,31 @@ #define COPY_flush_dcache (1U << 0) #define COPY_from_guest (0U << 1) #define COPY_to_guest (1U << 1) +#define COPY_ipa (0U << 2) +#define COPY_linear (1U << 2) + +static struct page_info *translate_get_page(struct vcpu *v, paddr_t addr, + bool linear, bool write) +{ + p2m_type_t p2mt; + struct page_info *page; + + if ( linear ) + return get_page_from_gva(v, addr, write ? GV2M_WRITE : GV2M_READ); + + page = get_page_from_gfn(v->domain, paddr_to_pfn(addr), &p2mt, P2M_ALLOC); + + if ( !page ) + return NULL; + + if ( !p2m_is_ram(p2mt) ) + { + put_page(page); + return NULL; + } + + return page; +} static unsigned long copy_guest(void *buf, paddr_t addr, unsigned int len, struct vcpu *v, unsigned int flags) @@ -21,8 +46,8 @@ static unsigned long copy_guest(void *buf, paddr_t addr, unsigned int len, unsigned size = min(len, (unsigned)PAGE_SIZE - offset); struct page_info *page; - page = get_page_from_gva(v, addr, - (flags & COPY_to_guest) ? GV2M_WRITE : GV2M_READ); + page = translate_get_page(v, addr, flags & COPY_linear, + flags & COPY_to_guest); if ( page == NULL ) return len; @@ -63,73 +88,40 @@ static unsigned long copy_guest(void *buf, paddr_t addr, unsigned int len, unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len) { return copy_guest((void *)from, (unsigned long)to, len, - current, COPY_to_guest); + current, COPY_to_guest | COPY_linear); } unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from, unsigned len) { return copy_guest((void *)from, (unsigned long)to, len, - current, COPY_to_guest | COPY_flush_dcache); + current, COPY_to_guest | COPY_flush_dcache | COPY_linear); } unsigned long raw_clear_guest(void *to, unsigned len) { - return copy_guest(NULL, (unsigned long)to, len, current, COPY_to_guest); + return copy_guest(NULL, (unsigned long)to, len, current, + COPY_to_guest | COPY_linear); } unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned len) { - return copy_guest(to, (unsigned long)from, len, current, COPY_from_guest); + return copy_guest(to, (unsigned long)from, len, current, + COPY_from_guest | COPY_linear); } -/* - * Temporarily map one physical guest page and copy data to or from it. - * The data to be copied cannot cross a page boundary. - */ int access_guest_memory_by_ipa(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: guestcopy: memory access crosses 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: guestcopy: 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: guestcopy: guest memory should be RAM.\n", - d->domain_id); - return -EINVAL; - } + unsigned long left; + int flags = COPY_ipa; - p = __map_domain_page(page); + flags |= is_write ? COPY_to_guest : COPY_from_guest; - if ( is_write ) - memcpy(p + offset, buf, size); - else - memcpy(buf, p + offset, size); + /* P2M is shared between all vCPUs, so the vcpu used does not matter. */ + left = copy_guest(buf, gpa, size, d->vcpu[0], flags); - unmap_domain_page(p); - put_page(page); - - return 0; + return (!left) ? 0 : -EINVAL; } /*