From patchwork Thu Sep 21 12:40:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 113242 Delivered-To: patch@linaro.org Received: by 10.80.163.150 with SMTP id s22csp1845932edb; Thu, 21 Sep 2017 05:42:50 -0700 (PDT) X-Google-Smtp-Source: AOwi7QAXbWC3i1wUipb01zvD2BpstvWH6ETA5ZyDilN/IWv4uETv4hUp/123PWD0BzWgMA5eXYdp X-Received: by 10.107.157.129 with SMTP id g123mr2918980ioe.182.1505997770691; Thu, 21 Sep 2017 05:42:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505997770; cv=none; d=google.com; s=arc-20160816; b=J/Qr9cgw7yXfxAY8DUsBXfRa6eKyvKQLP2vNiP86PFQAKHMhDt3+isUuOLLA8aRN91 ACghQ3X3S0QU2Io8OU4vFa1dav+MEK41b4N9FPsVyBlmK1lAHSEzRiJC7j5EmtfIMeEJ dmXTDwSGVkz2PKymO0l8c6bYgXkgxo3EUkVMlAGm5YhRmikZJlI0znmvDLtGrVMtI0Sn hW0nt+HHdfHyzy6jZUDO8pgNpofnbytQKVPp75dewRnSldcq94EsN2j/FtYMDVMYXJm8 6j92ysOPTvJOCdJN0Q2TNIRPGCNb5p+1k9WBXLCJpggfr2mNP4T46vwr9gFp6Aly1rmJ BZIw== 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 :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:cc:references:in-reply-to:message-id:date:to :from:arc-authentication-results; bh=cuXsr75AteBATzUw8p67P7KSjnRWWXhpXj9lBsHy9YU=; b=fEapXmVwv1sq3dSgwSwTKZ2xOM/+gYABtlUCbvIMlfUP40AD5N2eeJrd3RBYAavmtp I1Ued+McyI50vYtq17h1201euDnhfUqiycg+pY+mtlEoY1Ym/ztGu7yxJt/GWKlTTEmF B9/+6ElNKH8v3oBSDqJ5s1nDEC0Eor5v5ygmWrzrdkp3PtomfiFExAaml8nzeP9unrUQ xs8WRCIauJFM3JP0yPqAAHkQNe0/gONo/1PJ3F7irrCmiVMZQdEehRJCZiQhQPa6e2RS acZJBvef6Ts7MYXXpp/95ZHYzL9MOw+koJA70IvBGewOSdQ8GbDZez+Ce5OMFOtnE2uT BPSQ== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id x7si1495647ite.61.2017.09.21.05.42.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 05:42:50 -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 1dv0ml-0001H0-2E; Thu, 21 Sep 2017 12:40:55 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv0mj-0001Ck-A7 for xen-devel@lists.xen.org; Thu, 21 Sep 2017 12:40:53 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id 07/A3-03610-553B3C95; Thu, 21 Sep 2017 12:40:53 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrCLMWRWlGSWpSXmKPExsVysyfVTTdw8+F Ig/nLuSyWfFzM4sDocXT3b6YAxijWzLyk/IoE1oyz+yexFHxLrzjzYTd7A+N0jy5GLg4hgc2M EheXX2GCcE4zSnw9P4Wli5GTg01AU+LO509MILaIgLTEtc+XGUGKmAUWM0p83t/LDJIQFrCRu LNqLSOIzSKgKvHjxHmwOK+AhcSBk6/AbAkBeYldbRdZQWxOAUuJtsPfwGwhoJpfE06wTmDkXs DIsIpRozi1qCy1SNfIXC+pKDM9oyQ3MTNH19DATC83tbg4MT01JzGpWC85P3cTI9DHDECwg3H x2sBDjJIcTEqivAHuhyOF+JLyUyozEosz4otKc1KLDzHKcHAoSfCm+QDlBItS01Mr0jJzgMEG k5bg4FES4WUBSfMWFyTmFmemQ6ROMepydNy8+4dJiCUvPy9VSpzXBKRIAKQoozQPbgQs8C8xy koJ8zICHSXEU5BalJtZgir/ilGcg1FJmNcRZApPZl4J3KZXQEcwAR2RveEAyBEliQgpqQbG3U 5nP1/RCOn9lrplRwfHY8kyEcY69nqe+MJTjJJz9T+3K54JF8hRcuQ81iR2uGPNtyMb+r9pG4v k11SevVV9w5aDi4Hx47kLAnsWPjT5++ii5LmUrGXp23M978UtXfo0LSfo8fHpi+s/3z4v8OhH ovuhDcENWY9/S7AXbFPZ2/P/oYPr1OAFSizFGYmGWsxFxYkAP90GgncCAAA= X-Env-Sender: julien.grall@arm.com X-Msg-Ref: server-6.tower-21.messagelabs.com!1505997648!60906395!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 61800 invoked from network); 21 Sep 2017 12:40:48 -0000 Received: from usa-sjc-mx-foss1.foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-6.tower-21.messagelabs.com with SMTP; 21 Sep 2017 12:40:48 -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 31C5C1529; Thu, 21 Sep 2017 05:40:48 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.206.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 228D33F58C; Thu, 21 Sep 2017 05:40:46 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xen.org Date: Thu, 21 Sep 2017 13:40:23 +0100 Message-Id: <20170921124035.2410-5-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170921124035.2410-1-julien.grall@arm.com> References: <20170921124035.2410-1-julien.grall@arm.com> Cc: George Dunlap , Andrew Cooper , Julien Grall , Jan Beulich Subject: [Xen-devel] [PATCH v2 04/16] xen/x86: p2m-pod: Fix coding style 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" Also take the opportunity to: - move from 1 << * to 1UL << *. - use unsigned when possible - move from unsigned int -> unsigned long for some induction variables Signed-off-by: Julien Grall Acked-by: Andrew Cooper Reviewed-by: Wei Liu Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Jan Beulich Cc: Andrew Cooper Changes in v2: - Add Andrew's acked-by --- xen/arch/x86/mm/p2m-pod.c | 102 +++++++++++++++++++++++----------------------- 1 file changed, 52 insertions(+), 50 deletions(-) diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 6f045081b5..f04d6e03e2 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -60,7 +60,7 @@ p2m_pod_cache_add(struct p2m_domain *p2m, struct page_info *page, unsigned int order) { - int i; + unsigned long i; struct page_info *p; struct domain *d = p2m->domain; @@ -70,23 +70,24 @@ p2m_pod_cache_add(struct p2m_domain *p2m, mfn = page_to_mfn(page); /* Check to make sure this is a contiguous region */ - if( mfn_x(mfn) & ((1 << order) - 1) ) + if ( mfn_x(mfn) & ((1UL << order) - 1) ) { printk("%s: mfn %lx not aligned order %u! (mask %lx)\n", __func__, mfn_x(mfn), order, ((1UL << order) - 1)); return -1; } - for(i=0; i < 1 << order ; i++) { + for ( i = 0; i < 1UL << order ; i++) + { struct domain * od; p = mfn_to_page(_mfn(mfn_x(mfn) + i)); od = page_get_owner(p); - if(od != d) + if ( od != d ) { printk("%s: mfn %lx expected owner d%d, got owner d%d!\n", __func__, mfn_x(mfn), d->domain_id, - od?od->domain_id:-1); + od ? od->domain_id : -1); return -1; } } @@ -99,12 +100,12 @@ p2m_pod_cache_add(struct p2m_domain *p2m, * guaranteed to be zero; but by reclaiming zero pages, we implicitly * promise to provide zero pages. So we scrub pages before using. */ - for ( i = 0; i < (1 << order); i++ ) + for ( i = 0; i < (1UL << order); i++ ) clear_domain_page(_mfn(mfn_x(page_to_mfn(page)) + i)); /* First, take all pages off the domain list */ lock_page_alloc(p2m); - for(i=0; i < 1 << order ; i++) + for ( i = 0; i < 1UL << order ; i++ ) { p = page + i; page_list_del(p, &d->page_list); @@ -128,7 +129,7 @@ p2m_pod_cache_add(struct p2m_domain *p2m, default: BUG(); } - p2m->pod.count += 1L << order; + p2m->pod.count += 1UL << order; return 0; } @@ -140,7 +141,7 @@ static struct page_info * p2m_pod_cache_get(struct p2m_domain *p2m, unsigned int order) { struct page_info *p = NULL; - int i; + unsigned long i; ASSERT(pod_locked_by_me(p2m)); @@ -162,7 +163,7 @@ static struct page_info * p2m_pod_cache_get(struct p2m_domain *p2m, p = page_list_remove_head(&p2m->pod.super); mfn = mfn_x(page_to_mfn(p)); - for ( i=0; ipod.single); @@ -174,12 +175,12 @@ static struct page_info * p2m_pod_cache_get(struct p2m_domain *p2m, case PAGE_ORDER_2M: BUG_ON( page_list_empty(&p2m->pod.super) ); p = page_list_remove_head(&p2m->pod.super); - p2m->pod.count -= 1 << order; + p2m->pod.count -= 1UL << order; break; case PAGE_ORDER_4K: BUG_ON( page_list_empty(&p2m->pod.single) ); p = page_list_remove_head(&p2m->pod.single); - p2m->pod.count -= 1; + p2m->pod.count -= 1UL; break; default: BUG(); @@ -187,7 +188,7 @@ static struct page_info * p2m_pod_cache_get(struct p2m_domain *p2m, /* Put the pages back on the domain page_list */ lock_page_alloc(p2m); - for ( i = 0 ; i < (1 << order); i++ ) + for ( i = 0 ; i < (1UL << order); i++ ) { BUG_ON(page_get_owner(p + i) != p2m->domain); page_list_add_tail(p + i, &p2m->domain->page_list); @@ -251,7 +252,8 @@ p2m_pod_set_cache_target(struct p2m_domain *p2m, unsigned long pod_target, int p while ( pod_target < p2m->pod.count ) { struct page_info * page; - int order, i; + unsigned int order; + unsigned long i; if ( (p2m->pod.count - pod_target) > SUPERPAGE_PAGES && !page_list_empty(&p2m->pod.super) ) @@ -264,10 +266,10 @@ p2m_pod_set_cache_target(struct p2m_domain *p2m, unsigned long pod_target, int p ASSERT(page != NULL); /* Then free them */ - for ( i = 0 ; i < (1 << order) ; i++ ) + for ( i = 0 ; i < (1UL << order) ; i++ ) { /* Copied from common/memory.c:guest_remove_page() */ - if ( unlikely(!get_page(page+i, d)) ) + if ( unlikely(!get_page(page + i, d)) ) { gdprintk(XENLOG_INFO, "Bad page free for domain %u\n", d->domain_id); ret = -EINVAL; @@ -275,12 +277,12 @@ p2m_pod_set_cache_target(struct p2m_domain *p2m, unsigned long pod_target, int p } if ( test_and_clear_bit(_PGT_pinned, &(page+i)->u.inuse.type_info) ) - put_page_and_type(page+i); + put_page_and_type(page + i); if ( test_and_clear_bit(_PGC_allocated, &(page+i)->count_info) ) - put_page(page+i); + put_page(page + i); - put_page(page+i); + put_page(page + i); if ( preemptible && pod_target != p2m->pod.count && hypercall_preempt_check() ) @@ -513,7 +515,7 @@ p2m_pod_decrease_reservation(struct domain *d, xen_pfn_t gpfn, unsigned int order) { - int ret=0; + int ret = 0; unsigned long i, n; struct p2m_domain *p2m = p2m_get_hostp2m(d); bool_t steal_for_cache; @@ -556,7 +558,7 @@ p2m_pod_decrease_reservation(struct domain *d, } /* No populate-on-demand? Don't need to steal anything? Then we're done!*/ - if(!pod && !steal_for_cache) + if ( !pod && !steal_for_cache ) goto out_unlock; if ( !nonpod ) @@ -567,7 +569,7 @@ p2m_pod_decrease_reservation(struct domain *d, */ p2m_set_entry(p2m, gpfn, INVALID_MFN, order, p2m_invalid, p2m->default_access); - p2m->pod.entry_count-=(1<pod.entry_count -= 1UL << order; BUG_ON(p2m->pod.entry_count < 0); ret = 1; goto out_entry_check; @@ -625,7 +627,7 @@ p2m_pod_decrease_reservation(struct domain *d, * avoid breaking up superpages. */ struct page_info *page; - unsigned int j; + unsigned long j; ASSERT(mfn_valid(mfn)); @@ -753,13 +755,13 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, unsigned long gfn) } /* Now, do a quick check to see if it may be zero before unmapping. */ - for ( i=0; icount_info & PGC_count_mask) > 1 ) @@ -790,12 +792,12 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, unsigned long gfn) } /* Finally, do a full zero-check */ - for ( i=0; i < SUPERPAGE_PAGES; i++ ) + for ( i = 0; i < SUPERPAGE_PAGES; i++ ) { map = map_domain_page(_mfn(mfn_x(mfn0) + i)); - for ( j=0; jdomain; int i, j; @@ -856,7 +858,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) max_ref++; /* First, get the gfn list, translate to mfns, and map the pages. */ - for ( i=0; iget_entry(p2m, gfns[i], types + i, &a, 0, NULL, NULL); @@ -877,14 +879,14 @@ p2m_pod_zero_check(struct p2m_domain *p2m, unsigned long *gfns, int count) * Then, go through and check for zeroed pages, removing write permission * for those with zeroes. */ - for ( i=0; idefault_access); + types[i], p2m->default_access); } else { @@ -968,7 +970,7 @@ static void p2m_pod_emergency_sweep(struct p2m_domain *p2m) { unsigned long gfns[POD_SWEEP_STRIDE]; - unsigned long i, j=0, start, limit; + unsigned long i, j = 0, start, limit; p2m_type_t t; @@ -985,7 +987,7 @@ p2m_pod_emergency_sweep(struct p2m_domain *p2m) * careful about spinlock recursion limits and POD_SWEEP_STRIDE. */ p2m_lock(p2m); - for ( i=p2m->pod.reclaim_single; i > 0 ; i-- ) + for ( i = p2m->pod.reclaim_single; i > 0 ; i-- ) { p2m_access_t a; (void)p2m->get_entry(p2m, i, &t, &a, 0, NULL, NULL); @@ -1079,7 +1081,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, unsigned long gfn, struct page_info *p = NULL; /* Compiler warnings */ unsigned long gfn_aligned; mfn_t mfn; - int i; + unsigned long i; ASSERT(gfn_locked_by_me(p2m, gfn)); pod_lock(p2m); @@ -1143,7 +1145,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, unsigned long gfn, mfn = page_to_mfn(p); - BUG_ON((mfn_x(mfn) & ((1 << order)-1)) != 0); + BUG_ON((mfn_x(mfn) & ((1UL << order) - 1)) != 0); gfn_aligned = (gfn >> order) << order; @@ -1156,7 +1158,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, unsigned long gfn, paging_mark_dirty(d, mfn_add(mfn, i)); } - p2m->pod.entry_count -= (1 << order); + p2m->pod.entry_count -= (1UL << order); BUG_ON(p2m->pod.entry_count < 0); pod_eager_record(p2m, gfn_aligned, order); @@ -1198,8 +1200,8 @@ remap_and_retry: * NOTE: In a p2m fine-grained lock scenario this might * need promoting the gfn lock from gfn->2M superpage. */ - gfn_aligned = (gfn>>order)<> order) << order; + for ( i = 0; i < (1UL << order); i++ ) p2m_set_entry(p2m, gfn_aligned + i, INVALID_MFN, PAGE_ORDER_4K, p2m_populate_on_demand, p2m->default_access); if ( tb_init_done ) @@ -1262,7 +1264,7 @@ guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn, if ( rc == 0 ) { pod_lock(p2m); - p2m->pod.entry_count += 1 << order; + p2m->pod.entry_count += 1UL << order; p2m->pod.entry_count -= pod_count; BUG_ON(p2m->pod.entry_count < 0); pod_unlock(p2m);