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

Jan Kara jack@suse.cz
Tue Jun 16 09:40:29 CEST 2026


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 <anonymemeow@gmail.com>

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.
>   */
>  
>  #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.

								Honza

-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR


More information about the ltp mailing list