[XEN PATCH] misra: add deviation of Rule 5.6 for shadow paging code

Nicola Vetrini posted 1 patch 2 days ago
automation/eclair_analysis/ECLAIR/deviations.ecl | 5 +++++
docs/misra/deviations.rst                        | 2 ++
2 files changed, 7 insertions(+)
[XEN PATCH] misra: add deviation of Rule 5.6 for shadow paging code
Posted by Nicola Vetrini 2 days ago
The rule headline states: "A typedef name shall be a unique identifier".

in x86/mm/shadow/multi.c the typedef names for `guest_va_t` and `guest_pa_t`
are deliberately reused multiple times due to the file being included with
different GUEST_PAGING_LEVELS. As a result, a deviation for the rule is
introduced.

No functional change.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
CI pipeline: https://gitlab.com/xen-project/people/bugseng/xen/-/pipelines/2216437709
---
 automation/eclair_analysis/ECLAIR/deviations.ecl | 5 +++++
 docs/misra/deviations.rst                        | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl b/automation/eclair_analysis/ECLAIR/deviations.ecl
index 219ba6993b90..86e782da3f12 100644
--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -143,6 +143,11 @@ number of guest paging levels."
 -config=MC3A2.R5.6,reports+={deliberate,"any_area(any_loc(file(^xen/arch/x86/include/asm/guest_pt\\.h$)))&&any_area(any_loc(text(^.*(guest_intpte_t|guest_l[12]e_t).*$)))"}
 -doc_end
 
+-doc_begin="On X86 shadow paging code, the types \"guest_(va|pa)_t\" are deliberately
+defined multiple times, depending on the number of guest paging levels."
+-config=MC3A2.R5.6,reports+={deliberate,"any_area(any_loc(file(^xen/arch/x86/mm/shadow/multi\\.c$)))&&any_area(any_loc(text(^typedef.*guest_(va|pa)_t.*$)))"}
+-doc_end
+
 -doc_begin="The following files are imported from the gnu-efi package."
 -file_tag+={adopted_r5_6,"^xen/include/efi/.*$"}
 -file_tag+={adopted_r5_6,"^xen/arch/.*/include/asm/.*/efibind\\.h$"}
diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
index b3431ef24e26..7f877142109d 100644
--- a/docs/misra/deviations.rst
+++ b/docs/misra/deviations.rst
@@ -187,6 +187,8 @@ Deviations related to MISRA C:2012 Rules:
      - Tagged as `deliberate` for ECLAIR. Such types are:
          - guest_intpte_t
          - guest_l[12]e_t
+         - guest_va_t
+         - guest_pa_t
 
    * - R5.6
      - Some files are not subject to respect MISRA rules at
-- 
2.43.0
Re: [XEN PATCH] misra: add deviation of Rule 5.6 for shadow paging code
Posted by Jan Beulich 1 day, 15 hours ago
On 16.12.2025 01:11, Nicola Vetrini wrote:
> The rule headline states: "A typedef name shall be a unique identifier".
> 
> in x86/mm/shadow/multi.c the typedef names for `guest_va_t` and `guest_pa_t`
> are deliberately reused multiple times due to the file being included with
> different GUEST_PAGING_LEVELS. As a result, a deviation for the rule is
> introduced.
> 
> No functional change.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

Looks plausible, yet I wonder if we wouldn't better do away with guest_pa_t.
It has one single use (the per-CPU trace_emulate_write_val), and judging
from the involved logic as well as other naming (e.g. the .write_val.l1 field
used in sh_trace_emulate()) it's really guest_l1e_t that's meant there.

Jan