Skip to content

Commit

Permalink
x86/alternatives: build time check feature is in range
Browse files Browse the repository at this point in the history
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é <[email protected]>
Reviewed-by: Andrew Cooper <[email protected]>
  • Loading branch information
royger authored and andyhhp committed Sep 26, 2024
1 parent aa5a06d commit a184ac7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xen/arch/x86/include/asm/alternative-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions xen/arch/x86/include/asm/alternative.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */ \
Expand Down

0 comments on commit a184ac7

Please sign in to comment.