From: Oleg Nesterov <oleg@redhat.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: andrii@kernel.org, mhiramat@kernel.org, peterz@infradead.org,
clm@meta.com, jolsa@kernel.org, mingo@kernel.org,
paulmck@kernel.org, rostedt@goodmis.org,
linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH 3/3] uprobes: make uprobe_register() return struct uprobe *
Date: Thu, 11 Jul 2024 20:26:06 +0200 [thread overview]
Message-ID: <20240711182606.GA29154@redhat.com> (raw)
In-Reply-To: <CAEf4Bzb0ErnW0o09fk2TCJnY3LNW7U4aB0YcUJqKjfNH+m-uyA@mail.gmail.com>
On 07/11, Andrii Nakryiko wrote:
>
> On Thu, Jul 11, 2024 at 2:28 AM Oleg Nesterov <oleg@redhat.com> 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.
next prev parent reply other threads:[~2024-07-11 18:27 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240710140017.GA1074@redhat.com>
2024-07-10 16:30 ` [PATCH 0/3] uprobes: future cleanups for review Oleg Nesterov
2024-07-10 16:30 ` [PATCH 1/3] uprobes: kill uprobe_register_refctr() Oleg Nesterov
2024-07-10 18:03 ` Andrii Nakryiko
2024-07-10 19:32 ` Oleg Nesterov
2024-07-10 16:31 ` [PATCH 2/3] uprobes: simplify error handling for alloc_uprobe() Oleg Nesterov
2024-07-11 15:18 ` Masami Hiramatsu
2024-07-10 16:31 ` [PATCH 3/3] uprobes: make uprobe_register() return struct uprobe * Oleg Nesterov
2024-07-10 16:48 ` Jiri Olsa
2024-07-10 18:23 ` Andrii Nakryiko
2024-07-10 19:38 ` Jiri Olsa
2024-07-10 19:48 ` Andrii Nakryiko
2024-07-10 19:20 ` Oleg Nesterov
2024-07-10 18:21 ` Andrii Nakryiko
2024-07-10 20:16 ` Oleg Nesterov
2024-07-10 20:46 ` Andrii Nakryiko
2024-07-11 9:26 ` Oleg Nesterov
2024-07-11 17:11 ` Andrii Nakryiko
2024-07-11 18:26 ` Oleg Nesterov [this message]
2024-07-11 8:27 ` [PATCH 0/3] uprobes: future cleanups for review Peter Zijlstra
2024-07-11 8:45 ` Oleg Nesterov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240711182606.GA29154@redhat.com \
--to=oleg@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andrii@kernel.org \
--cc=clm@meta.com \
--cc=jolsa@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).