Skip to contentSkip to conversation

xen: address violations of MISRA C Rule 17.1

PATCH In review Simone Ballarin 3 participants 9 messages Mar 28, 2024 – Apr 5, 2024

lore
Share & tools
lore
#0 lore raw

v3 cover xen: address violations of MISRA C Rule 17.1

MISRA C Rule 20.7 states: "The features of `<stdarg.h>' shall not be used".

The Xen community wants to avoid using variadic functions except for specific circumstances where it feels appropriate by strict code review.

Functions hypercall_create_continuation and hypercall_xlat_continuation are internal helpers made to break long running hypercalls into multiple calls. They take a variable number of arguments depending on the original hypercall they are trying to continue. Add SAF deviations for the aforementioned functions.

Add deviation for printf()-like functions.

---
Changes in v3:
- use regexes to exempt all .*printk and .*printf functions, instead of manually listing them one by one;
- rebase: change SAF-3-safe in SAF-4-safe.
Changes in v2:
- replace "related to console output" with "printf()-like functions";
- replace "special hypercalls" with "internal helpers".

Simone Ballarin (2):
MISRA C:2012 Rule 17.1 states: The features of `<stdarg.h>' shall not
be used
MISRA C Rule 20.7 states: "The features of `<stdarg.h>' shall not be
used"

 automation/eclair_analysis/ECLAIR/deviations.ecl | 13 +++++++++++++
 docs/misra/deviations.rst                        |  5 +++++
 docs/misra/safe.json                             |  8 ++++++++
 xen/arch/arm/domain.c                            |  1 +
 xen/arch/x86/hypercall.c                         |  2 ++
 5 files changed, 29 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 1/2 MISRA C:2012 Rule 17.1 states: The features of `<stdarg.h>' shall not be used

The Xen community wants to avoid using variadic functions except for specific circumstances where it feels appropriate by strict code review.

Add deviation for printf()-like functions.

---
Changes in v3:
- use regex to exempt all .*printk and .*printf functions, instead of manually listing them one by one.
Changes in v2:
- replace "console output related" with "printf()-like".

---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 13 +++++++++++++
 docs/misra/deviations.rst                        |  5 +++++
 2 files changed, 18 insertions(+)
automation/eclair_analysis/ECLAIR/deviations.ecl +13 -0
index de9ba723fb..936c738caf 100644
@@ -386,6 +386,19 @@ explicit comment indicating the fallthrough intention is present."
 -config=MC3R1.R16.6,switch_clauses+={deliberate, "default(0)"}
 -doc_end
 
+#
+# Series 17.
+#
+
+-doc_begin="printf()-like functions are allowed to use the variadic features provided by stdarg.h."
+-config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(^.*printk\(.*\)$)))"}
+-config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(^.*printf\(.*\)$)))"}
+-config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(panic)&&kind(function))))"}
+-config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(elf_call_log_callback)&&kind(function))))"}
+-config=MC3R1.R17.1,reports+={deliberate,"any_area(^.*va_list.*$&&context(ancestor_or_self(name(vprintk_common)&&kind(function))))"}
+-config=MC3R1.R17.1,macros+={hide , "^va_(arg|start|copy|end)$"}
+-doc_end
+
 #
 # Series 18.
 #
docs/misra/deviations.rst +5 -0
index eb5ef2bd9d..dd254a9640 100644
@@ -334,6 +334,11 @@ Deviations related to MISRA C:2012 Rules:
        improve readability.
      - Tagged as `deliberate` for ECLAIR.
 
+   * - R17.1
+     - printf()-like functions  are allowed to use the variadic features provided
+       by `stdarg.h`.
+     - Tagged as `deliberate` for ECLAIR.
+
    * - R20.4
      - The override of the keyword \"inline\" in xen/compiler.h is present so
        that section contents checks pass when the compiler chooses not to
Signature · 1 line
2.34.1
#3 lore raw

PATCH v3 2/2 MISRA C Rule 20.7 states: "The features of `<stdarg.h>' shall not be used"

