From nobody Wed May 15 04:37:24 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 1690987147400852.6438135924992; Wed, 2 Aug 2023 07:39:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574972.900629 (Exim 4.92) (envelope-from ) id 1qRCzo-0006eR-9z; Wed, 02 Aug 2023 14:38:40 +0000 Received: by outflank-mailman (output) from mailman id 574972.900629; Wed, 02 Aug 2023 14:38:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzo-0006dO-4Z; Wed, 02 Aug 2023 14:38:40 +0000 Received: by outflank-mailman (input) for mailman id 574972; Wed, 02 Aug 2023 14:38:38 +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 1qRCzm-0006bO-Pb for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:38 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 444042f5-3142-11ee-b260-6b7b168915f2; Wed, 02 Aug 2023 16:38:37 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 4A5D14EE0740; Wed, 2 Aug 2023 16:38:36 +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: 444042f5-3142-11ee-b260-6b7b168915f2 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, Nicola Vetrini , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [XEN PATCH 01/11] x86/efi: move variable declaration to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:07 +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: 1690987149090100001 Content-Type: text/plain; charset="utf-8" The variable declaration is moved where it's actually used, rather than being declared in the switch before any clause, thus being classified as unreachable code. No functional changes. Signed-off-by: Nicola Vetrini --- xen/arch/x86/efi/efi-boot.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/efi/efi-boot.h b/xen/arch/x86/efi/efi-boot.h index 92f4cfe8bd..b00441b1a2 100644 --- a/xen/arch/x86/efi/efi-boot.h +++ b/xen/arch/x86/efi/efi-boot.h @@ -390,8 +390,6 @@ static void __init efi_arch_edd(void) { switch ( DevicePathType(devp.DevPath) ) { - const u8 *p; - case ACPI_DEVICE_PATH: if ( state !=3D root || boot_edd_info_nr > EDD_INFO_MAX ) break; @@ -463,7 +461,8 @@ static void __init efi_arch_edd(void) params->device_path_info_length =3D sizeof(struct edd_device_params) - offsetof(struct edd_device_params, key); - for ( p =3D (const u8 *)¶ms->key; p < ¶ms->checksu= m; ++p ) + for ( const u8 *p =3D (const u8 *)¶ms->key; + p < ¶ms->checksum; ++p ) params->checksum -=3D *p; break; case MEDIA_DEVICE_PATH: --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987147036891.6019406076412; Wed, 2 Aug 2023 07:39:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574973.900637 (Exim 4.92) (envelope-from ) id 1qRCzo-0006px-NU; Wed, 02 Aug 2023 14:38:40 +0000 Received: by outflank-mailman (output) from mailman id 574973.900637; Wed, 02 Aug 2023 14:38:40 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzo-0006ms-Hy; Wed, 02 Aug 2023 14:38:40 +0000 Received: by outflank-mailman (input) for mailman id 574973; Wed, 02 Aug 2023 14:38:39 +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 1qRCzn-0006bO-Pv for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:39 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 44f44a64-3142-11ee-b260-6b7b168915f2; Wed, 02 Aug 2023 16:38:39 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id D50094EE0741; Wed, 2 Aug 2023 16:38:37 +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: 44f44a64-3142-11ee-b260-6b7b168915f2 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, Nicola Vetrini , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [XEN PATCH 02/11] x86: move declarations to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:08 +0200 Message-Id: <204bf3ffcdda04d6d6cf072c42b78720e1e85b4d.1690985045.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: 1690989360675100001 Content-Type: text/plain; charset="utf-8" Variable declarations between a switch statement guard and before any case label are unreachable code, and hence violate Rule 2.1: "A project shall not contain unreachable code". Therefore the declarations are moved in the smallest enclosing scope, near other variable definitions. Signed-off-by: Nicola Vetrini --- xen/arch/x86/cpuid.c | 3 +-- xen/arch/x86/domain.c | 23 +++++++++++------------ xen/arch/x86/irq.c | 3 +-- xen/arch/x86/msr.c | 3 +-- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/xen/arch/x86/cpuid.c b/xen/arch/x86/cpuid.c index 455a09b2dd..90e1370e90 100644 --- a/xen/arch/x86/cpuid.c +++ b/xen/arch/x86/cpuid.c @@ -37,6 +37,7 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf, { const struct domain *d =3D v->domain; const struct cpu_policy *p =3D d->arch.cpu_policy; + const struct cpu_user_regs *regs; =20 *res =3D EMPTY_LEAF; =20 @@ -136,8 +137,6 @@ void guest_cpuid(const struct vcpu *v, uint32_t leaf, */ switch ( leaf ) { - const struct cpu_user_regs *regs; - case 0x1: /* TODO: Rework topology logic. */ res->b &=3D 0x00ffffffu; diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c index 5f66c2ae33..015f7b14ab 100644 --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -2268,6 +2268,17 @@ int domain_relinquish_resources(struct domain *d) { int ret; struct vcpu *v; + enum { + PROG_iommu_pagetables =3D 1, + PROG_shared, + PROG_paging, + PROG_vcpu_pagetables, + PROG_xen, + PROG_l4, + PROG_l3, + PROG_l2, + PROG_done, + }; =20 BUG_ON(!cpumask_empty(d->dirty_cpumask)); =20 @@ -2291,18 +2302,6 @@ int domain_relinquish_resources(struct domain *d) #define PROGRESS(x) \ d->arch.rel_priv =3D PROG_ ## x; /* Fallthrough */ case PROG_ ## x =20 - enum { - PROG_iommu_pagetables =3D 1, - PROG_shared, - PROG_paging, - PROG_vcpu_pagetables, - PROG_xen, - PROG_l4, - PROG_l3, - PROG_l2, - PROG_done, - }; - case 0: ret =3D pci_release_devices(d); if ( ret ) diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 6abfd81621..4fd0cc163d 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -1135,6 +1135,7 @@ static void cf_check irq_guest_eoi_timer_fn(void *dat= a) struct irq_desc *desc =3D data; unsigned int i, irq =3D desc - irq_desc; irq_guest_action_t *action; + cpumask_t *cpu_eoi_map; =20 spin_lock_irq(&desc->lock); =20 @@ -1169,8 +1170,6 @@ static void cf_check irq_guest_eoi_timer_fn(void *dat= a) =20 switch ( action->ack_type ) { - cpumask_t *cpu_eoi_map; - case ACKTYPE_UNMASK: if ( desc->handler->end ) desc->handler->end(desc, 0); diff --git a/xen/arch/x86/msr.c b/xen/arch/x86/msr.c index ecf126566d..0e61e0fe4e 100644 --- a/xen/arch/x86/msr.c +++ b/xen/arch/x86/msr.c @@ -335,11 +335,10 @@ int guest_wrmsr(struct vcpu *v, uint32_t msr, uint64_= t val) const struct cpu_policy *cp =3D d->arch.cpu_policy; struct vcpu_msrs *msrs =3D v->arch.msrs; int ret =3D X86EMUL_OKAY; + uint64_t rsvd; =20 switch ( msr ) { - uint64_t rsvd; - /* Read-only */ case MSR_IA32_PLATFORM_ID: case MSR_CORE_CAPABILITIES: --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987147589216.74367761294354; Wed, 2 Aug 2023 07:39:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574974.900654 (Exim 4.92) (envelope-from ) id 1qRCzp-0007KM-TU; Wed, 02 Aug 2023 14:38:41 +0000 Received: by outflank-mailman (output) from mailman id 574974.900654; Wed, 02 Aug 2023 14:38:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzp-0007J7-PX; Wed, 02 Aug 2023 14:38:41 +0000 Received: by outflank-mailman (input) for mailman id 574974; Wed, 02 Aug 2023 14:38:40 +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 1qRCzo-0006bO-Px for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:40 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 45699fe4-3142-11ee-b260-6b7b168915f2; Wed, 02 Aug 2023 16:38:39 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 04B374EE0742; Wed, 2 Aug 2023 16:38:38 +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: 45699fe4-3142-11ee-b260-6b7b168915f2 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, Nicola Vetrini , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [XEN PATCH 03/11] x86/uaccess: move declarations to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:09 +0200 Message-Id: <6d5e4f307b360393e29641d727ef78b697643f47.1690985045.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: 1690989431435100003 Content-Type: text/plain; charset="utf-8" The variable declarations inside macros {put,get}_unsafe_size are considered unreachable code, as they appear in a switch statement, before any clause. They are moved in the enclosing scope to resolve the violation. No functional changes. Signed-off-by: Nicola Vetrini Reviewed-by: Stefano Stabellini --- xen/arch/x86/include/asm/uaccess.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/include/asm/uaccess.h b/xen/arch/x86/include/asm/= uaccess.h index 684fccd95c..a2aaab1e87 100644 --- a/xen/arch/x86/include/asm/uaccess.h +++ b/xen/arch/x86/include/asm/uaccess.h @@ -191,11 +191,12 @@ struct __large_struct { unsigned long buf[100]; }; =20 #define put_unsafe_size(x, ptr, size, grd, retval, errret) = \ do { = \ + long dummy_; = \ + = \ retval =3D 0; = \ stac(); = \ switch ( size ) = \ { = \ - long dummy_; = \ case 1: = \ put_unsafe_asm(x, ptr, grd, retval, "b", "b", "iq", errret); = \ break; = \ @@ -218,11 +219,12 @@ do { = \ =20 #define get_unsafe_size(x, ptr, size, grd, retval, errret) = \ do { = \ + long dummy_; = \ + = \ retval =3D 0; = \ stac(); = \ switch ( size ) = \ { = \ - long dummy_; = \ case 1: get_unsafe_asm(x, ptr, grd, retval, "b", "=3Dq", errret); brea= k; \ case 2: get_unsafe_asm(x, ptr, grd, retval, "w", "=3Dr", errret); brea= k; \ case 4: get_unsafe_asm(x, ptr, grd, retval, "k", "=3Dr", errret); brea= k; \ --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987148534848.2103037178398; Wed, 2 Aug 2023 07:39:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574977.900676 (Exim 4.92) (envelope-from ) id 1qRCzt-0007nI-09; Wed, 02 Aug 2023 14:38:45 +0000 Received: by outflank-mailman (output) from mailman id 574977.900676; Wed, 02 Aug 2023 14:38:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzs-0007ly-OA; Wed, 02 Aug 2023 14:38:44 +0000 Received: by outflank-mailman (input) for mailman id 574977; Wed, 02 Aug 2023 14:38:43 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzr-0007ap-7l for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:43 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 45e7e813-3142-11ee-8613-37d641c3527e; Wed, 02 Aug 2023 16:38:40 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id BFDC64EE0743; Wed, 2 Aug 2023 16:38:39 +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: 45e7e813-3142-11ee-8613-37d641c3527e 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, Nicola Vetrini , Paul Durrant , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [XEN PATCH 04/11] x86emul: move variable definitions to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38: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: 1690989409149100001 Content-Type: text/plain; charset="utf-8" Variable declarations between a switch statement guard and before any case label are unreachable code, and hence violate Rule 2.1: "A project shall not contain unreachable code". Therefore the variable declarations are moved in the only clause scope that uses it. Signed-off-by: Nicola Vetrini --- xen/arch/x86/hvm/emulate.c | 9 ++++----- xen/arch/x86/hvm/hvm.c | 10 ++++------ xen/arch/x86/x86_emulate/0f01.c | 7 +++---- xen/arch/x86/x86_emulate/blk.c | 17 ++++++++--------- xen/arch/x86/x86_emulate/decode.c | 3 ++- xen/arch/x86/x86_emulate/fpu.c | 3 +-- xen/arch/x86/x86_emulate/util-xen.c | 4 ++-- xen/arch/x86/x86_emulate/x86_emulate.c | 14 +++++++------- 8 files changed, 31 insertions(+), 36 deletions(-) diff --git a/xen/arch/x86/hvm/emulate.c b/xen/arch/x86/hvm/emulate.c index 75ee98a73b..2261e8655b 100644 --- a/xen/arch/x86/hvm/emulate.c +++ b/xen/arch/x86/hvm/emulate.c @@ -1994,6 +1994,7 @@ static int cf_check hvmemul_rep_stos( bool_t df =3D !!(ctxt->regs->eflags & X86_EFLAGS_DF); int rc =3D hvmemul_virtual_to_linear(seg, offset, bytes_per_rep, reps, hvm_access_write, hvmemul_ctxt, &ad= dr); + char *buf; =20 if ( rc !=3D X86EMUL_OKAY ) return rc; @@ -2025,7 +2026,6 @@ static int cf_check hvmemul_rep_stos( switch ( p2mt ) { unsigned long bytes; - char *buf; =20 default: /* Allocate temporary buffer. */ @@ -2289,16 +2289,15 @@ static int cf_check hvmemul_cache_op( struct hvm_emulate_ctxt *hvmemul_ctxt =3D container_of(ctxt, struct hvm_emulate_ctxt, ctxt); uint32_t pfec =3D PFEC_page_present; + unsigned long addr; + int rc; + void *mapping; =20 if ( !cache_flush_permitted(current->domain) ) return X86EMUL_OKAY; =20 switch ( op ) { - unsigned long addr; - int rc; - void *mapping; - case x86emul_clflush: case x86emul_clflushopt: case x86emul_clwb: diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 2180abeb33..4170343b34 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1494,10 +1494,10 @@ static int cf_check hvm_load_cpu_msrs(struct domain= *d, hvm_domain_context_t *h) =20 for ( i =3D 0; i < ctxt->count; ++i ) { + int rc; + switch ( ctxt->msr[i].index ) { - int rc; - case MSR_SPEC_CTRL: case MSR_INTEL_MISC_FEATURES_ENABLES: case MSR_PKRS: @@ -3522,6 +3522,7 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t= *msr_content) struct domain *d =3D v->domain; uint64_t *var_range_base, *fixed_range_base; int ret; + unsigned int index; =20 var_range_base =3D (uint64_t *)v->arch.hvm.mtrr.var_ranges; fixed_range_base =3D (uint64_t *)v->arch.hvm.mtrr.fixed_ranges; @@ -3533,8 +3534,6 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t= *msr_content) =20 switch ( msr ) { - unsigned int index; - case MSR_EFER: *msr_content =3D v->arch.hvm.guest_efer; break; @@ -3636,6 +3635,7 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_= t msr_content, struct vcpu *v =3D current; struct domain *d =3D v->domain; int ret; + unsigned int index; =20 HVMTRACE_3D(MSR_WRITE, msr, (uint32_t)msr_content, (uint32_t)(msr_content >> 32)); @@ -3668,8 +3668,6 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_= t msr_content, =20 switch ( msr ) { - unsigned int index; - case MSR_EFER: if ( hvm_set_efer(msr_content) ) return X86EMUL_EXCEPTION; diff --git a/xen/arch/x86/x86_emulate/0f01.c b/xen/arch/x86/x86_emulate/0f0= 1.c index ba43fc394b..22a14b12c3 100644 --- a/xen/arch/x86/x86_emulate/0f01.c +++ b/xen/arch/x86/x86_emulate/0f01.c @@ -24,13 +24,12 @@ int x86emul_0f01(struct x86_emulate_state *s, { enum x86_segment seg =3D (s->modrm_reg & 1) ? x86_seg_idtr : x86_seg_g= dtr; int rc; + unsigned long base, limit, cr0, cr0w, cr4; + struct segment_register sreg; + uint64_t msr_val; =20 switch ( s->modrm ) { - unsigned long base, limit, cr0, cr0w, cr4; - struct segment_register sreg; - uint64_t msr_val; - case 0xc6: switch ( s->vex.pfx ) { diff --git a/xen/arch/x86/x86_emulate/blk.c b/xen/arch/x86/x86_emulate/blk.c index e790f4f900..f2956c0d52 100644 --- a/xen/arch/x86/x86_emulate/blk.c +++ b/xen/arch/x86/x86_emulate/blk.c @@ -26,19 +26,18 @@ int x86_emul_blk( struct x86_emulate_ctxt *ctxt) { int rc =3D X86EMUL_OKAY; - - switch ( s->blk ) - { - bool zf; + bool zf; #ifndef X86EMUL_NO_FPU + struct { + struct x87_env32 env; struct { - struct x87_env32 env; - struct { - uint8_t bytes[10]; - } freg[8]; - } fpstate; + uint8_t bytes[10]; + } freg[8]; + } fpstate; #endif =20 + switch ( s->blk ) + { /* * Throughout this switch(), memory clobbers are used to compensate * that other operands may not properly express the (full) memory diff --git a/xen/arch/x86/x86_emulate/decode.c b/xen/arch/x86/x86_emulate/d= ecode.c index f58ca3984e..daebf3a9bd 100644 --- a/xen/arch/x86/x86_emulate/decode.c +++ b/xen/arch/x86/x86_emulate/decode.c @@ -1758,9 +1758,9 @@ int x86emul_decode(struct x86_emulate_state *s, /* Fetch the immediate operand, if present. */ switch ( d & SrcMask ) { + case SrcImm: { unsigned int bytes; =20 - case SrcImm: if ( !(d & ByteOp) ) { if ( mode_64bit() && !amd_like(ctxt) && @@ -1785,6 +1785,7 @@ int x86emul_decode(struct x86_emulate_state *s, case SrcImm16: s->imm1 =3D insn_fetch_type(uint16_t); break; + } } =20 ctxt->opcode =3D opcode; diff --git a/xen/arch/x86/x86_emulate/fpu.c b/xen/arch/x86/x86_emulate/fpu.c index 480d879657..002d5e1253 100644 --- a/xen/arch/x86/x86_emulate/fpu.c +++ b/xen/arch/x86/x86_emulate/fpu.c @@ -84,11 +84,10 @@ int x86emul_fpu(struct x86_emulate_state *s, uint8_t b; int rc; struct x86_emulate_stub stub =3D {}; + unsigned long dummy; =20 switch ( b =3D ctxt->opcode ) { - unsigned long dummy; - case 0x9b: /* wait/fwait */ host_and_vcpu_must_have(fpu); get_fpu(X86EMUL_FPU_wait); diff --git a/xen/arch/x86/x86_emulate/util-xen.c b/xen/arch/x86/x86_emulate= /util-xen.c index 5e90818010..7ab2ac712f 100644 --- a/xen/arch/x86/x86_emulate/util-xen.c +++ b/xen/arch/x86/x86_emulate/util-xen.c @@ -77,10 +77,10 @@ bool cf_check x86_insn_is_portio(const struct x86_emula= te_state *s, bool cf_check x86_insn_is_cr_access(const struct x86_emulate_state *s, const struct x86_emulate_ctxt *ctxt) { + unsigned int ext; + switch ( ctxt->opcode ) { - unsigned int ext; - case X86EMUL_OPC(0x0f, 0x01): if ( x86_insn_modrm(s, NULL, &ext) >=3D 0 && (ext & 5) =3D=3D 4 ) /* SMSW / LMSW */ diff --git a/xen/arch/x86/x86_emulate/x86_emulate.c b/xen/arch/x86/x86_emul= ate/x86_emulate.c index e88245eae9..d6c04fd5f3 100644 --- a/xen/arch/x86/x86_emulate/x86_emulate.c +++ b/xen/arch/x86/x86_emulate/x86_emulate.c @@ -1479,15 +1479,15 @@ x86_emulate( break; } =20 + enum x86_segment seg; + struct segment_register cs, sreg; + struct cpuid_leaf leaf; + uint64_t msr_val; + unsigned int i, n; + unsigned long dummy; + switch ( ctxt->opcode ) { - enum x86_segment seg; - struct segment_register cs, sreg; - struct cpuid_leaf leaf; - uint64_t msr_val; - unsigned int i, n; - unsigned long dummy; - case 0x00: case 0x01: add: /* add reg,mem */ if ( ops->rmw && dst.type =3D=3D OP_MEM ) state->rmw =3D rmw_add; --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987148397912.6290201139162; Wed, 2 Aug 2023 07:39:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574975.900663 (Exim 4.92) (envelope-from ) id 1qRCzs-0007d3-4K; Wed, 02 Aug 2023 14:38:44 +0000 Received: by outflank-mailman (output) from mailman id 574975.900663; Wed, 02 Aug 2023 14:38:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzs-0007cn-0n; Wed, 02 Aug 2023 14:38:44 +0000 Received: by outflank-mailman (input) for mailman id 574975; Wed, 02 Aug 2023 14:38:42 +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 1qRCzp-0006bO-WE for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:42 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 465e692a-3142-11ee-b260-6b7b168915f2; Wed, 02 Aug 2023 16:38:41 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 978C14EE0744; Wed, 2 Aug 2023 16:38:40 +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: 465e692a-3142-11ee-b260-6b7b168915f2 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, Nicola Vetrini , Jan Beulich , Paul Durrant , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [XEN PATCH 05/11] drivers/pci: move variable definitions to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:11 +0200 Message-Id: <99f434f5d8b9c8eca275f23799a642ba34e79eb8.1690985045.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: 1690990072149100001 Content-Type: text/plain; charset="utf-8" Variable declarations between a switch statement guard and before any case label are unreachable code, and hence violate Rule 2.1: "A project shall not contain unreachable code". Therefore the variable declarations are moved in the smallest enclosing scope, near other variable definitions. Signed-off-by: Nicola Vetrini --- xen/drivers/passthrough/pci.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/xen/drivers/passthrough/pci.c b/xen/drivers/passthrough/pci.c index 33452791a8..3f5fa5beef 100644 --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -315,6 +315,7 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg,= u8 bus, u8 devfn) struct pci_dev *pdev; unsigned int pos; int rc; + unsigned int cap, sec_bus, sub_bus; =20 list_for_each_entry ( pdev, &pseg->alldevs_list, alldevs_list ) if ( pdev->bus =3D=3D bus && pdev->devfn =3D=3D devfn ) @@ -343,8 +344,6 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pseg,= u8 bus, u8 devfn) /* update bus2bridge */ switch ( pdev->type =3D pdev_type(pseg->nr, bus, devfn) ) { - unsigned int cap, sec_bus, sub_bus; - case DEV_TYPE_PCIe2PCI_BRIDGE: case DEV_TYPE_LEGACY_PCI_BRIDGE: sec_bus =3D pci_conf_read8(pdev->sbdf, PCI_SECONDARY_BUS); @@ -424,11 +423,11 @@ static struct pci_dev *alloc_pdev(struct pci_seg *pse= g, u8 bus, u8 devfn) =20 static void free_pdev(struct pci_seg *pseg, struct pci_dev *pdev) { + unsigned int sec_bus, sub_bus; + /* update bus2bridge */ switch ( pdev->type ) { - unsigned int sec_bus, sub_bus; - case DEV_TYPE_PCIe2PCI_BRIDGE: case DEV_TYPE_LEGACY_PCI_BRIDGE: sec_bus =3D pci_conf_read8(pdev->sbdf, PCI_SECONDARY_BUS); @@ -1555,11 +1554,10 @@ int iommu_do_pci_domctl( u8 bus, devfn; int ret =3D 0; uint32_t machine_sbdf; + unsigned int flags; =20 switch ( domctl->cmd ) { - unsigned int flags; - case XEN_DOMCTL_get_device_group: { u32 max_sdevs; --=20 2.34.1 From nobody Wed May 15 04:37:24 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 169098714656818.394192597014353; Wed, 2 Aug 2023 07:39:06 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574976.900670 (Exim 4.92) (envelope-from ) id 1qRCzs-0007gH-Kn; Wed, 02 Aug 2023 14:38:44 +0000 Received: by outflank-mailman (output) from mailman id 574976.900670; Wed, 02 Aug 2023 14:38:44 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzs-0007fA-BK; Wed, 02 Aug 2023 14:38:44 +0000 Received: by outflank-mailman (input) for mailman id 574976; Wed, 02 Aug 2023 14:38:42 +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 1qRCzq-0006bO-QF for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:42 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 46b8c10b-3142-11ee-b260-6b7b168915f2; Wed, 02 Aug 2023 16:38:42 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 5E2AE4EE0745; Wed, 2 Aug 2023 16:38:41 +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: 46b8c10b-3142-11ee-b260-6b7b168915f2 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, Nicola Vetrini , Paul Durrant Subject: [XEN PATCH 06/11] xen/ioreq: move variable declaration to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:12 +0200 Message-Id: <587d42fef7a0fc3fb3e7e5ef3deed6617b84cf03.1690985045.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: 1690989339108100001 Content-Type: text/plain; charset="utf-8" Variable declarations between a switch statement guard and before any case label are unreachable code, and hence violate Rule 2.1: "A project shall not contain unreachable code". Therefore the variable declarations are moved in the smallest enclosing scope, near other variable definitions. Signed-off-by: Nicola Vetrini --- xen/common/ioreq.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/xen/common/ioreq.c b/xen/common/ioreq.c index 7cb717f7a2..5044f43b81 100644 --- a/xen/common/ioreq.c +++ b/xen/common/ioreq.c @@ -1111,6 +1111,7 @@ struct ioreq_server *ioreq_server_select(struct domai= n *d, FOR_EACH_IOREQ_SERVER(d, id, s) { struct rangeset *r; + unsigned long start, end; =20 if ( !s->enabled ) continue; @@ -1119,8 +1120,6 @@ struct ioreq_server *ioreq_server_select(struct domai= n *d, =20 switch ( type ) { - unsigned long start, end; - case XEN_DMOP_IO_RANGE_PORT: start =3D addr; end =3D start + p->size - 1; --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987148297420.86490622211454; Wed, 2 Aug 2023 07:39:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574978.900680 (Exim 4.92) (envelope-from ) id 1qRCzt-0007yB-FC; Wed, 02 Aug 2023 14:38:45 +0000 Received: by outflank-mailman (output) from mailman id 574978.900680; Wed, 02 Aug 2023 14:38:45 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzt-0007vk-7n; Wed, 02 Aug 2023 14:38:45 +0000 Received: by outflank-mailman (input) for mailman id 574978; Wed, 02 Aug 2023 14:38:43 +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 1qRCzr-0006bO-QZ for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:43 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 473a13cb-3142-11ee-b260-6b7b168915f2; Wed, 02 Aug 2023 16:38:42 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id EE2194EE073F; Wed, 2 Aug 2023 16:38:41 +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: 473a13cb-3142-11ee-b260-6b7b168915f2 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, Nicola Vetrini , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [XEN PATCH 07/11] xen: address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:13 +0200 Message-Id: <7f8cbd8c8ad64cd3a0d099f31cb4d3fad48aa63b.1690985045.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: 1690989457848100001 Content-Type: text/plain; charset="utf-8" Rule 2.1 states: "A project shall not contain unreachable code". The functions - machine_halt - maybe_reboot - machine_restart are not supposed to return, hence the following break statement is marked as intentionally unreachable with the ASSERT_UNREACHABLE() macro to justify the violation of the rule. Signed-off-by: Nicola Vetrini --- xen/common/shutdown.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xen/common/shutdown.c b/xen/common/shutdown.c index a933ee001e..88f735a30e 100644 --- a/xen/common/shutdown.c +++ b/xen/common/shutdown.c @@ -38,39 +38,45 @@ void hwdom_shutdown(u8 reason) printk("Hardware Dom%u halted: halting machine\n", hardware_domain->domain_id); machine_halt(); - break; /* not reached */ + ASSERT_UNREACHABLE(); + break; =20 case SHUTDOWN_crash: debugger_trap_immediate(); printk("Hardware Dom%u crashed: ", hardware_domain->domain_id); kexec_crash(CRASHREASON_HWDOM); maybe_reboot(); - break; /* not reached */ + ASSERT_UNREACHABLE(); + break; =20 case SHUTDOWN_reboot: printk("Hardware Dom%u shutdown: rebooting machine\n", hardware_domain->domain_id); machine_restart(0); - break; /* not reached */ + ASSERT_UNREACHABLE(); + break; =20 case SHUTDOWN_watchdog: printk("Hardware Dom%u shutdown: watchdog rebooting machine\n", hardware_domain->domain_id); kexec_crash(CRASHREASON_WATCHDOG); machine_restart(0); - break; /* not reached */ + ASSERT_UNREACHABLE(); + break; =20 case SHUTDOWN_soft_reset: printk("Hardware domain %d did unsupported soft reset, rebooting.\= n", hardware_domain->domain_id); machine_restart(0); - break; /* not reached */ + ASSERT_UNREACHABLE(); + break; =20 default: printk("Hardware Dom%u shutdown (unknown reason %u): ", hardware_domain->domain_id, reason); maybe_reboot(); - break; /* not reached */ + ASSERT_UNREACHABLE(); + break; } } =20 =20 --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987148289340.676860512419; Wed, 2 Aug 2023 07:39:08 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574979.900708 (Exim 4.92) (envelope-from ) id 1qRCzv-0000Fe-UB; Wed, 02 Aug 2023 14:38:47 +0000 Received: by outflank-mailman (output) from mailman id 574979.900708; Wed, 02 Aug 2023 14:38:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzv-0000Dx-Fv; Wed, 02 Aug 2023 14:38:47 +0000 Received: by outflank-mailman (input) for mailman id 574979; Wed, 02 Aug 2023 14:38:45 +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 1qRCzt-0007ap-7L for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:45 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 47b43c9a-3142-11ee-8613-37d641c3527e; Wed, 02 Aug 2023 16:38:43 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id C89704EE0740; Wed, 2 Aug 2023 16:38:42 +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: 47b43c9a-3142-11ee-8613-37d641c3527e 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, Nicola Vetrini , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Wei Liu Subject: [XEN PATCH 08/11] xen: move declarations to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:14 +0200 Message-Id: <055dce166662183c68fb488fa7f7722a3a5fcd98.1690985045.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: 1690989387818100001 Content-Type: text/plain; charset="utf-8" Declarations between a switch statement guard and before any case label are unreachable code, and hence violate Rule 2.1: "A project shall not contain unreachable code". Therefore the variable declarations are moved in the smallest enclosing scope, near other variable definitions. Signed-off-by: Nicola Vetrini --- xen/common/compat/memory.c | 3 +-- xen/common/domain.c | 15 +++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/xen/common/compat/memory.c b/xen/common/compat/memory.c index 8ca63ceda6..d4c4204119 100644 --- a/xen/common/compat/memory.c +++ b/xen/common/compat/memory.c @@ -85,13 +85,12 @@ int compat_memory_op(unsigned int cmd, XEN_GUEST_HANDLE= _PARAM(void) compat) struct compat_mem_access_op mao; struct compat_mem_acquire_resource mar; } cmp; + xen_pfn_t *space; =20 set_xen_guest_handle(nat.hnd, COMPAT_ARG_XLAT_VIRT_BASE); split =3D 0; switch ( op ) { - xen_pfn_t *space; - case XENMEM_increase_reservation: case XENMEM_decrease_reservation: case XENMEM_populate_physmap: diff --git a/xen/common/domain.c b/xen/common/domain.c index 304aa04fa6..e3aeaf059d 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -401,6 +401,13 @@ static int domain_teardown(struct domain *d) { struct vcpu *v; int rc; + enum { + PROG_none, + PROG_gnttab_mappings, + PROG_vcpu_teardown, + PROG_arch_teardown, + PROG_done, + }; =20 BUG_ON(!d->is_dying); =20 @@ -435,14 +442,6 @@ static int domain_teardown(struct domain *d) case PROG_vcpu_ ## x: \ v =3D d->teardown.vcpu =20 - enum { - PROG_none, - PROG_gnttab_mappings, - PROG_vcpu_teardown, - PROG_arch_teardown, - PROG_done, - }; - case PROG_none: BUILD_BUG_ON(PROG_none !=3D 0); =20 --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987151133338.42221815360335; Wed, 2 Aug 2023 07:39:11 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574981.900712 (Exim 4.92) (envelope-from ) id 1qRCzw-0000Kk-8t; Wed, 02 Aug 2023 14:38:48 +0000 Received: by outflank-mailman (output) from mailman id 574981.900712; Wed, 02 Aug 2023 14:38:48 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzv-0000J0-Sz; Wed, 02 Aug 2023 14:38:47 +0000 Received: by outflank-mailman (input) for mailman id 574981; Wed, 02 Aug 2023 14:38:46 +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 1qRCzt-0007ap-U6 for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:45 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 48220271-3142-11ee-8613-37d641c3527e; Wed, 02 Aug 2023 16:38:44 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 95DD24EE0742; Wed, 2 Aug 2023 16:38:43 +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: 48220271-3142-11ee-8613-37d641c3527e 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, Nicola Vetrini , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu Subject: [XEN PATCH 09/11] x86/xstate: moved BUILD_BUG_ON to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:15 +0200 Message-Id: <4cdcd0a9f99109463686420d6c3fc6681d215d99.1690985045.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: 1690989482232100001 Content-Type: text/plain; charset="utf-8" Variable declarations between a switch statement guard and before any case label are unreachable code, and hence violate Rule 2.1: "A project shall not contain unreachable code". Therefore the variable declarations are moved in the smallest enclosing scope, near other variable definitions. Signed-off-by: Nicola Vetrini --- xen/arch/x86/xstate.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c index 92496f3795..cb2b9e720c 100644 --- a/xen/arch/x86/xstate.c +++ b/xen/arch/x86/xstate.c @@ -396,9 +396,10 @@ void xrstor(struct vcpu *v, uint64_t mask) */ for ( prev_faults =3D faults =3D 0; ; prev_faults =3D faults ) { + BUILD_BUG_ON(sizeof(faults) !=3D 4); /* Clang doesn't support %z i= n asm. */ + switch ( __builtin_expect(ptr->fpu_sse.x[FPU_WORD_SIZE_OFFSET], 8)= ) { - BUILD_BUG_ON(sizeof(faults) !=3D 4); /* Clang doesn't support = %z in asm. */ #define _xrstor(insn) \ asm volatile ( "1: .byte " insn "\n" \ "3:\n" \ --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987147022862.3196370483242; Wed, 2 Aug 2023 07:39:07 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574980.900702 (Exim 4.92) (envelope-from ) id 1qRCzv-00009w-Bd; Wed, 02 Aug 2023 14:38:47 +0000 Received: by outflank-mailman (output) from mailman id 574980.900702; Wed, 02 Aug 2023 14:38:47 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzv-00007s-4D; Wed, 02 Aug 2023 14:38:47 +0000 Received: by outflank-mailman (input) for mailman id 574980; Wed, 02 Aug 2023 14:38:45 +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 1qRCzt-0006bO-Hd for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:45 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 4884aa7a-3142-11ee-b260-6b7b168915f2; Wed, 02 Aug 2023 16:38:45 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 519DB4EE0746; Wed, 2 Aug 2023 16:38:44 +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: 4884aa7a-3142-11ee-b260-6b7b168915f2 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, Nicola Vetrini , George Dunlap , Dario Faggioli Subject: [XEN PATCH 10/11] xen/sched: add ASSERT_UNREACHABLE() to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:16 +0200 Message-Id: <3f1385f2ddb151a53ca092ea1caeac5d12fd80f5.1690985045.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: 1690990032795100001 Content-Type: text/plain; charset="utf-8" The break statement after the return statement is definitely unreachable. As such, an call to the ASSERT_UNREACHABLE() macro is added to signal the intentionality of such construct. Signed-off-by: Nicola Vetrini --- The break in the clause is mandated by Required Rule 16.3, which is not yet an accepted rule for Xen, but may be in the future. --- xen/common/sched/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/xen/common/sched/core.c b/xen/common/sched/core.c index 022f548652..fcee902b4e 100644 --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -2233,6 +2233,7 @@ static bool sched_tasklet_check_cpu(unsigned int cpu) /* fallthrough */ case TASKLET_enqueued|TASKLET_scheduled: return true; + ASSERT_UNREACHABLE(); break; case TASKLET_scheduled: clear_bit(_TASKLET_scheduled, tasklet_work); --=20 2.34.1 From nobody Wed May 15 04:37:24 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 1690987150490154.98878912100793; Wed, 2 Aug 2023 07:39:10 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.574982.900728 (Exim 4.92) (envelope-from ) id 1qRCzx-0000y3-Vj; Wed, 02 Aug 2023 14:38:49 +0000 Received: by outflank-mailman (output) from mailman id 574982.900728; Wed, 02 Aug 2023 14:38:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRCzx-0000vx-Kp; Wed, 02 Aug 2023 14:38:49 +0000 Received: by outflank-mailman (input) for mailman id 574982; Wed, 02 Aug 2023 14:38:47 +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 1qRCzv-0007ap-E4 for xen-devel@lists.xenproject.org; Wed, 02 Aug 2023 14:38:47 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 4900c027-3142-11ee-8613-37d641c3527e; Wed, 02 Aug 2023 16:38:45 +0200 (CEST) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id F2D134EE0747; Wed, 2 Aug 2023 16:38:44 +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: 4900c027-3142-11ee-8613-37d641c3527e 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, Nicola Vetrini , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= , Wei Liu , George Dunlap Subject: [XEN PATCH 11/11] x86/mm: Add assertion to address MISRA C:2012 Rule 2.1 Date: Wed, 2 Aug 2023 16:38:17 +0200 Message-Id: <91b2f2c9e728c1f19f7baab301299d995a074279.1690985045.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: 1690990098630100001 Content-Type: text/plain; charset="utf-8" The ASSERT_UNREACHABLE() assertion is added before a definitely unreachable return statement to address MISRA C:2012 Rule 2.1, because the explicit return from a non-void function is a defensive coding measure, and thus intended to be unreachable. No functional changes. Signed-off-by: Nicola Vetrini --- xen/arch/x86/mm.c | 1 + xen/arch/x86/mm/p2m-pod.c | 1 + 2 files changed, 2 insertions(+) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index be2b10a391..ebd4f3827a 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -4879,6 +4879,7 @@ long arch_memory_op(unsigned long cmd, XEN_GUEST_HAND= LE_PARAM(void) arg) return subarch_memory_op(cmd, arg); } =20 + ASSERT_UNREACHABLE(); return 0; } =20 diff --git a/xen/arch/x86/mm/p2m-pod.c b/xen/arch/x86/mm/p2m-pod.c index 9969eb45fa..cd5501217f 100644 --- a/xen/arch/x86/mm/p2m-pod.c +++ b/xen/arch/x86/mm/p2m-pod.c @@ -1045,6 +1045,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, const gfn_= t *gfns, unsigned int count } =20 return; + ASSERT_UNREACHABLE(); =20 out_unmap: /* --=20 2.34.1