Skip to contentSkip to conversation

address remaining violations of Rule 20.12

PATCH In review Nicola Vetrini 3 participants 8 messages Jun 7, 2024 – Jun 18, 2024

lore
Share & tools
lore
#0 lore raw

v2 cover address remaining violations of Rule 20.12

This series addresses the remaining violations of Rule 20.12, and consequently sets the rule (and others) as clean to enable the gating.

Patches 1 and 2 are retained from the previous version, while patch 3 was sent standalone and now merged in this series, as it depends on the previous two patches.

Nicola Vetrini (3):
x86/domain: deviate violation of MISRA C Rule 20.12 automation/eclair_analysis: address remaining violations of MISRA C

    Rule 20.12

automation/eclair_analysis: add more clean MISRA guidelines

 automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++
 automation/eclair_analysis/ECLAIR/tagging.ecl    | 4 +++-
 docs/misra/safe.json                             | 8 ++++++++
 xen/arch/x86/domain.c                            | 1 +
 xen/arch/x86/domctl.c                            | 1 +
 5 files changed, 19 insertions(+), 1 deletion(-)

--
2.34.1

#1 lore raw

PATCH v2 1/3 x86/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_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.

---
 docs/misra/safe.json  | 8 ++++++++
 xen/arch/x86/domain.c | 1 +
 xen/arch/x86/domctl.c | 1 +
 3 files changed, 10 insertions(+)
docs/misra/safe.json +8 -0
index 9b13bcf71706..c213e0a0be3b 100644
@@ -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/arch/x86/domain.c +1 -0
index 536542841ef5..ccadfe0c9e70 100644
@@ -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
index 9a72d57333e9..335aedf46d03 100644
@@ -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

--
2.34.1

#2 lore raw

PATCH v2 2/3 automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12

In reply to 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.

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++
 1 file changed, 6 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +6 -0
index 447c1e6661d1..e2653f77eb2c 100644
@@ -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.
 #

--
2.34.1

Acked-by on v2 2/3
#3 lore raw

Re: [XEN PATCH for-4.19 v2 2/3] automation/eclair_analysis: address remaining violations of MISRA C Rule 20.12

Quoted 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.

Quoted 24 lines
---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 6 ++++++
 1 file changed, 6 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +6 -1
index 447c1e6661d1..e2653f77eb2c 100644
@@ -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.
 #
--

2.34.1

#4 lore raw

PATCH v2 3/3 automation/eclair_analysis: add more clean MISRA guidelines

In reply to Nicola Vetrini

Rules 20.9, 20.12 and 14.4 are now clean on ARM and x86, so they are added to the list of clean guidelines.

Some guidelines listed in the additional clean section for ARM are also clean on x86, so they can be removed from there.

No functional change.

---
 automation/eclair_analysis/ECLAIR/tagging.ecl | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
automation/eclair_analysis/ECLAIR/tagging.ecl +3 -1
index a354ff322e03..b829655ca0bc 100644
@@ -60,6 +60,7 @@ MC3R1.R11.7||
 MC3R1.R11.9||
 MC3R1.R12.5||
 MC3R1.R14.1||
+MC3R1.R14.4||
 MC3R1.R16.7||
 MC3R1.R17.1||
 MC3R1.R17.3||
@@ -73,6 +74,7 @@ MC3R1.R20.4||
 MC3R1.R20.6||
 MC3R1.R20.9||
 MC3R1.R20.11||
+MC3R1.R20.12||
 MC3R1.R20.13||
 MC3R1.R20.14||
 MC3R1.R21.3||
@@ -105,7 +107,7 @@ if(string_equal(target,"x86_64"),
 )
 
 if(string_equal(target,"arm64"),
-    service_selector({"additional_clean_guidelines","MC3R1.R14.4||MC3R1.R16.6||MC3R1.R20.12||MC3R1.R2.1||MC3R1.R5.3||MC3R1.R7.2||MC3R1.R7.3||MC3R1.R8.6||MC3R1.R9.3"})
+    service_selector({"additional_clean_guidelines","MC3R1.R16.6||MC3R1.R2.1||MC3R1.R5.3||MC3R1.R7.3"})
 )
 
 -reports+={clean:added,"service(clean_guidelines_common||additional_clean_guidelines)"}

