From patchwork Tue May 7 15:14:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 10933113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5979414DB for ; Tue, 7 May 2019 15:16:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 48196287FD for ; Tue, 7 May 2019 15:16:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38BEE287FF; Tue, 7 May 2019 15:16:53 +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=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, 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 AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B7749287FD for ; Tue, 7 May 2019 15:16:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hO1oP-0007Ll-A4; Tue, 07 May 2019 15:15:21 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hO1oO-0007LK-2w for xen-devel@lists.xenproject.org; Tue, 07 May 2019 15:15:20 +0000 X-Inumbo-ID: ecb7c372-70da-11e9-843c-bc764e045a96 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTP id ecb7c372-70da-11e9-843c-bc764e045a96; Tue, 07 May 2019 15:15:18 +0000 (UTC) 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 8D03115AD; Tue, 7 May 2019 08:15:18 -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 9CA613F5AF; Tue, 7 May 2019 08:15:16 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 7 May 2019 16:14:49 +0100 Message-Id: <20190507151458.29350-6-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190507151458.29350-1-julien.grall@arm.com> References: <20190507151458.29350-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH 05/14] xen/grant-table: Make arch specific macros typesafe 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: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Jan Beulich , =?utf-8?q?Roger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch rework all the arch specific macros in grant_table.h to use the typesafe MFN/GFN. At the same time, some functions are renamed s/gmfn/gfn/ to match the current naming scheme (see include/mm.h). No functional changes intended. Signed-off-by: Julien Grall Acked-by: Jan Beulich Reviewed-by: Stefano Stabellini --- Changes in v2: - Update commit message to explain the changes made - Fix indentation - Adapt the code to match the new prototype of mfn_to_gfn - Add Jan's acked-by for non-ARM parts --- xen/common/grant_table.c | 4 ++-- xen/include/asm-arm/grant_table.h | 12 ++++++------ xen/include/asm-x86/grant_table.h | 19 +++++++------------ 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/xen/common/grant_table.c b/xen/common/grant_table.c index 80728ea57d..abc966f775 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1935,7 +1935,7 @@ gnttab_setup_table( op.status = GNTST_okay; for ( i = 0; i < op.nr_frames; i++ ) { - xen_pfn_t gmfn = gnttab_shared_gmfn(d, gt, i); + xen_pfn_t gmfn = gfn_x(gnttab_shared_gfn(d, gt, i)); /* Grant tables cannot be shared */ BUG_ON(SHARED_M2P(gmfn)); @@ -3149,7 +3149,7 @@ gnttab_get_status_frames(XEN_GUEST_HANDLE_PARAM(gnttab_get_status_frames_t) uop, for ( i = 0; i < op.nr_frames; i++ ) { - gmfn = gnttab_status_gmfn(d, gt, i); + gmfn = gfn_x(gnttab_status_gfn(d, gt, i)); if ( copy_to_guest_offset(op.frame_list, i, &gmfn, 1) ) op.status = GNTST_bad_virt_addr; } diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h index 051db1362b..750536184e 100644 --- a/xen/include/asm-arm/grant_table.h +++ b/xen/include/asm-arm/grant_table.h @@ -65,15 +65,15 @@ void gnttab_mark_dirty(struct domain *d, mfn_t mfn); } while ( 0 ) #define gnttab_get_frame_gfn(gt, st, idx) ({ \ - _gfn((st) ? gnttab_status_gmfn(NULL, gt, idx) \ - : gnttab_shared_gmfn(NULL, gt, idx)); \ + (st) ? gnttab_status_gfn(NULL, gt, idx) \ + : gnttab_shared_gfn(NULL, gt, idx); \ }) -#define gnttab_shared_gmfn(d, t, i) \ - gfn_x(((i) >= nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i]) +#define gnttab_shared_gfn(d, t, i) \ + (((i) >= nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i]) -#define gnttab_status_gmfn(d, t, i) \ - gfn_x(((i) >= nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i]) +#define gnttab_status_gfn(d, t, i) \ + (((i) >= nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i]) #define gnttab_need_iommu_mapping(d) \ (is_domain_direct_mapped(d) && need_iommu_pt_sync(d)) diff --git a/xen/include/asm-x86/grant_table.h b/xen/include/asm-x86/grant_table.h index 8b604ed51f..661228dd39 100644 --- a/xen/include/asm-x86/grant_table.h +++ b/xen/include/asm-x86/grant_table.h @@ -39,24 +39,19 @@ static inline int replace_grant_host_mapping(uint64_t addr, mfn_t frame, #define gnttab_destroy_arch(gt) do {} while ( 0 ) #define gnttab_set_frame_gfn(gt, st, idx, gfn) do {} while ( 0 ) #define gnttab_get_frame_gfn(gt, st, idx) ({ \ - unsigned long mfn_ = (st) ? gnttab_status_mfn(gt, idx) \ - : gnttab_shared_mfn(gt, idx); \ - unsigned long gpfn_ = get_gpfn_from_mfn(mfn_); \ + mfn_t mfn_ = (st) ? gnttab_status_mfn(gt, idx) \ + : gnttab_shared_mfn(gt, idx); \ + unsigned long gpfn_ = get_gpfn_from_mfn(mfn_x(mfn_)); \ VALID_M2P(gpfn_) ? _gfn(gpfn_) : INVALID_GFN; \ }) -#define gnttab_shared_mfn(t, i) \ - ((virt_to_maddr((t)->shared_raw[i]) >> PAGE_SHIFT)) +#define gnttab_shared_mfn(t, i) _mfn(__virt_to_mfn((t)->shared_raw[i])) -#define gnttab_shared_gmfn(d, t, i) \ - (mfn_to_gmfn(d, gnttab_shared_mfn(t, i))) +#define gnttab_shared_gfn(d, t, i) mfn_to_gfn(d, gnttab_shared_mfn(t, i)) +#define gnttab_status_mfn(t, i) _mfn(__virt_to_mfn((t)->status[i])) -#define gnttab_status_mfn(t, i) \ - ((virt_to_maddr((t)->status[i]) >> PAGE_SHIFT)) - -#define gnttab_status_gmfn(d, t, i) \ - (mfn_to_gmfn(d, gnttab_status_mfn(t, i))) +#define gnttab_status_gfn(d, t, i) mfn_to_gfn(d, gnttab_status_mfn(t, i)) #define gnttab_mark_dirty(d, f) paging_mark_dirty(d, f)