]> xenbits.xensource.com Git - xen.git/commitdiff
x86/alternatives: allow replacement code snippets to be re-used
authorJan Beulich <jbeulich@suse.com>
Fri, 2 May 2025 07:44:49 +0000 (09:44 +0200)
committerJan Beulich <jbeulich@suse.com>
Fri, 2 May 2025 07:44:49 +0000 (09:44 +0200)
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 <jbeulich@suse.com>
Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/arch/x86/include/asm/alternative-asm.h

index 83e8594f0eaf7751c335fdb72e57fa09ac159b28..22da9f89f15ab6f719e7eff71acdf40abdca291f 100644 (file)
@@ -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))))
 
     .section .altinstr_replacement, "ax", @progbits
 
     decl_repl(\newinstr1, 1)
+    .ifnes "\newinstr2", "\newinstr1"
     decl_repl(\newinstr2, 2)
+    .else
+    clone_repl(2, 1)
+    .endif
 
     .popsection
 .endm