From patchwork Tue Dec 12 19:01:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121633 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508363qgn; Tue, 12 Dec 2017 11:04:29 -0800 (PST) X-Google-Smtp-Source: ACJfBosnGzvQOrT/eQfaXDMCBBMY1hg3wHhOiriYZdZxiBChXsqBgcQE6+dnYAI4bSrR/+ZcfTfv X-Received: by 10.36.230.3 with SMTP id e3mr951865ith.15.1513105469395; Tue, 12 Dec 2017 11:04:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105469; cv=none; d=google.com; s=arc-20160816; b=YJV9BbnjBeYVsncnkVC9LZsaJW1ieLy21Z88kmwVhz7efwSKoG/UYaDT44JNQ9sWD6 fl/MHQZBNIKwCo644oGPH/YqF+rgemW0yyz2gfQdW3RdJFf68RkpCOTcyNtmkc1u/ZkC MOEdDhbQGWFGMImBwS0fjTiVwh1FHEyz+JgktDUA1DTFRRJRuZeLEnaY+Wfx548uhfe7 cOyuYG4lM+2etc1E2H3OhMBmWSOKHpR2aI4ksMBDuKvXMjpVQt66qHNlz6JX+p7agjCQ hZGtGG7JAqRlHqOcODdWUhF83YYGfEdSJAuZb4VBUFSH0u6B+jlfRTqbOQsGaywpKXde exAg== 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=QFCp3FN4sLjX0azzWJAQsewX8PDGI17E/6JpSVKNXGk=; b=ObSm4ivLmmr1OuXilp0s0Dp/4hbamtYi0uQCrl72w71BdT3OdwT9tW+b5AZowy1zMt rNEdK/uWa9Zhz986akBviDj+cHyOLZEfokBSNVvnAet2adcKhLR6Y9QjkmSBtjiEHtAy fVyP2AKk74qGTldplLzzTSXE2R6ot6ee6GhR52B/P/k2QyEdFhLKBuArhaWnxKKtnhGN WX7kquTBhD8Umi3Q+MXyNRn+ZCH5CaAEP/Eru9UXs+bXWUHplA7pYYKKeQqcwpnv/NQL llWLtZ/NsWFP4v0EllaFWR4uiDcQIhkD5qRvkm3x4SSVPeLEmluDz5jGv8LbDyHsxrwH q7Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LPqTkkT5; 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 s14si194697iti.33.2017.12.12.11.04.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:29 -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=LPqTkkT5; 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 1eOpot-0002Pk-BY; Tue, 12 Dec 2017 19:02:23 +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 1eOpot-0002P7-1b for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:23 +0000 X-Inumbo-ID: e81ffe0c-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wr0-x244.google.com (unknown [2a00:1450:400c:c0c::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id e81ffe0c-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:01:49 +0100 (CET) Received: by mail-wr0-x244.google.com with SMTP id v105so22216925wrc.3 for ; Tue, 12 Dec 2017 11:02: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=0Kkn4SJWtPiaeGe/u6GgAi4s0koavzToH/OIviWzGWE=; b=LPqTkkT5cSN2SSXJCKWDlgz8kbpF/eiDka1SrfMjwlXvwRmKwmaeBA6BtQyMyjpARD CCdCN4vgx2vwjUzCrQQQ9bL+GtTOy2YAm3ApL4/YiKWTbJoDyphz6YwrruBgyAA6xYm4 Qt4tawY/QeZkchGaD4wmYwtAijvjvtl24lEng= 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=0Kkn4SJWtPiaeGe/u6GgAi4s0koavzToH/OIviWzGWE=; b=bvkcxhSEFeO6b+jh3u+O4v0DyVOH1qaeAZrnHSGBDm735etWxqdOKaVK5ezJ3m3+Ta h5boMzEj67EoY9AnPva2gmoQkbWTNXphUpbVntWxbx8iHLX49yYyZ9mEXowEipRLeCkg jvcCawCEXHMsqAOEmapKspL1N4DaNMSfkh6LmWffWM1yy/J68Q/oZBilJK5PBMCSUEjc O7ysPBN1nmKoLUW/ntba2GqsOW8tMlY2fiQVXGCPziipPJQIpuDS/GOPkRicu87fEO2d WVspCl/mWi9Dx//LxZGwfrgXPt23Zu6Jf91clbK6F7xnTaEEj+cA/w19uL4k6IWhoKyH Lm/Q== X-Gm-Message-State: AKGB3mKN/UciwVjAVvfXMGVGFbZC4FfwHptL50qPObu1d1PkGirS0JfY WqNZpK9cXxXT8mcR87R5jaSBjNZlzSo= X-Received: by 10.223.160.217 with SMTP id n25mr4675958wrn.27.1513105340440; Tue, 12 Dec 2017 11:02:20 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:19 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:01:58 +0000 Message-Id: <20171212190212.5535-3-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 02/16] xen/arm: raw_copy_to_guest_helper: Rework the prototype and rename 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" All the helpers within arch/arm/guestcopy.c are doing the same things: copy data from/to the guest. At the moment, the logic is duplicated in each helpers making more difficult to implement new variant. The first step for the consolidation is to get a common prototype and a base. For convenience (it is at the beginning of the file!), raw_copy_to_guest_helper is chosen. The function is now renamed copy_guest to show it will be a generic function to copy data from/to the guest. Note that for now, only copying to guest virtual address is supported. Follow-up patches will extend the support. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Use vaddr_t - Use uint64_t for addr in copy_guest - Add a BUILD_BUG_ON to make sure vaddr_t fit in uint64_t. --- xen/arch/arm/guestcopy.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 2620e659b4..08d0fa0a83 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -7,11 +7,13 @@ #define COPY_flush_dcache (1U << 0) -static unsigned long raw_copy_to_guest_helper(void *to, const void *from, - unsigned len, int flags) +static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len, + unsigned int flags) { /* XXX needs to handle faults */ - unsigned offset = (vaddr_t)to & ~PAGE_MASK; + unsigned offset = addr & ~PAGE_MASK; + + BUILD_BUG_ON((sizeof(addr)) < sizeof(vaddr_t)); while ( len ) { @@ -19,21 +21,21 @@ static unsigned long raw_copy_to_guest_helper(void *to, const void *from, unsigned size = min(len, (unsigned)PAGE_SIZE - offset); struct page_info *page; - page = get_page_from_gva(current, (vaddr_t) to, GV2M_WRITE); + page = get_page_from_gva(current, addr, GV2M_WRITE); if ( page == NULL ) return len; p = __map_domain_page(page); p += offset; - memcpy(p, from, size); + memcpy(p, buf, size); if ( flags & COPY_flush_dcache ) clean_dcache_va_range(p, size); unmap_domain_page(p - offset); put_page(page); len -= size; - from += size; - to += size; + buf += size; + addr += size; /* * After the first iteration, guest virtual address is correctly * aligned to PAGE_SIZE. @@ -46,13 +48,13 @@ static unsigned long raw_copy_to_guest_helper(void *to, const void *from, unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len) { - return raw_copy_to_guest_helper(to, from, len, 0); + return copy_guest((void *)from, (vaddr_t)to, len, 0); } unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from, unsigned len) { - return raw_copy_to_guest_helper(to, from, len, COPY_flush_dcache); + return copy_guest((void *)from, (vaddr_t)to, len, COPY_flush_dcache); } unsigned long raw_clear_guest(void *to, unsigned len)