From patchwork Tue Dec 4 20:26:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 152857 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8503498ljp; Tue, 4 Dec 2018 12:29:33 -0800 (PST) X-Google-Smtp-Source: AFSGD/Uz8S/h+sJQofb4sxinExDBz0aF6S4oVG+bvu8fxFeAwrJiu5U0G7d0AqmehRtDn0UvvnOj X-Received: by 2002:a81:6308:: with SMTP id x8mr12781715ywb.438.1543955373565; Tue, 04 Dec 2018 12:29:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543955373; cv=none; d=google.com; s=arc-20160816; b=gYv1fMdrksqCV+Ci+D1stKEn1StT0atBheskf/2QQHjGey0EwatMw++bnkJBt20mb4 c3ALDJ7M1DtpWhB79PV3KNpTyBCY4BARtB8Ry9D6/6q1Jup7rA+LBZ1Va9pIEhr2qfAD v1fKmtYIzU1usr8C2EyHaW1CIBUZ5pOQQ9SKPHNYcCbIH2bjZ6NREFzRHYjW6zw0NYAr ZTwuMshLfWJ/l7P4ikMvYYXlbgQCHBjmqex46AtMxburNSdhLdGJk3YK9Ybor519n9h5 lXwEaY+dlWSn7goFKKB3YYEt+Bs91oJ38wrpvEgHNDj/Kx61+eh+Jj+GVeL2Cwpxsf3s 6CMA== 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=xF1Rh7fRzIRutYnOgc8LCBXEoPsh84q6ZLmCRMeKQjw=; b=C4/tgwralQ/KCZLj+qdmEap2n2bYOO2TaPIga/AwmbW8qN5mz/dWbIZLrE3LqBoA67 6m8KKWrK1+KVm7gTrxGR7ePhcUQFwkWXxmAkbN8em2O2A0rYY9P2Du6VD9VFJcjBbQlA kGsNV7HFOflPThwYQ3h0MRvs8vMmlhGwe4plCJZ1b+DUB5f75CqNAOiuIPFZ/G/r8dJ2 aJm43oCzrmpBB7UP5uK7cbeAH9upcAoQIEq2dVXkCwItzS6gPjeJgUYHS2bGVrt8t1ct H8vs2fS2wUAyIQima/otMuqbwpaU311cjyzqrESHQ7yPrrVpfOar9iNBnEQ1UiSqP9Rj 515g== 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 b14-v6si10624506ybn.14.2018.12.04.12.29.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 12:29:33 -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 1gUHI8-0008Hc-2X; Tue, 04 Dec 2018 20:27:36 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1gUHI6-0008E9-GU for xen-devel@lists.xenproject.org; Tue, 04 Dec 2018 20:27:34 +0000 X-Inumbo-ID: 07e54c18-f803-11e8-a27c-c3aaa8c709e1 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 07e54c18-f803-11e8-a27c-c3aaa8c709e1; Tue, 04 Dec 2018 20:27:33 +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 73D2C165C; Tue, 4 Dec 2018 12:27:33 -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 AB04B3F614; Tue, 4 Dec 2018 12:27:32 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 4 Dec 2018 20:26:49 +0000 Message-Id: <20181204202651.8836-16-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181204202651.8836-1-julien.grall@arm.com> References: <20181204202651.8836-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH for-4.12 v2 15/17] 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 --- 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) @@ -1573,22 +1596,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.