From patchwork Thu Nov 23 18:31: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: 119534 Delivered-To: patch@linaro.org Received: by 10.80.225.132 with SMTP id k4csp1172972edl; Thu, 23 Nov 2017 10:34:13 -0800 (PST) X-Google-Smtp-Source: AGs4zMZmxU+yREygR8gN9Y6MymRPStumjK2E5iVIqZFYizru3swOuJaMCNkvzduy7hKsaU8nY0mE X-Received: by 10.36.154.71 with SMTP id l68mr12085993ite.57.1511462053416; Thu, 23 Nov 2017 10:34:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511462053; cv=none; d=google.com; s=arc-20160816; b=uUP8qu+fkVJKG6B15mytFLP3jSz8L7I4IWV8z0uk5VOyvagy43FrZj26I//wVDInDh EKhYFv+Q6nnToIlI898IOud60xdffp2hVY5lN4w/4HOYayY9Wr3uRY/Fgu6vzqd5ndBG cvc1XgBKO4Ch5nm2IX73DLvITjVITCydb+QtzXcAcdIHw8B5GwyDNtTtCZQKN2p0DtoU 86QkDXnzWOfN//b+pJCZIO2xbNBpbshQqNZ6tn4t6xnf1Me9XQU9pVhyYMGL1n//2E2f oea55alGXjAXdLuFAbtNdIZS5en7hpwLJy9dM2/FRvaUjoyedhBGeVGR8z+qlWC6djQ9 GmUg== 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=d0TmRE2xqp4KL82jEn8DNjqW8X+96ZBF7cnaWtaAEn8=; b=reY/nwf2a2vQQXPDZ4XgZY51lQ5x2vlbwKrctOV7srlM24iceFfjOOBuZqe6WwIhNA S5/oVLP0dnsTZf5aVc9tIWW/qFd4SaTo8RBphujwk90byU2rbAg+MhEwmOHw0xGZcxq5 Gfqz861PwgVzflhmEbbHH1S3+fySQzSg7NXihP2cXZpiPOPJKE4HJf+fUpRiJ/PmbXmf RtgbqDVXQHjMLWCZKBci+hQcMUwqIC1vbG8oa0/kj6vU52Yb6aJ7x/AS2l2L8ibOd4uO 7PGuJTryo2si5RtZw2jW+YLf8+Im4VL1MmFTxPYSXbUavbSFYXhLARd2oboz7igSQeh4 FOwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=c3tGbLUj; 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 203si10903398iou.284.2017.11.23.10.34.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Nov 2017 10:34:13 -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=c3tGbLUj; 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 1eHwIR-0005Bd-1r; Thu, 23 Nov 2017 18:32:23 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eHwIP-0005A4-35 for xen-devel@lists.xen.org; Thu, 23 Nov 2017 18:32:21 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 94/FE-32540-434171A5; Thu, 23 Nov 2017 18:32:20 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVyMbThiK6xiHi UwewtJhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa8a0vk+sBcsEKw5P8G5gXMHTxcjFISQwmVGi +UA/E4jDIjCPWeLTlAWsII6EQD+rxJ4tj4EcDiAnT2LrAxMIM01i2X6JLkZOILNS4ufMV2wgY SEBNYk1b6IgZvYxSfx6+5wFJM4moCOxbkYtSLmIgLTEtc+XGUFsZoF4icdTr7OB2MICKRJbD+ 8Bi7MIqEo8nn4NbCSvgI3EuaYgiE3yErvaLrKC2JwCthJHD3xghthqI/H5s+IERsEFjAyrGNW LU4vKUot0zfWSijLTM0pyEzNzdA0NzPRyU4uLE9NTcxKTivWS83M3MQKDjAEIdjDOvOx/iFGS g0lJlFfml1iUEF9SfkplRmJxRnxRaU5q8SFGGQ4OJQleSWHxKCHBotT01Iq0zBxguMOkJTh4l ER4twsBpXmLCxJzizPTIVKnGO05Lty59IeJ48CeW0Dy2czXDcwc0662NjELseTl56VKifNuBm kTAGnLKM2DGwqLz0uMslLCvIxAZwrxFKQW5WaWoMq/YhTnYFQS5n0LMoUnM68EbvcroLOYgM7 6eVwY5KySRISUVAOj2rW5D+OT3hRu6YnXSnQIUHJ5++HrjIxsvl8q61/LzNixdFGSfNpRSQG9 nYuWanja9Xw6fGKx/ySnmak3Kjdw7/phm7Wr7qaaj8GZK7dPPv/Pskj71B/fTT/ff1Vdam9oy b3jmNuXrZPDpoj98P+tGJK8JjFFP2imSMy+ovYvDonfjzytettbpMRSnJFoqMVcVJwIABHy4b nKAgAA X-Env-Sender: julien.grall@linaro.org X-Msg-Ref: server-7.tower-27.messagelabs.com!1511461939!113294630!1 X-Originating-IP: [209.85.128.196] 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 24990 invoked from network); 23 Nov 2017 18:32:19 -0000 Received: from mail-wr0-f196.google.com (HELO mail-wr0-f196.google.com) (209.85.128.196) by server-7.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 23 Nov 2017 18:32:19 -0000 Received: by mail-wr0-f196.google.com with SMTP id a63so18316668wrc.12 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=6Ykuugv1wRnCMhjTW6Y4HYWwWVvbSm5l2UqY4jm75HE=; b=c3tGbLUjyz/6g6aqwmYIbyLPtK0eZ50rSh9aDtZKhmAoT1IidhlX9yhutPgC1H/Fv3 FKIWp9+qeYVy2yOSuVvsu/T3FiwyQU51/J5CfhFiFlwnPUcGvJMSa+rvjWYAMAGL8X+t 58Hkyyg1WVLPE6Am310y8xEgtU8mcnszlU3mQ= 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=6Ykuugv1wRnCMhjTW6Y4HYWwWVvbSm5l2UqY4jm75HE=; b=cr4kwGRmHYs3OIGb8ZJUGIrheNGsQv9g7nBPWZyaeoKowU7fAf18gYEkoJveETKTJU +ilSwof7YD5abM1Se0MMZFs5SsggjJhkqB6kwgLVNLf9gmvHsAOJ/NG1rt5bPApjWtUe k7T0y6mVZvCSLemLJ0/RbNTufBba55K7Px0qiThg/jduG46gNzuWDGtFt1giGrYs01SR 9UC8kzxZtyjHX/a1B8Lm+VC3OZhym81oiX88rtff5z4gULjcm+Wt1Ol7GcltFXaqLF9a SSDozjw5pDPMUNchBrDcKtl6Qj/VDzC/Xo/t303y95jhqyDTWUm+2lKgB6AQ2CHfgcBu bd1g== X-Gm-Message-State: AJaThX7W+ProPNdS79S5XPUqsd298riQ7ne34dJpHp5Ys1Q1jgtf1AlT 1KMBowhnepQaU+dy7mQ5KB55U+E8zec= X-Received: by 10.223.139.67 with SMTP id v3mr22616174wra.70.1511461939269; Thu, 23 Nov 2017 10:32:19 -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.18 (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:58 +0000 Message-Id: <20171123183210.12045-5-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 04/16] xen/arm: Extend copy_to_guest to support zeroing 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 function copy_to_guest can easily be extended to support zeroing guest VA. To avoid using a new bit, it is considered that a NULL buffer (i.e buf == NULL) means the guest memory will be zeroed. Lastly, reimplement raw_clear_guest using copy_to_guest. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- xen/arch/arm/guestcopy.c | 41 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 1ffa717ca6..3aaa80859e 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -29,7 +29,16 @@ static unsigned long copy_guest(void *buf, paddr_t addr, unsigned int len, p = __map_domain_page(page); p += offset; if ( flags & COPY_to_guest ) - memcpy(p, buf, size); + { + /* + * buf will be NULL when the caller request to zero the + * guest memory. + */ + if ( buf ) + memcpy(p, buf, size); + else + memset(p, 0, size); + } else memcpy(buf, p, size); @@ -65,35 +74,7 @@ unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from, unsigned long raw_clear_guest(void *to, unsigned len) { - /* XXX needs to handle faults */ - unsigned offset = (vaddr_t)to & ~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) to, GV2M_WRITE); - if ( page == NULL ) - return len; - - p = __map_domain_page(page); - p += offset; - memset(p, 0x00, size); - - unmap_domain_page(p - offset); - put_page(page); - len -= size; - to += size; - /* - * After the first iteration, guest virtual address is correctly - * aligned to PAGE_SIZE. - */ - offset = 0; - } - - return 0; + return copy_guest(NULL, (unsigned long)to, len, COPY_to_guest); } unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned len)