Re: [PATCH v3 09/19] unwind: Introduce sframe user space unwinding
From: Peter Zijlstra
Date: Tue Oct 29 2024 - 14:10:34 EST
On Tue, Oct 29, 2024 at 09:50:18AM -0700, Josh Poimboeuf wrote:
> On Tue, Oct 29, 2024 at 02:27:09PM +0100, Peter Zijlstra wrote:
> > > +int sframe_add_section(unsigned long sframe_addr, unsigned long text_start,
> > > + unsigned long text_end)
> > > +{
> > > + struct mm_struct *mm = current->mm;
> > > + struct vm_area_struct *sframe_vma;
> > > +
> > > + mmap_read_lock(mm);
> >
> > DEFINE_GUARD(mmap_read_lock, struct mm_struct *,
> > mmap_read_lock(_T), mmap_read_unlock(_T))
> >
> > in include/linux/mmap_lock.h ?
>
> Will do.
>
> > > @@ -2784,6 +2785,16 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
> > > case PR_RISCV_SET_ICACHE_FLUSH_CTX:
> > > error = RISCV_SET_ICACHE_FLUSH_CTX(arg2, arg3);
> > > break;
> > > + case PR_ADD_SFRAME:
> > > + if (arg5)
> > > + return -EINVAL;
> > > + error = sframe_add_section(arg2, arg3, arg4);
> > > + break;
> > > + case PR_REMOVE_SFRAME:
> > > + if (arg3 || arg4 || arg5)
> > > + return -EINVAL;
> > > + error = sframe_remove_section(arg2);
> > > + break;
> > > default:
> > > error = -EINVAL;
> > > break;
> >
> > So I realize that mtree has an internal lock, but are we sure we don't
> > want a lock around those prctl()s?
>
> Not that I can tell? It relies on the mtree internal locking for
> atomicity.
>
> For sframe_remove_section() it uses srcu to delay the freeing until all
> sframe_find()'s have completed.
Yeah it does all that. But I was sorta looking at all that kmalloc and
copy from user stuff, but I suppose you can race that without problem.