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: Wed, 10 Jul 2024 22:16:51 +0200 [thread overview]
Message-ID: <20240710201651.GG9228@redhat.com> (raw)
In-Reply-To: <CAEf4BzZa0Ye83QfTbw6Sw3ERg2PJ7ioN_pEFHYui6JGEHhOg4Q@mail.gmail.com>
On 07/10, Andrii Nakryiko wrote:
>
> On Wed, Jul 10, 2024 at 9:33 AM Oleg Nesterov <oleg@redhat.com> wrote:
> >
> > This way uprobe_unregister() and uprobe_apply() do not need find_uprobe() +
> > put_uprobe(). And to me this change simplifies the code a bit.
> >
> > Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> > ---
> > include/linux/uprobes.h | 14 ++++++------
> > kernel/events/uprobes.c | 45 ++++++++++++-------------------------
> > kernel/trace/bpf_trace.c | 12 +++++-----
> > kernel/trace/trace_uprobe.c | 28 +++++++++++------------
> > 4 files changed, 41 insertions(+), 58 deletions(-)
> >
> > diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
> > index aa89a8b67039..399509befcf4 100644
> > --- a/include/linux/uprobes.h
> > +++ b/include/linux/uprobes.h
>
> I don't see struct uprobe forward-declared in this header, maybe we
> should add it?
Probably yes, thanks... Although the current code already uses
struct uprobes * without forward-declaration at least if CONFIG_UPROBES=y.
Thanks, will add.
> > static inline int
> > -uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool add)
> > +uprobe_apply(struct uprobe* uprobe, struct uprobe_consumer *uc, bool add)
> > {
> > return -ENOSYS;
> > }
>
> complete aside, when I was looking at this code I was wondering why we
> even need uprobe_apply, it looks like some hacky variant of
> uprobe_register and uprobe_unregister.
All I can say is that
- I can hardly recall this logic, I'll try to do this tomorrow
and write another email
- in any case this logic is ugly and needs more cleanups
- but this patch only tries to simplify this code without any
visible changes.
> > @@ -1133,41 +1126,39 @@ EXPORT_SYMBOL_GPL(uprobe_unregister);
> > * refcount is released when the last @uc for the @uprobe
> > * unregisters. Caller of uprobe_register() is required to keep @inode
> > * (and the containing mount) referenced.
> > - *
> > - * Return errno if it cannot successully install probes
> > - * else return 0 (success)
>
> mention that it never returns NULL, but rather encodes error code
> inside the pointer on error? It's an important part of the contract.
OK...
> > /*
>
> this should be /** for doccomment checking (you'd get a warning for
> missing @uprobe if there was this extra star)
Well, this is what we have before this patch, but OK
> > * uprobe_apply - unregister an already registered probe.
> > - * @inode: the file in which the probe has to be removed.
> > - * @offset: offset from the start of the file.
>
> add @uprobe description now?
If only I knew what this @uprobe description can say ;)
> > @@ -3180,10 +3181,8 @@ static void bpf_uprobe_unregister(struct path *path, struct bpf_uprobe *uprobes,
> > {
> > u32 i;
> >
> > - for (i = 0; i < cnt; i++) {
> > - uprobe_unregister(d_real_inode(path->dentry), uprobes[i].offset,
> > - &uprobes[i].consumer);
> > - }
> > + for (i = 0; i < cnt; i++)
>
> you'll now need !IS_ERR_OR_NULL(uprobes[i].uprobe) check (or just NULL
> check if you null-out it below)
Hmm... are you sure? I'll re-check... See also the end of my email.
> > @@ -3477,11 +3476,12 @@ int bpf_uprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr
> > &bpf_uprobe_multi_link_lops, prog);
> >
> > for (i = 0; i < cnt; i++) {
> > - err = uprobe_register(d_real_inode(link->path.dentry),
> > + uprobes[i].uprobe = uprobe_register(d_real_inode(link->path.dentry),
>
> will uprobe keep inode alive as long as uprobe is attached?
Why? No, this patch doesn't (shouldn't) change the current behaviour.
The users still need kern_path/path_put to, say, prevent umount.
> we can NULL-out uprobe on error for bpf_uprobe_unregister() to handle
> only NULL vs non-NULL case
Not sure I understand...
> or maybe better yet let's just have local struct uprobe variable and
> only assign it if registration succeeded
We can, but
> (still need NULL check in
> bpf_uprobe_unregister above)
Why?
If bpf_uprobe_unregister() is called by bpf_uprobe_multi_link_attach() on
error, it passes cnt = i where is the 1st failed uprobe index. IOW,
uptobes[i].uprobe can't be IS_ERR_OR_NULL() in the 0..cnt-1 range.
If it is called by bpf_uprobe_multi_link_release() then the whole
0..umulti_link->cnt-1 range should be fine?
Oleg.
next prev parent reply other threads:[~2024-07-10 20:18 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-10 14:00 [PATCH 0/2] uprobes: document mmap_lock, don't abuse get_user_pages_remote() Oleg Nesterov
2024-07-10 14:00 ` [PATCH 1/2] uprobes: document the usage of mm->mmap_lock Oleg Nesterov
2024-07-10 14:51 ` Masami Hiramatsu
2024-07-10 15:10 ` Oleg Nesterov
2024-07-11 0:07 ` Masami Hiramatsu
2024-07-11 9:49 ` Oleg Nesterov
2024-07-11 14:19 ` Masami Hiramatsu
2024-07-11 15:25 ` Oleg Nesterov
2024-07-10 14:01 ` [PATCH 2/2] uprobes: is_trap_at_addr: don't use get_user_pages_remote() Oleg Nesterov
2024-07-10 15:15 ` Andrii Nakryiko
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 [this message]
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
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=20240710201651.GG9228@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.