From patchwork Thu Jul 20 16:04:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Liu X-Patchwork-Id: 9855295 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 23D5860392 for ; Thu, 20 Jul 2017 16:07:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14A1728678 for ; Thu, 20 Jul 2017 16:07:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 098CE286DE; Thu, 20 Jul 2017 16:07:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 99DF028678 for ; Thu, 20 Jul 2017 16:06:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYDwJ-0000Ep-HA; Thu, 20 Jul 2017 16:04:35 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dYDwH-0000DT-T0 for xen-devel@lists.xenproject.org; Thu, 20 Jul 2017 16:04:33 +0000 Received: from [85.158.139.211] by server-16.bemta-5.messagelabs.com id CA/65-01712-094D0795; Thu, 20 Jul 2017 16:04:32 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprBIsWRWlGSWpSXmKPExsXitHRDpO6EKwW RBseX8ll83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBlHZt1iLbigWbGw+z17A2OPbBcjJ4eEgL/E 3ad7mUBsNgFliZ+dvWwgtoiAnkTTgeeMXYxcHMwCcxglps7tYgRJCAvYShx4O5MdxGYRUJX4f f8BWJxXwFxi4a69rBBD5SV2tV0EszkFLCTW/PoKtkAIqGbz/vksELaCRMf0Y0wQvYISJ2c+AY szC0hIHHzxgnkCI+8sJKlZSFILGJlWMWoUpxaVpRbpGhnpJRVlpmeU5CZm5ugaGpjq5aYWFye mp+YkJhXrJefnbmIEhk89AwPjDsY97X6HGCU5mJREeVkCCyKF+JLyUyozEosz4otKc1KLDzHK cHAoSfD+vASUEyxKTU+tSMvMAQYyTFqCg0dJhNfxMlCat7ggMbc4Mx0idYrRmKNjxs9vTByvJ vz/xiTEkpeflyolzvsZZJIASGlGaR7cIFiEXWKUlRLmZWRgYBDiKUgtys0sQZV/xSjOwagkzB sNspAnM68Ebt8roFOYgE555AZ2SkkiQkqqgVFovYNNN+umQ8JSCmZ/Xp9v3Kjj//Wt6KYnTQE LWJLaOZe3bVl7+6H4o4PtP+dEOecZ8v07JWdj4y7ZZ9b50kJ0smXcJU8lE0v5V9xObGGuiYG3 5bimGmycY5saO43LcSbj1IjYNPOzkfcq2wyX7PxmMukda26fgNK6ZVNutobuebfgYJJrqBJLc UaioRZzUXEiAIIdF3SrAgAA X-Env-Sender: prvs=3674d857a=wei.liu2@citrix.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1500566668!100959585!2 X-Originating-IP: [66.165.176.89] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni44OSA9PiAyMDMwMDc=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51934 invoked from network); 20 Jul 2017 16:04:31 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-6.tower-206.messagelabs.com with RC4-SHA encrypted SMTP; 20 Jul 2017 16:04:31 -0000 X-IronPort-AV: E=Sophos;i="5.40,384,1496102400"; d="scan'208";a="432307686" From: Wei Liu To: Xen-devel Date: Thu, 20 Jul 2017 17:04:13 +0100 Message-ID: <20170720160426.2343-9-wei.liu2@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170720160426.2343-1-wei.liu2@citrix.com> References: <20170720160426.2343-1-wei.liu2@citrix.com> MIME-Version: 1.0 Cc: George Dunlap , Andrew Cooper , Wei Liu , Jan Beulich Subject: [Xen-devel] [PATCH v3 08/21] x86/mm: export get_page_from_pagenr 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP It will be used by different files later, so export it via asm-x86/mm.h. Make it return 0 on success and -EINVAL on failure to match other get_page_from functions. Fix all call sites. Signed-off-by: Wei Liu --- xen/arch/x86/mm.c | 26 +++++++++++++------------- xen/include/asm-x86/mm.h | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index d264f76684..472f0d40d5 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -689,7 +689,7 @@ int map_ldt_shadow_page(unsigned int off) } -static int get_page_from_pagenr(unsigned long page_nr, struct domain *d) +int get_page_from_pagenr(unsigned long page_nr, struct domain *d) { struct page_info *page = mfn_to_page(page_nr); @@ -697,10 +697,10 @@ static int get_page_from_pagenr(unsigned long page_nr, struct domain *d) { gdprintk(XENLOG_WARNING, "Could not get page ref for mfn %"PRI_mfn"\n", page_nr); - return 0; + return -EINVAL; } - return 1; + return 0; } @@ -714,7 +714,7 @@ static int get_page_and_type_from_pagenr(unsigned long page_nr, int rc; if ( likely(partial >= 0) && - unlikely(!get_page_from_pagenr(page_nr, d)) ) + unlikely(get_page_from_pagenr(page_nr, d)) ) return -EINVAL; rc = (preemptible ? @@ -768,7 +768,7 @@ get_##level##_linear_pagetable( \ if ( (pfn = level##e_get_pfn(pde)) != pde_pfn ) \ { \ /* Make sure the mapped frame belongs to the correct domain. */ \ - if ( unlikely(!get_page_from_pagenr(pfn, d)) ) \ + if ( unlikely(get_page_from_pagenr(pfn, d)) ) \ return 0; \ \ /* \ @@ -2998,7 +2998,7 @@ int new_guest_cr3(unsigned long mfn) } rc = paging_mode_refcounts(d) - ? (get_page_from_pagenr(mfn, d) ? 0 : -EINVAL) + ? (!get_page_from_pagenr(mfn, d) ? 0 : -EINVAL) : get_page_and_type_from_pagenr(mfn, PGT_root_page_table, d, 0, 1); switch ( rc ) { @@ -3921,7 +3921,7 @@ long do_mmu_update( xsm_checked = xsm_needed; } - if ( unlikely(!get_page_from_pagenr(mfn, pg_owner)) ) + if ( unlikely(get_page_from_pagenr(mfn, pg_owner)) ) { gdprintk(XENLOG_WARNING, "Could not get page for mach->phys update\n"); @@ -4135,7 +4135,7 @@ static int create_grant_va_mapping( return GNTST_general_error; } - if ( !get_page_from_pagenr(gl1mfn, current->domain) ) + if ( get_page_from_pagenr(gl1mfn, current->domain) ) { guest_unmap_l1e(pl1e); return GNTST_general_error; @@ -4185,7 +4185,7 @@ static int replace_grant_va_mapping( return GNTST_general_error; } - if ( !get_page_from_pagenr(gl1mfn, current->domain) ) + if ( get_page_from_pagenr(gl1mfn, current->domain) ) { rc = GNTST_general_error; goto out; @@ -4295,7 +4295,7 @@ int replace_grant_pv_mapping(uint64_t addr, unsigned long frame, return GNTST_general_error; } - if ( !get_page_from_pagenr(gl1mfn, current->domain) ) + if ( get_page_from_pagenr(gl1mfn, current->domain) ) { guest_unmap_l1e(pl1e); return GNTST_general_error; @@ -4466,7 +4466,7 @@ static int __do_update_va_mapping( rc = -EINVAL; pl1e = guest_map_l1e(va, &gl1mfn); - if ( unlikely(!pl1e || !get_page_from_pagenr(gl1mfn, d)) ) + if ( unlikely(!pl1e || get_page_from_pagenr(gl1mfn, d)) ) goto out; gl1pg = mfn_to_page(gl1mfn); @@ -4838,7 +4838,7 @@ int xenmem_add_to_physmap_one( put_gfn(d, gfn); return -ENOMEM; } - if ( !get_page_from_pagenr(idx, d) ) + if ( get_page_from_pagenr(idx, d) ) break; mfn = idx; page = mfn_to_page(mfn); @@ -5371,7 +5371,7 @@ int ptwr_do_page_fault(struct vcpu *v, unsigned long addr, /* We are looking only for read-only mappings of p.t. pages. */ if ( ((l1e_get_flags(pte) & (_PAGE_PRESENT|_PAGE_RW)) != _PAGE_PRESENT) || rangeset_contains_singleton(mmio_ro_ranges, l1e_get_pfn(pte)) || - !get_page_from_pagenr(l1e_get_pfn(pte), d) ) + get_page_from_pagenr(l1e_get_pfn(pte), d) ) goto bail; page = l1e_get_page(pte); diff --git a/xen/include/asm-x86/mm.h b/xen/include/asm-x86/mm.h index 2550e35f85..6fc1e7d5ca 100644 --- a/xen/include/asm-x86/mm.h +++ b/xen/include/asm-x86/mm.h @@ -363,6 +363,7 @@ int put_old_guest_table(struct vcpu *); int get_page_from_l1e( l1_pgentry_t l1e, struct domain *l1e_owner, struct domain *pg_owner); void put_page_from_l1e(l1_pgentry_t l1e, struct domain *l1e_owner); +int get_page_from_pagenr(unsigned long page_nr, struct domain *d); static inline void put_page_and_type(struct page_info *page) {