From patchwork Tue Dec 12 19:02: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: 121638 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508573qgn; Tue, 12 Dec 2017 11:04:38 -0800 (PST) X-Google-Smtp-Source: ACJfBouV692BQ32/8WZ81FIpoELcVgrPp30h+d4YzkhjApPK4j7kGxO+CNVh9dbLk7hM2+7oGEuA X-Received: by 10.36.48.82 with SMTP id q79mr872530itq.75.1513105478484; Tue, 12 Dec 2017 11:04:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105478; cv=none; d=google.com; s=arc-20160816; b=LCt4ej3J35hwtYbE/x4Q200ms4RwvnsqwR5czKEOp9qJOtRAUISvzCqm22a8PyWerB SwjQzHjRNO3n8wIo1zc7y6KOwIJenU5KMGMcHvG07X81PXOMADpkwqbLCJNtK8QXvgJR kwoxeTmtQCECMiHd0avUq6wqRHB8L3YFuPIJy+0Wij8qAEBYrum2+yfOyp1v1ufma6fX 8jvGKBFjTwIZlUtjn1KGeRTucWr5nCa8JNwzzFMa869RF4BHMMHfggujhjerc2ZKTQsq xQg3RQ8B3GLp/XVLFAXWtjC1FFiENTe2TR6Wv0LsKx+d2Kn/nqi+ZXVQ5xBBJw6bRyat 9YxA== 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=4xzKJdh5C1GphT7huJmc7VPMKvgeF7YCIGGQx5V6SOQ=; b=qEg4UTXM7YVNZlZ/tZ5p5qQguoIlWAHfbAI8qVZUCwuCSR3BFzvvxXEJHJb4SgYET1 tUxnyZkjujNftUFlSJ6SlYT4SrqnktBnM+vk5wOK8oiDIO9VKpaaYUBqoqJyDc09Hghc GQWuGhlVhMALrh7y48t5IOcO/1l/OON9v1dwrU1gj2xaymL5Snbu0WA9bzPx0K8kgwtj gZZ935N3DxxCyN4JF/q8k0h2nkXn37VfsAQ+GwVme98Yr0mTKK+6AX8MMHVsfZoiRK4p nruMVOQd0sXLp0VTxBVye4Tw+jT47y+CDDfFmw8fF0hOA7gg1OMheBLYPK/tKQBW9FI2 7JYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Nue5Wq2Z; 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 j89si9814169ioo.113.2017.12.12.11.04.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:38 -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=Nue5Wq2Z; 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 1eOpow-0002R9-Od; Tue, 12 Dec 2017 19:02:26 +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 1eOpov-0002QA-IC for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:25 +0000 X-Inumbo-ID: e959279b-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wr0-x243.google.com (unknown [2a00:1450:400c:c0c::243]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id e959279b-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:01:51 +0100 (CET) Received: by mail-wr0-x243.google.com with SMTP id v105so22217017wrc.3 for ; Tue, 12 Dec 2017 11:02:23 -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=wKgoYPI3vIQ0Ur5h3rt3UoEsr0JryNQTtXHD8p5F4FM=; b=Nue5Wq2Z5GyRQoVk6lziMrcgcAEq3JJ/jc3894EhiZHIwVAxOU3X7DyCLudsdet6Uh /+4qfbGnoZv6uvcLxdZVqxWUaLuFauzQqSfOYSQwBhLwlRc/WCIYJ/fKWt7PLfCl+/7P 4vS4lOnR9NpNrJJa68BMDVDpyaxHveOE1edWc= 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=wKgoYPI3vIQ0Ur5h3rt3UoEsr0JryNQTtXHD8p5F4FM=; b=Wg2EHsvU3tUFha9VgCgoISBuRrnMEvr+eNoJkPFg4h7hwHo6o/g/nBaa5UDZTnQCJ9 V12dVztGGsLBherOtVCN5QxOfCcjbLM7Ho2KkPK4/UQC0Ys43aOpZXDbolHPAvazGeqF VSanAHmZuPFoAdTLyCnZ+i2ESXm+ufY/l6OgwAgx1jUFdujndb0ntTSFMHZmap8U3jms CdCs/FXwKiG5fPigxfSsy4h2GjxitYBRUshq7HZ7srNQt4+Nbhr7n9vZjvvttBc4Cyru DvxZwE5MUTQQVUJj08XEttr16OLDnJrYs7goiVZneRZDoAYK3JJDzxlNdXgKOx5mK4O7 1YNw== X-Gm-Message-State: AKGB3mLApLl5j8FVYrgeRoM8laA0eFKT8za0ZAZ2gvYIlR+smyJZp8qX 9w59Ek5AbPCZ3UpquBbGYVgOlwBX+Wk= X-Received: by 10.223.177.131 with SMTP id q3mr4709200wra.269.1513105342545; Tue, 12 Dec 2017 11:02:22 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:21 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:00 +0000 Message-Id: <20171212190212.5535-5-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 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 --- Changes in v3: - Use vaddr_t --- 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 12fb03dd19..ff7d15380f 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -31,7 +31,16 @@ static unsigned long copy_guest(void *buf, uint64_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); @@ -67,35 +76,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, (vaddr_t)to, len, COPY_to_guest); } unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned len)