From patchwork Tue Dec 4 20:26:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 152856 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8503459ljp; Tue, 4 Dec 2018 12:29:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/U+azz4yVhqTX4oEQc0g9NGpqCtrIchw+0Sqax3W2poBhuJ0cBQAla61hTxAH8y8pfYXzdM X-Received: by 2002:a0d:e0c5:: with SMTP id j188mr22446632ywe.164.1543955370372; Tue, 04 Dec 2018 12:29:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543955370; cv=none; d=google.com; s=arc-20160816; b=yBighro5y+TuzEObstN4qUbRVSCUuj+xUJPC9VLSVbwuL3gmEsoqlAlFRVt/55XNBj 34mvFkXAcJMre2TkJDbmZRQ21bwSz1L66Ny80z956V6dFtKWlbP8/9aYFcfH8KFOuq2K AYZxGVVug+gMJVchYHsSkPjvFxV6BhV2w+C3RM6u+XK4HreIgVCyDFQ2zKsIoAJOMoYZ Pvhlz49lVBapxC1hki+BnU/jY0drEzERj2tle8EMiWvgzqaBenffKKZf8oHuhmmIDBAe uzFtc9HzvUD2MsPb3zpc8yfJeXcD6k+MWRd36XZtlimLHG8oLLkMDf0Gy1IesgDizuXp kLwg== 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=Vr+y0FMpx1US+45Xx7tZzfOP68kW7psyDSbkcc6c2YI=; b=eZY1JOTKWA/ntLljFNe9J0HbQxFKqpyiPQMbjgeMgZUVkHEClWh3hcsbgduMVh+pbr R3NR8iYN04uIWz0AUH0zbFBvGkJsns9Pd8WvuE+F1yJVA3B+MOY8BEz9Gqf5ib3/EW92 pX7JGMdBUhYcS/9lkZXZghUXmzLNA2QudKFxEpSUFyiIZHmqeGVq8rHH9tqQcL8oNJeV +9ov5sgHwcRND6Xnw1/y/R4MHH0R8Lh8njCsj+zP7/9wcNF711h0qZN2lMWquwYA7HIq N0AkMHGKURT0gEcJ8AjkmhBwv1/vwy6uGSB37R6uJFQ+pu3KwyB/9qWkXQ6qyI6v4Tyn LQKw== 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 y128-v6si10047797yba.206.2018.12.04.12.29.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 04 Dec 2018 12:29:30 -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 1gUHI5-0008Cy-IX; Tue, 04 Dec 2018 20:27:33 +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 1gUHI4-00089u-22 for xen-devel@lists.xenproject.org; Tue, 04 Dec 2018 20:27:32 +0000 X-Inumbo-ID: 06a477b6-f803-11e8-aab0-8787de5d20f2 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 06a477b6-f803-11e8-aab0-8787de5d20f2; Tue, 04 Dec 2018 20:27:31 +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 6737C168F; Tue, 4 Dec 2018 12:27:31 -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 9E81B3F614; Tue, 4 Dec 2018 12:27:30 -0800 (PST) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 4 Dec 2018 20:26:47 +0000 Message-Id: <20181204202651.8836-14-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 13/17] xen/arm: p2m: Rework 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" A follow-up patch will add support for preemption in p2m_cache_flush_range. Because of the complexity for the 2 loops, it would be necessary to add preemption in both of them. This can be avoided by merging the 2 loops together and still keeping the code fairly simple to read and extend. Signed-off-by: Julien Grall Reviewed-by: Stefano Stabellini --- Changes in v2: - Patch added --- xen/arch/arm/p2m.c | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index c713226561..db22b53bfd 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1527,7 +1527,8 @@ int relinquish_p2m_mapping(struct domain *d) int p2m_cache_flush_range(struct domain *d, gfn_t start, gfn_t end) { struct p2m_domain *p2m = p2m_get_hostp2m(d); - gfn_t next_gfn; + gfn_t next_block_gfn; + mfn_t mfn = INVALID_MFN; p2m_type_t t; unsigned int order; @@ -1542,24 +1543,45 @@ int p2m_cache_flush_range(struct domain *d, gfn_t start, gfn_t end) start = gfn_max(start, p2m->lowest_mapped_gfn); end = gfn_min(end, p2m->max_mapped_gfn); - for ( ; gfn_x(start) < gfn_x(end); start = next_gfn ) - { - mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL); + next_block_gfn = start; - next_gfn = gfn_next_boundary(start, order); - - /* Skip hole and non-RAM page */ - if ( mfn_eq(mfn, INVALID_MFN) || !p2m_is_any_ram(t) ) - continue; - - /* XXX: Implement preemption */ - while ( gfn_x(start) < gfn_x(next_gfn) ) + while ( gfn_x(start) < gfn_x(end) ) + { + /* + * We want to flush page by page as: + * - it may not be possible to map the full block (can be up to 1GB) + * in Xen memory + * - we may want to do fine grain preemption as flushing multiple + * page in one go may take a long time + * + * As p2m_get_entry is able to return the size of the mapping + * in the p2m, it is pointless to execute it for each page. + * + * We can optimize it by tracking the gfn of the next + * block. So we will only call p2m_get_entry for each block (can + * be up to 1GB). + */ + if ( gfn_eq(start, next_block_gfn) ) { - flush_page_to_ram(mfn_x(mfn), false); + mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL); + next_block_gfn = gfn_next_boundary(start, order); - start = gfn_add(start, 1); - mfn = mfn_add(mfn, 1); + /* + * The following regions can be skipped: + * - Hole + * - non-RAM + */ + if ( mfn_eq(mfn, INVALID_MFN) || !p2m_is_any_ram(t) ) + { + start = next_block_gfn; + continue; + } } + + flush_page_to_ram(mfn_x(mfn), false); + + start = gfn_add(start, 1); + mfn = mfn_add(mfn, 1); } invalidate_icache();