uprobes: simplify rip-relative handling
PATCH v2 1/1 uprobes: simplify rip-relative handling
It is possible to replace rip-relative addressing mode with addressing mode of the same length: (reg+disp32). This eliminates the need to fix up immediate and instruction length.
v2: Rebased on top of Oleg's latest changes and run-tested.
--- arch/x86/include/asm/uprobes.h | 3 --- arch/x86/kernel/uprobes.c | 51 ++++++++++++++++-------------------------- 2 files changed, 19 insertions(+), 35 deletions(-)
arch/x86/include/asm/uprobes.h +0 -3
@@ -50,9 +50,6 @@ struct arch_uprobe {u8 opc1; } branch;struct { -#ifdef CONFIG_X86_64 -long riprel_target; -#endif u8 fixups;u8 ilen; } def;
arch/x86/kernel/uprobes.c +19 -32
114 lines not on this page · raw message
Signature · 1 line
1.8.1.4
Oleg Nesterov
maintainerQuoted 5 lines · Denys Vlasenko
It is possible to replace rip-relative addressing mode with addressing mode of the same length: (reg+disp32). This eliminates the need to fix up immediate and instruction length.
"and change instruction length", I presume.
I like this patch very much, and I would be happy to ack everything except this part:
Quoted 15 lines
arch/x86/kernel/uprobes.c +2
-6@@ -307,22 +313,13 @@ static void riprel_analyze(struct arch_uprobe *auprobe, struct insn *insn)* #1) for the scratch register. */ auprobe->def.fixups |=UPROBE_FIX_RIP_CX ; -/* Change modrm from 00 000 101 to 00 000 001. */ - *cursor =0x1 ; +/* Change modrm from 00 000 101 to 10 000 001. */ + *cursor =0x81 ; }else {/* Use %rax (register #0) for the scratch register. */ auprobe->def.fixups |=UPROBE_FIX_RIP_AX ; -/* Change modrm from 00 xxx 101 to 00 xxx 000 */ - *cursor = (reg <<3 ); - } -
arch/x86/kernel/uprobes.c static void riprel_analyze(struct arch_uprobe *auprobe, struct insn *insn) · line 323
Quoted 10 lines
arch/x86/kernel/uprobes.c +2
-7-/* Target address = address of next instruction + (signed) offset */ - auprobe->def.riprel_target = (long )insn->length + insn->displacement.value; - -/* Displacement field is gone; slide immediate field (if any) over. */ -if (insn->immediate.nbytes) { - cursor++; -memmove (cursor, cursor + insn->displacement.nbytes, insn->immediate.nbytes); +/* Change modrm from 00 xxx 101 to 10 xxx 000 */ + *cursor = (reg <<3 ) |0x80 ; }
As you know, this is black magic for me.
Masami, Jim, please review and ack/nack?
arch/x86/kernel/uprobes.c static void riprel_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs) · line 343
Quoted 6 lines
arch/x86/kernel/uprobes.c +1
-1@@ -343,26 +340,17 @@ static void riprel_pre_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)unsigned long *sr =scratch_reg (auprobe, regs); utask->autask.saved_scratch_register = *sr; - *sr = utask->vaddr + auprobe->def.riprel_target; + *sr = utask->vaddr + (int )auprobe->def.ilen;
^^^^^
Why? This is pointless and even misleading. I'll remove this part if you do not object.
Oleg.