From patchwork Mon Jun 3 16:03:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Grall X-Patchwork-Id: 165660 Delivered-To: patch@linaro.org Received: by 2002:a92:9e1a:0:0:0:0:0 with SMTP id q26csp4660356ili; Mon, 3 Jun 2019 09:05:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqyntzSNPHemmTRoqU/WPLQ7ujDKIirAv0X48hK4rmSRLejWQAk/UpX+faqxjZDFHCRe/4na X-Received: by 2002:a6b:5115:: with SMTP id f21mr16444157iob.173.1559577925683; Mon, 03 Jun 2019 09:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559577925; cv=none; d=google.com; s=arc-20160816; b=yd7gSv+MKxdAbZyqZU69QhGeY3+F02KEibGTmrMbQz23MIVPm88/a8NcF+TsR58ITO Vif+mVZNdvJN7UJncTXtch2LIyF9ArfbUHnoO+0vulE3Qnx2XqYjVCrZcUdo9uQAUBjM gT9SNl9eCYT4cqQX8zRtoq7QzL8RFGbeukCdC5vOBSdGNX5KSjVLSXp3ML4X7fW3M2yS 5VZcGvrBtbzzmx0ly8gYgYV5mUGVaxtuDY8lK5Bm0vc/KlwIbMy/7/yj8P1U1U6UVdsA ExANdXUKfEUjy1nLTP6IkGIfnqvUyBZsFt1I73F37tTCPxvaUBGeOgv4YP3NhtjQ8qmB gqow== 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:cc :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from; bh=ljZ+6jvUCRsDrx2GtEVxurJyTEoJcf/yB+y50iIMU4M=; b=YjzhRpDhfO3VepPyQ+0v/jODf3TobCf6hThTUNqW9q5p7Wb+wqYiZuzxVyCHRIswIi NyP4sK9llSQK7HXO4yUjftsIapLwvqbMekGjFH+lMfnNlvtQO3WyZy1HK7gePelpyt2E MXKDhtYNyMi+5+t8a7gJJDsv4SS1Wbte/ip5QZIpiLw+TvPBexHEVaqTvDDloXLkvrca a6chHkYfoayhFHIeUDrR92/+UXvbY7xs2Fl6HHDT014TxOY/DoqUYuSlckJ4hKzicsWG nxPM0B76Hp0JLRf84QVCGSpaXlshq+oIw/9ND7dizrUlIoHuc2ax5+Sjl9MgZHUvmn9I DN8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id n198si9353033itb.33.2019.06.03.09.05.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Jun 2019 09:05:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRO-0001v1-G8; Mon, 03 Jun 2019 16:04:06 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hXpRN-0001uG-9I for xen-devel@lists.xenproject.org; Mon, 03 Jun 2019 16:04:05 +0000 X-Inumbo-ID: 35a05018-8619-11e9-b34d-a759a37a7fc6 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 35a05018-8619-11e9-b34d-a759a37a7fc6; Mon, 03 Jun 2019 16:04:04 +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 0FD4AA78; Mon, 3 Jun 2019 09:04:04 -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 1F4AB3F246; Mon, 3 Jun 2019 09:04:01 -0700 (PDT) From: Julien Grall To: xen-devel@lists.xenproject.org Date: Mon, 3 Jun 2019 17:03:39 +0100 Message-Id: <20190603160350.29806-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190603160350.29806-1-julien.grall@arm.com> References: <20190603160350.29806-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH v3 03/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?Ro?= =?utf-8?q?ger_Pau_Monn=C3=A9?= MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 v3: - Add Stefano's reviewed-by 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 dd8a9d9046..7680241851 100644 --- a/xen/common/grant_table.c +++ b/xen/common/grant_table.c @@ -1960,7 +1960,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)); @@ -3174,7 +3174,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)