From patchwork Mon Oct 8 18:33:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 148421 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp3981957lji; Mon, 8 Oct 2018 11:36:10 -0700 (PDT) X-Google-Smtp-Source: ACcGV60n6M/QwQuAWwCT3m0eUSIoZdySALrK/5AxS9H98ho1vN8HTTFeHiiKEWTXkhD5oqhSiwFv X-Received: by 2002:a24:9d90:: with SMTP id f138-v6mr232925itd.57.1539023769984; Mon, 08 Oct 2018 11:36:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539023769; cv=none; d=google.com; s=arc-20160816; b=YMQnJxlKJROn7rRp5j5QPw+Of68N4iAyt1qfpr67t4WDLXL1nC58lo2ZbIOKdr/0YR b3fM4DZk4UUPMUxQjA8d816NnXdcbQ9HUAiao5Utm5HBFomPTvKCjCoAO6GLgPf4UpBl A+WMK5Lgo1nJg/s0CXdE60eL9sA5bLPjSnOuLKPXcaYWCaVEtFagX3fo6Kf81jm/+Uro RYA9VdaOKkrl69GnOlQbZRfN513kb1QsCc1YBzkoJemIsXjzzbb4yXcXQXkdCKSF5Os/ bo1SmvTTKaJhS63uUs05UcjsM4git/u/NZhMJSPPdGxVhnr3DhYZTh8oW1ltM9bcs+3+ ztbg== 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=g3rwvmlHgaV0Vu08ecPWtCsrKH6NcqQrqt+FLQKpElg=; b=Hx26nAe5SJGveN3Sb1nqifqUDJFkB6gFh0lRLhAwsVjPe1mEEBtJiyZPTU+WCAS9yg x478g6ZlxICxAKTcC8H3bC33++fbQb/EFSWGF80Qar/zptd1eOSz7uSKcFq8GLqoZ8Q/ vPe8H1+e8qVRuhjGyV9Jn56OWn2wY3L9r4unjJsaVwb4y+r+Wx5oOCQ/s3vU0Fn10eI9 Z+/Ob7dfobzuftvQnpyjt4mccg2no/rQ7E9OsSupfQdP0ND+/UYt5ooR3bys3JE8il5I HBMCfu53Pqf0i2DTpun7tXEZCMNrLPIdDchOiqh95924i4/Gkq3hsQjx1CVZk2T6eIQB tVsQ== 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 b73-v6si8327588itc.127.2018.10.08.11.36.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 08 Oct 2018 11:36:09 -0700 (PDT) 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 1g9aMJ-0005wM-Ic; Mon, 08 Oct 2018 18:34:23 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1g9aMI-0005tx-Bk for xen-devel@lists.xen.org; Mon, 08 Oct 2018 18:34:22 +0000 X-Inumbo-ID: 6b3e1984-cb28-11e8-a8a5-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id 6b3e1984-cb28-11e8-a8a5-bc764e045a96; Mon, 08 Oct 2018 20:31:49 +0200 (CEST) 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 ABCA2ED1; Mon, 8 Oct 2018 11:34:20 -0700 (PDT) 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 BE78B3F5B3; Mon, 8 Oct 2018 11:34:18 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Mon, 8 Oct 2018 19:33:52 +0100 Message-Id: <20181008183352.16291-17-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20181008183352.16291-1-julien.grall@arm.com> References: <20181008183352.16291-1-julien.grall@arm.com> Subject: [Xen-devel] [RFC 16/16] xen/arm: Track page accessed between batch of Set/Way operations 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: sstabellini@kernel.org, Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , andre.przywara@linaro.org, Tim Deegan , Julien Grall , Jan Beulich MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" At the moment, the implementation of Set/Way operations will go through all the entries of the guest P2M and flush them. However, this is very expensive and may render unusable a guest OS using them. For instance, Linux 32-bit will use Set/Way operations during secondary CPU bring-up. As the implementation is really expensive, it may be possible to hit the CPU bring-up timeout. To limit the Set/Way impact, we track what pages has been of the guest has been accessed between batch of Set/Way operations. This is done using bit[0] (aka valid bit) of the P2M entry. This patch adds a new per-arch helper is introduced to perform actions just before the guest is first unpaused. This will be used to invalidate the P2M to track access from the start of the guest. Signed-off-by: Julien Grall --- Cc: Stefano Stabellini Cc: Julien Grall Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Konrad Rzeszutek Wilk Cc: Tim Deegan Cc: Wei Liu --- xen/arch/arm/domain.c | 14 ++++++++++++++ xen/arch/arm/domain_build.c | 7 +++++++ xen/arch/arm/p2m.c | 32 +++++++++++++++++++++++++++++++- xen/arch/x86/domain.c | 4 ++++ xen/common/domain.c | 5 ++++- xen/include/asm-arm/p2m.h | 2 ++ xen/include/xen/domain.h | 2 ++ 7 files changed, 64 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c index feebbf5a92..f439f4657a 100644 --- a/xen/arch/arm/domain.c +++ b/xen/arch/arm/domain.c @@ -738,6 +738,20 @@ int arch_domain_soft_reset(struct domain *d) return -ENOSYS; } +void arch_domain_creation_finished(struct domain *d) +{ + /* + * To avoid flushing the whole guest RAM on the first Set/Way, we + * invalidate the P2M to track what has been accessed. + * + * This is only turned when IOMMU is not used or the page-table are + * not shared because bit[0] (e.g valid bit) unset will result + * IOMMU fault that could be not fixed-up. + */ + if ( !iommu_use_hap_pt(d) ) + p2m_invalidate_root(p2m_get_hostp2m(d)); +} + static int is_guest_pv32_psr(uint32_t psr) { switch (psr & PSR_MODE_MASK) diff --git a/xen/arch/arm/domain_build.c b/xen/arch/arm/domain_build.c index f552154e93..de96516faa 100644 --- a/xen/arch/arm/domain_build.c +++ b/xen/arch/arm/domain_build.c @@ -2249,6 +2249,13 @@ int __init construct_dom0(struct domain *d) v->is_initialised = 1; clear_bit(_VPF_down, &v->pause_flags); + /* + * XXX: We probably want a command line option to invalidate or not + * the P2M. This is because invalidating the P2M will not work with + * IOMMU, however if this is not done there will be an impact. + */ + p2m_invalidate_root(p2m_get_hostp2m(d)); + return 0; } diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index a3d4c563b1..8e0c31d7ac 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -1079,6 +1079,22 @@ static void p2m_invalidate_table(struct p2m_domain *p2m, mfn_t mfn) p2m->need_flush = true; } +/* + * Invalidate all entries in the root page-tables. This is + * useful to get fault on entry and do an action. + */ +void p2m_invalidate_root(struct p2m_domain *p2m) +{ + unsigned int i; + + p2m_write_lock(p2m); + + for ( i = 0; i < P2M_ROOT_LEVEL; i++ ) + p2m_invalidate_table(p2m, page_to_mfn(p2m->root + i)); + + p2m_write_unlock(p2m); +} + bool p2m_resolve_translation_fault(struct domain *d, gfn_t gfn) { struct p2m_domain *p2m = p2m_get_hostp2m(d); @@ -1539,7 +1555,8 @@ int p2m_cache_flush_range(struct domain *d, gfn_t start, gfn_t end) for ( ; gfn_x(start) < gfn_x(end); start = next_gfn ) { - mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, NULL); + bool valid; + mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order, &valid); next_gfn = gfn_next_boundary(start, order); @@ -1547,6 +1564,13 @@ 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) ) continue; + /* + * Page with valid bit (bit [0]) unset does not need to be + * cleaned + */ + if ( !valid ) + continue; + /* XXX: Implement preemption */ while ( gfn_x(start) < gfn_x(next_gfn) ) { @@ -1571,6 +1595,12 @@ static void p2m_flush_vm(struct vcpu *v) /* XXX: Handle preemption */ p2m_cache_flush_range(v->domain, p2m->lowest_mapped_gfn, p2m->max_mapped_gfn); + + /* + * Invalidate the p2m to track which page was modified by the guest + * between call of p2m_flush_vm(). + */ + p2m_invalidate_root(p2m); } /* diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 9371efc8c7..2b6d1c01a1 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -723,6 +723,10 @@ int arch_domain_soft_reset(struct domain *d) return ret; } +void arch_domain_creation_finished(struct domain *d) +{ +} + /* * These are the masks of CR4 bits (subject to hardware availability) which a * PV guest may not legitimiately attempt to modify. diff --git a/xen/common/domain.c b/xen/common/domain.c index 65151e2ac4..b402c635f9 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -1100,8 +1100,11 @@ int domain_unpause_by_systemcontroller(struct domain *d) * Creation is considered finished when the controller reference count * first drops to 0. */ - if ( new == 0 ) + if ( new == 0 && !d->creation_finished ) + { d->creation_finished = true; + arch_domain_creation_finished(d); + } domain_unpause(d); diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h index c470f062db..2a4652e7f4 100644 --- a/xen/include/asm-arm/p2m.h +++ b/xen/include/asm-arm/p2m.h @@ -225,6 +225,8 @@ int p2m_set_entry(struct p2m_domain *p2m, p2m_type_t t, p2m_access_t a); +void p2m_invalidate_root(struct p2m_domain *p2m); + /* * Clean & invalidate caches corresponding to a region [start,end) of guest * address space. diff --git a/xen/include/xen/domain.h b/xen/include/xen/domain.h index 5e393fd7f2..8d95ad4bf1 100644 --- a/xen/include/xen/domain.h +++ b/xen/include/xen/domain.h @@ -70,6 +70,8 @@ void arch_domain_unpause(struct domain *d); int arch_domain_soft_reset(struct domain *d); +void arch_domain_creation_finished(struct domain *d); + void arch_p2m_set_access_required(struct domain *d, bool access_required); int arch_set_info_guest(struct vcpu *, vcpu_guest_context_u);