address violations of MISRA C rules
cover address violations of MISRA C rules
Patches 1 to 4 address violations of MISRA C Rule 20.12 by deviating certain uses of some macros, while the last patch addresses some regressions introduced by the latest bitops series
Nicola Vetrini (5):
xen/domain: deviate violation of MISRA C Rule 20.12 x86/domain: deviate violation of MISRA C Rule 20.12
x86: deviate violation of MISRA C Rule 20.12 automation/eclair_analysis: address remaining violations of MISRA C
Rule 20.12
xen: fix MISRA regressions on rule 20.9 and 20.12
automation/eclair_analysis/ECLAIR/deviations.ecl | 8 +++++++- docs/misra/safe.json | 8 ++++++++ xen/arch/x86/domain.c | 1 + xen/arch/x86/domctl.c | 1 + xen/arch/x86/include/asm/shared.h | 1 + xen/common/domain.c | 1 + xen/include/xen/self-tests.h | 2 +- 7 files changed, 20 insertions(+), 2 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/5 xen/domain: deviate violation of MISRA C Rule 20.12
MISRA C Rule 20.12 states: "A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators".
In this case, builds where CONFIG_DEBUG_LOCK_PROFILE=y the domain_lock macro is used both as a regular macro argument and as an operand for stringification in the expansion of macro spin_lock_init_prof. A SAF-x-safe deviation is introduced to justify this.
No functional change.
--- docs/misra/safe.json | 8 ++++++++ xen/common/domain.c | 1 + 2 files changed, 9 insertions(+)
docs/misra/safe.json +8 -0
@@ -52,6 +52,14 @@ }, { "id": "SAF-6-safe", + "analyser": { + "eclair": "MC3R1.R20.12" + }, + "name": "MC3R1.R20.12: use of a macro argument that deliberately violates the Rule", + "text": "A macro parameter that is itself a macro is intentionally used within the macro both as a regular parameter and for text replacement." + }, + { + "id": "SAF-7-safe", "analyser": {}, "name": "Sentinel", "text": "Next ID to be used"
xen/common/domain.c +1 -0
@@ -632,6 +632,7 @@ struct domain *domain_create(domid_t domid,atomic_set (&d->refcnt,1 );RCU_READ_LOCK_INIT (&d->rcu_lock); +/* SAF-6-safe Rule 20.12 expansion of macro domain_lock in debug builds */ rspin_lock_init_prof (d, domain_lock);rspin_lock_init_prof (d, page_alloc_lock);spin_lock_init (&d->hypercall_deadlock_mutex);
Signature · 1 line
2.34.1
Re: [XEN PATCH 1/5] xen/domain: deviate violation of MISRA C Rule 20.12
Quoted 7 lines · Nicola Vetrini
MISRA C Rule 20.12 states: "A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators".
In this case, builds where
CONFIG_DEBUG_LOCK_PROFILE=ythedomain_lockmacro is used both as a regular macro argument and as an operand for stringification in the expansion of macrospin_lock_init_prof.
The shouldn't the marker be on the definition of spin_lock_init_prof(), rather than ...
xen/common/domain.c struct domain *domain_create(domid_t domid, · line 638
Quoted 10 lines
xen/common/domain.c +1
-0@@ -632,6 +632,7 @@ struct domain *domain_create(domid_t domid,atomic_set (&d->refcnt,1 );RCU_READ_LOCK_INIT (&d->rcu_lock); +/* SAF-6-safe Rule 20.12 expansion of macro domain_lock in debug builds */ rspin_lock_init_prof (d, domain_lock);rspin_lock_init_prof (d, page_alloc_lock);spin_lock_init (&d->hypercall_deadlock_mutex);
... actually just one of the two uses here (and presumably several more elsewhere)?
Jan
Re: [XEN PATCH 1/5] xen/domain: deviate violation of MISRA C Rule 20.12
Quoted 27 lines · Jan Beulich
Quoted 7 lines · Nicola Vetrini
MISRA C Rule 20.12 states: "A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators".
In this case, builds where
CONFIG_DEBUG_LOCK_PROFILE=ythedomain_lockmacro is used both as a regular macro argument and as an operand for stringification in the expansion of macrospin_lock_init_prof.The shouldn't the marker be on the definition of
spin_lock_init_prof(), rather than ...Quoted 11 lines
xen/common/domain.c +1
-0@@ -632,6 +632,7 @@ struct domain *domain_create(domid_t domid,atomic_set (&d->refcnt,1 );RCU_READ_LOCK_INIT (&d->rcu_lock); +/* SAF-6-safe Rule 20.12 expansion of macro domain_lock in debug builds */
rspin_lock_init_prof(d, domain_lock); rspin_lock_init_prof(d, page_alloc_lock); spin_lock_init(&d->hypercall_deadlock_mutex);... actually just one of the two uses here (and presumably several more elsewhere)?
Quoted 1 line
Jan
Actually it seems that this violation went away with some refactorings, so this patch is no longer needed other than for the addition to safe.json, so it can be folded into the next one. I'll make the adjustment.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
PATCH 2/5 x86/domain: deviate violation of MISRA C Rule 20.12
In reply to Nicola VetriniMISRA C Rule 20.12 states: "A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators".
In this case, builds where CONFIG_COMPAT=y the fpu_ctxt macro is used both as a regular macro argument and as an operand for stringification in the expansion of CHECK_FIELD_.
This is deviated using a SAF-x-safe comment.
No functional change.
--- xen/arch/x86/domain.c | 1 + xen/arch/x86/domctl.c | 1 + 2 files changed, 2 insertions(+)
xen/arch/x86/domain.c +1 -0
@@ -1084,6 +1084,7 @@ void arch_domain_creation_finished(struct domain *d)#ifdef CONFIG_COMPAT #define xen_vcpu_guest_context vcpu_guest_context#define fpu_ctxt fpu_ctxt.x +/* SAF-6-safe Rule 20.12 expansion of macro fpu_ctxt with CONFIG_COMPAT */ CHECK_FIELD_ (struct, vcpu_guest_context, fpu_ctxt);#undef fpu_ctxt#undef xen_vcpu_guest_context
xen/arch/x86/domctl.c +1 -0
@@ -1326,6 +1326,7 @@ long arch_do_domctl(#ifdef CONFIG_COMPAT #define xen_vcpu_guest_context vcpu_guest_context#define fpu_ctxt fpu_ctxt.x +/* SAF-6-safe Rule 20.12 expansion of macro fpu_ctxt with CONFIG_COMPAT */ CHECK_FIELD_ (struct, vcpu_guest_context, fpu_ctxt);#undef fpu_ctxt#undef xen_vcpu_guest_context
Signature · 1 line
2.34.1
Re: [XEN PATCH 2/5] x86/domain: deviate violation of MISRA C Rule 20.12
Quoted 4 lines · Nicola Vetrini
MISRA C Rule 20.12 states: "A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators".
Quoted 8 lines
In this case, builds where
CONFIG_COMPAT=ythefpu_ctxtmacro is used both as a regular macro argument and as an operand for stringification in the expansion ofCHECK_FIELD_.
This is deviated using a SAF-x-safe comment.No functional change.
Signed-off-by Nicola Vetrini <[email protected]>
At least for the time being; plans that Andrew vaguely described my render this unnecessary down the road.
Jan
Quoted 22 lines
xen/arch/x86/domain.c +1
-0@@ -1084,6 +1084,7 @@ void arch_domain_creation_finished(struct domain *d)#ifdef CONFIG_COMPAT #define xen_vcpu_guest_context vcpu_guest_context#define fpu_ctxt fpu_ctxt.x +/* SAF-6-safe Rule 20.12 expansion of macro fpu_ctxt with CONFIG_COMPAT */ CHECK_FIELD_ (struct, vcpu_guest_context, fpu_ctxt);#undef fpu_ctxt#undef xen_vcpu_guest_contextxen/arch/x86/domctl.c +1
-0@@ -1326,6 +1326,7 @@ long arch_do_domctl(#ifdef CONFIG_COMPAT #define xen_vcpu_guest_context vcpu_guest_context#define fpu_ctxt fpu_ctxt.x +/* SAF-6-safe Rule 20.12 expansion of macro fpu_ctxt with CONFIG_COMPAT */ CHECK_FIELD_ (struct, vcpu_guest_context, fpu_ctxt);#undef fpu_ctxt#undef xen_vcpu_guest_context
PATCH 3/5 x86: deviate violation of MISRA C Rule 20.12
In reply to Nicola VetriniMISRA C Rule 20.12 states: "A macro parameter used as an operand to the # or ## operators, which is itself subject to further macro replacement, shall only be used as an operand to these operators".
When the second parameter of GET_SET_SHARED is a macro and is used as both a regular parameter and for token pasting the rule deliberately violated. A SAF-x-safe comment is used to deviate the usage.
No functional change.
--- xen/arch/x86/include/asm/shared.h | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/include/asm/shared.h +1 -0
@@ -76,6 +76,7 @@ static inline void arch_set_##field(struct vcpu *v, \ GET_SET_SHARED(unsigned long, max_pfn) GET_SET_SHARED(xen_pfn_t, pfn_to_mfn_frame_list_list) +/* SAF-6-safe Rule 20.12: expansion of macro nmi_reason */ GET_SET_SHARED(unsigned long, nmi_reason) GET_SET_VCPU(unsigned long, cr2)
Signature · 1 line
2.34.1
Re: [XEN PATCH 3/5] x86: deviate violation of MISRA C Rule 20.12
xen/arch/x86/include/asm/shared.h static inline void arch_set_##field(struct vcpu *v, \ · line 80
Quoted 8 lines · Nicola Vetrini
xen/arch/x86/include/asm/shared.h +1
-0@@ -76,6 +76,7 @@ static inline void arch_set_##field(struct vcpu *v, \ GET_SET_SHARED(unsigned long, max_pfn) GET_SET_SHARED(xen_pfn_t, pfn_to_mfn_frame_list_list) +/* SAF-6-safe Rule 20.12: expansion of macro nmi_reason */ GET_SET_SHARED(unsigned long, nmi_reason)
Before we go this route, were alternatives at least considered? Plus didn't we special-case function-like macros already, when used in situations where only object-like macros would be expanded anyway?
As to alternatives: nmi_reason() is used in exactly one place. Dropping the #define and expanding the one use instead would be an option. I further wonder whether moving the #define-s past the piece of code you actually modify would also be an option (i.e. the tool then no longer complaining).
Jan
Re: [XEN PATCH 3/5] x86: deviate violation of MISRA C Rule 20.12
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Nicola Vetrini
xen/arch/x86/include/asm/shared.h +0
-0@@ -76,6 +76,7 @@ static inline void arch_set_##field(struct vcpu *v, \
Quoted 9 lines
xen/arch/x86/include/asm/shared.h static inline void arch_set_##field(struct vcpu *v, \ · line 80
Quoted 4 lines
xen/arch/x86/include/asm/shared.h +1
-0GET_SET_SHARED(unsigned long, max_pfn) GET_SET_SHARED(xen_pfn_t, pfn_to_mfn_frame_list_list) +/* SAF-6-safe Rule 20.12: expansion of macro nmi_reason */ GET_SET_SHARED(unsigned long, nmi_reason)Before we go this route, were alternatives at least considered? Plus didn't we special-case function-like macros already, when used in situations where only object-like macros would be expanded anyway?
It may be the case that this is already deviated, hence meaning that the patch can be dropped: I'll recheck.
In that case, thanks for pointing this out.
Quoted 7 lines
As to alternatives:
nmi_reason()is used in exactly one place. Dropping the #define and expanding the one use instead would be an option. I further wonder whether moving the #define-s past the piece of code you actually modify would also be an option (i.e. the tool then no longer complaining).Jan
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
PATCH 4/5 automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
In reply to Nicola VetriniThe DEFINE macro in asm-offsets.c (for all architectures) still generates violations despite the file(s) being excluded from compliance, due to the fact that in its expansion it sometimes refers entities in non-excluded files. These corner cases are deviated by the configuration.
No functional change.
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++ 1 file changed, 6 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +6 -0
@@ -483,6 +483,12 @@ leads to a violation of the Rule are deviated." -config=MC3R1.R20.12,macros+={deliberate, "name(GENERATE_CASE)&&loc(file(deliberate_generate_case))"} -doc_end +-doc_begin="The macro DEFINE is defined and used in excluded files asm-offsets.c. +This may still cause violations if entities outside these files are referred to +in the expansion." +-config=MC3R1.R20.12,macros+={deliberate, "name(DEFINE)&&loc(file(asm_offsets))"} +-doc_end + # # Series 21. #
Signature · 1 line
2.34.1
Re: [XEN PATCH 4/5] automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
automation/eclair_analysis/ECLAIR/deviations.ecl leads to a violation of the Rule are deviated." · line 490
Quoted 11 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +5
-0@@ -483,6 +483,12 @@ leads to a violation of the Rule are deviated." -config=MC3R1.R20.12,macros+={deliberate, "name(GENERATE_CASE)&&loc(file(deliberate_generate_case))"} -doc_end +-doc_begin="The macro DEFINE is defined and used in excluded files asm-offsets.c. +This may still cause violations if entities outside these files are referred to +in the expansion." +-config=MC3R1.R20.12,macros+={deliberate, "name(DEFINE)&&loc(file(asm_offsets))"} +-doc_end
Can you give an example of such a reference? Nothing _in_ asm-offsets.c should be referenced, I'd think. Only stuff in asm-offsets.h as _generated from_ asm-offsets.c will, of course, be.
Jan
Re: [XEN PATCH 4/5] automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -483,6 +483,12 @@ leads to a violation of the Rule are deviated." -config=MC3R1.R20.12,macros+={deliberate, "name(GENERATE_CASE)&&loc(file(deliberate_generate_case))"} -doc_end
Quoted 13 lines
Quoted 8 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+-doc_begin="The macro DEFINE is defined and used in excluded files
asm-offsets.c.
+This may still cause violations if entities outside these files are referred to
+in the expansion." +-config=MC3R1.R20.12,macros+={deliberate, "name(DEFINE)&&loc(file(asm_offsets))"}
+-doc_endCan you give an example of such a reference? Nothing _in_
asm-offsets.cshould be referenced, I'd think. Only stuff inasm-offsets.has_generatedfrom_asm-offsets.cwill, of course, be.
Perhaps I could have expressed that more clearly. What I meant is that there are some arguments to DEFINE that are not part of asm-offsets.c, therefore they end up in the violation report, but are not actually relevant, because the macro DEFINE is actually what we want to exclude.
See for instance at the link below VCPU_TRAP_{NMI,MCE}, which are defined in asm/domain.h and used as arguments to DEFINE inside asm-offsets.c.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH 4/5] automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
Quoted 29 lines · Nicola Vetrini
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -483,6 +483,12 @@ leads to a violation of the Rule are deviated." -config=MC3R1.R20.12,macros+={deliberate, "name(GENERATE_CASE)&&loc(file(deliberate_generate_case))"} -doc_endQuoted 14 lines
Quoted 8 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+-doc_begin="The macro DEFINE is defined and used in excluded files
asm-offsets.c.
+This may still cause violations if entities outside these files are referred to
+in the expansion." +-config=MC3R1.R20.12,macros+={deliberate, "name(DEFINE)&&loc(file(asm_offsets))"}
+-doc_endCan you give an example of such a reference? Nothing _in_
asm-offsets.cshould be referenced, I'd think. Only stuff inasm-offsets.has_generatedfrom_asm-offsets.cwill, of course, be.Perhaps I could have expressed that more clearly. What I meant is that there are some arguments to DEFINE that are not part of
asm-offsets.c, therefore they end up in the violation report, but are not actually relevant, because the macro DEFINE is actually what we want to exclude.
Quoted 5 lines
See for instance at the link below VCPU_TRAP_{NMI,MCE}, which are defined in
asm/domain.hand used as arguments to DEFINE insideasm-offsets.c.
I'm afraid I still don't understand: The file being supposed to be excluded from scanning, why does it even show up in that report?
Jan
Re: [XEN PATCH 4/5] automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
Quoted 34 lines · Jan Beulich
Quoted 33 lines · Nicola Vetrini
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -483,6 +483,12 @@ leads to a violation of the Rule are deviated." -config=MC3R1.R20.12,macros+={deliberate, "name(GENERATE_CASE)&&loc(file(deliberate_generate_case))"} -doc_endQuoted 14 lines
Quoted 8 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+-doc_begin="The macro DEFINE is defined and used in excluded files
asm-offsets.c.
+This may still cause violations if entities outside these files are referred to
+in the expansion." +-config=MC3R1.R20.12,macros+={deliberate, "name(DEFINE)&&loc(file(asm_offsets))"}
+-doc_endCan you give an example of such a reference? Nothing _in_
asm-offsets.cshould be referenced, I'd think. Only stuff inasm-offsets.has_generatedfrom_asm-offsets.cwill, of course, be.Perhaps I could have expressed that more clearly. What I meant is that there are some arguments to DEFINE that are not part of
asm-offsets.c, therefore they end up in the violation report, but are not actually relevant, because the macro DEFINE is actually what we want to exclude.See for instance at the link below VCPU_TRAP_{NMI,MCE}, which are defined in
asm/domain.hand used as arguments to DEFINE insideasm-offsets.c.
Quoted 6 lines
I'm afraid I still don't understand: The file being supposed to be excluded from scanning, why does it even show up in that report?
Jan
The report is made up of several source code locations. Three of them are within asm-offsets.c, which is excluded from compliance but still analyzed, but one references a macro definition in another file (e.g., VCPU_TRAP_NMI from asm/domain.h). So in this case the exclusion of asm-offsets.c is not enough for the report not to be shown.
The configuration is telling the tool that the macro DEFINE from asm-offsets is meant to be deviated, which is what is needed in this case.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH 4/5] automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
Quoted 39 lines · Nicola Vetrini
Quoted 38 lines · Jan Beulich
Quoted 36 lines · Nicola Vetrini
Quoted 8 lines · Jan Beulich
Quoted 7 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -483,6 +483,12 @@ leads to a violation of the Rule are deviated." -config=MC3R1.R20.12,macros+={deliberate, "name(GENERATE_CASE)&&loc(file(deliberate_generate_case))"} -doc_endQuoted 15 lines
Quoted 8 lines
automation/eclair_analysis/ECLAIR/deviations.ecl +1
-0+-doc_begin="The macro DEFINE is defined and used in excluded files
asm-offsets.c.
+This may still cause violations if entities outside these files are referred to
+in the expansion." +-config=MC3R1.R20.12,macros+={deliberate, "name(DEFINE)&&loc(file(asm_offsets))"}
+-doc_endCan you give an example of such a reference? Nothing _in_
asm-offsets.c
should be referenced, I'd think. Only stuff inasm-offsets.has_generatedfrom_asm-offsets.cwill, of course, be.Perhaps I could have expressed that more clearly. What I meant is that there are some arguments to DEFINE that are not part of
asm-offsets.c, therefore they end up in the violation report, but are not actually relevant, because the macro DEFINE is actually what we want to exclude.See for instance at the link below VCPU_TRAP_{NMI,MCE}, which are defined in
asm/domain.hand used as arguments to DEFINE insideasm-offsets.c.
Quoted 8 lines
Quoted 2 lines
I'm afraid I still don't understand: The file being supposed to be excluded from scanning, why does it even show up in that report?
The report is made up of several source code locations. Three of them are within
asm-offsets.c, which is excluded from compliance but still analyzed, but one references a macro definition in another file (e.g.,VCPU_TRAP_NMIfromasm/domain.h). So in this case the exclusion ofasm-offsets.cis not enough for the report not to be shown.
But the (would-be-)violation is in asm-offsets.c. The other locations pointed at are providing context. To report a violation, it should be enough to exclude the file where the violation itself is?
Jan
Re: [XEN PATCH 4/5] automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
Quoted 52 lines · Jan Beulich
Quoted 42 lines · Nicola Vetrini
Quoted 41 lines · Jan Beulich
Quoted 39 lines · Nicola Vetrini
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Nicola Vetrini
automation/eclair_analysis/ECLAIR/deviations.ecl +0
-0@@ -483,6 +483,12 @@ leads to a violation of the Rule aredeviated."
-config=MC3R1.R20.12,macros+={deliberate,
"name(GENERATE_CASE)&&loc(file(deliberate_generate_case))"}
-doc_endQuoted 17 lines
Quoted 10 lines
+-doc_begin="The macro DEFINE is defined and used in excluded files
asm-offsets.c.
+This may still cause violations if entities outside these files are
referred to
+in the expansion." +-config=MC3R1.R20.12,macros+={deliberate, "name(DEFINE)&&loc(file(asm_offsets))"}
+-doc_endCan you give an example of such a reference? Nothing _in_
asm-offsets.c
should be referenced, I'd think. Only stuff inasm-offsets.has_generatedfrom_asm-offsets.cwill, of course, be.Perhaps I could have expressed that more clearly. What I meant is that there are some arguments to DEFINE that are not part of
asm-offsets.c, therefore they end up in the violation report, but are not actually relevant, because the macro DEFINE is actually what we want to exclude.See for instance at the link below VCPU_TRAP_{NMI,MCE}, which are defined in
asm/domain.hand used as arguments to DEFINE insideasm-offsets.c.Quoted 8 lines
Quoted 2 lines
I'm afraid I still don't understand: The file being supposed to be excluded from scanning, why does it even show up in that report?
The report is made up of several source code locations. Three of them are within
asm-offsets.c, which is excluded from compliance but still analyzed, but one references a macro definition in another file (e.g.,VCPU_TRAP_NMIfromasm/domain.h). So in this case the exclusion ofasm-offsets.cis not enough for the report not to be shown.
Quoted 4 lines
But the (would-be-)violation is in
asm-offsets.c. The other locations pointed at are providing context. To report a violation, it should be enough to exclude the file where the violation itself is?
In general that may not be the safest choice, or it can limit the granularity of the configuration (not in the specific case, but the mechanism is general). It's a design aspect of the tool to show a report unless all its locations are not meant to be shown.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH 4/5] automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
In reply to Nicola VetriniQuoted 8 lines · Nicola Vetrini
The DEFINE macro in
asm-offsets.c(for all architectures) still generates violations despite the file(s) being excluded from compliance, due to the fact that in its expansion it sometimes refers entities in non-excluded files. These corner cases are deviated by the configuration.No functional change.
Signed-off-by Nicola Vetrini <[email protected]>
PATCH 5/5 xen: fix MISRA regressions on rule 20.9 and 20.12
In reply to Nicola Vetriniea59e7d780d9 ("xen/bitops: Cleanup and new infrastructure ahead of rearrangements") introduced new violations on previously clean rules 20.9 and 20.12.
The first is introduced because CONFIG_CC_IS_CLANG in xen/self-tests.h is not defined in the configuration under analysis. Using "defined()" instead avoids relying on the preprocessor's behaviour upon encountering an undedfined identifier and addresses the violation.
The violation of Rule 20.12 is due to "val" being used both as an ordinary argument in macro RUNTIME_CHECK, and as a stringification operator.
No functional change.
--- automation/eclair_analysis/ECLAIR/deviations.ecl | 2 +- xen/include/xen/self-tests.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
automation/eclair_analysis/ECLAIR/deviations.ecl +1 -1
@@ -473,7 +473,7 @@ deliberate." -doc_begin="Uses of a macro parameter for ordinary expansion and as an operand to the # or ## operators within the following macros are deliberate, to provide useful diagnostic messages to the user." --config=MC3R1.R20.12,macros+={deliberate, "name(ASSERT||BUILD_BUG_ON||BUILD_BUG_ON_ZERO)"} +-config=MC3R1.R20.12,macros+={deliberate, "name(ASSERT||BUILD_BUG_ON||BUILD_BUG_ON_ZERO||RUNTIME_CHECK)"} -doc_end -doc_begin="The helper macro GENERATE_CASE may use a macro parameter for ordinary
xen/include/xen/self-tests.h +1 -1
@@ -16,7 +16,7 @@* Clang < 8 can't fold constants through static inlines, causing this to * fail. Simply skip it for incredibly old compilers. */ -#if !CONFIG_CC_IS_CLANG ||CONFIG_CLANG_VERSION >=80000 +#if !defined(CONFIG_CC_IS_CLANG ) ||CONFIG_CLANG_VERSION >=80000 #define COMPILE_CHECK (fn, val, res) \ do { \ typeof(fn(val)) real = fn(val); \
Signature · 1 line
2.34.1
Re: [XEN PATCH 5/5] xen: fix MISRA regressions on rule 20.9 and 20.12
Quoted 8 lines · Nicola Vetrini
ea59e7d780d9("xen/bitops: Cleanup and new infrastructure ahead of rearrangements") introduced new violations on previously clean rules 20.9 and 20.12.The first is introduced because
CONFIG_CC_IS_CLANGinxen/self-tests.his not defined in the configuration under analysis. Using "defined()" instead avoids relying on the preprocessor's behaviour upon encountering an undedfined identifier and addresses the violation.
Quoted 7 lines
The violation of Rule 20.12 is due to "val" being used both as an ordinary argument in macro
RUNTIME_CHECK, and as a stringification operator.No functional change.
Fixes ea59e7d780d9 ("xen/bitops: Cleanup and new infrastructure ahead of rearrangements")Signed-off-by Nicola Vetrini <[email protected]>
Thankyou for this patch. I'd seen that I'd broken something. (Entirely my fault - I've done a lot of testing in Gitlab for the series, but never manually ran the Eclair jobs. I'll try to remember better next time.)
One question though.
https://gitlab.com/xen-project/xen/-/jobs/6994213979 says:
Failure: 1 regressions found for clean guidelines service MC3R1.R20.9: (required) All identifiers used in the controlling expression of #if' or #elif' preprocessing directives shall be #define'd before evaluation:
violation: 1
While there is a report for 20.12, it's not clean yet (so the first sentence wants adjusting), and RUNTIME_CHECK doesn't show up newly in it.
So, while I agree that RUNTIME_CHECK() should be included in the 20.12 exclusions, why is current Gitlab Run not reporting it?
~Andrew
Re: [XEN PATCH 5/5] xen: fix MISRA regressions on rule 20.9 and 20.12
Quoted 30 lines · Andrew Cooper
Quoted 8 lines · Nicola Vetrini
ea59e7d780d9("xen/bitops: Cleanup and new infrastructure ahead of rearrangements") introduced new violations on previously clean rules 20.9 and 20.12.The first is introduced because
CONFIG_CC_IS_CLANGinxen/self-tests.his not defined in the configuration under analysis. Using "defined()" instead avoids relying on the preprocessor's behaviour upon encountering an undedfined identifier and addresses the violation.Quoted 7 lines
The violation of Rule 20.12 is due to "val" being used both as an ordinary argument in macro
RUNTIME_CHECK, and as a stringification operator.No functional change.
Fixes ea59e7d780d9 ("xen/bitops: Cleanup and new infrastructure ahead of rearrangements")Signed-off-by Nicola Vetrini <[email protected]>Thankyou for this patch. I'd seen that I'd broken something. (Entirely my fault - I've done a lot of testing in Gitlab for the series, but never manually ran the Eclair jobs. I'll try to remember better next time.)
One question though.
https://gitlab.com/xen-project/xen/-/jobs/6994213979 says:Failure: 1 regressions found for clean guidelines service MC3R1.R20.9: (required) All identifiers used in the controlling expression of
#if' or#elif' preprocessing directives shall be #define'd before evaluation:
violation: 1
Quoted 7 lines
While there is a report for 20.12, it's not clean yet (so the first sentence wants adjusting), and
RUNTIME_CHECKdoesn't show up newly in it.So, while I agree that
RUNTIME_CHECK()should be included in the 20.12 exclusions, why is current Gitlab Run not reporting it?~Andrew
While Rule 20.12 wasn't clean on x86, but it was on arm, so in the arm64 run it is reported as such
https://gitlab.com/xen-project/xen/-/jobs/6994213980
with the other patches in the series the rule should be clean on both architectures, so this imbalance should disappear rather shortly.
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH 5/5] xen: fix MISRA regressions on rule 20.9 and 20.12
Quoted 47 lines · Nicola Vetrini
Quoted 37 lines · Andrew Cooper
Quoted 16 lines · Nicola Vetrini
ea59e7d780d9("xen/bitops: Cleanup and new infrastructure ahead of rearrangements")
introduced new violations on previously clean rules 20.9 and 20.12.The first is introduced because
CONFIG_CC_IS_CLANGinxen/self-tests.his not
defined in the configuration under analysis. Using "defined()" instead avoids
relying on the preprocessor's behaviour upon encountering an undedfined identifier
and addresses the violation.The violation of Rule 20.12 is due to "val" being used both as an ordinary argument
in macroRUNTIME_CHECK, and as a stringification operator.Quoted 5 lines
No functional change.
Fixes ea59e7d780d9 ("xen/bitops: Cleanup and new infrastructureahead of rearrangements")
Signed-off-by Nicola Vetrini <[email protected]>Thankyou for this patch. I'd seen that I'd broken something. (Entirely my fault - I've done a lot of testing in Gitlab for the series, but never manually ran the Eclair jobs. I'll try to remember better next time.)
One question though.
https://gitlab.com/xen-project/xen/-/jobs/6994213979 says:Failure: 1 regressions found for clean guidelines service MC3R1.R20.9: (required) All identifiers used in the controlling expression of
#if' or#elif' preprocessing directives shall be #define'd before evaluation:
violation: 1Quoted 8 lines
While there is a report for 20.12, it's not clean yet (so the first sentence wants adjusting), and
RUNTIME_CHECKdoesn't show up newly in it.So, while I agree that
RUNTIME_CHECK()should be included in the 20.12 exclusions, why is current Gitlab Run not reporting it?~Andrew
Quoted 8 lines
While Rule 20.12 wasn't clean on x86, but it was on arm, so in the arm64 run it is reported as such
https://gitlab.com/xen-project/xen/-/jobs/6994213980
with the other patches in the series the rule should be clean on both architectures, so this imbalance should disappear rather shortly.
Thanks - I'd just found the ARM report and was replying - I'll rebase onto this thread.
I still don't understand why the violation doesn't show up on the x86 build. Specifically, why it's missing from here:
https://saas.eclairit.com:3787/fs/var/local/eclair/xen-project.ecdf/xen-project/xen/ECLAIR_normal/staging/X86_64/6994213979/prev/PROJECT.ecd;/by_service/MC3R1.R20.12.html
From the ARM report, one is xen/lib/generic-ffsl.c:61 and checking with the x86 build log, we are building generic-ffsl.c too (which is expected.)
~Andrew
Re: [XEN PATCH 5/5] xen: fix MISRA regressions on rule 20.9 and 20.12
Quoted 57 lines · Andrew Cooper
Quoted 47 lines · Nicola Vetrini
Quoted 37 lines · Andrew Cooper
Quoted 16 lines · Nicola Vetrini
ea59e7d780d9("xen/bitops: Cleanup and new infrastructure ahead of rearrangements")
introduced new violations on previously clean rules 20.9 and 20.12.The first is introduced because
CONFIG_CC_IS_CLANGinxen/self-tests.his not
defined in the configuration under analysis. Using "defined()" instead avoids
relying on the preprocessor's behaviour upon encountering an undedfined identifier
and addresses the violation.The violation of Rule 20.12 is due to "val" being used both as an ordinary argument
in macroRUNTIME_CHECK, and as a stringification operator.Quoted 5 lines
No functional change.
Fixes ea59e7d780d9 ("xen/bitops: Cleanup and new infrastructureahead of rearrangements")
Signed-off-by Nicola Vetrini <[email protected]>Thankyou for this patch. I'd seen that I'd broken something. (Entirely my fault - I've done a lot of testing in Gitlab for the series, but never manually ran the Eclair jobs. I'll try to remember better next time.)
One question though.
https://gitlab.com/xen-project/xen/-/jobs/6994213979 says:Failure: 1 regressions found for clean guidelines service MC3R1.R20.9: (required) All identifiers used in the controlling expression of
#if' or#elif' preprocessing directives shall be #define'd before evaluation:
violation: 1Quoted 8 lines
While there is a report for 20.12, it's not clean yet (so the first sentence wants adjusting), and
RUNTIME_CHECKdoesn't show up newly in it.So, while I agree that
RUNTIME_CHECK()should be included in the 20.12 exclusions, why is current Gitlab Run not reporting it?~Andrew
Quoted 8 lines
While Rule 20.12 wasn't clean on x86, but it was on arm, so in the arm64 run it is reported as such
https://gitlab.com/xen-project/xen/-/jobs/6994213980
with the other patches in the series the rule should be clean on both architectures, so this imbalance should disappear rather shortly.
Quoted 7 lines
Thanks - I'd just found the ARM report and was replying - I'll rebase onto this thread.
I still don't understand why the violation doesn't show up on the x86 build. Specifically, why it's missing from here:
https://saas.eclairit.com:3787/fs/var/local/eclair/xen-project.ecdf/xen-project/xen/ECLAIR_normal/staging/X86_64/6994213979/prev/PROJECT.ecd;/by_service/MC3R1.R20.12.html
Note the "prev" here in the URL: this means you're looking at the analysis run before your series was merged (on 03147e6837ff045db)
this is the latest run for x86 on staging:
Quoted 4 lines
From the ARM report, one is
xen/lib/generic-ffsl.c:61and checking with the x86 build log, we are buildinggeneric-ffsl.ctoo (which is expected.)~Andrew
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Re: [XEN PATCH 5/5] xen: fix MISRA regressions on rule 20.9 and 20.12
Quoted 68 lines · Nicola Vetrini
Quoted 58 lines · Andrew Cooper
Quoted 48 lines · Nicola Vetrini
Quoted 38 lines · Andrew Cooper
Quoted 16 lines · Nicola Vetrini
ea59e7d780d9("xen/bitops: Cleanup and new infrastructure ahead of rearrangements")
introduced new violations on previously clean rules 20.9 and 20.12.The first is introduced because
CONFIG_CC_IS_CLANGinxen/self-tests.his not
defined in the configuration under analysis. Using "defined()" instead avoids
relying on the preprocessor's behaviour upon encountering an undedfined identifier
and addresses the violation.The violation of Rule 20.12 is due to "val" being used both as an ordinary argument
in macroRUNTIME_CHECK, and as a stringification operator.Quoted 5 lines
No functional change.
Fixes ea59e7d780d9 ("xen/bitops: Cleanup and new infrastructureahead of rearrangements")
Signed-off-by Nicola Vetrini <[email protected]>Thankyou for this patch. I'd seen that I'd broken something. (Entirely
my fault - I've done a lot of testing in Gitlab for the series, but never manually ran the Eclair jobs. I'll try to remember better next time.)One question though.
https://gitlab.com/xen-project/xen/-/jobs/6994213979 says:Failure: 1 regressions found for clean guidelines service MC3R1.R20.9: (required) All identifiers used in the controlling expression of
#if' or#elif' preprocessing directives shall be #define'd before evaluation:
violation: 1Quoted 8 lines
While there is a report for 20.12, it's not clean yet (so the first sentence wants adjusting), and
RUNTIME_CHECKdoesn't show up newly in it.So, while I agree that
RUNTIME_CHECK()should be included in the 20.12 exclusions, why is current Gitlab Run not reporting it?~Andrew
Quoted 8 lines
While Rule 20.12 wasn't clean on x86, but it was on arm, so in the arm64 run it is reported as such
https://gitlab.com/xen-project/xen/-/jobs/6994213980
with the other patches in the series the rule should be clean on both architectures, so this imbalance should disappear rather shortly.
Quoted 8 lines
Thanks - I'd just found the ARM report and was replying - I'll rebase onto this thread.
I still don't understand why the violation doesn't show up on the x86 build. Specifically, why it's missing from here:
https://saas.eclairit.com:3787/fs/var/local/eclair/xen-project.ecdf/xen-project/xen/ECLAIR_normal/staging/X86_64/6994213979/prev/PROJECT.ecd;/by_service/MC3R1.R20.12.html
Quoted 6 lines
Note the "prev" here in the URL: this means you're looking at the analysis run before your series was merged (on
03147e6837ff045db)this is the latest run for x86 on staging:
Oh - thankyou for explaining.
~Andrew
Quoted 11 lines · Nicola Vetrini
Patches 1 to 4 address violations of MISRA C Rule 20.12 by deviating certain uses of some macros, while the last patch addresses some regressions introduced by the latest bitops series
Nicola Vetrini (5):
xen/domain: deviate violation of MISRA C Rule 20.12 x86/domain: deviate violation of MISRA C Rule 20.12
x86: deviate violation of MISRA C Rule 20.12 automation/eclair_analysis: address remaining violations of MISRA CRule 20.12xen: fix MISRA regressions on rule 20.9 and 20.12
I've committed patch 5 because it fixes a blocking failure in Gitlab CI from content already accepted for Xen 4.19.
The others look fine to me, but you'll need to negotiate with Oleksii (CC'd) to get them in, at this point in the release.
Given that this series makes x86 clean to Rule 20.12, shouldn't there be a final patch making it blocking, to bring x86 in line with ARM?
~Andrew
Quoted 13 lines · Andrew Cooper
Quoted 11 lines · Nicola Vetrini
Patches 1 to 4 address violations of MISRA C Rule 20.12 by deviating certain uses of some macros, while the last patch addresses some regressions introduced by the latest bitops series
Nicola Vetrini (5):
xen/domain: deviate violation of MISRA C Rule 20.12 x86/domain: deviate violation of MISRA C Rule 20.12
x86: deviate violation of MISRA C Rule 20.12 automation/eclair_analysis: address remaining violations of MISRA CRule 20.12xen: fix MISRA regressions on rule 20.9 and 20.12
Quoted 3 lines
I've committed patch 5 because it fixes a blocking failure in Gitlab CI from content already accepted for Xen 4.19.
Thanks
Quoted 3 lines
The others look fine to me, but you'll need to negotiate with Oleksii (CC'd) to get them in, at this point in the release.
Well, having one more clean rule does look better for Xen, and the changes to the codebase are harmless enough, but ultimately given the closeness with the deadline I didn't really see a need to.
Quoted 3 lines
Given that this series makes x86 clean to Rule 20.12, shouldn't there be a final patch making it blocking, to bring x86 in line with ARM?
Good point, I should have done that in patch 4. I'll do a follow-up patch.
Quoted 1 line
~Andrew
Signature · 2 lines
Nicola Vetrini, BSc Software Engineer, BUGSENG srl (https://bugseng.com)
Quoted 30 lines · Nicola Vetrini
Quoted 15 lines · Andrew Cooper
Quoted 6 lines · Nicola Vetrini
Patches 1 to 4 address violations of MISRA C Rule 20.12 by deviating certain
uses of some macros, while the last patch addresses some regressions introduced
by the latest bitops seriesQuoted 7 lines
Nicola Vetrini (5):
xen/domain: deviate violation of MISRA C Rule 20.12 x86/domain: deviate violation of MISRA C Rule 20.12
x86: deviate violation of MISRA C Rule 20.12 automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12
xen: fix MISRA regressions on rule 20.9 and 20.12Quoted 3 lines
I've committed patch 5 because it fixes a blocking failure in Gitlab CI from content already accepted for Xen 4.19.
Thanks
Quoted 3 lines
The others look fine to me, but you'll need to negotiate with Oleksii (CC'd) to get them in, at this point in the release.
Well, having one more clean rule does look better for Xen, and the changes to the codebase are harmless enough, but ultimately given the closeness with the deadline I didn't really see a need to.
Quoted 6 lines
Quoted 3 lines
Given that this series makes x86 clean to Rule 20.12, shouldn't there be a final patch making it blocking, to bring x86 in line with ARM?
Good point, I should have done that in patch 4. I'll do a follow-up patch.
FWIW, given how simple this series is, I'm +1 for including it in 4.19, even at this point. It is definitely nicer to have the disposition of Rule 20.12 the same between ARM and x86.
Still - it's very much Oleksii's call.
~Andrew