From patchwork Thu Oct 12 15:28:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13419387 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B2355C41513 for ; Thu, 12 Oct 2023 15:29:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615839.957329 (Exim 4.92) (envelope-from ) id 1qqxcU-0006UV-3m; Thu, 12 Oct 2023 15:29:02 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615839.957329; Thu, 12 Oct 2023 15:29:02 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqxcT-0006TY-Ty; Thu, 12 Oct 2023 15:29:01 +0000 Received: by outflank-mailman (input) for mailman id 615839; Thu, 12 Oct 2023 15:29:01 +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 1qqxcT-0006QI-1J for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 15:29:01 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 109d92c0-6914-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 17:28:59 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id E020B4EE0744; Thu, 12 Oct 2023 17:28:57 +0200 (CEST) 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: 109d92c0-6914-11ee-98d4-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 , Simone Ballarin , Doug Goldstein , George Dunlap , Julien Grall , Wei Liu Subject: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT Date: Thu, 12 Oct 2023 17:28:45 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 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 2^ffs(x), where ffs(x) is the position of the lowest set bit in x. A deviation for ECLAIR is also introduced. Signed-off-by: Nicola Vetrini --- Changes in v2: - rename to LOWEST_BIT --- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ xen/include/xen/macros.h | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) -- 2.34.1 diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl index d8170106b449..b8e1155ee49d 100644 --- a/automation/eclair_analysis/ECLAIR/deviations.ecl +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl @@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern to obtain the value +2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_end + ### Set 3 ### # diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h index d0caae7db298..af47179d1056 100644 --- a/xen/include/xen/macros.h +++ b/xen/include/xen/macros.h @@ -8,8 +8,10 @@ #define DIV_ROUND(n, d) (((n) + (d) / 2) / (d)) #define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR(v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR(v, m) (((v) * ((m) & -(m))) & (m)) +#define LOWEST_BIT(x) ((x) & -(x)) + +#define MASK_EXTR(v, m) (((v) & (m)) / LOWEST_BIT(m)) +#define MASK_INSR(v, m) (((v) * LOWEST_BIT(m)) & (m)) #define count_args_(dot, a1, a2, a3, a4, a5, a6, a7, a8, x, ...) x #define count_args(args...) \ From patchwork Thu Oct 12 15:28:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13419382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 996E2C46CA1 for ; Thu, 12 Oct 2023 15:29:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615840.957343 (Exim 4.92) (envelope-from ) id 1qqxcV-0006ty-7f; Thu, 12 Oct 2023 15:29:03 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615840.957343; Thu, 12 Oct 2023 15:29:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqxcV-0006tr-4u; Thu, 12 Oct 2023 15:29:03 +0000 Received: by outflank-mailman (input) for mailman id 615840; Thu, 12 Oct 2023 15:29:01 +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 1qqxcT-0006QI-Og for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 15:29:01 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 11a4e2d1-6914-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 17:29:01 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 89A164EE0746; Thu, 12 Oct 2023 17:28:59 +0200 (CEST) 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: 11a4e2d1-6914-11ee-98d4-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 v2 2/8] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1 Date: Thu, 12 Oct 2023 17:28:46 +0200 Message-Id: <042f79da9c4480955c5fb82a25e4847c4777fbea.1697123806.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 The definitions of ffs{l}? violate Rule 10.1, by using the well-known pattern (x & -x); its usage is wrapped by the LOWEST_BIT macro. No functional change. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- 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/bitops.h index 71ae14cab355..8b5d61545e19 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 +#include + #include /* @@ -155,8 +157,8 @@ static inline int fls(unsigned int x) } -#define ffs(x) ({ unsigned int __t = (x); fls(__t & -__t); }) -#define ffsl(x) ({ unsigned long __t = (x); flsl(__t & -__t); }) +#define ffs(x) ({ unsigned int __t = (x); fls(LOWEST_BIT(__t)); }) +#define ffsl(x) ({ unsigned long __t = (x); flsl(LOWEST_BIT(__t)); }) /** * find_first_set_bit - find the first set bit in @word From patchwork Thu Oct 12 15:28:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13419385 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D760ACDB46E for ; Thu, 12 Oct 2023 15:29:22 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615841.957353 (Exim 4.92) (envelope-from ) id 1qqxcW-00079L-Es; Thu, 12 Oct 2023 15:29:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615841.957353; Thu, 12 Oct 2023 15:29:04 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqxcW-00079E-Bv; Thu, 12 Oct 2023 15:29:04 +0000 Received: by outflank-mailman (input) for mailman id 615841; Thu, 12 Oct 2023 15:29:03 +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 1qqxcV-0006QI-C9 for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 15:29:03 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 128e930c-6914-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 17:29:02 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 2DBBF4EE0747; Thu, 12 Oct 2023 17:29:01 +0200 (CEST) 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: 128e930c-6914-11ee-98d4-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 v2 3/8] xen/pdx: amend definition of PDX_GROUP_COUNT Date: Thu, 12 Oct 2023 17:28:47 +0200 Message-Id: <62f8b9c36ad78352fc796878fd9759307ec3e380.1697123806.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 The definition of PDX_GROUP_COUNT causes violations of MISRA C:2012 Rule 10.1, therefore the problematic part now uses the LOWEST_BIT macro, which encapsulates the pattern. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- 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..36d618a8ba7d 100644 --- a/xen/include/xen/pdx.h +++ b/xen/include/xen/pdx.h @@ -72,7 +72,7 @@ extern unsigned long max_pdx; #define PDX_GROUP_COUNT ((1 << PDX_GROUP_SHIFT) / \ - (sizeof(*frame_table) & -sizeof(*frame_table))) + (LOWEST_BIT(sizeof(*frame_table)))) extern unsigned long pdx_group_valid[]; /** From patchwork Thu Oct 12 15:28:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13419383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6C55ECDB47E for ; Thu, 12 Oct 2023 15:29:17 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615842.957363 (Exim 4.92) (envelope-from ) id 1qqxcX-0007Ph-OK; Thu, 12 Oct 2023 15:29:05 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615842.957363; Thu, 12 Oct 2023 15:29:05 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqxcX-0007PS-JY; Thu, 12 Oct 2023 15:29:05 +0000 Received: by outflank-mailman (input) for mailman id 615842; Thu, 12 Oct 2023 15:29:04 +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 1qqxcW-0006QI-Iq for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 15:29:04 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 134e2440-6914-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 17:29:04 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id CB0064EE0748; Thu, 12 Oct 2023 17:29:02 +0200 (CEST) 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: 134e2440-6914-11ee-98d4-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-next v2 4/8] x86_64/mm: express macro CNT using LOWEST_BIT Date: Thu, 12 Oct 2023 17:28:48 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 The various definitions of macro CNT (and the related BUILD_BUG_ON) can be rewritten using LOWEST_BIT, encapsulating a violation of MISRA C:2012 Rule 10.1. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- xen/arch/x86/x86_64/mm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) -- 2.34.1 diff --git a/xen/arch/x86/x86_64/mm.c b/xen/arch/x86/x86_64/mm.c index c3ebb777144a..0eb7b71124f5 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_info *info) ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1) ); #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (LOWEST_BIT(sizeof(*frame_table)) / \ sizeof(*compat_machine_to_phys_mapping)) - BUILD_BUG_ON((sizeof(*frame_table) & -sizeof(*frame_table)) % \ + BUILD_BUG_ON(LOWEST_BIT(sizeof(*frame_table)) % \ sizeof(*compat_machine_to_phys_mapping)); for ( i = smap; i < emap; i += (1UL << (L2_PAGETABLE_SHIFT - 2)) ) @@ -410,10 +410,10 @@ static int setup_m2p_table(struct mem_hotadd_info *info) va = RO_MPT_VIRT_START + smap * sizeof(*machine_to_phys_mapping); #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned long)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (LOWEST_BIT(sizeof(*frame_table)) / \ sizeof(*machine_to_phys_mapping)) - BUILD_BUG_ON((sizeof(*frame_table) & -sizeof(*frame_table)) % \ + BUILD_BUG_ON(LOWEST_BIT(sizeof(*frame_table)) % \ sizeof(*machine_to_phys_mapping)); i = smap; @@ -539,7 +539,7 @@ void __init paging_init(void) mpt_size = (max_page * BYTES_PER_LONG) + (1UL << L2_PAGETABLE_SHIFT) - 1; mpt_size &= ~((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 (LOWEST_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 = 0; #define MFN(x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (LOWEST_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)); From patchwork Thu Oct 12 15:28:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13419386 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8A2E3CDB484 for ; Thu, 12 Oct 2023 15:29:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615843.957370 (Exim 4.92) (envelope-from ) id 1qqxcY-0007Yh-9l; Thu, 12 Oct 2023 15:29:06 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615843.957370; Thu, 12 Oct 2023 15:29:06 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqxcY-0007Xp-4a; Thu, 12 Oct 2023 15:29:06 +0000 Received: by outflank-mailman (input) for mailman id 615843; Thu, 12 Oct 2023 15:29:05 +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 1qqxcX-0006QI-6e for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 15:29:05 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 13b50218-6914-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 17:29:04 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id EC4F64EE0749; Thu, 12 Oct 2023 17:29:03 +0200 (CEST) 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: 13b50218-6914-11ee-98d4-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-next v2 5/8] x86/io_apic: address violation of MISRA C:2012 Rule 10.1 Date: Thu, 12 Oct 2023 17:28:49 +0200 Message-Id: <1fe7602b48cabb7710025f6b4e32e9b99a1faacd.1697123806.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 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. --- 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..a0fc50d601fe 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 */ -#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))) #define IO_APIC_ID(idx) (mp_ioapics[idx].mpc_apicid) From patchwork Thu Oct 12 15:28:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13419388 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A8BEBCDB483 for ; Thu, 12 Oct 2023 15:29:23 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615845.957389 (Exim 4.92) (envelope-from ) id 1qqxca-000833-Vy; Thu, 12 Oct 2023 15:29:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615845.957389; Thu, 12 Oct 2023 15:29:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqxca-000829-OL; Thu, 12 Oct 2023 15:29:08 +0000 Received: by outflank-mailman (input) for mailman id 615845; Thu, 12 Oct 2023 15:29:07 +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 1qqxcZ-0006QC-0H for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 15:29:07 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1429e5d5-6914-11ee-9b0e-b553b5be7939; Thu, 12 Oct 2023 17:29:05 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id A206E4EE074B; Thu, 12 Oct 2023 17:29:04 +0200 (CEST) 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: 1429e5d5-6914-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 , Wei Liu Subject: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class Date: Thu, 12 Oct 2023 17:28:50 +0200 Message-Id: <6622a2ec7079f86b73ae420e1e840d3d35ffb3a0.1697123806.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 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 --- Note that the use of an enum constant as operand to [ ] and != 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/mctelem.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 { #define MC_NENT (MC_URGENT_NENT + MC_NONURGENT_NENT) -#define MC_NCLASSES (MC_NONURGENT + 1) - #define COOKIE2MCTE(c) ((struct mctelem_ent *)(c)) #define MCTE2COOKIE(tep) ((mctelem_cookie_t)(tep)) diff --git a/xen/arch/x86/cpu/mcheck/mctelem.h b/xen/arch/x86/cpu/mcheck/mctelem.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; typedef enum mctelem_class { - MC_URGENT, - MC_NONURGENT + MC_URGENT, + MC_NONURGENT, + MC_NCLASSES } mctelem_class_t; extern void mctelem_init(unsigned int); From patchwork Thu Oct 12 15:28:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13419380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92C3DCDB482 for ; Thu, 12 Oct 2023 15:29:16 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615844.957383 (Exim 4.92) (envelope-from ) id 1qqxca-0007ys-I7; Thu, 12 Oct 2023 15:29:08 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615844.957383; Thu, 12 Oct 2023 15:29:08 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqxca-0007yl-ER; Thu, 12 Oct 2023 15:29:08 +0000 Received: by outflank-mailman (input) for mailman id 615844; Thu, 12 Oct 2023 15:29:06 +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 1qqxcY-0006QI-SX for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 15:29:06 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 14ade131-6914-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 17:29:06 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 657A04EE074A; Thu, 12 Oct 2023 17:29:05 +0200 (CEST) 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: 14ade131-6914-11ee-98d4-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 , Paul Durrant Subject: [XEN PATCH][for-4.19 v2 7/8] xen/types: address Rule 10.1 for DECLARE_BITMAP use Date: Thu, 12 Oct 2023 17:28:51 +0200 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 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 --- docs/misra/safe.json | 8 ++++++++ xen/include/xen/iommu.h | 1 + xen/include/xen/types.h | 8 ++++++++ 3 files changed, 17 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 arithmetic operation", + "text": "This violation can be fixed with a cast to (int) of the 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 /* Features supported by the IOMMU */ + /* SAF-2-safe enum constant in arithmetic operation */ DECLARE_BITMAP(features, IOMMU_FEAT_count); /* 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..50171ea1ad28 100644 --- a/xen/include/xen/types.h +++ b/xen/include/xen/types.h @@ -22,6 +22,14 @@ typedef signed long ssize_t; typedef __PTRDIFF_TYPE__ ptrdiff_t; +/* + * Users of this macro are expected to pass a positive value. + * + * Eventually, this should become an unsigned quantity, but this + * requires fixing various uses of this macro and BITS_PER_LONG in signed + * contexts, such as type-safe 'min' macro uses, which give rise to build errors + * when the arguments have differing signedness, due to the build flags used. + */ #define BITS_TO_LONGS(bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) #define DECLARE_BITMAP(name,bits) \ From patchwork Thu Oct 12 15:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13419384 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0220FCDB47E for ; Thu, 12 Oct 2023 15:29:21 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.615846.957392 (Exim 4.92) (envelope-from ) id 1qqxcb-00087N-A9; Thu, 12 Oct 2023 15:29:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 615846.957392; Thu, 12 Oct 2023 15:29:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qqxcb-00085x-25; Thu, 12 Oct 2023 15:29:09 +0000 Received: by outflank-mailman (input) for mailman id 615846; Thu, 12 Oct 2023 15:29:07 +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 1qqxcZ-0006QI-No for xen-devel@lists.xenproject.org; Thu, 12 Oct 2023 15:29:07 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 1532993c-6914-11ee-98d4-6d05b1d4d9a1; Thu, 12 Oct 2023 17:29:07 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 434474EE074C; Thu, 12 Oct 2023 17:29:06 +0200 (CEST) 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: 1532993c-6914-11ee-98d4-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 v2 8/8] xen/compat: use BUILD_BUG_ON in CHECK_SIZE macros Date: Thu, 12 Oct 2023 17:28:52 +0200 Message-Id: <6138e02935236afd51a5db98d3527e5e2602468d.1697123806.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 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 --- Changes in v2: - replace the construct with a BUILD_BUG_ON. --- xen/include/xen/compat.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/xen/include/xen/compat.h b/xen/include/xen/compat.h index f2ce5bb3580a..4daa04183eac 100644 --- a/xen/include/xen/compat.h +++ b/xen/include/xen/compat.h @@ -151,12 +151,20 @@ CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ return x == c; \ } -#define CHECK_SIZE(name) \ - typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) != \ - sizeof(compat_ ## name ## _t)) * 2] +#define CHECK_SIZE(name) \ +static inline void __maybe_unused CHECK_SIZE_##name(void) \ +{ \ + typedef int CHECK_NAME(name, S)[1]; \ + BUILD_BUG_ON(sizeof(xen_ ## name ## _t) != \ + sizeof(compat_ ## name ## _t)); \ +} #define CHECK_SIZE_(k, n) \ - typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) != \ - sizeof(k compat_ ## n)) * 2] +static inline void __maybe_unused CHECK_SIZE_##k_##n(void) \ +{ \ + typedef int CHECK_NAME_(k, n, S)[1]; \ + BUILD_BUG_ON(sizeof(k xen_ ## n) != \ + sizeof(k compat_ ## n)); \ +} #define CHECK_FIELD_COMMON(name, t, f) \ static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \