Re: [PATCH 3/3] uprobes: make uprobe_register() return struct uprobe *
From: Oleg Nesterov
Date: Thu Jul 11 2024 - 14:28:06 EST
On 07/11, Andrii Nakryiko wrote:
>
> On Thu, Jul 11, 2024 at 2:28 AM Oleg Nesterov <oleg@xxxxxxxxxx> wrote:
> >
> > On 07/10, Oleg Nesterov wrote:
> > >
> > > -void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
> > > +void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
> > > {
> > > - struct uprobe *uprobe;
> > > -
> > > - uprobe = find_uprobe(inode, offset);
> > > - if (WARN_ON(!uprobe))
> > > - return;
> > > -
> > > down_write(&uprobe->register_rwsem);
> > > __uprobe_unregister(uprobe, uc);
> > > up_write(&uprobe->register_rwsem);
> > > - put_uprobe(uprobe);
> >
> > OK, this is obviously wrong, needs get_uprobe/put_uprobe. __uprobe_unregister()
> > can free this uprobe, so up_write(&uprobe->register_rwsem) is not safe.
>
> uprobe_register(), given it returns an uprobe instance to the caller
> should keep refcount on it (it belongs to uprobe_consumer).
Of course. And again, this patch doesn't change the curent behaviour.
> That's
> what I did for my patches, are you going to do that as well?
>
> We basically do the same thing, just interfaces look a bit different.
Not sure. Well I do not really know, I didn't read your series to the
end, sorry ;) The same for V1/V2 from Peter so far.
But let me say this just in case... With or without this change,
currently uprobe_consumer doesn't have an "individual" ref to uprobe.
The fact that uprobe->consumers != NULL adds a reference.
Lets not discuss if this is good or bad right now, this cleanup is
only cleanup.
------------------------------------------------------------------------
Now, let me add another "just in case" note to explain what I am going
to do in V2.
So. this patch should turn uprobe_unregister() into something like
void uprobe_unregister(struct uprobe *uprobe, struct uprobe_consumer *uc)
{
// Ugly !!!! please kill me!!!
get_uprobe(uprobe);
down_write(&uprobe->register_rwsem);
__uprobe_unregister(uprobe, uc);
up_write(&uprobe->register_rwsem);
put_uprobe(uprobe);
}
to simplify this change. And the next (simple) patch will kill these
get_uprobe + put_uprobe, we just need to shift the (possibly) final
put_uprobe() from delete_uprobe() to unregister().
But of course, I will recheck before I send V2.
Oleg.