From nobody Thu May 16 11:48:17 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1698413706235636.5331737809321; Fri, 27 Oct 2023 06:35:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.624383.972938 (Exim 4.92) (envelope-from ) id 1qwMym-0001Ii-QW; Fri, 27 Oct 2023 13:34:24 +0000 Received: by outflank-mailman (output) from mailman id 624383.972938; Fri, 27 Oct 2023 13:34:24 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMym-0001Hn-MI; Fri, 27 Oct 2023 13:34:24 +0000 Received: by outflank-mailman (input) for mailman id 624383; Fri, 27 Oct 2023 13:34:22 +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 1qwMyk-0000bA-Lr for xen-devel@lists.xenproject.org; Fri, 27 Oct 2023 13:34:22 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 883c68a9-74cd-11ee-9b0e-b553b5be7939; Fri, 27 Oct 2023 15:34:19 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id E4EE44EE074E; Fri, 27 Oct 2023 15:34:18 +0200 (CEST) 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: 883c68a9-74cd-11ee-9b0e-b553b5be7939 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , Simone Ballarin , Doug Goldstein , George Dunlap , Julien Grall , Wei Liu Subject: [XEN PATCH][for-4.19 v4 1/8] xen/include: add macro ISOLATE_LOW_BIT Date: Fri, 27 Oct 2023 15:34:08 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1698413707438100011 Content-Type: text/plain; charset="utf-8" The purpose of this macro is to encapsulate the well-known expression 'x & -x' that in 2's complement architectures on unsigned integers will give a mask where only the least significant nonzero bit of 'x' is set, or 0 if none are set. A deviation for ECLAIR is also introduced. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- Changes in v2: - rename to LOWEST_BIT Changes in v3: - entry for deviations.rst - comment on the macro defn Changes in v4: - Change the macro's name to ISOLATE_LOW_BIT --- automation/eclair_analysis/ECLAIR/deviations.ecl | 7 +++++++ docs/misra/deviations.rst | 8 ++++++++ xen/include/xen/macros.h | 10 ++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/= eclair_analysis/ECLAIR/deviations.ecl index fa56e5c00a27..139dabc8477f 100644 --- a/automation/eclair_analysis/ECLAIR/deviations.ecl +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl @@ -246,6 +246,13 @@ constant expressions are required.\"" "any()"} -doc_end =20 +-doc_begin=3D"The macro ISOLATE_LOW_BIT encapsulates a well-known pattern = to obtain +a mask where only the lowest bit set in the argument is set, if any, for u= nsigned +integers arguments on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=3DMC3R1.R10.1,reports+=3D{safe, "any_area(any_loc(any_exp(macro(^I= SOLATE_LOW_BIT$))))"} +-doc_end + # # Series 13 # diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst index 8511a189253b..d76b28279e59 100644 --- a/docs/misra/deviations.rst +++ b/docs/misra/deviations.rst @@ -192,6 +192,14 @@ Deviations related to MISRA C:2012 Rules: See automation/eclair_analysis/deviations.ecl for the full explanat= ion. - Tagged as `safe` for ECLAIR. =20 + * - R10.1 + - The macro ISOLATE_LOW_BIT encapsulates the well-known pattern (x & = -x) + applied to unsigned integer values on 2's complement architectures + (i.e., all architectures supported by Xen), used to obtain a mask w= here + just the least significant nonzero bit of x is set. + If no bits are set, 0 is returned. + - Tagged as `safe` for ECLAIR. + * - R13.5 - All developers and reviewers can be safely assumed to be well aware= of the short-circuit evaluation strategy for logical operators. diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h index d0caae7db298..4e1b1f4e4b56 100644 --- a/xen/include/xen/macros.h +++ b/xen/include/xen/macros.h @@ -8,8 +8,14 @@ #define DIV_ROUND(n, d) (((n) + (d) / 2) / (d)) #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) =20 -#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m)) +/* + * Given an unsigned integer argument, expands to a mask where just the le= ast + * significant nonzero bit of the argument is set, or 0 if no bits are set. + */ +#define ISOLATE_LOW_BIT(x) ((x) & -(x)) + +#define MASK_EXTR(v, m) (((v) & (m)) / ISOLATE_LOW_BIT(m)) +#define MASK_INSR(v, m) (((v) * ISOLATE_LOW_BIT(m)) & (m)) =20 #define count_args_(dot, a1, a2, a3, a4, a5, a6, a7, a8, x, ...) x #define count_args(args...) \ --=20 2.34.1 From nobody Thu May 16 11:48:17 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1698413699165712.8737428144601; Fri, 27 Oct 2023 06:34:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.624380.972908 (Exim 4.92) (envelope-from ) id 1qwMyl-0000bd-3A; Fri, 27 Oct 2023 13:34:23 +0000 Received: by outflank-mailman (output) from mailman id 624380.972908; Fri, 27 Oct 2023 13:34:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyl-0000bW-0D; Fri, 27 Oct 2023 13:34:23 +0000 Received: by outflank-mailman (input) for mailman id 624380; Fri, 27 Oct 2023 13:34:22 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyk-0000bB-C1 for xen-devel@lists.xenproject.org; Fri, 27 Oct 2023 13:34:22 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 88b6eba4-74cd-11ee-98d6-6d05b1d4d9a1; Fri, 27 Oct 2023 15:34:20 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id CA8504EE0C81; Fri, 27 Oct 2023 15:34:19 +0200 (CEST) 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: 88b6eba4-74cd-11ee-98d6-6d05b1d4d9a1 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN PATCH][for-4.19 v4 2/8] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1 Date: Fri, 27 Oct 2023 15:34:09 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1698413701265100003 Content-Type: text/plain; charset="utf-8" The definitions of ffs{l}? violate Rule 10.1, by using the well-known pattern (x & -x); its usage is wrapped by the ISOLATE_LOW_BIT macro. No functional change. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini Changes in v4: - Changed macro name. --- xen/arch/arm/include/asm/bitops.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/include/asm/bitops.h b/xen/arch/arm/include/asm/b= itops.h index 71ae14cab355..e674634d03bf 100644 --- a/xen/arch/arm/include/asm/bitops.h +++ b/xen/arch/arm/include/asm/bitops.h @@ -9,6 +9,8 @@ #ifndef _ARM_BITOPS_H #define _ARM_BITOPS_H =20 +#include + #include =20 /* @@ -155,8 +157,8 @@ static inline int fls(unsigned int x) } =20 =20 -#define ffs(x) ({ unsigned int __t =3D (x); fls(__t & -__t); }) -#define ffsl(x) ({ unsigned long __t =3D (x); flsl(__t & -__t); }) +#define ffs(x) ({ unsigned int __t =3D (x); fls(ISOLATE_LOW_BIT(__t)); }) +#define ffsl(x) ({ unsigned long __t =3D (x); flsl(ISOLATE_LOW_BIT(__t)); = }) =20 /** * find_first_set_bit - find the first set bit in @word --=20 2.34.1 From nobody Thu May 16 11:48:17 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1698413702654428.0267755654387; Fri, 27 Oct 2023 06:35:02 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.624382.972919 (Exim 4.92) (envelope-from ) id 1qwMyl-0000jo-Kb; Fri, 27 Oct 2023 13:34:23 +0000 Received: by outflank-mailman (output) from mailman id 624382.972919; Fri, 27 Oct 2023 13:34:23 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyl-0000hX-Eg; Fri, 27 Oct 2023 13:34:23 +0000 Received: by outflank-mailman (input) for mailman id 624382; Fri, 27 Oct 2023 13:34:22 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyk-0000bB-J7 for xen-devel@lists.xenproject.org; Fri, 27 Oct 2023 13:34:22 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 893a287f-74cd-11ee-98d6-6d05b1d4d9a1; Fri, 27 Oct 2023 15:34:21 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 9B9D54EE0C87; Fri, 27 Oct 2023 15:34:20 +0200 (CEST) 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: 893a287f-74cd-11ee-98d6-6d05b1d4d9a1 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , George Dunlap , Julien Grall , Wei Liu Subject: [XEN PATCH][for-4.19 v4 3/8] xen/pdx: amend definition of PDX_GROUP_COUNT Date: Fri, 27 Oct 2023 15:34:10 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1698413703461100001 Content-Type: text/plain; charset="utf-8" The definition of PDX_GROUP_COUNT causes violations of MISRA C:2012 Rule 10.1, therefore the problematic part now uses the ISOLATE_LOW_BIT macro, which encapsulates the pattern. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- Changes in v4: -CChanged macro name. --- xen/include/xen/pdx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xen/include/xen/pdx.h b/xen/include/xen/pdx.h index f3fbc4273aa4..6853dc1a601e 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -72,7 +72,7 @@ extern unsigned long max_pdx; =20 #define PDX_GROUP_COUNT ((1 << PDX_GROUP_SHIFT) / \ - (sizeof(*frame_table) & -sizeof(*frame_table))) + (ISOLATE_LOW_BIT(sizeof(*frame_table)))) extern unsigned long pdx_group_valid[]; =20 /** --=20 2.34.1 From nobody Thu May 16 11:48:17 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 169841369745936.51878611242023; Fri, 27 Oct 2023 06:34:57 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.624384.972948 (Exim 4.92) (envelope-from ) id 1qwMyp-0001b8-4G; Fri, 27 Oct 2023 13:34:27 +0000 Received: by outflank-mailman (output) from mailman id 624384.972948; Fri, 27 Oct 2023 13:34:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyp-0001ax-1T; Fri, 27 Oct 2023 13:34:27 +0000 Received: by outflank-mailman (input) for mailman id 624384; Fri, 27 Oct 2023 13:34:23 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyl-0000bB-J7 for xen-devel@lists.xenproject.org; Fri, 27 Oct 2023 13:34:23 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 89a45bec-74cd-11ee-98d6-6d05b1d4d9a1; Fri, 27 Oct 2023 15:34:22 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 7964E4EE0C88; Fri, 27 Oct 2023 15:34:21 +0200 (CEST) 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: 89a45bec-74cd-11ee-98d6-6d05b1d4d9a1 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , Wei Liu Subject: [XEN PATCH][for-4.19 v4 4/8] x86_64/mm: express macro CNT using ISOLATE_LOW_BIT Date: Fri, 27 Oct 2023 15:34:11 +0200 Message-Id: <8e56caec1dfa2ef9a528d58935f16c537adfdbea.1698410970.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1698413699448100001 Content-Type: text/plain; charset="utf-8" The various definitions of macro CNT (and the related BUILD_BUG_ON) can be rewritten using ISOLATE_LOW_BIT, encapsulating a violation of MISRA C:2012 Rule 10.1. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini Acked-by: Jan Beulich --- Changes in v4: - Changed macro name --- xen/arch/x86/x86_64/mm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index c3ebb777144a..710a756a3c07 100644 --- a/xen/arch/x86/x86_64/mm.c +++ b/xen/arch/x86/x86_64/mm.c @@ -351,9 +351,9 @@ static int setup_compat_m2p_table(struct mem_hotadd_inf= o *info) ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1) ); =20 #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (ISOLATE_LOW_BIT(sizeof(*frame_table)) / \ sizeof(*compat_machine_to_phys_mapping)) - BUILD_BUG_ON((sizeof(*frame_table) & -sizeof(*frame_table)) % \ + BUILD_BUG_ON(ISOLATE_LOW_BIT(sizeof(*frame_table)) % \ sizeof(*compat_machine_to_phys_mapping)); =20 for ( i =3D smap; i < emap; i +=3D (1UL << (L2_PAGETABLE_SHIFT - 2)) ) @@ -410,10 +410,10 @@ static int setup_m2p_table(struct mem_hotadd_info *in= fo) va =3D RO_MPT_VIRT_START + smap * sizeof(*machine_to_phys_mapping); =20 #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned long)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (ISOLATE_LOW_BIT(sizeof(*frame_table)) / \ sizeof(*machine_to_phys_mapping)) =20 - BUILD_BUG_ON((sizeof(*frame_table) & -sizeof(*frame_table)) % \ + BUILD_BUG_ON(ISOLATE_LOW_BIT(sizeof(*frame_table)) % \ sizeof(*machine_to_phys_mapping)); =20 i =3D smap; @@ -539,7 +539,7 @@ void __init paging_init(void) mpt_size =3D (max_page * BYTES_PER_LONG) + (1UL << L2_PAGETABLE_SHIFT= ) - 1; mpt_size &=3D ~((1UL << L2_PAGETABLE_SHIFT) - 1UL); #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned long)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (ISOLATE_LOW_BIT(sizeof(*frame_table)) / \ sizeof(*machine_to_phys_mapping)) BUILD_BUG_ON((sizeof(*frame_table) & ~sizeof(*frame_table)) % \ sizeof(*machine_to_phys_mapping)); @@ -666,7 +666,7 @@ void __init paging_init(void) mpt_size =3D 0; =20 #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (ISOLATE_LOW_BIT(sizeof(*frame_table)) / \ sizeof(*compat_machine_to_phys_mapping)) BUILD_BUG_ON((sizeof(*frame_table) & ~sizeof(*frame_table)) % \ sizeof(*compat_machine_to_phys_mapping)); --=20 2.34.1 From nobody Thu May 16 11:48:17 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1698413704853199.5940110207706; Fri, 27 Oct 2023 06:35:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.624385.972953 (Exim 4.92) (envelope-from ) id 1qwMyp-0001dn-Cs; Fri, 27 Oct 2023 13:34:27 +0000 Received: by outflank-mailman (output) from mailman id 624385.972953; Fri, 27 Oct 2023 13:34:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyp-0001dM-8m; Fri, 27 Oct 2023 13:34:27 +0000 Received: by outflank-mailman (input) for mailman id 624385; Fri, 27 Oct 2023 13:34:24 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMym-0000bB-JH for xen-devel@lists.xenproject.org; Fri, 27 Oct 2023 13:34:24 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8a0b81b2-74cd-11ee-98d6-6d05b1d4d9a1; Fri, 27 Oct 2023 15:34:23 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 2F1DC4EE0C89; Fri, 27 Oct 2023 15:34:22 +0200 (CEST) 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: 8a0b81b2-74cd-11ee-98d6-6d05b1d4d9a1 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , Wei Liu Subject: [XEN PATCH][for-4.19 v4 5/8] x86/io_apic: address violation of MISRA C:2012 Rule 10.1 Date: Fri, 27 Oct 2023 15:34:12 +0200 Message-Id: <6de2dac3c48426a11841130d14c9d01f383379ef.1698410970.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1698413705413100005 Content-Type: text/plain; charset="utf-8" The definition of IO_APIC_BASE contains a sum of an essentially enum value (FIX_IO_APIC_BASE_0) that is positive with an index that, in all instances, is unsigned, therefore the former is cast to unsigned, so that the operands are of the same essential type. No functional change. Signed-off-by: Nicola Vetrini Acked-by: Jan Beulich --- Eventually __fix_to_virt may become an inline function; in that case, it should retain unsigned int as its parameter type. Changes in v3: - style fix - Add missing S-o-b --- xen/arch/x86/include/asm/io_apic.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/include/asm/io_apic.h b/xen/arch/x86/include/asm/= io_apic.h index a7e4c9e146de..206bb961c005 100644 --- a/xen/arch/x86/include/asm/io_apic.h +++ b/xen/arch/x86/include/asm/io_apic.h @@ -14,9 +14,10 @@ * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar */ =20 -#define IO_APIC_BASE(idx) \ - ((volatile uint32_t *)(__fix_to_virt(FIX_IO_APIC_BASE_0 + (idx)) \ - + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK))) +#define IO_APIC_BASE(idx) \ + ((volatile uint32_t *) \ + (__fix_to_virt((unsigned int)FIX_IO_APIC_BASE_0 + (idx)) + \ + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK))) =20 #define IO_APIC_ID(idx) (mp_ioapics[idx].mpc_apicid) =20 --=20 2.34.1 From nobody Thu May 16 11:48:17 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1698413691835349.85742133671556; Fri, 27 Oct 2023 06:34:51 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.624386.972960 (Exim 4.92) (envelope-from ) id 1qwMyp-0001je-Rn; Fri, 27 Oct 2023 13:34:27 +0000 Received: by outflank-mailman (output) from mailman id 624386.972960; Fri, 27 Oct 2023 13:34:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyp-0001hl-Hs; Fri, 27 Oct 2023 13:34:27 +0000 Received: by outflank-mailman (input) for mailman id 624386; Fri, 27 Oct 2023 13:34:25 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyn-0000bB-JI for xen-devel@lists.xenproject.org; Fri, 27 Oct 2023 13:34:25 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8a77846d-74cd-11ee-98d6-6d05b1d4d9a1; Fri, 27 Oct 2023 15:34:23 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id D7CB24EE0C8A; Fri, 27 Oct 2023 15:34:22 +0200 (CEST) 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: 8a77846d-74cd-11ee-98d6-6d05b1d4d9a1 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , Wei Liu Subject: [XEN PATCH][for-4.19 v4 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class Date: Fri, 27 Oct 2023 15:34:13 +0200 Message-Id: <6efab48e9340916f23c94baf5c189d1d1c6ab7e6.1698410970.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1698413693461100001 Content-Type: text/plain; charset="utf-8" The definition of MC_NCLASSES contained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves the violation and makes it more resilient to possible additions to that enum. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- This patch has already been picked up in Andrew's for-next tree. Note that the use of an enum constant as operand to [ ] and !=3D is allowed by the Rule. --- xen/arch/x86/cpu/mcheck/mctelem.c | 2 -- xen/arch/x86/cpu/mcheck/mctelem.h | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/cpu/mcheck/mctelem.c b/xen/arch/x86/cpu/mcheck/mc= telem.c index 329ac20faf96..77a4d1d5ff48 100644 --- a/xen/arch/x86/cpu/mcheck/mctelem.c +++ b/xen/arch/x86/cpu/mcheck/mctelem.c @@ -64,8 +64,6 @@ struct mctelem_ent { =20 #define MC_NENT (MC_URGENT_NENT + MC_NONURGENT_NENT) =20 -#define MC_NCLASSES (MC_NONURGENT + 1) - #define COOKIE2MCTE(c) ((struct mctelem_ent *)(c)) #define MCTE2COOKIE(tep) ((mctelem_cookie_t)(tep)) =20 diff --git a/xen/arch/x86/cpu/mcheck/mctelem.h b/xen/arch/x86/cpu/mcheck/mc= telem.h index d4eba53ae0e5..21b251847bc0 100644 --- a/xen/arch/x86/cpu/mcheck/mctelem.h +++ b/xen/arch/x86/cpu/mcheck/mctelem.h @@ -55,8 +55,9 @@ typedef struct mctelem_cookie *mctelem_cookie_t; =20 typedef enum mctelem_class { - MC_URGENT, - MC_NONURGENT + MC_URGENT, + MC_NONURGENT, + MC_NCLASSES } mctelem_class_t; =20 extern void mctelem_init(unsigned int); --=20 2.34.1 From nobody Thu May 16 11:48:17 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1698413701932855.50381901695; Fri, 27 Oct 2023 06:35:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.624387.972965 (Exim 4.92) (envelope-from ) id 1qwMyq-0001rW-63; Fri, 27 Oct 2023 13:34:28 +0000 Received: by outflank-mailman (output) from mailman id 624387.972965; Fri, 27 Oct 2023 13:34:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyp-0001qU-Ul; Fri, 27 Oct 2023 13:34:27 +0000 Received: by outflank-mailman (input) for mailman id 624387; Fri, 27 Oct 2023 13:34:26 +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 1qwMyo-0000bA-1Q for xen-devel@lists.xenproject.org; Fri, 27 Oct 2023 13:34:26 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 8af313ac-74cd-11ee-9b0e-b553b5be7939; Fri, 27 Oct 2023 15:34:24 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 8CFF34EE0C8B; Fri, 27 Oct 2023 15:34:23 +0200 (CEST) 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: 8af313ac-74cd-11ee-9b0e-b553b5be7939 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , George Dunlap , Julien Grall , Wei Liu , Paul Durrant Subject: [XEN PATCH][for-4.19 v4 7/8] xen/types: address Rule 10.1 for DECLARE_BITMAP use Date: Fri, 27 Oct 2023 15:34:14 +0200 Message-Id: <86d78caaef0bb2d73f25ce641dfc80e0a1dc4112.1698410970.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1698413703594100003 Content-Type: text/plain; charset="utf-8" Given its use in the declaration 'DECLARE_BITMAP(features, IOMMU_FEAT_count)' the argument 'bits' has essential type 'enum iommu_feature', which is not allowed by the Rule as an operand to the addition operator in macro 'BITS_TO_LONGS'. This construct is deviated with a deviation comment. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- Changes in v3: - edited comment --- docs/misra/safe.json | 8 ++++++++ xen/include/xen/iommu.h | 1 + xen/include/xen/types.h | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/docs/misra/safe.json b/docs/misra/safe.json index 39c5c056c7d4..952324f85cf9 100644 --- a/docs/misra/safe.json +++ b/docs/misra/safe.json @@ -20,6 +20,14 @@ }, { "id": "SAF-2-safe", + "analyser": { + "eclair": "MC3R1.R10.1" + }, + "name": "MC3R1.R10.1: use of an enumeration constant in an ari= thmetic operation", + "text": "This violation can be fixed with a cast to (int) of t= he enumeration constant, but a deviation was chosen due to code readability= (see also the comment in BITS_TO_LONGS)." + }, + { + "id": "SAF-3-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used" diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 0e747b0bbc1c..d5c25770915b 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -360,6 +360,7 @@ struct domain_iommu { #endif =20 /* Features supported by the IOMMU */ + /* SAF-2-safe enum constant in arithmetic operation */ DECLARE_BITMAP(features, IOMMU_FEAT_count); =20 /* Does the guest share HAP mapping with the IOMMU? */ diff --git a/xen/include/xen/types.h b/xen/include/xen/types.h index aea259db1ef2..64e75674da4f 100644 --- a/xen/include/xen/types.h +++ b/xen/include/xen/types.h @@ -22,6 +22,11 @@ typedef signed long ssize_t; =20 typedef __PTRDIFF_TYPE__ ptrdiff_t; =20 +/* + * Users of this macro are expected to pass a positive value. + * + * XXX: should become an unsigned quantity + */ #define BITS_TO_LONGS(bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) #define DECLARE_BITMAP(name,bits) \ --=20 2.34.1 From nobody Thu May 16 11:48:17 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 Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 16984137043391015.3961060749698; Fri, 27 Oct 2023 06:35:04 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.624388.972972 (Exim 4.92) (envelope-from ) id 1qwMyq-00020g-Pk; Fri, 27 Oct 2023 13:34:28 +0000 Received: by outflank-mailman (output) from mailman id 624388.972972; Fri, 27 Oct 2023 13:34:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyq-0001wb-BE; Fri, 27 Oct 2023 13:34:28 +0000 Received: by outflank-mailman (input) for mailman id 624388; Fri, 27 Oct 2023 13:34:26 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qwMyo-0000bB-JI for xen-devel@lists.xenproject.org; Fri, 27 Oct 2023 13:34:26 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8b68a9e1-74cd-11ee-98d6-6d05b1d4d9a1; Fri, 27 Oct 2023 15:34:25 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 638DB4EE0C8D; Fri, 27 Oct 2023 15:34:24 +0200 (CEST) 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: 8b68a9e1-74cd-11ee-98d6-6d05b1d4d9a1 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , George Dunlap , Julien Grall , Wei Liu Subject: [XEN PATCH][for-4.19 v4 8/8] xen/compat: use BUILD_BUG_ON in CHECK_SIZE macros Date: Fri, 27 Oct 2023 15:34:15 +0200 Message-Id: <16877f531dd79442a7fad6e8bacd17f445a0ad66.1698410970.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZM-MESSAGEID: 1698413705414100006 Content-Type: text/plain; charset="utf-8" BUILD_BUG_ON is the preferred way to induce a build error upon statically determined incorrect conditions. This also fixes a MISRA C:2012 Rule 10.1 violation in the previous formulation. Signed-off-by: Nicola Vetrini Acked-by: Jan Beulich --- Changes in v2: - replace the construct with a BUILD_BUG_ON. Changes in v3: - drop unused typedef. --- xen/include/xen/compat.h | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/xen/include/xen/compat.h b/xen/include/xen/compat.h index f2ce5bb3580a..41a5d61eef98 100644 --- a/xen/include/xen/compat.h +++ b/xen/include/xen/compat.h @@ -151,12 +151,18 @@ CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ return x =3D=3D c; \ } =20 -#define CHECK_SIZE(name) \ - typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) !=3D \ - sizeof(compat_ ## name ## _t)) * = 2] +#define CHECK_SIZE(name) \ +static inline void __maybe_unused CHECK_SIZE_##name(void) \ +{ \ + BUILD_BUG_ON(sizeof(xen_ ## name ## _t) !=3D \ + sizeof(compat_ ## name ## _t)); \ +} #define CHECK_SIZE_(k, n) \ - typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) !=3D \ - sizeof(k compat_ ## n)) * 2] +static inline void __maybe_unused CHECK_SIZE_##k_##n(void) \ +{ \ + BUILD_BUG_ON(sizeof(k xen_ ## n) !=3D \ + sizeof(k compat_ ## n)); \ +} =20 #define CHECK_FIELD_COMMON(name, t, f) \ static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## = _t *c) \ --=20 2.34.1