From: Song Liu <songliubraving@meta.com>
To: Amir Goldstein <amir73il@gmail.com>
Cc: "Song Liu" <songliubraving@meta.com>,
"Alexei Starovoitov" <alexei.starovoitov@gmail.com>,
"Song Liu" <song@kernel.org>, bpf <bpf@vger.kernel.org>,
Linux-Fsdevel <linux-fsdevel@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>,
"LSM List" <linux-security-module@vger.kernel.org>,
"Kernel Team" <kernel-team@meta.com>,
"Andrii Nakryiko" <andrii@kernel.org>,
"Eddy Z" <eddyz87@gmail.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Martin KaFai Lau" <martin.lau@linux.dev>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>, "KP Singh" <kpsingh@kernel.org>,
"Matt Bobrowski" <mattbobrowski@google.com>,
"repnop@google.com" <repnop@google.com>,
"Jeff Layton" <jlayton@kernel.org>,
"Josef Bacik" <josef@toxicpanda.com>,
"Mickaël Salaün" <mic@digikod.net>,
"gnoack@google.com" <gnoack@google.com>
Subject: Re: [RFC/PATCH v2 bpf-next fanotify 7/7] selftests/bpf: Add test for BPF based fanotify fastpath handler
Date: Tue, 19 Nov 2024 08:35:47 +0000 [thread overview]
Message-ID: <CFCDD4D9-4CD5-42E1-A741-6CD96E13FFCA@fb.com> (raw)
In-Reply-To: <CAOQ4uxga-iZtL+OsocdxwSyBqNKnGsgnq+OQ56Lm4neQ8kP82A@mail.gmail.com>
Hi Amir,
Thanks for sharing these thoughts. I will take a closer look
later, as I am not awake enough to fully understand everything.
> On Nov 18, 2024, at 11:59 PM, Amir Goldstein <amir73il@gmail.com> wrote:
[...]
>> Moving struct_ops hook inside send_to_group does save
>> us an indirect call. But this also means we need to
>> introduce the fastpath concept to both fsnotify and
>> fanotify. I personally don't really like duplications
>> like this (see the big BUILD_BUG_ON array in
>> fanotify_handle_event).
>>
>> OTOH, maybe the benefit of one fewer indirect call
>> justifies the extra complexity. Let me think more
>> about it.
>>
>
> I need to explain something about fsnotify vs. fanotify
> in order to argue why the feature should be "fanotify", but the
> bottom line is that is should not be too hard to avoid the indirect
> call even if the feature is introduced through fanotify API as I think
> that it should be.
When I first looked into this, I thought about "whether
there will be a use case that uses fsnotify but not fanotify".
I didn't get any conclusion on this back then. But according
to this thread, I think we are pretty confident that future
use cases (such as FAN_PRE_ACCESS) will have a fanotify part.
If this is the case, I think fanotify-bpf makes more sense.
> TLDR:
> The fsnotify_backend abstraction has become somewhat
> of a theater of abstraction over time, because the feature
> distance between fanotify backend and all the rest has grew
> quite large.
>
> The logic in send_to_group() is *seemingly* the generic fsnotify
> logic, but not really, because only fanotify has ignore masks
> and only fanotify has mark types (inode,mount,sb).
>
> This difference is encoded by the group->ops->handle_event()
> operation that only fanotify implements.
> All the rest of the backends implement the simpler ->handle_inode_event().
>
> Similarly, the group->private union is always dominated by the size
> of group->fanotify_data, so there is no big difference if we place
> group->fp_hook (or ->filter_hook) outside of fanotify_data, so that
> we can query and call it from send_to_group() saving the indirect call
> to ->handle_event().
>
> That still leaves the question if we need to call fanotify_group_event_mask()
> before the filter hook.
I was trying Alexei's idea to move the API to fsnotify, and got
stucked at fanotify_group_event_mask(). It appears we should
always honor these built-in filters.
> fanotify_group_event_mask() does several things, but I think that
> the only thing relevant before the filter hook is this line:
> /*
> * Send the event depending on event flags in mark mask.
> */
> if (!fsnotify_mask_applicable(mark->mask, ondir, type))
> continue;
>
> This code is related to the two "built-in fanotify filters", namely
> FAN_ONDIR and FAN_EVENT_ON_CHILD.
> These built-in filters are so lame that they serve as a good example
> why a programmable filter is a better idea.
> For example, users need to opt-in for events on directories, but they
> cannot request events only on directories.
>
> Historically, the "generic" abstraction in send_to_group() has dealt
> with the non-generic fanotify ignore mask, but has not dealt with
> these non-generic fanotify built-in filters.
>
> However, since commit 31a371e419c8 ("fanotify: prepare for setting
> event flags in ignore mask"), send_to_group() is already aware of those
> fanotify built-in filters.
I will continue on this tomorrow. It is time to get some sleep. :)
>
> So unless I am missing something, if we align the marks iteration
> loop in send_to_group() to look exactly like the marks iteration loop in
> fanotify_group_event_mask(), there should be no problem to call
> the filter hook directly, right before calling ->handle_event().
>
> Hope this brain dump helps.
Thanks again for your input!
Song
>
> Thanks,
> Amir.
next prev parent reply other threads:[~2024-11-19 8:35 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-14 8:43 [RFC/PATCH v2 bpf-next fanotify 0/7] Fanotify " Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 1/7] fanotify: Introduce fanotify " Song Liu
2024-11-15 8:51 ` Amir Goldstein
2024-11-15 17:11 ` Song Liu
2024-11-15 17:32 ` Amir Goldstein
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 2/7] samples/fanotify: Add a sample " Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 3/7] bpf: Make bpf inode storage available to tracing programs Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 4/7] bpf: fs: Add three kfuncs Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 5/7] bpf: Allow bpf map hold reference on dentry Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 6/7] fanotify: Enable bpf based fanotify fastpath handler Song Liu
2024-11-14 8:43 ` [RFC/PATCH v2 bpf-next fanotify 7/7] selftests/bpf: Add test for BPF " Song Liu
2024-11-14 20:14 ` Alexei Starovoitov
2024-11-14 23:02 ` Song Liu
2024-11-15 0:41 ` Alexei Starovoitov
2024-11-15 1:10 ` Song Liu
2024-11-15 1:31 ` Alexei Starovoitov
2024-11-15 7:01 ` Song Liu
2024-11-15 19:41 ` Alexei Starovoitov
2024-11-15 21:05 ` Song Liu
2024-11-18 20:51 ` Song Liu
2024-11-19 0:10 ` Alexei Starovoitov
2024-11-19 1:10 ` Song Liu
2024-11-19 7:59 ` Amir Goldstein
2024-11-19 8:35 ` Song Liu [this message]
2024-11-15 7:26 ` Amir Goldstein
2024-11-15 20:04 ` Alexei Starovoitov
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=CFCDD4D9-4CD5-42E1-A741-6CD96E13FFCA@fb.com \
--to=songliubraving@meta.com \
--cc=alexei.starovoitov@gmail.com \
--cc=amir73il@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brauner@kernel.org \
--cc=daniel@iogearbox.net \
--cc=eddyz87@gmail.com \
--cc=gnoack@google.com \
--cc=jack@suse.cz \
--cc=jlayton@kernel.org \
--cc=josef@toxicpanda.com \
--cc=kernel-team@meta.com \
--cc=kpsingh@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=martin.lau@linux.dev \
--cc=mattbobrowski@google.com \
--cc=mic@digikod.net \
--cc=repnop@google.com \
--cc=song@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®