From patchwork Thu Sep 15 11:28:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 76286 Delivered-To: patch@linaro.org Received: by 10.140.106.72 with SMTP id d66csp2387360qgf; Thu, 15 Sep 2016 04:31:01 -0700 (PDT) X-Received: by 10.107.163.132 with SMTP id m126mr18700619ioe.106.1473939061711; Thu, 15 Sep 2016 04:31:01 -0700 (PDT) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id b197si5487234ioe.46.2016.09.15.04.31.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Sep 2016 04:31:01 -0700 (PDT) Received-SPF: neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=neutral (google.com: 192.237.175.120 is neither permitted nor denied by best guess record for domain of xen-devel-bounces@lists.xen.org) smtp.mailfrom=xen-devel-bounces@lists.xen.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 1bkUqw-00052a-Fw; Thu, 15 Sep 2016 11:29:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bkUqu-0004yP-KM for xen-devel@lists.xen.org; Thu, 15 Sep 2016 11:29:12 +0000 Received: from [85.158.143.35] by server-4.bemta-6.messagelabs.com id 17/79-29421-7068AD75; Thu, 15 Sep 2016 11:29:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrOLMWRWlGSWpSXmKPExsVysyfVTZe97Va 4waIuboslHxezODB6HN39mymAMYo1My8pvyKBNWPS6t3MBZ+UKpZ+uMHSwDhboouRi0NIYBOj xLnlz1ggnNOMEt/+3WbuYuTkYBPQlLjz+RMTiC0iIC1x7fNlRpAiZoF2Rom1/b1gRcICeRKLN rSyg9gsAqoS7S3XwOK8Aq4Spy9uYAGxJQTkJE4em8zaxcjBwQkUX/JcFCQsJOAicezETrYJjN wLGBlWMWoUpxaVpRbpGpnoJRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhXrJefnbmIEepgBCHY wrlwXeIhRkoNJSZTXLe1WuBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ3n0tQDnBotT01Iq0zBxg qMGkJTh4lER4f4CkeYsLEnOLM9MhUqcYFaXEIfoEQBIZpXlwbbDwvsQoKyXMywh0iBBPQWpRb mYJqvwrRnEORiVhXtZWoCk8mXklcNNfAS1mAlq8Zc11kMUliQgpqQbGWf177VVqA3lKlv60Wf J5+fU8v9zcn8fm9lTbS/zY6XPf4XG38LvmR+IJd0Oz7d3qJ5hdz5u6rlhJJpK/gfXnjdezjlR ucBRqTJqiulf70k6960n97wVfFG7fcT8xqnRlZJ+/ZYjFs/lLP31YoKoUoae72LncefaWb+nf Xe+qlD6a+iuEWe2BEktxRqKhFnNRcSIAenvus2oCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-14.tower-21.messagelabs.com!1473938950!28049045!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 8.84; banners=-,-,- X-VirusChecked: Checked Received: (qmail 27486 invoked from network); 15 Sep 2016 11:29:10 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-14.tower-21.messagelabs.com with SMTP; 15 Sep 2016 11:29:10 -0000 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 47D7BAD7; Thu, 15 Sep 2016 04:29:10 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.218.32]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 465EC3F251; Thu, 15 Sep 2016 04:29:09 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 15 Sep 2016 12:28:34 +0100 Message-Id: <1473938919-31976-19-git-send-email-julien.grall@arm.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1473938919-31976-1-git-send-email-julien.grall@arm.com> References: <1473938919-31976-1-git-send-email-julien.grall@arm.com> Cc: proskurin@sec.in.tum.de, Julien Grall , sstabellini@kernel.org, steve.capper@arm.com, wei.chen@linaro.org Subject: [Xen-devel] [for-4.8][PATCH v2 18/23] xen/arm: p2m: Re-implement relinquish_p2m_mapping using p2m_{get, set}_entry X-BeenThere: xen-devel@lists.xen.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.xen.org Sender: "Xen-devel" The function relinquish_p2m_mapping can be re-implemented using p2m_{get,set}_entry by iterating over the range mapped and using the mapping order given by the callee. Given that the preemption was chosen arbitrarily, it is now done on every 512 iterations. Meaning that Xen may check more often if the function is preempted when there are no mappings. Finally drop the operation RELINQUISH in apply_* as nobody is using it anymore. Note that the functions could have been dropped in one go at the end, however I find easier to drop the operations one by one avoiding a big deletion in the patch that remove the last operation. Signed-off-by: Julien Grall --- Changes in v2: - Erase entry one by one as I have not time so far to check whether it is possible to avoid removing entry in the p2m. - Use gfn_next_boundary --- xen/arch/arm/p2m.c | 77 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 59 insertions(+), 18 deletions(-) diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c index 5f7aef0..ce09c4c 100644 --- a/xen/arch/arm/p2m.c +++ b/xen/arch/arm/p2m.c @@ -754,7 +754,6 @@ static int p2m_mem_access_radix_set(struct p2m_domain *p2m, gfn_t gfn, enum p2m_operation { INSERT, REMOVE, - RELINQUISH, MEMACCESS, }; @@ -1318,7 +1317,6 @@ static int apply_one_level(struct domain *d, break; - case RELINQUISH: case REMOVE: if ( !p2m_valid(orig_pte) ) { @@ -1502,17 +1500,6 @@ static int apply_p2m_changes(struct domain *d, { switch ( op ) { - case RELINQUISH: - /* - * Arbitrarily, preempt every 512 operations or 8192 nops. - * 512*P2M_ONE_PROGRESS == 8192*P2M_ONE_PROGRESS_NOP == 0x2000 - * This is set in preempt_count_limit. - * - */ - p2m->lowest_mapped_gfn = _gfn(addr >> PAGE_SHIFT); - rc = -ERESTART; - goto out; - case MEMACCESS: { /* @@ -1919,16 +1906,70 @@ int p2m_init(struct domain *d) return rc; } +/* + * The function will go through the p2m and remove page reference when it + * is required. The mapping will be removed from the p2m. + * + * XXX: See whether the mapping can be left intact in the p2m. + */ int relinquish_p2m_mapping(struct domain *d) { struct p2m_domain *p2m = &d->arch.p2m; - unsigned long nr; + unsigned long count = 0; + p2m_type_t t; + int rc = 0; + unsigned int order; + + /* Convenience alias */ + gfn_t start = p2m->lowest_mapped_gfn; + gfn_t end = p2m->max_mapped_gfn; + + p2m_write_lock(p2m); + + for ( ; gfn_x(start) < gfn_x(end); + start = gfn_next_boundary(start, order) ) + { + mfn_t mfn = p2m_get_entry(p2m, start, &t, NULL, &order); + + count++; + /* + * Arbitrarily preempt every 512 iterations. + */ + if ( !(count % 512) && hypercall_preempt_check() ) + { + rc = -ERESTART; + break; + } - nr = gfn_x(p2m->max_mapped_gfn) - gfn_x(p2m->lowest_mapped_gfn); + /* + * p2m_set_entry will take care of removing reference on page + * when it is necessary and removing the mapping in the p2m. + */ + if ( !mfn_eq(mfn, INVALID_MFN) ) + { + /* + * For valid mapping, the start will always be aligned as + * entry will be removed whilst relinquishing. + */ + rc = __p2m_set_entry(p2m, start, order, INVALID_MFN, + p2m_invalid, p2m_access_rwx); + if ( unlikely(rc) ) + { + printk(XENLOG_G_ERR "Unable to remove mapping gfn=%#"PRI_gfn" order=%u from the p2m of domain %d\n", gfn_x(start), order, d->domain_id); + break; + } + } + } - return apply_p2m_changes(d, RELINQUISH, p2m->lowest_mapped_gfn, nr, - INVALID_MFN, 0, p2m_invalid, - d->arch.p2m.default_access); + /* + * Update lowest_mapped_gfn so on the next call we still start where + * we stopped. + */ + p2m->lowest_mapped_gfn = start; + + p2m_write_unlock(p2m); + + return rc; } int p2m_cache_flush(struct domain *d, gfn_t start, unsigned long nr)