Re: [PATCH v3 04/13] uprobes: travers uprobe's consumer list locklessly under SRCU protection

Jiri Olsa
2024-08-22T17:35:49Z

On Thu, Aug 22, 2024 at 09:59:29AM -0700, Andrii Nakryiko wrote:
> On Thu, Aug 22, 2024 at 7:22 AM Jiri Olsa <olsajiri@gmail.com> wrote:
> >
> > On Mon, Aug 12, 2024 at 09:29:08PM -0700, Andrii Nakryiko wrote:
> >
> > SNIP
> >
> > > @@ -1125,18 +1103,31 @@ void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
> > > int err;
> > >
> > > down_write(&uprobe->register_rwsem);
> > > - if (WARN_ON(!consumer_del(uprobe, uc))) {
> > > - err = -ENOENT;
> > > - } else {
> > > - err = register_for_each_vma(uprobe, NULL);
> > > - /* TODO : cant unregister? schedule a worker thread */
> > > - if (unlikely(err))
> > > - uprobe_warn(current, "unregister, leaking uprobe");
> > > - }
> > > +
> > > + list_del_rcu(&uc->cons_node);
> >
> > hi,
> > I'm using this patchset as base for my changes and stumbled on this today,
> > I'm probably missing something, but should we keep the 'uprobe->consumer_rwsem'
> > lock around the list_del_rcu?
> >
>
> Note that original code also didn't take consumer_rwsem, but rather
> kept register_rwsem (which we still use).

humm, consumer_del took consumer_rwsem, right?

jirka

>
> There is a bit of mix of using register_rwsem and consumer_rwsem for
> working with consumer list. Code hints at this as being undesirable
> and "temporary", but you know, it's not broken :)
>
> Anyways, my point is that we didn't change the behavior, this should
> be fine. That _rcu() in list_del_rcu() is not about lockless
> modification of the list, but rather modification in such a way as to
> keep lockless RCU-protected *readers* correct. It just does some more
> memory barrier/release operations more carefully.
>
> > jirka
> >
> >
> > > + err = register_for_each_vma(uprobe, NULL);
> > > +
> > > up_write(&uprobe->register_rwsem);
> > >
> > > - if (!err)
> > > - put_uprobe(uprobe);
> > > + /* TODO : cant unregister? schedule a worker thread */
> > > + if (unlikely(err)) {
> > > + uprobe_warn(current, "unregister, leaking uprobe");
> > > + goto out_sync;
> > > + }
> > > +
> > > + put_uprobe(uprobe);
> > > +