From patchwork Thu Nov 23 18:31:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 119536 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp1172988edl; Thu, 23 Nov 2017 10:34:14 -0800 (PST) X-Google-Smtp-Source: AGs4zMar9fVti/NtaE1Q4vN4kYRsHZNriePcW2lfV68o/NAPqtP/GZPIO05c65hEGmJUUOymeHpf X-Received: by 10.107.88.9 with SMTP id m9mr10303821iob.68.1511462054644; Thu, 23 Nov 2017 10:34:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511462054; cv=none; d=google.com; s=arc-20160816; b=Had8wgk5l+wlM98ph4YKdl9slv5zXor38rsQMvCHr5kvCkywX/2xG8/KLVEmmxnU4I VWA9eyUrujcp6MUFdVWWaSvnNqwRE6GG7k6xK4o+NPXmJhC6c9wgM1GXx/DNabGnVGZV c9bL3jhH83V2oUb1y8Zyn1YxJ85UNRDQeHgGQwA/9Y1PfAEs7rIYePLY7KB6T2I48cDH FSiLpx/NHpQgG9J3/XeNH7WFRu1WDvlTzZfyelzyLd5K9azTE/WZ1cQPeUyKfDzxMaSX Jaliuv+CME0ifMuvQIq3QzwDC60+Nx0acA3lYsuG02/TP0/7fvL99kku0Wc8oVEcY404 imig== 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=5/5WYGgDDEllG+8pXC5/4UdBQfPN9XQ1NjdK2qVgPjU=; b=vYYJdrPJKf3soKNW6m/412Wl4vuN2OZwX7iIB3giu2AmRm89JcwYYTJq832/qbUzCB OhivhXWJaCmZzNMOYhH+EvEXYliBL7JVcVgG2/PUtv2uO7oJvp9lUf8KM8cETQfgVvpT xY4V+yVnonSmI2ZSHlSb384egISjlidaxbTx3g8DKnElI0gfRTJWjvUq/nm4t3hSaEO0 jWpH0cD6sYeFdQLxgiVluqzyGCeE0a6OO7xQOaRZsmd6Fg7p65mMp2RArpZQ7XEKGrBf TpNF6gb9pv0ddMFMDL+ETWPzmtMFkjAD91gCmR8J7fOYYAcTiM7kEJOr1Uc1ur5I5hVF L0oQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Ixp7xlwa; 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 a134si846819ita.169.2017.11.23.10.34.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 10:34:14 -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=Ixp7xlwa; 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 1eHwIQ-0005BL-Qv; Thu, 23 Nov 2017 18:32:22 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHwIP-00059o-1b for xen-devel@lists.xen.org; Thu, 23 Nov 2017 18:32:21 +0000 Received: from [85.158.137.68] by server-17.bemta-3.messagelabs.com id 6F/83-13440-334171A5; Thu, 23 Nov 2017 18:32:19 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRWlGSWpSXmKPExsVyMbThkK6xiHi UQcdFToslHxezODB6HN39mymAMYo1My8pvyKBNWP+mgbWgg3SFc87NzI2ME4X6WLk4hASmMQo 0dMwnbmLkZODRWAes0RDnxZIQkKgn1Xi9r5drCAJCYE8iRfzNzJC2GkSJ47uhrKrJE797WXvY uQAmqQmseZNFMTQPiaJdxvXgcXZBHQk1s2oBSkXEZCWuPb5Mlgrs0C8xOOp19lAbGGBTImWSc 3sEDeoSmx60ga2llfARuLT4/XMEKvkJXa1XQSLcwrYShw98IEZYq2NxOfPihMYBRcwMqxi1Ch OLSpLLdI1stBLKspMzyjJTczM0TU0MNbLTS0uTkxPzUlMKtZLzs/dxAgMtnoGBsYdjO0n/A4x SnIwKYnyyvwSixLiS8pPqcxILM6ILyrNSS0+xCjDwaEkwesrLB4lJFiUmp5akZaZAwx7mLQEB 4+SCO92IaA0b3FBYm5xZjpE6hSjPceFO5f+MHEc2HMLSD6b+bqBmWPa1dYmZiGWvPy8VClxXk +QqQIgbRmleXBDYXF6iVFWSpiXkYGBQYinILUoN7MEVf4VozgHo5Iw71uQ5TyZeSVwu18BncU EdNbP48IgZ5UkIqSkGhiL5/kbZxgKOf19Ff76ddjO0OMKgl89Ypb/v7xN4NLTawL9136w+Acl JrhUz/B6J3m/bcdnveBqkWqf7BeMZ+J29sjM79lp2OoX+urkIY++LSdXhd1r6cz1nXvJLDpzc iqLYmINC1PrZKH1isX/bAIzPk/182OSezXN3HXWttctL1/yfpn2rVqJpTgj0VCLuag4EQBo1O KjzgIAAA== X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-7.tower-31.messagelabs.com!1511461938!108759238!1 X-Originating-IP: [209.85.128.194] 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 14343 invoked from network); 23 Nov 2017 18:32:19 -0000 Received: from mail-wr0-f194.google.com (HELO mail-wr0-f194.google.com) (209.85.128.194) by server-7.tower-31.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 23 Nov 2017 18:32:19 -0000 Received: by mail-wr0-f194.google.com with SMTP id k18so13374169wre.1 for ; Thu, 23 Nov 2017 10:32:19 -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=+q3cgWIse653ZY0dMk/l5QdcfE70HHh/XxgLEDBYGrc=; b=Ixp7xlwapDbCUMnVrALKp5NEVQULHA/1zGvuZA0ubVweZbl88tFXSYJTGfyOqaNHdT 9JRsJLIMmDjqjuf9u0WgCxJmEukFGqZUIZBf8kK2BpPLDzfyXHX+emIXtt7j3kjWxrxB XVwcTjFYmQCiZYliCtmTHZMtQkapjc1c85wvs= 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=+q3cgWIse653ZY0dMk/l5QdcfE70HHh/XxgLEDBYGrc=; b=hDhnT0WqW73P6kQZvPTicAywzxbQ9k4y7+vyqrE4Fr3CmNkNKRsOe3O+UJ+SQXt9k4 MSeh9OmqMlyv+Miko99qAs5WvVqdg8+mfSkAAZdGQfXz5P3qKgnGBqpSh4DsENqUqICG T1u1bK+kbElzluGCOSn2bC3ZBAQwk8hjZqdd9I1PW2yBaDJkajUhAEzAXmLbjIavM/dr SxQ3Nq/tP0jsdk9YUDPUIkioqRltf9hl4LbGQecYQfx1Tc61l36v6/TN/jVUX6iS1ju/ 4OlPOL7l9x1LmxgID6ITTwNX3IFwQM1eQxBFfdLLr6FsfovF5C3vKjJ+V9iKAJTyQRXk StgQ== X-Gm-Message-State: AJaThX7vd9R/i+VRbsVBczxvuLkYl94DHu0hN8KgVos6TnbNcsnLWwzB nUcfDCpUVPvNAkcPABxEsPCkmjlWdLY= X-Received: by 10.223.130.17 with SMTP id 17mr22616749wrb.131.1511461938527; Thu, 23 Nov 2017 10:32:18 -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.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 10:32:18 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 23 Nov 2017 18:31:57 +0000 Message-Id: <20171123183210.12045-4-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 03/16] xen/arm: Extend copy_to_guest to support copying from guest VA and use it 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 (formerly called raw_copy_to_guest_helper) and raw_copy_from_guest is: - The direction of the memcpy - The permission use for translating the address Extend copy_to_guest to support copying from guest VA by adding using a bit in the flags to tell the direction of the copy. Lastly, reimplement raw_copy_from_guest using copy_to_guest. Signed-off-by: Julien Grall --- xen/arch/arm/guestcopy.c | 46 +++++++++++++--------------------------------- 1 file changed, 13 insertions(+), 33 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index d1cfbe922c..1ffa717ca6 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -6,6 +6,8 @@ #include #define COPY_flush_dcache (1U << 0) +#define COPY_from_guest (0U << 1) +#define COPY_to_guest (1U << 1) static unsigned long copy_guest(void *buf, paddr_t addr, unsigned int len, unsigned int flags) @@ -19,13 +21,18 @@ 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(current, addr, GV2M_WRITE); + page = get_page_from_gva(current, addr, + (flags & COPY_to_guest) ? GV2M_WRITE : GV2M_READ); if ( page == NULL ) return len; p = __map_domain_page(page); p += offset; - memcpy(p, buf, size); + if ( flags & COPY_to_guest ) + memcpy(p, buf, size); + else + memcpy(buf, p, size); + if ( flags & COPY_flush_dcache ) clean_dcache_va_range(p, size); @@ -46,13 +53,14 @@ 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, 0); + return copy_guest((void *)from, (unsigned long)to, len, COPY_to_guest); } unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from, unsigned len) { - return copy_guest((void *)from, (unsigned long)to, len, COPY_flush_dcache); + return copy_guest((void *)from, (unsigned long)to, len, + COPY_to_guest | COPY_flush_dcache); } unsigned long raw_clear_guest(void *to, unsigned len) @@ -90,35 +98,7 @@ unsigned long raw_clear_guest(void *to, unsigned len) unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned len) { - unsigned offset = (vaddr_t)from & ~PAGE_MASK; - - while ( len ) - { - void *p; - unsigned size = min(len, (unsigned)(PAGE_SIZE - offset)); - struct page_info *page; - - page = get_page_from_gva(current, (vaddr_t) from, GV2M_READ); - if ( page == NULL ) - return len; - - p = __map_domain_page(page); - p += ((vaddr_t)from & (~PAGE_MASK)); - - memcpy(to, p, size); - - unmap_domain_page(p); - put_page(page); - len -= size; - from += size; - to += size; - /* - * After the first iteration, guest virtual address is correctly - * aligned to PAGE_SIZE. - */ - offset = 0; - } - return 0; + return copy_guest(to, (unsigned long)from, len, COPY_from_guest); } /*