From patchwork Tue Dec 12 19:01: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: 121637 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508566qgn; Tue, 12 Dec 2017 11:04:38 -0800 (PST) X-Google-Smtp-Source: ACJfBot3RYkfxp47RgPAcztje9ush8tT7r2kn3evFYZ8f2eh++oc8SMSW7UTqVszwpmvDi3ir+hF X-Received: by 10.36.13.141 with SMTP id 135mr868699itx.1.1513105478389; 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=Yj3tfTA4N1RJz6qtHjxk+onhjNTchSisyAgQNrgT5rraK15TLxkwVrntUV78gcNHpH snx9l8A6/MYXXIySQKJeHoNBIK7t8ubRsXOW6lcBwG97IfuU3SLtoV+kclXnf5zz5iG/ xYXGcFlnlPwh+tkZ1mDqt/OFnJC1cTYRMfa4xFikhzWVRhlcnnwm/3Y10qNiGEb912+T LjBt/lXlXxrp3KsP5YHqx2dROlbPqiuUeg0RwMfVvwwOV4JhfS64fXzreaq+HOCjz4EB l1DUle7xaTNDBH9h+o8ex6hvZ3hhm2AeZ7V+NEjkIm8aAu8Cg5kUGKy6xtY/vwc6KmfA PoCA== 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=33boym0iDmpfsXmmsfx3Cc4p6qyAFC5nypFaH+cDut8=; b=IgKrJd9nFnmPZVEAWRNHMRn1NH+yOI0Jig3bV0iydCfwYsNJnWP4saQ6neqkUnMkjA ZXVX77yRl+pqwS80iw0rcPXans4dehK9kzVfISl2dkJdAuZrO9MpusT7oYs08j4KsfUH znj8FPLG9rTuNLltGnUD4e5VSckYx5nS877TSZvpFtBfzihh8OKRBcWf5N51M0Yumf5z JRGMRkMGIj9FkXwM3QwE363cGENVqI1aRNMnL3p4LLym+lYmwGJEKpPjqxlWVDRkxBzw UZieFVQkwoGrtSVgYSwycdUvDs6dIse3KeoUoDJXt4yGl5h9GW0qYqCVNxi3qme5NB6q K3rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=b7eg6LXU; 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 11si192198iti.19.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=b7eg6LXU; 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-0002PE-0w; 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 1eOpor-0002Or-MB for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:21 +0000 X-Inumbo-ID: e77c6f8c-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 e77c6f8c-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:01:48 +0100 (CET) Received: by mail-wr0-x244.google.com with SMTP id h1so22163349wre.12 for ; Tue, 12 Dec 2017 11:02:20 -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=MdxMH+VIvgy5VjBNW3qVmrBsYeleqekgCTkPmsYq044=; b=b7eg6LXUZNC0uARS2Mjz+lBNJow3Hf+y/yL5ya/+ZTUpgTWfN7Vb79LbUoCHaL/AHS pkSUIRH2IaUzRcRTD9Vk5hrj3aIv5BgNED0Y28jozqIdIk8hAYivg08lndPDY4iUze7h hYApzJFx63XC9bibiLSnt789pY2+yr9KnhCYQ= 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=MdxMH+VIvgy5VjBNW3qVmrBsYeleqekgCTkPmsYq044=; b=KXsWVmd+8a8Uy+o7Pyb+AG1uEz8EY+0Cwd/WnG2ZYCKJc+xxsDuCOeaAcrj24A4MyR liDHmzpBaPEZHnrYBDq2Cncm+WO0YocS0R4NzSKRR0ZXyvnY/9rgtnepH9qnpzcOvs+v EFZbl5lknuuAwrjSuiDvvvPyCOUI05OHz92ovR50ItoKL5eYdDjuXM8dJNvP/4zjxd3K o2rBB9KPjmDdezpXkiSMRxC/vnvVuLhlBsJ5/JfpZU/W032zn1T0p2zYf3Mv0b7+X0S3 qxO0ztjxUVmhaNMjnZnPxld8cP2GpgTWKqIiIBusFDM7Sxie0wVBq1bCJMDeAg+H1cQA u1WA== X-Gm-Message-State: AKGB3mKY5+CBTtWsI2P40Khxj01JoZXZX0vHFojjH3parAVMJ0uzXXPz 01HTRuFqtEaFdPb/swbnXR90Ob9ptJA= X-Received: by 10.223.139.67 with SMTP id v3mr4659404wra.70.1513105339432; Tue, 12 Dec 2017 11:02:19 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:18 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:01:57 +0000 Message-Id: <20171212190212.5535-2-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 01/16] xen/arm: raw_copy_to_guest_helper: Rename flush_dcache to flags 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" In a follow-up patch, it will be necessary to pass more flags to the function. Rename flush_dcache to flags and introduce a define to tell whether the cache needs to be flushed after the copy. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/guestcopy.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 4ee07fcea3..2620e659b4 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -5,8 +5,10 @@ #include #include +#define COPY_flush_dcache (1U << 0) + static unsigned long raw_copy_to_guest_helper(void *to, const void *from, - unsigned len, int flush_dcache) + unsigned len, int flags) { /* XXX needs to handle faults */ unsigned offset = (vaddr_t)to & ~PAGE_MASK; @@ -24,7 +26,7 @@ static unsigned long raw_copy_to_guest_helper(void *to, const void *from, p = __map_domain_page(page); p += offset; memcpy(p, from, size); - if ( flush_dcache ) + if ( flags & COPY_flush_dcache ) clean_dcache_va_range(p, size); unmap_domain_page(p - offset); @@ -50,7 +52,7 @@ unsigned long raw_copy_to_guest(void *to, const void *from, unsigned len) unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from, unsigned len) { - return raw_copy_to_guest_helper(to, from, len, 1); + return raw_copy_to_guest_helper(to, from, len, COPY_flush_dcache); } unsigned long raw_clear_guest(void *to, unsigned len) 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) 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); } /* 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) From patchwork Tue Dec 12 19:02:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121639 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508587qgn; Tue, 12 Dec 2017 11:04:38 -0800 (PST) X-Google-Smtp-Source: ACJfBosv7mcimO4OxUeCl/E4YoU9c/9GtnonHBgUfwD/8FByDqpsm1zClaprvbjSC98aW31ISoHb X-Received: by 10.107.200.86 with SMTP id y83mr7303448iof.196.1513105478897; 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=xeOvE6ZYD3Y7kbku/xMnApDo293mpqySVxhOoaJaMpJwuomt1JCNvu6Zo8zJkDqINW hAu/zmFfhTCgRqwTellBvQIdXKoKBoEBI5u9HJ3JrFP5zYFWUhAD39t1KkneJKH66Sfi O3IQQud6FOZxUe4iXIQ2sNzfKCrIqEJGGNEHkOUhzPxcKTFsuYT9aCNGXy70MWUZQY7Q DFsUx/4bvaYhvV1+ACo8CdNe+zZJIrzWRXPiirts784i7PyXlwJL3Ku2tbgONkgVeQ4K 5cZPnTVo4gxQ4k7BkHASBPA7x+U3AalAA/JPigwzbZZ2IBEGNbIFn1qUwWbS1SG27KJ3 DUvA== 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=zVQ91kCA5fugVCwEWEQjtY0VjOR2Dw/PuR4+hAQl/+I=; b=OWKLmAst4WmJ95o4LwX6w6koL5p3VncJgzqKH/ewnRGA7CXgczLpxsytmyNzKiNAA1 VdvGvzUwHSrZZE16JFJJXGKoO9+r6IToBJRYWv07Mvwddv3+wAW0nQceNsTdVf/Qe7ci Th+NSMqnjJDkhVYvv8GynUbVsb9Wsy+u9MY77joWoxYcJvVqUSzUfVL5n+yrbSXhXN1w PbKGoYHFeoIxP8ciPQxUue5HGGdZYw7THJF9uUibCIlbyD6jkh72IsUdJ+gV7V8WvEB/ yHpQ5Cva+0hw0P9eVYcGoe/qtxuv1btYZbHNys1saXBlTdTe0Xrk/l8jfDgWXjS0QUP5 z3lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=bO8V8pUn; 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 62si170502itm.135.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=bO8V8pUn; 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-0002RS-Vn; 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-0002QX-Pn for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:25 +0000 X-Inumbo-ID: ea18b679-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 ea18b679-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:01:53 +0100 (CET) Received: by mail-wr0-x244.google.com with SMTP id y21so22240334wrc.1 for ; Tue, 12 Dec 2017 11:02:25 -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=JgAkwrCOYEZme6ItEpbHZL8valMoHMrkCvfrHMHnOp4=; b=bO8V8pUnifSDcerdEUu30/wK/Lg6bJ6AOrH7zfLwMKXqlp4yu+EoRhVht/GynSZVt5 4OM/o5RHeEMHn0jbhwncTnjsXFdCdBPa9BtX8eXx9iwA+61ev5oO5nIZvMylIwnMbRDT j5p2L3yJGmqzxS5leP26Ia8sPKYrq45jN1/hM= 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=JgAkwrCOYEZme6ItEpbHZL8valMoHMrkCvfrHMHnOp4=; b=hEhQUk1WU2B4LI9alXQ675fIxufm8nBMlQULAG9IJoVAKqlE2ebf5Fe0YMZzd/DbLI KFryzI2lIB1PRifIQpTbnsrOkQ2aA9U38/QeJv3F/DP4qjmXzYuomFCMgyeKUAtr/slx e9ZYS8RLnsrTyFBSKpofkftvjP8j9w2OoNGj1bNW0fxdBiIrvjm0SyevsJD4+cVEh4Cc n7AjBXkUIoJnLLA1Jc7uea642DkNrljytuGcAAVlxwcaUgkjmfcWrZxShwDyali7vbga yJ+GzOXLk5Tbdlk1Edz8qC8xUuN64BZbXTF5+DwTGv1uLMhhfXZF8MTp4ECnkRQkbUkl JRhA== X-Gm-Message-State: AKGB3mLbVacMW+BVUZqVweCfo4DSYs6WcYGrG57AMP53sP43H6Z6Myvj D94WDQMxZmZEWzXg7MO8LR3o3TpXYrI= X-Received: by 10.223.197.131 with SMTP id m3mr5076201wrg.203.1513105343738; Tue, 12 Dec 2017 11:02:23 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:22 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:01 +0000 Message-Id: <20171212190212.5535-6-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 05/16] xen/arm: guest_copy: Extend the prototype to pass the vCPU 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" Currently, guest_copy assumes the copy will only be done for the current vCPU. copy_guest is meant to be vCPU agnostic, so extend the prototype to pass the vCPU. At the same time, encapsulate the vCPU in an union to allow extension for copying from a guest domain (ipa case) in the future. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Encapsulate the vCPU in an union. - Rework the commit message --- xen/arch/arm/guestcopy.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index ff7d15380f..7e92e27beb 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -9,8 +9,18 @@ #define COPY_from_guest (0U << 1) #define COPY_to_guest (1U << 1) +typedef union +{ + struct + { + struct vcpu *v; + } gva; +} copy_info_t; + +#define GVA_INFO(vcpu) ((copy_info_t) { .gva = { vcpu } }) + static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len, - unsigned int flags) + copy_info_t info, unsigned int flags) { /* XXX needs to handle faults */ unsigned offset = addr & ~PAGE_MASK; @@ -23,7 +33,7 @@ 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, + page = get_page_from_gva(info.gva.v, addr, (flags & COPY_to_guest) ? GV2M_WRITE : GV2M_READ); if ( page == NULL ) return len; @@ -64,24 +74,27 @@ 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, COPY_to_guest); + return copy_guest((void *)from, (vaddr_t)to, len, + GVA_INFO(current), 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, + return copy_guest((void *)from, (vaddr_t)to, len, GVA_INFO(current), COPY_to_guest | COPY_flush_dcache); } unsigned long raw_clear_guest(void *to, unsigned len) { - return copy_guest(NULL, (vaddr_t)to, len, COPY_to_guest); + return copy_guest(NULL, (vaddr_t)to, len, GVA_INFO(current), + COPY_to_guest); } unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned len) { - return copy_guest(to, (vaddr_t)from, len, COPY_from_guest); + return copy_guest(to, (vaddr_t)from, len, GVA_INFO(current), + COPY_from_guest); } /* From patchwork Tue Dec 12 19:02:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121636 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508560qgn; Tue, 12 Dec 2017 11:04:38 -0800 (PST) X-Google-Smtp-Source: ACJfBotIylIRzbhCwXFu3MDBC3y4pQbJEkejTQ7MjuKOelr2DmzYoe5rDkPLsCHBab5dPlpm6xcj X-Received: by 10.107.2.137 with SMTP id 131mr7072341ioc.186.1513105478056; 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=vJH/YtFMngO/HXq6DPmgvuZtED/A7EQjqhX+8UyzONQWI/Z/n0zifzEZf+yuYd2iJx lXe9ydkwi2Grnz2CHjIoI6wtJqOAcSrDu6vdLKvM6LfFYIwVNmR/J2mvpSxGnVq9E/XI V1KlVOw+bziAkn+1UDP76q/hAVP0xgSwtaqL5CBAEfsQokIl8AeCSlgEv1L+Yb/7FQWW CoAo3CDcQtuRvuuRfiYBCwKCa7pPjoULj2Uf+umjtiDpGyq/Eabyrw5icG602UWbVPxf ef/xxEp701pe+OsAo7KePSAv5LtZbSVpFDiPqmwyMqSCmkKw7FbO2ycWHcGQE4w29/wH KzdQ== 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=WAFclMjRBQMH9zicDBCUKu8/yM70VLupqj1rtjwnwxM=; b=D2UzgSeq7wAxprGBalEPk1VylDRhtI6I/8VdLkKAN99QZpfIVifuAN1gcBCHNJWpBu d7WfhX0xo99uFZSGt8gfm7+8BjnLopOUx/3tGliaSIv28ep727Ui6LGP0X8tOT3wyg6j 55o9upgMiTfSKvRt601ZQ0xk2ziDHkMH9+VGE2X+O7oYZ+SCn9edYzT9Xd+2H2j7uC+0 P77jH8wxgAVesSvCoZtaMv2jCPTuSR1AtRSRZnKZFTh62yXKaX87KtZUmxg8vdMLl1va DnHMBgbkTVxA8NJv3l5jGKGDyMXd4L+ySCoW8xgYpXcR08HUjH1jJP9ZbqH/iEcDcXDb 2iig== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Rorc8Wed; 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 e81si179156itc.113.2017.12.12.11.04.37 (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=Rorc8Wed; 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 1eOpp3-0002W6-6T; Tue, 12 Dec 2017 19:02:33 +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 1eOpp2-0002VH-7K for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:32 +0000 X-Inumbo-ID: ed45d09f-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 ed45d09f-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:01:58 +0100 (CET) Received: by mail-wm0-x243.google.com with SMTP id i11so689311wmf.4 for ; Tue, 12 Dec 2017 11:02:30 -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=23sZqACdcVyMz/9na7hwK8jKYk8KTNy3pXQpkHgAYxM=; b=Rorc8Wed+CKR6QuCqo+vBXG1XgFq39FGcsE23n09JAytXewCHUw34bJvVbW+2ybU96 3oV9rSZRAJkgm3WPwRJ/ihKB8LvcRd/Y+QcXRtz/sZZFqQMdgIodslPKWfyhtbK6QeJD SqJOaRIDnJVyUqu0F+XnABcnnzZnVhY+sQiLA= 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=23sZqACdcVyMz/9na7hwK8jKYk8KTNy3pXQpkHgAYxM=; b=NRNA5u5Vfpi72KM5ZSVU4VbjmwmrNh8GV19lyxFpH/VHVMZptlDIZLolRRuY4NcFri ym29SGZFcdB1Q0T+vsrYZYhrrY5ptWDM5PF1koz7eInC3dL1o3psLo9mLCYacUE2oH5m zH2zf7eLplZCQnPhviPiNnko9MdP3/se4alN107yGuT9bz1vj7YNRPjM1MNucLmQebI8 R+W6qAz8h2ObhBeJEtahpZplLj/3/0PmOWCn3LQoX94wIG8oL/l8BxWO+JFYisdqhvVC XAjIfOgN1zkuR5FXfzOUUAByAlICrFVyKlwZFyg8knds3sfsnkTKwXZCIR8cLWel56zw cBaw== X-Gm-Message-State: AKGB3mL7q1KGxZiEEll/9jwSZW7RGWcaVkPq6B2rbqFXbc6rw0LeJ2qB nJUGQtBAvUGZ17E1S628NAx2y7PmgqQ= X-Received: by 10.28.22.16 with SMTP id 16mr2829321wmw.138.1513105349032; Tue, 12 Dec 2017 11:02:29 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:24 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:02 +0000 Message-Id: <20171212190212.5535-7-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 06/16] xen/arm: Extend copy_to_guest to support copying from/to guest physical address 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 and access_guest_memory_by_ipa are: - The latter does not support copying data crossing page boundary - The former is copying from/to guest VA whilst the latter from guest PA copy_to_guest can easily be extended to support copying from/to guest physical address. For that a new bit is used to tell whether linear address or ipa is been used. Lastly access_guest_memory_by_ipa is reimplemented using copy_to_guest. This also has the benefits to extend the use of it, it is now possible to copy data crossing page boundary. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Rework the patch after the interface changes in the previous patch. - Use uint64_t rather than paddr_t in translate_get_page - Add a BUILD_BUG_ON to check whether paddr_t fits in uint64_t --- xen/arch/arm/guestcopy.c | 91 +++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 47 deletions(-) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 7e92e27beb..93e4aa2d3f 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -8,6 +8,8 @@ #define COPY_flush_dcache (1U << 0) #define COPY_from_guest (0U << 1) #define COPY_to_guest (1U << 1) +#define COPY_ipa (0U << 2) +#define COPY_linear (1U << 2) typedef union { @@ -15,9 +17,39 @@ typedef union { struct vcpu *v; } gva; + + struct + { + struct domain *d; + } gpa; } copy_info_t; #define GVA_INFO(vcpu) ((copy_info_t) { .gva = { vcpu } }) +#define GPA_INFO(domain) ((copy_info_t) { .gpa = { domain } }) + +static struct page_info *translate_get_page(copy_info_t info, uint64_t addr, + bool linear, bool write) +{ + p2m_type_t p2mt; + struct page_info *page; + + if ( linear ) + return get_page_from_gva(info.gva.v, addr, + write ? GV2M_WRITE : GV2M_READ); + + page = get_page_from_gfn(info.gpa.d, paddr_to_pfn(addr), &p2mt, P2M_ALLOC); + + if ( !page ) + return NULL; + + if ( !p2m_is_ram(p2mt) ) + { + put_page(page); + return NULL; + } + + return page; +} static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len, copy_info_t info, unsigned int flags) @@ -26,6 +58,7 @@ static unsigned long copy_guest(void *buf, uint64_t addr, unsigned int len, unsigned offset = addr & ~PAGE_MASK; BUILD_BUG_ON((sizeof(addr)) < sizeof(vaddr_t)); + BUILD_BUG_ON((sizeof(addr)) < sizeof(paddr_t)); while ( len ) { @@ -33,8 +66,8 @@ 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(info.gva.v, addr, - (flags & COPY_to_guest) ? GV2M_WRITE : GV2M_READ); + page = translate_get_page(info, addr, flags & COPY_linear, + flags & COPY_to_guest); if ( page == NULL ) return len; @@ -75,75 +108,39 @@ 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, - GVA_INFO(current), COPY_to_guest); + GVA_INFO(current), COPY_to_guest | COPY_linear); } unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from, unsigned len) { return copy_guest((void *)from, (vaddr_t)to, len, GVA_INFO(current), - COPY_to_guest | COPY_flush_dcache); + COPY_to_guest | COPY_flush_dcache | COPY_linear); } unsigned long raw_clear_guest(void *to, unsigned len) { return copy_guest(NULL, (vaddr_t)to, len, GVA_INFO(current), - COPY_to_guest); + COPY_to_guest | COPY_linear); } unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned len) { return copy_guest(to, (vaddr_t)from, len, GVA_INFO(current), - COPY_from_guest); + COPY_from_guest | COPY_linear); } -/* - * Temporarily map one physical guest page and copy data to or from it. - * The data to be copied cannot cross a page boundary. - */ int access_guest_memory_by_ipa(struct domain *d, paddr_t gpa, void *buf, uint32_t size, bool is_write) { - struct page_info *page; - uint64_t offset = gpa & ~PAGE_MASK; /* Offset within the mapped page */ - p2m_type_t p2mt; - void *p; - - /* Do not cross a page boundary. */ - if ( size > (PAGE_SIZE - offset) ) - { - printk(XENLOG_G_ERR "d%d: guestcopy: memory access crosses page boundary.\n", - d->domain_id); - return -EINVAL; - } - - page = get_page_from_gfn(d, paddr_to_pfn(gpa), &p2mt, P2M_ALLOC); - if ( !page ) - { - printk(XENLOG_G_ERR "d%d: guestcopy: failed to get table entry.\n", - d->domain_id); - return -EINVAL; - } + unsigned long left; + int flags = COPY_ipa; - if ( !p2m_is_ram(p2mt) ) - { - put_page(page); - printk(XENLOG_G_ERR "d%d: guestcopy: guest memory should be RAM.\n", - d->domain_id); - return -EINVAL; - } - - p = __map_domain_page(page); + flags |= is_write ? COPY_to_guest : COPY_from_guest; - if ( is_write ) - memcpy(p + offset, buf, size); - else - memcpy(buf, p + offset, size); + left = copy_guest(buf, gpa, size, GPA_INFO(d), flags); - unmap_domain_page(p); - put_page(page); - - return 0; + return (!left) ? 0 : -EINVAL; } /* From patchwork Tue Dec 12 19:02:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121640 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508608qgn; Tue, 12 Dec 2017 11:04:39 -0800 (PST) X-Google-Smtp-Source: ACJfBovOkwoSthvcJjsZhdoUqP+WBoCF9gLFqO1xegxBQjYIr6uWYupVxxhuNx9VNMBfQzw2nGC+ X-Received: by 10.107.173.70 with SMTP id w67mr6811275ioe.246.1513105479723; Tue, 12 Dec 2017 11:04:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105479; cv=none; d=google.com; s=arc-20160816; b=M9qA2EGXEtOHdGPf20DUNf5butaf3vJOYGXOJVbN+HcNSokCZYK0Cm99gRVKS/Lb+r Hub9JLYt0vPyZPkcP8ZQuZTG6MmU73WQ+wFZiEsqcxLrtP31BYCspU+V9aB4nRN9s/xX jkNhF+YXsGLlhYpKkxJlxrooN8yRmQWjXtbsqaZNa56T2nLAVwNVopYpX5UImVy422H3 yj3+BtJXtfessItWKl7RdyoWUcTHHHocCQzoTpHRxV0VMdwjaTeHAMUHX1mjHLOSh8ur r/ocCTRiZYhDWClgT8SlY1ptyAJnM73KaB/KNGRX4mdu9tunwZPfGcqy8KjztY3Ij14n PgcA== 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=1aaD9qnLb0LYG5CpaP/C6CPO+IoMf2VAru40ykpMbmw=; b=jMrvEcckH1tbBBrgS/OTtpUuf1I22AK0iTc0zOTnben/FlGJRISfrNIZggkBqT3Rws Ihha+Yl7QNJe2gBNZXGfLo9wsFZnPheVj92zKqvaubQC6HEzCm5wPlujynSQIRlYSCp2 NeagfRu+OdmmrGfHPT4PoNpZTRXdP6t2UVR5nIn6qrban3lGm7SwjMtxJ1+pGe+qKcG4 yOqHaDQlkNxhVdtDCkTaxyKBFpnnB9S/iD52rnHF6H6ExNvS5NsH9qEzDyRXgXQWX1K9 dAA+7dtqZsboLM9bUWSZJkFFxgRshCLKXpNsjHupe80Ak/LH8EqJfCnWaDsO5I6FEUP0 T2bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=jAJb/sUR; 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 s31si12505760ioi.146.2017.12.12.11.04.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:39 -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=jAJb/sUR; 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 1eOpp3-0002WY-Do; Tue, 12 Dec 2017 19:02:33 +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 1eOpp2-0002VI-8U for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:32 +0000 X-Inumbo-ID: eddb1c6a-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 eddb1c6a-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:01:59 +0100 (CET) Received: by mail-wm0-x243.google.com with SMTP id r78so652083wme.5 for ; Tue, 12 Dec 2017 11:02:31 -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=MyFwm1Ppczs1NIORYl7fjDlL6EedtAlEclHWy3YKWVU=; b=jAJb/sUR/TFo+YiZ+5wCEqhoBEob9c0FSnho+M+zxrGKyxefre9OGb24o2sOjll8Om bjNO8l6zgejdz9jN1iYWQEo2akIffGnzio53HBrtPLzz1epMYFLo8HAj9nLGHza8ZfPM jjRQb7PcU8WbjB2OF5iL+ZX0H4ntMBySJ/WbY= 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=MyFwm1Ppczs1NIORYl7fjDlL6EedtAlEclHWy3YKWVU=; b=MeaCQDPqzm6+IFzQOBHA2Ncg/GziDlC7ERfW/ynGDDb7zeDQKnENwIllf/oPGS8d2J NDERKeW6jwx3DhK8nvGPVbz+6xjIdniOaRtZFC9DB84tRNY2Bq8r/8/Dp4ioeI/LEW6W LXEZHTqEhehhvGv/I+bkJUebRpVa4AsTe7UZSAM6iCHVqwLd2Wq4RtT+y9efQISchmEB wYr1i69vKi/LphzfmrOLTg9lbQAEuSdId5udPN4ipzuhLzEmlAbwFcQpGWO8m2UvVTpD 9AHq8P2fPjSu4w0nKSPHuUA0Yc6k6IrkaXaTOcENSE2GDIW2fgLSjrS3TlPWwfk7xxdM 1cOg== X-Gm-Message-State: AKGB3mIgxkzWEwHQIyagxYZzEZOqXGu71hbP2iaqNrXE2DFiKkCmqd/Z UWyo5jGS2YlLzc4JZQV3U9dMyLuovZU= X-Received: by 10.28.138.75 with SMTP id m72mr2808006wmd.97.1513105350004; Tue, 12 Dec 2017 11:02:30 -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.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:29 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:03 +0000 Message-Id: <20171212190212.5535-8-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 07/16] xen/arm: Introduce copy_to_guest_phys_flush_dcache 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" This new function will be used in a follow-up patch to copy data to the guest using the IPA (aka guest physical address) and then clean the cache. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Use the new interface --- xen/arch/arm/guestcopy.c | 9 +++++++++ xen/include/asm-arm/guest_access.h | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/xen/arch/arm/guestcopy.c b/xen/arch/arm/guestcopy.c index 93e4aa2d3f..7a0f3e9d5f 100644 --- a/xen/arch/arm/guestcopy.c +++ b/xen/arch/arm/guestcopy.c @@ -130,6 +130,15 @@ unsigned long raw_copy_from_guest(void *to, const void __user *from, unsigned le COPY_from_guest | COPY_linear); } +unsigned long copy_to_guest_phys_flush_dcache(struct domain *d, + paddr_t gpa, + void *buf, + unsigned int len) +{ + return copy_guest(buf, gpa, len, GPA_INFO(d), + COPY_to_guest | COPY_ipa | COPY_flush_dcache); +} + int access_guest_memory_by_ipa(struct domain *d, paddr_t gpa, void *buf, uint32_t size, bool is_write) { diff --git a/xen/include/asm-arm/guest_access.h b/xen/include/asm-arm/guest_access.h index 6796801cfe..224d2a033b 100644 --- a/xen/include/asm-arm/guest_access.h +++ b/xen/include/asm-arm/guest_access.h @@ -11,6 +11,12 @@ unsigned long raw_copy_to_guest_flush_dcache(void *to, const void *from, unsigned long raw_copy_from_guest(void *to, const void *from, unsigned len); unsigned long raw_clear_guest(void *to, unsigned len); +/* Copy data to guest physical address, then clean the region. */ +unsigned long copy_to_guest_phys_flush_dcache(struct domain *d, + paddr_t phys, + void *buf, + unsigned int len); + int access_guest_memory_by_ipa(struct domain *d, paddr_t ipa, void *buf, uint32_t size, bool is_write); From patchwork Tue Dec 12 19:02:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121645 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508731qgn; Tue, 12 Dec 2017 11:04:46 -0800 (PST) X-Google-Smtp-Source: ACJfBotCQPrPD7QjB3N9d0xI9gfPElZ7r1Nrw+BqEGLLq8o3lZsbGaRG1ItS26SoJ2Am6A4/EtuG X-Received: by 10.36.206.130 with SMTP id v124mr890217itg.81.1513105486386; Tue, 12 Dec 2017 11:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105486; cv=none; d=google.com; s=arc-20160816; b=cb+4d0ob1HQPee43CYIv+Chk8p7eD0mB3hvxy0merfRNKpV8PoBJYvJDzoLRNYEvlu WPR512zkXe2XCI92s5M5DXFeBuki37n07borjnJE5ixlCe6o5Re7a34mg449N2p4EMPX KeSlPFL/H/Py3xiPTYrWkO8VV6An2WV2hHN7fZWet0/15xTRcdl1JrkCUuedejGddXqb q75rEr6EoOMBAoEvGCsXK1BE4tCG5ygss80Tywkg1WOwbofhyZ3Ks390oeKbX1rIBwJo HFB05tUDURhn2SElMZOvCPjYKNuuc+M5HfHrcnL4Ho5KetIkbP0UIHnrXHtiPzkgBFiU /V0Q== 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=SFURQjsaDIJV73GG8hckDyacMam/E+r9BD72hq7/xM8=; b=iye7D685bfg3hJzJQvSdwKt+FORzgBiXzS01MPhbB9rT+oWQ+7G6lsXLRznYC1URmF i0YMY3OqFFQQ5TSb4MAtpomIbYxw6vwEy7bt+XcHmOcqYgEBHX12xsbigRFgsA6pB6/A FpQTWu9O51BxQ5hhsqTTCIRmpguSZUVFobDxuneBPVeID6cWrDMP9UxDpg2Tfsi/lEqq YH0xwvk29b7ektqB0DpzqqUpwx5k+gZJnvB/JWB2HXt3Ea/o0w0Soa6uTtB3IKvqbuo0 Ib3gR8MJG24jnobCeNIcAE75u7n9nMqaDVPpkmFPy8H3sRja92URQbRskGrbnx9/8J6+ +QAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KLXv77Vc; 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 x189si164056itb.172.2017.12.12.11.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:46 -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=KLXv77Vc; 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 1eOpp4-0002Yi-Px; Tue, 12 Dec 2017 19:02:34 +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 1eOpp4-0002Xr-3d for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:34 +0000 X-Inumbo-ID: ee8c69cd-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wr0-x242.google.com (unknown [2a00:1450:400c:c0c::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id ee8c69cd-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:00 +0100 (CET) Received: by mail-wr0-x242.google.com with SMTP id y21so22240729wrc.1 for ; Tue, 12 Dec 2017 11:02:32 -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=s8S0y1gqjP0wTdZqWWLUTW3a7kvHJ2Nn2FjfLMpDcZk=; b=KLXv77VclmstaoauiYN2eEEKVv3m4eAbZ3gxUxwJqbgTnWdoEzgxav011lX9yXDsDt 6fOVXHZtz27RwH6QEj4dSzBPHwRnYrt9gbCqzmM7ER7t7fe1v7dzjx8u3NZLkPOWLh1v jAKALqL9UogsBwC9yqbw7mkVq7Ns7M6qHR34E= 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=s8S0y1gqjP0wTdZqWWLUTW3a7kvHJ2Nn2FjfLMpDcZk=; b=hVn57W0Xm+DV4IhVKO/Vez58RJlWRyToUY3S244ZirWZTIk5nePxd/FmYJAk23SCok qeNNdrAjbjFm2tuUhBfUOl7hhQNRLNUff+y9l5yCD+4D5AS8d7nFSkgwQSfjNzjE2fqW wXmSarw44kPzDFDPZL+c84/aNlM4VHQgyaJ+14f48NPle1edamu7+PKuEqBM8w6Sc3L6 /IalA+rK01nRuFDzgcz4998Rer25Gr/gVNPTLA5MC0vSn0D69428YqneDmncAkC2a9Wm c1cWS/yQ7GHx8n1ipWXNRFEqyxGxHEPhhTzrsseifCRL0r81QfsRIOr4ebfoCkA0HFDJ gzqg== X-Gm-Message-State: AKGB3mIlxtPe67yMXxqY56yj0VHZte/29SpDSy8W74m44atepvyO2KSx 5JE7d7CgTYkof2yZ1lkcoIx0049HP24= X-Received: by 10.223.193.135 with SMTP id x7mr5006561wre.211.1513105351243; Tue, 12 Dec 2017 11:02:31 -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.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:30 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:04 +0000 Message-Id: <20171212190212.5535-9-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 08/16] xen/arm: kernel: Rework kernel_zimage_load to use the generic copy helper 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 kernel_zimage is dealing with IPA but uses gvirt_to_maddr to do the translation. This is currently working fine because the stage-1 MMU is disabled. Furthermore, the function is implementing its own copy to guest resulting in code duplication and making more difficult to update the logic in page-tables (such support for Populate On Demand). The new copy_to_guest_phys_flush_dcache could be used here by temporarily mapping the full kernel in the virtual space. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/domain_build.c | 1 + xen/arch/arm/kernel.c | 33 ++++++++++++--------------------- xen/arch/arm/kernel.h | 2 ++ 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index d7b114ec23..aa6ff8d456 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2135,6 +2135,7 @@ int construct_dom0(struct domain *d) d->max_pages = ~0U; kinfo.unassigned_mem = dom0_mem; + kinfo.d = d; rc = kernel_probe(&kinfo); if ( rc < 0 ) diff --git a/xen/arch/arm/kernel.c b/xen/arch/arm/kernel.c index a6c6413712..2fb0b9684d 100644 --- a/xen/arch/arm/kernel.c +++ b/xen/arch/arm/kernel.c @@ -15,6 +15,8 @@ #include #include +#include + #include "kernel.h" #define UIMAGE_MAGIC 0x27051956 @@ -157,7 +159,8 @@ static void kernel_zimage_load(struct kernel_info *info) paddr_t load_addr = kernel_zimage_place(info); paddr_t paddr = info->zimage.kernel_addr; paddr_t len = info->zimage.len; - unsigned long offs; + void *kernel; + int rc; info->entry = load_addr; @@ -165,29 +168,17 @@ static void kernel_zimage_load(struct kernel_info *info) printk("Loading zImage from %"PRIpaddr" to %"PRIpaddr"-%"PRIpaddr"\n", paddr, load_addr, load_addr + len); - for ( offs = 0; offs < len; ) - { - uint64_t par; - paddr_t s, l, ma = 0; - void *dst; - - s = offs & ~PAGE_MASK; - l = min(PAGE_SIZE - s, len); - - par = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE); - if ( par ) - { - panic("Unable to map translate guest address"); - return; - } - dst = map_domain_page(maddr_to_mfn(ma)); + kernel = ioremap_wc(paddr, len); + if ( !kernel ) + panic("Unable to map the hwdom kernel"); - copy_from_paddr(dst + s, paddr + offs, l); + rc = copy_to_guest_phys_flush_dcache(info->d, load_addr, + kernel, len); + if ( rc != 0 ) + panic("Unable to copy the kernel in the hwdom memory"); - unmap_domain_page(dst); - offs += l; - } + iounmap(kernel); } /* diff --git a/xen/arch/arm/kernel.h b/xen/arch/arm/kernel.h index c1b07d4f7b..6d695097b5 100644 --- a/xen/arch/arm/kernel.h +++ b/xen/arch/arm/kernel.h @@ -15,6 +15,8 @@ struct kernel_info { enum domain_type type; #endif + struct domain *d; + void *fdt; /* flat device tree */ paddr_t unassigned_mem; /* RAM not (yet) assigned to a bank */ struct meminfo mem; From patchwork Tue Dec 12 19:02:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121634 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508506qgn; Tue, 12 Dec 2017 11:04:35 -0800 (PST) X-Google-Smtp-Source: ACJfBouNtL0M0mCGC56CP2fNqTswrEvJH0en52FxeHPGblkAQkzFZF+rEWQF95/WD8aznLh89uZ7 X-Received: by 10.107.169.152 with SMTP id f24mr6361702ioj.219.1513105475329; Tue, 12 Dec 2017 11:04:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105475; cv=none; d=google.com; s=arc-20160816; b=RdLXi1eucMnsddX67wlui/AhFOsHrL8zL4W/ggRFtnPWyTUdwnMq4kfn2yWGWXk7A8 kPxmi13BEDQ8u1TGo5NY+mnUjh/MkBSA8aal6qUnzG9rC03FL/PDSliQFA5hzWwnjKoq FOasyBRtHL2QcQuKLSdEp7xh58gObVGKJ2vQngWrTiEbZsbgVmM571PZKfmKtSrBLoZc hNpcLvBJidLgLd+BNhS0KRjUNqZjUWIVv1Ju04vsRyPut6ftZo/InRtL7nAzz5Hi5jLH 0cU3YrA/90V3rhyjXVDycX8NI79vkYTIhb3A5LPsB9GnGjK6UB4eAgFCR0kuXGetis0H Em4Q== 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=pbU/cNVw3C3eZcDyk7Pcqz8KcQMQI8s3FmJayqUL1Vg=; b=GcszxU1krqdlaNGsLQBEJeZtloVfKCQHj7WrlQpePwFae3FMPgc2t4a4RkspnZwZhB fVOCPDAg4/xs8xx+elIB2ia2N3vLee5HLb6yI+/gS7GNM293QEG/4NqSMk5hS62lKV2W NcjWV/+FUaqfo9jBXceoY57a/m2ycYXfczBRh5bVWaBUWqpxBF2kUc4ST2QXh1Mf6HN/ xqnwOZi9Adt1pFs33R0lU+l50leWe9MiRF45mYkW9DwKZnCJfzNv8ogjIVXO/t+Ao9Jr ocEdll2xOqpuzTK+Iacryi7ReGzYS/jy9IrqmsEilYN1Rs9yTdq0qmkDW7WUkjDy3I47 hVuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=UyDnKcNh; 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 y62si191725itg.38.2017.12.12.11.04.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:35 -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=UyDnKcNh; 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 1eOpp7-0002b2-0z; Tue, 12 Dec 2017 19:02:37 +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 1eOpp5-0002ZM-EW for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:35 +0000 X-Inumbo-ID: ef46245b-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wr0-x241.google.com (unknown [2a00:1450:400c:c0c::241]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id ef46245b-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:01 +0100 (CET) Received: by mail-wr0-x241.google.com with SMTP id l22so22203747wrc.11 for ; Tue, 12 Dec 2017 11:02:33 -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=Qd4oZes4m/rpQ0NKa8VAFcomBS8OlY6pRMzFwuSfxb0=; b=UyDnKcNhiyXEPinaoQEc4Pio4410BrGM4nEBTga65np8DMPvpt08IbKYumNy7r0Rzu 57M7U3AfXNtCTSSKNb+Yks67u1X6VC3y3us+WXEtK/Q2zPk1c/NnD2UxdX8MFEopSAPz 1NdkOUsMk/0wX+B81n1yganfghMe3sKgwbmsU= 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=Qd4oZes4m/rpQ0NKa8VAFcomBS8OlY6pRMzFwuSfxb0=; b=sbEve4bxhbByTvpWtdF+omgJZr8pWj7SdfCISqbklPHMi1bzKX9b1pD7nXpqqdxTFL jidKf2Vw5rOGz4YSxrsRGaMF1jm09HOcbeO5tCjQmYAp2oChzKq0Ij9eN9rqOVkpWdW5 gTADCIDdqNDoH0ibxbYiGDzbHphEtBUnOACabzedEd3YMKiUFU2mWNs2442XtpCzrUXj 43gqo3153p1cD3bIQEH5MmamFDiQQFY4NGA6fTM0HWqov9/Nyi46SCl3Yj0ut3oz6HvF Z5U6s++zWbUbA5u2uXxiSzwVw98vKLmvTLrkkMnsIL8QBjsF3jsDTMZrLvI1JIPPNCws tCSQ== X-Gm-Message-State: AKGB3mIV9CQfg8vxWuwl1L7C2Q2J/dfEy+RUjPYxPoa7USVb8h18ny0P QphMIccIAw1bdlQmwliXSmrlFkE6VOk= X-Received: by 10.223.185.79 with SMTP id b15mr4964208wrg.58.1513105352490; Tue, 12 Dec 2017 11:02:32 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:31 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:05 +0000 Message-Id: <20171212190212.5535-10-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 09/16] xen/arm: domain_build: Rework initrd_load to use the generic copy helper 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 initrd_load is dealing with IPA but uses gvirt_to_maddr to do the translation. This is currently working fine because the stage-1 MMU is disabled. Furthermore, the function is implementing its own copy to guest resulting in code duplication and making more difficult to update the logic in page-tables (such support for Populate On Demand). The new copy_to_guest_phys_flush_dcache could be used here by temporarily mapping the full initrd in the virtual space. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/domain_build.c | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index aa6ff8d456..66fd77def6 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1968,11 +1968,11 @@ static void initrd_load(struct kernel_info *kinfo) const struct bootmodule *mod = kinfo->initrd_bootmodule; paddr_t load_addr = kinfo->initrd_paddr; paddr_t paddr, len; - unsigned long offs; int node; int res; __be32 val[2]; __be32 *cellp; + void __iomem *initrd; if ( !mod || !mod->size ) return; @@ -2002,29 +2002,14 @@ static void initrd_load(struct kernel_info *kinfo) if ( res ) panic("Cannot fix up \"linux,initrd-end\" property"); - for ( offs = 0; offs < len; ) - { - uint64_t par; - paddr_t s, l, ma = 0; - void *dst; - - s = offs & ~PAGE_MASK; - l = min(PAGE_SIZE - s, len); - - par = gvirt_to_maddr(load_addr + offs, &ma, GV2M_WRITE); - if ( par ) - { - panic("Unable to translate guest address"); - return; - } - - dst = map_domain_page(maddr_to_mfn(ma)); + initrd = ioremap_wc(paddr, len); + if ( !initrd ) + panic("Unable to map the hwdom initrd"); - copy_from_paddr(dst + s, paddr + offs, l); - - unmap_domain_page(dst); - offs += l; - } + res = copy_to_guest_phys_flush_dcache(kinfo->d, load_addr, + initrd, len); + if ( res != 0 ) + panic("Unable to copy the initrd in the hwdom memory"); } static void evtchn_fixup(struct domain *d, struct kernel_info *kinfo) From patchwork Tue Dec 12 19:02:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121644 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508726qgn; Tue, 12 Dec 2017 11:04:46 -0800 (PST) X-Google-Smtp-Source: ACJfBos8Wo2Ij6GiBeHRoJoRtucHayJGm4T5kAtvfcA8Jd9acLhXsOXYFQ+czNVLDFmh4WG7WhnQ X-Received: by 10.36.115.79 with SMTP id y76mr881320itb.144.1513105486110; Tue, 12 Dec 2017 11:04:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105486; cv=none; d=google.com; s=arc-20160816; b=f/ywfDaq4KLhQdbkN3qSyKSGuketFKARYR+mxeB6fHhkju56tapx5v2P2r7eBXvxAz nCI6GVdfGgorjSGo67QsRRKOAQh229EAkdmIgQTzHvtz7/AlFSCyl+kt4ZYVleJK6c8f XDhbLrkDAl5oEj0UptfMV9qMCShRPxGNeUPBlSmH66nEDSRskEKhaG0RTTy0ABmpA0A5 wAEHiUehE8X3LdsUftX3X5Qas0qgOH9W68Rh+XjeIUxCwpwyvhIAFOdyfr+oyETAlbYG 1rNTaD4olPg+BadLqu3T3CRQrFCDyftLuC5uopJMT4VLtBQQIeWvidoNaeQf+KmIxD0G bVSg== 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=ZX41R8Kz/NEBCQJIVRTTnfM6NlqEmyX0/I/LyJPTr8w=; b=GpHFRFRIXWdgs7tkUDxRKS9pgiJfgoDR56OmBrqi9q3uqH6TQJvSQMGL+HY2Wz1yLw xUpER0UM7auXKMJi+7QX9TIxZkyqz+lemqbJfpp3bBQbbvdsi/QMaahP4QQUbczEJ6Jw MMwuq0Db0QQB0LQc5hg5/MMUlxMgmoXbCk/oki561ebRE5VXbSxrt1i9z8pbURe+si5y NKgrb6TpJ80yKy8nqSrLtV+2PYIrSRG3P8GrslAeWFCobICW25HhfmVtsz20+jIhTHlT 1MP/b8W1ZPTa7f6BZScafwuYTfy9IbEp9A78dNjWL8khU3jCqA7rPkmBZWnwkRf2ws1l VQ5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Rrop5gAn; 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 o189si191223itc.18.2017.12.12.11.04.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:46 -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=Rrop5gAn; 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 1eOpp7-0002be-9J; Tue, 12 Dec 2017 19:02:37 +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 1eOpp5-0002Zp-Q9 for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:35 +0000 X-Inumbo-ID: efe06f9a-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 efe06f9a-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:02 +0100 (CET) Received: by mail-wr0-x243.google.com with SMTP id x49so22183496wrb.13 for ; Tue, 12 Dec 2017 11:02:34 -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=OAyrQLPkZ4XMKTzacliWHSEdVkVcvpNFnWM880UKNyI=; b=Rrop5gAnX6zEOk4JE8DSyDAy55TKi0Rv/ff7AnwORGgpROUuWewfr/qU7ZiM7hWydy LkD+TgRpRov7+BH3UiR18Zh0keUfLou4DPtqC71e3K6VQlMaBV5r12qJ9d0WGW5eKNt7 8O19Uj1heWI/TJHOYTsj8gSflEs2MO7Qrhbag= 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=OAyrQLPkZ4XMKTzacliWHSEdVkVcvpNFnWM880UKNyI=; b=LrjuBhl5P8lB9h8RT7VvPB9SWVHiMRcYLa3EbJwyePw1gYEw0c8lLYxgQLOjtwktyy NTvjYWZXkX3GvH9ji82KNFjwwiaJY1kxTCYp1jGpDU4lieKO/taqauofK8yGQ3/pDAQ3 6AsLh5iBZJBcZHl/82Y/ZjTXqAFJaO1XQK43uCy5Q47TFVW5xWCny+m/UlRyu+qctR68 5Xpy2cv2gqKTURHp6Ixu0FuQOnYmjQpCiX5DEArk/NrQ9nl6pm4pXF9hx1HTOtl8aKo8 pNO3Ijs9lFXJaXr7Ic6pXYA3FWT4ZOPHJMNBvLSlc2Xdz4Hljq8kM1yG8MnYIA7fAn5n OhpQ== X-Gm-Message-State: AKGB3mJ6CYTYnapLF0VpQpIOGRYFdjIz+J1W309x1AkOWG271L/rNiQT frLlvUaBEb7mtTTJPKSP93zPTbqePK0= X-Received: by 10.223.176.194 with SMTP id j2mr4468436wra.62.1513105353367; Tue, 12 Dec 2017 11:02:33 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:32 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:06 +0000 Message-Id: <20171212190212.5535-11-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 10/16] xen/arm: domain_build: Use copy_to_guest_phys_flush_dcache in dtb_load 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 dtb_load is dealing with IPA but uses gvirt_to_maddr to do the translation. This is currently working fine because the stage-1 MMU is disabled. Rather than relying on such assumption, use the new copy_to_guest_phys_flush_dcache. This also result to a slightly more comprehensible code. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/domain_build.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index 66fd77def6..155c952349 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -1950,14 +1950,15 @@ static int prepare_acpi(struct domain *d, struct kernel_info *kinfo) #endif static void dtb_load(struct kernel_info *kinfo) { - void * __user dtb_virt = (void * __user)(register_t)kinfo->dtb_paddr; unsigned long left; printk("Loading dom0 DTB to 0x%"PRIpaddr"-0x%"PRIpaddr"\n", kinfo->dtb_paddr, kinfo->dtb_paddr + fdt_totalsize(kinfo->fdt)); - left = raw_copy_to_guest_flush_dcache(dtb_virt, kinfo->fdt, - fdt_totalsize(kinfo->fdt)); + left = copy_to_guest_phys_flush_dcache(kinfo->d, kinfo->dtb_paddr, + kinfo->fdt, + fdt_totalsize(kinfo->fdt)); + if ( left != 0 ) panic("Unable to copy the DTB to dom0 memory (left = %lu bytes)", left); xfree(kinfo->fdt); From patchwork Tue Dec 12 19:02:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121641 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508647qgn; Tue, 12 Dec 2017 11:04:41 -0800 (PST) X-Google-Smtp-Source: ACJfBotZBq3kprtJM7RDMxfi7buxK1kfUNVbitvvp1HuwSzD7m9OI35iFbqvEZ1FCrrMUlxjY/Aj X-Received: by 10.107.195.70 with SMTP id t67mr7009576iof.74.1513105481781; Tue, 12 Dec 2017 11:04:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105481; cv=none; d=google.com; s=arc-20160816; b=Pbztczy4MF9IMHXe0oeEqzz3wPfqMXJn2TSdO9eRewsHd548vG02OGKQLMBOYFgpYr 5YZqbI+JjJdDXCW2lo+jDo8I1zui4myz2vM0ub9Y1gn4NTkeXREuESIVdjJjYpg4QDxm JM7kEbEWlOBHGVt54w52Jpe1sbxjx4JMHVPtsT1jSqH1289o0zDg9nTOlOg9KpxD3H3j S/tJ2XgI6sfUMPPY0n++T52lqbe4M5RL/rMmRALNWmmo7uBRmUhHWqGr8aBfBJaXJiD2 7fKEYeEU1AYb1XboTVc4/YWeCYUUp0wdgpI5paWK1ogKeb0Sntr6bHNJC0U79ZYglyor abAA== 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=J/7+XDx7B7uXtHPbAerUyL/c3mshQzk/vnX5ElYs+LM=; b=P/yyRK1W3ENJcdaI3xMBT/kTXNZz/wUCzLxSnKwHjvvVr3yv4CBqnA9PzulTCxBgdJ 0cNDwF2+5tYSaPUWraFxW4bKjEMrMNVlNeVAvLVyNIDuezIlAu8X29lA44QBtzyo3XZy isklZtrz0IWvyJ37zgLaNv16J1SS+Qn5bjon1J2IN+aE5hkWpUQFFXW0RiEy0OUFlpjT 3lopr+y7+H4QdaKQlYdGA/iHmo8UlsulLrUV/QEBVsX0kLsUbJovHaz64MH6aGDr3ikz aI8Eyk2xNag9CRNxWqBC1M064fOTCMNAeyLaRPVL9arbvPskUnJ/M/IjkufQBCPWqA/M S2Rw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=MvCY6jfX; 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 w21si185026ita.83.2017.12.12.11.04.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:41 -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=MvCY6jfX; 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 1eOppB-0002gF-Gm; Tue, 12 Dec 2017 19:02:41 +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 1eOppA-0002f3-7a for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:40 +0000 X-Inumbo-ID: f22d23bc-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 f22d23bc-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:06 +0100 (CET) Received: by mail-wm0-x243.google.com with SMTP id 64so698315wme.3 for ; Tue, 12 Dec 2017 11:02:38 -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=c7lqXg8maW6sBnICeiDRVz9+9FK1rWYdzhNYk3D8MxQ=; b=MvCY6jfX5bCrSncISjFGbUQjiEYSh9bEowStCyR/ChScBmc8apb0XjtNNhxZuymAGI auCAI3iiN0/Q0mgrVjOAGTHHwP282qhqfxm2vvkCSEegxBKqUUSw684pf5bZ73T+DXxH Bc4eAmYw8m4aT4JaOjr3jba/4A/1wbx1CnY88= 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=c7lqXg8maW6sBnICeiDRVz9+9FK1rWYdzhNYk3D8MxQ=; b=iGP9bt5qbBpcmuzDrNM+1tq83AoIQBQk0BWcM2hQAtDSMDMa4/rwFICMGlCpyUAnO7 JqCfGf6V2uBrE32KyK8gYO4JjdFh7f5eReY/QrgJl7xP/wCyuD1sUjo/7gTCeveK0dX6 KfKjORgdUypbZn3TUgnYHt4OyZqrdDQBnLWru+cglViC71CNFz2CCggHANuEdQVvq8d2 IBFK2eC062COfN9Zd1e1JZAg6yqViz+/3FL9OCP9vJymHJ+IXP8FPtb3OB+BseN2caI6 j7Ju2GCJ54d7wl4JRZLmiWy8WlaisAHw8+X5ePlPEKXJkDWJwl64Ht29mjjLbH1vDKU/ Pnug== X-Gm-Message-State: AKGB3mIwh5+T9xV08ckvlNQ0x2dUsrfPK444dN1zvsobskVfE5y9aibL PjCmWWE7ofo8Xl9rtMAdrBJ487YAYuA= X-Received: by 10.28.35.80 with SMTP id j77mr2674797wmj.109.1513105357171; Tue, 12 Dec 2017 11:02:37 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:33 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:07 +0000 Message-Id: <20171212190212.5535-12-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 11/16] xen/arm: p2m: Rename p2m_flush_tlb and p2m_flush_tlb_sync 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" Rename p2m_flush_tlb and p2m_flush_tlb_sync to respectively p2m_tlb_flush and p2m_force_tlb_flush_sync. At first glance, inverting 'flush' and 'tlb' might seem pointless but would be helpful in the future in order to get more easily some code ported from x86 P2M or even to shared with. For p2m_flush_tlb_sync, the 'force' was added because the TLBs are flush unconditionally. A follow-up patch will add an helper to flush TLBs only in certain cases. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/p2m.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 7bf34aaa8c..95090874c3 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -51,7 +51,7 @@ static const paddr_t level_masks[] = static const uint8_t level_orders[] = { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER }; -static void p2m_flush_tlb(struct p2m_domain *p2m); +static void p2m_tlb_flush(struct p2m_domain *p2m); /* Unlock the flush and do a P2M TLB flush if necessary */ void p2m_write_unlock(struct p2m_domain *p2m) @@ -64,7 +64,7 @@ void p2m_write_unlock(struct p2m_domain *p2m) * to avoid someone else modify the P2M before the TLB * invalidation has completed. */ - p2m_flush_tlb(p2m); + p2m_tlb_flush(p2m); } write_unlock(&p2m->lock); @@ -137,7 +137,7 @@ void p2m_restore_state(struct vcpu *n) *last_vcpu_ran = n->vcpu_id; } -static void p2m_flush_tlb(struct p2m_domain *p2m) +static void p2m_tlb_flush(struct p2m_domain *p2m) { unsigned long flags = 0; uint64_t ovttbr; @@ -169,11 +169,11 @@ static void p2m_flush_tlb(struct p2m_domain *p2m) * * Must be called with the p2m lock held. */ -static void p2m_flush_tlb_sync(struct p2m_domain *p2m) +static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m) { ASSERT(p2m_is_write_locked(p2m)); - p2m_flush_tlb(p2m); + p2m_tlb_flush(p2m); p2m->need_flush = false; } @@ -674,7 +674,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, * flush? */ if ( p2m->need_flush ) - p2m_flush_tlb_sync(p2m); + p2m_force_tlb_flush_sync(p2m); mfn = _mfn(entry.p2m.base); ASSERT(mfn_valid(mfn)); @@ -863,7 +863,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, * For more details see (D4.7.1 in ARM DDI 0487A.j). */ p2m_remove_pte(entry, p2m->clean_pte); - p2m_flush_tlb_sync(p2m); + p2m_force_tlb_flush_sync(p2m); p2m_write_pte(entry, split_pte, p2m->clean_pte); @@ -939,7 +939,7 @@ static int __p2m_set_entry(struct p2m_domain *p2m, { if ( likely(!p2m->mem_access_enabled) || P2M_CLEAR_PERM(pte) != P2M_CLEAR_PERM(orig_pte) ) - p2m_flush_tlb_sync(p2m); + p2m_force_tlb_flush_sync(p2m); else p2m->need_flush = true; } @@ -1143,7 +1143,7 @@ static int p2m_alloc_table(struct domain *d) * Make sure that all TLBs corresponding to the new VMID are flushed * before using it */ - p2m_flush_tlb(p2m); + p2m_tlb_flush(p2m); return 0; } From patchwork Tue Dec 12 19:02:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121643 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508715qgn; Tue, 12 Dec 2017 11:04:45 -0800 (PST) X-Google-Smtp-Source: ACJfBosmZxY6U+5i+Wx5ovBc3t7CZhb3hHrlGib1Cu6+Lebz7MlpsTdffTVAh+Te4/iEXbTt+88W X-Received: by 10.36.216.138 with SMTP id b132mr762423itg.121.1513105485176; Tue, 12 Dec 2017 11:04:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105485; cv=none; d=google.com; s=arc-20160816; b=ZJcPgVG6TPcYmWzUDlca1M12DB/jbxUkNo/+x1IlRomTFBWFAAd6aupGwxRs/tDG6P /VCHOuXeUvtIQYpBCRCJZwWs8LHaxyT6gnpIxK8yhDA6JAic6dD1beOdJG/20DE9nXsN MzPAqb7nAFmTz9427yoq4LgB3jAEJ8oTfrBgjmLDyENOJjGo7EvCzjTT3W1aOOnqK8YR lGXNMrJMpah5m6vpEj6agzJ8PY2TIfAl/qqadtAqKgkTfyuI+l5azPsgAE5L3G/iAKpN fbH5fJ/bxFfUDU+yjcGkCSZsrDTdbZWvrqagcSc0Entxm9lwq6ofTL477x+sABwSt8rL I9Og== 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=uasytb7Xs0xBIT5punk+/1NW+6ipsNt95YpOqNZ+uuM=; b=TNSxE0RsXAkzpEQIFjyzuKWdj0lwQuTXdAD038R9/ll3FcPLejMFlya51ezsyMDWGb iM4VvYB7kTOEsqSKfYAVl1X9fyX9adZ8Da4rb9jyOQMRerXwJm9PDu0jUU8Bn9Pt3teq jtKMPL9qwBJB97V3OFZ4+NeYJJ+HyAW3sqXh3br1DUQAq7yIjdWGF5XLRsybF6ujUoEm 8k3VzQeeiZP8iwDoPqtL/33u2kq0X2HvaXaZW/ZXrwByNHvRn+3TTOaR6+ij/0r/3Zsq ai0XcNqLGbiNaNuXyLOKKXJXRhKgsOO0WTOciUYUFVzQiJxf12gdyDj2XYl+WD8VvEWI hTcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EmptYypL; 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 g20si10116091ioe.182.2017.12.12.11.04.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:45 -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=EmptYypL; 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 1eOppD-0002ij-On; Tue, 12 Dec 2017 19:02:43 +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 1eOppC-0002hU-IH for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:42 +0000 X-Inumbo-ID: f3790f2d-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wm0-x242.google.com (unknown [2a00:1450:400c:c09::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id f3790f2d-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:08 +0100 (CET) Received: by mail-wm0-x242.google.com with SMTP id i11so690303wmf.4 for ; Tue, 12 Dec 2017 11:02:40 -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=0bFGviCHyRMKr+LG6sn7FWHbTHVabqNxDjGNxpuc/LU=; b=EmptYypLeMBHcDhQWrlu926CabfGdET/gAUdH0IBF40uBYB25ylmzI+Q2TaDdgBK2z Sj6ZSqQNzropA+M5AvFAzaW/MaIzxhja3smXFVfEgjQ2BJsmD8wfo6ur/jMQRtNcTjVx K+TZny4jOx6Tp1CzVFeGHPcrPfHJbAeNAhmYY= 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=0bFGviCHyRMKr+LG6sn7FWHbTHVabqNxDjGNxpuc/LU=; b=Li78BuLnnv7QjmeCMgHkHa47Vi2Fy+idd+yfh58D7CVvG7tg3GCVPGo1PKa6YI8veA jL/VeX2Az1TyemqoDfScUayfIfvWAaocARm8B8hbCEOlfFdGoJlsq9n5FnOElYKFpmt/ 8AhTZU+QJDaDOw9z7YQi/TuvYmjeVXtbJjfndyEpjsp2Rzgj/R3HqrYryFRoYAzhAJOW WWjAXWyQdG5MduFpC0be3skrwnfBpSQvOL6GT/Ejh8sEemIljdZVTO3vtcvqXMLQLhhA aTtc6u96uxZMs5sd6NJoWgHnKWsaPo0JH2I+NJpZNJnHSO1piKwFMbzc09xMcovIr7Da kQ2Q== X-Gm-Message-State: AKGB3mJjsj3u0Qq75cdiqHdLOxDghJmXM4mx+46g6JEnwQjuj8+ClN1S sMdMZ2/JUBwlRcAwqFKM92P7bePBx8w= X-Received: by 10.28.226.214 with SMTP id z205mr2684111wmg.149.1513105359427; Tue, 12 Dec 2017 11:02:39 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:38 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:08 +0000 Message-Id: <20171212190212.5535-13-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 12/16] xen/arm: p2m: Introduce p2m_tlb_flush_sync, export it 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" Multiple places in the code requires to flush the TLBs only when p2m->need_flush is set. Rather than open-coding it, introduce a new helper p2m_tlb_flush_sync to do it. Note that p2m_tlb_flush_sync is exported as it might be used by other part of Xen. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by - Fix typo in the commit message --- xen/arch/arm/p2m.c | 27 +++++++++++++-------------- xen/include/asm-arm/p2m.h | 2 ++ 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 95090874c3..15711a4c80 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -51,21 +51,15 @@ static const paddr_t level_masks[] = static const uint8_t level_orders[] = { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER }; -static void p2m_tlb_flush(struct p2m_domain *p2m); - /* Unlock the flush and do a P2M TLB flush if necessary */ void p2m_write_unlock(struct p2m_domain *p2m) { - if ( p2m->need_flush ) - { - p2m->need_flush = false; - /* - * The final flush is done with the P2M write lock taken to - * to avoid someone else modify the P2M before the TLB - * invalidation has completed. - */ - p2m_tlb_flush(p2m); - } + /* + * The final flush is done with the P2M write lock taken to avoid + * someone else modifying the P2M wbefore the TLB invalidation has + * completed. + */ + p2m_tlb_flush_sync(p2m); write_unlock(&p2m->lock); } @@ -177,6 +171,12 @@ static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m) p2m->need_flush = false; } +void p2m_tlb_flush_sync(struct p2m_domain *p2m) +{ + if ( p2m->need_flush ) + p2m_force_tlb_flush_sync(p2m); +} + /* * Find and map the root page table. The caller is responsible for * unmapping the table. @@ -673,8 +673,7 @@ static void p2m_free_entry(struct p2m_domain *p2m, * XXX: Should we defer the free of the page table to avoid the * flush? */ - if ( p2m->need_flush ) - p2m_force_tlb_flush_sync(p2m); + p2m_tlb_flush_sync(p2m); mfn = _mfn(entry.p2m.base); ASSERT(mfn_valid(mfn)); diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index faadcfe8fe..a0abc84ed8 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -204,6 +204,8 @@ static inline int p2m_is_write_locked(struct p2m_domain *p2m) return rw_is_write_locked(&p2m->lock); } +void p2m_tlb_flush_sync(struct p2m_domain *p2m); + /* Look up the MFN corresponding to a domain's GFN. */ mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t); From patchwork Tue Dec 12 19:02:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121642 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508700qgn; Tue, 12 Dec 2017 11:04:44 -0800 (PST) X-Google-Smtp-Source: ACJfBouXavykNCjdIwLFglFxye4n486rpZbFXTDvsz6j+KadZ/9uacxMVLrFFlsSM0QE/SiHCRdR X-Received: by 10.107.27.195 with SMTP id b186mr6065595iob.277.1513105484360; Tue, 12 Dec 2017 11:04:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105484; cv=none; d=google.com; s=arc-20160816; b=RyiydEXmHZaM93krHsN4i82A2jkflB1JPP/CNzf1KQbHrQRgKTc6oZSY0AIfXKKoIa s4cN3BmFsqhxoKe/w88K/cES2/upnZadq/gzff+3pKzGsGqGnIAsf0ZRZFND2ZauGOqi kcVxkzEo5xSzLLvaFivYdVLsJ5V1lZ8kmjcEjLVJYc/wo4ndnItZrrge7Q6JfwVyE25H mtWpDQXO2RheZNjfsD2WkRjgjx2hoWJHberFuetxLQxlnAdYxHXcSaVzdorP6DtsNMWp kEhumcqCAf3EdyVWsw9GPU/q8UcWBcyxo60gl2qi4GhZapcwPYs5Fa7dSC5jxIYQxjCg 7Faw== 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=EOmIyVfSW+Dj+WddoLINtxZ6lsFbembqzCe1mTszIG4=; b=nOkuA/LHQUYUNXI4cK/ZIkdounWdMBuUHBk46yNaTi0n7aUkzwGsI6iLwH7xysjF3O 7OFPES3N8nfVamVpN/lSf8D+yOHuijAA9WjFmTla2MnnFB4guWImxn79P37ofUo58JYA pM6WDQdo1wKAQYVtFv3+KLLlZzd9bOh+c+ED6dbzcmkaN/tyZgWnp9NquwhS46b5K3Jx YVd881FHFl+7TDre4Q8mnWhpU9rVHOY+6I50YLXWz25dlW+zITooSXfl8t8pcL5H3Wf0 WNtwP8t2D+Ianmssg9RQMLn2Ln+3mQ3s9DVSpUQt8PHkHLYKtFBx/AvS4CCSk6OsZZe/ wo6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=j4PhFPjU; 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 66si11930210ios.150.2017.12.12.11.04.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:44 -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=j4PhFPjU; 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 1eOppG-0002mG-3K; Tue, 12 Dec 2017 19:02:46 +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 1eOppE-0002kB-Uf for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:44 +0000 X-Inumbo-ID: f50ed967-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 f50ed967-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:11 +0100 (CET) Received: by mail-wm0-x243.google.com with SMTP id t8so683388wmc.3 for ; Tue, 12 Dec 2017 11:02:43 -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=4ahZ8uEy02X+uawVFiv+SZLHVmwQh6VKOEFS0hlxlgg=; b=j4PhFPjUdwVJUXrKTYTBzN1DVHW9EctVrhfcXNQUNxqx3Kuz2IiVQ6RrCPoZakvg/E qH7LDmrj4jV2e+8puNSA3kTkFcuLoxBz+mTF645asYy26m1MTXX31wGmtNrJljKcBQOa 5wdcfOZUBNyUSFgEHRs0cHoRlwkBrpxJSLa5g= 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=4ahZ8uEy02X+uawVFiv+SZLHVmwQh6VKOEFS0hlxlgg=; b=mdQdZ++is2kejPHpNEiId9+Ahu/IkjrAn/L5TUrm9HVWtVgvSJBxEtj/SnauHNSoNo qMdKR3rciZGPoxZym4uXPnBZ+mNPbx1G/QiNlrTMYktcCaYr/VOKeSvzidvazazvFC9v zHMCglAcis0v3omj6NdtfVtxAgOkdxbzNZPrBIfWo5StSqqArDCngOeNqPnIvHLP4n0q hMTYYCMeagFNhPrERHrXLTDnAaIiO63UrH+AN0PIfSOqjh+KWwgxGkvC0eAPxbrTgi5g J43m5f6jNvT6fXafsXbPocxTWakWVvJGOoUXdhHj8HuiOVNO1AmWY8LXEy95XwShdGLS cVDQ== X-Gm-Message-State: AKGB3mK/8XacRdFycj3mb0Gx4lEuK0KwoEi3ZvEWZkd2vGBOW/wbHXkO LT0Abset69GXH52n5TSuGGswg/+GLso= X-Received: by 10.28.210.72 with SMTP id j69mr2716066wmg.51.1513105362132; Tue, 12 Dec 2017 11:02:42 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:40 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:09 +0000 Message-Id: <20171212190212.5535-14-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 13/16] xen/arm: p2m: Fold p2m_tlb_flush into p2m_force_tlb_flush_sync 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" p2m_tlb_flush is called in 2 places: p2m_alloc_table and p2m_force_tlb_flush_sync. p2m_alloc_table is called when the domain is initialized and could be replace by a call to p2m_force_tlb_flush_sync with the P2M write locked. This seems a bit pointless but would allow to have a single API for flushing and avoid misusage in the P2M code. So update p2m_alloc_table to use p2m_force_tlb_flush_sync and fold p2m_tlb_flush in p2m_force_tlb_flush_sync. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by --- xen/arch/arm/p2m.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 15711a4c80..22165ae376 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -131,11 +131,18 @@ void p2m_restore_state(struct vcpu *n) *last_vcpu_ran = n->vcpu_id; } -static void p2m_tlb_flush(struct p2m_domain *p2m) +/* + * Force a synchronous P2M TLB flush. + * + * Must be called with the p2m lock held. + */ +static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m) { unsigned long flags = 0; uint64_t ovttbr; + ASSERT(p2m_is_write_locked(p2m)); + /* * ARM only provides an instruction to flush TLBs for the current * VMID. So switch to the VTTBR of a given P2M if different. @@ -156,18 +163,7 @@ static void p2m_tlb_flush(struct p2m_domain *p2m) isb(); local_irq_restore(flags); } -} - -/* - * Force a synchronous P2M TLB flush. - * - * Must be called with the p2m lock held. - */ -static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m) -{ - ASSERT(p2m_is_write_locked(p2m)); - p2m_tlb_flush(p2m); p2m->need_flush = false; } @@ -1142,7 +1138,9 @@ static int p2m_alloc_table(struct domain *d) * Make sure that all TLBs corresponding to the new VMID are flushed * before using it */ - p2m_tlb_flush(p2m); + p2m_write_lock(p2m); + p2m_force_tlb_flush_sync(p2m); + p2m_write_unlock(p2m); return 0; } From patchwork Tue Dec 12 19:02:10 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121630 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508149qgn; Tue, 12 Dec 2017 11:04:20 -0800 (PST) X-Google-Smtp-Source: ACJfBouh5zgGSb+bVLDzVB8g85ZVILnEt4VlYJNQUHfUEf5N6lKrK/QH0UueaNsEFy46hTCSXfb9 X-Received: by 10.107.180.66 with SMTP id d63mr6449925iof.276.1513105459965; Tue, 12 Dec 2017 11:04:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105459; cv=none; d=google.com; s=arc-20160816; b=tu60kd+XepNhmk2Q6Zh9GN1tKsAHgt3I0JwU/8qxhpJOZvPMm4XIC+7EX8iVagqQae mPZuQWTKNTh1H/Xw6hoZYi5f6SKSIlicS20UKXE8eOFJhxNoSvpz8qSmTCmL4AmKpNHE WuL0J4qLPCjYgIJjUYMWbh3IbPDDYdEllUaCsm3v5jKP89rw8hkAxU6JEjawbDiJVXkq /XZGKycimkbT/NcSwFp0rJ+n3zTo6Wj3QPptVjfdj0o6GAbwvSGcqIBDSbTVfmDF5jfK IROvh6BSTMsB8AuWQjTSogVDLOQr8NjgElofFtJT5DyJZ5JAtmJgtfUocCH0CI239vdK I7zA== 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=4hDbzON8Zw/z1Xah8T7HnCr2MVp5YMos5NGyVRnB0xU=; b=ylu1pGUtTMWf0lK/dmKtoOpVCrotTRXI1WRQuBaHDZZhxCWQCOSW0tHsbc+LUKShiE PuUslYCmQFtsLJRLEHZ+q//oavBC6bEy87PCAtQnraWl2LxzgOUerAiG9XVTAPRCrXNK avWLBzaeXtrbbC73NnP2Ghm/quPRWpaMBZsl3fj1DJvGzacbpAo2JnDMChf4oh+cbokx yK3tcwCIp5Qjhf/nO15CiUunom4idO8OiCxyjnt5k5wgmOmEAd1u2cUWtPS+zcXmpxAI wftKaC9d4wZ81p9UMGHkonxf5UAnEaBGY/xVqRb+7SNWts0GMAqzkVxBaQK1WEPj4AnI bFKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=FKdYr+a8; 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 y139si178074itc.57.2017.12.12.11.04.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:19 -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=FKdYr+a8; 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 1eOppG-0002mn-AD; Tue, 12 Dec 2017 19:02:46 +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 1eOppF-0002l1-9X for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:45 +0000 X-Inumbo-ID: f5a01aaf-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wm0-x244.google.com (unknown [2a00:1450:400c:c09::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id f5a01aaf-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:12 +0100 (CET) Received: by mail-wm0-x244.google.com with SMTP id y82so18619436wmg.1 for ; Tue, 12 Dec 2017 11:02:44 -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=YE15pR3nJyD9psVJ0Bn7eV7Iev/t6WK9IBXSYJHwXaQ=; b=FKdYr+a8u2fa/A0HFOsef8k3sRa7QxAErFFvaA6ZYWXSpH+u8kcsiTUT9uJOpnpjcK Y8yexFK/rqkNpjpIKS2INJr8CdVfczeF035ydMQLCOe7V7j/YV9jq4+15/7+ikIlUcal XagB/+9RqgUIkHC+f+4+cIFgcPGvhsxf/cCJI= 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=YE15pR3nJyD9psVJ0Bn7eV7Iev/t6WK9IBXSYJHwXaQ=; b=mkzob9EA3P1mCTDgESGQjUdcy0wpgaTKlaAWZaqMlzHFLZKWDJSMVhjyZZUmlu+Ykp HBo8izanPnMpVry21YlCZI6P3gOZO6bOoG92jXAyvhhvgxl0sUG3gwRXYuTiNgpzutsl CZf0LVqeD0640KW3kf5XR5TYnQSOWMLqpuyYMSxbHm0LnQFD2Ae2772LQHtxUK+HFYm1 YgmDDC43MskBmOZJY4Cf7hr87xTh1Wc8UkwXGvurjdYZfDsnIEBAjSxlrcQfYMFgGtql d2BI+6gEO5Us0kCdOaXobIwAUS7wwDBQSi1ln2bAvaMktF/8l56O0Qqy4Ii3WJa4tI9W 1Tkw== X-Gm-Message-State: AKGB3mLFax6/P2qjHrlWOy/nuumO92qQni/LumDGXIJnuygIBDgVpsob qphY7goLjDZn2503oxm+KyWdy4IORKo= X-Received: by 10.28.232.70 with SMTP id f67mr2864435wmh.90.1513105363048; Tue, 12 Dec 2017 11:02:43 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:42 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:10 +0000 Message-Id: <20171212190212.5535-15-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 14/16] xen/arm: traps: Remove the field gva from mmio_info_t 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" mmio_info_t is used to gather information in order do emulation of a region. Guest virtual address is unlikely to be a useful information and not currently used. So remove the field gva from mmio_info_t and replace by a local variable. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Stefano's reviewed-by - Fix typo in the commit message --- xen/arch/arm/traps.c | 13 +++++++------ xen/include/asm-arm/mmio.h | 1 - 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index ff3d6ff2aa..130e85a6ba 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -2000,6 +2000,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, { const struct hsr_dabt dabt = hsr.dabt; int rc; + vaddr_t gva; mmio_info_t info; uint8_t fsc = hsr.dabt.dfsc & ~FSC_LL_MASK; mfn_t mfn; @@ -2013,13 +2014,13 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, info.dabt = dabt; - info.gva = get_hfar(true /* is_data */); + gva = get_hfar(true /* is_data */); if ( hpfar_is_valid(dabt.s1ptw, fsc) ) - info.gpa = get_faulting_ipa(info.gva); + info.gpa = get_faulting_ipa(gva); else { - rc = gva_to_ipa(info.gva, &info.gpa, GV2M_READ); + rc = gva_to_ipa(gva, &info.gpa, GV2M_READ); /* * We may not be able to translate because someone is * playing with the Stage-2 page table of the domain. @@ -2040,7 +2041,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, .kind = dabt.s1ptw ? npfec_kind_in_gpt : npfec_kind_with_gla }; - p2m_mem_access_check(info.gpa, info.gva, npfec); + p2m_mem_access_check(info.gpa, gva, npfec); /* * The only way to get here right now is because of mem_access, * thus reinjecting the exception to the guest is never required. @@ -2077,8 +2078,8 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, } gdprintk(XENLOG_DEBUG, "HSR=0x%x pc=%#"PRIregister" gva=%#"PRIvaddr - " gpa=%#"PRIpaddr"\n", hsr.bits, regs->pc, info.gva, info.gpa); - inject_dabt_exception(regs, info.gva, hsr.len); + " gpa=%#"PRIpaddr"\n", hsr.bits, regs->pc, gva, info.gpa); + inject_dabt_exception(regs, gva, hsr.len); } static void enter_hypervisor_head(struct cpu_user_regs *regs) diff --git a/xen/include/asm-arm/mmio.h b/xen/include/asm-arm/mmio.h index c620eed4cd..37e2b7a707 100644 --- a/xen/include/asm-arm/mmio.h +++ b/xen/include/asm-arm/mmio.h @@ -29,7 +29,6 @@ typedef struct { struct hsr_dabt dabt; - vaddr_t gva; paddr_t gpa; } mmio_info_t; From patchwork Tue Dec 12 19:02:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121646 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508894qgn; Tue, 12 Dec 2017 11:04:53 -0800 (PST) X-Google-Smtp-Source: ACJfBosY452KRNvd/Mkl9eOiCb3lLufkLyUofLHZ1lkkXfD0uvcaG8/d5cWPw6m9MatTDzAivnhW X-Received: by 10.107.9.153 with SMTP id 25mr6407748ioj.214.1513105493464; Tue, 12 Dec 2017 11:04:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105493; cv=none; d=google.com; s=arc-20160816; b=he+Dh2ZcQ0FgNx41dLyXNnb7Oy47H1+elRB2ri+8PndJ5fOn0M7iSzjT8t3EU0UnLm NhnYoPM20pQ69yyodc+ndHW2ahKVJfXUMfTyrCw32BfRWOs0DbaPElFH2A4Ddod9DinI Z5vG7r27q9WI9n2voZ+wCOzMYnECS+PCzndrpYx6OeizlxcufLQ03nOnhOsW6rfktguu 1YLLg11xJF21F/vwSrI7Gt4WJ6tKzBspfeI56zQI5tGswzdSspJ6Kx6KudxUuXaMMcyz Mfq52zmCnkwAN0DFQRWh++5OSjNGB+lSWllVWoH3oTz9LYg4vSeAF/NK3kHeG0sC8Syr uwHA== 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=CZE+oyomRKKvRSlGYC1+McHASPRxcTY2mwBzixb5DKc=; b=mccomAI6RufXRJogN4cvCQlLYSasAbPAstbFZ6GSdyceeDKuEM9zRUfkrX/VozKW1i w3HhnpX1121VtXCZufiATi9AUzoLKMBz4i1/lJ1Bix9ROXwkns9IIvQtBQD7HUdkjYg5 0dSpuFLsfCgt8qdDTieE2FcIlFSxgqf/mtokydl51WZv2PTN8USnDPEazdis3chkTr5K URAPzK9GYI3nENB6Og19N3CacLFnAo01uNqMSOC3HOA8WsAM7DCK3fae5jIeC4TsL+zr S5VXKwWbQYbsnWRt07fF41Lda5U1cGKopl+HbKJoV3kJ/i8g8z9vzgsL1XFu/6S0XEhn N94A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=S5M0Qjms; 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 x96si189164ita.75.2017.12.12.11.04.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:53 -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=S5M0Qjms; 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 1eOppI-0002qE-Gb; Tue, 12 Dec 2017 19:02:48 +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 1eOppH-0002oF-6d for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:47 +0000 X-Inumbo-ID: f636b397-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wm0-x235.google.com (unknown [2a00:1450:400c:c09::235]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id f636b397-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:13 +0100 (CET) Received: by mail-wm0-x235.google.com with SMTP id f9so736252wmh.0 for ; Tue, 12 Dec 2017 11:02:45 -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=qPFzJq8aaVN4O0j6U4B5pbmSl19Ta7P3rtY7sc2bLOE=; b=S5M0QjmsdPfR/jHgW2Ab5SIjDGIy5fQWr4cHM3HmJzBxBnyfdQB6ZkX6U3cDKurrbS Dr8VB1dbA7nQfo2lG7wPZi4mN5TX42qJ3rLm9r7+gdWyX3RtKvqmCRqvki5jj0mWDIpO 9yYH4amD/1dPmdoJhBZQSRe+RGTTDw9k7gQHg= 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=qPFzJq8aaVN4O0j6U4B5pbmSl19Ta7P3rtY7sc2bLOE=; b=g1R+AJOYUaEV3FAjQpCBDfdJcmKobLuc9+wLUbBOmdRfXzjL/njotfc+5F+beDvAiz dTP4U5DNtz5uV3ld71tYSsW5vK9jSWQcYIwh0wAdlh7Aq+/Wxu7CfnvjwYdhrwRaxKte CbAhqXjTPJzEvbF/I91zt8s/+MBeSiY5fjuJ79koUyeK8AnccGPbGi2nmu7Ip4t9VyMF +qrjKuHS7MXh5wLeYVHjTJPmoDGcZDDqJ+I65UvxzwKlCqBaMKTZ8Q23axgzsZRyosGf xhlIfPlHEAOFT9nmARiPZrzGXyEI5tRyxAh273RIFR9MR8m3cZPeqCc6H+Dk5eTneHEU cecQ== X-Gm-Message-State: AKGB3mJowW1uFEA02VnO4KNQdCs37ftX+8565AXIcFUFR06cQWZseN/9 JOKew9ucpz4+BJZQFeyQbfXcKpbvAzI= X-Received: by 10.28.5.201 with SMTP id 192mr2513460wmf.142.1513105364086; Tue, 12 Dec 2017 11:02:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:43 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:11 +0000 Message-Id: <20171212190212.5535-16-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 15/16] xen/arm: traps: Move the definition of mmio_info_t in try_handle_mmio 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" mmio_info_t is currently filled by do_trap_data_guest_abort but only important when emulation an MMIO region. A follow-up patch will merge stage-2 prefetch abort and stage-2 data abort in a single helper. To prepare that, mmio_info_t is now filled by try_handle_mmio. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini dabt; + const struct hsr_dabt dabt = hsr.dabt; + mmio_info_t info = { + .gpa = gpa, + .dabt = dabt + }; int rc; /* stage-1 page table should never live in an emulated MMIO region */ @@ -1955,7 +1960,7 @@ static bool try_handle_mmio(struct cpu_user_regs *regs, if ( check_workaround_766422() && (regs->cpsr & PSR_THUMB) && dabt.write ) { - rc = decode_instruction(regs, &info->dabt); + rc = decode_instruction(regs, &info.dabt); if ( rc ) { gprintk(XENLOG_DEBUG, "Unable to decode instruction\n"); @@ -1963,7 +1968,7 @@ static bool try_handle_mmio(struct cpu_user_regs *regs, } } - return !!handle_mmio(info); + return !!handle_mmio(&info); } /* @@ -2001,7 +2006,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, const struct hsr_dabt dabt = hsr.dabt; int rc; vaddr_t gva; - mmio_info_t info; + paddr_t gpa; uint8_t fsc = hsr.dabt.dfsc & ~FSC_LL_MASK; mfn_t mfn; @@ -2012,15 +2017,13 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, if ( dabt.eat ) return __do_trap_serror(regs, true); - info.dabt = dabt; - gva = get_hfar(true /* is_data */); if ( hpfar_is_valid(dabt.s1ptw, fsc) ) - info.gpa = get_faulting_ipa(gva); + gpa = get_faulting_ipa(gva); else { - rc = gva_to_ipa(gva, &info.gpa, GV2M_READ); + rc = gva_to_ipa(gva, &gpa, GV2M_READ); /* * We may not be able to translate because someone is * playing with the Stage-2 page table of the domain. @@ -2041,7 +2044,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, .kind = dabt.s1ptw ? npfec_kind_in_gpt : npfec_kind_with_gla }; - p2m_mem_access_check(info.gpa, gva, npfec); + p2m_mem_access_check(gpa, gva, npfec); /* * The only way to get here right now is because of mem_access, * thus reinjecting the exception to the guest is never required. @@ -2053,7 +2056,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, * Attempt first to emulate the MMIO as the data abort will * likely happen in an emulated region. */ - if ( try_handle_mmio(regs, &info) ) + if ( try_handle_mmio(regs, hsr, gpa) ) { advance_pc(regs, hsr); return; @@ -2064,11 +2067,11 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, * with the Stage-2 page table. Walk the Stage-2 PT to check * if the entry exists. If it's the case, return to the guest */ - mfn = gfn_to_mfn(current->domain, gaddr_to_gfn(info.gpa)); + mfn = gfn_to_mfn(current->domain, gaddr_to_gfn(gpa)); if ( !mfn_eq(mfn, INVALID_MFN) ) return; - if ( try_map_mmio(gaddr_to_gfn(info.gpa)) ) + if ( try_map_mmio(gaddr_to_gfn(gpa)) ) return; break; @@ -2078,7 +2081,7 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, } gdprintk(XENLOG_DEBUG, "HSR=0x%x pc=%#"PRIregister" gva=%#"PRIvaddr - " gpa=%#"PRIpaddr"\n", hsr.bits, regs->pc, gva, info.gpa); + " gpa=%#"PRIpaddr"\n", hsr.bits, regs->pc, gva, gpa); inject_dabt_exception(regs, gva, hsr.len); } From patchwork Tue Dec 12 19:02:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 121632 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4508250qgn; Tue, 12 Dec 2017 11:04:23 -0800 (PST) X-Google-Smtp-Source: ACJfBosBNUOnGfPIaThlXkCH0CmWDB2arZAmcXgFUCKnmeXvZQdT0okwIXodcILHV5wvl2Fy/7Mv X-Received: by 10.107.182.196 with SMTP id g187mr6168615iof.225.1513105463769; Tue, 12 Dec 2017 11:04:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513105463; cv=none; d=google.com; s=arc-20160816; b=KtDrKpPoM7oKWhBqykV6JT4W9QaxmjHbt+6hbOZOyhMlw6guZvY2GQdTvcrl5WSuhP 1qcaSXkySlSveq3U7sgt91UQvcelVuZS+QDfcQmVRBGIF/BU0210kJybMTCx1JL9yLKP PXL7RVDYwjwuIPdTrdQBtZuhkGYD/b6IJz0CFZzrrNC/YCXR88bHH090ECVhlAArzfHo 7C16l/IyqxxhBGC+qiZZd5p50iQrDwVlyhbIUr8SuWvj8hevPkOKRJY12NBBw56VJacf 4IYtFtVht1rnbatLyPxVvw+gjVuu836hxZc/C5LUbBP9HSFjHrXFDHwokxU1ayShLIHm U/rw== 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=CWVnWPQp0AwJsq9oV9GFlaRglZWxR6tIUy5FGVDM/fk=; b=TSz3oFLXZN+LaMZC5plV5qfu51FwlrAS9a0IudN09OOSBWucfi1ASm3M5RGRWu3myZ ZndnLTUhY0ZdybWMC01YQtCX31igATeLLeYJSJ1UMytRcqA9AQa7uvuSFyhVpbUxksoK OZQzIyBDD0H3EuxJ7jiwTKTewLI8/LQovVAOR9BI5cQQktebIokAz4RyBylo5yXyaSBJ Wr1LAQVM0hIDb1Bw91Ym6Y+UudfNnXHJknRtSaGhHkj7sP864PZh0PMZgaWGK336clAx 2//u0nGehAnSzmFtR9ypcq1ohxtFWmhLGvvQAqScTMqV/UKnCxIwB9rqVy07UBbYJYsW 4BkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ZLSsQoW+; 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 f32si12696809iod.248.2017.12.12.11.04.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:04:23 -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=ZLSsQoW+; 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 1eOppJ-0002s9-OQ; Tue, 12 Dec 2017 19:02:49 +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 1eOppI-0002qB-Io for xen-devel@lists.xen.org; Tue, 12 Dec 2017 19:02:48 +0000 X-Inumbo-ID: f703e8b6-df6e-11e7-b4a6-bc764e045a96 Received: from mail-wm0-x242.google.com (unknown [2a00:1450:400c:c09::242]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id f703e8b6-df6e-11e7-b4a6-bc764e045a96; Tue, 12 Dec 2017 20:02:14 +0100 (CET) Received: by mail-wm0-x242.google.com with SMTP id 64so699056wme.3 for ; Tue, 12 Dec 2017 11:02:46 -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=Zv2pZFvHcS6glpBpgJMzZ5Xb62L+gscMb+BNHVIr3sE=; b=ZLSsQoW+kgNM+0mXRHWUo5T5DLYsVNFCi9QHRDZmQQtRMQdxxSqJ7wKL5AGeX3cI7X sMG+ql6dXzfJB8lYvNshe9fl3DfMBQLC82VjIHGMpqyxZTBjwZWFvgeBQd3/ucbDvLzO 49qsymU9LJnK8/mYPp/A7TtlQX01huq6Z0v7w= 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=Zv2pZFvHcS6glpBpgJMzZ5Xb62L+gscMb+BNHVIr3sE=; b=rQBYVGFRlfsiY6VzXcW4109QSb4klSGssbo5TuLpke77uVYGQod3P41+2HcdqhM6Hr yi2FOQJCo9C7DxAeBTok8f94XwJ9RsIYNJlF0v22Bv97aGOnp9gBvAOYhOOvQOrxRFQR U3dpwlTf0tNQHx9Xn56LX/x0O5RF3VIgHXucOJ1fpcSvTi5tAeEQfH5xaw9Ls+AVYufm I0cl0ir2gqZr8x5diWZ7yfL7zo2zLs/TEycKGQVua2ckGbjxQ5/MpvsaHHbuc00EBtSK 6rr7CvaITfvmeevq+Z8UD49trhD+fp5JkyHV0I2lqvE6ozqXG1NK/h8Q5OaqVYFseYGo dAXw== X-Gm-Message-State: AKGB3mL2tO7pUVEz+MZ5oAgWcfBTi6AbzCMHzkn//JuMl0f9o5sY75Ev Z54nB0ldJVaTIEP3I33VBmcALLO6uYA= X-Received: by 10.28.109.139 with SMTP id b11mr2501207wmi.85.1513105365077; Tue, 12 Dec 2017 11:02:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Dec 2017 11:02:44 -0800 (PST) From: Julien Grall To: xen-devel@lists.xen.org Date: Tue, 12 Dec 2017 19:02:12 +0000 Message-Id: <20171212190212.5535-17-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 16/16] xen/arm: traps: Merge do_trap_instr_abort_guest and do_trap_data_abort_guest 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 two helpers do_trap_instr_abort_guest and do_trap_data_abort_guest are used trap stage-2 abort. While the former is only handling prefetch abort and the latter data abort, they are very similarly and does not warrant to have separate helpers. For instance, merging the both will make easier to maintain stage-2 abort handling. So consolidate the two helpers in a new helper do_trap_stage2_abort. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2 - Fix the way to compute npfec.write_access --- xen/arch/arm/traps.c | 133 ++++++++++++++++----------------------------------- 1 file changed, 41 insertions(+), 92 deletions(-) diff --git a/xen/arch/arm/traps.c b/xen/arch/arm/traps.c index 082396c26d..013c1600ec 100644 --- a/xen/arch/arm/traps.c +++ b/xen/arch/arm/traps.c @@ -1861,79 +1861,6 @@ static inline bool hpfar_is_valid(bool s1ptw, uint8_t fsc) return s1ptw || (fsc == FSC_FLT_TRANS && !check_workaround_834220()); } -static void do_trap_instr_abort_guest(struct cpu_user_regs *regs, - const union hsr hsr) -{ - int rc; - register_t gva; - uint8_t fsc = hsr.iabt.ifsc & ~FSC_LL_MASK; - paddr_t gpa; - mfn_t mfn; - - gva = get_hfar(false /* is_data */); - - /* - * If this bit has been set, it means that this instruction abort is caused - * by a guest external abort. We can handle this instruction abort as guest - * SError. - */ - if ( hsr.iabt.eat ) - return __do_trap_serror(regs, true); - - - if ( hpfar_is_valid(hsr.iabt.s1ptw, fsc) ) - gpa = get_faulting_ipa(gva); - else - { - /* - * Flush the TLB to make sure the DTLB is clear before - * doing GVA->IPA translation. If we got here because of - * an entry only present in the ITLB, this translation may - * still be inaccurate. - */ - flush_tlb_local(); - - /* - * We may not be able to translate because someone is - * playing with the Stage-2 page table of the domain. - * Return to the guest. - */ - rc = gva_to_ipa(gva, &gpa, GV2M_READ); - if ( rc == -EFAULT ) - return; /* Try again */ - } - - switch ( fsc ) - { - case FSC_FLT_PERM: - { - const struct npfec npfec = { - .insn_fetch = 1, - .gla_valid = 1, - .kind = hsr.iabt.s1ptw ? npfec_kind_in_gpt : npfec_kind_with_gla - }; - - p2m_mem_access_check(gpa, gva, npfec); - /* - * The only way to get here right now is because of mem_access, - * thus reinjecting the exception to the guest is never required. - */ - return; - } - case FSC_FLT_TRANS: - /* - * The PT walk may have failed because someone was playing - * with the Stage-2 page table. Walk the Stage-2 PT to check - * if the entry exists. If it's the case, return to the guest - */ - mfn = gfn_to_mfn(current->domain, _gfn(paddr_to_pfn(gpa))); - if ( !mfn_eq(mfn, INVALID_MFN) ) - return; - } - - inject_iabt_exception(regs, gva, hsr.len); -} - static bool try_handle_mmio(struct cpu_user_regs *regs, const union hsr hsr, paddr_t gpa) @@ -1945,6 +1872,8 @@ static bool try_handle_mmio(struct cpu_user_regs *regs, }; int rc; + ASSERT(hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); + /* stage-1 page table should never live in an emulated MMIO region */ if ( dabt.s1ptw ) return false; @@ -2000,29 +1929,43 @@ static bool try_map_mmio(gfn_t gfn) return !map_regions_p2mt(d, gfn, 1, mfn, p2m_mmio_direct_c); } -static void do_trap_data_abort_guest(struct cpu_user_regs *regs, - const union hsr hsr) +static void do_trap_stage2_abort_guest(struct cpu_user_regs *regs, + const union hsr hsr) { - const struct hsr_dabt dabt = hsr.dabt; + /* + * The encoding of hsr_iabt is a subset of hsr_dabt. So use + * hsr_dabt to represent an abort fault. + */ + const struct hsr_xabt xabt = hsr.xabt; int rc; vaddr_t gva; paddr_t gpa; - uint8_t fsc = hsr.dabt.dfsc & ~FSC_LL_MASK; + uint8_t fsc = xabt.fsc & ~FSC_LL_MASK; mfn_t mfn; + bool is_data = (hsr.ec == HSR_EC_DATA_ABORT_LOWER_EL); /* - * If this bit has been set, it means that this data abort is caused - * by a guest external abort. We treat this data abort as guest SError. + * If this bit has been set, it means that this stage-2 abort is caused + * by a guest external abort. We treat this stage-2 abort as guest SError. */ - if ( dabt.eat ) + if ( xabt.eat ) return __do_trap_serror(regs, true); - gva = get_hfar(true /* is_data */); + gva = get_hfar(is_data); - if ( hpfar_is_valid(dabt.s1ptw, fsc) ) + if ( hpfar_is_valid(xabt.s1ptw, fsc) ) gpa = get_faulting_ipa(gva); else { + /* + * Flush the TLB to make sure the DTLB is clear before + * doing GVA->IPA translation. If we got here because of + * an entry only present in the ITLB, this translation may + * still be inaccurate. + */ + if ( !is_data ) + flush_tlb_local(); + rc = gva_to_ipa(gva, &gpa, GV2M_READ); /* * We may not be able to translate because someone is @@ -2038,10 +1981,11 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, case FSC_FLT_PERM: { const struct npfec npfec = { - .read_access = !dabt.write, - .write_access = dabt.write, + .insn_fetch = !is_data, + .read_access = is_data && !hsr.dabt.write, + .write_access = is_data && hsr.dabt.write, .gla_valid = 1, - .kind = dabt.s1ptw ? npfec_kind_in_gpt : npfec_kind_with_gla + .kind = xabt.s1ptw ? npfec_kind_in_gpt : npfec_kind_with_gla }; p2m_mem_access_check(gpa, gva, npfec); @@ -2055,8 +1999,10 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, /* * Attempt first to emulate the MMIO as the data abort will * likely happen in an emulated region. + * + * Note that emulated region cannot be executed */ - if ( try_handle_mmio(regs, hsr, gpa) ) + if ( is_data && try_handle_mmio(regs, hsr, gpa) ) { advance_pc(regs, hsr); return; @@ -2071,18 +2017,21 @@ static void do_trap_data_abort_guest(struct cpu_user_regs *regs, if ( !mfn_eq(mfn, INVALID_MFN) ) return; - if ( try_map_mmio(gaddr_to_gfn(gpa)) ) + if ( is_data && try_map_mmio(gaddr_to_gfn(gpa)) ) return; break; default: - gprintk(XENLOG_WARNING, "Unsupported DFSC: HSR=%#x DFSC=%#x\n", - hsr.bits, dabt.dfsc); + gprintk(XENLOG_WARNING, "Unsupported FSC: HSR=%#x DFSC=%#x\n", + hsr.bits, xabt.fsc); } gdprintk(XENLOG_DEBUG, "HSR=0x%x pc=%#"PRIregister" gva=%#"PRIvaddr " gpa=%#"PRIpaddr"\n", hsr.bits, regs->pc, gva, gpa); - inject_dabt_exception(regs, gva, hsr.len); + if ( is_data ) + inject_dabt_exception(regs, gva, hsr.len); + else + inject_iabt_exception(regs, gva, hsr.len); } static void enter_hypervisor_head(struct cpu_user_regs *regs) @@ -2215,11 +2164,11 @@ void do_trap_guest_sync(struct cpu_user_regs *regs) case HSR_EC_INSTR_ABORT_LOWER_EL: perfc_incr(trap_iabt); - do_trap_instr_abort_guest(regs, hsr); + do_trap_stage2_abort_guest(regs, hsr); break; case HSR_EC_DATA_ABORT_LOWER_EL: perfc_incr(trap_dabt); - do_trap_data_abort_guest(regs, hsr); + do_trap_stage2_abort_guest(regs, hsr); break; default: