Commit 5c22c472 authored by Hou Wenlong's avatar Hou Wenlong Committed by Borislav Petkov (AMD)

x86/paravirt: Use relative reference for the original instruction offset

Similar to the alternative patching, use a relative reference for original
instruction offset rather than absolute one, which saves 8 bytes for one
PARA_SITE entry on x86_64.  As a result, a R_X86_64_PC32 relocation is
generated instead of an R_X86_64_64 one, which also reduces relocation
metadata on relocatable builds. Hardcode the alignment to 4 now.

  [ bp: Massage commit message. ]
Signed-off-by: default avatarHou Wenlong <houwenlong.hwl@antgroup.com>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Reviewed-by: default avatarJuergen Gross <jgross@suse.com>
Link: https://lore.kernel.org/r/9e6053107fbaabc0d33e5d2865c5af2c67ec9925.1686301237.git.houwenlong.hwl@antgroup.com
parent b85ea95d
...@@ -743,16 +743,16 @@ void native_pv_lock_init(void) __init; ...@@ -743,16 +743,16 @@ void native_pv_lock_init(void) __init;
#else /* __ASSEMBLY__ */ #else /* __ASSEMBLY__ */
#define _PVSITE(ptype, ops, word, algn) \ #define _PVSITE(ptype, ops) \
771:; \ 771:; \
ops; \ ops; \
772:; \ 772:; \
.pushsection .parainstructions,"a"; \ .pushsection .parainstructions,"a"; \
.align algn; \ .align 4; \
word 771b; \ .long 771b-.; \
.byte ptype; \ .byte ptype; \
.byte 772b-771b; \ .byte 772b-771b; \
_ASM_ALIGN; \ .align 4; \
.popsection .popsection
...@@ -760,7 +760,7 @@ void native_pv_lock_init(void) __init; ...@@ -760,7 +760,7 @@ void native_pv_lock_init(void) __init;
#ifdef CONFIG_PARAVIRT_XXL #ifdef CONFIG_PARAVIRT_XXL
#define PARA_PATCH(off) ((off) / 8) #define PARA_PATCH(off) ((off) / 8)
#define PARA_SITE(ptype, ops) _PVSITE(ptype, ops, .quad, 8) #define PARA_SITE(ptype, ops) _PVSITE(ptype, ops)
#define PARA_INDIRECT(addr) *addr(%rip) #define PARA_INDIRECT(addr) *addr(%rip)
#ifdef CONFIG_DEBUG_ENTRY #ifdef CONFIG_DEBUG_ENTRY
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
/* These all sit in the .parainstructions section to tell us what to patch. */ /* These all sit in the .parainstructions section to tell us what to patch. */
struct paravirt_patch_site { struct paravirt_patch_site {
u8 *instr; /* original instructions */ s32 instr_offset; /* original instructions */
u8 type; /* type of this instruction */ u8 type; /* type of this instruction */
u8 len; /* length of original instruction */ u8 len; /* length of original instruction */
}; };
...@@ -263,11 +263,11 @@ extern struct paravirt_patch_template pv_ops; ...@@ -263,11 +263,11 @@ extern struct paravirt_patch_template pv_ops;
#define _paravirt_alt(insn_string, type) \ #define _paravirt_alt(insn_string, type) \
"771:\n\t" insn_string "\n" "772:\n" \ "771:\n\t" insn_string "\n" "772:\n" \
".pushsection .parainstructions,\"a\"\n" \ ".pushsection .parainstructions,\"a\"\n" \
_ASM_ALIGN "\n" \ " .align 4\n" \
_ASM_PTR " 771b\n" \ " .long 771b-.\n" \
" .byte " type "\n" \ " .byte " type "\n" \
" .byte 772b-771b\n" \ " .byte 772b-771b\n" \
_ASM_ALIGN "\n" \ " .align 4\n" \
".popsection\n" ".popsection\n"
/* Generate patchable code, with the default asm parameters. */ /* Generate patchable code, with the default asm parameters. */
......
...@@ -1431,20 +1431,22 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start, ...@@ -1431,20 +1431,22 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
{ {
struct paravirt_patch_site *p; struct paravirt_patch_site *p;
char insn_buff[MAX_PATCH_LEN]; char insn_buff[MAX_PATCH_LEN];
u8 *instr;
for (p = start; p < end; p++) { for (p = start; p < end; p++) {
unsigned int used; unsigned int used;
instr = (u8 *)&p->instr_offset + p->instr_offset;
BUG_ON(p->len > MAX_PATCH_LEN); BUG_ON(p->len > MAX_PATCH_LEN);
/* prep the buffer with the original instructions */ /* prep the buffer with the original instructions */
memcpy(insn_buff, p->instr, p->len); memcpy(insn_buff, instr, p->len);
used = paravirt_patch(p->type, insn_buff, (unsigned long)p->instr, p->len); used = paravirt_patch(p->type, insn_buff, (unsigned long)instr, p->len);
BUG_ON(used > p->len); BUG_ON(used > p->len);
/* Pad the rest with nops */ /* Pad the rest with nops */
add_nops(insn_buff + used, p->len - used); add_nops(insn_buff + used, p->len - used);
text_poke_early(p->instr, insn_buff, p->len); text_poke_early(instr, insn_buff, p->len);
} }
} }
extern struct paravirt_patch_site __start_parainstructions[], extern struct paravirt_patch_site __start_parainstructions[],
......
...@@ -240,7 +240,7 @@ patch_paravirt_call_sites(struct paravirt_patch_site *start, ...@@ -240,7 +240,7 @@ patch_paravirt_call_sites(struct paravirt_patch_site *start,
struct paravirt_patch_site *p; struct paravirt_patch_site *p;
for (p = start; p < end; p++) for (p = start; p < end; p++)
patch_call(p->instr, ct); patch_call((void *)&p->instr_offset + p->instr_offset, ct);
} }
static __init_or_module void static __init_or_module void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment