Skip to contentSkip to conversation

x86: calculate number of synthetic feature and bug enumerators

PATCH In review Jan Beulich 2 participants 3 messages Jan 19 – Feb 2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: calculate number of synthetic feature and bug enumerators

Rather than spelling out their amounts (requiring updates when multiples of 32 are crossed), introduce a sentinel each and calculate the two numbers from those.

No difference in generated code, albeit debug info size grows quite a bit.

---
This is an alternative to "x86: guard synthetic feature and bug enumerators", bulding upon the expectation that when adding to the end of either list people will notice the sentinel and not forget to update it.

xen/arch/x86/include/asm/cpufeatures.h +8 -2
@@ -7,7 +7,6 @@
 #define FSCAPINTS FEATURESET_NR_ENTRIES
 
 /* Synthetic words follow the featureset words. */
-#define X86_NR_SYNTH 2
 #define X86_SYNTH(x) (FSCAPINTS * 32 + (x))
 
 /* Synthetic features */
@@ -44,9 +43,11 @@ XEN_CPUFEATURE(IBPB_ENTRY_HVM,    X86_SY
 XEN_CPUFEATURE(USE_VMCALL,        X86_SYNTH(30)) /* Use VMCALL instead of VMMCALL */
 XEN_CPUFEATURE(PDX_COMPRESSION,   X86_SYNTH(31)) /* PDX compression */
 XEN_CPUFEATURE(XEN_REP_MOVSB,     X86_SYNTH(32)) /* REP MOVSB used for memcpy() */
+XEN_CPUFEATURE(nr,                X86_SYNTH(33)) /* Number of synthetic features */
+
+#define X86_NR_SYNTH DIV_ROUND_UP(X86_FEATURE_nr - FSCAPINTS * 32, 32)
 
 /* Bug words follow the synthetic words. */
-#define X86_NR_BUG 1
 #define X86_BUG(x) ((FSCAPINTS + X86_NR_SYNTH) * 32 + (x))
 
 #define X86_BUG_FPU_PTRS          X86_BUG( 0) /* (F)X{SAVE,RSTOR} doesn't save/restore FOP/FIP/FDP. */
@@ -64,5 +65,10 @@ XEN_CPUFEATURE(XEN_REP_MOVSB,     X86_SY
 #define X86_SPEC_BHB_LOOPS        X86_BUG(20) /* Use clear_bhb_loops for BHI mitigation.*/
 #define X86_SPEC_BHB_LOOPS_LONG   X86_BUG(21) /* Upgrade clear_bhb_loops to the "long" sequence. */
 
+#define X86_BUG_nr                X86_BUG(22) /* Number of bug identifiers */
+
+#define X86_NR_BUG DIV_ROUND_UP(X86_BUG_nr - (FSCAPINTS + X86_NR_SYNTH) * 32, \
+                                32)
+
 /* Total number of capability words, inc synth and bug words. */
 #define NCAPINTS (FSCAPINTS + X86_NR_SYNTH + X86_NR_BUG) /* N 32-bit words worth of info */
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jan Beulich

Rather than spelling out their amounts (requiring updates when multiples of 32 are crossed), introduce a sentinel each and calculate the two numbers from those.

No difference in generated code, albeit debug info size grows quite a bit.

Presumably because of the substantial increase in preprocessed output?

Quoted 6 lines

---
This is an alternative to "x86: guard synthetic feature and bug enumerators", bulding upon the expectation that when adding to the end of either list people will notice the sentinel and not forget to update it.

The extra preprocessing overhead is not ideal, but it's certainly preferable to the first version.

#2 lore raw
Quoted 8 lines · Andrew Cooper
Quoted 5 lines · Jan Beulich

Rather than spelling out their amounts (requiring updates when multiples of 32 are crossed), introduce a sentinel each and calculate the two numbers from those.

No difference in generated code, albeit debug info size grows quite a bit.

Presumably because of the substantial increase in preprocessed output?

I wouldn't expect that to matter. My suspicion was that de-duplication might not work very well there. But I didn't go check, as debug info size really isn't a primary concern to me.

Quoted 10 lines
Quoted 5 lines

---
This is an alternative to "x86: guard synthetic feature and bug enumerators", bulding upon the expectation that when adding to the end of either list people will notice the sentinel and not forget to update it.

The extra preprocessing overhead is not ideal, but it's certainly preferable to the first version.

Thanks.

Jan