From patchwork Tue Dec 12 19:01:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121635 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508539qgn; Tue, 12 Dec 2017 11:04:37 -0800 (PST) X-Google-Smtp-Source: ACJfBovRnEjeFfuicFD2gGQx3anydfgy4R1kSbKWKTRHl6XF3/8PQU7NAh4aWddATyOLV1rIvW55 X-Received: by 10.107.101.11 with SMTP id z11mr7378716iob.66.1513105476983; Tue, 12 Dec 2017 11:04:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105476; cv=none; d=google.com; s=arc-20160816; b=PYHsv+FcKfCzUnAdJ89MgGRrcjRR0IaSRo+uqLLgWrr7bpl8eI3J1U58xtRctsyo8E qS9klSCDda9OvWtoYmapapKIz0jVjgeJj/jwLlnWLhLfWPtOJCQh5JXd+/0H0ZrkBb93 58nbJVP2/SwyYi6WXBwWpuSWfc8U7EusLPnayFm9pFrNamAMSd1k1n4kX1eElgosdyO4 f4cmusXN1QV3wDgdq8repMrlMT/89ZWxg6/MVf+xnYndsmYbDcLHYoDKfjVJvnYtmLMJ wEOjaEx/XIFNjBO3/UzCYRr3RKP6XDluwsnxgmYccLdVBK2yJzv5JjMB+BXFGJnklCS/ oqJw== 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=CfHLrCBmap/EWcu+fMe+i4axe/9YE/7SBDDA7KuSr50=; b=aNTLoRjAH2x21sxOXLDG7/o3uEb+ufn+k9fTK7Qr2ba3O6lF97bPHkzliVyrhzz3PP gW2AeEAMnXy+X7/QvQCHCAXHIQ0s1L/cBAuiXeR6y4MXDc4FNVTEs6qlDY3mjSVwWkzY i8R+JsKdxUhzaCBca1fptrAhz4w4QcugW1S0jXokbGxg6jJisKxnMcvjiJYYIkVmQqjV Ir2BlYq2xnoQckvyXJqXnRxcsep1+KOTaLvhIl78bo091XMoJdLaGHDKR2cA+5Hzt/bz NrbpBSvfuzLewjSAdmbP9uYHt/K6WwzdRfINHphj6cScrabR0vDtqGYQUK/3fcJZ/9ig dfCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GDHp/Mbv; 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 y62si185969itg.67.2017.12.12.11.04.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:36 -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=GDHp/Mbv; 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 1eOpov-0002QD-IA; Tue, 12 Dec 2017 19:02:25 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOpou-0002Px-9d for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:24 +0000 X-Inumbo-ID: e8c20872-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wm0-x243.google.com (unknown [2a00:1450:400c:c09::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id e8c20872-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:01:50 +0100 (CET) Received: by mail-wm0-x243.google.com with SMTP id r78so651191wme.5 for ; Tue, 12 Dec 2017 11:02:22 -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=WJ4hpN4xEoc6h55GjpipEYjR68GZxAgoxZuqb7EwQVA=; b=GDHp/Mbv4JXmBZXl0BuFMKQK8HjnZ1wyPri0aSdlwl/WxnNl6eCveq0Jzf2oLjSGQn LlhIrNCD639ZaiB5TJCfwPNHuNsIryzUkBq5qsWGshX23pbmxjwbYc+OH0zzWRZOhgn7 faWfv7gFReTOVE4wMGRckKow5HnESSJowaf1A= 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=WJ4hpN4xEoc6h55GjpipEYjR68GZxAgoxZuqb7EwQVA=; b=hLMgw2z15hnotESmxqfWTaziUjkEBt9Onf42CBdDDckc/11QVZJmpdwJxmG4cUaI1v +EkPQVXxqTDnVEX73NEJ+u9Sp7TWZqxIZ6vfHwenNnKs/UApx673lymEqNR8cWVK3PPv hQOCwsy0BWnmp0COyFksevSGhzvbUsf/YdXJFK2jmhTx19dd5JI/DOs390p9aWHyeywV 1Tk9sEH7CBDrirG7EhOVyVfPruG4+5MKqOgG7Q49wLgJ3F5RgWfN/Udum/qba4m5kEw1 rh98VIhp45FyeCudFzB90SbYdlQY6OB3tB99muB9WMq4u1Bpwq4P5lXlDb6txPpbBc/g dECQ== X-Gm-Message-State: AKGB3mKrLqzv50Ycrz+tFiDoG2KzHdGgQ0ILhOVkwxRb/ZRq+8BCmJqg xFqevigtWQYj4uvMN3v1fOb5fyT2BuE= X-Received: by 10.28.194.139 with SMTP id s133mr2667254wmf.14.1513105341281; Tue, 12 Dec 2017 11:02:21 -0800 (PST) Received: from e108454-lin.cambridge.arm.com ([2001:41d0:1:6c23::1]) by smtp.gmail.com with ESMTPSA id n14sm207508wmh.37.2017.12.12.11.02.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:20 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:01:59 +0000 Message-Id: <20171212190212.5535-4-julien.grall@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171212190212.5535-1-julien.grall@linaro.org> References: <20171212190212.5535-1-julien.grall@linaro.org> Cc: sstabellini@kernel.org, Julien Grall , andre.przywara@linaro.org Subject: [Xen-devel] [v2 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 Reviewed-by: Stefano Stabellini --- Changes in v2: - Use vaddr_t --- 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 08d0fa0a83..12fb03dd19 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, uint64_t addr, unsigned int len, unsigned int flags) @@ -21,13 +23,18 @@ static unsigned long copy_guest(void *buf, uint64_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); @@ -48,13 +55,14 @@ static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len, unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len) { - return copy_guest((void *)from, (vaddr_t)to, len, 0); + return copy_guest((void *)from, (vaddr_t)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, (vaddr_t)to, len, COPY_flush_dcache); + return copy_guest((void *)from, (vaddr_t)to, len, + COPY_to_guest | COPY_flush_dcache); } unsigned long raw_clear_guest(void *to, unsigned len) @@ -92,35 +100,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, (vaddr_t)from, len, COPY_from_guest); } /*