From patchwork Fri Oct 6 08:26:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411126 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 D873DE92FFB for ; Fri, 6 Oct 2023 08:26:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613302.953759 (Exim 4.92) (envelope-from ) id 1qogA8-0006V9-To; Fri, 06 Oct 2023 08:26:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613302.953759; Fri, 06 Oct 2023 08:26:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qogA8-0006V1-RF; Fri, 06 Oct 2023 08:26:20 +0000 Received: by outflank-mailman (input) for mailman id 613302; Fri, 06 Oct 2023 08:26:19 +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 1qogA7-0006Fc-M6 for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:19 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 05292aa9-6422-11ee-9b0d-b553b5be7939; Fri, 06 Oct 2023 10:26:17 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 6AD184EE073A; Fri, 6 Oct 2023 10:26:16 +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: 05292aa9-6422-11ee-9b0d-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 1/9] xen/include: add macro LOWEST_POW2 Date: Fri, 6 Oct 2023 10:26:04 +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 --- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ xen/include/xen/macros.h | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl index d8170106b449..016164643105 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_POW2 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_POW2$))))"} +-doc_end + ### Set 3 ### # diff --git a/xen/include/xen/macros.h b/xen/include/xen/macros.h index d0caae7db298..bb9a1c9a53d0 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_POW2(x) ((x) & -(x)) + +#define MASK_EXTR(v, m) (((v) & (m)) / LOWEST_POW2(m)) +#define MASK_INSR(v, m) (((v) * LOWEST_POW2(m)) & (m)) #define count_args_(dot, a1, a2, a3, a4, a5, a6, a7, a8, x, ...) x #define count_args(args...) \ From patchwork Fri Oct 6 08:26:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411122 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 DCA5AE92FF9 for ; Fri, 6 Oct 2023 08:26:32 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613305.953783 (Exim 4.92) (envelope-from ) id 1qogAA-00074x-Qb; Fri, 06 Oct 2023 08:26:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613305.953783; Fri, 06 Oct 2023 08:26:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qogAA-00073K-KM; Fri, 06 Oct 2023 08:26:22 +0000 Received: by outflank-mailman (input) for mailman id 613305; Fri, 06 Oct 2023 08:26:20 +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 1qogA8-0006Fc-MH for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:20 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 05a511e9-6422-11ee-9b0d-b553b5be7939; Fri, 06 Oct 2023 10:26:18 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 56B8C4EE073C; Fri, 6 Oct 2023 10:26:17 +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: 05a511e9-6422-11ee-9b0d-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 , Julien Grall , Bertrand Marquis , Volodymyr Babchuk Subject: [XEN PATCH][for-4.19 2/9] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1 Date: Fri, 6 Oct 2023 10:26:05 +0200 Message-Id: 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_POW2 macro. No functional change. --- 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..d119e1ccc952 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_POW2(__t)); }) +#define ffsl(x) ({ unsigned long __t = (x); flsl(LOWEST_POW2(__t)); }) /** * find_first_set_bit - find the first set bit in @word From patchwork Fri Oct 6 08:26:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411121 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 C0AE3E92FFA for ; Fri, 6 Oct 2023 08:26:30 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613303.953762 (Exim 4.92) (envelope-from ) id 1qogA9-0006Xf-61; Fri, 06 Oct 2023 08:26:21 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613303.953762; Fri, 06 Oct 2023 08:26:21 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qogA9-0006X1-2p; Fri, 06 Oct 2023 08:26:21 +0000 Received: by outflank-mailman (input) for mailman id 613303; Fri, 06 Oct 2023 08:26:19 +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 1qogA7-0006Fk-U6 for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:19 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 062776ce-6422-11ee-98d3-6d05b1d4d9a1; Fri, 06 Oct 2023 10:26:19 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 2DC6D4EE073D; Fri, 6 Oct 2023 10:26:18 +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: 062776ce-6422-11ee-98d3-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 3/9] xen/pdx: amend definition of PDX_GROUP_COUNT Date: Fri, 6 Oct 2023 10:26:06 +0200 Message-Id: <370da41f72fa55c95a97268c250efc76a33d93d3.1696514677.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_POW2 macro, which encapsulates the pattern. Signed-off-by: Nicola Vetrini --- 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..5b88a4a2cd86 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_POW2(sizeof(*frame_table)))) extern unsigned long pdx_group_valid[]; /** From patchwork Fri Oct 6 08:26:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411124 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 8090CE92FFA for ; Fri, 6 Oct 2023 08:26:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613304.953779 (Exim 4.92) (envelope-from ) id 1qogAA-00071H-Fr; Fri, 06 Oct 2023 08:26:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613304.953779; Fri, 06 Oct 2023 08:26:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qogAA-0006zP-CQ; Fri, 06 Oct 2023 08:26:22 +0000 Received: by outflank-mailman (input) for mailman id 613304; Fri, 06 Oct 2023 08:26:20 +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 1qogA8-0006Fk-Jt for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:20 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 06973160-6422-11ee-98d3-6d05b1d4d9a1; Fri, 06 Oct 2023 10:26:19 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 0C6664EE073E; Fri, 6 Oct 2023 10:26:18 +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: 06973160-6422-11ee-98d3-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 4/9] x86_64/mm: express macro CNT using LOWEST_POW2 Date: Fri, 6 Oct 2023 10:26:07 +0200 Message-Id: <1a44e7559ce4c7588a7b76c19d3154e471417cfa.1696514677.git.nicola.vetrini@bugseng.com> 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_POW2, encapsulating a violation of MISRA C:2012 Rule 10.1. Signed-off-by: Nicola Vetrini --- I do find somewhat odd the multiple identical #define-s and #undef-s of CNT in this file, as well as the last BUILD_BUG_ON((sizeof(*frame_table) & ~sizeof(*frame_table)) [...] Perhaps here a cleanup is needed, to have a single definition of CNT and identical BUILD_BUG_ON-s (wrapped in a macro, even)? --- 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..8ae704f920a1 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_POW2(sizeof(*frame_table)) / \ sizeof(*compat_machine_to_phys_mapping)) - BUILD_BUG_ON((sizeof(*frame_table) & -sizeof(*frame_table)) % \ + BUILD_BUG_ON(LOWEST_POW2(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_POW2(sizeof(*frame_table)) / \ sizeof(*machine_to_phys_mapping)) - BUILD_BUG_ON((sizeof(*frame_table) & -sizeof(*frame_table)) % \ + BUILD_BUG_ON(LOWEST_POW2(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_POW2(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_POW2(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 Fri Oct 6 08:26:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411123 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 0DCB1E92FF8 for ; Fri, 6 Oct 2023 08:26:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613306.953791 (Exim 4.92) (envelope-from ) id 1qogAB-0007AS-9F; Fri, 06 Oct 2023 08:26:23 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613306.953791; Fri, 06 Oct 2023 08:26: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 1qogAB-00077t-1k; Fri, 06 Oct 2023 08:26:23 +0000 Received: by outflank-mailman (input) for mailman id 613306; Fri, 06 Oct 2023 08:26:21 +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 1qogA9-0006Fk-KG for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:21 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0704009e-6422-11ee-98d3-6d05b1d4d9a1; Fri, 06 Oct 2023 10:26:20 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id C12D34EE074E; Fri, 6 Oct 2023 10:26:19 +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: 0704009e-6422-11ee-98d3-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 5/9] x86/cpu-policy: address violations of MISRA C Rule 10.1 Date: Fri, 6 Oct 2023 10:26:08 +0200 Message-Id: <463572d126a7700e5e90ef3a49104bd4b8c1c389.1696514677.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 The COUNT_LEAVES macro is introduced to avoid using an essentially boolean value in a subtraction. No functional change. Signed-off-by: Nicola Vetrini --- xen/include/xen/lib/x86/cpu-policy.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/xen/include/xen/lib/x86/cpu-policy.h b/xen/include/xen/lib/x86/cpu-policy.h index bab3eecda6c1..700993cc67e8 100644 --- a/xen/include/xen/lib/x86/cpu-policy.h +++ b/xen/include/xen/lib/x86/cpu-policy.h @@ -95,17 +95,18 @@ const char *x86_cpuid_vendor_to_str(unsigned int vendor); #define CPUID_GUEST_NR_EXTD MAX(CPUID_GUEST_NR_EXTD_INTEL, \ CPUID_GUEST_NR_EXTD_AMD) +#define COUNT_LEAVES(X) ((X) - ((X) ? 1 : 0)) /* * Maximum number of leaves a struct cpu_policy turns into when serialised for * interaction with the toolstack. (Sum of all leaves in each union, less the * entries in basic which sub-unions hang off of.) */ -#define CPUID_MAX_SERIALISED_LEAVES \ - (CPUID_GUEST_NR_BASIC + \ - CPUID_GUEST_NR_FEAT - !!CPUID_GUEST_NR_FEAT + \ - CPUID_GUEST_NR_CACHE - !!CPUID_GUEST_NR_CACHE + \ - CPUID_GUEST_NR_TOPO - !!CPUID_GUEST_NR_TOPO + \ - CPUID_GUEST_NR_XSTATE - !!CPUID_GUEST_NR_XSTATE + \ +#define CPUID_MAX_SERIALISED_LEAVES \ + (CPUID_GUEST_NR_BASIC + \ + COUNT_LEAVES(CPUID_GUEST_NR_FEAT) + \ + COUNT_LEAVES(CPUID_GUEST_NR_CACHE) + \ + COUNT_LEAVES(CPUID_GUEST_NR_TOPO) + \ + COUNT_LEAVES(CPUID_GUEST_NR_XSTATE) + \ CPUID_GUEST_NR_EXTD + 2 /* hv_limit and hv2_limit */ ) /* Maximum number of MSRs written when serialising a cpu_policy. */ From patchwork Fri Oct 6 08:26:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411125 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 9E1DCE92FFC for ; Fri, 6 Oct 2023 08:26:33 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613307.953807 (Exim 4.92) (envelope-from ) id 1qogAC-0007gs-LG; Fri, 06 Oct 2023 08:26:24 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613307.953807; Fri, 06 Oct 2023 08:26: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 1qogAC-0007fb-EE; Fri, 06 Oct 2023 08:26:24 +0000 Received: by outflank-mailman (input) for mailman id 613307; Fri, 06 Oct 2023 08:26: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 1qogAA-0006Fk-KV for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:22 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 076ff614-6422-11ee-98d3-6d05b1d4d9a1; Fri, 06 Oct 2023 10:26:21 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 7C7D14EE0C87; Fri, 6 Oct 2023 10:26:20 +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: 076ff614-6422-11ee-98d3-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 6/9] x86/io_apic: address violation of MISRA C:2012 Rule 10.1 Date: Fri, 6 Oct 2023 10:26:09 +0200 Message-Id: <7def4be3f63306569a2ac1776c2d6ed24ff24ee2.1696514677.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. Reviewed-by: Stefano Stabellini --- 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 Fri Oct 6 08:26:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411128 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 EE6D0E92FF8 for ; Fri, 6 Oct 2023 08:26:36 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613308.953813 (Exim 4.92) (envelope-from ) id 1qogAD-0007o0-7I; Fri, 06 Oct 2023 08:26:25 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613308.953813; Fri, 06 Oct 2023 08:26:25 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qogAC-0007mB-S9; Fri, 06 Oct 2023 08:26:24 +0000 Received: by outflank-mailman (input) for mailman id 613308; Fri, 06 Oct 2023 08:26: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 1qogAB-0006Fk-Kn for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:23 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 07db203e-6422-11ee-98d3-6d05b1d4d9a1; Fri, 06 Oct 2023 10:26:22 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 333864EE0C81; Fri, 6 Oct 2023 10:26:21 +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: 07db203e-6422-11ee-98d3-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 7/9] x86/mce: Move MC_NCLASSES into the enum mctelem_class Date: Fri, 6 Oct 2023 10:26:10 +0200 Message-Id: <08293d72e236a7a6aec0305bc3f901a6636747ab.1696514677.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 Acked-by: Andrew Cooper --- 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 Fri Oct 6 08:26:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411127 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 F377CE92FF9 for ; Fri, 6 Oct 2023 08:26:35 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613309.953828 (Exim 4.92) (envelope-from ) id 1qogAE-0008Ma-VB; Fri, 06 Oct 2023 08:26:26 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613309.953828; Fri, 06 Oct 2023 08:26:26 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qogAE-0008L1-Pl; Fri, 06 Oct 2023 08:26:26 +0000 Received: by outflank-mailman (input) for mailman id 613309; Fri, 06 Oct 2023 08:26: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 1qogAC-0006Fk-LE for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:24 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 085ea74b-6422-11ee-98d3-6d05b1d4d9a1; Fri, 06 Oct 2023 10:26:22 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id DEEA04EE0C88; Fri, 6 Oct 2023 10:26:21 +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: 085ea74b-6422-11ee-98d3-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 , Paul Durrant , George Dunlap , Julien Grall , Wei Liu Subject: [XEN PATCH][for-4.19 8/9] xen/types: address Rule 10.1 for DECLARE_BITMAP use Date: Fri, 6 Oct 2023 10:26:11 +0200 Message-Id: <9642dcb4ab51ec9eaeedf16056fbcd946a3efbea.1696514677.git.nicola.vetrini@bugseng.com> 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'. A comment in BITS_TO_LONGS is added to make it clear that values passed are meant to be positive. Signed-off-by: Nicola Vetrini --- xen/include/xen/iommu.h | 2 +- xen/include/xen/types.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 0e747b0bbc1c..34aa0b9b5b81 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -360,7 +360,7 @@ struct domain_iommu { #endif /* Features supported by the IOMMU */ - DECLARE_BITMAP(features, IOMMU_FEAT_count); + DECLARE_BITMAP(features, (int)IOMMU_FEAT_count); /* Does the guest share HAP mapping with the IOMMU? */ bool hap_pt_share; diff --git a/xen/include/xen/types.h b/xen/include/xen/types.h index aea259db1ef2..936e83d333a0 100644 --- a/xen/include/xen/types.h +++ b/xen/include/xen/types.h @@ -22,6 +22,7 @@ typedef signed long ssize_t; typedef __PTRDIFF_TYPE__ ptrdiff_t; +/* Users of this macro are expected to pass a positive value */ #define BITS_TO_LONGS(bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) #define DECLARE_BITMAP(name,bits) \ From patchwork Fri Oct 6 08:26:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13411129 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 95459E92FFE for ; Fri, 6 Oct 2023 08:26:37 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.613310.953834 (Exim 4.92) (envelope-from ) id 1qogAF-0008Rm-Jx; Fri, 06 Oct 2023 08:26:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 613310.953834; Fri, 06 Oct 2023 08:26: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 1qogAF-0008QV-8Q; Fri, 06 Oct 2023 08:26:27 +0000 Received: by outflank-mailman (input) for mailman id 613310; Fri, 06 Oct 2023 08:26: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 1qogAD-0006Fk-LQ for xen-devel@lists.xenproject.org; Fri, 06 Oct 2023 08:26:25 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 08da8f32-6422-11ee-98d3-6d05b1d4d9a1; Fri, 06 Oct 2023 10:26:23 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id BEC954EE0C89; Fri, 6 Oct 2023 10:26:22 +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: 08da8f32-6422-11ee-98d3-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 9/9] xen/compat: address Rule 10.1 for macros CHECK_SIZE Date: Fri, 6 Oct 2023 10:26:12 +0200 Message-Id: <7edf60c0e7bd0680d8b8f8d3aec1264ee5a43878.1696514677.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 The essential type of the result of an inequality operator is essentially boolean, therefore it shouldn't be used as an argument of the multiplication operator, which expects an integer. Signed-off-by: Nicola Vetrini --- xen/include/xen/compat.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/xen/include/xen/compat.h b/xen/include/xen/compat.h index f2ce5bb3580a..5ffee6a9fed1 100644 --- a/xen/include/xen/compat.h +++ b/xen/include/xen/compat.h @@ -151,12 +151,14 @@ CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ return x == c; \ } +#define SIZE_NEQUAL(a, b) \ + (sizeof(a) != sizeof(b) ? 1 : 0) #define CHECK_SIZE(name) \ - typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) != \ - sizeof(compat_ ## name ## _t)) * 2] + typedef int CHECK_NAME(name, S)[1 - (SIZE_NEQUAL(xen_ ## name ## _t, \ + compat_ ## name ## _t)) * 2] #define CHECK_SIZE_(k, n) \ - typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) != \ - sizeof(k compat_ ## n)) * 2] + typedef int CHECK_NAME_(k, n, S)[1 - (SIZE_NEQUAL(k xen_ ## n, \ + k compat_ ## n)) * 2] #define CHECK_FIELD_COMMON(name, t, f) \ static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \