From 0d32eb28447ebc9800d53a573839dbc4441cc3b2 Mon Sep 17 00:00:00 2001 From: Andrew Cooper Date: Wed, 21 May 2025 22:40:52 +0100 Subject: [PATCH] x86/alternatives: Factor out access to ideal_nops[] ... in order to rework the calculation. No functional change. Signed-off-by: Andrew Cooper Acked-by: Jan Beulich --- xen/arch/x86/alternative.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index c87665bffe..f0644055d3 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -86,6 +86,11 @@ static bool init_or_livepatch_read_mostly toolchain_nops_are_ideal; # define toolchain_nops_are_ideal false #endif +static const unsigned char *init_or_livepatch get_ideal_nops(unsigned int noplen) +{ + return ideal_nops[noplen]; +} + static void __init arch_init_ideal_nops(void) { switch ( boot_cpu_data.vendor ) @@ -116,7 +121,7 @@ static void __init arch_init_ideal_nops(void) } #ifdef HAVE_AS_NOPS_DIRECTIVE - if ( memcmp(ideal_nops[ASM_NOP_MAX], toolchain_nops, ASM_NOP_MAX) == 0 ) + if ( memcmp(get_ideal_nops(ASM_NOP_MAX), toolchain_nops, ASM_NOP_MAX) == 0 ) toolchain_nops_are_ideal = true; #endif } @@ -127,9 +132,11 @@ void init_or_livepatch add_nops(void *insns, unsigned int len) while ( len > 0 ) { unsigned int noplen = len; + if ( noplen > ASM_NOP_MAX ) noplen = ASM_NOP_MAX; - memcpy(insns, ideal_nops[noplen], noplen); + + memcpy(insns, get_ideal_nops(noplen), noplen); insns += noplen; len -= noplen; }