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.

uprobes: Add do_ref_ctr argument to uprobe_write function

Making update_ref_ctr call in uprobe_write conditional based
on do_ref_ctr argument. This way we can use uprobe_write for
instruction update without doing ref_ctr_offset update.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lore.kernel.org/r/20250720112133.244369-8-jolsa@kernel.org

authored by

Jiri Olsa and committed by
Peter Zijlstra
18a11125 ec46350f

+5 -5
+1 -1
include/linux/uprobes.h
··· 200 200 extern int uprobe_write_opcode(struct arch_uprobe *auprobe, struct vm_area_struct *vma, unsigned long vaddr, uprobe_opcode_t, 201 201 bool is_register); 202 202 extern int uprobe_write(struct arch_uprobe *auprobe, struct vm_area_struct *vma, const unsigned long opcode_vaddr, 203 - uprobe_opcode_t *insn, int nbytes, uprobe_write_verify_t verify, bool is_register); 203 + uprobe_opcode_t *insn, int nbytes, uprobe_write_verify_t verify, bool is_register, bool do_update_ref_ctr); 204 204 extern struct uprobe *uprobe_register(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc); 205 205 extern int uprobe_apply(struct uprobe *uprobe, struct uprobe_consumer *uc, bool); 206 206 extern void uprobe_unregister_nosync(struct uprobe *uprobe, struct uprobe_consumer *uc);
+4 -4
kernel/events/uprobes.c
··· 491 491 bool is_register) 492 492 { 493 493 return uprobe_write(auprobe, vma, opcode_vaddr, &opcode, UPROBE_SWBP_INSN_SIZE, 494 - verify_opcode, is_register); 494 + verify_opcode, is_register, true /* do_update_ref_ctr */); 495 495 } 496 496 497 497 int uprobe_write(struct arch_uprobe *auprobe, struct vm_area_struct *vma, 498 498 const unsigned long insn_vaddr, uprobe_opcode_t *insn, int nbytes, 499 - uprobe_write_verify_t verify, bool is_register) 499 + uprobe_write_verify_t verify, bool is_register, bool do_update_ref_ctr) 500 500 { 501 501 const unsigned long vaddr = insn_vaddr & PAGE_MASK; 502 502 struct mm_struct *mm = vma->vm_mm; ··· 537 537 } 538 538 539 539 /* We are going to replace instruction, update ref_ctr. */ 540 - if (!ref_ctr_updated && uprobe->ref_ctr_offset) { 540 + if (do_update_ref_ctr && !ref_ctr_updated && uprobe->ref_ctr_offset) { 541 541 ret = update_ref_ctr(uprobe, mm, is_register ? 1 : -1); 542 542 if (ret) { 543 543 folio_put(folio); ··· 589 589 590 590 out: 591 591 /* Revert back reference counter if instruction update failed. */ 592 - if (ret < 0 && ref_ctr_updated) 592 + if (do_update_ref_ctr && ret < 0 && ref_ctr_updated) 593 593 update_ref_ctr(uprobe, mm, is_register ? -1 : 1); 594 594 595 595 /* try collapse pmd for compound page */