mirror of
https://github.com/xen-project/xen.git
synced 2026-10-29 18:50:05 +01:00
x86/alt: Clean up struct alt_instr and its users
* Rename some fields for consistency and clarity, and use standard types.
* Don't opencode the use of ALT_{ORIG,REPL}_PTR().
No functional change.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
This commit is contained in:
1 parent
2ad245b467
commit
4faa8fdd87
2 files changed
+19
-19
No files matched your search
+12
-12
@@ -163,8 +163,6 @@ void init_or_livepatch apply_alternatives(const struct alt_instr *start,
|
||||
const struct alt_instr *end)
|
||||
{
|
||||
const struct alt_instr *a;
|
||||
u8 *instr, *replacement;
|
||||
u8 insnbuf[MAX_PATCH_LEN];
|
||||
|
||||
printk(KERN_INFO "alt table %p -> %p\n", start, end);
|
||||
|
||||
@@ -179,23 +177,25 @@ void init_or_livepatch apply_alternatives(const struct alt_instr *start,
|
||||
*/
|
||||
for ( a = start; a < end; a++ )
|
||||
{
|
||||
instr = (u8 *)&a->instr_offset + a->instr_offset;
|
||||
replacement = (u8 *)&a->repl_offset + a->repl_offset;
|
||||
BUG_ON(a->replacementlen > a->instrlen);
|
||||
BUG_ON(a->instrlen > sizeof(insnbuf));
|
||||
uint8_t *orig = ALT_ORIG_PTR(a);
|
||||
uint8_t *repl = ALT_REPL_PTR(a);
|
||||
uint8_t buf[MAX_PATCH_LEN];
|
||||
|
||||
BUG_ON(a->repl_len > a->orig_len);
|
||||
BUG_ON(a->orig_len > sizeof(buf));
|
||||
BUG_ON(a->cpuid >= NCAPINTS * 32);
|
||||
|
||||
if ( !boot_cpu_has(a->cpuid) )
|
||||
continue;
|
||||
|
||||
memcpy(insnbuf, replacement, a->replacementlen);
|
||||
memcpy(buf, repl, a->repl_len);
|
||||
|
||||
/* 0xe8/0xe9 are relative branches; fix the offset. */
|
||||
if ( a->replacementlen >= 5 && (*insnbuf & 0xfe) == 0xe8 )
|
||||
*(s32 *)(insnbuf + 1) += replacement - instr;
|
||||
if ( a->repl_len >= 5 && (*buf & 0xfe) == 0xe8 )
|
||||
*(int32_t *)(buf + 1) += repl - orig;
|
||||
|
||||
add_nops(insnbuf + a->replacementlen,
|
||||
a->instrlen - a->replacementlen);
|
||||
text_poke(instr, insnbuf, a->instrlen);
|
||||
add_nops(buf + a->repl_len, a->orig_len - a->repl_len);
|
||||
text_poke(orig, buf, a->orig_len);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
#include <xen/types.h>
|
||||
|
||||
struct alt_instr {
|
||||
s32 instr_offset; /* original instruction */
|
||||
s32 repl_offset; /* offset to replacement instruction */
|
||||
u16 cpuid; /* cpuid bit set for replacement */
|
||||
u8 instrlen; /* length of original instruction */
|
||||
u8 replacementlen; /* length of new instruction, <= instrlen */
|
||||
int32_t orig_offset; /* original instruction */
|
||||
int32_t repl_offset; /* offset to replacement instruction */
|
||||
uint16_t cpuid; /* cpuid bit set for replacement */
|
||||
uint8_t orig_len; /* length of original instruction */
|
||||
uint8_t repl_len; /* length of new instruction, <= instrlen */
|
||||
};
|
||||
|
||||
#define __ALT_PTR(a,f) ((u8 *)((void *)&(a)->f + (a)->f))
|
||||
#define ALT_ORIG_PTR(a) __ALT_PTR(a, instr_offset)
|
||||
#define __ALT_PTR(a,f) ((uint8_t *)((void *)&(a)->f + (a)->f))
|
||||
#define ALT_ORIG_PTR(a) __ALT_PTR(a, orig_offset)
|
||||
#define ALT_REPL_PTR(a) __ALT_PTR(a, repl_offset)
|
||||
|
||||
extern void add_nops(void *insns, unsigned int len);
|
||||
|
||||