Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

kprobes: treewide: Use 'kprobe_opcode_t *' for the code address in get_optimized_kprobe()

Since get_optimized_kprobe() is only used inside kprobes,
it doesn't need to use 'unsigned long' type for 'addr' parameter.
Make it use 'kprobe_opcode_t *' for the 'addr' parameter and
subsequent call of arch_within_optimized_kprobe() also should use
'kprobe_opcode_t *'.

Note that MAX_OPTIMIZED_LENGTH and RELATIVEJUMP_SIZE are defined
by byte-size, but the size of 'kprobe_opcode_t' depends on the
architecture. Therefore, we must be careful when calculating
addresses using those macros.

Link: https://lkml.kernel.org/r/163163040680.489837.12133032364499833736.stgit@devnote2

Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

authored by

Masami Hiramatsu and committed by
Steven Rostedt (VMware)
c42421e2 57d4e317

+16 -15
+4 -3
arch/arm/probes/kprobes/opt-arm.c
··· 347 347 } 348 348 349 349 int arch_within_optimized_kprobe(struct optimized_kprobe *op, 350 - unsigned long addr) 350 + kprobe_opcode_t *addr) 351 351 { 352 - return ((unsigned long)op->kp.addr <= addr && 353 - (unsigned long)op->kp.addr + RELATIVEJUMP_SIZE > addr); 352 + return (op->kp.addr <= addr && 353 + op->kp.addr + (RELATIVEJUMP_SIZE / sizeof(kprobe_opcode_t)) > addr); 354 + 354 355 } 355 356 356 357 void arch_remove_optimized_kprobe(struct optimized_kprobe *op)
+3 -3
arch/powerpc/kernel/optprobes.c
··· 301 301 } 302 302 } 303 303 304 - int arch_within_optimized_kprobe(struct optimized_kprobe *op, unsigned long addr) 304 + int arch_within_optimized_kprobe(struct optimized_kprobe *op, kprobe_opcode_t *addr) 305 305 { 306 - return ((unsigned long)op->kp.addr <= addr && 307 - (unsigned long)op->kp.addr + RELATIVEJUMP_SIZE > addr); 306 + return (op->kp.addr <= addr && 307 + op->kp.addr + (RELATIVEJUMP_SIZE / sizeof(kprobe_opcode_t)) > addr); 308 308 }
+3 -3
arch/x86/kernel/kprobes/opt.c
··· 367 367 368 368 /* Check the addr is within the optimized instructions. */ 369 369 int arch_within_optimized_kprobe(struct optimized_kprobe *op, 370 - unsigned long addr) 370 + kprobe_opcode_t *addr) 371 371 { 372 - return ((unsigned long)op->kp.addr <= addr && 373 - (unsigned long)op->kp.addr + op->optinsn.size > addr); 372 + return (op->kp.addr <= addr && 373 + op->kp.addr + op->optinsn.size > addr); 374 374 } 375 375 376 376 /* Free optimized instruction slot */
+1 -1
include/linux/kprobes.h
··· 329 329 struct list_head *done_list); 330 330 extern void arch_unoptimize_kprobe(struct optimized_kprobe *op); 331 331 extern int arch_within_optimized_kprobe(struct optimized_kprobe *op, 332 - unsigned long addr); 332 + kprobe_opcode_t *addr); 333 333 334 334 extern void opt_pre_handler(struct kprobe *p, struct pt_regs *regs); 335 335
+5 -5
kernel/kprobes.c
··· 485 485 * Return an optimized kprobe whose optimizing code replaces 486 486 * instructions including 'addr' (exclude breakpoint). 487 487 */ 488 - static struct kprobe *get_optimized_kprobe(unsigned long addr) 488 + static struct kprobe *get_optimized_kprobe(kprobe_opcode_t *addr) 489 489 { 490 490 int i; 491 491 struct kprobe *p = NULL; 492 492 struct optimized_kprobe *op; 493 493 494 494 /* Don't check i == 0, since that is a breakpoint case. */ 495 - for (i = 1; !p && i < MAX_OPTIMIZED_LENGTH; i++) 496 - p = get_kprobe((void *)(addr - i)); 495 + for (i = 1; !p && i < MAX_OPTIMIZED_LENGTH / sizeof(kprobe_opcode_t); i++) 496 + p = get_kprobe(addr - i); 497 497 498 498 if (p && kprobe_optready(p)) { 499 499 op = container_of(p, struct optimized_kprobe, kp); ··· 967 967 lockdep_assert_held(&text_mutex); 968 968 969 969 /* Find the overlapping optimized kprobes. */ 970 - _p = get_optimized_kprobe((unsigned long)p->addr); 970 + _p = get_optimized_kprobe(p->addr); 971 971 if (unlikely(_p)) 972 972 /* Fallback to unoptimized kprobe */ 973 973 unoptimize_kprobe(_p, true); ··· 989 989 if (!kprobe_queued(p)) { 990 990 arch_disarm_kprobe(p); 991 991 /* If another kprobe was blocked, re-optimize it. */ 992 - _p = get_optimized_kprobe((unsigned long)p->addr); 992 + _p = get_optimized_kprobe(p->addr); 993 993 if (unlikely(_p) && reopt) 994 994 optimize_kprobe(_p); 995 995 }