Skip to contentSkip to conversation

uprobes: simplify rip-relative handling

PATCH In review Denys Vlasenko 3 participants 3 messages May 1, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v4 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 correct for changing instruction length.

v2: Rebased on top of Oleg's latest changes and run-tested.
v3: Removed unnecessary cast.
Improved comments based on Oleg's feedback.
v4: Changed arch_uprobe_xol_was_trapped() comment to reflect new logic. Rebased to Oleg's uprobes/core,

CC Jim Keniston <[email protected]>
CC Masami Hiramatsu <[email protected]>
CC Srikar Dronamraju <[email protected]>
CC Ingo Molnar <[email protected]>
CC Oleg Nesterov <[email protected]>
---
 arch/x86/include/asm/uprobes.h |  3 --
 arch/x86/kernel/uprobes.c      | 72 ++++++++++++++++++------------------------
 2 files changed, 31 insertions(+), 44 deletions(-)
arch/x86/include/asm/uprobes.h +0 -3
index a040d49..7be3c07 100644
@@ -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 +31 -41

142 lines not on this page · raw message

Signature · 1 line
1.8.1.4
maintainer
#1 lore raw

Thanks, I hope that Jim's ack still applies to this version.

Quoted 2 lines · Denys Vlasenko

v4: Changed arch_uprobe_xol_was_trapped() comment to reflect new logic.

Hmm. I guess you meant arch_uprobe_post_xol()... please see below.

arch/x86/kernel/uprobes.c static int push_ret_address(struct pt_regs *regs, unsigned long ip) · line 414

Quoted 9 lines

static int default_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs) {

arch/x86/kernel/uprobes.c +2 -2
 	struct uprobe_task *utask = current->utask;
-	long correction = (long)(utask->vaddr - utask->xol_vaddr);
 
-	riprel_post_xol(auprobe, regs, &correction);
+	riprel_post_xol(auprobe, regs);
 	if (auprobe->def.fixups & UPROBE_FIX_IP) {
+		long correction = (long)(utask->vaddr - utask->xol_vaddr);

Can't resist, I'll remove this pointless cast ;)

Quoted 4 lines

* If the original instruction was a rip-relative instruction such as
* "movl %edx,0xnnnn(%rip)", we have instead executed an equivalent
- * instruction using a scratch register -- e.g., "movl %edx,(%rax)".
- * We need to restore the contents of the scratch register and adjust

Quoted 8 lines

- * the ip, keeping in mind that the instruction we executed is 4 bytes
- * shorter than the original instruction (since we squeezed out the offset
- * field). (FIX_RIP_AX or FIX_RIP_CX)
+ * instruction using a scratch register -- e.g., "movl %edx,0xnnnn(%rax)".
+ * We need to restore the contents of the scratch register
+ * (FIX_RIP_AX or FIX_RIP_CX).
*/
int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)

Perhaps it makes sense to move this part of the comment above default_post_xol_op() which actually does this...

I won't insist, I do not really care because I almost never read the comments anyway ;)

Oleg.

Reviewed-by
#2 lore raw
Quoted 1 line · Oleg Nesterov

Thanks, I hope that Jim's ack still applies to this version.

Yes. v4 looks fine, although Oleg has a good point about moving the comment. But I'd move more of the comment, starting with
* We have to fix things up as follows:

Quoted 39 lines · Denys Vlasenko
Quoted 2 lines

v4: Changed arch_uprobe_xol_was_trapped() comment to reflect new logic.

Hmm. I guess you meant arch_uprobe_post_xol()... please see below.

arch/x86/kernel/uprobes.c static int push_ret_address(struct pt_regs *regs, unsigned long ip) · line 414

Quoted 9 lines

static int default_post_xol_op(struct arch_uprobe *auprobe, struct pt_regs *regs) {

arch/x86/kernel/uprobes.c +2 -2
 	struct uprobe_task *utask = current->utask;
-	long correction = (long)(utask->vaddr - utask->xol_vaddr);
 
-	riprel_post_xol(auprobe, regs, &correction);
+	riprel_post_xol(auprobe, regs);
 	if (auprobe->def.fixups & UPROBE_FIX_IP) {
+		long correction = (long)(utask->vaddr - utask->xol_vaddr);

Can't resist, I'll remove this pointless cast ;)

Quoted 4 lines

* If the original instruction was a rip-relative instruction such as
* "movl %edx,0xnnnn(%rip)", we have instead executed an equivalent
- * instruction using a scratch register -- e.g., "movl %edx,(%rax)".
- * We need to restore the contents of the scratch register and adjust

Quoted 8 lines

- * the ip, keeping in mind that the instruction we executed is 4 bytes
- * shorter than the original instruction (since we squeezed out the offset
- * field). (FIX_RIP_AX or FIX_RIP_CX)
+ * instruction using a scratch register -- e.g., "movl %edx,0xnnnn(%rax)".
+ * We need to restore the contents of the scratch register
+ * (FIX_RIP_AX or FIX_RIP_CX).
*/
int arch_uprobe_post_xol(struct arch_uprobe *auprobe, struct pt_regs *regs)

Perhaps it makes sense to move this part of the comment above default_post_xol_op() which actually does this...

I won't insist, I do not really care because I almost never read the comments anyway ;)

Oleg.