[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] x86/gen-cpuid: Avoid violations of Misra rule 1.3


  • To: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Date: Wed, 2 Aug 2023 14:10:03 +0100
  • Authentication-results: esa4.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Jan Beulich <JBeulich@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • Delivery-date: Wed, 02 Aug 2023 13:10:46 +0000
  • Ironport-data: A9a23:kdUL3K0nU1Q7GZNya/bD5cxxkn2cJEfYwER7XKvMYLTBsI5bpzwGm DAWWjuFbP2LamDzetkiPI6/oB4BuZeEyNUxGwtlpC1hF35El5HIVI+TRqvS04F+DeWYFR46s J9OAjXkBJppJpMJjk71atANlVEliefTAOK6ULWeUsxIbVcMYD87jh5+kPIOjIdtgNyoayuAo tq3qMDEULOf82cc3lk8teTb8XuDgNyo4GlD5gxmP6gS1LPjvyJ94Kw3dPnZw0TQGuG4LsbiL 87fwbew+H/u/htFIrtJRZ6iLyXm6paLVeS/oiI+t5qK23CulQRrukoPD9IOaF8/ttm8t4sZJ OOhF3CHYVxB0qXkwIzxWvTDes10FfUuFLTveRBTvSEPpqFvnrSFL/hGVSkL0YMkFulfQkJF0 NAVCj02Qy+8htCUn4qJdvMvv5F2RCXrFNt3VnBIyDjYCbAtQIzZQrWM7thdtNsyrpkQR7CEP ZNfMGcxKk2aOHWjOX9OYH46tM6uimPybHtzr1WNqLBsy2PS0BZwwP7mN9+9ltmiHJ8NzhbJ+ z+cl4j/KiMCM9Cw9QWiy2ClrKyfjD72aak0SrLto5aGh3XMnzdOWXX6T2CTsfS/z0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MqzM2nX3w1EBvDSk8eutaN2zwTmHxi1UMXyMEWg39F/pMgTJtP4f jCL81T5cRzZ95Tabg4CPYKQMOxBGCISRXQMHiKKVCiD60DM2Klke+H3Fz03pDVRHUl9upMpH 2aaiIkiYcbQTOTNfGz
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Add the script to the X86 section in ./MAINTAINERS.

Structures or unions without any named members aren't liked by Misra
(nor the C standard). Avoid emitting such for leaves without any known
bits.

The placeholders are affected similarly, but are only visible to MISRA in the
middle of a patch series adding a new leaf.  The absence of a name was
intentional as these defines need to not duplicate names.

As that's not deemed acceptable any more, move placeholder processing into the
main loop and append the the word number to generate unique names.

  $ diff cpuid-autogen-{before,after}.h
  @@ -1034,7 +1034,7 @@
       bool intel_psfd:1, ipred_ctrl:1, rrsba_ctrl:1, ddp_ctrl:1,     ...

   #define CPUID_BITFIELD_14 \
  -    bool :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1,   ...
  +    uint32_t _placeholder_14

   #define CPUID_BITFIELD_15 \
       bool :1, :1, :1, :1, avx_vnni_int8:1, avx_ne_convert:1, :1,    ...
  @@ -1043,19 +1043,19 @@
       bool rdcl_no:1, eibrs:1, rsba:1, skip_l1dfl:1, intel_ssb_no:1, ...

   #define CPUID_BITFIELD_17 \
  -    bool :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1, :1,   ...
  +    uint32_t _placeholder_17

   #define CPUID_BITFIELD_18 \
  -    uint32_t :32 /* placeholder */
  +    uint32_t _placeholder_18

   #define CPUID_BITFIELD_19 \
  -    uint32_t :32 /* placeholder */
  +    uint32_t _placeholder_19

   #define CPUID_BITFIELD_20 \
  -    uint32_t :32 /* placeholder */
  +    uint32_t _placeholder_20

   #define CPUID_BITFIELD_21 \
  -    uint32_t :32 /* placeholder */
  +    uint32_t _placeholder_21

   #endif /* __XEN_X86__FEATURESET_DATA__ */

No functional change.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
---
CC: Jan Beulich <JBeulich@xxxxxxxx>
CC: Roger Pau Monné <roger.pau@xxxxxxxxxx>
CC: Wei Liu <wl@xxxxxxx>
CC: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>

v2:
 * Write it more pythonically.  Fix up the placeholders too.
---
 MAINTAINERS            |  1 +
 xen/tools/gen-cpuid.py | 11 ++++++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/MAINTAINERS b/MAINTAINERS
index d8a02a6c1918..a0805d35cd71 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -601,6 +601,7 @@ F:  xen/arch/x86/
 F:     xen/include/public/arch-x86/
 F:     xen/include/xen/lib/x86
 F:     xen/lib/x86
+F:     xen/tools/gen-cpuid.py
 F:     tools/firmware/hvmloader/
 F:     tools/firmware/rombios/
 F:     tools/firmware/vgabios/
diff --git a/xen/tools/gen-cpuid.py b/xen/tools/gen-cpuid.py
index 72cf11654ba9..5797bc64c803 100755
--- a/xen/tools/gen-cpuid.py
+++ b/xen/tools/gen-cpuid.py
@@ -363,8 +363,8 @@ def crunch_numbers(state):
     state.deep_features = deps.keys()
     state.nr_deep_deps = len(state.deep_deps.keys())
 
-    # Calculate the bitfield name declarations
-    for word in range(state.nr_entries):
+    # Calculate the bitfield name declarations.  Leave 4 placeholders on the 
end
+    for word in range(state.nr_entries + 4):
 
         names = []
         for bit in range(32):
@@ -382,7 +382,10 @@ def crunch_numbers(state):
 
             names.append(name.lower())
 
-        state.bitfields.append("bool " + ":1, ".join(names) + ":1")
+        if any(names):
+            state.bitfields.append("bool " + ":1, ".join(names) + ":1")
+        else:
+            state.bitfields.append("uint32_t _placeholder_%s" % (word, ))
 
 
 def write_results(state):
@@ -464,8 +467,6 @@ def write_results(state):
 
 """)
 
-    state.bitfields += ["uint32_t :32 /* placeholder */"] * 4
-
     for idx, text in enumerate(state.bitfields):
         state.output.write(
             "#define CPUID_BITFIELD_%d \\\n    %s\n\n"

base-commit: 51588938e0cd0e02dbc1d6d8c697c577135ff666
-- 
2.30.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.