address most remaining Misra rule 2.1 violations
cover address most remaining Misra rule 2.1 violations
Let's try to get the unreachable code rule almost clean: With this series in place, as per [1] x86_64-allcode has one violation left, x86_64-amd has two; ARM64-* are clean. But see also "gnttab: unreachable code when GNTTAB_MAX_VERSION < 2" [2].
The first two thirds of this series are hopefully largely uncontroversial, whereas the last third may be.
01: x86/IO-APIC: address Misra 2.1 rule violations
02: x86/mm: pagetable_dying() is HVM+SHADOW_PAGING only
03: x86/shadow: eliminate unused forms of sh_map_and_validate_gl<N>e() 04: x86: add noreturn in a few more places
05: x86/crash: address Misra 2.1 rule violation
06: kexec: machine_reboot_kexec() doesn't return
07: altp2m: address Misra 2.1 rule violation
08: Arm/GIC: add noreturn in a few more places
09: Eclair: deviate BUILD_ERROR() wrt rule 2.1 and introduce variants 10: PCI/physdev: address Misra 2.1 rule violation
11: x86/HVM: address Misra 2.1 rule violations
12: x86/nSVM: address Misra 2.1 rule violation
Jan
[1] https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/2796557177
[2] https://lists.xen.org/archives/html/xen-devel/2026-07/msg01293.html
PATCH 1/12 x86/IO-APIC: address Misra 2.1 rule violations
In both functions cases 0..3 are handled, and a 2-bit mask is applied to the switch() expression. Therefore the default: cases are reported unreachable by Eclair. Subsume the "case 2" blocks each into the corresponding default ones.
While there also drop all the pointless figure braces inside the various case blocks, inserting blank lines instead between them.
No functional change.
xen/arch/x86/io_apic.c +18 -54
@@ -804,66 +804,48 @@ static int __init MPBIOS_polarity(int idswitch (mp_irqs[idx].mpc_irqflag &3 ) {case 0 :/* conforms, ie. bus-type dependent polarity */ - {switch (mp_bus_id_to_type[bus]) {case MP_BUS_ISA :/* ISA pin */ - { polarity =default_ISA_polarity (idx);break ; - } +case MP_BUS_EISA :/* EISA pin */ - { polarity =default_EISA_polarity (idx);break ; - } +case MP_BUS_PCI :/* PCI pin */ - { polarity =default_PCI_polarity (idx);break ; - } +case MP_BUS_MCA :/* MCA pin */ - { polarity =default_MCA_polarity (idx);break ; - } +case MP_BUS_NEC98 :/* NEC 98 pin */ - { polarity =default_NEC98_polarity (idx);break ; - } +default : - {printk (KERN_WARNING "broken BIOS!!\n" ); polarity =1 ;break ; } - }break ; - } +case 1 :/* high active */ - { polarity =0 ;break ; - } -case 2 :/* reserved */ - { -printk (KERN_WARNING "broken BIOS!!\n" ); - polarity =1 ; -break ; - } +case 3 :/* low active */ - { polarity =1 ;break ; - } -default :/* invalid */ - { + +default :/* reserved */ printk (KERN_WARNING "broken BIOS!!\n" ); polarity =1 ;break ; } - }return polarity; }
@@ -878,66 +860,48 @@ static int MPBIOS_trigger(int idx)switch ((mp_irqs[idx].mpc_irqflag>>2 ) &3 ) {case 0 :/* conforms, ie. bus-type dependent */ - {switch (mp_bus_id_to_type[bus]) {case MP_BUS_ISA :/* ISA pin */ - { trigger =default_ISA_trigger (idx);break ; - } +case MP_BUS_EISA :/* EISA pin */ - { trigger =default_EISA_trigger (idx);break ; - } +case MP_BUS_PCI :/* PCI pin */ - { trigger =default_PCI_trigger (idx);break ; - } +case MP_BUS_MCA :/* MCA pin */ - { trigger =default_MCA_trigger (idx);break ; - } +case MP_BUS_NEC98 :/* NEC 98 pin */ - { trigger =default_NEC98_trigger (idx);break ; - } +default : - {printk (KERN_WARNING "broken BIOS!!\n" ); trigger =1 ;break ; } - }break ; - } +case 1 :/* edge */ - { trigger =0 ;break ; - } -case 2 :/* reserved */ - { -printk (KERN_WARNING "broken BIOS!!\n" ); - trigger =1 ; -break ; - } +case 3 :/* level */ - { trigger =1 ;break ; - } -default :/* invalid */ - { + +default :/* reserved */ printk (KERN_WARNING "broken BIOS!!\n" ); trigger =0 ;break ; } - }return trigger; }
Re: [PATCH 01/12] x86/IO-APIC: address Misra 2.1 rule violations
Quoted 5 lines · Jan Beulich
In both functions cases 0..3 are handled, and a 2-bit mask is applied to the
switch()expression. Therefore the default: cases are reported unreachable by Eclair. Subsume the "case 2" blocks each into the corresponding default ones.
Quoted 7 lines
While there also drop all the pointless figure braces inside the various case blocks, inserting blank lines instead between them.
No functional change.
Signed-off-by Jan Beulich <[email protected]>
Quoted 153 lines
xen/arch/x86/io_apic.c +18
-54@@ -804,66 +804,48 @@ static int __init MPBIOS_polarity(int idswitch (mp_irqs[idx].mpc_irqflag &3 ) {case 0 :/* conforms, ie. bus-type dependent polarity */ - {switch (mp_bus_id_to_type[bus]) {case MP_BUS_ISA :/* ISA pin */ - { polarity =default_ISA_polarity (idx);break ; - } +case MP_BUS_EISA :/* EISA pin */ - { polarity =default_EISA_polarity (idx);break ; - } +case MP_BUS_PCI :/* PCI pin */ - { polarity =default_PCI_polarity (idx);break ; - } +case MP_BUS_MCA :/* MCA pin */ - { polarity =default_MCA_polarity (idx);break ; - } +case MP_BUS_NEC98 :/* NEC 98 pin */ - { polarity =default_NEC98_polarity (idx);break ; - } +default : - {printk (KERN_WARNING "broken BIOS!!\n" ); polarity =1 ;break ; } - }break ; - } +case 1 :/* high active */ - { polarity =0 ;break ; - } -case 2 :/* reserved */ - { -printk (KERN_WARNING "broken BIOS!!\n" ); - polarity =1 ; -break ; - } +case 3 :/* low active */ - { polarity =1 ;break ; - } -default :/* invalid */ - { + +default :/* reserved */ printk (KERN_WARNING "broken BIOS!!\n" ); polarity =1 ;break ; } - }return polarity; }@@ -878,66 +860,48 @@ static int MPBIOS_trigger(int idx)switch ((mp_irqs[idx].mpc_irqflag>>2 ) &3 ) {case 0 :/* conforms, ie. bus-type dependent */ - {switch (mp_bus_id_to_type[bus]) {case MP_BUS_ISA :/* ISA pin */ - { trigger =default_ISA_trigger (idx);break ; - } +case MP_BUS_EISA :/* EISA pin */ - { trigger =default_EISA_trigger (idx);break ; - } +case MP_BUS_PCI :/* PCI pin */ - { trigger =default_PCI_trigger (idx);break ; - } +case MP_BUS_MCA :/* MCA pin */ - { trigger =default_MCA_trigger (idx);break ; - } +case MP_BUS_NEC98 :/* NEC 98 pin */ - { trigger =default_NEC98_trigger (idx);break ; - } +default : - {printk (KERN_WARNING "broken BIOS!!\n" ); trigger =1 ;break ; } - }break ; - } +case 1 :/* edge */ - { trigger =0 ;break ; - } -case 2 :/* reserved */ - { -printk (KERN_WARNING "broken BIOS!!\n" ); - trigger =1 ; -break ; - } +case 3 :/* level */ - { trigger =1 ;break ; - } -default :/* invalid */ - { + +default :/* reserved */ printk (KERN_WARNING "broken BIOS!!\n" ); trigger =0 ;break ; } - }return trigger; }
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Re: [PATCH 01/12] x86/IO-APIC: address Misra 2.1 rule violations
In reply to Jan BeulichQuoted 11 lines · Jan Beulich
In both functions cases 0..3 are handled, and a 2-bit mask is applied to the
switch()expression. Therefore the default: cases are reported unreachable by Eclair. Subsume the "case 2" blocks each into the corresponding default ones.While there also drop all the pointless figure braces inside the various case blocks, inserting blank lines instead between them.
No functional change.
Signed-off-by Jan Beulich <[email protected]>
Quoted 62 lines
xen/arch/x86/io_apic.c +7
-22@@ -804,66 +804,48 @@ static int __init MPBIOS_polarity(int idswitch (mp_irqs[idx].mpc_irqflag &3 ) {case 0 :/* conforms, ie. bus-type dependent polarity */ - {switch (mp_bus_id_to_type[bus]) {case MP_BUS_ISA :/* ISA pin */ - { polarity =default_ISA_polarity (idx);break ; - } +case MP_BUS_EISA :/* EISA pin */ - { polarity =default_EISA_polarity (idx);break ; - } +case MP_BUS_PCI :/* PCI pin */ - { polarity =default_PCI_polarity (idx);break ; - } +case MP_BUS_MCA :/* MCA pin */ - { polarity =default_MCA_polarity (idx);break ; - } +case MP_BUS_NEC98 :/* NEC 98 pin */ - { polarity =default_NEC98_polarity (idx);break ; - } +default : - {printk (KERN_WARNING "broken BIOS!!\n" ); polarity =1 ;break ; } - }break ; - } +case 1 :/* high active */ - { polarity =0 ;break ; - } -case 2 :/* reserved */ - { -printk (KERN_WARNING "broken BIOS!!\n" ); - polarity =1 ; -break ; - } +
xen/arch/x86/io_apic.c static int __init MPBIOS_polarity(int id · line 845
Quoted 10 lines
xen/arch/x86/io_apic.c +2
-4case 3 :/* low active */ - { polarity =1 ;break ; - } -default :/* invalid */ - { + +default :/* reserved */ printk (KERN_WARNING "broken BIOS!!\n" );
We should also see about improving those messages, because this is not helpful at all.
Thanks, Roger.
PATCH 2/12 x86/mm: pagetable_dying() is HVM+SHADOW_PAGING only
In reply to Jan BeulichThe referenced commit didn't go far enough, leaving a Misra rule 2.1 (unreachable code) violation: The function lacks "noreturn" in this configuration. Since with SHADOW_PAGING=n paging_mode_shadow() is compile- time-constant false, the compiler can DCE the call site. Hence we can avoid building the function itself altogether.
No functional change.
xen/arch/x86/mm/paging.c +2 -6
@@ -872,22 +872,18 @@ int paging_enable(struct domain *d, u32 }#endif -#ifdef CONFIG_HVM +#if defined(CONFIG_HVM ) && defined(CONFIG_SHADOW_PAGING )/* Called from the guest to indicate that a process is being torn down * and therefore its pagetables will soon be discarded */ void pagetable_dying (paddr_t gpa) { -#ifdef CONFIG_SHADOW_PAGING struct vcpu *curr = current;ASSERT (paging_mode_shadow (curr->domain)); curr->arch.paging.mode->shadow.pagetable_dying (gpa); -#else -BUG (); -#endif } -#endif /* CONFIG_HVM */ +#endif /* HVM && SHADOW_PAGING */ /* Print paging-assistance info to the console */ void paging_dump_domain_info (struct domain *d)
Re: [PATCH 02/12] x86/mm: pagetable_dying() is HVM+SHADOW_PAGING only
Quoted 10 lines · Jan Beulich
The referenced commit didn't go far enough, leaving a Misra rule 2.1 (unreachable code) violation: The function lacks "noreturn" in this configuration. Since with SHADOW_PAGING=n
paging_mode_shadow()is compile- time-constant false, the compiler can DCE the call site. Hence we can avoid building the function itself altogether.No functional change.
Fixes 2fb2dee1ac62 ("x86/mm: pagetable_dying() is HVM-only")Signed-off-by Jan Beulich <[email protected]>
Thanks, Roger.
PATCH 3/12 x86/shadow: eliminate unused forms of sh_map_and_validate_gl<N>e()
In reply to Jan BeulichThe L2H, L3, and L4 forms only have GUEST_PAGING_LEVELS=4 call sites, i.e. their 2- and 3-level forms are unreachable, violating Misra rule 2.1. The L2H form additionally is unused (call site DCE-d) with PV32=n.
xen/arch/x86/mm/shadow/multi.c +5 -12
@@ -1789,35 +1789,30 @@ sh_map_and_validate(struct vcpu *v, mfn_return result; } +#if GUEST_PAGING_LEVELS >=4 int sh_map_and_validate_gl4e (struct vcpu *v,mfn_t gl4mfn,void *new_gl4p,u32 size) { -#if GUEST_PAGING_LEVELS >=4 return sh_map_and_validate (v, gl4mfn, new_gl4p, size, SH_type_l4_shadow, shadow_l4_index, validate_gl4e); -#else // ! GUEST_PAGING_LEVELS >= 4 -BUG ();/* Called in wrong paging mode! */ -#endif }int sh_map_and_validate_gl3e (struct vcpu *v,mfn_t gl3mfn,void *new_gl3p,u32 size) { -#if GUEST_PAGING_LEVELS >=4 return sh_map_and_validate (v, gl3mfn, new_gl3p, size, SH_type_l3_shadow, shadow_l3_index, validate_gl3e); -#else // ! GUEST_PAGING_LEVELS >= 4 -BUG ();/* Called in wrong paging mode! */ -#endif } +#endif /* GUEST_PAGING_LEVELS >= 4 */ +int sh_map_and_validate_gl2e (struct vcpu *v,mfn_t gl2mfn,void *new_gl2p,u32 size)
@@ -1828,19 +1823,17 @@ sh_map_and_validate_gl2e(struct vcpu *v, validate_gl2e); } +#if defined(CONFIG_PV32 ) &&GUEST_PAGING_LEVELS >=4 int sh_map_and_validate_gl2he (struct vcpu *v,mfn_t gl2mfn,void *new_gl2p,u32 size) { -#if GUEST_PAGING_LEVELS >=4 && defined(CONFIG_PV32 )return sh_map_and_validate (v, gl2mfn, new_gl2p, size, SH_type_l2h_shadow, shadow_l2_index, validate_gl2e); -#else /* Non-PAE guests don't have different kinds of l2 table */ -BUG ();/* Called in wrong paging mode! */ -#endif } +#endif /* CONFIG_PV32 && GUEST_PAGING_LEVELS >= 4 */ int sh_map_and_validate_gl1e(struct vcpu *v, mfn_t gl1mfn,
Re: [PATCH 03/12] x86/shadow: eliminate unused forms of sh_map_and_validate_gl<N>e()
Quoted 5 lines · Jan Beulich
The L2H, L3, and L4 forms only have GUEST_PAGING_LEVELS=4 call sites, i.e. their 2- and 3-level forms are unreachable, violating Misra rule 2.1. The L2H form additionally is unused (call site DCE-d) with PV32=n.
Signed-off-by Jan Beulich <[email protected]>
Looks like a net win in the number of ifdefs.
Thanks, Roger.
PATCH 4/12 x86: add noreturn in a few more places
In reply to Jan Beulichstart_secondary(), do_double_fault(), play_dead(), and tboot_s3_error() never return, so would better be annotated anyway. The do_double_fault() change needs accompanying by adjustments to entry_from_{pv,xen}(), as Eclair then deems the "return" there as unreachable.
context_switch() and continue_running() are odd: We can't (unconditionally) add noreturn to their declarations, as Arm's variants do return. Put the attribute on x86'es definitions instead (the use of unreachable() in reset_stack_and_call_ind() allows the compiler to figure that out itself, but Eclair wants the annotation in addition).
---entry_from_pv() wants the annotation only when PV=n, yet once added gcc then warns about "return" being used in a "noreturn" function. Is there any other approach to address this besides adding #ifdef inside the function (i.e. replacing the !IS_ENABLED(CONFIG_PV) check that's there)?
xen/arch/x86/domain.c +2 -2
@@ -2163,7 +2163,7 @@ static void __context_switch(void)per_cpu (curr_vcpu, cpu) = n; } -void context_switch (struct vcpu *prev,struct vcpu *next) +void noreturncontext_switch (struct vcpu *prev,struct vcpu *next) {unsigned int cpu =smp_processor_id ();struct cpu_info *info =get_cpu_info ();
@@ -2240,7 +2240,7 @@ void context_switch(struct vcpu *prev, sreset_stack_and_call_ind (nextd->arch.ctxt_switch->tail); } -void continue_running (struct vcpu *same) +void noreturncontinue_running (struct vcpu *same) {reset_stack_and_call_ind (same->domain->arch.ctxt_switch->tail); }
xen/arch/x86/include/asm/cpuidle.h +1 -1
@@ -26,7 +26,7 @@ static inline int mwait_idle_init(structint cpuidle_init_cpu (unsigned int cpu); void cf_check default_dead_idle(void); void cf_check acpi_dead_idle(void); -void play_dead (void ); +void noreturnplay_dead (void );void trace_exit_reason (u32 *irq_traced); void update_idle_stats(struct acpi_processor_power *power, struct acpi_processor_cx *cx,
xen/arch/x86/include/asm/tboot.h +1 -1
@@ -126,7 +126,7 @@ int tboot_in_measured_env(void);int tboot_protect_mem_regions (void ); int cf_check tboot_parse_dmar_table(acpi_table_handler dmar_handler);int tboot_s3_resume (void ); -void tboot_s3_error (int error); +void noreturntboot_s3_error (int error);int tboot_wake_ap (int apicid,unsigned long sipi_vec);#else static inline void tboot_probe (void ) {}
xen/arch/x86/smpboot.c +1 -1
@@ -326,7 +326,7 @@ static void set_cpu_sibling_map(unsigned } } -void asmlinkage start_secondary(void) +void asmlinkage noreturn start_secondary(void) {struct cpu_info *info =get_cpu_info ();unsigned int cpu =smp_processor_id ();
xen/arch/x86/traps.c +3 -3
@@ -1080,7 +1080,7 @@ const char *vector_name(unsigned int vecreturn (vec <ARRAY_SIZE (names) && names[vec][0 ]) ? names[vec] :"???" ; } -void asmlinkage do_double_fault(struct cpu_user_regs *regs) +void asmlinkage noreturn do_double_fault(struct cpu_user_regs *regs) {unsigned int cpu;struct extra_state state;
@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase X86_ET_HW_EXC :switch ( vec ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;
@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase X86_ET_HW_EXC :switch ( regs->fred_ss.vector ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;
Re: [PATCH 04/12] x86: add noreturn in a few more places
Quoted 5 lines · Jan Beulich
start_secondary(),do_double_fault(),play_dead(), andtboot_s3_error()never return, so would better be annotated anyway. Thedo_double_fault()change needs accompanying by adjustments to entry_from_{pv,xen}(), as Eclair then deems the "return" there as unreachable.
Quoted 7 lines
context_switch()andcontinue_running()are odd: We can't (unconditionally) add noreturn to their declarations, as Arm's variants do return. Put the attribute on x86'es definitions instead (the use ofunreachable()inreset_stack_and_call_ind()allows the compiler to figure that out itself, but Eclair wants the annotation in addition).Signed-off-by Jan Beulich <[email protected]>
Quoted 6 lines
---
entry_from_pv()wants the annotation only when PV=n, yet once added gcc then warns about "return" being used in a "noreturn" function. Is there any other approach to address this besides adding #ifdef inside the function (i.e. replacing the !IS_ENABLED(CONFIG_PV) check that's there)?
Besides GCC's warning, this would violate MISRA C's Rule 17.9 ("A function declared with a _Noreturn function specifier shall not return to its caller") which is not (yet) adopted by Xen, as it comes with MISRA C:2012 Amendment 3, whereas as you know Xen is based on MISRA C:2012 Amendment 2 rules. Besides this, perhaps an alternative could be something like this (untested):
#define __noreturn_0
#define __noreturn_1 __attribute__((noreturn))
#define __noreturn_select(x) __noreturn_select_(x) #define __noreturn_select_(x) __noreturn_ ## x
#define noreturn(cond) __noreturn_select(cond)
assuming use sites such as noreturn(IS_ENABLED(CONFIG_FOO))
Quoted 83 lines
xen/arch/x86/domain.c +2
-2@@ -2163,7 +2163,7 @@ static void __context_switch(void)per_cpu (curr_vcpu, cpu) = n; } -void context_switch (struct vcpu *prev,struct vcpu *next) +void noreturncontext_switch (struct vcpu *prev,struct vcpu *next) {unsigned int cpu =smp_processor_id ();struct cpu_info *info =get_cpu_info ();@@ -2240,7 +2240,7 @@ void context_switch(struct vcpu *prev, sreset_stack_and_call_ind (nextd->arch.ctxt_switch->tail); } -void continue_running (struct vcpu *same) +void noreturncontinue_running (struct vcpu *same) {reset_stack_and_call_ind (same->domain->arch.ctxt_switch->tail); }xen/arch/x86/include/asm/cpuidle.h +1
-1@@ -26,7 +26,7 @@ static inline int mwait_idle_init(structint cpuidle_init_cpu (unsigned int cpu); void cf_check default_dead_idle(void); void cf_check acpi_dead_idle(void); -void play_dead (void ); +void noreturnplay_dead (void );void trace_exit_reason (u32 *irq_traced); void update_idle_stats(struct acpi_processor_power *power, struct acpi_processor_cx *cx,xen/arch/x86/include/asm/tboot.h +1
-1@@ -126,7 +126,7 @@ int tboot_in_measured_env(void);int tboot_protect_mem_regions (void ); int cf_check tboot_parse_dmar_table(acpi_table_handler dmar_handler);int tboot_s3_resume (void ); -void tboot_s3_error (int error); +void noreturntboot_s3_error (int error);int tboot_wake_ap (int apicid,unsigned long sipi_vec);#else static inline void tboot_probe (void ) {}xen/arch/x86/smpboot.c +1
-1@@ -326,7 +326,7 @@ static void set_cpu_sibling_map(unsigned } } -void asmlinkage start_secondary(void) +void asmlinkage noreturn start_secondary(void) {struct cpu_info *info =get_cpu_info ();unsigned int cpu =smp_processor_id ();xen/arch/x86/traps.c +1
-1@@ -1080,7 +1080,7 @@ const char *vector_name(unsigned int vecreturn (vec <ARRAY_SIZE (names) && names[vec][0 ]) ? names[vec] :"???" ; } -void asmlinkage do_double_fault(struct cpu_user_regs *regs) +void asmlinkage noreturn do_double_fault(struct cpu_user_regs *regs) {unsigned int cpu;struct extra_state state;xen/arch/x86/traps.c +2
-2@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase X86_ET_HW_EXC :switch ( vec ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase X86_ET_HW_EXC :switch ( regs->fred_ss.vector ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Re: [PATCH 04/12] x86: add noreturn in a few more places
Quoted 15 lines · Nicola Vetrini
Quoted 14 lines · Jan Beulich
start_secondary(),do_double_fault(),play_dead(), andtboot_s3_error()never return, so would better be annotated anyway. Thedo_double_fault()
change needs accompanying by adjustments to entry_from_{pv,xen}(), as Eclair then deems the "return" there as unreachable.
context_switch()andcontinue_running()are odd: We can't (unconditionally) add noreturn to their declarations, as Arm's variants do
return. Put the attribute on x86'es definitions instead (the use ofunreachable()inreset_stack_and_call_ind()allows the compiler to figure
that out itself, but Eclair wants the annotation in addition).
Quoted 3 lines
Quoted 1 line
Signed-off-by Jan Beulich <[email protected]>Reviewed-by Nicola Vetrini <[email protected]>
Thanks, yet Andrew's objection will need dealing with.
Quoted 19 lines
Quoted 6 lines
---
entry_from_pv()wants the annotation only when PV=n, yet once added gcc then warns about "return" being used in a "noreturn" function. Is there any other approach to address this besides adding #ifdef inside the function (i.e. replacing the !IS_ENABLED(CONFIG_PV) check that's there)?Besides GCC's warning, this would violate MISRA C's Rule 17.9 ("A function declared with a
_Noreturnfunction specifier shall not return to its caller")
which is not (yet) adopted by Xen, as it comes with MISRA C:2012 Amendment 3, whereas as you know Xen is based on MISRA C:2012 Amendment 2 rules.
Besides this, perhaps an alternative could be something like this (untested):#define
__noreturn_0
#define__noreturn_1__attribute__((noreturn))
Quoted 6 lines
#define
__noreturn_select(x)__noreturn_select_(x)#define__noreturn_select_(x)__noreturn_## x#define noreturn(cond)
__noreturn_select(cond)assuming use sites such as noreturn(IS_ENABLED(CONFIG_FOO))
But how is
void asmlinkage noreturn(!IS_ENABLED(CONFIG_PV))entry_from_pv(struct cpu_user_regs *regs)
(besides of course not being correct to use this way) different from
void asmlinkage
#ifndef CONFIG_PV
noreturn
#endifentry_from_pv(struct cpu_user_regs *regs)
? We'd still end up with a "noreturn" function having "return" statements.
Jan
Re: [PATCH 04/12] x86: add noreturn in a few more places
In reply to Jan BeulichQuoted 13 lines · Jan Beulich
xen/arch/x86/traps.c +1
-1@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase X86_ET_HW_EXC :switch ( vec ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;
xen/arch/x86/traps.c void asmlinkage entry_from_xen(struct cp · line 2621
Quoted 8 lines
xen/arch/x86/traps.c +1
-1@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase X86_ET_HW_EXC :switch ( regs->fred_ss.vector ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;
For starters you're missing a break, and the only reason this isn't a compile error is the trailing comment. Second, it's a tailcall anyway. There really is nothing unreachable anywhere in this construct.
But by far the most important, it the singular noreturn attribute on do_double_fault() (elsewhere, and not visible when reading these two functions) which is preventing #DF falling into #MC. This introduces fragility which did not exist previously.
do_double_fault() would conditionally return if we ever got around to fixing espfix64.
So no - I'm going to insist that Eclair is taught to accept "return some_noreturn_fn();" as intentional. It is objectively less fragile than the MISRA-preferred option.
~Andrew
Re: [PATCH 04/12] x86: add noreturn in a few more places
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
xen/arch/x86/traps.c +1
-2@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase X86_ET_HW_EXC :switch ( vec ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase X86_ET_HW_EXC :switch ( regs->fred_ss.vector ) { -case X86_EXC_DF :return do_double_fault (regs);
Quoted 8 lines
xen/arch/x86/traps.c void asmlinkage entry_from_pv(struct cpu · line 2310
Quoted 5 lines
xen/arch/x86/traps.c +1
-0+case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;For starters you're missing a break, and the only reason this isn't a compile error is the trailing comment.
"break" there would again be unreachable, though.
Quoted 2 lines
Second, it's a tailcall anyway.
There really is nothing unreachable anywhere in this construct.
Just that the concept of "tailcall" is an optimization, not something inherent to the language.
Quoted 4 lines
But by far the most important, it the singular noreturn attribute on
do_double_fault()(elsewhere, and not visible when reading these two functions) which is preventing #DF falling into #MC. This introduces fragility which did not exist previously.
I realized that when making the patch, yet what do you do when the rule is as it is? Hence why I added the comment, really.
Quoted 2 lines
do_double_fault()would conditionally return if we ever got around to fixing espfix64.
And hence would have to lose its "noreturn". At which point call sites would need inspecting. (As said - yes, I do realize the fragility.)
Quoted 3 lines
So no - I'm going to insist that Eclair is taught to accept "return
some_noreturn_fn();" as intentional. It is objectively less fragile than the MISRA-preferred option.
Nicola, thoughts?
Jan
Re: [PATCH 04/12] x86: add noreturn in a few more places
Quoted 46 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
xen/arch/x86/traps.c +1
-2@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase X86_ET_HW_EXC :switch ( vec ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase X86_ET_HW_EXC :switch ( regs->fred_ss.vector ) { -case X86_EXC_DF :return do_double_fault (regs);Quoted 8 lines
xen/arch/x86/traps.c void asmlinkage entry_from_pv(struct cpu · line 2310
Quoted 5 lines
xen/arch/x86/traps.c +1
-0+case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;For starters you're missing a break, and the only reason this isn't a compile error is the trailing comment.
"break" there would again be unreachable, though.
Quoted 2 lines
Second, it's a tailcall anyway.
There really is nothing unreachable anywhere in this construct.Just that the concept of "tailcall" is an optimization, not something inherent to the language.
Quoted 4 lines
But by far the most important, it the singular noreturn attribute on
do_double_fault()(elsewhere, and not visible when reading these two functions) which is preventing #DF falling into #MC. This introduces fragility which did not exist previously.I realized that when making the patch, yet what do you do when the rule is as it is? Hence why I added the comment, really.
Quoted 2 lines
do_double_fault()would conditionally return if we ever got around to fixing espfix64.
Quoted 9 lines
And hence would have to lose its "noreturn". At which point call sites would need inspecting. (As said - yes, I do realize the fragility.)
Quoted 3 lines
So no - I'm going to insist that Eclair is taught to accept "return
some_noreturn_fn();" as intentional. It is objectively less fragile than the MISRA-preferred option.Nicola, thoughts?
If you find a suitable argument from the toolchain that the generated code is correct even though you return from a function where you promised not to return in its declaration, I suppose that's fine, but that MISRA Rule I mentioned ("A function declared with a _Noreturn function specifier shall not return to its caller"), which is not (yet) applied to Xen exists to defend from stumbling on UB 71 of C11: A function declared with a _Noreturn function specifier shall not return to its caller.
So in general ECLAIR should not accept this by default. What you can do is deviate these (hopefully few) cases if you have backing evidence of the correct behavior.
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Re: [PATCH 04/12] x86: add noreturn in a few more places
Quoted 65 lines · Nicola Vetrini
Quoted 46 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
xen/arch/x86/traps.c +1
-2@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase X86_ET_HW_EXC :switch ( vec ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase X86_ET_HW_EXC :switch ( regs->fred_ss.vector ) { -case X86_EXC_DF :return do_double_fault (regs);Quoted 8 lines
xen/arch/x86/traps.c void asmlinkage entry_from_pv(struct cpu · line 2310
Quoted 5 lines
xen/arch/x86/traps.c +1
-0+case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;For starters you're missing a break, and the only reason this isn't a compile error is the trailing comment.
"break" there would again be unreachable, though.
Quoted 2 lines
Second, it's a tailcall anyway.
There really is nothing unreachable anywhere in this construct.Just that the concept of "tailcall" is an optimization, not something inherent to the language.
Quoted 4 lines
But by far the most important, it the singular noreturn attribute on
do_double_fault()(elsewhere, and not visible when reading these two functions) which is preventing #DF falling into #MC. This introduces fragility which did not exist previously.I realized that when making the patch, yet what do you do when the rule is as it is? Hence why I added the comment, really.
Quoted 2 lines
do_double_fault()would conditionally return if we ever got around to fixing espfix64.Quoted 8 lines
And hence would have to lose its "noreturn". At which point call sites would need inspecting. (As said - yes, I do realize the fragility.)
Quoted 3 lines
So no - I'm going to insist that Eclair is taught to accept "return
some_noreturn_fn();" as intentional. It is objectively less fragile than the MISRA-preferred option.Nicola, thoughts?
If you find a suitable argument from the toolchain that the generated code is correct even though you return from a function where you promised not to return in its declaration, I suppose that's fine, but that MISRA Rule I mentioned ("A function declared with a
_Noreturnfunction specifier shall not return to its caller"), which is not (yet) applied to Xen exists to defend from stumbling on UB 71 of C11: A function declared with a_Noreturnfunction specifier shall not return to its caller.
Quoted 3 lines
So in general ECLAIR should not accept this by default. What you can do is deviate these (hopefully few) cases if you have backing evidence of the correct behavior.
The disagreement between you suggesting a deviation and Andrew demanding "that Eclair is taught to accept ..." will need resolving. The argument towards the code being overall less fragile in its original shape cannot easily be put away. And Misra demanding code to be made more fragile than it needs to be cannot really be the goal either.
Jan
Re: [PATCH 04/12] x86: add noreturn in a few more places
Quoted 70 lines · Jan Beulich
Quoted 65 lines · Nicola Vetrini
Quoted 46 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
xen/arch/x86/traps.c +1
-2@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase X86_ET_HW_EXC :switch ( vec ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase X86_ET_HW_EXC :switch ( regs->fred_ss.vector ) { -case X86_EXC_DF :return do_double_fault (regs);Quoted 8 lines
xen/arch/x86/traps.c void asmlinkage entry_from_pv(struct cpu · line 2310
Quoted 5 lines
xen/arch/x86/traps.c +1
-0+case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;For starters you're missing a break, and the only reason this isn't a compile error is the trailing comment.
"break" there would again be unreachable, though.
Quoted 2 lines
Second, it's a tailcall anyway.
There really is nothing unreachable anywhere in this construct.Just that the concept of "tailcall" is an optimization, not something inherent to the language.
Quoted 4 lines
But by far the most important, it the singular noreturn attribute on
do_double_fault()(elsewhere, and not visible when reading these two functions) which is preventing #DF falling into #MC. This introduces fragility which did not exist previously.I realized that when making the patch, yet what do you do when the rule is as it is? Hence why I added the comment, really.
Quoted 2 lines
do_double_fault()would conditionally return if we ever got around to fixing espfix64.Quoted 8 lines
And hence would have to lose its "noreturn". At which point call sites would need inspecting. (As said - yes, I do realize the fragility.)
Quoted 3 lines
So no - I'm going to insist that Eclair is taught to accept "return
some_noreturn_fn();" as intentional. It is objectively less fragile than the MISRA-preferred option.Nicola, thoughts?
If you find a suitable argument from the toolchain that the generated code is correct even though you return from a function where you promised not to return in its declaration, I suppose that's fine, but that MISRA Rule I mentioned ("A function declared with a
_Noreturnfunction specifier shall not return to its caller"), which is not (yet) applied to Xen exists to defend from stumbling on UB 71 of C11: A function declared with a_Noreturnfunction specifier shall not return to its caller.Quoted 3 lines
So in general ECLAIR should not accept this by default. What you can do is deviate these (hopefully few) cases if you have backing evidence of the correct behavior.
Quoted 6 lines
The disagreement between you suggesting a deviation and Andrew demanding "that Eclair is taught to accept ..." will need resolving. The argument towards the code being overall less fragile in its original shape cannot easily be put away. And Misra demanding code to be made more fragile than it needs to be cannot really be the goal either.
Well, I feel like I have explained my reasoning, but let me step back a bit and lay out the possible safe alternatives I see for this construct. By the way, perhaps it's a better idea to split off this change from the other additions of noreturn, which can probably go in as is.
Adding noreturn to do_double_fault() while keeping "return do_double_fault()" in the #DF path is likely subtly broken (i.e. the compiler can rightfully optimize assuming the function does not return) so that's not a feasible solution.
If noreturn is added to do_double_fault(), removing the return in entry_from_pv(), shouldn't that be guarded against falling trough via BUG() or equivalent constructs that do not vanish in release builds? My understanding, that may be incorrect, is that returning from do_double_fault() is currently not expected to happen (hence the panic() in it).
The third option is to ignore all this and not add noreturn to do_double_fault, adding a specific deviation. The deviation is not necessarily done via SAF, can also be something as shown below (untested):
-config=MC3A2.R2.1,reports+={deliberate, "any_area(decl(name(do_double_fault)))"}
and then in its documentation in rst you can summarize why it's not being touched.
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Re: [PATCH 04/12] x86: add noreturn in a few more places
Quoted 71 lines · Nicola Vetrini
Quoted 70 lines · Jan Beulich
Quoted 68 lines · Nicola Vetrini
Quoted 46 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
xen/arch/x86/traps.c +0
-0@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase
X86_ET_HW_EXC:
switch ( vec )
{
- caseX86_EXC_DF: returndo_double_fault(regs); + caseX86_EXC_DF:do_double_fault(regs); /* noreturn */ caseX86_EXC_MC: returndo_machine_check(regs); }
break;xen/arch/x86/traps.c +0
-0@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase
X86_ET_HW_EXC:
switch (regs->fred_ss.vector)
{
- caseX86_EXC_DF: returndo_double_fault(regs);Quoted 8 lines
Quoted 5 lines
+ case
X86_EXC_DF:do_double_fault(regs); /* noreturn */ caseX86_EXC_MC: returndo_machine_check(regs); }
break;For starters you're missing a break, and the only reason this isn't a compile error is the trailing comment.
"break" there would again be unreachable, though.
Quoted 2 lines
Second, it's a tailcall anyway.
There really is nothing unreachable anywhere in this construct.Just that the concept of "tailcall" is an optimization, not something inherent to the language.
Quoted 4 lines
But by far the most important, it the singular noreturn attribute on
do_double_fault()(elsewhere, and not visible when reading these two functions) which is preventing #DF falling into #MC. This introduces fragility which did not exist previously.I realized that when making the patch, yet what do you do when the rule is as it is? Hence why I added the comment, really.
Quoted 2 lines
do_double_fault()would conditionally return if we ever got around to fixing espfix64.Quoted 8 lines
And hence would have to lose its "noreturn". At which point call sites would need inspecting. (As said - yes, I do realize the fragility.)
Quoted 3 lines
So no - I'm going to insist that Eclair is taught to accept "return
some_noreturn_fn();" as intentional. It is objectively less fragile than the MISRA-preferred option.Nicola, thoughts?
If you find a suitable argument from the toolchain that the generated code is correct even though you return from a function where you promised not to return in its declaration, I suppose that's fine, but that MISRA Rule I mentioned ("A function declared with a
_Noreturnfunction specifier shall not return to its caller"), which is not (yet) applied to Xen exists to defend from stumbling on UB 71 of C11: A function declared with a_Noreturnfunction specifier shall not return to its caller.So in general ECLAIR should not accept this by default. What you can do is deviate these (hopefully few) cases if you have backing evidence of the correct behavior.
Quoted 8 lines
Quoted 6 lines
The disagreement between you suggesting a deviation and Andrew demanding "that Eclair is taught to accept ..." will need resolving. The argument towards the code being overall less fragile in its original shape cannot easily be put away. And Misra demanding code to be made more fragile than it needs to be cannot really be the goal either.
Well, I feel like I have explained my reasoning, but let me step back a bit and lay out the possible safe alternatives I see for this construct. By the way, perhaps it's a better idea to split off this change from the other additions of noreturn, which can probably go in as is.
Yes, yet on my question to Andrew whether that should cover just the two hunks above or also the adding of noreturn to do_double_fault() I didn't get any reply so far.
Jan
Re: [PATCH 04/12] x86: add noreturn in a few more places
In reply to Nicola VetriniQuoted 78 lines · Nicola Vetrini
Quoted 70 lines · Jan Beulich
Quoted 65 lines · Nicola Vetrini
Quoted 46 lines · Jan Beulich
Quoted 17 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
xen/arch/x86/traps.c +0
-0@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase
X86_ET_HW_EXC:
switch ( vec )
{
- caseX86_EXC_DF: returndo_double_fault(regs); + caseX86_EXC_DF:do_double_fault(regs); /* noreturn */ caseX86_EXC_MC: returndo_machine_check(regs); }
break;xen/arch/x86/traps.c +0
-0@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase
X86_ET_HW_EXC:
switch (regs->fred_ss.vector)
{
- caseX86_EXC_DF: returndo_double_fault(regs);Quoted 8 lines
Quoted 5 lines
+ case
X86_EXC_DF:do_double_fault(regs); /* noreturn */ caseX86_EXC_MC: returndo_machine_check(regs); }
break;For starters you're missing a break, and the only reason this isn't a compile error is the trailing comment.
"break" there would again be unreachable, though.
Quoted 2 lines
Second, it's a tailcall anyway.
There really is nothing unreachable anywhere in this construct.Just that the concept of "tailcall" is an optimization, not something inherent to the language.
Quoted 4 lines
But by far the most important, it the singular noreturn attribute on
do_double_fault()(elsewhere, and not visible when reading these two functions) which is preventing #DF falling into #MC. This introduces fragility which did not exist previously.I realized that when making the patch, yet what do you do when the rule is as it is? Hence why I added the comment, really.
Quoted 2 lines
do_double_fault()would conditionally return if we ever got around to fixing espfix64.Quoted 8 lines
And hence would have to lose its "noreturn". At which point call sites would need inspecting. (As said - yes, I do realize the fragility.)
Quoted 3 lines
So no - I'm going to insist that Eclair is taught to accept "return
some_noreturn_fn();" as intentional. It is objectively less fragile than the MISRA-preferred option.Nicola, thoughts?
If you find a suitable argument from the toolchain that the generated code is correct even though you return from a function where you promised not to return in its declaration, I suppose that's fine, but that MISRA Rule I mentioned ("A function declared with a
_Noreturnfunction specifier shall not return to its caller"), which is not (yet) applied to Xen exists to defend from stumbling on UB 71 of C11: A function declared with a_Noreturnfunction specifier shall not return to its caller.Quoted 3 lines
So in general ECLAIR should not accept this by default. What you can do is deviate these (hopefully few) cases if you have backing evidence of the correct behavior.
Quoted 6 lines
The disagreement between you suggesting a deviation and Andrew demanding "that Eclair is taught to accept ..." will need resolving. The argument towards the code being overall less fragile in its original shape cannot easily be put away. And Misra demanding code to be made more fragile than it needs to be cannot really be the goal either.
Quoted 3 lines
Well, I feel like I have explained my reasoning, but let me step back a bit and lay out the possible safe alternatives I see for this construct. By the way, perhaps it's a better idea to split off this change from the other additions of noreturn, which can probably go in as is.
Adding noreturn to
do_double_fault()while keeping "returndo_double_fault()" in the #DF path is likely subtly broken (i.e. the compiler can rightfully optimize assuming the function does not return) so that's not a feasible solution.
Hmm, why would this be subtly broken? do_double_fault() doesn't (and won't ever) return. So the compiler optimizing based on that is quite okay.
Quoted 1 line
If noreturn is added to
do_double_fault(), removing the return inentry_from_pv(), shouldn't that be guarded against falling trough viaBUG()or equivalent constructs that do not vanish in release builds? My understanding, that may be incorrect, is that returning fromdo_double_fault()is currently not expected to happen (hence thepanic()in it).
This would feel odd to me - do_double_fault() is really already BUG()-like, so following a call to it by such a construct would end up questionable.
All of the above (and maybe more) is what I understand makes Andrew say "Eclair needs to be taught ...". Andrew, maybe you could expand a bit?
Jan
Re: [PATCH 04/12] x86: add noreturn in a few more places
In reply to Andrew CooperQuoted 31 lines · Andrew Cooper
Quoted 12 lines · Jan Beulich
xen/arch/x86/traps.c +1
-1@@ -2304,7 +2304,7 @@ void asmlinkage entry_from_pv(struct cpucase X86_ET_HW_EXC :switch ( vec ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;xen/arch/x86/traps.c void asmlinkage entry_from_xen(struct cp · line 2621
Quoted 8 lines
xen/arch/x86/traps.c +1
-1@@ -2615,7 +2615,7 @@ void asmlinkage entry_from_xen(struct cpcase X86_ET_HW_EXC :switch ( regs->fred_ss.vector ) { -case X86_EXC_DF :return do_double_fault (regs); +case X86_EXC_DF :do_double_fault (regs);/* noreturn */ case X86_EXC_MC :return do_machine_check (regs); }break ;For starters you're missing a break, and the only reason this isn't a compile error is the trailing comment. Second, it's a tailcall anyway. There really is nothing unreachable anywhere in this construct.
But by far the most important, it the singular noreturn attribute on
do_double_fault()(elsewhere, and not visible when reading these two functions) which is preventing #DF falling into #MC. This introduces fragility which did not exist previously.
Quoted 6 lines
do_double_fault()would conditionally return if we ever got around to fixing espfix64.So no - I'm going to insist that Eclair is taught to accept "return
some_noreturn_fn();" as intentional. It is objectively less fragile than the MISRA-preferred option.
Oh, also: For a v2, how much of this change do you demand dropping / splitting off? Just the two hunks above, or also the one adding noreturn to do_double_fault()?
Jan
PATCH 5/12 x86/crash: address Misra 2.1 rule violation
In reply to Jan BeulichThe use of unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.
No functional change.
xen/arch/x86/crash.c +0 -2
@@ -118,8 +118,6 @@ static int cf_check do_nmi_crash(for ( ; ; )halt (); - -unreachable (); }static void nmi_shootdown_cpus (void )
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
Quoted 2 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.
Urg, isn't that something that should be fixed in Eclair then? Otherwise all the unreachable() calls in our codebase are likely to be found by Eclair sooner or later, and will need to be removed.
Thanks, Roger.
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
Quoted 7 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.Urg, isn't that something that should be fixed in Eclair then? Otherwise all the
unreachable()calls in our codebase are likely to be found by Eclair sooner or later, and will need to be removed.
No, aiui most are covered by deviations. In particular ones in BUG() and ASSERT_UNREACHABLE().
Jan
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.Urg, isn't that something that should be fixed in Eclair then? Otherwise all the
unreachable()calls in our codebase are likely to be found by Eclair sooner or later, and will need to be removed.No, aiui most are covered by deviations. In particular ones in
BUG()andASSERT_UNREACHABLE().
Shouldn't this be a deviation then also? Maybe it would be helpful if the commit message states why this is handled differently from other unreachable() instances then.
Thanks, Roger.
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Urg, isn't that something that should be fixed in Eclair then? Otherwise all the
unreachable()calls in our codebase are likely to be found by Eclair sooner or later, and will need to be removed.No, aiui most are covered by deviations. In particular ones in
BUG()andASSERT_UNREACHABLE().Shouldn't this be a deviation then also?
Maybe, just that I had no good idea how to express such a deviation (preferably without a SAF comment).
Quoted 3 lines
Maybe it would be helpful if
the commit message states why this is handled differently from otherunreachable()instances then.
I've added "..., , and the one here isn't covered by a deviation" to the first sentence. Will that suffice?
Jan
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
Quoted 19 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Urg, isn't that something that should be fixed in Eclair then? Otherwise all the
unreachable()calls in our codebase are likely to be found by Eclair sooner or later, and will need to be removed.No, aiui most are covered by deviations. In particular ones in
BUG()andASSERT_UNREACHABLE().Shouldn't this be a deviation then also?
Maybe, just that I had no good idea how to express such a deviation (preferably without a SAF comment).
Quoted 6 lines
Quoted 3 lines
Maybe it would be helpful if
the commit message states why this is handled differently from otherunreachable()instances then.I've added "..., , and the one here isn't covered by a deviation" to the first sentence. Will that suffice?
TBH, the handling of unreachable() feels inconsistent to me. I don't blame you for this, I know you are just trying to fix the remaining issues.
I guess I will defer the change to someone more familiar with MISRA and why some unreachable() usages are covered by deviations while others aren't.
I think the point of adding something to the commit message is to justify why this is removed vs a deviation being added.
Thanks, Roger.
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
Quoted 31 lines · Roger Pau Monné
Quoted 19 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Urg, isn't that something that should be fixed in Eclair then? Otherwise all the
unreachable()calls in our codebase are likely to be found by Eclair sooner or later, and will need to be removed.No, aiui most are covered by deviations. In particular ones in
BUG()andASSERT_UNREACHABLE().Shouldn't this be a deviation then also?
Maybe, just that I had no good idea how to express such a deviation (preferably without a SAF comment).
Quoted 6 lines
Quoted 3 lines
Maybe it would be helpful if
the commit message states why this is handled differently from otherunreachable()instances then.I've added "..., , and the one here isn't covered by a deviation" to the first sentence. Will that suffice?
TBH, the handling of
unreachable()feels inconsistent to me. I don't blame you for this, I know you are just trying to fix the remaining issues.
Quoted 7 lines
I guess I will defer the change to someone more familiar with MISRA and why some
unreachable()usages are covered by deviations while others aren't.I think the point of adding something to the commit message is to justify why this is removed vs a deviation being added.
Actually this should be done with a deviation, and I thought it was already taken care of by
-config=MC3A2.R2.1,statements+={deliberate, "call(decl(name(__builtin_unreachable||panic||do_unexpected_trap||machine_halt||machine_restart||reboot_or_halt)))"}
namely because unreachable() expands to a call to __builtin_unreachable(). It might be worth checking why that is not the case. Probably the configuration needs a slight tweaking.
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
Quoted 36 lines · Nicola Vetrini
Quoted 35 lines · Roger Pau Monné
Quoted 19 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Urg, isn't that something that should be fixed in Eclair then? Otherwise all the
unreachable()calls in our codebase are likely to be found by Eclair sooner or later, and will need to be removed.No, aiui most are covered by deviations. In particular ones in
BUG()andASSERT_UNREACHABLE().Shouldn't this be a deviation then also?
Maybe, just that I had no good idea how to express such a deviation (preferably without a SAF comment).
Quoted 6 lines
Quoted 3 lines
Maybe it would be helpful if
the commit message states why this is handled differently from otherunreachable()instances then.I've added "..., , and the one here isn't covered by a deviation" to the first sentence. Will that suffice?
TBH, the handling of
unreachable()feels inconsistent to me. I don't blame you for this, I know you are just trying to fix the remaining issues.I guess I will defer the change to someone more familiar with MISRA and why some
unreachable()usages are covered by deviations while others aren't.
Quoted 8 lines
Quoted 2 lines
I think the point of adding something to the commit message is to justify why this is removed vs a deviation being added.
Actually this should be done with a deviation, and I thought it was already taken care of by
-config=MC3A2.R2.1,statements+={deliberate, "call(decl(name(__builtin_unreachable||panic||do_unexpected_trap||machine_halt||machine_restart||reboot_or_halt)))"}
namely because
unreachable()expands to a call to__builtin_unreachable(). It might be worth checking why that is not the case. Probably the configuration needs a slight tweaking.
Question (on my side at least) is: How would such "checking" look like? As said elsewhere, the syntax used in and the semantics of all these deviations are close to impossible to fully understand (which is very certainly different for you). Yet without fully understanding what's written at present, how would one "check" that this is actually what is wanted/needed?
Jan
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
Quoted 46 lines · Jan Beulich
Quoted 36 lines · Nicola Vetrini
Quoted 35 lines · Roger Pau Monné
Quoted 19 lines · Jan Beulich
Quoted 6 lines · Roger Pau Monné
Quoted 5 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monné
Quoted 2 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Urg, isn't that something that should be fixed in Eclair then? Otherwise all the
unreachable()calls in our codebase are likely to be found by Eclair sooner or later, and will need to be removed.No, aiui most are covered by deviations. In particular ones in
BUG()andASSERT_UNREACHABLE().Shouldn't this be a deviation then also?
Maybe, just that I had no good idea how to express such a deviation (preferably without a SAF comment).
Quoted 6 lines
Quoted 3 lines
Maybe it would be helpful if
the commit message states why this is handled differently from otherunreachable()instances then.I've added "..., , and the one here isn't covered by a deviation" to the first sentence. Will that suffice?
TBH, the handling of
unreachable()feels inconsistent to me. I don't blame you for this, I know you are just trying to fix the remaining issues.I guess I will defer the change to someone more familiar with MISRA and why some
unreachable()usages are covered by deviations while others aren't.Quoted 8 lines
Quoted 2 lines
I think the point of adding something to the commit message is to justify why this is removed vs a deviation being added.
Actually this should be done with a deviation, and I thought it was already taken care of by
-config=MC3A2.R2.1,statements+={deliberate, "call(decl(name(__builtin_unreachable||panic||do_unexpected_trap||machine_halt||machine_restart||reboot_or_halt)))"}
namely because
unreachable()expands to a call to__builtin_unreachable(). It might be worth checking why that is not the case. Probably the configuration needs a slight tweaking.
Quoted 8 lines
Question (on my side at least) is: How would such "checking" look like? As said elsewhere, the syntax used in and the semantics of all these deviations are close to impossible to fully understand (which is very certainly different for you). Yet without fully understanding what's written at present, how would one "check" that this is actually what is wanted/needed?
Jan
In this particular case the violation is caused by the __builtin_unreachable() itself, because it is located after for(;;), according to the Eclair's report:
xen/arch/x86/crash.c:119.5-119.7: for' statement is one cause of unreachability of the next statement xen/arch/x86/crash.c:122.5-122.17: reference to function __builtin_unreachable(void)' is unreachable
<preprocessed xen/arch/x86/crash.c>:16007.5-16007.25: preprocessed tokens xen/include/xen/compiler.h:50.23-50.43: expanded from macro `unreachable'
That deviation "-config=MC3A2.R2.1,statements+={deliberate, "call(decl(name(__builtin_unreachable ..." is about code placed after __builtin_unreachable() (I hope I'm right).
Actually, Eclair says us that we do not need to place (unnecessary) __builtin_unreachable() after for(;;).
From my point of view, Jan's patch is OK. Maybe just need to mention
this loop for(;;) in commit message.
Dmytro.
Re: [PATCH 05/12] x86/crash: address Misra 2.1 rule violation
In reply to Jan BeulichQuoted 6 lines · Jan Beulich
The use of
unreachable(), when unreachability is visible to Eclair (and compilers), is deemed a violation. Drop the redundant statement.No functional change.
Signed-off-by Jan Beulich <[email protected]>
PATCH 6/12 kexec: machine_reboot_kexec() doesn't return
In reply to Jan BeulichMark it as such, and then remove the code following at its sole call site, for Eclair flagging that as a Misra rule 2.1 (unreachable code) violation.
xen/common/kexec.c +1 -4
@@ -401,7 +401,7 @@ void kexec_crash(enum crash_reason reasoBUG (); } -static long cf_check kexec_reboot (void *_image) +static long noreturn cf_check kexec_reboot (void *_image) {struct kexec_image *image = _image;
@@ -409,9 +409,6 @@ static long cf_check kexec_reboot(void *kexec_common_shutdown ();machine_reboot_kexec (image); - -BUG (); -return 0 ; } static void cf_check do_crashdump_trigger(unsigned char key)
xen/include/xen/kexec.h +1 -1
@@ -48,7 +48,7 @@ int machine_kexec_add_page(struct kexec_int machine_kexec_load (struct kexec_image *image);void machine_kexec_unload (struct kexec_image *image);void machine_kexec_reserved (xen_kexec_reserve_t *reservation); -void machine_reboot_kexec (struct kexec_image *image); +void noreturnmachine_reboot_kexec (struct kexec_image *image);void machine_kexec (struct kexec_image *image);void kexec_crash (enum crash_reason reason);void kexec_crash_save_cpu (void );
Re: [PATCH 06/12] kexec: machine_reboot_kexec() doesn't return
Quoted 5 lines · Jan Beulich
Mark it as such, and then remove the code following at its sole call site, for Eclair flagging that as a Misra rule 2.1 (unreachable code) violation.
Signed-off-by Jan Beulich <[email protected]>
Quoted 32 lines
xen/common/kexec.c +1
-4@@ -401,7 +401,7 @@ void kexec_crash(enum crash_reason reasoBUG (); } -static long cf_check kexec_reboot (void *_image) +static long noreturn cf_check kexec_reboot (void *_image) {struct kexec_image *image = _image;@@ -409,9 +409,6 @@ static long cf_check kexec_reboot(void *kexec_common_shutdown ();machine_reboot_kexec (image); - -BUG (); -return 0 ; } static void cf_check do_crashdump_trigger(unsigned char key)xen/include/xen/kexec.h +1
-1@@ -48,7 +48,7 @@ int machine_kexec_add_page(struct kexec_int machine_kexec_load (struct kexec_image *image);void machine_kexec_unload (struct kexec_image *image);void machine_kexec_reserved (xen_kexec_reserve_t *reservation); -void machine_reboot_kexec (struct kexec_image *image); +void noreturnmachine_reboot_kexec (struct kexec_image *image);void machine_kexec (struct kexec_image *image);void kexec_crash (enum crash_reason reason);void kexec_crash_save_cpu (void );
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Dmytro Prokopchuk1
Reviewed-byRe: [PATCH 06/12] kexec: machine_reboot_kexec() doesn't return
Quoted 31 lines · Nicola Vetrini
Quoted 7 lines · Jan Beulich
Mark it as such, and then remove the code following at its sole call site,
for Eclair flagging that as a Misra rule 2.1 (unreachable code) violation.Signed-off-by Jan Beulich <[email protected]>Reviewed-by Nicola Vetrini <[email protected]>Quoted 20 lines
xen/common/kexec.c +1
-4@@ -401,7 +401,7 @@ void kexec_crash(enum crash_reason reaso BUG(); } -static long cf_check kexec_reboot (void *_image) +static long noreturn cf_check kexec_reboot (void *_image) { struct kexec_image *image = _image;@@ -409,9 +409,6 @@ static long cf_check kexec_reboot(void * kexec_common_shutdown(); machine_reboot_kexec(image); - - BUG(); - return 0; }
Quoted 13 lines
xen/include/xen/kexec.h int machine_kexec_add_page(struct kexec_ · line 54
Quoted 12 lines
xen/common/kexec.c +0
-0static void cf_check do_crashdump_trigger(unsigned char key)xen/include/xen/kexec.h +1
-1@@ -48,7 +48,7 @@ int machine_kexec_add_page(struct kexec_ int machine_kexec_load(struct kexec_image *image); void machine_kexec_unload(struct kexec_image *image); void machine_kexec_reserved(xen_kexec_reserve_t *reservation); -void machine_reboot_kexec (struct kexec_image *image); +void noreturnmachine_reboot_kexec (struct kexec_image *image); void machine_kexec(struct kexec_image *image); void kexec_crash(enum crash_reason reason); void kexec_crash_save_cpu(void);
LGTM.
Re: [PATCH 06/12] kexec: machine_reboot_kexec() doesn't return
In reply to Jan BeulichQuoted 4 lines · Jan Beulich
Mark it as such, and then remove the code following at its sole call site, for Eclair flagging that as a Misra rule 2.1 (unreachable code) violation.
Signed-off-by Jan Beulich <[email protected]>
PATCH 7/12 altp2m: address Misra 2.1 rule violation
In reply to Jan BeulichThe stub altp2m_vcpu_idx() is recognized as "noreturn" function lacking respective annotation (or having a return statement), which hence is deemed unreachable code by Misra / Eclair. All call sites are guarded by altp2m_active() checks, hence an inline function isn't needed. A declaration will suffice, with call sites then getting DCE-d.
No functional change.
xen/include/asm-generic/altp2m.h +2 -7
@@ -14,13 +14,8 @@ static inline bool altp2m_active(const s return false; } -/* Alternate p2m VCPU */ -static inline unsigned int altp2m_vcpu_idx (const struct vcpu *v) -{ -/* Not implemented on GENERIC, should not be reached. */ -BUG (); -return 0 ; -} +/* Alternate p2m VCPU - placeholder on GENERIC */ +unsigned int altp2m_vcpu_idx (const struct vcpu *v);#endif /* __ASM_GENERIC_ALTP2M_H */
Re: [PATCH 07/12] altp2m: address Misra 2.1 rule violation
Quoted 9 lines · Jan Beulich
The stub
altp2m_vcpu_idx()is recognized as "noreturn" function lacking respective annotation (or having a return statement), which hence is deemed unreachable code by Misra / Eclair. All call sites are guarded byaltp2m_active()checks, hence an inline function isn't needed. A declaration will suffice, with call sites then getting DCE-d.No functional change.
Signed-off-by Jan Beulich <[email protected]>
Quoted 19 lines
xen/include/asm-generic/altp2m.h +2
-7@@ -14,13 +14,8 @@ static inline bool altp2m_active(const s return false; } -/* Alternate p2m VCPU */ -static inline unsigned int altp2m_vcpu_idx (const struct vcpu *v) -{ -/* Not implemented on GENERIC, should not be reached. */ -BUG (); -return 0 ; -} +/* Alternate p2m VCPU - placeholder on GENERIC */ +unsigned int altp2m_vcpu_idx (const struct vcpu *v);#endif /* __ASM_GENERIC_ALTP2M_H */
PATCH 8/12 Arm/GIC: add noreturn in a few more places
In reply to Jan BeulichLPI related functions having just BUG() in them are disliked by Misra / Eclair, as long as they don't also have a noreturn attribute.
---
From its description "Unreachability caused by calls to the following functions or macros is deliberate and there is no risk of code being unexpectedly left out." I would have expected the respective entry in deviations.ecl to cover all of these cases, but clearly that isn't the case.
Of course having noreturn on functions returning non-void is somewhat odd.
xen/arch/arm/gic-v2.c +1 -1
@@ -1315,7 +1315,7 @@ static int __init gicv2_init(void)return 0 ; } -static void gicv2_do_LPI (unsigned int lpi) +static void noreturngicv2_do_LPI (unsigned int lpi) {/* No LPIs in a GICv2 */ BUG ();
xen/arch/arm/include/asm/gic_v3_its.h +1 -1
@@ -229,7 +229,7 @@ static inline unsigned int vgic_v3_its_creturn 0 ; } -static inline void gicv3_do_LPI (unsigned int lpi) +static inline void noreturngicv3_do_LPI (unsigned int lpi) {/* We don't enable LPIs without an ITS. */ BUG ();
xen/arch/arm/vgic-v2.c +4 -3
@@ -718,14 +718,15 @@ static void vgic_v2_domain_free(struct d/* Nothing to be cleanup for this driver */ } -static struct pending_irq *vgic_v2_lpi_to_pending (struct domain *d, -unsigned int vlpi) +static struct pending_irq *noreturnvgic_v2_lpi_to_pending (struct domain *d, +unsigned int vlpi) {/* Dummy function, no LPIs on a VGICv2. */ BUG (); } -static int vgic_v2_lpi_get_priority (struct domain *d,unsigned int vlpi) +static int noreturnvgic_v2_lpi_get_priority (struct domain *d, +unsigned int vlpi) {/* Dummy function, no LPIs on a VGICv2. */ BUG ();
Re: [PATCH 08/12] Arm/GIC: add noreturn in a few more places
Quoted 4 lines · Jan Beulich
LPI related functions having just
BUG()in them are disliked by Misra / Eclair, as long as they don't also have a noreturn attribute.Signed-off-by Jan Beulich <[email protected]>
Quoted 53 lines
---
Quoted 1 line
From its description "Unreachability caused by calls to the following
functions or macros is deliberate and there is no risk of code being unexpectedly left out." I would have expected the respective entry in deviations.ecl to cover all of these cases, but clearly that isn't the case.
Of course having noreturn on functions returning non-void is somewhat odd.
xen/arch/arm/gic-v2.c +1
-1@@ -1315,7 +1315,7 @@ static int __init gicv2_init(void)return 0 ; } -static void gicv2_do_LPI (unsigned int lpi) +static void noreturngicv2_do_LPI (unsigned int lpi) {/* No LPIs in a GICv2 */ BUG ();xen/arch/arm/include/asm/gic_v3_its.h +1
-1@@ -229,7 +229,7 @@ static inline unsigned int vgic_v3_its_creturn 0 ; } -static inline void gicv3_do_LPI (unsigned int lpi) +static inline void noreturngicv3_do_LPI (unsigned int lpi) {/* We don't enable LPIs without an ITS. */ BUG ();xen/arch/arm/vgic-v2.c +4
-3@@ -718,14 +718,15 @@ static void vgic_v2_domain_free(struct d/* Nothing to be cleanup for this driver */ } -static struct pending_irq *vgic_v2_lpi_to_pending (struct domain *d, -unsigned int vlpi) +static struct pending_irq *noreturnvgic_v2_lpi_to_pending (struct domain *d, +unsigned int vlpi) {/* Dummy function, no LPIs on a VGICv2. */ BUG (); } -static int vgic_v2_lpi_get_priority (struct domain *d,unsigned int vlpi) +static int noreturnvgic_v2_lpi_get_priority (struct domain *d, +unsigned int vlpi) {/* Dummy function, no LPIs on a VGICv2. */ BUG ();
PATCH 9/12 Eclair: deviate BUILD_ERROR() wrt rule 2.1 and introduce variants
In reply to Jan BeulichBUILD_ERROR() is even stronger a guard than assertions in general, and ASSERT_UNREACHABLE() (or BUG()) in particular. Deviate it just like those to allow use for marking unreachable portions of code.
In some cases code being unreachable is dependent upon configuration. Introduce two variants, as constructs like
if ( IS_ENABLED(CONFIG_...) )
BUILD_ERROR("...");results in the if() still being reported as unreachable. Sadly these two new macros introduce a new 20.12 violation each, which hence also needs deviating.
automation/eclair_analysis/ECLAIR/deviations.ecl +2 -0
@@ -19,6 +19,7 @@ Constant expressions and unreachable bra -doc_begin="Unreachability inside an ASSERT_UNREACHABLE() and analogous macro calls is deliberate and safe." -config=MC3A2.R2.1,reports+={deliberate, "any_area(any_loc(any_exp(macro(name(ASSERT_UNREACHABLE||PARSE_ERR_RET||PARSE_ERR||FAIL_MSR||FAIL_CPUID)))))"} +-config=MC3A2.R2.1,reports+={deliberate, "any_area(any_loc(any_exp(macro(^BUILD_ERROR(|_IF(|_NOT))$))))"} -doc_end -doc_begin="The asm-offset files are not linked deliberately, since they are used to generate definitions for asm modules."
@@ -667,6 +668,7 @@ deliberate." to the # or ## operators within the following macros are deliberate, to provide useful diagnostic messages to the user." -config=MC3A2.R20.12,macros+={deliberate, "name(ASSERT||BUILD_BUG_ON||BUILD_BUG_ON_ZERO||RUNTIME_CHECK)"} +-config=MC3A2.R20.12,macros+={deliberate, "^BUILD_ERROR(|_IF(|_NOT))$"} -doc_end -doc_begin="The helper macro GENERATE_CASE may use a macro parameter for ordinary
xen/include/xen/macros.h +15 -0
@@ -64,6 +64,21 @@*/ #define BUILD_ERROR (msg) asm ( ".error \"" msg "\"" ) +/* +* Like above, but conditional upon @cfg (not) being enabled. @cfg must be +* suitable to pass to IS_ENABLED(). +*/ +#define BUILD_ERROR_IF (cfg) \ + (IS_ENABLED(cfg) \ + ? ({ BUILD_ERROR( #cfg " unexpectedly enabled"); }) \ + : (void)0) + +#define BUILD_ERROR_IF_NOT (cfg) \ + (!IS_ENABLED(cfg) \ + ? ({ BUILD_ERROR( #cfg " unexpectedly disabled"); }) \ + : (void)0) + +/* Hide a value from the optimiser. */ #define HIDE (x) \ ({ \
Re: [PATCH 09/12] Eclair: deviate BUILD_ERROR() wrt rule 2.1 and introduce variants
Quoted 7 lines · Jan Beulich
BUILD_ERROR()is even stronger a guard than assertions in general, andASSERT_UNREACHABLE()(orBUG()) in particular. Deviate it just like those to allow use for marking unreachable portions of code.In some cases code being unreachable is dependent upon configuration. Introduce two variants, as constructs like
Quoted 8 lines
if ( IS_ENABLED(CONFIG_...) ) BUILD_ERROR("...");results in the
if()still being reported as unreachable. Sadly these two new macros introduce a new 20.12 violation each, which hence also needs deviating.Signed-off-by Jan Beulich <[email protected]>
Presumably you did not fold at least one of the following patches where the construct is actually used into this one to separate concerns?
Quoted 52 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -19,6 +19,7 @@ Constant expressions and unreachable bra -doc_begin="Unreachability inside an ASSERT_UNREACHABLE() andanalogous macro calls is deliberate and safe."
-config=MC3A2.R2.1,reports+={deliberate,
"any_area(any_loc(any_exp(macro(name(ASSERT_UNREACHABLE||PARSE_ERR_RET||PARSE_ERR||FAIL_MSR||FAIL_CPUID)))))"}+-config=MC3A2.R2.1,reports+={deliberate, "any_area(any_loc(any_exp(macro(^BUILD_ERROR(|_IF(|_NOT))$))))"}-doc_end
-doc_begin="The asm-offset files are not linked deliberately, since
they are used to generate definitions for asm modules."automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -667,6 +668,7 @@ deliberate." to the # or ## operators within the following macros are deliberate,to provide
useful diagnostic messages to the user." -config=MC3A2.R20.12,macros+={deliberate,
"name(ASSERT||BUILD_BUG_ON||BUILD_BUG_ON_ZERO||RUNTIME_CHECK)"}+-config=MC3A2.R20.12,macros+={deliberate, "^BUILD_ERROR(|_IF(|_NOT))$"}-doc_end
-doc_begin="The helper macro
GENERATE_CASEmay use a macro parameter
for ordinaryxen/include/xen/macros.h +2
-0@@ -64,6 +64,21 @@*/ #define BUILD_ERROR (msg) asm ( ".error \"" msg "\"" ) +/* +* Like above, but conditional upon @cfg (not) being enabled. @cfg must be
+ * suitable to pass toIS_ENABLED().
+ */xen/include/xen/macros.h +11
-0+#define BUILD_ERROR_IF (cfg) \ + (IS_ENABLED(cfg) \ + ? ({ BUILD_ERROR( #cfg " unexpectedly enabled"); }) \ + : (void)0) + +#define BUILD_ERROR_IF_NOT (cfg) \ + (!IS_ENABLED(cfg) \ + ? ({ BUILD_ERROR( #cfg " unexpectedly disabled"); }) \ + : (void)0) + +/* Hide a value from the optimiser. */ #define HIDE (x) \ ({ \
Signature · 4 lines
Nicola Vetrini, B.Sc. Software Engineer BUGSENG (https://bugseng.com) LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
Re: [PATCH 09/12] Eclair: deviate BUILD_ERROR() wrt rule 2.1 and introduce variants
Quoted 12 lines · Nicola Vetrini
Quoted 11 lines · Jan Beulich
BUILD_ERROR()is even stronger a guard than assertions in general, andASSERT_UNREACHABLE()(orBUG()) in particular. Deviate it just like those
to allow use for marking unreachable portions of code.In some cases code being unreachable is dependent upon configuration. Introduce two variants, as constructs like
if ( IS_ENABLED(CONFIG_...) ) BUILD_ERROR("...");
Quoted 8 lines
Quoted 6 lines
results in the
if()still being reported as unreachable. Sadly these two
new macros introduce a new 20.12 violation each, which hence also needs deviating.Signed-off-by Jan Beulich <[email protected]>Reviewed-by Nicola Vetrini <[email protected]>
Thanks.
Quoted 2 lines
Presumably you did not fold at least one of the following patches where the construct is actually used into this one to separate concerns?
Partly for that, partly to keep subsequent patches possible to go in independently, i.e. in any order.
Jan
Re: [PATCH 09/12] Eclair: deviate BUILD_ERROR() wrt rule 2.1 and introduce variants
In reply to Jan BeulichQuoted 7 lines · Jan Beulich
BUILD_ERROR()is even stronger a guard than assertions in general, andASSERT_UNREACHABLE()(orBUG()) in particular. Deviate it just like those to allow use for marking unreachable portions of code.In some cases code being unreachable is dependent upon configuration. Introduce two variants, as constructs like
Quoted 8 lines
if ( IS_ENABLED(CONFIG_...) ) BUILD_ERROR("...");results in the
if()still being reported as unreachable. Sadly these two new macros introduce a new 20.12 violation each, which hence also needs deviating.Signed-off-by Jan Beulich <[email protected]>
Quoted 43 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +2
-0@@ -19,6 +19,7 @@ Constant expressions and unreachable bra -doc_begin="Unreachability inside an ASSERT_UNREACHABLE() and analogous macro calls is deliberate and safe." -config=MC3A2.R2.1,reports+={deliberate, "any_area(any_loc(any_exp(macro(name(ASSERT_UNREACHABLE||PARSE_ERR_RET||PARSE_ERR||FAIL_MSR||FAIL_CPUID)))))"} +-config=MC3A2.R2.1,reports+={deliberate, "any_area(any_loc(any_exp(macro(^BUILD_ERROR(|_IF(|_NOT))$))))"} -doc_end -doc_begin="The asm-offset files are not linked deliberately, since they are used to generate definitions for asm modules."@@ -667,6 +668,7 @@ deliberate." to the # or ## operators within the following macros are deliberate, to provide useful diagnostic messages to the user." -config=MC3A2.R20.12,macros+={deliberate, "name(ASSERT||BUILD_BUG_ON||BUILD_BUG_ON_ZERO||RUNTIME_CHECK)"} +-config=MC3A2.R20.12,macros+={deliberate, "^BUILD_ERROR(|_IF(|_NOT))$"} -doc_end -doc_begin="The helper macro GENERATE_CASE may use a macro parameter for ordinaryxen/include/xen/macros.h +15
-0@@ -64,6 +64,21 @@*/ #define BUILD_ERROR (msg) asm ( ".error \"" msg "\"" ) +/* +* Like above, but conditional upon @cfg (not) being enabled. @cfg must be +* suitable to pass to IS_ENABLED(). +*/ +#define BUILD_ERROR_IF (cfg) \ + (IS_ENABLED(cfg) \ + ? ({ BUILD_ERROR( #cfg " unexpectedly enabled"); }) \ + : (void)0) + +#define BUILD_ERROR_IF_NOT (cfg) \ + (!IS_ENABLED(cfg) \ + ? ({ BUILD_ERROR( #cfg " unexpectedly disabled"); }) \ + : (void)0) + +/* Hide a value from the optimiser. */ #define HIDE (x) \ ({ \
PATCH 10/12 PCI/physdev: address Misra 2.1 rule violation
In reply to Jan BeulichCases 0..3 are handled, and a 2-bit mask is applied to the switch() expression. Therefore the default: case is reported unreachable by Eclair. Insert BUILD_ERROR() to annotate this for Eclair.
No functional change.
xen/drivers/pci/physdev.c +1 -1
@@ -114,7 +114,7 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_break ;default : - ret = -EINVAL ; +BUILD_ERROR ("PCI_DEVICE_RESET_* inconsistency" );break ; }write_unlock (&pdev->domain->pci_lock);
Re: [PATCH 10/12] PCI/physdev: address Misra 2.1 rule violation
Quoted 7 lines · Jan Beulich
Cases 0..3 are handled, and a 2-bit mask is applied to the
switch()expression. Therefore the default: case is reported unreachable by Eclair. InsertBUILD_ERROR()to annotate this for Eclair.No functional change.
Signed-off-by Jan Beulich <[email protected]>
Quoted 12 lines
xen/drivers/pci/physdev.c +1
-1@@ -114,7 +114,7 @@ ret_t pci_physdev_op(int cmd, XEN_GUEST_break ;default : - ret = -EINVAL ; +BUILD_ERROR ("PCI_DEVICE_RESET_* inconsistency" );break ; }write_unlock (&pdev->domain->pci_lock);
PATCH 11/12 x86/HVM: address Misra 2.1 rule violations
In reply to Jan BeulichIn hvm_set_cr3() the "bad_cr3" label is reachable only with SHADOW_PAGING=y; the code being there is therefore a Misra rule 2.1 (unreachable code) violation when SHADOW_PAGING=n.
Similarly code past the initial switch() in hvm_debug_op() is reachable only when CONFIG_INTEL_VMX=y.
No functional change.
xen/arch/x86/hvm/hvm.c +3 -0
@@ -2455,6 +2455,7 @@ int hvm_set_cr3(unsigned long value, booreturn X86EMUL_OKAY ; bad_cr3: +BUILD_ERROR_IF_NOT (CONFIG_SHADOW_PAGING );gdprintk (XENLOG_ERR ,"Invalid CR3\n" );domain_crash (currd);return X86EMUL_UNHANDLEABLE ;
@@ -5201,6 +5202,8 @@ int hvm_debug_op(struct vcpu *v, int32_treturn -ENOSYS ; } +BUILD_ERROR_IF_NOT (CONFIG_INTEL_VMX ); +vcpu_pause (v); switch ( op )
Re: [PATCH 11/12] x86/HVM: address Misra 2.1 rule violations
Quoted 10 lines · Jan Beulich
In
hvm_set_cr3()the "bad_cr3" label is reachable only with SHADOW_PAGING=y; the code being there is therefore a Misra rule 2.1 (unreachable code) violation when SHADOW_PAGING=n.Similarly code past the initial
switch()inhvm_debug_op()is reachable only whenCONFIG_INTEL_VMX=y.No functional change.
Signed-off-by Jan Beulich <[email protected]>
Thanks, Roger.
PATCH 12/12 x86/nSVM: address Misra 2.1 rule violation
In reply to Jan BeulichThe 16-bit range of "port" is fully handled by the switch(). Therefore the
default: case is reported unreachable by Eclair. Insert BUILD_ERROR() to annotate this for Eclair.
No functional change.
xen/arch/x86/hvm/svm/nestedsvm.c +1 -1
@@ -845,7 +845,7 @@ nsvm_vmcb_guest_intercepts_ioio(paddr_t ++gfn;break ;default : -BUG (); +BUILD_ERROR ("I/O port range not fully covered" );break ; }
Re: [PATCH 12/12] x86/nSVM: address Misra 2.1 rule violation
Quoted 7 lines · Jan Beulich
The 16-bit range of "port" is fully handled by the
switch(). Therefore the
default: case is reported unreachable by Eclair. InsertBUILD_ERROR()to annotate this for Eclair.No functional change.
Signed-off-by Jan Beulich <[email protected]>
That however is a bit weird IMO, as we have usually said we would prefer not to use fixed width types in general, and hence one might argue that port should be unsigned int. Then the BUILD_ERROR() might trigger?
Thanks, Roger.
Re: [PATCH 12/12] x86/nSVM: address Misra 2.1 rule violation
Quoted 10 lines · Roger Pau Monné
Quoted 7 lines · Jan Beulich
The 16-bit range of "port" is fully handled by the
switch(). Therefore the
default: case is reported unreachable by Eclair. InsertBUILD_ERROR()to annotate this for Eclair.No functional change.
Signed-off-by Jan Beulich <[email protected]>Acked-by Roger Pau Monné <[email protected]>
Thanks.
Quoted 4 lines
That however is a bit weird IMO, as we have usually said we would prefer not to use fixed width types in general, and hence one might argue that port should be unsigned int. Then the
BUILD_ERROR()might trigger?
Yes, such a type change would need accompanying by removal of that BUILD_ERROR(). The default: case then also wouldn't be deemed unreachable anymore (even though in practice it still would be).
Jan