Skip to contentSkip to conversation

x86/cpu-policy: minor adjustments

PATCH New Jan Beulich 1 participant 3 messages Aug 29, 2023

lore
Share & tools
lore
#0 lore raw

cover x86/cpu-policy: minor adjustments

Two minor oddities I noticed while moving the XSA-435 prereqs back to 4.11 (a 3rd one is mentioned in a remark in patch 1).

1: add (another) size check of deep_features[]
2: drop NR_DEEP_DEPS

Jan

#1 lore raw

PATCH 1/2 x86/cpu-policy: add (another) size check of deep_features[]

Having this check in library code guarantees that the tool stack use(s) will also be covered.

---
Dropping the check from arch/x86/cpu-policy.c:build_assertions() in exchange may be an option. While there checking is against FSCAPINTS, the difference is only on the surface: That's a #define resolving to FEATURESET_NR_ENTRIES.

Really the duplication of deep_features[] itself is also somewhat odd. While not quite as big as deep_deps[], both Xen and libxg could certainly get away with just a single instance each.

xen/lib/x86/cpuid.c +1 -0
@@ -298,6 +298,7 @@ const uint32_t *x86_cpu_policy_lookup_de
     } deep_deps[] = INIT_DEEP_DEPS;
     unsigned int start = 0, end = ARRAY_SIZE(deep_deps);
 
+    BUILD_BUG_ON(ARRAY_SIZE(deep_features) != FEATURESET_NR_ENTRIES);
     BUILD_BUG_ON(ARRAY_SIZE(deep_deps) != NR_DEEP_DEPS);
 
     /* Fast early exit. */
#2 lore raw

PATCH 2/2 x86/cpu-policy: drop NR_DEEP_DEPS

In reply to Jan Beulich

The constant is solely used in a build time check of the array size of x86_cpu_policy_lookup_deep_deps():deep_deps[], thus merely proving that Python got its internal calculations right. There's no real dependency on this constant expressing the number of elements in INIT_DEEP_DEPS.

xen/lib/x86/cpuid.c +0 -1
@@ -299,7 +299,6 @@ const uint32_t *x86_cpu_policy_lookup_de
     unsigned int start = 0, end = ARRAY_SIZE(deep_deps);
 
     BUILD_BUG_ON(ARRAY_SIZE(deep_features) != FEATURESET_NR_ENTRIES);
-    BUILD_BUG_ON(ARRAY_SIZE(deep_deps) != NR_DEEP_DEPS);
 
     /* Fast early exit. */
     if ( !test_bit(feature, deep_features) )
xen/tools/gen-cpuid.py +0 -5
@@ -37,7 +37,6 @@ class State(object):
         self.hvm_hap_max = set() # HVM HAP max features
         self.bitfields = [] # Text to declare named bitfields in C
         self.deep_deps = {} # { feature num => dependant features }
-        self.nr_deep_deps = 0 # Number of entries in deep_deps
         self.deep_features = set() # featureset of keys in deep_deps
 
 def parse_definitions(state):
@@ -362,7 +361,6 @@ def crunch_numbers(state):
         state.deep_deps[feat] = seen[1:]
 
     state.deep_features = deps.keys()
-    state.nr_deep_deps = len(state.deep_deps.keys())
 
     # Calculate the bitfield name declarations.  Leave 4 placeholders on the end
     for word in range(state.nr_entries + 4):
@@ -421,8 +419,6 @@ def write_results(state):
 
 #define INIT_HVM_HAP_MAX_FEATURES { \\\n%s\n}
 
-#define NR_DEEP_DEPS %sU
-
 #define INIT_DEEP_FEATURES { \\\n%s\n}
 
 #define INIT_DEEP_DEPS { \\
@@ -436,7 +432,6 @@ def write_results(state):
        format_uint32s(state, state.hvm_shadow_max, 4),
        format_uint32s(state, state.hvm_hap_def, 4),
        format_uint32s(state, state.hvm_hap_max, 4),
-       state.nr_deep_deps,
        format_uint32s(state, state.deep_features, 4),
        ))