Skip to content

Commit

Permalink
x86/alternative: Remove text_poke_loc::len
Browse files Browse the repository at this point in the history
Per the BUG_ON(len != insn.length) in text_poke_loc_init(), tp->len
must indeed be the same as text_opcode_size(tp->opcode). Use this to
remove this field from the structure.

Sadly, due to 8 byte alignment, this only increases the structure
padding.

Tested-by: Alexei Starovoitov <ast@kernel.org>
Tested-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20191111132457.989922744@infradead.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Nov 27, 2019
1 parent 67c1d4a commit 97e6c97
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions arch/x86/kernel/alternative.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,6 @@ static void do_sync_core(void *info)

struct text_poke_loc {
void *addr;
int len;
s32 rel32;
u8 opcode;
const u8 text[POKE_MAX_OPCODE_SIZE];
Expand All @@ -965,6 +964,7 @@ int notrace poke_int3_handler(struct pt_regs *regs)
{
struct text_poke_loc *tp;
void *ip;
int len;

/*
* Having observed our INT3 instruction, we now must observe
Expand Down Expand Up @@ -1004,7 +1004,8 @@ int notrace poke_int3_handler(struct pt_regs *regs)
return 0;
}

ip += tp->len;
len = text_opcode_size(tp->opcode);
ip += len;

switch (tp->opcode) {
case INT3_INSN_OPCODE:
Expand Down Expand Up @@ -1085,10 +1086,12 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
* Second step: update all but the first byte of the patched range.
*/
for (do_sync = 0, i = 0; i < nr_entries; i++) {
if (tp[i].len - sizeof(int3) > 0) {
int len = text_opcode_size(tp[i].opcode);

if (len - sizeof(int3) > 0) {
text_poke((char *)tp[i].addr + sizeof(int3),
(const char *)tp[i].text + sizeof(int3),
tp[i].len - sizeof(int3));
len - sizeof(int3));
do_sync++;
}
}
Expand Down Expand Up @@ -1141,7 +1144,6 @@ void text_poke_loc_init(struct text_poke_loc *tp, void *addr,
BUG_ON(len != insn.length);

tp->addr = addr;
tp->len = len;
tp->opcode = insn.opcode.bytes[0];

switch (tp->opcode) {
Expand Down

0 comments on commit 97e6c97

Please sign in to comment.