In reply to Simone Ballarin

The Xen community wants to avoid using variadic functions except for specific circumstances where it feels appropriate by strict code review.

Functions hypercall_create_continuation and hypercall_xlat_continuation are internal helper functions made to break long running hypercalls into multiple calls. They take a variable number of arguments depending on the original hypercall they are trying to continue.

Add SAF deviations for the aforementioned functions.

---
Changes in v3:
- rebase: change SAF-3-safe to SAF-4-safe.
Changes in v2:
- replaced "special hypercalls" with "internal helper functions".

---
 docs/misra/safe.json     | 8 ++++++++
 xen/arch/arm/domain.c    | 1 +
 xen/arch/x86/hypercall.c | 2 ++
 3 files changed, 11 insertions(+)
docs/misra/safe.json +8 -0
index d361d0e65c..fe2bc18509 100644
@@ -36,6 +36,14 @@
         },
         {
             "id": "SAF-4-safe",
+            "analyser": {
+                "eclair": "MC3R1.R17.1"
+            },
+            "name": "Rule 17.1: internal helper functions made to break long running hypercalls into multiple calls.",
+            "text": "They need to take a variable number of arguments depending on the original hypercall they are trying to continue."
+        },
+        {
+            "id": "SAF-5-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
xen/arch/arm/domain.c +1 -0
index f38cb5e04c..34cbfe699a 100644
@@ -382,6 +382,7 @@ unsigned long hypercall_create_continuation(
     const char *p = format;
     unsigned long arg, rc;
     unsigned int i;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     current->hcall_preempted = true;
xen/arch/x86/hypercall.c +2 -0
index 01cd73040d..133e9f221c 100644
@@ -31,6 +31,7 @@ unsigned long hypercall_create_continuation(
     const char *p = format;
     unsigned long arg;
     unsigned int i;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     curr->hcall_preempted = true;
@@ -115,6 +116,7 @@ int hypercall_xlat_continuation(unsigned int *id, unsigned int nr,
     struct cpu_user_regs *regs;
     unsigned int i, cval = 0;
     unsigned long nval = 0;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     ASSERT(nr <= ARRAY_SIZE(mcs->call.args));
Signature · 1 line
2.34.1
#4 lore raw

Re: [XEN PATCH v3 2/2] MISRA C Rule 20.7 states: "The features of `<stdarg.h>' shall not be used"

Quoted 2 lines · Simone Ballarin

The Xen community wants to avoid using variadic functions except for specific circumstances where it feels appropriate by strict code review.

In the title, s/20.7/17.1/ I suppose?

Jan

Quoted 71 lines

Functions hypercall_create_continuation and hypercall_xlat_continuation are internal helper functions made to break long running hypercalls into multiple calls. They take a variable number of arguments depending on the original hypercall they are trying to continue.

Add SAF deviations for the aforementioned functions.

---
Changes in v3:
- rebase: change SAF-3-safe to SAF-4-safe.
Changes in v2:
- replaced "special hypercalls" with "internal helper functions".

---
 docs/misra/safe.json     | 8 ++++++++
 xen/arch/arm/domain.c    | 1 +
 xen/arch/x86/hypercall.c | 2 ++
 3 files changed, 11 insertions(+)
docs/misra/safe.json +8 -0
index d361d0e65c..fe2bc18509 100644
@@ -36,6 +36,14 @@
         },
         {
             "id": "SAF-4-safe",
+            "analyser": {
+                "eclair": "MC3R1.R17.1"
+            },
+            "name": "Rule 17.1: internal helper functions made to break long running hypercalls into multiple calls.",
+            "text": "They need to take a variable number of arguments depending on the original hypercall they are trying to continue."
+        },
+        {
+            "id": "SAF-5-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
xen/arch/arm/domain.c +1 -0
index f38cb5e04c..34cbfe699a 100644
@@ -382,6 +382,7 @@ unsigned long hypercall_create_continuation(
     const char *p = format;
     unsigned long arg, rc;
     unsigned int i;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     current->hcall_preempted = true;
xen/arch/x86/hypercall.c +2 -0
index 01cd73040d..133e9f221c 100644
@@ -31,6 +31,7 @@ unsigned long hypercall_create_continuation(
     const char *p = format;
     unsigned long arg;
     unsigned int i;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     curr->hcall_preempted = true;
@@ -115,6 +116,7 @@ int hypercall_xlat_continuation(unsigned int *id, unsigned int nr,
     struct cpu_user_regs *regs;
     unsigned int i, cval = 0;
     unsigned long nval = 0;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     ASSERT(nr <= ARRAY_SIZE(mcs->call.args));
#5 lore raw

Re: [XEN PATCH v3 2/2] MISRA C Rule 20.7 states: "The features of `<stdarg.h>' shall not be used"

Quoted 78 lines · Jan Beulich
Quoted 2 lines · Simone Ballarin

The Xen community wants to avoid using variadic functions except for specific circumstances where it feels appropriate by strict code review.

In the title, s/20.7/17.1/ I suppose?

Jan

Quoted 70 lines

Functions hypercall_create_continuation and hypercall_xlat_continuation are internal helper functions made to break long running hypercalls into multiple calls. They take a variable number of arguments depending on the original hypercall they are trying to continue.

Add SAF deviations for the aforementioned functions.

---
Changes in v3:
- rebase: change SAF-3-safe to SAF-4-safe.
Changes in v2:
- replaced "special hypercalls" with "internal helper functions".

---
  docs/misra/safe.json     | 8 ++++++++
  xen/arch/arm/domain.c    | 1 +
  xen/arch/x86/hypercall.c | 2 ++
  3 files changed, 11 insertions(+)
docs/misra/safe.json +8 -0
index d361d0e65c..fe2bc18509 100644
@@ -36,6 +36,14 @@
          },
          {
              "id": "SAF-4-safe",
+            "analyser": {
+                "eclair": "MC3R1.R17.1"
+            },
+            "name": "Rule 17.1: internal helper functions made to break long running hypercalls into multiple calls.",
+            "text": "They need to take a variable number of arguments depending on the original hypercall they are trying to continue."
+        },
+        {
+            "id": "SAF-5-safe",
              "analyser": {},
              "name": "Sentinel",
              "text": "Next ID to be used"
xen/arch/arm/domain.c +1 -0
index f38cb5e04c..34cbfe699a 100644
@@ -382,6 +382,7 @@ unsigned long hypercall_create_continuation(
      const char *p = format;
      unsigned long arg, rc;
      unsigned int i;
+    /* SAF-4-safe allowed variadic function */
      va_list args;
 
      current->hcall_preempted = true;
xen/arch/x86/hypercall.c +2 -0
index 01cd73040d..133e9f221c 100644
@@ -31,6 +31,7 @@ unsigned long hypercall_create_continuation(
      const char *p = format;
      unsigned long arg;
      unsigned int i;
+    /* SAF-4-safe allowed variadic function */
      va_list args;
 
      curr->hcall_preempted = true;
@@ -115,6 +116,7 @@ int hypercall_xlat_continuation(unsigned int *id, unsigned int nr,
      struct cpu_user_regs *regs;
      unsigned int i, cval = 0;
      unsigned long nval = 0;
+    /* SAF-4-safe allowed variadic function */
      va_list args;
 
Quoted 3 lines

xen/arch/x86/hypercall.c int hypercall_xlat_continuation(unsigned int *id, unsigned int nr, · line 122

Quoted 1 line
xen/arch/x86/hypercall.c +0 -0
      ASSERT(nr <= ARRAY_SIZE(mcs->call.args));

Yes, sorry.

Signature · 3 lines
Simone Ballarin, M.Sc.

Field Application Engineer, BUGSENG (https://bugseng.com)
Reviewed-by on v3 2/2
#6 lore raw

Re: [XEN PATCH v3 2/2] MISRA C Rule 20.7 states: "The features of `<stdarg.h>' shall not be used"

In reply to Simone Ballarin
Quoted 11 lines · Simone Ballarin

The Xen community wants to avoid using variadic functions except for specific circumstances where it feels appropriate by strict code review.

Functions hypercall_create_continuation and hypercall_xlat_continuation are internal helper functions made to break long running hypercalls into multiple calls. They take a variable number of arguments depending on the original hypercall they are trying to continue.

Add SAF deviations for the aforementioned functions.

I fixed the title on commit

Quoted 65 lines

---
Changes in v3:
- rebase: change SAF-3-safe to SAF-4-safe.
Changes in v2:
- replaced "special hypercalls" with "internal helper functions".

---
 docs/misra/safe.json     | 8 ++++++++
 xen/arch/arm/domain.c    | 1 +
 xen/arch/x86/hypercall.c | 2 ++
 3 files changed, 11 insertions(+)
docs/misra/safe.json +8 -0
index d361d0e65c..fe2bc18509 100644
@@ -36,6 +36,14 @@
         },
         {
             "id": "SAF-4-safe",
+            "analyser": {
+                "eclair": "MC3R1.R17.1"
+            },
+            "name": "Rule 17.1: internal helper functions made to break long running hypercalls into multiple calls.",
+            "text": "They need to take a variable number of arguments depending on the original hypercall they are trying to continue."
+        },
+        {
+            "id": "SAF-5-safe",
             "analyser": {},
             "name": "Sentinel",
             "text": "Next ID to be used"
xen/arch/arm/domain.c +1 -0
index f38cb5e04c..34cbfe699a 100644
@@ -382,6 +382,7 @@ unsigned long hypercall_create_continuation(
     const char *p = format;
     unsigned long arg, rc;
     unsigned int i;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     current->hcall_preempted = true;
xen/arch/x86/hypercall.c +2 -0
index 01cd73040d..133e9f221c 100644
@@ -31,6 +31,7 @@ unsigned long hypercall_create_continuation(
     const char *p = format;
     unsigned long arg;
     unsigned int i;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     curr->hcall_preempted = true;
@@ -115,6 +116,7 @@ int hypercall_xlat_continuation(unsigned int *id, unsigned int nr,
     struct cpu_user_regs *regs;
     unsigned int i, cval = 0;
     unsigned long nval = 0;
+    /* SAF-4-safe allowed variadic function */
     va_list args;
 
     ASSERT(nr <= ARRAY_SIZE(mcs->call.args));
Signature · 1 line
2.34.1
#7 lore raw

Re: [XEN PATCH v3 2/2] MISRA C Rule 20.7 states: "The features of `<stdarg.h>' shall not be used"

Quoted 9 lines · Stefano Stabellini
Quoted 8 lines · Simone Ballarin

The Xen community wants to avoid using variadic functions except for specific circumstances where it feels appropriate by strict code review.

Functions hypercall_create_continuation and hypercall_xlat_continuation are internal helper functions made to break long running hypercalls into multiple calls. They take a variable number of arguments depending on the original hypercall they are trying to continue.

Quoted 8 lines
Quoted 3 lines

Add SAF deviations for the aforementioned functions.

I fixed the title on commit

Did you forget to push then? I don't see this change in the tree, yet.

Jan

#8 lore raw

Re: [XEN PATCH v3 2/2] MISRA C Rule 20.7 states: "The features of `<stdarg.h>' shall not be used"

Quoted 12 lines · Jan Beulich
Quoted 11 lines · Stefano Stabellini
Quoted 10 lines · Simone Ballarin

The Xen community wants to avoid using variadic functions except for specific circumstances where it feels appropriate by strict code review.

Functions hypercall_create_continuation and hypercall_xlat_continuation are internal helper functions made to break long running hypercalls into multiple calls. They take a variable number of arguments depending on the original hypercall they are trying to continue.

Add SAF deviations for the aforementioned functions.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

I fixed the title on commit

Did you forget to push then? I don't see this change in the tree, yet.

Yep, thanks!