From: AnonymeMeow <anonymemeow@gmail.com>
To: jack@suse.cz
Cc: amir73il@gmail.com, ltp@lists.linux.it,
AnonymeMeow <anonymemeow@gmail.com>
Subject: [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID
Date: Tue, 16 Jun 2026 02:06:28 +0800 [thread overview]
Message-ID: <20260615180629.7148-5-anonymemeow@gmail.com> (raw)
In-Reply-To: <20260615180629.7148-1-anonymemeow@gmail.com>
Add test variants for FAN_REPORT_PIDFD combined with FAN_REPORT_TID,
both with and without FAN_REPORT_FD_ERROR. Add PIDFD_THREAD fallback
definition for old headers.
Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
include/lapi/pidfd.h | 4 ++
.../kernel/syscalls/fanotify/fanotify21.c | 56 ++++++++++++++-----
2 files changed, 47 insertions(+), 13 deletions(-)
diff --git a/include/lapi/pidfd.h b/include/lapi/pidfd.h
index a3205032c..eb4e3466d 100644
--- a/include/lapi/pidfd.h
+++ b/include/lapi/pidfd.h
@@ -43,6 +43,10 @@ struct pidfd_info {
# define PIDFD_NONBLOCK O_NONBLOCK
#endif
+#ifndef PIDFD_THREAD
+# define PIDFD_THREAD O_EXCL
+#endif
+
#ifndef PIDFS_IOCTL_MAGIC
# define PIDFS_IOCTL_MAGIC 0xFF
#endif
diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
index 22f9767db..fd43c8c1c 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify21.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
@@ -12,6 +12,7 @@
*
* 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
@@ -32,6 +33,9 @@
#define MOUNT_PATH "fs_mnt"
#define TEST_FILE MOUNT_PATH "/testfile"
+#define TST_VARIANT_FD_ERROR (tst_variant & 1)
+#define TST_VARIANT_PIDFD_THREAD (tst_variant & 2)
+
struct pidfd_fdinfo_t {
int pos;
int flags;
@@ -67,6 +71,7 @@ static char event_buf[BUF_SZ];
static struct pidfd_fdinfo_t exp_pidfd_fdinfo;
static int fd_error_unsupported;
+static int thread_pidfd_unsupported;
static struct tst_clone_args clone_args = {
.flags = CLONE_NEWPID,
@@ -90,21 +95,37 @@ static void read_pidfd_fdinfo(int pidfd, struct pidfd_fdinfo_t *pidfd_fdinfo)
static void generate_event(void)
{
int fd;
+ int pidfd;
+
+ pidfd = TST_VARIANT_PIDFD_THREAD ? SAFE_PIDFD_OPEN(tst_gettid(), PIDFD_THREAD)
+ : SAFE_PIDFD_OPEN(tst_getpid(), 0);
+ read_pidfd_fdinfo(pidfd, &exp_pidfd_fdinfo);
+ SAFE_CLOSE(pidfd);
/* Generate a single FAN_OPEN event on the watched object. */
fd = SAFE_OPEN(TEST_FILE, O_RDONLY);
SAFE_CLOSE(fd);
}
+static const char *test_variant_name(void)
+{
+ switch (tst_variant) {
+ case 0: return "";
+ case 1: return "(FAN_REPORT_FD_ERROR)";
+ case 2: return "(FAN_REPORT_TID)";
+ case 3: return "(FAN_REPORT_FD_ERROR | FAN_REPORT_TID)";
+ }
+ return NULL;
+}
+
static void do_setup(void)
{
- int pidfd;
int init_flags = FAN_REPORT_PIDFD;
/* Bind mount so remount ro/rw always work */
SAFE_MOUNT(MOUNT_PATH, MOUNT_PATH, "none", MS_BIND, NULL);
- if (tst_variant) {
+ if (TST_VARIANT_FD_ERROR) {
fanotify_fd = -1;
fd_error_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_FD_ERROR, ".");
if (fd_error_unsupported)
@@ -112,6 +133,15 @@ static void do_setup(void)
init_flags |= FAN_REPORT_FD_ERROR;
}
+ if (TST_VARIANT_PIDFD_THREAD) {
+ fanotify_fd = -1;
+ thread_pidfd_unsupported = fanotify_init_flags_supported_on_fs(
+ FAN_REPORT_PIDFD | FAN_REPORT_TID, ".");
+ if (thread_pidfd_unsupported)
+ return;
+ init_flags |= FAN_REPORT_TID;
+ }
+
SAFE_TOUCH(TEST_FILE, 0666, NULL);
/*
@@ -125,12 +155,6 @@ static void do_setup(void)
fanotify_fd = SAFE_FANOTIFY_INIT(init_flags, O_RDWR);
SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD, FAN_OPEN, AT_FDCWD,
TEST_FILE);
-
- pidfd = SAFE_PIDFD_OPEN(getpid(), 0);
-
- read_pidfd_fdinfo(pidfd, &exp_pidfd_fdinfo);
-
- SAFE_CLOSE(pidfd);
}
static void do_test(unsigned int num)
@@ -138,19 +162,25 @@ static void do_test(unsigned int num)
int i = 0, len;
struct test_case_t *tc = &test_cases[num];
int nopidfd_err = tc->want_pidfd_err ?
- (tst_variant ? -ESRCH : FAN_NOPIDFD) : 0;
- int fd_err = (tc->remount_ro && tst_variant) ? -EROFS : 0;
+ (TST_VARIANT_FD_ERROR ? -ESRCH : FAN_NOPIDFD) : 0;
+ int fd_err = (tc->remount_ro && TST_VARIANT_FD_ERROR) ? -EROFS : 0;
pid_t reader_pid;
int reader_exit_status;
tst_res(TINFO, "Test #%d.%d: %s %s", num, tst_variant, tc->name,
- tst_variant ? "(FAN_REPORT_FD_ERROR)" : "");
+ test_variant_name());
- if (fd_error_unsupported && tst_variant) {
+ if (fd_error_unsupported && TST_VARIANT_FD_ERROR) {
FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_FD_ERROR, fd_error_unsupported);
return;
}
+ if (thread_pidfd_unsupported && TST_VARIANT_PIDFD_THREAD) {
+ FANOTIFY_INIT_FLAGS_ERR_MSG(
+ FAN_REPORT_PIDFD | FAN_REPORT_TID, thread_pidfd_unsupported);
+ return;
+ }
+
/* remount ro/rw the bind mount */
SAFE_MOUNT("none", MOUNT_PATH, "none", MS_BIND | MS_REMOUNT |
(tc->remount_ro ? MS_RDONLY : 0), NULL);
@@ -333,7 +363,7 @@ static struct tst_test test = {
.setup = do_setup,
.test = do_test,
.tcnt = ARRAY_SIZE(test_cases),
- .test_variants = 2,
+ .test_variants = 4,
.cleanup = do_cleanup,
.all_filesystems = 1,
.needs_root = 1,
--
2.54.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2026-06-15 18:08 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <em6fgj3mkdyapnpi5yszfj563gwjoehyxxo6mk6cwiyyydkiah@vpunmf3gm5nt>
2026-06-15 18:06 ` [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID AnonymeMeow
2026-06-15 18:06 ` [LTP] [PATCH 1/5] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+ AnonymeMeow
2026-06-15 18:31 ` [LTP] " linuxtestproject.agent
2026-06-16 7:40 ` [LTP] [PATCH 1/5] " Jan Kara
2026-06-16 11:27 ` Amir Goldstein
2026-06-16 11:48 ` Jan Kara
2026-06-15 18:06 ` [LTP] [PATCH 2/5] fanotify21: Stop relying on exited child for pidfd error AnonymeMeow
2026-06-16 7:48 ` Jan Kara
2026-06-15 18:06 ` [LTP] [PATCH 3/5] fanotify21: Simplify read_pidfd_fdinfo() AnonymeMeow
2026-06-16 7:46 ` Jan Kara
2026-06-15 18:06 ` AnonymeMeow [this message]
2026-06-16 7:55 ` [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID Jan Kara
2026-06-16 8:24 ` Andrea Cervesato via ltp
2026-06-16 9:12 ` Jan Kara
2026-06-16 9:37 ` Andrea Cervesato via ltp
2026-06-15 18:06 ` [LTP] [PATCH 5/5] fanotify21: Add FAN_REPORT_TID pidfd coverage AnonymeMeow
2026-06-16 7:57 ` Jan Kara
2026-06-16 11:39 ` [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID Amir Goldstein
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=20260615180629.7148-5-anonymemeow@gmail.com \
--to=anonymemeow@gmail.com \
--cc=amir73il@gmail.com \
--cc=jack@suse.cz \
--cc=ltp@lists.linux.it \
/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