diff --git a/xen/arch/x86/alternative.c b/xen/arch/x86/alternative.c index 22af224f08..047bfc6e42 100644 --- a/xen/arch/x86/alternative.c +++ b/xen/arch/x86/alternative.c @@ -378,13 +378,6 @@ static int init_or_livepatch _apply_alternatives(struct alt_instr *start, text_poke(orig, buf, total_len); } - /* - * Clobber endbr64 instructions now that altcall has finished optimising - * all indirect branches to direct ones. - */ - if ( force && system_state < SYS_STATE_active ) - seal_endbr64(); - return 0; } @@ -533,6 +526,8 @@ static int __init cf_check nmi_apply_alternatives( rc = apply_alt_calls(__alt_call_sites_start, __alt_call_sites_end); if ( rc ) panic("Unable to apply alternative calls: %d\n", rc); + + seal_endbr64(); } /* diff --git a/xen/arch/x86/include/asm/alternative-call.h b/xen/arch/x86/include/asm/alternative-call.h index 49a04a7cc4..bbc49a5274 100644 --- a/xen/arch/x86/include/asm/alternative-call.h +++ b/xen/arch/x86/include/asm/alternative-call.h @@ -2,7 +2,8 @@ #ifndef X86_ALTERNATIVE_CALL_H #define X86_ALTERNATIVE_CALL_H -#include +#include +#include /* Simply the relative position of the source call. */ struct alt_call { @@ -86,8 +87,10 @@ struct alt_call { rettype ret_; \ register unsigned long r10_ asm("r10"); \ register unsigned long r11_ asm("r11"); \ - asm volatile (ALTERNATIVE("call *%c[addr](%%rip)", "call .", \ - X86_FEATURE_ALWAYS) \ + asm volatile ("1: call *%c[addr](%%rip)\n\t" \ + ".pushsection .alt_call_sites, \"a\", @progbits\n\t" \ + ".long 1b - .\n\t" \ + ".popsection" \ : ALT_CALL ## n ## _OUT, "=a" (ret_), \ "=r" (r10_), "=r" (r11_) ASM_CALL_CONSTRAINT \ : [addr] "i" (&(func)), "g" (func) \