address violations of MISRA C Rule 20.7
PATCH v3 1/7 x86/msi: address violation of MISRA C Rule 20.7 and coding style
In reply to Nicola VetriniMISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
While at it, the style of these macros has been somewhat uniformed.
No functional change.
---
Changes in v2:
- Make the style change more consistent
--- xen/arch/x86/include/asm/msi.h | 49 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-)
xen/arch/x86/include/asm/msi.h +25 -24
@@ -147,33 +147,34 @@ int msi_free_irq(struct msi_desc *entry);*/ #define NR_HP_RESERVED_VECTORS 20 -#define msi_control_reg (base) (base + PCI_MSI_FLAGS) -#define msi_lower_address_reg (base) (base + PCI_MSI_ADDRESS_LO) -#define msi_upper_address_reg (base) (base + PCI_MSI_ADDRESS_HI) -#define msi_data_reg (base, is64bit) \ - ( (is64bit == 1) ? base+PCI_MSI_DATA_64 : base+PCI_MSI_DATA_32 ) -#define msi_mask_bits_reg (base, is64bit) \ - ( (is64bit == 1) ? base+PCI_MSI_MASK_BIT : base+PCI_MSI_MASK_BIT-4) +#define msi_control_reg (base) ((base) + PCI_MSI_FLAGS) +#define msi_lower_address_reg (base) ((base) + PCI_MSI_ADDRESS_LO) +#define msi_upper_address_reg (base) ((base) + PCI_MSI_ADDRESS_HI) +#define msi_data_reg (base, is64bit) \ + (((is64bit) == 1) ? (base) + PCI_MSI_DATA_64 : (base) + PCI_MSI_DATA_32) +#define msi_mask_bits_reg (base, is64bit) \ + (((is64bit) == 1) ? (base) + PCI_MSI_MASK_BIT \ + : (base) + PCI_MSI_MASK_BIT - 4)#define msi_pending_bits_reg (base, is64bit) \ - ((base) + PCI_MSI_MASK_BIT + ((is64bit) ? 4 : 0)) -#define msi_disable (control) control &= ~PCI_MSI_FLAGS_ENABLE + ((base) + PCI_MSI_MASK_BIT + ((is64bit) ? 4 : 0)) +#define msi_disable (control) ({ (control) &= ~PCI_MSI_FLAGS_ENABLE })#define multi_msi_capable (control) \ - (1 << ((control & PCI_MSI_FLAGS_QMASK) >> 1)) + (1 << (((control) & PCI_MSI_FLAGS_QMASK) >> 1))#define multi_msi_enable (control, num) \ - control |= (((fls(num) - 1) << 4) & PCI_MSI_FLAGS_QSIZE); -#define is_64bit_address (control) (!!(control & PCI_MSI_FLAGS_64BIT)) -#define is_mask_bit_support (control) (!!(control & PCI_MSI_FLAGS_MASKBIT)) -#define msi_enable (control, num) multi_msi_enable(control, num); \ - control |= PCI_MSI_FLAGS_ENABLE - -#define msix_control_reg (base) (base + PCI_MSIX_FLAGS) -#define msix_table_offset_reg (base) (base + PCI_MSIX_TABLE) -#define msix_pba_offset_reg (base) (base + PCI_MSIX_PBA) -#define msix_enable (control) control |= PCI_MSIX_FLAGS_ENABLE -#define msix_disable (control) control &= ~PCI_MSIX_FLAGS_ENABLE -#define msix_table_size (control) ((control & PCI_MSIX_FLAGS_QSIZE)+1) -#define msix_unmask (address) (address & ~PCI_MSIX_VECTOR_BITMASK) -#define msix_mask (address) (address | PCI_MSIX_VECTOR_BITMASK) + ({ (control) |= (((fls(num) - 1) << 4) & PCI_MSI_FLAGS_QSIZE) }) +#define is_64bit_address (control) (!!((control) & PCI_MSI_FLAGS_64BIT)) +#define is_mask_bit_support (control) (!!((control) & PCI_MSI_FLAGS_MASKBIT)) +#define msi_enable (control, num) ({ multi_msi_enable(control, num); \ + (control) |= PCI_MSI_FLAGS_ENABLE }) + +#define msix_control_reg (base) ((base) + PCI_MSIX_FLAGS) +#define msix_table_offset_reg (base) ((base) + PCI_MSIX_TABLE) +#define msix_pba_offset_reg (base) ((base) + PCI_MSIX_PBA) +#define msix_enable (control) ({ (control) |= PCI_MSIX_FLAGS_ENABLE }) +#define msix_disable (control) ({ (control) &= ~PCI_MSIX_FLAGS_ENABLE }) +#define msix_table_size (control) (((control) & PCI_MSIX_FLAGS_QSIZE) + 1) +#define msix_unmask (address) ((address) & ~PCI_MSIX_VECTOR_BITMASK) +#define msix_mask (address) ((address) | PCI_MSIX_VECTOR_BITMASK)/* * MSI Defined Data Structures
Signature · 1 line
2.34.1
v3 cover address violations of MISRA C Rule 20.7
Hi all,
this series aims to refactor some macros that cause violations of MISRA C Rule 20.7 ("Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses"). All the macros touched by these patches are in some way involved in violations, and the strategy adopted to bring them into compliance is to add parentheses around macro arguments where needed.
Deviations from the rule have been amended to encompass also direct use in initializer lists of macro arguments.
Patch 1 is taken, with adjustments, from the earlier series (which was incorrectly tagged as v1). All other patches are new in this series and are pairwise indipendent.
Nicola Vetrini (7):
x86/msi: address violation of MISRA C Rule 20.7 and coding style arm/public: address violations of MISRA C Rule 20.7 x86/vPMU: address violations of MISRA C Rule 20.7 x86/hvm: address violations of MISRA C Rule 20.7 automation/eclair: add deviations for Rule 20.7 xen/mm: address violations of MISRA C Rule 20.7 x86/amd: address violations of MISRA C Rule 20.7
.../eclair_analysis/ECLAIR/deviations.ecl | 25 +++++++++- docs/misra/deviations.rst | 14 +++++- docs/misra/rules.rst | 2 +- xen/arch/x86/hvm/domain.c | 6 +-- xen/arch/x86/include/asm/amd.h | 3 +- xen/arch/x86/include/asm/msi.h | 49 ++++++++++--------- xen/arch/x86/include/asm/vpmu.h | 4 +- xen/include/public/arch-arm.h | 2 +- xen/include/xen/mm.h | 14 +++--- 9 files changed, 77 insertions(+), 42 deletions(-)
Signature · 1 line
2.34.1
PATCH v3 4/7 x86/hvm: address violations of MISRA C Rule 20.7
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
--- xen/arch/x86/hvm/domain.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
xen/arch/x86/hvm/domain.c +3 -3
@@ -132,9 +132,9 @@ int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) s = (struct segment_register ) \ { 0, { (r)->s ## _ar }, (r)->s ## _limit, (r)->s ## _base }; \/* Set accessed / busy bit for present segments. */ \ - if ( s.p ) \ - s.type |= (x86_seg_##s != x86_seg_tr ? 1 : 2); \ - check_segment(&s, x86_seg_ ## s); }) + if ( (s).p ) \ + (s).type |= (x86_seg_##s != x86_seg_tr ? 1 : 2); \ + check_segment(&(s), x86_seg_ ## s); }) rc =SEG (cs, regs); rc |=SEG (ds, regs);
Signature · 1 line
2.34.1
PATCH v3 7/7 x86/amd: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniMISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
--- xen/arch/x86/include/asm/amd.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/include/asm/amd.h +2 -1
@@ -119,7 +119,8 @@ #define AMD_LEGACY_ERRATUM(...) -1 /* legacy */, __VA_ARGS__, 0#define AMD_OSVW_ERRATUM (osvw_id, ...) osvw_id, __VA_ARGS__, 0#define AMD_MODEL_RANGE (f, m_start, s_start, m_end, s_end) \ - ((f << 24) | (m_start << 16) | (s_start << 12) | (m_end << 4) | (s_end)) + (((f) << 24) | ((m_start) << 16) | ((s_start) << 12) | \ + ((m_end) << 4) | (s_end))#define AMD_MODEL_RANGE_FAMILY (range) (((range) >> 24) & 0xff)#define AMD_MODEL_RANGE_START (range) (((range) >> 12) & 0xfff)#define AMD_MODEL_RANGE_END (range) ((range) & 0xfff)
Signature · 1 line
2.34.1
PATCH v3 2/7 arm/public: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniMISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
--- xen/include/public/arch-arm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/include/public/arch-arm.h +1 -1
@@ -209,7 +209,7 @@do { \ __typeof__(&(hnd)) _sxghr_tmp = &(hnd); \ _sxghr_tmp->q =0 ; \ - _sxghr_tmp->p = val; \ + _sxghr_tmp->p = (val); \ } while ( 0 )#define set_xen_guest_handle (hnd, val) set_xen_guest_handle_raw(hnd, val)
Signature · 1 line
2.34.1
PATCH v3 3/7 x86/vPMU: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniMISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
--- xen/arch/x86/include/asm/vpmu.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/arch/x86/include/asm/vpmu.h +2 -2
@@ -23,8 +23,8 @@#define MSR_TYPE_ARCH_CTRL 4/* Start of PMU register bank */ -#define vpmu_reg_pointer (ctxt, offset) ((void *)((uintptr_t)ctxt + \ - (uintptr_t)ctxt->offset)) +#define vpmu_reg_pointer (ctxt, offset) ((void *)((uintptr_t)(ctxt) + \ + (uintptr_t)(ctxt)->offset))/* Arch specific operations shared by all vpmus */ struct arch_vpmu_ops {
Signature · 1 line
2.34.1
PATCH v3 5/7 automation/eclair: add deviations for Rule 20.7
In reply to Nicola VetriniThese deviations deal with the following cases:
- macro arguments used directly as initializer list arguments;
- uses of the __config_enabled macro, that can't be brought into compliance without breaking its functionality;
- exclude files that are out of scope (efi headers and cpu_idle);
- uses of alternative_{call,vcall}[0-9] macros.
The existing configuration for R20.7 is reordered so that it matches the cases listed in its documentation comment.
--- .../eclair_analysis/ECLAIR/deviations.ecl | 25 +++++++++++++++++-- docs/misra/deviations.rst | 14 ++++++++++- docs/misra/rules.rst | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-)
automation/eclair_analysis/ECLAIR/deviations.ecl +23 -2
@@ -401,12 +401,33 @@ unexpected result when the structure is given as argument to a sizeof() operator -doc_begin="Code violating Rule 20.7 is safe when macro parameters are used: (1) as function arguments; (2) as macro arguments; (3) as array indices; (4) as lhs -in assignments." +in assignments; (5) as initializers, possibly designated, in initalizer lists." -config=MC3R1.R20.7,expansion_context= {safe, "context(__call_expr_arg_contexts)"}, +{safe, "left_right(^[(,\\[]$,^[),\\]]$)"}, {safe, "context(skip_to(__expr_non_syntactic_contexts, stmt_child(node(array_subscript_expr), subscript)))"}, {safe, "context(skip_to(__expr_non_syntactic_contexts, stmt_child(operator(assign), lhs)))"}, -{safe, "left_right(^[(,\\[]$,^[),\\]]$)"} +{safe, "context(skip_to(__expr_non_syntactic_contexts, stmt_child(node(init_list_expr||designated_init_expr), init)))"} +-doc_end + +-doc_begin="Violations involving the __config_enabled macros cannot be fixed without +breaking the macro's logic; futhermore, the macro is only ever used in the context +of the IS_ENABLED or STATIC_IF/STATIC_IF_NOT macros, so it always receives a literal +0 or 1 as input, posing no risk to safety." +-config=MC3R1.R20.7,reports+={safe, "any_area(any_loc(any_exp(macro(^___config_enabled$))))"} +-doc_end + +-doc_begin="Violations due to the use of macros defined in files that are +not in scope for compliance are allowed, as that is imported code." +-file_tag+={gnu_efi_include, "^xen/include/efi/.*$"} +-file_tag+={acpi_cpu_idle, "^xen/arch/x86/acpi/cpu_idle\\.c$"} +-config=MC3R1.R20.7,reports+={safe, "any_area(any_loc(file(gnu_efi_include)))"} +-config=MC3R1.R20.7,reports+={safe, "any_area(any_loc(file(acpi_cpu_idle)))"} +-doc_end + +-doc_begin="To avoid compromising readability, the macros alternative_(v)?call[0-9] are allowed +not to parenthesize their arguments." +-config=MC3R1.R20.7,reports+={safe, "any_area(any_loc(any_exp(macro(^alternative_(v)?call[0-9]$))))"} -doc_end -doc_begin="Uses of variadic macros that have one of their arguments defined as
docs/misra/deviations.rst +13 -1
@@ -345,7 +345,19 @@ Deviations related to MISRA C:2012 Rules: (1) as function arguments; (2) as macro arguments; (3) as array indices; - (4) as lhs in assignments. + (4) as lhs in assignments; + (5) as initializers, possibly designated, in initalizer lists. + - Tagged as `safe` for ECLAIR. + + * - R20.7 + - Violations due to the use of macros defined in files that are not + in scope for compliance are allowed, as that is imported code. + - Tagged as `safe` for ECLAIR. + + * - R20.7 + - To avoid compromising readability, the macros `alternative_(v)?call[0-9]` + are allowed not to parenthesize their arguments, as there are already + sanity checks in place. - Tagged as `safe` for ECLAIR. * - R20.12
docs/misra/rules.rst +1 -1
@@ -560,7 +560,7 @@ maintainers if you want to suggest a change. shall be enclosed in parentheses - Extra parentheses are not required when macro parameters are used as function arguments, as macro arguments, array indices, lhs in - assignments + assignments or as initializers in initalizer lists. * - `Rule 20.9 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_20_09.c>`_ - Required
Signature · 1 line
2.34.1
PATCH v3 6/7 xen/mm: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniMISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
--- xen/include/xen/mm.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
xen/include/xen/mm.h +7 -7
@@ -415,15 +415,15 @@ page_list_splice(struct page_list_head *list, struct page_list_head *head) }#define page_list_for_each (pos, head) \ - for ( pos = (head)->next; pos; pos = page_list_next(pos, head) ) + for ( (pos) = (head)->next; (pos); (pos) = page_list_next(pos, head) )#define page_list_for_each_safe (pos, tmp, head) \ - for ( pos = (head)->next; \ - pos ? (tmp = page_list_next(pos, head), 1) : 0; \ - pos = tmp ) + for ( (pos) = (head)->next; \ + (pos) ? ((tmp) = page_list_next(pos, head), 1) : 0; \ + (pos) = (tmp) )#define page_list_for_each_safe_reverse (pos, tmp, head) \ - for ( pos = (head)->tail; \ - pos ? (tmp = page_list_prev(pos, head), 1) : 0; \ - pos = tmp ) + for ( (pos) = (head)->tail; \ + (pos) ? ((tmp) = page_list_prev(pos, head), 1) : 0; \ + (pos) = (tmp) )#else # define page_list_head list_head# define PAGE_LIST_HEAD_INIT LIST_HEAD_INIT
Signature · 1 line
2.34.1
Re: [XEN PATCH v3 3/7] x86/vPMU: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniQuoted 9 lines · Nicola Vetrini
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
Signed-off-by Nicola Vetrini <[email protected]>
Re: [XEN PATCH v3 4/7] x86/hvm: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniQuoted 9 lines · Nicola Vetrini
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
Signed-off-by Nicola Vetrini <[email protected]>
albeit once again ...
xen/arch/x86/hvm/domain.c int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) · line 136
Quoted 11 lines
xen/arch/x86/hvm/domain.c +2
-3@@ -132,9 +132,9 @@ int arch_set_info_hvm_guest(struct vcpu *v, const struct vcpu_hvm_context *ctx) s = (struct segment_register ) \ { 0, { (r)->s ## _ar }, (r)->s ## _limit, (r)->s ## _base }; \/* Set accessed / busy bit for present segments. */ \ - if ( s.p ) \ - s.type |= (x86_seg_##s != x86_seg_tr ? 1 : 2); \ - check_segment(&s, x86_seg_ ## s); }) +if ( (s).p ) \ + (s).type |= (x86_seg_##s != x86_seg_tr ? 1 : 2); \
... addressing the style issue (blanks around ##) while touching code would have been nice.
Jan
Quoted 4 lines
xen/arch/x86/hvm/domain.c +1
-0+ check_segment(&(s), x86_seg_ ## s); }) rc =SEG (cs, regs); rc |=SEG (ds, regs);
Re: [XEN PATCH v3 6/7] xen/mm: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniQuoted 9 lines · Nicola Vetrini
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
Signed-off-by Nicola Vetrini <[email protected]>
Re: [XEN PATCH v3 7/7] x86/amd: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniQuoted 9 lines · Nicola Vetrini
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
Signed-off-by Nicola Vetrini <[email protected]>
Re: [XEN PATCH v3 1/7] x86/msi: address violation of MISRA C Rule 20.7 and coding style
In reply to Nicola VetriniQuoted 59 lines · Nicola Vetrini
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
While at it, the style of these macros has been somewhat uniformed.
No functional change.
Signed-off-by Nicola Vetrini <[email protected]>---
Changes in v2:
- Make the style change more consistent--- xen/arch/x86/include/asm/msi.h | 49 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-)xen/arch/x86/include/asm/msi.h +11
-19@@ -147,33 +147,34 @@ int msi_free_irq(struct msi_desc *entry);*/ #define NR_HP_RESERVED_VECTORS 20 -#define msi_control_reg (base) (base + PCI_MSI_FLAGS) -#define msi_lower_address_reg (base) (base + PCI_MSI_ADDRESS_LO) -#define msi_upper_address_reg (base) (base + PCI_MSI_ADDRESS_HI) -#define msi_data_reg (base, is64bit) \ - ( (is64bit == 1) ? base+PCI_MSI_DATA_64 : base+PCI_MSI_DATA_32 ) -#define msi_mask_bits_reg (base, is64bit) \ - ( (is64bit == 1) ? base+PCI_MSI_MASK_BIT : base+PCI_MSI_MASK_BIT-4) +#define msi_control_reg (base) ((base) + PCI_MSI_FLAGS) +#define msi_lower_address_reg (base) ((base) + PCI_MSI_ADDRESS_LO) +#define msi_upper_address_reg (base) ((base) + PCI_MSI_ADDRESS_HI) +#define msi_data_reg (base, is64bit) \ + (((is64bit) == 1) ? (base) + PCI_MSI_DATA_64 : (base) + PCI_MSI_DATA_32) +#define msi_mask_bits_reg (base, is64bit) \ + (((is64bit) == 1) ? (base) + PCI_MSI_MASK_BIT \ + : (base) + PCI_MSI_MASK_BIT - 4)#define msi_pending_bits_reg (base, is64bit) \ - ((base) + PCI_MSI_MASK_BIT + ((is64bit) ? 4 : 0)) -#define msi_disable (control) control &= ~PCI_MSI_FLAGS_ENABLE + ((base) + PCI_MSI_MASK_BIT + ((is64bit) ? 4 : 0)) +#define msi_disable (control) ({ (control) &= ~PCI_MSI_FLAGS_ENABLE })#define multi_msi_capable (control) \ - (1 << ((control & PCI_MSI_FLAGS_QMASK) >> 1)) + (1 << (((control) & PCI_MSI_FLAGS_QMASK) >> 1))#define multi_msi_enable (control, num) \ - control |= (((fls(num) - 1) << 4) & PCI_MSI_FLAGS_QSIZE); -#define is_64bit_address (control) (!!(control & PCI_MSI_FLAGS_64BIT)) -#define is_mask_bit_support (control) (!!(control & PCI_MSI_FLAGS_MASKBIT)) -#define msi_enable (control, num) multi_msi_enable(control, num); \ - control |= PCI_MSI_FLAGS_ENABLE - -#define msix_control_reg (base) (base + PCI_MSIX_FLAGS) -#define msix_table_offset_reg (base) (base + PCI_MSIX_TABLE) -#define msix_pba_offset_reg (base) (base + PCI_MSIX_PBA)
xen/arch/x86/include/asm/msi.h int msi_free_irq(struct msi_desc *entry); · line 168
Quoted 10 lines
xen/arch/x86/include/asm/msi.h +5
-5-#define msix_enable (control) control |= PCI_MSIX_FLAGS_ENABLE -#define msix_disable (control) control &= ~PCI_MSIX_FLAGS_ENABLE -#define msix_table_size (control) ((control & PCI_MSIX_FLAGS_QSIZE)+1) -#define msix_unmask (address) (address & ~PCI_MSIX_VECTOR_BITMASK) -#define msix_mask (address) (address | PCI_MSIX_VECTOR_BITMASK) + ({ (control) |= (((fls(num) - 1) << 4) & PCI_MSI_FLAGS_QSIZE) }) +#define is_64bit_address (control) (!!((control) & PCI_MSI_FLAGS_64BIT)) +#define is_mask_bit_support (control) (!!((control) & PCI_MSI_FLAGS_MASKBIT)) +#define msi_enable (control, num) ({ multi_msi_enable(control, num); \ + (control) |= PCI_MSI_FLAGS_ENABLE })
Neither this nor ...
xen/arch/x86/include/asm/msi.h int msi_free_irq(struct msi_desc *entry); · line 174
Quoted 5 lines
xen/arch/x86/include/asm/msi.h +5
-0+#define msix_control_reg (base) ((base) + PCI_MSIX_FLAGS) +#define msix_table_offset_reg (base) ((base) + PCI_MSIX_TABLE) +#define msix_pba_offset_reg (base) ((base) + PCI_MSIX_PBA) +#define msix_enable (control) ({ (control) |= PCI_MSIX_FLAGS_ENABLE }) +#define msix_disable (control) ({ (control) &= ~PCI_MSIX_FLAGS_ENABLE })
... these would compile afaict, if they were used.
Once again - before fiddling with these we need to settle on which of these we want to keep (and then also use, rather than open-coding), and which to drop (instead of massaging).
Jan
Re: [XEN PATCH v3 1/7] x86/msi: address violation of MISRA C Rule 20.7 and coding style
Quoted 92 lines · Jan Beulich
Quoted 71 lines · Nicola Vetrini
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
While at it, the style of these macros has been somewhat uniformed.
No functional change.
Signed-off-by Nicola Vetrini <[email protected]>---
Changes in v2:
- Make the style change more consistent--- xen/arch/x86/include/asm/msi.h | 49 +++++++++++++++++----------------- 1 file changed, 25 insertions(+), 24 deletions(-)xen/arch/x86/include/asm/msi.h +13
-24@@ -147,33 +147,34 @@ int msi_free_irq(struct msi_desc *entry);*/ #define NR_HP_RESERVED_VECTORS 20 -#define msi_control_reg (base) (base + PCI_MSI_FLAGS) -#define msi_lower_address_reg (base) (base + PCI_MSI_ADDRESS_LO) -#define msi_upper_address_reg (base) (base + PCI_MSI_ADDRESS_HI) -#define msi_data_reg (base, is64bit) \ - ( (is64bit == 1) ? base+PCI_MSI_DATA_64 : base+PCI_MSI_DATA_32 ) -#define msi_mask_bits_reg (base, is64bit) \ - ( (is64bit == 1) ? base+PCI_MSI_MASK_BIT : base+PCI_MSI_MASK_BIT-4) +#define msi_control_reg (base) ((base) + PCI_MSI_FLAGS) +#define msi_lower_address_reg (base) ((base) + PCI_MSI_ADDRESS_LO) +#define msi_upper_address_reg (base) ((base) + PCI_MSI_ADDRESS_HI) +#define msi_data_reg (base, is64bit) \ + (((is64bit) == 1) ? (base) + PCI_MSI_DATA_64 : (base) + PCI_MSI_DATA_32) +#define msi_mask_bits_reg (base, is64bit) \ + (((is64bit) == 1) ? (base) + PCI_MSI_MASK_BIT \ + : (base) + PCI_MSI_MASK_BIT - 4)#define msi_pending_bits_reg (base, is64bit) \ - ((base) + PCI_MSI_MASK_BIT + ((is64bit) ? 4 : 0)) -#define msi_disable (control) control &= ~PCI_MSI_FLAGS_ENABLE + ((base) + PCI_MSI_MASK_BIT + ((is64bit) ? 4 : 0)) +#define msi_disable (control) ({ (control) &= ~PCI_MSI_FLAGS_ENABLE })#define multi_msi_capable (control) \ - (1 << ((control & PCI_MSI_FLAGS_QMASK) >> 1)) + (1 << (((control) & PCI_MSI_FLAGS_QMASK) >> 1))#define multi_msi_enable (control, num) \ - control |= (((fls(num) - 1) << 4) & PCI_MSI_FLAGS_QSIZE); -#define is_64bit_address (control) (!!(control & PCI_MSI_FLAGS_64BIT)) -#define is_mask_bit_support (control) (!!(control & PCI_MSI_FLAGS_MASKBIT)) -#define msi_enable (control, num) multi_msi_enable(control, num); \ - control |= PCI_MSI_FLAGS_ENABLE - -#define msix_control_reg (base) (base + PCI_MSIX_FLAGS) -#define msix_table_offset_reg (base) (base + PCI_MSIX_TABLE) -#define msix_pba_offset_reg (base) (base + PCI_MSIX_PBA) -#define msix_enable (control) control |= PCI_MSIX_FLAGS_ENABLE -#define msix_disable (control) control &= ~PCI_MSIX_FLAGS_ENABLE -#define msix_table_size (control) ((control & PCI_MSIX_FLAGS_QSIZE)+1) -#define msix_unmask (address) (address & ~PCI_MSIX_VECTOR_BITMASK) -#define msix_mask (address) (address | PCI_MSIX_VECTOR_BITMASK) + ({ (control) |= (((fls(num) - 1) << 4) & PCI_MSI_FLAGS_QSIZE) }) +#define is_64bit_address (control) (!!((control) &Quoted 7 lines
PCI_MSI_FLAGS_64BIT))
+#defineis_mask_bit_support(control)(!!((control) &PCI_MSI_FLAGS_MASKBIT))
+#definemsi_enable(control, num)({ multi_msi_enable(control,
num); \
+ (control) |=PCI_MSI_FLAGS_ENABLE})Neither this nor ...
Quoted 7 lines
xen/arch/x86/include/asm/msi.h +4
-0+#define msix_control_reg (base) ((base) + PCI_MSIX_FLAGS) +#define msix_table_offset_reg (base) ((base) + PCI_MSIX_TABLE) +#define msix_pba_offset_reg (base) ((base) + PCI_MSIX_PBA) +#define msix_enable (control) ({ (control) |=
PCI_MSIX_FLAGS_ENABLE})
+#definemsix_disable(control)({ (control) &=
~PCI_MSIX_FLAGS_ENABLE })... these would compile afaict, if they were used.
Quoted 5 lines
Once again - before fiddling with these we need to settle on which of these we want to keep (and then also use, rather than open-coding), and which to drop (instead of massaging).
Jan
Ok, we can drop this patch from this for now.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH v3 2/7] arm/public: address violations of MISRA C Rule 20.7
In reply to Nicola VetriniQuoted 9 lines · Nicola Vetrini
MISRA C Rule 20.7 states: "Expressions resulting from the expansion of macro parameters shall be enclosed in parentheses". Therefore, some macro definitions should gain additional parentheses to ensure that all current and future users will be safe with respect to expansions that can possibly alter the semantics of the passed-in macro parameter.
No functional change.
Signed-off-by Nicola Vetrini <[email protected]>
Quoted 20 lines
--- xen/include/public/arch-arm.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/include/public/arch-arm.h +1
-1@@ -209,7 +209,7 @@do { \ __typeof__(&(hnd)) _sxghr_tmp = &(hnd); \ _sxghr_tmp->q =0 ; \ - _sxghr_tmp->p = val; \ + _sxghr_tmp->p = (val); \ } while ( 0 )#define set_xen_guest_handle (hnd, val) set_xen_guest_handle_raw(hnd, val)Signature · 1 line
2.34.1
Re: [XEN PATCH v3 5/7] automation/eclair: add deviations for Rule 20.7
In reply to Nicola VetriniQuoted 11 lines · Nicola Vetrini
These deviations deal with the following cases:
- macro arguments used directly as initializer list arguments;
- uses of the__config_enabledmacro, that can't be brought into compliance without breaking its functionality;
- exclude files that are out of scope (efi headers andcpu_idle);
- uses of alternative_{call,vcall}[0-9] macros.The existing configuration for R20.7 is reordered so that it matches the cases listed in its documentation comment.
Signed-off-by Nicola Vetrini <[email protected]>
Re: [XEN PATCH v3 5/7] automation/eclair: add deviations for Rule 20.7
In reply to Nicola VetriniQuoted 11 lines · Nicola Vetrini
These deviations deal with the following cases:
- macro arguments used directly as initializer list arguments;
- uses of the__config_enabledmacro, that can't be brought into compliance without breaking its functionality;
- exclude files that are out of scope (efi headers andcpu_idle);
- uses of alternative_{call,vcall}[0-9] macros.The existing configuration for R20.7 is reordered so that it matches the cases listed in its documentation comment.
Signed-off-by Nicola Vetrini <[email protected]>
Quoted 87 lines
--- .../eclair_analysis/ECLAIR/deviations.ecl | 25 +++++++++++++++++-- docs/misra/deviations.rst | 14 ++++++++++- docs/misra/rules.rst | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-)automation/eclair_analysis/ECLAIR/deviations.ecl +23
-2@@ -401,12 +401,33 @@ unexpected result when the structure is given as argument to a sizeof() operator -doc_begin="Code violating Rule 20.7 is safe when macro parameters are used: (1) as function arguments; (2) as macro arguments; (3) as array indices; (4) as lhs -in assignments." +in assignments; (5) as initializers, possibly designated, in initalizer lists." -config=MC3R1.R20.7,expansion_context= {safe, "context(__call_expr_arg_contexts)"}, +{safe, "left_right(^[(,\\[]$,^[),\\]]$)"}, {safe, "context(skip_to(__expr_non_syntactic_contexts, stmt_child(node(array_subscript_expr), subscript)))"}, {safe, "context(skip_to(__expr_non_syntactic_contexts, stmt_child(operator(assign), lhs)))"}, -{safe, "left_right(^[(,\\[]$,^[),\\]]$)"} +{safe, "context(skip_to(__expr_non_syntactic_contexts, stmt_child(node(init_list_expr||designated_init_expr), init)))"} +-doc_end + +-doc_begin="Violations involving the __config_enabled macros cannot be fixed without +breaking the macro's logic; futhermore, the macro is only ever used in the context +of the IS_ENABLED or STATIC_IF/STATIC_IF_NOT macros, so it always receives a literal +0 or 1 as input, posing no risk to safety." +-config=MC3R1.R20.7,reports+={safe, "any_area(any_loc(any_exp(macro(^___config_enabled$))))"} +-doc_end + +-doc_begin="Violations due to the use of macros defined in files that are +not in scope for compliance are allowed, as that is imported code." +-file_tag+={gnu_efi_include, "^xen/include/efi/.*$"} +-file_tag+={acpi_cpu_idle, "^xen/arch/x86/acpi/cpu_idle\\.c$"} +-config=MC3R1.R20.7,reports+={safe, "any_area(any_loc(file(gnu_efi_include)))"} +-config=MC3R1.R20.7,reports+={safe, "any_area(any_loc(file(acpi_cpu_idle)))"} +-doc_end + +-doc_begin="To avoid compromising readability, the macros alternative_(v)?call[0-9] are allowed +not to parenthesize their arguments." +-config=MC3R1.R20.7,reports+={safe, "any_area(any_loc(any_exp(macro(^alternative_(v)?call[0-9]$))))"} -doc_end -doc_begin="Uses of variadic macros that have one of their arguments defined asdocs/misra/deviations.rst +13
-1@@ -345,7 +345,19 @@ Deviations related to MISRA C:2012 Rules: (1) as function arguments; (2) as macro arguments; (3) as array indices; - (4) as lhs in assignments. + (4) as lhs in assignments; + (5) as initializers, possibly designated, in initalizer lists. + - Tagged as `safe` for ECLAIR. + + * - R20.7 + - Violations due to the use of macros defined in files that are not + in scope for compliance are allowed, as that is imported code. + - Tagged as `safe` for ECLAIR. + + * - R20.7 + - To avoid compromising readability, the macros `alternative_(v)?call[0-9]` + are allowed not to parenthesize their arguments, as there are already + sanity checks in place. - Tagged as `safe` for ECLAIR. * - R20.12docs/misra/rules.rst +1
-1@@ -560,7 +560,7 @@ maintainers if you want to suggest a change. shall be enclosed in parentheses - Extra parentheses are not required when macro parameters are used as function arguments, as macro arguments, array indices, lhs in - assignments + assignments or as initializers in initalizer lists. * - `Rule 20.9 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_20_09.c>`_ - RequiredSignature · 1 line
2.34.1