From nobody Fri Apr 19 16:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1651830192884356.99296534000666; Fri, 6 May 2022 02:43:12 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.322794.544224 (Exim 4.92) (envelope-from ) id 1nmuU1-0005Ox-0s; Fri, 06 May 2022 09:42:45 +0000 Received: by outflank-mailman (output) from mailman id 322794.544224; Fri, 06 May 2022 09:42:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmuU0-0005Oq-TC; Fri, 06 May 2022 09:42:44 +0000 Received: by outflank-mailman (input) for mailman id 322794; Fri, 06 May 2022 09:42:43 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmuTz-00059C-M8 for xen-devel@lists.xenproject.org; Fri, 06 May 2022 09:42:43 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id dee23dd7-cd20-11ec-8fc4-03012f2f19d4; Fri, 06 May 2022 11:42:41 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 150D8153B; Fri, 6 May 2022 02:42:40 -0700 (PDT) Received: from e129167.arm.com (unknown [10.57.2.250]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5EB373FA31; Fri, 6 May 2022 02:42:38 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: dee23dd7-cd20-11ec-8fc4-03012f2f19d4 From: Michal Orzel To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Jan Beulich Subject: [PATCH v2 1/2] xen/arm: gnttab: use static inlines for gnttab_{release_}host_mapping* Date: Fri, 6 May 2022 11:42:24 +0200 Message-Id: <20220506094225.181815-2-michal.orzel@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506094225.181815-1-michal.orzel@arm.com> References: <20220506094225.181815-1-michal.orzel@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1651830194098100003 Content-Type: text/plain; charset="utf-8" Function unmap_common_complete (common/grant_table.c) defines and sets a variable ld that is later on passed to a macro: gnttab_host_mapping_get_page_type(). On Arm this macro does not make use of any arguments causing a compiler to warn about unused-but-set variable (when -Wunused-but-set-variable is enabled). Fix it by converting this macro to a static inline helper and using the boolean return type. While there, also convert macro gnttab_release_host_mappings. Signed-off-by: Michal Orzel Reviewed-by: Jan Beulich Acked-by: Julien Grall --- Changes since v1: - mark parameters as const --- xen/arch/arm/include/asm/grant_table.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/include/asm/grant_table.h b/xen/arch/arm/include/= asm/grant_table.h index d31a4d6805..5ccaf6d51f 100644 --- a/xen/arch/arm/include/asm/grant_table.h +++ b/xen/arch/arm/include/asm/grant_table.h @@ -29,12 +29,22 @@ static inline void gnttab_mark_dirty(struct domain *d, = mfn_t mfn) #endif } =20 +static inline bool gnttab_host_mapping_get_page_type(const bool ro, + const struct domain *= ld, + const struct domain *= rd) +{ + return false; +} + +static inline bool gnttab_release_host_mappings(const struct domain *d) +{ + return true; +} + int create_grant_host_mapping(unsigned long gpaddr, mfn_t mfn, unsigned int flags, unsigned int cache_flags= ); -#define gnttab_host_mapping_get_page_type(ro, ld, rd) (0) int replace_grant_host_mapping(unsigned long gpaddr, mfn_t mfn, unsigned long new_gpaddr, unsigned int flag= s); -#define gnttab_release_host_mappings(domain) 1 =20 /* * The region used by Xen on the memory will never be mapped in DOM0 --=20 2.25.1 From nobody Fri Apr 19 16:50:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=arm.com Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1651830190683631.397728514111; Fri, 6 May 2022 02:43:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.322795.544229 (Exim 4.92) (envelope-from ) id 1nmuU1-0005Rk-8z; Fri, 06 May 2022 09:42:45 +0000 Received: by outflank-mailman (output) from mailman id 322795.544229; Fri, 06 May 2022 09:42:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmuU1-0005RK-4w; Fri, 06 May 2022 09:42:45 +0000 Received: by outflank-mailman (input) for mailman id 322795; Fri, 06 May 2022 09:42:44 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmuU0-00059C-3i for xen-devel@lists.xenproject.org; Fri, 06 May 2022 09:42:44 +0000 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by se1-gles-flk1.inumbo.com (Halon) with ESMTP id e02f8aee-cd20-11ec-8fc4-03012f2f19d4; Fri, 06 May 2022 11:42:42 +0200 (CEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 2091F152B; Fri, 6 May 2022 02:42:42 -0700 (PDT) Received: from e129167.arm.com (unknown [10.57.2.250]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6ADF43FA31; Fri, 6 May 2022 02:42:40 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: e02f8aee-cd20-11ec-8fc4-03012f2f19d4 From: Michal Orzel To: xen-devel@lists.xenproject.org Cc: Stefano Stabellini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk , Jan Beulich Subject: [PATCH v2 2/2] xen/arm: gnttab: modify macros to evaluate all arguments and only once Date: Fri, 6 May 2022 11:42:25 +0200 Message-Id: <20220506094225.181815-3-michal.orzel@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220506094225.181815-1-michal.orzel@arm.com> References: <20220506094225.181815-1-michal.orzel@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1651830192663100001 Content-Type: text/plain; charset="utf-8" Modify macros to evaluate all the arguments and make sure the arguments are evaluated only once. Introduce following intermediate macros: gnttab_status_gfn_, gnttab_shared_gfn_ that do not take domain as a parameter. These are to be used locally and allow us to avoid passing NULL from gnttab_get_frame_gfn to the respective macros (without _ suffix). Make use of a domain parameter from gnttab_shared_gfn and gnttab_status_gfn by adding an ASSERT. Signed-off-by: Michal Orzel --- Changes since v1: - use typeof for all data types - introduce intermediate macros --- xen/arch/arm/include/asm/grant_table.h | 75 ++++++++++++++++++-------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/xen/arch/arm/include/asm/grant_table.h b/xen/arch/arm/include/= asm/grant_table.h index 5ccaf6d51f..3550990ceb 100644 --- a/xen/arch/arm/include/asm/grant_table.h +++ b/xen/arch/arm/include/asm/grant_table.h @@ -58,54 +58,87 @@ int replace_grant_host_mapping(unsigned long gpaddr, mf= n_t mfn, =20 #define gnttab_init_arch(gt) \ ({ \ - unsigned int ngf_ =3D (gt)->max_grant_frames; = \ + typeof(gt) gt_ =3D (gt); = \ + unsigned int ngf_ =3D gt_->max_grant_frames; = \ unsigned int nsf_ =3D grant_to_status_frames(ngf_); = \ \ - (gt)->arch.shared_gfn =3D xmalloc_array(gfn_t, ngf_); = \ - (gt)->arch.status_gfn =3D xmalloc_array(gfn_t, nsf_); = \ - if ( (gt)->arch.shared_gfn && (gt)->arch.status_gfn ) \ + gt_->arch.shared_gfn =3D xmalloc_array(gfn_t, ngf_); = \ + gt_->arch.status_gfn =3D xmalloc_array(gfn_t, nsf_); = \ + if ( gt_->arch.shared_gfn && gt_->arch.status_gfn ) \ { \ while ( ngf_-- ) \ - (gt)->arch.shared_gfn[ngf_] =3D INVALID_GFN; = \ + gt_->arch.shared_gfn[ngf_] =3D INVALID_GFN; = \ while ( nsf_-- ) \ - (gt)->arch.status_gfn[nsf_] =3D INVALID_GFN; = \ + gt_->arch.status_gfn[nsf_] =3D INVALID_GFN; = \ } \ else \ - gnttab_destroy_arch(gt); \ - (gt)->arch.shared_gfn ? 0 : -ENOMEM; \ + gnttab_destroy_arch(gt_); \ + gt_->arch.shared_gfn ? 0 : -ENOMEM; \ }) =20 #define gnttab_destroy_arch(gt) \ do { \ - XFREE((gt)->arch.shared_gfn); \ - XFREE((gt)->arch.status_gfn); \ + typeof(gt) gt_ =3D (gt); = \ + XFREE(gt_->arch.shared_gfn); \ + XFREE(gt_->arch.status_gfn); \ } while ( 0 ) =20 #define gnttab_set_frame_gfn(gt, st, idx, gfn, mfn) \ ({ \ int rc_ =3D 0; = \ - gfn_t ogfn =3D gnttab_get_frame_gfn(gt, st, idx); = \ - if ( gfn_eq(ogfn, INVALID_GFN) || gfn_eq(ogfn, gfn) || \ - (rc_ =3D guest_physmap_remove_page((gt)->domain, ogfn, mfn, = \ + const typeof(gt) gt_ =3D (gt); = \ + const typeof(st) st_ =3D (st); = \ + const typeof(idx) idx_ =3D (idx); = \ + const typeof(gfn) gfn_ =3D (gfn); = \ + const gfn_t ogfn_ =3D gnttab_get_frame_gfn(gt_, st_, idx_); = \ + if ( gfn_eq(ogfn_, INVALID_GFN) || gfn_eq(ogfn_, gfn_) || \ + (rc_ =3D guest_physmap_remove_page(gt_->domain, ogfn_, mfn, = \ 0)) =3D=3D 0 ) = \ - ((st) ? (gt)->arch.status_gfn \ - : (gt)->arch.shared_gfn)[idx] =3D (gfn); = \ + (st_ ? gt_->arch.status_gfn \ + : gt_->arch.shared_gfn)[idx_] =3D gfn_; = \ rc_; \ }) =20 #define gnttab_get_frame_gfn(gt, st, idx) ({ \ - (st) ? gnttab_status_gfn(NULL, gt, idx) \ - : gnttab_shared_gfn(NULL, gt, idx); \ + (st) ? gnttab_status_gfn_(gt, idx) \ + : gnttab_shared_gfn_(gt, idx); \ }) =20 +#define gnttab_shared_gfn_(t, i) \ + ({ \ + const typeof(t) t_ =3D (t); = \ + const typeof(i) i_ =3D (i); = \ + (i_ >=3D nr_grant_frames(t_)) ? INVALID_GFN = \ + : t_->arch.shared_gfn[i_]; \ + }) + +#define gnttab_status_gfn_(t, i) \ + ({ \ + const typeof(t) t_ =3D (t); = \ + const typeof(i) i_ =3D (i); = \ + (i_ >=3D nr_status_frames(t_)) ? INVALID_GFN = \ + : t_->arch.status_gfn[i_]; \ + }) + #define gnttab_shared_gfn(d, t, i) \ - (((i) >=3D nr_grant_frames(t)) ? INVALID_GFN : (t)->arch.shared_gfn[i]) + ({ \ + const typeof(t) t_ =3D (t); = \ + ASSERT((d)->grant_table =3D=3D t_); = \ + gnttab_shared_gfn_(t_, i); \ + }) =20 #define gnttab_status_gfn(d, t, i) \ - (((i) >=3D nr_status_frames(t)) ? INVALID_GFN : (t)->arch.status_gfn[i= ]) + ({ \ + const typeof(t) t_ =3D (t); = \ + ASSERT((d)->grant_table =3D=3D t_); = \ + gnttab_status_gfn_(t_, i); \ + }) =20 -#define gnttab_need_iommu_mapping(d) \ - (is_domain_direct_mapped(d) && is_iommu_enabled(d)) +#define gnttab_need_iommu_mapping(d) \ + ({ \ + const typeof(d) d_ =3D (d); = \ + is_domain_direct_mapped(d_) && is_iommu_enabled(d_); \ + }) =20 #endif /* __ASM_GRANT_TABLE_H__ */ /* --=20 2.25.1