[PATCH] x86/gen-cpuid: Fix debugging for cycle detection

Andrew Cooper posted 1 patch 2 months ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20250829192939.1090358-1-andrew.cooper3@citrix.com
xen/tools/gen-cpuid.py | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] x86/gen-cpuid: Fix debugging for cycle detection
Posted by Andrew Cooper 2 months ago
Jan reports the following exception when using the cycle debugging:

  Feature IBRSB, seen [IBRSB, STIBP, INTEL_PSFD, EIBRS, IPRED_CTRL, RRSBA_CTRL, RRSBA, BHI_CTRL], to_process [SSBD]
  Traceback (most recent call last):
    File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 594, in <module>
      sys.exit(main())
               ^^^^^^
    File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 588, in main
      crunch_numbers(state)
    File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 366, in crunch_numbers
      (state.names[feat], repl(seen), repl(to_process)))
                                      ^^^^^^^^^^^^^^^^
    File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 364, in repl
      return "[" + ", ".join((state.names[x] for x in l)) + "]"
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 364, in <genexpr>
      return "[" + ", ".join((state.names[x] for x in l)) + "]"
                              ~~~~~~~~~~~^^^
  KeyError: 534
  make[2]: *** [/local/xen.git/xen/include/xen/lib/x86/Makefile:9: cpuid-autogen.h] Error 1

This is caused by commit ce8c930851a5 ("x86/cpu-policy: MSR_ARCH_CAPS feature
names") being rather lazy and marking dependenices on unknown features.

Introduce a helper to pick the known features in a range, and use it for
ARCH_CAPS.

Additionally, remove trailing whitepsace from the debug print.

Reported-by: Jan Beulich <jbeulich@suse.com>
Fixes: ce8c930851a5 ("x86/cpu-policy: MSR_ARCH_CAPS feature names")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
 xen/tools/gen-cpuid.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/xen/tools/gen-cpuid.py b/xen/tools/gen-cpuid.py
index 6f96d1368e9e..403369aedcd9 100755
--- a/xen/tools/gen-cpuid.py
+++ b/xen/tools/gen-cpuid.py
@@ -168,6 +168,10 @@ def crunch_numbers(state):
     state.hvm_shadow_max = state.pv_max         | state.raw['S'] | state.raw['s']
     state.hvm_hap_max =    state.hvm_shadow_max | state.raw['H'] | state.raw['h']
 
+    def feat_range(start, last):
+        """ Select all known features in the given range """
+        return [ x for x in state.names.keys() if start <= x <= last ]
+
     #
     # Feature dependency information.
     #
@@ -338,7 +342,7 @@ def crunch_numbers(state):
         PSFD: [EPSF],
 
         # The ARCH_CAPS CPUID bit enumerates the availability of the whole register.
-        ARCH_CAPS: list(range(RDCL_NO, RDCL_NO + 64)),
+        ARCH_CAPS: feat_range(RDCL_NO, RDCL_NO + 63),
 
         # The behaviour described by RRSBA depend on eIBRS being active.
         EIBRS: [RRSBA],
@@ -362,7 +366,7 @@ def crunch_numbers(state):
             # To debug, uncomment the following lines:
             # def repl(l):
             #     return "[" + ", ".join((state.names[x] for x in l)) + "]"
-            # sys.stderr.write("Feature %s, seen %s, to_process %s \n" % \
+            # sys.stderr.write("Feature %s, seen %s, to_process %s\n" % \
             #     (state.names[feat], repl(seen), repl(to_process)))
 
             f = to_process.pop(0)

base-commit: e7c689a249ca6b8d14a077bb0f3311eaeda2ca19
-- 
2.39.5


Re: [PATCH] x86/gen-cpuid: Fix debugging for cycle detection
Posted by Jan Beulich 1 month, 4 weeks ago
On 29.08.2025 21:29, Andrew Cooper wrote:
> Jan reports the following exception when using the cycle debugging:
> 
>   Feature IBRSB, seen [IBRSB, STIBP, INTEL_PSFD, EIBRS, IPRED_CTRL, RRSBA_CTRL, RRSBA, BHI_CTRL], to_process [SSBD]
>   Traceback (most recent call last):
>     File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 594, in <module>
>       sys.exit(main())
>                ^^^^^^
>     File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 588, in main
>       crunch_numbers(state)
>     File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 366, in crunch_numbers
>       (state.names[feat], repl(seen), repl(to_process)))
>                                       ^^^^^^^^^^^^^^^^
>     File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 364, in repl
>       return "[" + ", ".join((state.names[x] for x in l)) + "]"
>                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     File "/local/xen.git/xen/../xen/tools/gen-cpuid.py", line 364, in <genexpr>
>       return "[" + ", ".join((state.names[x] for x in l)) + "]"
>                               ~~~~~~~~~~~^^^
>   KeyError: 534
>   make[2]: *** [/local/xen.git/xen/include/xen/lib/x86/Makefile:9: cpuid-autogen.h] Error 1
> 
> This is caused by commit ce8c930851a5 ("x86/cpu-policy: MSR_ARCH_CAPS feature
> names") being rather lazy and marking dependenices on unknown features.
> 
> Introduce a helper to pick the known features in a range, and use it for
> ARCH_CAPS.
> 
> Additionally, remove trailing whitepsace from the debug print.
> 
> Reported-by: Jan Beulich <jbeulich@suse.com>
> Fixes: ce8c930851a5 ("x86/cpu-policy: MSR_ARCH_CAPS feature names")
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Acked-by: Jan Beulich <jbeulich@suse.com>