On Wed, Jul 10, 2024 at 11:16:31AM +0200, Peter Zijlstra wrote: > If it were an actual sequence count, I could make it work, but sadly, > not. Also, vma_end_write() seems to be missing :-( If anything it could > be used to lockdep annotate the thing. > > Mooo.. I need to stare more at this to see if perhaps it can be made to > work, but so far, no joy :/ See, this is what I want, except I can't close the race against VMA modification because of that crazy locking scheme :/ --- a/kernel/events/uprobes.c +++ b/kernel/events/uprobes.c @@ -2146,11 +2146,58 @@ static int is_trap_at_addr(struct mm_str return is_trap_insn(&opcode); } -static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) +#ifndef CONFIG_PER_VMA_LOCK +static struct uprobe *__find_active_uprobe(unsigned long bp_vaddr) +{ + return NULL; +} +#else +static struct uprobe *__find_active_uprobe(unsigned long bp_vaddr) { struct mm_struct *mm = current->mm; struct uprobe *uprobe = NULL; struct vm_area_struct *vma; + MA_STATE(mas, &mm->mm_mt, bp_vaddr, bp_vaddr); + + guard(rcu)(); + +again: + vma = mas_walk(&mas); + if (!vma) + return NULL; + + /* vma_write_start() -- in progress */ + if (READ_ONCE(vma->vm_lock_seq) == READ_ONCE(vma->vm_mm->mm_lock_seq)) + return NULL; + + /* + * Completely broken, because of the crazy vma locking scheme you + * cannot avoid the per-vma rwlock and doing so means you're racy + * against modifications. + * + * A simple actual seqcount would'be been cheaper and more usefull. + */ + + if (!valid_vma(vma, false)) + return NULL; + + struct inode = file_inode(vma->vm_file); + loff_t offset = vaddr_to_offset(vma, bp_vaddr); + + // XXX: if (vma_seq_retry(...)) goto again; + + return find_uprobe(inode, offset); +} +#endif + +static struct uprobe *find_active_uprobe(unsigned long bp_vaddr, int *is_swbp) +{ + struct uprobe *uprobe = __find_active_uprobe(bp_vaddr) + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma; + + if (uprobe) + return uprobe; mmap_read_lock(mm); vma = vma_lookup(mm, bp_vaddr);