x86/alt: Support for automatic padding calculations
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 9 Feb 2018 12:47:58 +0000 (12:47 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 9 Mar 2018 14:44:16 +0000 (14:44 +0000)
commit4008c71d7af2e367b0d236b205576b941d5e2df4
tree8666f28166b0ffd61ae61f71499679c5fd8dcada
parentf54999f6147c9cde143cc50483f0187f75de188a
x86/alt: Support for automatic padding calculations

The correct amount of padding in an origin patch site can be calculated
automatically, based on the relative lengths of the replacements.

This requires a bit of trickery to calculate correctly, especially in the
ALTENRATIVE_2 case where a branchless max() calculation in needed.  The
calculation is further complicated because GAS's idea of true is -1 rather
than 1, which is why the extra negations are required.

Additionally, have apply_alternatives() attempt to optimise the padding nops.
This is complicated by the fact that we must not attempt to optimise nops over
an origin site which has already been modified.

To keep track of this, add a priv field to struct alt_instr, which gets
modified by apply_alternatives().  This method is used in preference to a
local variable in case we make multiple passes.  One extra requirement is that
alt_instr's referring to the same origin site must now be consecutive, but we
already have this property.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/Rules.mk
xen/arch/x86/alternative.c
xen/include/asm-x86/alternative-asm.h
xen/include/asm-x86/alternative.h