From patchwork Thu Dec 7 09:48:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13483082 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 4CA63C4167B for ; Thu, 7 Dec 2023 09:51:14 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.649722.1014536 (Exim 4.92) (envelope-from ) id 1rBB28-00049X-Bo; Thu, 07 Dec 2023 09:51:04 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 649722.1014536; Thu, 07 Dec 2023 09:51: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 1rBB28-00049Q-7B; Thu, 07 Dec 2023 09:51:04 +0000 Received: by outflank-mailman (input) for mailman id 649722; Thu, 07 Dec 2023 09:51:02 +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 1rBB26-00048w-EC for xen-devel@lists.xenproject.org; Thu, 07 Dec 2023 09:51:02 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 1f34fa2d-94e6-11ee-9b0f-b553b5be7939; Thu, 07 Dec 2023 10:50:58 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id B5F134EE073A; Thu, 7 Dec 2023 10:50:57 +0100 (CET) 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: 1f34fa2d-94e6-11ee-9b0f-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Jan Beulich , Andrew Cooper , Kevin Tian , Simone Ballarin Subject: [PATCH 1/3] AMD/IOMMU: address violations of MISRA C:2012 Rule 14.4 Date: Thu, 7 Dec 2023 10:48:42 +0100 Message-Id: <097df7703c372a687206251fe97bfc5df18222b6.1701941924.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 14.4 whose headline states: "The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type". Add comparisons to avoid using enum constants as controlling expressions to comply with Rule 14.4. No functional change. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin Reviewed-by: Stefano Stabellini --- xen/drivers/passthrough/amd/iommu_init.c | 4 ++-- xen/drivers/passthrough/vtd/iommu.c | 4 ++-- xen/drivers/passthrough/vtd/quirks.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/xen/drivers/passthrough/amd/iommu_init.c b/xen/drivers/passthrough/amd/iommu_init.c index 5515cb70fd..e02a09a9a7 100644 --- a/xen/drivers/passthrough/amd/iommu_init.c +++ b/xen/drivers/passthrough/amd/iommu_init.c @@ -1480,7 +1480,7 @@ int __init amd_iommu_init(bool xt) goto error_out; } - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) register_keyhandler('V', &amd_iommu_dump_intremap_tables, "dump IOMMU intremap tables", 0); @@ -1498,7 +1498,7 @@ int __init amd_iommu_init_late(void) /* Further initialize the device table(s). */ pci_init = true; - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) rc = iterate_ivrs_mappings(amd_iommu_setup_device_table); for_each_amd_iommu ( iommu ) diff --git a/xen/drivers/passthrough/vtd/iommu.c b/xen/drivers/passthrough/vtd/iommu.c index e13b7d99db..bd6d69a6f5 100644 --- a/xen/drivers/passthrough/vtd/iommu.c +++ b/xen/drivers/passthrough/vtd/iommu.c @@ -2543,7 +2543,7 @@ static int __must_check init_vtd_hw(bool resume) /* * Enable interrupt remapping */ - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) { int apic; for ( apic = 0; apic < nr_ioapics; apic++ ) @@ -2559,7 +2559,7 @@ static int __must_check init_vtd_hw(bool resume) } } } - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) { for_each_drhd_unit ( drhd ) { diff --git a/xen/drivers/passthrough/vtd/quirks.c b/xen/drivers/passthrough/vtd/quirks.c index 5a56565ea8..950dcd56ef 100644 --- a/xen/drivers/passthrough/vtd/quirks.c +++ b/xen/drivers/passthrough/vtd/quirks.c @@ -392,7 +392,7 @@ void __init platform_quirks_init(void) map_igd_reg(); /* Tylersburg interrupt remap quirk */ - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) tylersburg_intremap_quirk(); } From patchwork Thu Dec 7 09:48:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13483083 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 8A11FC4167B for ; Thu, 7 Dec 2023 09:51:20 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.649723.1014544 (Exim 4.92) (envelope-from ) id 1rBB2H-0004Rw-HX; Thu, 07 Dec 2023 09:51:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 649723.1014544; Thu, 07 Dec 2023 09:51:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rBB2H-0004Rp-Eb; Thu, 07 Dec 2023 09:51:13 +0000 Received: by outflank-mailman (input) for mailman id 649723; Thu, 07 Dec 2023 09:51:11 +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 1rBB2F-00048w-Rv for xen-devel@lists.xenproject.org; Thu, 07 Dec 2023 09:51:11 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 264f2883-94e6-11ee-9b0f-b553b5be7939; Thu, 07 Dec 2023 10:51:10 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id 91B904EE073A; Thu, 7 Dec 2023 10:51:09 +0100 (CET) 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: 264f2883-94e6-11ee-9b0f-b553b5be7939 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Wei Liu , Simone Ballarin Subject: [PATCH 2/3] xen/x86: address violations of MISRA C:2012 Rule 14.4 Date: Thu, 7 Dec 2023 10:48:43 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 14.4 whose headline states: "The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type". Add comparisons to avoid using enum constants as controlling expressions to comply with Rule 14.4. No functional change. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin Reviewed-by: Stefano Stabellini --- xen/arch/x86/hpet.c | 6 +++--- xen/arch/x86/msi.c | 4 ++-- xen/arch/x86/x86_emulate/x86_emulate.c | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/xen/arch/x86/hpet.c b/xen/arch/x86/hpet.c index 7be26c6a9b..d1ddc8ddf6 100644 --- a/xen/arch/x86/hpet.c +++ b/xen/arch/x86/hpet.c @@ -279,7 +279,7 @@ static int hpet_msi_write(struct hpet_event_channel *ch, struct msi_msg *msg) { ch->msi.msg = *msg; - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) { int rc = iommu_update_ire_from_msi(&ch->msi, msg); @@ -353,7 +353,7 @@ static int __init hpet_setup_msi_irq(struct hpet_event_channel *ch) u32 cfg = hpet_read32(HPET_Tn_CFG(ch->idx)); irq_desc_t *desc = irq_to_desc(ch->msi.irq); - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) { ch->msi.hpet_id = hpet_blockid; ret = iommu_setup_hpet_msi(&ch->msi); @@ -372,7 +372,7 @@ static int __init hpet_setup_msi_irq(struct hpet_event_channel *ch) ret = __hpet_setup_msi_irq(desc); if ( ret < 0 ) { - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) iommu_update_ire_from_msi(&ch->msi, NULL); return ret; } diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c index 7f8e794254..72dce2e4ab 100644 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -189,7 +189,7 @@ static int write_msi_msg(struct msi_desc *entry, struct msi_msg *msg) { entry->msg = *msg; - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) { int rc; @@ -555,7 +555,7 @@ int msi_free_irq(struct msi_desc *entry) destroy_irq(entry[nr].irq); /* Free the unused IRTE if intr remap enabled */ - if ( iommu_intremap ) + if ( iommu_intremap != iommu_intremap_off ) iommu_update_ire_from_msi(entry + nr, NULL); } diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emulate/x86_emulate.c index cf780da501..00b7365ed3 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -1320,7 +1320,7 @@ x86_emulate( ea.bytes = 2; goto srcmem_common; case SrcMem: - if ( state->simd_size ) + if ( state->simd_size != simd_none ) break; ea.bytes = (d & ByteOp) ? 1 : op_bytes; srcmem_common: @@ -1460,7 +1460,7 @@ x86_emulate( /* Becomes a normal DstMem operation from here on. */ case DstMem: generate_exception_if(ea.type == OP_MEM && evex.z, X86_EXC_UD); - if ( state->simd_size ) + if ( state->simd_size != simd_none ) { generate_exception_if(lock_prefix, X86_EXC_UD); break; @@ -8176,7 +8176,7 @@ x86_emulate( goto done; } - if ( state->rmw ) + if ( state->rmw != rmw_NONE ) { ea.val = src.val; op_bytes = dst.bytes; @@ -8205,7 +8205,7 @@ x86_emulate( dst.type = OP_NONE; } - else if ( state->simd_size ) + else if ( state->simd_size != simd_none ) { generate_exception_if(!op_bytes, X86_EXC_UD); generate_exception_if((vex.opcx && (d & TwoOp) && From patchwork Thu Dec 7 09:48:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simone Ballarin X-Patchwork-Id: 13483084 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 DCE38C4167B for ; Thu, 7 Dec 2023 09:51:28 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.649724.1014555 (Exim 4.92) (envelope-from ) id 1rBB2O-0004rQ-PO; Thu, 07 Dec 2023 09:51:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 649724.1014555; Thu, 07 Dec 2023 09:51: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 1rBB2O-0004r8-M4; Thu, 07 Dec 2023 09:51:20 +0000 Received: by outflank-mailman (input) for mailman id 649724; Thu, 07 Dec 2023 09:51: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 1rBB2N-0004o2-Rs for xen-devel@lists.xenproject.org; Thu, 07 Dec 2023 09:51:19 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 2b15ea27-94e6-11ee-98e7-6d05b1d4d9a1; Thu, 07 Dec 2023 10:51:18 +0100 (CET) Received: from beta.station (net-37-182-35-120.cust.vodafonedsl.it [37.182.35.120]) by support.bugseng.com (Postfix) with ESMTPSA id 0F9654EE073A; Thu, 7 Dec 2023 10:51:18 +0100 (CET) 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: 2b15ea27-94e6-11ee-98e7-6d05b1d4d9a1 From: Simone Ballarin To: xen-devel@lists.xenproject.org Cc: consulting@bugseng.com, Maria Celeste Cesario , Simone Ballarin , Doug Goldstein , Stefano Stabellini , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [PATCH 3/3] xen: address violations of MISRA C:2012 Rule 14.4 Date: Thu, 7 Dec 2023 10:48:44 +0100 Message-Id: <3012fb117b4ef6458bdb5cfd046c86bce60a6d51.1701941924.git.maria.celeste.cesario@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 From: Maria Celeste Cesario The xen sources contain violations of MISRA C:2012 Rule 14.4 whose headline states: "The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type". Struct domain member is_dying is an anonymous enum designed to act as boolean. Add deviation to mark its uses in controlling expressions as deliberate. Signed-off-by: Maria Celeste Cesario Signed-off-by: Simone Ballarin Reviewed-by: Stefano Stabellini --- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ docs/misra/deviations.rst | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl index b0c79741b5..683f2bbfe8 100644 --- a/automation/eclair_analysis/ECLAIR/deviations.ecl +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl @@ -321,6 +321,12 @@ statements are deliberate" -config=MC3R1.R14.3,statements={deliberate , "wrapped(any(),node(if_stmt))" } -doc_end +-doc_begin="The XEN team relies on the fact that the enum is_dying has the +constant with assigned value 0 act as false and the other ones as true, +therefore have the same behavior of a boolean" +-config=MC3R1.R14.4,etypes+={deliberate, "stmt(child(cond,child(expr,ref(^?::is_dying$))))","src_type(enum)"} +-doc_end + # # Series 20. # diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst index 6e7c4f25b8..eda3c8100c 100644 --- a/docs/misra/deviations.rst +++ b/docs/misra/deviations.rst @@ -270,6 +270,12 @@ Deviations related to MISRA C:2012 Rules: statements are deliberate. - Project-wide deviation; tagged as `disapplied` for ECLAIR. + * - R14.4 + - The XEN team relies on the fact that the enum is_dying has the + constant with assigned value 0 act as false and the other ones as true, + therefore have the same behavior of a boolean. + - Project-wide deviation; tagged as `deliberate` for ECLAIR. + * - R20.7 - Code violating Rule 20.7 is safe when macro parameters are used: (1) as function arguments;