From patchwork Fri Dec 14 11:58:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 153827 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp1972841ljp; Fri, 14 Dec 2018 04:01:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/XJh/5g1qSUy7QaNzhEPR6+jtnzzUeSEohNl01MCbzczPbTflVgrKuhIHAykHvUE5jhBNl/ X-Received: by 2002:a81:6d46:: with SMTP id i67mr2625173ywc.1.1544788872271; Fri, 14 Dec 2018 04:01:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544788872; cv=none; d=google.com; s=arc-20160816; b=cZlPtwfYPijUXyNs+96xc6I6M2Mu+AvqlHGkIODAxGN4gqf7Co/26Yo0TcXqixf3TX x43SC7fkO9l87YirMN+vxK4+3KGWZSYfHUy75BlOaYEKqJfib+qVR8sNZd6wU89y5EXv fN3bvgn3+WmmizEWTDmFsSD2eXrX8P2oWD+2PkR90+PDPm67q7FoZQe0hOtD81rmiLn6 IrTQWlBpFy+Ry2LB4HlPsMNgFfLAX+htWPJsIUOmthetMbtOOAA6c6Z/OLkKJPL+VNS3 vc6KKgwczm31ooWaZN2GsgdyuEgQj1fC5IE5Kq/Lzsz9xX/QO+q2mhVsh9qCgss+AqEW vCzg== 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:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=Al+qjQT1iLXqzA4Ecolhn87M3Mkl7jk1Vvik4XS+GK8=; b=qTI4A/6lO4r4cSO1w65sXZBST/6Yy775kluVpBIZXkTiAsQhR227rqQ2IApGHXRLKb yPnufA6Il4JDK9/gJLnZHI1EtpCsrgSC+ohour2dXPMl3CVMFi2wtV6/Nh5ybdnCr/Y6 oXT6gmCtEMR9P8Ai5qbeUhDb0RP+WkwWFkscVWaSF90mad6tGCN9zPtl/cAhDYUDuDlA Z4cPkGj+p7u+2hH3Admjgoap10hZ+VvHxFs2aEKrrBXP+Vjdslge1SaoF9Sg4t1hN/PY IOh/ag76Mnc5UtxFw2fnSWIowyKTQyCaIzERWk3hwUCj4Y9xkO2EG02Ds/5232Z2JF9S zFJQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id t190-v6si2438227ybf.478.2018.12.14.04.01.11 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Dec 2018 04:01:12 -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; 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 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gXm7X-0001IQ-9g; Fri, 14 Dec 2018 11:59:07 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gXm7W-0001Hq-OL for xen-devel@lists.xenproject.org; Fri, 14 Dec 2018 11:59:06 +0000 X-Inumbo-ID: a79143f4-ff97-11e8-8e1d-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id a79143f4-ff97-11e8-8e1d-bc764e045a96; Fri, 14 Dec 2018 11:59:05 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D28B215AD; Fri, 14 Dec 2018 03:59:04 -0800 (PST) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 15CB93F575; Fri, 14 Dec 2018 03:59:03 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Fri, 14 Dec 2018 11:58:53 +0000 Message-Id: <20181214115855.6713-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181214115855.6713-1-julien.grall@arm.com> References: <20181214115855.6713-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v3 3/5] xen/arm: p2m: Add support for preemption in p2m_cache_flush_range X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Julien Grall , sstabellini@kernel.org MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" p2m_cache_flush_range does not yet support preemption, this may be an issue as cleaning the cache can take a long time. While the current caller (XEN_DOMCTL_cacheflush) does not stricly require preemption, this will be necessary for new caller in a follow-up patch. The preemption implemented is quite simple, a counter is incremented by: - 1 on region skipped - 10 for each page requiring a flush When the counter reach 512 or above, we will check if preemption is needed. If not, the counter will be reset to 0. If yes, the function will stop, update start (to allow resuming later on) and return -ERESTART. This allows the caller to decide how the preemption will be done. For now, XEN_DOMCTL_cacheflush will continue to ignore the preemption. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Patch added --- xen/arch/arm/domctl.c | 8 +++++++- xen/arch/arm/p2m.c | 35 ++++++++++++++++++++++++++++++++--- xen/include/asm-arm/p2m.h | 4 +++- 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c index 20691528a6..9da88b8c64 100644 --- a/xen/arch/arm/domctl.c +++ b/xen/arch/arm/domctl.c @@ -54,6 +54,7 @@ long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, { gfn_t s = _gfn(domctl->u.cacheflush.start_pfn); gfn_t e = gfn_add(s, domctl->u.cacheflush.nr_pfns); + int rc; if ( domctl->u.cacheflush.nr_pfns > (1U<= 512 ) + { + if ( softirq_pending(smp_processor_id()) ) + { + rc = -ERESTART; + break; + } + count = 0; + } + /* * We want to flush page by page as: * - it may not be possible to map the full block (can be up to 1GB) @@ -1568,22 +1591,28 @@ int p2m_cache_flush_range(struct domain *d, gfn_t start, gfn_t end) if ( mfn_eq(mfn, INVALID_MFN) || !p2m_is_any_ram(t) ) { + count++; start = next_block_gfn; continue; } } + count += 10; + flush_page_to_ram(mfn_x(mfn), false); start = gfn_add(start, 1); mfn = mfn_add(mfn, 1); } - invalidate_icache(); + if ( rc != -ERESTART ) + invalidate_icache(); p2m_read_unlock(p2m); - return 0; + *pstart = start; + + return rc; } mfn_t gfn_to_mfn(struct domain *d, gfn_t gfn) diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index 7c1d930b1d..a633e27cc9 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -232,8 +232,10 @@ bool p2m_resolve_translation_fault(struct domain *d, gfn_t gfn); /* * Clean & invalidate caches corresponding to a region [start,end) of guest * address space. + * + * start will get updated if the function is preempted. */ -int p2m_cache_flush_range(struct domain *d, gfn_t start, gfn_t end); +int p2m_cache_flush_range(struct domain *d, gfn_t *pstart, gfn_t end); /* * Map a region in the guest p2m with a specific p2m type.