address violations of MISRA C:2012 Rule 10.1
v2 cover address violations of MISRA C:2012 Rule 10.1
The widely-used construct
(x & -x), where x is an unsigned integer quantity represented in 2's complement, does yield the expected result. Since all architectures that are targets for compliance do fulfill such requirements, the construct is deemed safe and deviated.
The use of 'DECLARE_BITMAP(features, IOMMU_FEAT_count);' is deviated, to avoid harming code readability.
On the contrary, other uses of inappropriate types are changed.
Changes in v2:
- the patch 'x86/cpu-policy' has been dropped, in favour of the patch submitted by Andrew Cooper.
Nicola Vetrini (8):
xen/include: add macro LOWEST_BIT
arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1 xen/pdx: amend definition of PDX_GROUP_COUNT x86_64/mm: express macro CNT using LOWEST_BIT x86/io_apic: address violation of MISRA C:2012 Rule 10.1 x86/mce: Move MC_NCLASSES into the enum mctelem_class xen/types: address Rule 10.1 for DECLARE_BITMAP use xen/compat: use BUILD_BUG_ON in CHECK_SIZE macros
.../eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ docs/misra/safe.json | 8 ++++++++ xen/arch/arm/include/asm/bitops.h | 6 ++++-- xen/arch/x86/cpu/mcheck/mctelem.c | 2 -- xen/arch/x86/cpu/mcheck/mctelem.h | 5 +++-- xen/arch/x86/include/asm/io_apic.h | 7 ++++--- xen/arch/x86/x86_64/mm.c | 12 ++++++------ xen/include/xen/compat.h | 18 +++++++++++++----- xen/include/xen/iommu.h | 1 + xen/include/xen/macros.h | 6 ++++-- xen/include/xen/pdx.h | 2 +- xen/include/xen/types.h | 8 ++++++++ 12 files changed, 58 insertions(+), 23 deletions(-)
--
2.34.1
PATCH v2 7/8 xen/types: address Rule 10.1 for DECLARE_BITMAP use
Given its use in the declaration 'DECLARE_BITMAP(features, IOMMU_FEAT_count)' the argument 'bits' has essential type 'enum iommu_feature', which is not allowed by the Rule as an operand to the addition operator in macro 'BITS_TO_LONGS'.
This construct is deviated with a deviation comment.
--- docs/misra/safe.json | 8 ++++++++ xen/include/xen/iommu.h | 1 + xen/include/xen/types.h | 8 ++++++++ 3 files changed, 17 insertions(+)
docs/misra/safe.json +8 -0
@@ -20,6 +20,14 @@ }, { "id": "SAF-2-safe", + "analyser": { + "eclair": "MC3R1.R10.1" + }, + "name": "MC3R1.R10.1: use of an enumeration constant in an arithmetic operation", + "text": "This violation can be fixed with a cast to (int) of the enumeration constant, but a deviation was chosen due to code readability (see also the comment in BITS_TO_LONGS)." + }, + { + "id": "SAF-3-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used"
xen/include/xen/iommu.h +1 -0
@@ -360,6 +360,7 @@ struct domain_iommu {#endif /* Features supported by the IOMMU */ +/* SAF-2-safe enum constant in arithmetic operation */ DECLARE_BITMAP (features, IOMMU_FEAT_count);/* Does the guest share HAP mapping with the IOMMU? */
xen/include/xen/types.h +8 -0
@@ -22,6 +22,14 @@ typedef signed long ssize_t;typedef __PTRDIFF_TYPE__ ptrdiff_t ; +/* +* Users of this macro are expected to pass a positive value. +* +* Eventually, this should become an unsigned quantity, but this +* requires fixing various uses of this macro and BITS_PER_LONG in signed +* contexts, such as type-safe 'min' macro uses, which give rise to build errors +* when the arguments have differing signedness, due to the build flags used. +*/ #define BITS_TO_LONGS (bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)#define DECLARE_BITMAP (name,bits) \
Signature · 1 line
2.34.1
PATCH v2 2/8 arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1
In reply to Nicola VetriniThe definitions of ffs{l}? violate Rule 10.1, by using the well-known pattern (x & -x); its usage is wrapped by the LOWEST_BIT macro.
No functional change.
--- xen/arch/arm/include/asm/bitops.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
xen/arch/arm/include/asm/bitops.h +4 -2
@@ -9,6 +9,8 @@#ifndef _ARM_BITOPS_H#define _ARM_BITOPS_H +#include <xen/macros.h> +#include <asm/asm_defns.h> /*
@@ -155,8 +157,8 @@ static inline int fls(unsigned int x) } -#define ffs (x) ({ unsigned int __t = (x); fls(__t & -__t); }) -#define ffsl (x) ({ unsigned long __t = (x); flsl(__t & -__t); }) +#define ffs (x) ({ unsigned int __t = (x); fls(LOWEST_BIT(__t)); }) +#define ffsl (x) ({ unsigned long __t = (x); flsl(LOWEST_BIT(__t)); })/** * find_first_set_bit - find the first set bit in @word
Signature · 1 line
2.34.1
PATCH v2 4/8 x86_64/mm: express macro CNT using LOWEST_BIT
In reply to Nicola VetriniThe various definitions of macro CNT (and the related BUILD_BUG_ON) can be rewritten using LOWEST_BIT, encapsulating a violation of MISRA C:2012 Rule 10.1.
--- xen/arch/x86/x86_64/mm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
xen/arch/x86/x86_64/mm.c +6 -6
@@ -351,9 +351,9 @@ static int setup_compat_m2p_table(struct mem_hotadd_info *info) ~((1UL << (L2_PAGETABLE_SHIFT - 2)) - 1) );#define MFN (x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (LOWEST_BIT(sizeof(*frame_table)) / \ sizeof(*compat_machine_to_phys_mapping)) -BUILD_BUG_ON ((sizeof (*frame_table) & -sizeof (*frame_table)) % \ +BUILD_BUG_ON (LOWEST_BIT (sizeof (*frame_table)) % \sizeof (*compat_machine_to_phys_mapping));for ( i = smap; i < emap; i += (1UL << (L2_PAGETABLE_SHIFT -2 )) )
@@ -410,10 +410,10 @@ static int setup_m2p_table(struct mem_hotadd_info *info) va =RO_MPT_VIRT_START + smap *sizeof (*machine_to_phys_mapping);#define MFN (x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned long)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (LOWEST_BIT(sizeof(*frame_table)) / \ sizeof(*machine_to_phys_mapping)) -BUILD_BUG_ON ((sizeof (*frame_table) & -sizeof (*frame_table)) % \ +BUILD_BUG_ON (LOWEST_BIT (sizeof (*frame_table)) % \sizeof (*machine_to_phys_mapping)); i = smap;
@@ -539,7 +539,7 @@ void __init paging_init(void) mpt_size = (max_page *BYTES_PER_LONG ) + (1UL <<L2_PAGETABLE_SHIFT ) -1 ; mpt_size &= ~((1UL <<L2_PAGETABLE_SHIFT ) -1UL );#define MFN (x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned long)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (LOWEST_BIT(sizeof(*frame_table)) / \ sizeof(*machine_to_phys_mapping))BUILD_BUG_ON ((sizeof (*frame_table) & ~sizeof (*frame_table)) % \sizeof (*machine_to_phys_mapping));
@@ -666,7 +666,7 @@ void __init paging_init(void) mpt_size =0 ;#define MFN (x) (((x) << L2_PAGETABLE_SHIFT) / sizeof(unsigned int)) -#define CNT ((sizeof(*frame_table) & -sizeof(*frame_table)) / \ +#define CNT (LOWEST_BIT(sizeof(*frame_table)) / \ sizeof(*compat_machine_to_phys_mapping))BUILD_BUG_ON ((sizeof (*frame_table) & ~sizeof (*frame_table)) % \sizeof (*compat_machine_to_phys_mapping));
--
2.34.1
PATCH v2 8/8 xen/compat: use BUILD_BUG_ON in CHECK_SIZE macros
In reply to Nicola VetriniBUILD_BUG_ON is the preferred way to induce a build error upon statically determined incorrect conditions.
This also fixes a MISRA C:2012 Rule 10.1 violation in the previous formulation.
---
Changes in v2:
- replace the construct with a BUILD_BUG_ON.
--- xen/include/xen/compat.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
xen/include/xen/compat.h +13 -5
@@ -151,12 +151,20 @@ CHECK_NAME_(k, n, T)(k xen_ ## n *x, \return x == c; \ } -#define CHECK_SIZE (name) \ - typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) != \ - sizeof(compat_ ## name ## _t)) * 2] +#define CHECK_SIZE (name) \ +static inline void __maybe_unused CHECK_SIZE_##name(void) \ +{ \ + typedef int CHECK_NAME(name, S)[1]; \ + BUILD_BUG_ON(sizeof(xen_ ## name ## _t) != \ + sizeof(compat_ ## name ## _t)); \ +}#define CHECK_SIZE_ (k, n) \ - typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) != \ - sizeof(k compat_ ## n)) * 2] +static inline void __maybe_unused CHECK_SIZE_##k_##n(void) \ +{ \ + typedef int CHECK_NAME_(k, n, S)[1]; \ + BUILD_BUG_ON(sizeof(k xen_ ## n) != \ + sizeof(k compat_ ## n)); \ +}#define CHECK_FIELD_COMMON (name, t, f) \ static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
Signature · 1 line
2.34.1
PATCH v2 3/8 xen/pdx: amend definition of PDX_GROUP_COUNT
In reply to Nicola VetriniThe definition of PDX_GROUP_COUNT causes violations of MISRA C:2012 Rule 10.1, therefore the problematic part now uses the LOWEST_BIT macro, which encapsulates the pattern.
--- xen/include/xen/pdx.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/xen/pdx.h +1 -1
@@ -72,7 +72,7 @@extern unsigned long max_pdx;#define PDX_GROUP_COUNT ((1 << PDX_GROUP_SHIFT) / \ - (sizeof(*frame_table) & -sizeof(*frame_table))) + (LOWEST_BIT(sizeof(*frame_table))))extern unsigned long pdx_group_valid[];/**
Signature · 1 line
2.34.1
PATCH v2 1/8 xen/include: add macro LOWEST_BIT
In reply to Nicola VetriniThe purpose of this macro is to encapsulate the well-known expression 'x & -x', that in 2's complement architectures on unsigned integers will give 2^ffs(x), where ffs(x) is the position of the lowest set bit in x.
A deviation for ECLAIR is also introduced.
---
Changes in v2:
- rename to LOWEST_BIT
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ xen/include/xen/macros.h | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-)
automation/eclair_analysis/ECLAIR/deviations.ecl +6 -0
@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern to obtain the value +2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_end + ### Set 3 ### #
xen/include/xen/macros.h +4 -2
@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m)) +#define LOWEST_BIT (x) ((x) & -(x)) + +#define MASK_EXTR (v, m) (((v) & (m)) / LOWEST_BIT(m)) +#define MASK_INSR (v, m) (((v) * LOWEST_BIT(m)) & (m))#define count_args_ (dot, a1, a2, a3, a4, a5, a6, a7, a8, x, ...) x #define count_args(args...) \
--
2.34.1
PATCH v2 5/8 x86/io_apic: address violation of MISRA C:2012 Rule 10.1
In reply to Nicola VetriniThe definition of IO_APIC_BASE contains a sum of an essentially enum value (FIX_IO_APIC_BASE_0) that is positive with an index that, in all instances, is unsigned, therefore the former is cast to unsigned, so that the operands are of the same essential type.
No functional change.
--- xen/arch/x86/include/asm/io_apic.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
xen/arch/x86/include/asm/io_apic.h +4 -3
@@ -14,9 +14,10 @@* Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar */ -#define IO_APIC_BASE (idx) \ - ((volatile uint32_t *)(__fix_to_virt(FIX_IO_APIC_BASE_0 + (idx)) \ - + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK))) +#define IO_APIC_BASE (idx) \ + ((volatile uint32_t *) \ + (__fix_to_virt((unsigned int)FIX_IO_APIC_BASE_0 + (idx)) \ + + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK)))#define IO_APIC_ID (idx) (mp_ioapics[idx].mpc_apicid)
Signature · 1 line
2.34.1
PATCH v2 6/8 x86/mce: Move MC_NCLASSES into the enum mctelem_class
In reply to Nicola VetriniThe definition of MC_NCLASSES contained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves the violation and makes it more resilient to possible additions to that enum.
---
Note that the use of an enum constant as operand to [ ] and != is allowed by the Rule.
--- xen/arch/x86/cpu/mcheck/mctelem.c | 2 -- xen/arch/x86/cpu/mcheck/mctelem.h | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-)
xen/arch/x86/cpu/mcheck/mctelem.c +0 -2
@@ -64,8 +64,6 @@ struct mctelem_ent {#define MC_NENT (MC_URGENT_NENT + MC_NONURGENT_NENT) -#define MC_NCLASSES (MC_NONURGENT + 1) -#define COOKIE2MCTE (c) ((struct mctelem_ent *)(c))#define MCTE2COOKIE (tep) ((mctelem_cookie_t)(tep))
xen/arch/x86/cpu/mcheck/mctelem.h +3 -2
@@ -55,8 +55,9 @@typedef struct mctelem_cookie *mctelem_cookie_t ;typedef enum mctelem_class { -MC_URGENT , -MC_NONURGENT +MC_URGENT , +MC_NONURGENT , +MC_NCLASSES }mctelem_class_t ;extern void mctelem_init (unsigned int );
Signature · 1 line
2.34.1
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Nicola VetriniQuoted 20 lines · Nicola Vetrini
The purpose of this macro is to encapsulate the well-known expression 'x & -x', that in 2's complement architectures on unsigned integers will give 2^ffs(x), where ffs(x) is the position of the lowest set bit in x.
A deviation for ECLAIR is also introduced.
Signed-off-by Nicola Vetrini <[email protected]>---
Changes in v2:
- rename toLOWEST_BIT--- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ xen/include/xen/macros.h | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-)automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0
automation/eclair_analysis/ECLAIR/deviations.ecl still non-negative." · line 281
Quoted 8 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +5
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern to obtain the value +2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_end
Please also add the same deviation and explanation to docs/misra/deviations.rst. Other than that, this looks fine.
Quoted 23 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0### Set 3 ### #xen/include/xen/macros.h +4
-3@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m)) +#define LOWEST_BIT (x) ((x) & -(x)) + +#define MASK_EXTR (v, m) (((v) & (m)) / LOWEST_BIT(m)) +#define MASK_INSR (v, m) (((v) * LOWEST_BIT(m)) & (m))#define count_args_ (dot, a1, a2, a3, a4, a5, a6, a7, a8, x, ...) x #define count_args(args...) \ --2.34.1
Re: [XEN PATCH][for-4.19 v2 2/8] arm/bitops: encapsulate violation of MISRA C:2012 Rule 10.1
In reply to Nicola VetriniQuoted 6 lines · Nicola Vetrini
The definitions of ffs{l}? violate Rule 10.1, by using the well-known pattern (x & -x); its usage is wrapped by the
LOWEST_BITmacro.No functional change.
Signed-off-by Nicola Vetrini <[email protected]>
Re: [XEN PATCH][for-4.19 v2 3/8] xen/pdx: amend definition of PDX_GROUP_COUNT
In reply to Nicola VetriniQuoted 5 lines · Nicola Vetrini
The definition of
PDX_GROUP_COUNTcauses violations of MISRA C:2012 Rule 10.1, therefore the problematic part now uses theLOWEST_BITmacro, which encapsulates the pattern.Signed-off-by Nicola Vetrini <[email protected]>
Re: [XEN PATCH][for-next v2 4/8] x86_64/mm: express macro CNT using LOWEST_BIT
In reply to Nicola VetriniQuoted 5 lines · Nicola Vetrini
The various definitions of macro CNT (and the related
BUILD_BUG_ON) can be rewritten usingLOWEST_BIT, encapsulating a violation of MISRA C:2012 Rule 10.1.Signed-off-by Nicola Vetrini <[email protected]>
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
In reply to Nicola VetriniQuoted 5 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves the violation and makes it more resilient to possible additions to that enum.Signed-off-by Nicola Vetrini <[email protected]>
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Nicola VetriniHi Nicola,
Quoted 3 lines · Nicola Vetrini
The purpose of this macro is to encapsulate the well-known expression 'x & -x', that in 2's complement architectures on unsigned integers will give 2^ffs(x), where ffs(x) is the position of the lowest set bit in x.
In the commit message it is clear that the macro will return the lowest set bit. But...
Quoted 34 lines
A deviation for ECLAIR is also introduced.
Signed-off-by Nicola Vetrini <[email protected]>---
Changes in v2:
- rename toLOWEST_BIT--- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ xen/include/xen/macros.h | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-)automation/eclair_analysis/ECLAIR/deviations.ecl +6
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern to obtain the value +2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_end + ### Set 3 ### #xen/include/xen/macros.h +0
-0
xen/include/xen/macros.h line 11
Quoted 6 lines
xen/include/xen/macros.h +1
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m)) +#define LOWEST_BIT (x) ((x) & -(x))
... this is not reflected in the name of the macro. So it is not obvious if it will return the lowest bit set or clear.
Can you at least add a comment on top explaining what it returns? Something like:
/* Return the lowest bit set */
Cheers,
Signature · 1 line
Julien Grall
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Stefano StabelliniQuoted 25 lines · Stefano Stabellini
Quoted 24 lines · Nicola Vetrini
The purpose of this macro is to encapsulate the well-known expression 'x & -x', that in 2's complement architectures on unsigned integers will give 2^ffs(x), where ffs(x) is the position of the lowest set bit in x.
A deviation for ECLAIR is also introduced.
Signed-off-by Nicola Vetrini <[email protected]>---
Changes in v2:
- rename toLOWEST_BIT--- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ xen/include/xen/macros.h | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-)automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end
Quoted 12 lines
Quoted 7 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern toobtain the value
+2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_endPlease also add the same deviation and explanation to
docs/misra/deviations.rst. Other than that, this looks fine.
Ok.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Julien GrallQuoted 57 lines · Julien Grall
Hi Nicola,
Quoted 3 lines · Nicola Vetrini
The purpose of this macro is to encapsulate the well-known expression 'x & -x', that in 2's complement architectures on unsigned integers will give 2^ffs(x), where ffs(x) is the position of the lowest set bit in x.
In the commit message it is clear that the macro will return the lowest set bit. But...
Quoted 37 lines
A deviation for ECLAIR is also introduced.
Signed-off-by Nicola Vetrini <[email protected]>---
Changes in v2:
- rename toLOWEST_BIT--- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ xen/include/xen/macros.h | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-)automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern toobtain the value
+2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_endautomation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+ ### Set 3 ### #xen/include/xen/macros.h +0
-0xen/include/xen/macros.h line 11
Quoted 6 lines
xen/include/xen/macros.h +1
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m)) +#define LOWEST_BIT (x) ((x) & -(x))... this is not reflected in the name of the macro. So it is not obvious if it will return the lowest bit set or clear.
Quoted 6 lines
Can you at least add a comment on top explaining what it returns? Something like:
/* Return the lowest bit set */
Cheers,
No problem
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Nicola Vetriniautomation/eclair_analysis/ECLAIR/deviations.ecl still non-negative." · line 281
Quoted 11 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +5
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern to obtain the value +2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_end
Why is this added here rather than by ...
xen/include/xen/macros.h line 12
Quoted 8 lines
xen/include/xen/macros.h +0
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))
a SAF-<n>-safe comment here?
xen/include/xen/macros.h line 11
Quoted 1 line
xen/include/xen/macros.h +1
-0+#define LOWEST_BIT (x) ((x) & -(x))
Personally I consider the name misleading: I'd expect a macro of this name to return a bit number, not a mask with a single bit set. No good, reasonably short name comes to mind - ISOLATE_LOW_BIT() is too long for my taste.
Jan
Re: [XEN PATCH][for-next v2 5/8] x86/io_apic: address violation of MISRA C:2012 Rule 10.1
In reply to Nicola VetriniQuoted 15 lines · Nicola Vetrini
The definition of
IO_APIC_BASEcontains a sum of an essentially enum value (FIX_IO_APIC_BASE_0) that is positive with an index that, in all instances, is unsigned, therefore the former is cast to unsigned, so that the operands are of the same essential type.No functional change.
--- xen/arch/x86/include/asm/io_apic.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)xen/arch/x86/include/asm/io_apic.h +0
-0
xen/arch/x86/include/asm/io_apic.h line 20
Quoted 10 lines
xen/arch/x86/include/asm/io_apic.h +4
-3@@ -14,9 +14,10 @@* Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar */ -#define IO_APIC_BASE (idx) \ - ((volatile uint32_t *)(__fix_to_virt(FIX_IO_APIC_BASE_0 + (idx)) \ - + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK))) +#define IO_APIC_BASE (idx) \ + ((volatile uint32_t *) \ + (__fix_to_virt((unsigned int)FIX_IO_APIC_BASE_0 + (idx)) \ + + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK)))
Let's assume that down the road we want to make __fix_to_virt() an inline function (which perhaps it really ought to be already): Won't this trade one violation for another then? I wonder whether the better course of action wouldn't be to switch the two enums to be "anonymous", even if that means adjusting __set_fixmap() and __set_fixmap_x().
As an aside, since you touch the entire construct, it would be nice if the
+ was also moved to the end of the earlier line.
Jan
Re: [XEN PATCH][for-next v2 5/8] x86/io_apic: address violation of MISRA C:2012 Rule 10.1
In reply to Nicola VetriniQuoted 9 lines · Nicola Vetrini
The definition of
IO_APIC_BASEcontains a sum of an essentially enum value (FIX_IO_APIC_BASE_0) that is positive with an index that, in all instances, is unsigned, therefore the former is cast to unsigned, so that the operands are of the same essential type.No functional change.
--- xen/arch/x86/include/asm/io_apic.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Oh, also - there's no S-o-b here.
Jan
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
In reply to Nicola VetriniQuoted 3 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves the violation and makes it more resilient to possible additions to that enum.
And using an enumerator as array dimension specifier is okay for Misra? That would be odd when elsewhere named enums are treated specially.
Jan
Quoted 27 lines
xen/arch/x86/cpu/mcheck/mctelem.c +0
-2@@ -64,8 +64,6 @@ struct mctelem_ent {#define MC_NENT (MC_URGENT_NENT + MC_NONURGENT_NENT) -#define MC_NCLASSES (MC_NONURGENT + 1) -#define COOKIE2MCTE (c) ((struct mctelem_ent *)(c))#define MCTE2COOKIE (tep) ((mctelem_cookie_t)(tep))xen/arch/x86/cpu/mcheck/mctelem.h +3
-2@@ -55,8 +55,9 @@typedef struct mctelem_cookie *mctelem_cookie_t ;typedef enum mctelem_class { -MC_URGENT , -MC_NONURGENT +MC_URGENT , +MC_NONURGENT , +MC_NCLASSES }mctelem_class_t ;extern void mctelem_init (unsigned int );
Re: [XEN PATCH][for-4.19 v2 7/8] xen/types: address Rule 10.1 for DECLARE_BITMAP use
In reply to Nicola Vetrinixen/include/xen/types.h typedef signed long ssize_t; · line 26
Quoted 8 lines · Nicola Vetrini
xen/include/xen/types.h +2
-0@@ -22,6 +22,14 @@ typedef signed long ssize_t;typedef __PTRDIFF_TYPE__ ptrdiff_t ; +/* +* Users of this macro are expected to pass a positive value.
Is passing 0 going to cause any issues?
xen/include/xen/types.h typedef signed long ssize_t; · line 32
Quoted 5 lines
xen/include/xen/types.h +5
-0+* Eventually, this should become an unsigned quantity, but this +* requires fixing various uses of this macro and BITS_PER_LONG in signed +* contexts, such as type-safe 'min' macro uses, which give rise to build errors +* when the arguments have differing signedness, due to the build flags used. +*/
I'm not convinced of the usefulness of this part of the comment.
Jan
Quoted 3 lines
xen/include/xen/types.h +0
-0#define BITS_TO_LONGS (bits) \ (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)#define DECLARE_BITMAP (name,bits) \
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
Quoted 3 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves the violation and makes it more resilient to possible additions to that enum.And using an enumerator as array dimension specifier is okay for Misra? That would be odd when elsewhere named enums are treated specially.
Jan
Yes, the array subscript operator is one of the few places where an enum can be used as an operand (also because negative values wouldn't compile), as opposed to mixing them with ordinary integers.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Jan BeulichQuoted 24 lines · Jan Beulich
Quoted 8 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern toQuoted 6 lines
obtain the value
+2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_endWhy is this added here rather than by ...
Quoted 6 lines
xen/include/xen/macros.h +0
-0@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))
Quoted 5 lines
xen/include/xen/macros.h line 12
Quoted 2 lines
xen/include/xen/macros.h +0
-2-#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
One reason is that now that violations only belonging to tool configurations and similar are documented in docs/misra/deviations.rst (committed in Stefano's branch for-4.19 [1]). Also, there were disagreements on the SAF naming scheme, and patches like those would not be accepted at the moment.
Quoted 8 lines
xen/include/xen/macros.h line 11
Quoted 1 line
xen/include/xen/macros.h +1
-0+#define LOWEST_BIT (x) ((x) & -(x))Personally I consider the name misleading: I'd expect a macro of this name to return a bit number, not a mask with a single bit set. No good, reasonably short name comes to mind -
ISOLATE_LOW_BIT()is too long for my taste.Jan
[1] https://gitlab.com/xen-project/people/sstabellini/xen/-/commits/for-4.19
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
Quoted 32 lines · Nicola Vetrini
Quoted 25 lines · Jan Beulich
Quoted 9 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern toQuoted 6 lines
obtain the value
+2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_endWhy is this added here rather than by ...
Quoted 6 lines
xen/include/xen/macros.h +0
-0@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))Quoted 5 lines
xen/include/xen/macros.h line 12
Quoted 2 lines
xen/include/xen/macros.h +0
-2-#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).
But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.
Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
Jan
Re: [XEN PATCH][for-next v2 5/8] x86/io_apic: address violation of MISRA C:2012 Rule 10.1
In reply to Jan BeulichQuoted 19 lines · Jan Beulich
Quoted 18 lines · Nicola Vetrini
The definition of
IO_APIC_BASEcontains a sum of an essentially enum value (FIX_IO_APIC_BASE_0) that is positive with an index that, in all instances, is unsigned, therefore the former is cast to unsigned, so that the operands are of the same essential type.No functional change.
--- xen/arch/x86/include/asm/io_apic.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)xen/arch/x86/include/asm/io_apic.h +0
-0@@ -14,9 +14,10 @@* Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar */
Quoted 14 lines
xen/arch/x86/include/asm/io_apic.h line 23
Quoted 10 lines
xen/arch/x86/include/asm/io_apic.h +4
-3-#define IO_APIC_BASE (idx) \ - ((volatile uint32_t *)(__fix_to_virt(FIX_IO_APIC_BASE_0 + (idx)) \ - + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK))) +#define IO_APIC_BASE (idx) \ + ((volatile uint32_t *) \ + (__fix_to_virt((unsigned int)FIX_IO_APIC_BASE_0 + (idx)) \ + + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK)))Let's assume that down the road we want to make
__fix_to_virt()an inline function (which perhaps it really ought to be already): Won't this trade one violation for another then?
I don't think so: the violation is in the argument to the macro (i.e., the fact that idx is unsigned and FIX_IO_APIC_BASE_0 is a constant from a named enum). Do you see a way in which a MISRA rule is violated if __fix_to_virt becomes a function with an unsigned int argument?
Quoted 4 lines
I wonder whether the better course of
action wouldn't be to switch the two enums to be "anonymous", even if that means adjusting__set_fixmap()and__set_fixmap_x().
I don't know. It certainly would help from a violation count perspective, though that's more of a code style decision in my opinion.
Quoted 3 lines
As an aside, since you touch the entire construct, it would be nice if the
+ was also moved to the end of the earlier line.
Sure
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next v2 5/8] x86/io_apic: address violation of MISRA C:2012 Rule 10.1
In reply to Jan BeulichQuoted 6 lines · Jan Beulich
Quoted 5 lines · Nicola Vetrini
The definition of
IO_APIC_BASEcontains a sum of an essentially enum value (FIX_IO_APIC_BASE_0) that is positive with an index that, in all instances, is unsigned, therefore the former is cast to unsigned, so that the operands are of the same essential type.
Quoted 8 lines
Quoted 4 lines
No functional change.
--- xen/arch/x86/include/asm/io_apic.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)Oh, also - there's no S-o-b here.
Jan
Ah, good catch.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Jan BeulichQuoted 43 lines · Jan Beulich
Quoted 32 lines · Nicola Vetrini
Quoted 25 lines · Jan Beulich
Quoted 9 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known pattern toQuoted 6 lines
obtain the value
+2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_endWhy is this added here rather than by ...
Quoted 6 lines
xen/include/xen/macros.h +0
-0@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))Quoted 5 lines
xen/include/xen/macros.h line 12
Quoted 2 lines
xen/include/xen/macros.h +0
-2-#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 6 lines
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
I agree
Re: [XEN PATCH][for-4.19 v2 8/8] xen/compat: use BUILD_BUG_ON in CHECK_SIZE macros
In reply to Nicola VetriniQuoted 7 lines · Nicola Vetrini
BUILD_BUG_ONis the preferred way to induce a build error upon statically determined incorrect conditions.This also fixes a MISRA C:2012 Rule 10.1 violation in the previous formulation.
Signed-off-by Nicola Vetrini <[email protected]>
Hmm, looking back it's indeed not clear why I didn't use BUILD_BUG_ON() right away. Perhaps just to avoid inline functions when things can be done without. And/or because originally the macros were intended to be usable in function bodies, not (just) at file scope. However, ...
xen/include/xen/compat.h CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ · line 157
Quoted 13 lines
xen/include/xen/compat.h +4
-3@@ -151,12 +151,20 @@ CHECK_NAME_(k, n, T)(k xen_ ## n *x, \return x == c; \ } -#define CHECK_SIZE (name) \ - typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) != \ - sizeof(compat_ ## name ## _t)) * 2] +#define CHECK_SIZE (name) \ +static inline void __maybe_unused CHECK_SIZE_##name(void) \ +{ \ + typedef int CHECK_NAME(name, S)[1]; \
... what's this and ...
xen/include/xen/compat.h CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ · line 164
Quoted 9 lines
xen/include/xen/compat.h +6
-2+ BUILD_BUG_ON(sizeof(xen_ ## name ## _t) != \ + sizeof(compat_ ## name ## _t)); \ +}#define CHECK_SIZE_ (k, n) \ - typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) != \ - sizeof(k compat_ ## n)) * 2] +static inline void __maybe_unused CHECK_SIZE_##k_##n(void) \ +{ \ + typedef int CHECK_NAME_(k, n, S)[1]; \
... this needed for? The types aren't used anywhere afaict.
Jan
Quoted 6 lines
xen/include/xen/compat.h +3
-0+ BUILD_BUG_ON(sizeof(k xen_ ## n) != \ + sizeof(k compat_ ## n)); \ +}#define CHECK_FIELD_COMMON (name, t, f) \ static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ## t ## _t *c) \
Re: [XEN PATCH][for-next v2 5/8] x86/io_apic: address violation of MISRA C:2012 Rule 10.1
In reply to Nicola VetriniQuoted 25 lines · Nicola Vetrini
Quoted 7 lines · Jan Beulich
Quoted 6 lines · Nicola Vetrini
xen/arch/x86/include/asm/io_apic.h +0
-0@@ -14,9 +14,10 @@* Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar */ Quoted 16 lines
xen/arch/x86/include/asm/io_apic.h line 23
Quoted 10 lines
xen/arch/x86/include/asm/io_apic.h +4
-3-#define IO_APIC_BASE (idx) \ - ((volatile uint32_t *)(__fix_to_virt(FIX_IO_APIC_BASE_0 + (idx)) \ - + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK))) +#define IO_APIC_BASE (idx) \ + ((volatile uint32_t *) \ + (__fix_to_virt((unsigned int)FIX_IO_APIC_BASE_0 + (idx)) \ + + (mp_ioapics[idx].mpc_apicaddr & ~PAGE_MASK)))Let's assume that down the road we want to make
__fix_to_virt()an inline
function (which perhaps it really ought to be already): Won't this trade
one violation for another then?
Quoted 6 lines
I don't think so: the violation is in the argument to the macro (i.e., the fact that
idx is unsigned andFIX_IO_APIC_BASE_0is a constant from a named enum). Do you see a way in
which a MISRA rule is violated if__fix_to_virtbecomes a function with an unsigned int argument?
No. But I assumed such a function would take an enum parameter.
Jan
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
In reply to Nicola VetriniQuoted 8 lines · Nicola Vetrini
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves the
violation and makes it more resilient to possible additions to that enum.
Quoted 8 lines
Quoted 2 lines
And using an enumerator as array dimension specifier is okay for Misra? That would be odd when elsewhere named enums are treated specially.
Yes, the array subscript operator is one of the few places where an enum can be used as
an operand (also because negative values wouldn't compile), as opposed to mixing them
with ordinary integers.
When saying "odd" I didn't even think of negative values. May I therefore ask for the reasoning of why this specific case is deemed non-risky? To me there looks to be a fair risk of creating undersized arrays, leading to out-of-bounds accesses.
Jan
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
Quoted 18 lines · Jan Beulich
Quoted 8 lines · Nicola Vetrini
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves the
violation and makes it more resilient to possible additions to that enum.Quoted 8 lines
Quoted 2 lines
And using an enumerator as array dimension specifier is okay for Misra? That would be odd when elsewhere named enums are treated specially.
Yes, the array subscript operator is one of the few places where an enum can be used as
an operand (also because negative values wouldn't compile), as opposed to mixing them
with ordinary integers.
Quoted 6 lines
When saying "odd" I didn't even think of negative values. May I therefore ask for the reasoning of why this specific case is deemed non-risky? To me there looks to be a fair risk of creating undersized arrays, leading to out-of-bounds accesses.
Jan
Two reasons: MC_NCLASSES is the last value of the enum, and a pattern I've spot in various other places in Xen, so I assumed it was a fairly common pattern for the community. The other reason is that since the value of an enum constant can be derived statically, there is little risk of it being the wrong value, because no arithmetic is done on it in its use as an array's size (and besides, the enum changed the last time ~15 years ago, so I think it's unlikely to change much in the near future).
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
Quoted 28 lines · Nicola Vetrini
Quoted 21 lines · Jan Beulich
Quoted 13 lines · Nicola Vetrini
Quoted 11 lines · Jan Beulich
Quoted 6 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves
the
violation and makes it more resilient to possible additions to that enum.And using an enumerator as array dimension specifier is okay for Misra?
That would be odd when elsewhere named enums are treated specially.Quoted 6 lines
Yes, the array subscript operator is one of the few places where an enum
can be used as
an operand (also because negative values wouldn't compile), as opposed to mixing them
with ordinary integers.Quoted 5 lines
When saying "odd" I didn't even think of negative values. May I therefore
ask for the reasoning of why this specific case is deemed non-risky? To me there looks to be a fair risk of creating undersized arrays, leading to out-of-bounds accesses.
Quoted 11 lines
Two reasons:
MC_NCLASSESis the last value of the enum, and a pattern I've spot in various
other places in Xen, so I assumed it was a fairly common pattern for the community.
The other reason is that since the value of an enum constant can be derived statically, there
is little risk of it being the wrong value, because no arithmetic is done on it in its use
as an array's size (and besides, the enum changed the last time ~15 years ago, so I think
it's unlikely to change much in the near future).
You focus on the specific instance, yet my question was on the general principle.
Jan
Re: [XEN PATCH][for-4.19 v2 7/8] xen/types: address Rule 10.1 for DECLARE_BITMAP use
In reply to Jan BeulichQuoted 5 lines · Jan Beulich
Quoted 4 lines · Nicola Vetrini
xen/include/xen/types.h +0
-0@@ -22,6 +22,14 @@ typedef signed long ssize_t;
Quoted 7 lines
xen/include/xen/types.h typedef signed long ssize_t; · line 26
Quoted 4 lines
xen/include/xen/types.h +2
-0typedef __PTRDIFF_TYPE__ ptrdiff_t ; +/* +* Users of this macro are expected to pass a positive value. Is passing 0 going to cause any issues?
I don't think so, even if that wouldn't make much sense. Given that the usage of the zero lenght array extension is documented, that shouldn't be a concern either.
Quoted 9 lines
Quoted 8 lines
xen/include/xen/types.h +2
-0+* Eventually, this should become an unsigned quantity, but this +* requires fixing various uses of this macro and BITS_PER_LONG in signed
+ * contexts, such as type-safe 'min' macro uses, which give rise to build errors
+ * when the arguments have differing signedness, due to the build flags used.
+ */
Quoted 4 lines
I'm not convinced of the usefulness of this part of the comment.
Jan
Isn't it useful to record why it was left as-is, and what should be done about it? If it's not, this can be dropped on commit, in my opinion.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
In reply to Jan BeulichQuoted 41 lines · Jan Beulich
Quoted 28 lines · Nicola Vetrini
Quoted 21 lines · Jan Beulich
Quoted 13 lines · Nicola Vetrini
Quoted 11 lines · Jan Beulich
Quoted 6 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012 Rule 10.1, therefore by moving it as an enumeration constant resolves
the
violation and makes it more resilient to possible additions to that enum.And using an enumerator as array dimension specifier is okay for Misra?
That would be odd when elsewhere named enums are treated specially.Quoted 6 lines
Yes, the array subscript operator is one of the few places where an enum
can be used as
an operand (also because negative values wouldn't compile), as opposed to mixing them
with ordinary integers.Quoted 5 lines
When saying "odd" I didn't even think of negative values. May I therefore
ask for the reasoning of why this specific case is deemed non-risky? To me there looks to be a fair risk of creating undersized arrays, leading to out-of-bounds accesses.Quoted 11 lines
Two reasons:
MC_NCLASSESis the last value of the enum, and a pattern I've spot in various
other places in Xen, so I assumed it was a fairly common pattern for the community.
The other reason is that since the value of an enum constant can be derived statically, there
is little risk of it being the wrong value, because no arithmetic is done on it in its use
as an array's size (and besides, the enum changed the last time ~15 years ago, so I think
it's unlikely to change much in the near future).
Quoted 4 lines
You focus on the specific instance, yet my question was on the general principle.
Jan
A couple of reasons why this is allowed:
- associating values to set of symbols is typical and makes sense in some contexts
- out-of-bounds operations on arrays are dealt with by a host of other guidelines (Series 18, mainly)
- this rule is about which kinds of operands makes sense to use with certain operators. It was deemed unlikely by MISRA that risky behaviour may arise by
using symbolic indices
as subscripts, given the rest of the other guidelines and the
unspecified and undefined
associated with Rule 10.1. It's not impossible that problems will
arise, but far less
likely than using enums with no restrictions at all (such as those
caused by an enum of
and implementation-defined type used in an arithmetic operation, that
could give
unexpected results).
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
Quoted 62 lines · Nicola Vetrini
Quoted 47 lines · Jan Beulich
Quoted 33 lines · Nicola Vetrini
Quoted 24 lines · Jan Beulich
Quoted 15 lines · Nicola Vetrini
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012
Rule 10.1, therefore by moving it as an enumeration constant resolves
the
violation and makes it more resilient to possible additions to that
enum.Quoted 3 lines
And using an enumerator as array dimension specifier is okay for Misra?
That would be odd when elsewhere named enums are treated specially.Quoted 7 lines
Yes, the array subscript operator is one of the few places where an enum
can be used as
an operand (also because negative values wouldn't compile), as opposed
to mixing them
with ordinary integers.Quoted 7 lines
When saying "odd" I didn't even think of negative values. May I therefore
ask for the reasoning of why this specific case is deemed non-risky? To
me there looks to be a fair risk of creating undersized arrays, leading
to out-of-bounds accesses.Quoted 12 lines
Two reasons:
MC_NCLASSESis the last value of the enum, and a pattern I've spot in various
other places in Xen, so I assumed it was a fairly common pattern for the
community.
The other reason is that since the value of an enum constant can be derived statically, there
is little risk of it being the wrong value, because no arithmetic is done on it in its use
as an array's size (and besides, the enum changed the last time ~15 years ago, so I think
it's unlikely to change much in the near future).Quoted 2 lines
You focus on the specific instance, yet my question was on the general principle.
A couple of reasons why this is allowed:
- associating values to set of symbols is typical and makes sense in some contexts
- out-of-bounds operations on arrays are dealt with by a host of other guidelines
(Series 18, mainly)
- this rule is about which kinds of operands makes sense to use with certain operators.
It was deemed unlikely by MISRA that risky behaviour may arise by
using symbolic indices
as subscripts, given the rest of the other guidelines and the
Quoted 8 lines
unspecified and undefined
associated with Rule 10.1. It's not impossible that problems will
arise, but far less
likely than using enums with no restrictions at all (such as those
caused by an enum of
and implementation-defined type used in an arithmetic operation, that
could give
unexpected results).
Now you appear to focus on uses of arrays, not their definition. Yet even there I wonder: array[idx] is nothing else than *(array + idx). Adding integer types and enums is disallowed. Nothing is said about arithmetic on pointers throughout the description of the type model and its rules. So despite the restriction on integer types, adding enums to pointers is permitted?
Jan
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Jan BeulichQuoted 44 lines · Jan Beulich
Quoted 33 lines · Nicola Vetrini
Quoted 26 lines · Jan Beulich
Quoted 9 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0@@ -274,6 +274,12 @@ still non-negative." -config=MC3R1.R10.1,etypes+={safe, "stmt(operator(logical)||node(conditional_operator||binary_conditional_operator))", "dst_type(ebool||boolean)"} -doc_end +-doc_begin="The macro LOWEST_BIT encapsulates a well-known patternQuoted 7 lines
to
obtain the value
+2^ffs(x) for unsigned integers on two's complement architectures +(all the architectures supported by Xen satisfy this requirement)." +-config=MC3R1.R10.1,reports+={safe, "any_area(any_loc(any_exp(macro(^LOWEST_BIT$))))"} +-doc_endWhy is this added here rather than by ...
Quoted 6 lines
xen/include/xen/macros.h +0
-0@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d))Quoted 5 lines
xen/include/xen/macros.h line 12
Quoted 2 lines
xen/include/xen/macros.h +0
-2-#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 8 lines
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
Jan
While this is true, in this case I'm not willing to deviate with a SAF, given that
some ECLAIR-specific configuration would be needed anyways, given that I'm deviating a macro definition, rather than the line where it's actually used (and maybe other tools would need that as well).
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next v2 6/8] x86/mce: Move MC_NCLASSES into the enum mctelem_class
In reply to Jan BeulichQuoted 73 lines · Jan Beulich
Quoted 63 lines · Nicola Vetrini
Quoted 47 lines · Jan Beulich
Quoted 33 lines · Nicola Vetrini
Quoted 24 lines · Jan Beulich
Quoted 15 lines · Nicola Vetrini
Quoted 10 lines · Jan Beulich
Quoted 8 lines · Nicola Vetrini
The definition of
MC_NCLASSEScontained a violation of MISRA C:2012
Rule 10.1, therefore by moving it as an enumeration constant resolves
the
violation and makes it more resilient to possible additions to that
enum.Quoted 3 lines
And using an enumerator as array dimension specifier is okay for Misra?
That would be odd when elsewhere named enums are treated specially.Quoted 7 lines
Yes, the array subscript operator is one of the few places where an enum
can be used as
an operand (also because negative values wouldn't compile), as opposed
to mixing them
with ordinary integers.Quoted 7 lines
When saying "odd" I didn't even think of negative values. May I therefore
ask for the reasoning of why this specific case is deemed non-risky? To
me there looks to be a fair risk of creating undersized arrays, leading
to out-of-bounds accesses.Quoted 12 lines
Two reasons:
MC_NCLASSESis the last value of the enum, and a pattern I've spot in various
other places in Xen, so I assumed it was a fairly common pattern for the
community.
The other reason is that since the value of an enum constant can be derived statically, there
is little risk of it being the wrong value, because no arithmetic is done on it in its use
as an array's size (and besides, the enum changed the last time ~15 years ago, so I think
it's unlikely to change much in the near future).Quoted 2 lines
You focus on the specific instance, yet my question was on the general principle.
A couple of reasons why this is allowed:
- associating values to set of symbols is typical and makes sense in some contexts
- out-of-bounds operations on arrays are dealt with by a host of other guidelines
(Series 18, mainly)
- this rule is about which kinds of operands makes sense to use with certain operators.
It was deemed unlikely by MISRA that risky behaviour may arise by
using symbolic indices
as subscripts, given the rest of the other guidelines and the
unspecified and undefinedQuoted 8 lines
associated with Rule 10.1. It's not impossible that problems will
arise, but far less
likely than using enums with no restrictions at all (such as those
caused by an enum of
and implementation-defined type used in an arithmetic operation,
that
could give
unexpected results).
Quoted 8 lines
Now you appear to focus on uses of arrays, not their definition. Yet even there I wonder: array[idx] is nothing else than *(array + idx). Adding integer types and enums is disallowed. Nothing is said about arithmetic on pointers throughout the description of the type model and its rules. So despite the restriction on integer types, adding enums to pointers is permitted?
Jan
It's not disallowed just to add enums to integers, but the operation of addition on (named) enums. The MISRA C coding standard deemed arr[IDX] an appropriate (not to be interpreted as safe, though what is unsafe is inappropriate as a consequence of the essential type model) use of enums.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-4.19 v2 8/8] xen/compat: use BUILD_BUG_ON in CHECK_SIZE macros
In reply to Jan BeulichQuoted 45 lines · Jan Beulich
Quoted 7 lines · Nicola Vetrini
BUILD_BUG_ONis the preferred way to induce a build error upon statically determined incorrect conditions.This also fixes a MISRA C:2012 Rule 10.1 violation in the previous formulation.
Signed-off-by Nicola Vetrini <[email protected]>Hmm, looking back it's indeed not clear why I didn't use
BUILD_BUG_ON()right away. Perhaps just to avoid inline functions when things can be done without. And/or because originally the macros were intended to be usable in function bodies, not (just) at file scope. However, ...Quoted 11 lines
xen/include/xen/compat.h +0
-3@@ -151,12 +151,20 @@ CHECK_NAME_(k, n, T)(k xen_ ## n *x, \return x == c; \ } -#define CHECK_SIZE (name) \ - typedef int CHECK_NAME(name, S)[1 - (sizeof(xen_ ## name ## _t) != \ - sizeof(compat_ ## name ##_t)) * 2]
xen/include/xen/compat.h CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ · line 157
Quoted 4 lines
xen/include/xen/compat.h +4
-0+#define CHECK_SIZE (name) \ +static inline void __maybe_unused CHECK_SIZE_##name(void) \ +{ \ + typedef int CHECK_NAME(name, S)[1]; \... what's this and ...
xen/include/xen/compat.h CHECK_NAME_(k, n, T)(k xen_ ## n *x, \ · line 164
Quoted 10 lines
xen/include/xen/compat.h +3
-2+ BUILD_BUG_ON(sizeof(xen_ ## name ## _t) != \ + sizeof(compat_ ## name ## _t)); \ +}#define CHECK_SIZE_ (k, n) \ - typedef int CHECK_NAME_(k, n, S)[1 - (sizeof(k xen_ ## n) != \ - sizeof(k compat_ ## n)) *2]
xen/include/xen/compat.h +3
-0+static inline void __maybe_unused CHECK_SIZE_##k_##n(void) \ +{ \ +typedef int CHECK_NAME_ (k ,n ,S )[1 ]; \... this needed for? The types aren't used anywhere afaict.
Quoted 9 lines
Jan
Quoted 7 lines
xen/include/xen/compat.h +3
-0+ BUILD_BUG_ON(sizeof(k xen_ ## n) != \ + sizeof(k compat_ ## n)); \ +}#define CHECK_FIELD_COMMON (name, t, f) \ static inline int __maybe_unused name(xen_ ## t ## _t *x, compat_ ##t ## _t *c) \
You're probably right. I was wondering the same thing when replacing the code with BUILD_BUG_ON.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Nicola Vetrini+Luca
Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
Quoted 11 lines
xen/include/xen/macros.h line 12
Quoted 8 lines
xen/include/xen/macros.h +0
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
Quoted 8 lines
Quoted 1 line
Jan
While this is true, in this case I'm not willing to deviate with a SAF, given that
some ECLAIR-specific configuration would be needed anyways, given that I'm deviating a macro definition, rather than the line where it's actually used (and maybe other tools would need
that as well).
Did I get it right that the problem with using SAF in this case is that it wouldn't be sufficient to add a SAF comment on top of the MACRO definition, but we would need a SAF comment on top of every MACRO invocation?
If so, then not just for this MACRO but in general basically we have to use deviations.rst.
Luca, do you know what would be the behavior for cppcheck and/or Coverity? I imagine it will be the same and they would also need a deviation at every MACRO invocation, not just the definition?
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
Quoted 38 lines · Stefano Stabellini
Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
Quoted 11 lines
xen/include/xen/macros.h line 12
Quoted 8 lines
xen/include/xen/macros.h +0
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
Quoted 8 lines
Quoted 1 line
Jan
While this is true, in this case I'm not willing to deviate with a SAF, given that
some ECLAIR-specific configuration would be needed anyways, given that I'm deviating a macro definition, rather than the line where it's actually used (and maybe other tools would need
that as well).
Quoted 7 lines
Did I get it right that the problem with using SAF in this case is that it wouldn't be sufficient to add a SAF comment on top of the MACRO definition, but we would need a SAF comment on top of every MACRO invocation?
If so, then not just for this MACRO but in general basically we have to use
deviations.rst.
That would be pretty sad.
Jan
Quoted 3 lines
Luca, do you know what would be the behavior for cppcheck and/or Coverity? I imagine it will be the same and they would also need a deviation at every MACRO invocation, not just the definition?
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
Quoted 44 lines · Jan Beulich
Quoted 43 lines · Stefano Stabellini
Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
Quoted 11 lines
xen/include/xen/macros.h line 12
Quoted 8 lines
xen/include/xen/macros.h +0
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
Quoted 8 lines
Quoted 1 line
Jan
While this is true, in this case I'm not willing to deviate with a SAF, given that
some ECLAIR-specific configuration would be needed anyways, given that I'm deviating a macro definition, rather than the line where it's actually used (and maybe other tools would need
that as well).Did I get it right that the problem with using SAF in this case is that it wouldn't be sufficient to add a SAF comment on top of the MACRO definition, but we would need a SAF comment on top of every MACRO invocation?
Quoted 7 lines
Quoted 2 lines
If so, then not just for this MACRO but in general basically we have to use
deviations.rst.That would be pretty sad.
Jan
Local deviation comments are for local deviations; deviating patterns is a tool configuration.
Quoted 3 lines
Quoted 3 lines
Luca, do you know what would be the behavior for cppcheck and/or Coverity? I imagine it will be the same and they would also need a deviation at every MACRO invocation, not just the definition?
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Stefano StabelliniQuoted 49 lines · Stefano Stabellini
+Luca
Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
Quoted 11 lines
xen/include/xen/macros.h line 12
Quoted 8 lines
xen/include/xen/macros.h +0
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
Quoted 8 lines
Quoted 1 line
Jan
While this is true, in this case I'm not willing to deviate with a SAF, given that
some ECLAIR-specific configuration would be needed anyways, given that I'm deviating a macro definition, rather than the line where it's actually used (and maybe other tools would need
that as well).Did I get it right that the problem with using SAF in this case is that it wouldn't be sufficient to add a SAF comment on top of the MACRO definition, but we would need a SAF comment on top of every MACRO invocation?
Quoted 6 lines
If so, then not just for this MACRO but in general basically we have to use
deviations.rst.Luca, do you know what would be the behavior for cppcheck and/or Coverity? I imagine it will be the same and they would also need a deviation at every MACRO invocation, not just the definition?
Seems that cppcheck reports at the macro definition, instead Coverity reports at the macro invocation.
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Nicola VetriniQuoted 51 lines · Nicola Vetrini
Quoted 50 lines · Jan Beulich
Quoted 49 lines · Stefano Stabellini
Quoted 33 lines
Quoted 27 lines
Quoted 12 lines
Quoted 11 lines
xen/include/xen/macros.h line 12
Quoted 8 lines
xen/include/xen/macros.h +0
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 6 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in
Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Quoted 5 lines
Well, that needs resolving. The naming there shouldn't lead to patches
being accepted that later may need redoing.Jan
Quoted 9 lines
While this is true, in this case I'm not willing to deviate with a SAF, given
that
some ECLAIR-specific configuration would be needed anyways, given that I'm
deviating a macro definition, rather than the line where it's actually used
(and maybe other tools would need
that as well).Did I get it right that the problem with using SAF in this case is that
it wouldn't be sufficient to add a SAF comment on top of the MACRO definition, but we would need a SAF comment on top of every MACRO invocation?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
If so, then not just for this MACRO but in general basically we have to
usedeviations.rst.That would be pretty sad.
Local deviation comments are for local deviations; deviating patterns is a tool configuration.
That's orthogonal. A deviating comment on a macro definition, when it is about an aspect that's meaningful only after the macro is expanded (i.e. not violating some rule concerning macro definitions only), would be quite helpful to limit the number of such comments that need sprinkling across the code base.
Jan
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
In reply to Luca FancelluQuoted 49 lines · Luca Fancellu
Quoted 49 lines · Stefano Stabellini
+Luca
Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
Quoted 11 lines
xen/include/xen/macros.h line 12
Quoted 8 lines
xen/include/xen/macros.h +0
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
Quoted 8 lines
Quoted 1 line
Jan
While this is true, in this case I'm not willing to deviate with a SAF, given that
some ECLAIR-specific configuration would be needed anyways, given that I'm deviating a macro definition, rather than the line where it's actually used (and maybe other tools would need
that as well).Did I get it right that the problem with using SAF in this case is that it wouldn't be sufficient to add a SAF comment on top of the MACRO definition, but we would need a SAF comment on top of every MACRO invocation?
If so, then not just for this MACRO but in general basically we have to use
deviations.rst.
Quoted 6 lines
Quoted 3 lines
Luca, do you know what would be the behavior for cppcheck and/or Coverity? I imagine it will be the same and they would also need a deviation at every MACRO invocation, not just the definition?
Seems that cppcheck reports at the macro definition, instead Coverity reports at the macro invocation.
Does that mean that a /* SAF-xx-safe */ comment would work at the MACRO definition for cppcheck but not for Coverity?
If so, then I wonder if cppcheck's behavior is what we would like to have, but from a code compliance point of view it is the least reliable, so that's the reason why both Coverity and ECLAIR don't implement it. In terms of correctness of the implementation we know cppcheck is lagging a bit behind...
Re: [XEN PATCH][for-next][for-4.19 v2 1/8] xen/include: add macro LOWEST_BIT
Quoted 61 lines · Stefano Stabellini
Quoted 49 lines · Luca Fancellu
Quoted 49 lines · Stefano Stabellini
+Luca
Quoted 29 lines
Quoted 29 lines
Quoted 12 lines
Quoted 11 lines
xen/include/xen/macros.h line 12
Quoted 8 lines
xen/include/xen/macros.h +0
-2@@ -8,8 +8,10 @@#define DIV_ROUND (n, d) (((n) + (d) / 2) / (d))#define DIV_ROUND_UP (n, d) (((n) + (d) - 1) / (d)) -#define MASK_EXTR (v, m) (((v) & (m)) / ((m) & -(m))) -#define MASK_INSR (v, m) (((v) * ((m) & -(m))) & (m))a SAF-<n>-safe comment here?
Quoted 5 lines
One reason is that now that violations only belonging to tool configurations
and similar are documented indocs/misra/deviations.rst(committed in Stefano's
branch for-4.19 [1]).But tool configuration means every analysis tool needs configuring separately. That's why the comment tagging scheme was decided to be preferred, iirc.
Quoted 3 lines
Also, there were disagreements on the SAF naming scheme, and
patches like those would not be accepted at the moment.Well, that needs resolving. The naming there shouldn't lead to patches being accepted that later may need redoing.
Quoted 8 lines
Quoted 1 line
Jan
While this is true, in this case I'm not willing to deviate with a SAF, given that
some ECLAIR-specific configuration would be needed anyways, given that I'm deviating a macro definition, rather than the line where it's actually used (and maybe other tools would need
that as well).Did I get it right that the problem with using SAF in this case is that it wouldn't be sufficient to add a SAF comment on top of the MACRO definition, but we would need a SAF comment on top of every MACRO invocation?
If so, then not just for this MACRO but in general basically we have to use
deviations.rst.Quoted 6 lines
Quoted 3 lines
Luca, do you know what would be the behavior for cppcheck and/or Coverity? I imagine it will be the same and they would also need a deviation at every MACRO invocation, not just the definition?
Seems that cppcheck reports at the macro definition, instead Coverity reports at the macro invocation.
Quoted 8 lines
Does that mean that a /* SAF-xx-safe */ comment would work at the MACRO definition for cppcheck but not for Coverity?
If so, then I wonder if cppcheck's behavior is what we would like to have, but from a code compliance point of view it is the least reliable, so that's the reason why both Coverity and ECLAIR don't implement it. In terms of correctness of the implementation we know cppcheck is lagging a bit behind...
Yes, I’m starting to think that if we want to deviate a large number of macro usage, We should come up with something like declaring the macro somewhere and adding the in-code comment automatically by the script before the analysis... But we need to see how feasible it is.