From: Jiri Olsa <olsajiri@gmail.com>
To: Hou Tao <houtao@huaweicloud.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Andrii Nakryiko <andrii@kernel.org>,
bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
John Fastabend <john.fastabend@gmail.com>,
KP Singh <kpsingh@chromium.org>,
Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>
Subject: Re: [RFC/PATCH bpf-next] bpf: Fix d_path test after last fs update
Date: Thu, 31 Aug 2023 10:54:34 +0200 [thread overview]
Message-ID: <ZPBVSjDQndPpI3ie@krava> (raw)
In-Reply-To: <89bb059e-f371-8354-5770-f022396e0b38@huaweicloud.com>
On Thu, Aug 31, 2023 at 03:37:37PM +0800, Hou Tao wrote:
> Hi
>
> On 8/30/2023 5:35 PM, Jiri Olsa wrote:
> > Recent commit [1] broken d_path test, because now filp_close is not
> > called directly from sys_close, but eventually later when the file
> > is finally released.
>
> To make test_d_path self-test pass, beside attaching to a different
> function (e.g., __fput_sync or filp_flush), we could also use
> close_range() or even dup2() to close the created fd, because these
> syscalls still use filp_close() to close the opened file.
nice, I like the close_range solution ;-) patch below fixes the test
>
> >
> > I can't see any other solution than to hook filp_flush function and
> > that also means we need to add it to btf_allowlist_d_path list, so
> > it can use the d_path helper.
> >
> > But it's probably not very stable because filp_flush is static so it
> > could be potentially inlined.
> >
> > Also if we'd keep the current filp_close hook and find a way how to 'wait'
> > for it to be called so user space can go with checks, then it looks
> > like d_path might not work properly when the task is no longer around.
>
> It seems there is no need to wait for it to be called, because
> filp_close() is still called synchronously by some syscall (e.g.,
> close_range or io_uring). So if the bpf program tries to collect many
> close event as possible, it should be attach to both filp_close() and
> __fput_sync(), right ?
>
right, when we hook to close_range it's still synchronous
thanks,
jirka
---
diff --git a/tools/testing/selftests/bpf/prog_tests/d_path.c b/tools/testing/selftests/bpf/prog_tests/d_path.c
index 911345c526e6..8a558c980753 100644
--- a/tools/testing/selftests/bpf/prog_tests/d_path.c
+++ b/tools/testing/selftests/bpf/prog_tests/d_path.c
@@ -91,6 +91,7 @@ static int trigger_fstat_events(pid_t pid)
out_close:
/* triggers filp_close */
+#define close(fd) close_range(fd, fd, 0)
close(pipefd[0]);
close(pipefd[1]);
close(sockfd);
@@ -98,6 +99,7 @@ static int trigger_fstat_events(pid_t pid)
close(devfd);
close(localfd);
close(indicatorfd);
+#undef close
return ret;
}
prev parent reply other threads:[~2023-08-31 8:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-30 9:35 [RFC/PATCH bpf-next] bpf: Fix d_path test after last fs update Jiri Olsa
2023-08-30 13:27 ` Jiri Olsa
2023-08-30 18:35 ` Song Liu
2023-08-30 19:04 ` Jiri Olsa
2023-08-30 20:29 ` Alexei Starovoitov
2023-08-31 10:42 ` Jiri Olsa
2023-08-30 22:11 ` Yonghong Song
2023-08-31 5:24 ` Song Liu
2023-08-31 8:23 ` Jiri Olsa
2023-08-31 7:52 ` Jiri Olsa
2023-08-31 7:37 ` Hou Tao
2023-08-31 8:54 ` Jiri Olsa [this message]
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=ZPBVSjDQndPpI3ie@krava \
--to=olsajiri@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=haoluo@google.com \
--cc=houtao@huaweicloud.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=sdf@google.com \
--cc=songliubraving@fb.com \
--cc=yhs@fb.com \
/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