--
2.34.1

#5 lore raw

Re: [XEN PATCH for-4.19 v2 3/3] automation/eclair_analysis: add more clean MISRA guidelines

Quoted 2 lines · Nicola Vetrini

Rules 20.9, 20.12 and 14.4 are now clean on ARM and x86, so they are added to the list of clean guidelines.

Why is 20.9 being mentioned here when ...

Quoted 11 lines
automation/eclair_analysis/ECLAIR/tagging.ecl +1 -0
@@ -60,6 +60,7 @@ MC3R1.R11.7||
 MC3R1.R11.9||
 MC3R1.R12.5||
 MC3R1.R14.1||
+MC3R1.R14.4||
 MC3R1.R16.7||
 MC3R1.R17.1||
 MC3R1.R17.3||

automation/eclair_analysis/ECLAIR/tagging.ecl MC3R1.R20.4|| · line 80

Quoted 7 lines
automation/eclair_analysis/ECLAIR/tagging.ecl +1 -0
@@ -73,6 +74,7 @@ MC3R1.R20.4||
 MC3R1.R20.6||
 MC3R1.R20.9||
 MC3R1.R20.11||
+MC3R1.R20.12||
 MC3R1.R20.13||
 MC3R1.R20.14||
 MC3R1.R21.3||

... nothing changes in its regard?

Jan

#6 lore raw

Re: [XEN PATCH for-4.19 v2 3/3] automation/eclair_analysis: add more clean MISRA guidelines

Quoted 18 lines · Jan Beulich
Quoted 2 lines · Nicola Vetrini

Rules 20.9, 20.12 and 14.4 are now clean on ARM and x86, so they are added to the list of clean guidelines.

Why is 20.9 being mentioned here when ...

Quoted 12 lines
automation/eclair_analysis/ECLAIR/tagging.ecl +1 -0
@@ -60,6 +60,7 @@ MC3R1.R11.7||
 MC3R1.R11.9||
 MC3R1.R12.5||
 MC3R1.R14.1||
+MC3R1.R14.4||
 MC3R1.R16.7||
 MC3R1.R17.1||
 MC3R1.R17.3||
@@ -73,6 +74,7 @@ MC3R1.R20.4||
 MC3R1.R20.6||
Quoted 9 lines

automation/eclair_analysis/ECLAIR/tagging.ecl MC3R1.R20.4|| · line 80

Quoted 6 lines
automation/eclair_analysis/ECLAIR/tagging.ecl +1 -0
 MC3R1.R20.9||
 MC3R1.R20.11||
+MC3R1.R20.12||
 MC3R1.R20.13||
 MC3R1.R20.14||
 MC3R1.R21.3||

... nothing changes in its regard?

Right, it should be removed from the message.

Quoted 1 line

Jan

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
#7 lore raw

Re: [XEN PATCH for-4.19 v2 3/3] automation/eclair_analysis: add more clean MISRA guidelines

Quoted 29 lines · Nicola Vetrini
Quoted 18 lines · Jan Beulich
Quoted 2 lines · Nicola Vetrini

Rules 20.9, 20.12 and 14.4 are now clean on ARM and x86, so they are added to the list of clean guidelines.

Why is 20.9 being mentioned here when ...

Quoted 12 lines
automation/eclair_analysis/ECLAIR/tagging.ecl +1 -0
@@ -60,6 +60,7 @@ MC3R1.R11.7||
 MC3R1.R11.9||
 MC3R1.R12.5||
 MC3R1.R14.1||
+MC3R1.R14.4||
 MC3R1.R16.7||
 MC3R1.R17.1||
 MC3R1.R17.3||
@@ -73,6 +74,7 @@ MC3R1.R20.4||
 MC3R1.R20.6||
Quoted 9 lines

automation/eclair_analysis/ECLAIR/tagging.ecl MC3R1.R20.4|| · line 80

Quoted 6 lines
automation/eclair_analysis/ECLAIR/tagging.ecl +1 -0
 MC3R1.R20.9||
 MC3R1.R20.11||
+MC3R1.R20.12||
 MC3R1.R20.13||
 MC3R1.R20.14||
 MC3R1.R21.3||

... nothing changes in its regard?

Quoted 1 line

Right, it should be removed from the message.

I fixed the commit message, acked the patch and committed it