From: Jan Beulich Date: Fri, 2 May 2025 07:44:49 +0000 (+0200) Subject: x86/alternatives: allow replacement code snippets to be re-used X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b458596ac3b2ac3c365769d4fd278ae17aa76d22;p=xen.git x86/alternatives: allow replacement code snippets to be re-used In a number of cases we use ALTERNATIVE_2 with both replacement insns / insn sequences being identical. Avoid emitting the same code twice, and instead alias the necessary helper labels to the existing ones. Signed-off-by: Jan Beulich Acked-by: Andrew Cooper --- diff --git a/xen/arch/x86/include/asm/alternative-asm.h b/xen/arch/x86/include/asm/alternative-asm.h index 83e8594f0e..22da9f89f1 100644 --- a/xen/arch/x86/include/asm/alternative-asm.h +++ b/xen/arch/x86/include/asm/alternative-asm.h @@ -51,6 +51,8 @@ #define decl_repl(insn, nr) .L\@_repl_s\()nr: insn; .L\@_repl_e\()nr: #define repl_len(nr) (.L\@_repl_e\()nr - .L\@_repl_s\()nr) +#define clone_repl(new, old) .equiv .L\@_repl_s\()new, .L\@_repl_s\()old; \ + .equiv .L\@_repl_e\()new, .L\@_repl_e\()old #define as_max(a, b) ((a) ^ (((a) ^ (b)) & -as_true((a) < (b)))) @@ -100,7 +102,11 @@ .section .altinstr_replacement, "ax", @progbits decl_repl(\newinstr1, 1) + .ifnes "\newinstr2", "\newinstr1" decl_repl(\newinstr2, 2) + .else + clone_repl(2, 1) + .endif .popsection .endm