Re: [PATCH 1/5] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+

Amir Goldstein <[email protected]>
Newsgroups gmane.linux.ltp
Message-ID <CAOQ4uxhnrH3=XsCBhuO3oYtS=pZcRjkAchtrVwtnfJzBVmpNfQ@mail.gmail.com>
On Tue, Jun 16, 2026 at 9:40 AM Jan Kara <[email protected]> wrote:
>
> On Tue 16-06-26 02:06:25, AnonymeMeow wrote:
> > fanotify_init() used to reject FAN_REPORT_PIDFD combined with
> > FAN_REPORT_TID with EINVAL. Since Linux v7.2, fanotify supports
> > reporting pidfds for thread IDs, so this combination is expected to
> > succeed.
> >
> > Keep expecting EINVAL on older kernels and adjust the test expectation
> > based on the running kernel version.
> >
> > Signed-off-by: AnonymeMeow <[email protected]>
>
> Thanks for the fixes! Some comment below. And take your time with final
> exams, that's more important than some failing LTP tests :)
>
> > diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c
> > index b32ecf6aa..9a78f6ff0 100644
> > --- a/testcases/kernel/syscalls/fanotify/fanotify20.c
> > +++ b/testcases/kernel/syscalls/fanotify/fanotify20.c
> > @@ -8,13 +8,14 @@
> >
> >  /*\
> >   * This source file contains a test case which ensures that the
> > - * :manpage:`fanotify(7)` API returns an expected error code when provided an
> > - * invalid initialization flag alongside FAN_REPORT_PIDFD. Additionally, it
> > - * checks that the operability with existing FAN_REPORT_* flags is maintained
> > - * and functioning as intended.
> > + * :manpage:`fanotify(7)` API returns an expected error code when provided
> > + * unsupported initialization flags, e.g. FAN_REPORT_PIDFD combined with
> > + * FAN_REPORT_TID. Additionally, it checks that the operability with
> > + * supported FAN_REPORT_* flags is maintained and functioning as intended.
> >   *
> >   * NOTE: FAN_REPORT_PIDFD support was added in v5.15-rc1 in
> >   * af579beb666a ("fanotify: add pidfd support to the fanotify API").
> > + * FAN_REPORT_PIDFD combined with FAN_REPORT_TID is supported since v7.2-rc1.

Can add the upstream commit here.

> >   */
> >
> >  #define _GNU_SOURCE
> > @@ -26,8 +27,10 @@
> >
> >  #define MOUNT_PATH   "fs_mnt"
> >  #define FLAGS_DESC(x) .flags = x, .desc = #x
> > +#define PIDFD_TID_FLAGS (FAN_REPORT_PIDFD | FAN_REPORT_TID)
> >
> >  static int fd;
> > +static int thread_pidfd_supported;
> >
> >  static struct test_case_t {
> >       unsigned int flags;
> > @@ -51,17 +54,21 @@ static void do_setup(void)
> >        */
> >       REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_PIDFD,
> >                                                   MOUNT_PATH);
> > +
> > +     thread_pidfd_supported = tst_kvercmp(7, 2, 0) >= 0;
> >  }
> >
> >  static void do_test(unsigned int i)
> >  {
> >       struct test_case_t *tc = &test_cases[i];
> > +     int exp_errno = (tc->flags & PIDFD_TID_FLAGS) == PIDFD_TID_FLAGS &&
> > +                     thread_pidfd_supported ? 0 : tc->exp_errno;
> >
> > -     tst_res(TINFO, "Test %s on %s", tc->exp_errno ? "fail" : "pass",
> > +     tst_res(TINFO, "Test %s on %s", exp_errno ? "fail" : "pass",
> >               tc->desc);
> >
> >       TST_EXP_FD_OR_FAIL(fd = fanotify_init(tc->flags, O_RDONLY),
> > -                        tc->exp_errno);
> > +                        exp_errno);
>
> Hum, this looks somewhat ugly. Ideally we'd initialize test case .exp_errno
> accordingly to the expected return of the syscall (but that's not really
> possible because the initializer has to be constant). Checking how other
> tests handle it, I think we can clone the tests to two. One that expects
> failure and is skipped for kernels >= 7.2 and one that expects success and
> is skipped for kernels < 7.2. And we can have in the test description
> .min_kver and .max_kver fields that would store for which kernel versions
> the test should be performed.

LOL there is nothing to test in the >= 7.2 test.

The test that these flag combination are allowed:
                FLAGS_DESC(FAN_REPORT_PIDFD | FAN_REPORT_TID),
                FLAGS_DESC(FAN_REPORT_PIDFD | FAN_REPORT_FID |
FAN_REPORT_DFID_NAME),

Is already "tested" by the tests that use them.
and we don't have any tests that >= 5.10 has support for
FAN_MARK_FILESYSTEM etc.

Easiest is to just skip fanotify20 for version >= 7.2

Thanks,
Amir.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.