]> xenbits.xensource.com Git - people/aperard/xen-unstable.git/commitdiff
x86/alternatives: build time check feature is in range
authorRoger Pau Monné <roger.pau@citrix.com>
Thu, 26 Sep 2024 10:14:31 +0000 (12:14 +0200)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 26 Sep 2024 13:18:03 +0000 (14:18 +0100)
Ensure at build time the feature(s) used for the alternative blocks are in
range of the featureset.

No functional change intended, as all current usages are correct.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/include/asm/alternative-asm.h
xen/arch/x86/include/asm/alternative.h

index 4092f5ba70a6350624bc2a86a9e115fa34c34278..83e8594f0eaf7751c335fdb72e57fa09ac159b28 100644 (file)
@@ -12,6 +12,9 @@
  * instruction. See apply_alternatives().
  */
 .macro altinstruction_entry orig, repl, feature, orig_len, repl_len, pad_len
+    .if \feature >= NCAPINTS * 32
+        .error "alternative feature outside of featureset range"
+    .endif
     .long \orig - .
     .long \repl - .
     .word \feature
index 69555d781ef9093013fb8d814f84bbb425e403b9..38472fb58e2da4e782419f24b99cdccccef00991 100644 (file)
@@ -7,6 +7,7 @@
 #include <xen/lib.h>
 #include <xen/stringify.h>
 #include <asm/asm-macros.h>
+#include <asm/cpufeatureset.h>
 
 struct __packed alt_instr {
     int32_t  orig_offset;   /* original instruction */
@@ -59,6 +60,9 @@ extern void alternative_branches(void);
                     alt_repl_len(n2)) "-" alt_orig_len)
 
 #define ALTINSTR_ENTRY(feature, num)                                    \
+        " .if " STR(feature) " >= " STR(NCAPINTS * 32) "\n"             \
+        " .error \"alternative feature outside of featureset range\"\n" \
+        " .endif\n"                                                     \
         " .long .LXEN%=_orig_s - .\n"             /* label           */ \
         " .long " alt_repl_s(num)" - .\n"         /* new instruction */ \
         " .word " __stringify(feature) "\n"       /* feature bit     */ \