From patchwork Fri Oct 6 12:25:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 9989119 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 14FBC60247 for ; Fri, 6 Oct 2017 12:28:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0645928D9D for ; Fri, 6 Oct 2017 12:28:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF68D28D9E; Fri, 6 Oct 2017 12:27:59 +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 8384828D9F for ; Fri, 6 Oct 2017 12:27: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 1e0Rh1-00065t-Al; Fri, 06 Oct 2017 12:25:27 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e0Rgz-00065O-Do for xen-devel@lists.xenproject.org; Fri, 06 Oct 2017 12:25:25 +0000 Received: from [85.158.143.35] by server-1.bemta-6.messagelabs.com id 7D/6A-03428-43677D95; Fri, 06 Oct 2017 12:25:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRWlGSWpSXmKPExsXitHRDpK5J2fV IgyX9vBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa8bdq7/ZClp1K36vO8nWwDhBuYuRk0NCwF/i w9x3LCA2m4COxNSnl1i7GDk4RARUJG7vNQAJMwuESaxecJERxBYW8Jb4uecTO4jNAlRy9tJNs FZeARuJSef3MEGMlJfY1XaRFcTmFLCVeH35JFhcCKim9dR7Zoh6QYmTM5+wQMzXlGjd/psdwp aXaN46mxmiXkVi/dRZbBMY+WYhaZmFpGUWkpYFjMyrGDWKU4vKUot0DS30kooy0zNKchMzc3Q NDcz0clOLixPTU3MSk4r1kvNzNzECQ40BCHYw3twYcIhRkoNJSZT3ffH1SCG+pPyUyozE4oz4 otKc1OJDjDIcHEoSvF9LgHKCRanpqRVpmTnAoIdJS3DwKInwrgNJ8xYXJOYWZ6ZDpE4x6nJ03 Lz7h0mIJS8/L1VKnPcASJEASFFGaR7cCFgEXmKUlRLmZQQ6SoinILUoN7MEVf4VozgHo5Iw70 GQKTyZeSVwm14BHcEEdMScpisgR5QkIqSkGhitwhNsL53zqG9KkH4p8T7817IPDKI1v6TZLmm xCz1/NJn9o8zjgH/vJ/TcXpdibf+xOOfeXS7Lu92Vq550R4R/e8l9cf3cNoFWmV2KjeJ3G3q2 3f2Zs8gvdeGfhQ93tq9j+Le4f7Ofg/60s3e63XwX109NvCnKn/dQvrLimkr3st/CzvPtoxcps RRnJBpqMRcVJwIARUSWprsCAAA= X-Env-Sender: prvs=445054343=Paul.Durrant@citrix.com X-Msg-Ref: server-7.tower-21.messagelabs.com!1507292722!76718821!1 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.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23157 invoked from network); 6 Oct 2017 12:25:23 -0000 Received: from smtp.citrix.com (HELO SMTP.CITRIX.COM) (66.165.176.89) by server-7.tower-21.messagelabs.com with RC4-SHA encrypted SMTP; 6 Oct 2017 12:25:23 -0000 X-IronPort-AV: E=Sophos;i="5.42,483,1500940800"; d="scan'208";a="442760824" From: Paul Durrant To: Date: Fri, 6 Oct 2017 13:25:11 +0100 Message-ID: <20171006122519.30345-4-paul.durrant@citrix.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171006122519.30345-1-paul.durrant@citrix.com> References: <20171006122519.30345-1-paul.durrant@citrix.com> MIME-Version: 1.0 Cc: Andrew Cooper , Paul Durrant Subject: [Xen-devel] [PATCH v9 03/11] x86/hvm/ioreq: use gfn_t in struct hvm_ioreq_page 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 This patch adjusts the ioreq server code to use type-safe gfn_t values where possible. No functional change. Signed-off-by: Paul Durrant Reviewed-by: Roger Pau Monné Reviewed-by: Wei Liu Acked-by: Jan Beulich --- Cc: Andrew Cooper --- xen/arch/x86/hvm/ioreq.c | 44 ++++++++++++++++++++-------------------- xen/include/asm-x86/hvm/domain.h | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/xen/arch/x86/hvm/ioreq.c b/xen/arch/x86/hvm/ioreq.c index f162e27ab1..d220c8b1f7 100644 --- a/xen/arch/x86/hvm/ioreq.c +++ b/xen/arch/x86/hvm/ioreq.c @@ -217,7 +217,7 @@ bool handle_hvm_io_completion(struct vcpu *v) return true; } -static unsigned long hvm_alloc_ioreq_gfn(struct hvm_ioreq_server *s) +static gfn_t hvm_alloc_ioreq_gfn(struct hvm_ioreq_server *s) { struct domain *d = s->domain; unsigned int i; @@ -227,20 +227,19 @@ static unsigned long hvm_alloc_ioreq_gfn(struct hvm_ioreq_server *s) for ( i = 0; i < sizeof(d->arch.hvm_domain.ioreq_gfn.mask) * 8; i++ ) { if ( test_and_clear_bit(i, &d->arch.hvm_domain.ioreq_gfn.mask) ) - return d->arch.hvm_domain.ioreq_gfn.base + i; + return _gfn(d->arch.hvm_domain.ioreq_gfn.base + i); } - return gfn_x(INVALID_GFN); + return INVALID_GFN; } -static void hvm_free_ioreq_gfn(struct hvm_ioreq_server *s, - unsigned long gfn) +static void hvm_free_ioreq_gfn(struct hvm_ioreq_server *s, gfn_t gfn) { struct domain *d = s->domain; - unsigned int i = gfn - d->arch.hvm_domain.ioreq_gfn.base; + unsigned int i = gfn_x(gfn) - d->arch.hvm_domain.ioreq_gfn.base; ASSERT(!IS_DEFAULT(s)); - ASSERT(gfn != gfn_x(INVALID_GFN)); + ASSERT(!gfn_eq(gfn, INVALID_GFN)); set_bit(i, &d->arch.hvm_domain.ioreq_gfn.mask); } @@ -249,7 +248,7 @@ static void hvm_unmap_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) { struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; - if ( iorp->gfn == gfn_x(INVALID_GFN) ) + if ( gfn_eq(iorp->gfn, INVALID_GFN) ) return; destroy_ring_for_helper(&iorp->va, iorp->page); @@ -258,7 +257,7 @@ static void hvm_unmap_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) if ( !IS_DEFAULT(s) ) hvm_free_ioreq_gfn(s, iorp->gfn); - iorp->gfn = gfn_x(INVALID_GFN); + iorp->gfn = INVALID_GFN; } static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) @@ -271,16 +270,17 @@ static int hvm_map_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) return -EINVAL; if ( IS_DEFAULT(s) ) - iorp->gfn = buf ? - d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_PFN] : - d->arch.hvm_domain.params[HVM_PARAM_IOREQ_PFN]; + iorp->gfn = _gfn(buf ? + d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_PFN] : + d->arch.hvm_domain.params[HVM_PARAM_IOREQ_PFN]); else iorp->gfn = hvm_alloc_ioreq_gfn(s); - if ( iorp->gfn == gfn_x(INVALID_GFN) ) + if ( gfn_eq(iorp->gfn, INVALID_GFN) ) return -ENOMEM; - rc = prepare_ring_for_helper(d, iorp->gfn, &iorp->page, &iorp->va); + rc = prepare_ring_for_helper(d, gfn_x(iorp->gfn), &iorp->page, + &iorp->va); if ( rc ) hvm_unmap_ioreq_gfn(s, buf); @@ -316,10 +316,10 @@ static void hvm_remove_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) struct domain *d = s->domain; struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; - if ( IS_DEFAULT(s) || iorp->gfn == gfn_x(INVALID_GFN) ) + if ( IS_DEFAULT(s) || gfn_eq(iorp->gfn, INVALID_GFN) ) return; - if ( guest_physmap_remove_page(d, _gfn(iorp->gfn), + if ( guest_physmap_remove_page(d, iorp->gfn, _mfn(page_to_mfn(iorp->page)), 0) ) domain_crash(d); clear_page(iorp->va); @@ -331,12 +331,12 @@ static int hvm_add_ioreq_gfn(struct hvm_ioreq_server *s, bool buf) struct hvm_ioreq_page *iorp = buf ? &s->bufioreq : &s->ioreq; int rc; - if ( IS_DEFAULT(s) || iorp->gfn == gfn_x(INVALID_GFN) ) + if ( IS_DEFAULT(s) || gfn_eq(iorp->gfn, INVALID_GFN) ) return 0; clear_page(iorp->va); - rc = guest_physmap_add_page(d, _gfn(iorp->gfn), + rc = guest_physmap_add_page(d, iorp->gfn, _mfn(page_to_mfn(iorp->page)), 0); if ( rc == 0 ) paging_mark_dirty(d, _mfn(page_to_mfn(iorp->page))); @@ -597,8 +597,8 @@ static int hvm_ioreq_server_init(struct hvm_ioreq_server *s, INIT_LIST_HEAD(&s->ioreq_vcpu_list); spin_lock_init(&s->bufioreq_lock); - s->ioreq.gfn = gfn_x(INVALID_GFN); - s->bufioreq.gfn = gfn_x(INVALID_GFN); + s->ioreq.gfn = INVALID_GFN; + s->bufioreq.gfn = INVALID_GFN; rc = hvm_ioreq_server_alloc_rangesets(s, id); if ( rc ) @@ -764,11 +764,11 @@ int hvm_get_ioreq_server_info(struct domain *d, ioservid_t id, ASSERT(!IS_DEFAULT(s)); - *ioreq_gfn = s->ioreq.gfn; + *ioreq_gfn = gfn_x(s->ioreq.gfn); if ( s->bufioreq.va != NULL ) { - *bufioreq_gfn = s->bufioreq.gfn; + *bufioreq_gfn = gfn_x(s->bufioreq.gfn); *bufioreq_port = s->bufioreq_evtchn; } diff --git a/xen/include/asm-x86/hvm/domain.h b/xen/include/asm-x86/hvm/domain.h index e17bbe4004..3bd9c5d7c0 100644 --- a/xen/include/asm-x86/hvm/domain.h +++ b/xen/include/asm-x86/hvm/domain.h @@ -36,7 +36,7 @@ #include struct hvm_ioreq_page { - unsigned long gfn; + gfn_t gfn; struct page_info *page; void *va; };