summaryrefslogtreecommitdiff
path: root/arch/x86/include/asm/text-patching.h
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2022-03-08 18:30:20 +0300
committerPeter Zijlstra <peterz@infradead.org>2022-03-15 12:32:34 +0300
commitba27d1a80871eb8dbeddf34ec7d396c149cbb8d7 (patch)
tree93ba8f18ff513a2f74fdff43e436752d0cbb2d25 /arch/x86/include/asm/text-patching.h
parentbbf92368b0b1fe472d489e62d3340d7897e9c697 (diff)
downloadlinux-ba27d1a80871eb8dbeddf34ec7d396c149cbb8d7.tar.xz
x86/ibt,paravirt: Use text_gen_insn() for paravirt_patch()
Less duplication is more better. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Josh Poimboeuf <jpoimboe@redhat.com> Link: https://lore.kernel.org/r/20220308154317.697253958@infradead.org
Diffstat (limited to 'arch/x86/include/asm/text-patching.h')
-rw-r--r--arch/x86/include/asm/text-patching.h20
1 files changed, 14 insertions, 6 deletions
diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/text-patching.h
index 1c4cfb1c6e4f..c6015b407461 100644
--- a/arch/x86/include/asm/text-patching.h
+++ b/arch/x86/include/asm/text-patching.h
@@ -96,32 +96,40 @@ union text_poke_insn {
};
static __always_inline
-void *text_gen_insn(u8 opcode, const void *addr, const void *dest)
+void __text_gen_insn(void *buf, u8 opcode, const void *addr, const void *dest, int size)
{
- static union text_poke_insn insn; /* per instance */
- int size = text_opcode_size(opcode);
+ union text_poke_insn *insn = buf;
+
+ BUG_ON(size < text_opcode_size(opcode));
/*
* Hide the addresses to avoid the compiler folding in constants when
* referencing code, these can mess up annotations like
* ANNOTATE_NOENDBR.
*/
+ OPTIMIZER_HIDE_VAR(insn);
OPTIMIZER_HIDE_VAR(addr);
OPTIMIZER_HIDE_VAR(dest);
- insn.opcode = opcode;
+ insn->opcode = opcode;
if (size > 1) {
- insn.disp = (long)dest - (long)(addr + size);
+ insn->disp = (long)dest - (long)(addr + size);
if (size == 2) {
/*
* Ensure that for JMP8 the displacement
* actually fits the signed byte.
*/
- BUG_ON((insn.disp >> 31) != (insn.disp >> 7));
+ BUG_ON((insn->disp >> 31) != (insn->disp >> 7));
}
}
+}
+static __always_inline
+void *text_gen_insn(u8 opcode, const void *addr, const void *dest)
+{
+ static union text_poke_insn insn; /* per instance */
+ __text_gen_insn(&insn, opcode, addr, dest, text_opcode_size(opcode));
return &insn.text;
}