All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions
@ 2026-06-07  0:33 AnonymeMeow
  2026-06-07  0:33 ` [PATCH v5 1/2] fanotify: report thread pidfds for FAN_REPORT_TID AnonymeMeow
                   ` (2 more replies)
  0 siblings, 3 replies; 24+ messages in thread
From: AnonymeMeow @ 2026-06-07  0:33 UTC (permalink / raw)
  To: jack; +Cc: amir73il, brauner, linux-fsdevel, linux-kernel, AnonymeMeow

The pidfd API now supports pidfds for tasks that are not thread group leaders,
but fanotify has not caught up yet. This patch set lifts that restriction and
allows fanotify to report pidfds referring to the event-generating thread.

Additionally, this patch set allows fanotify to hand out pidfds for reaped
tasks by registering the event pid with pidfs when pidfd reporting is
requested and dropping the pid_has_task() check before the pidfd_prepare()
call, as suggested by Christian.

Link: https://lore.kernel.org/lkml/20260528-schmuckvoll-heilen-garen-be77b4208671@brauner/
Link: https://lore.kernel.org/lkml/20260602-patzt-sturz-segen-f1f305d61b75@brauner/

Changes since v4:
 - Add a pidfs_register_pid_gfp() helper function to pass in custom flags.

v4: https://lore.kernel.org/lkml/20260603001516.26234-1-anonymemeow@gmail.com/

AnonymeMeow (2):
  fanotify: report thread pidfds for FAN_REPORT_TID
  fanotify: allow reporting pidfds for reaped tasks

 fs/notify/fanotify/fanotify.c      | 17 +++++++++------
 fs/notify/fanotify/fanotify_user.c | 33 +++++++-----------------------
 fs/pidfs.c                         | 10 +++++----
 include/linux/pidfs.h              | 18 +++++++++++++++-
 4 files changed, 41 insertions(+), 37 deletions(-)

-- 
2.54.0


^ permalink raw reply	[flat|nested] 24+ messages in thread

* [PATCH v5 1/2] fanotify: report thread pidfds for FAN_REPORT_TID
  2026-06-07  0:33 [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions AnonymeMeow
@ 2026-06-07  0:33 ` AnonymeMeow
  2026-06-07  0:33 ` [PATCH v5 2/2] fanotify: allow reporting pidfds for reaped tasks AnonymeMeow
  2026-06-09 10:29 ` [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions Jan Kara
  2 siblings, 0 replies; 24+ messages in thread
From: AnonymeMeow @ 2026-06-07  0:33 UTC (permalink / raw)
  To: jack; +Cc: amir73il, brauner, linux-fsdevel, linux-kernel, AnonymeMeow

The FAN_REPORT_PIDFD and FAN_REPORT_TID flags used to be mutually
exclusive because by the time the pidfd support was introduced to
fanotify, pidfds could only be created for thread group leaders. Now
that the pidfd API supports thread-specific pidfds via PIDFD_THREAD,
this restriction can be lifted.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
 fs/notify/fanotify/fanotify_user.c | 27 ++++++++-------------------
 1 file changed, 8 insertions(+), 19 deletions(-)

diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index ae904451dfc0..ebdd48942029 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -19,6 +19,7 @@
 #include <linux/memcontrol.h>
 #include <linux/statfs.h>
 #include <linux/exportfs.h>
+#include <linux/pidfd.h>
 
 #include <asm/ioctls.h>
 
@@ -903,25 +904,21 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
 		metadata.fd = fd >= 0 ? fd : FAN_NOFD;
 
 	if (pidfd_mode) {
-		/*
-		 * Complain if the FAN_REPORT_PIDFD and FAN_REPORT_TID mutual
-		 * exclusion is ever lifted. At the time of incoporating pidfd
-		 * support within fanotify, the pidfd API only supported the
-		 * creation of pidfds for thread-group leaders.
-		 */
-		WARN_ON_ONCE(FAN_GROUP_FLAG(group, FAN_REPORT_TID));
+		unsigned int tid_mode = FAN_GROUP_FLAG(group, FAN_REPORT_TID);
+		enum pid_type pidtype = tid_mode ? PIDTYPE_PID : PIDTYPE_TGID;
+		unsigned int pidfd_flags = tid_mode ? PIDFD_THREAD : 0;
 
 		/*
-		 * The PIDTYPE_TGID check for an event->pid is performed
+		 * The pid_has_task() check for an event->pid is performed
 		 * preemptively in an attempt to catch out cases where the event
-		 * listener reads events after the event generating process has
+		 * listener reads events after the event generating task has
 		 * already terminated.  Depending on flag FAN_REPORT_FD_ERROR,
 		 * report either -ESRCH or FAN_NOPIDFD to the event listener in
 		 * those cases with all other pidfd creation errors reported as
 		 * the error code itself or as FAN_EPIDFD.
 		 */
-		if (metadata.pid && pid_has_task(event->pid, PIDTYPE_TGID))
-			pidfd = pidfd_prepare(event->pid, 0, &pidfd_file);
+		if (metadata.pid && pid_has_task(event->pid, pidtype))
+			pidfd = pidfd_prepare(event->pid, pidfd_flags, &pidfd_file);
 
 		if (!FAN_GROUP_FLAG(group, FAN_REPORT_FD_ERROR) && pidfd < 0)
 			pidfd = pidfd == -ESRCH ? FAN_NOPIDFD : FAN_EPIDFD;
@@ -1628,14 +1625,6 @@ SYSCALL_DEFINE2(fanotify_init, unsigned int, flags, unsigned int, event_f_flags)
 #endif
 		return -EINVAL;
 
-	/*
-	 * A pidfd can only be returned for a thread-group leader; thus
-	 * FAN_REPORT_PIDFD and FAN_REPORT_TID need to remain mutually
-	 * exclusive.
-	 */
-	if ((flags & FAN_REPORT_PIDFD) && (flags & FAN_REPORT_TID))
-		return -EINVAL;
-
 	/* Don't allow mixing mnt events with inode events for now */
 	if (flags & FAN_REPORT_MNT) {
 		if (class != FAN_CLASS_NOTIF)
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [PATCH v5 2/2] fanotify: allow reporting pidfds for reaped tasks
  2026-06-07  0:33 [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions AnonymeMeow
  2026-06-07  0:33 ` [PATCH v5 1/2] fanotify: report thread pidfds for FAN_REPORT_TID AnonymeMeow
@ 2026-06-07  0:33 ` AnonymeMeow
  2026-06-09 10:29 ` [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions Jan Kara
  2 siblings, 0 replies; 24+ messages in thread
From: AnonymeMeow @ 2026-06-07  0:33 UTC (permalink / raw)
  To: jack; +Cc: amir73il, brauner, linux-fsdevel, linux-kernel, AnonymeMeow

Fanotify used to refuse to report pidfds for reaped tasks by applying a
pid_has_task() check before calling pidfd_prepare(). This prevented
userspace from obtaining information about the task.

Register the event pid with pidfs when creating the fanotify event if
pidfd reporting was requested, so pidfd_prepare() can later create a
pidfd for the reaped task.

Suggested-by: Christian Brauner <brauner@kernel.org>
Link: https://lore.kernel.org/linux-fsdevel/20260528-schmuckvoll-heilen-garen-be77b4208671@brauner/

Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
 fs/notify/fanotify/fanotify.c      | 17 +++++++++++------
 fs/notify/fanotify/fanotify_user.c | 18 +++++-------------
 fs/pidfs.c                         | 10 ++++++----
 include/linux/pidfs.h              | 18 +++++++++++++++++-
 4 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/fs/notify/fanotify/fanotify.c b/fs/notify/fanotify/fanotify.c
index 38290b9c07f7..ece9523e775b 100644
--- a/fs/notify/fanotify/fanotify.c
+++ b/fs/notify/fanotify/fanotify.c
@@ -14,6 +14,7 @@
 #include <linux/sched/mm.h>
 #include <linux/statfs.h>
 #include <linux/stringhash.h>
+#include <linux/pidfs.h>
 
 #include "fanotify.h"
 
@@ -842,6 +843,15 @@ static struct fanotify_event *fanotify_alloc_event(
 	/* Whoever is interested in the event, pays for the allocation. */
 	old_memcg = set_active_memcg(group->memcg);
 
+	if (FAN_GROUP_FLAG(group, FAN_REPORT_TID))
+		pid = task_pid(current);
+	else
+		pid = task_tgid(current);
+
+	if (FAN_GROUP_FLAG(group, FAN_REPORT_PIDFD) &&
+	    pidfs_register_pid_gfp(pid, gfp))
+		goto out;
+
 	if (fanotify_is_perm_event(mask)) {
 		event = fanotify_alloc_perm_event(data, data_type, gfp);
 	} else if (fanotify_is_error_event(mask)) {
@@ -863,15 +873,10 @@ static struct fanotify_event *fanotify_alloc_event(
 	if (!event)
 		goto out;
 
-	if (FAN_GROUP_FLAG(group, FAN_REPORT_TID))
-		pid = get_pid(task_pid(current));
-	else
-		pid = get_pid(task_tgid(current));
-
 	/* Mix event info, FAN_ONDIR flag and pid into event merge key */
 	hash ^= hash_long((unsigned long)pid | ondir, FANOTIFY_EVENT_HASH_BITS);
 	fanotify_init_event(event, hash, mask);
-	event->pid = pid;
+	event->pid = get_pid(pid);
 
 out:
 	set_active_memcg(old_memcg);
diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
index ebdd48942029..b604e3da58ad 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -904,20 +904,12 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
 		metadata.fd = fd >= 0 ? fd : FAN_NOFD;
 
 	if (pidfd_mode) {
-		unsigned int tid_mode = FAN_GROUP_FLAG(group, FAN_REPORT_TID);
-		enum pid_type pidtype = tid_mode ? PIDTYPE_PID : PIDTYPE_TGID;
-		unsigned int pidfd_flags = tid_mode ? PIDFD_THREAD : 0;
+		unsigned int pidfd_flags = PIDFD_STALE;
 
-		/*
-		 * The pid_has_task() check for an event->pid is performed
-		 * preemptively in an attempt to catch out cases where the event
-		 * listener reads events after the event generating task has
-		 * already terminated.  Depending on flag FAN_REPORT_FD_ERROR,
-		 * report either -ESRCH or FAN_NOPIDFD to the event listener in
-		 * those cases with all other pidfd creation errors reported as
-		 * the error code itself or as FAN_EPIDFD.
-		 */
-		if (metadata.pid && pid_has_task(event->pid, pidtype))
+		if (FAN_GROUP_FLAG(group, FAN_REPORT_TID))
+			pidfd_flags |= PIDFD_THREAD;
+
+		if (metadata.pid)
 			pidfd = pidfd_prepare(event->pid, pidfd_flags, &pidfd_file);
 
 		if (!FAN_GROUP_FLAG(group, FAN_REPORT_FD_ERROR) && pidfd < 0)
diff --git a/fs/pidfs.c b/fs/pidfs.c
index 1cce4f34a051..15efecf5cb07 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -991,14 +991,16 @@ static void pidfs_put_data(void *data)
 }
 
 /**
- * pidfs_register_pid - register a struct pid in pidfs
+ * pidfs_register_pid_gfp - register a struct pid in pidfs with custom GFP
+ * flags
  * @pid: pid to pin
+ * @gfp: GFP flags for memory allocation
  *
- * Register a struct pid in pidfs.
+ * Register a struct pid in pidfs with custom GFP flags.
  *
  * Return: On success zero, on error a negative error code is returned.
  */
-int pidfs_register_pid(struct pid *pid)
+int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp)
 {
 	struct pidfs_attr *new_attr __free(kfree) = NULL;
 	struct pidfs_attr *attr;
@@ -1014,7 +1016,7 @@ int pidfs_register_pid(struct pid *pid)
 	if (attr)
 		return 0;
 
-	new_attr = kmem_cache_zalloc(pidfs_attr_cachep, GFP_KERNEL);
+	new_attr = kmem_cache_zalloc(pidfs_attr_cachep, gfp);
 	if (!new_attr)
 		return -ENOMEM;
 
diff --git a/include/linux/pidfs.h b/include/linux/pidfs.h
index 416bdff4d6ce..0abf7da9ab23 100644
--- a/include/linux/pidfs.h
+++ b/include/linux/pidfs.h
@@ -2,6 +2,8 @@
 #ifndef _LINUX_PID_FS_H
 #define _LINUX_PID_FS_H
 
+#include <linux/gfp_types.h>
+
 struct coredump_params;
 
 struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags);
@@ -14,7 +16,21 @@ void pidfs_exit(struct task_struct *tsk);
 void pidfs_coredump(const struct coredump_params *cprm);
 #endif
 extern const struct dentry_operations pidfs_dentry_operations;
-int pidfs_register_pid(struct pid *pid);
+int pidfs_register_pid_gfp(struct pid *pid, gfp_t gfp);
+
+/**
+ * pidfs_register_pid - register a struct pid in pidfs
+ * @pid: pid to pin
+ *
+ * Register a struct pid in pidfs.
+ *
+ * Return: On success zero, on error a negative error code is returned.
+ */
+static inline int pidfs_register_pid(struct pid *pid)
+{
+	return pidfs_register_pid_gfp(pid, GFP_KERNEL);
+}
+
 void pidfs_free_pid(struct pid *pid);
 
 #endif /* _LINUX_PID_FS_H */
-- 
2.54.0


^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions
  2026-06-07  0:33 [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions AnonymeMeow
  2026-06-07  0:33 ` [PATCH v5 1/2] fanotify: report thread pidfds for FAN_REPORT_TID AnonymeMeow
  2026-06-07  0:33 ` [PATCH v5 2/2] fanotify: allow reporting pidfds for reaped tasks AnonymeMeow
@ 2026-06-09 10:29 ` Jan Kara
  2026-06-10  7:31   ` Christian Brauner
  2 siblings, 1 reply; 24+ messages in thread
From: Jan Kara @ 2026-06-09 10:29 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: jack, amir73il, brauner, linux-fsdevel, linux-kernel

On Sun 07-06-26 08:33:41, AnonymeMeow wrote:
> The pidfd API now supports pidfds for tasks that are not thread group leaders,
> but fanotify has not caught up yet. This patch set lifts that restriction and
> allows fanotify to report pidfds referring to the event-generating thread.
> 
> Additionally, this patch set allows fanotify to hand out pidfds for reaped
> tasks by registering the event pid with pidfs when pidfd reporting is
> requested and dropping the pid_has_task() check before the pidfd_prepare()
> call, as suggested by Christian.
> 
> Link: https://lore.kernel.org/lkml/20260528-schmuckvoll-heilen-garen-be77b4208671@brauner/
> Link: https://lore.kernel.org/lkml/20260602-patzt-sturz-segen-f1f305d61b75@brauner/
> 
> Changes since v4:
>  - Add a pidfs_register_pid_gfp() helper function to pass in custom flags.
> 
> v4: https://lore.kernel.org/lkml/20260603001516.26234-1-anonymemeow@gmail.com/

The patches look good to me. Thanks! I'd prefer the change adding gfp
argument to pidfs_register_pid() was a separate commit but unless Christian
objects I can live with that. I'll wait for Christian's ack for pidfs
changes before merging this through my tree.
								Honza

> AnonymeMeow (2):
>   fanotify: report thread pidfds for FAN_REPORT_TID
>   fanotify: allow reporting pidfds for reaped tasks
> 
>  fs/notify/fanotify/fanotify.c      | 17 +++++++++------
>  fs/notify/fanotify/fanotify_user.c | 33 +++++++-----------------------
>  fs/pidfs.c                         | 10 +++++----
>  include/linux/pidfs.h              | 18 +++++++++++++++-
>  4 files changed, 41 insertions(+), 37 deletions(-)
> 
> -- 
> 2.54.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions
  2026-06-09 10:29 ` [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions Jan Kara
@ 2026-06-10  7:31   ` Christian Brauner
  2026-06-10  9:14     ` Jan Kara
  0 siblings, 1 reply; 24+ messages in thread
From: Christian Brauner @ 2026-06-10  7:31 UTC (permalink / raw)
  To: Jan Kara; +Cc: AnonymeMeow, amir73il, linux-fsdevel, linux-kernel

On Tue, Jun 09, 2026 at 12:29:05PM +0200, Jan Kara wrote:
> On Sun 07-06-26 08:33:41, AnonymeMeow wrote:
> > The pidfd API now supports pidfds for tasks that are not thread group leaders,
> > but fanotify has not caught up yet. This patch set lifts that restriction and
> > allows fanotify to report pidfds referring to the event-generating thread.
> > 
> > Additionally, this patch set allows fanotify to hand out pidfds for reaped
> > tasks by registering the event pid with pidfs when pidfd reporting is
> > requested and dropping the pid_has_task() check before the pidfd_prepare()
> > call, as suggested by Christian.
> > 
> > Link: https://lore.kernel.org/lkml/20260528-schmuckvoll-heilen-garen-be77b4208671@brauner/
> > Link: https://lore.kernel.org/lkml/20260602-patzt-sturz-segen-f1f305d61b75@brauner/
> > 
> > Changes since v4:
> >  - Add a pidfs_register_pid_gfp() helper function to pass in custom flags.
> > 
> > v4: https://lore.kernel.org/lkml/20260603001516.26234-1-anonymemeow@gmail.com/
> 
> The patches look good to me. Thanks! I'd prefer the change adding gfp
> argument to pidfs_register_pid() was a separate commit but unless Christian
> objects I can live with that. I'll wait for Christian's ack for pidfs

I would also prefer it to be a separate commit but same as you I'm not
gonna insist. :)

> changes before merging this through my tree.

Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions
  2026-06-10  7:31   ` Christian Brauner
@ 2026-06-10  9:14     ` Jan Kara
  2026-06-15 18:06       ` [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID AnonymeMeow
  0 siblings, 1 reply; 24+ messages in thread
From: Jan Kara @ 2026-06-10  9:14 UTC (permalink / raw)
  To: Christian Brauner
  Cc: Jan Kara, AnonymeMeow, amir73il, linux-fsdevel, linux-kernel

On Wed 10-06-26 09:31:22, Christian Brauner wrote:
> On Tue, Jun 09, 2026 at 12:29:05PM +0200, Jan Kara wrote:
> > On Sun 07-06-26 08:33:41, AnonymeMeow wrote:
> > > The pidfd API now supports pidfds for tasks that are not thread group leaders,
> > > but fanotify has not caught up yet. This patch set lifts that restriction and
> > > allows fanotify to report pidfds referring to the event-generating thread.
> > > 
> > > Additionally, this patch set allows fanotify to hand out pidfds for reaped
> > > tasks by registering the event pid with pidfs when pidfd reporting is
> > > requested and dropping the pid_has_task() check before the pidfd_prepare()
> > > call, as suggested by Christian.
> > > 
> > > Link: https://lore.kernel.org/lkml/20260528-schmuckvoll-heilen-garen-be77b4208671@brauner/
> > > Link: https://lore.kernel.org/lkml/20260602-patzt-sturz-segen-f1f305d61b75@brauner/
> > > 
> > > Changes since v4:
> > >  - Add a pidfs_register_pid_gfp() helper function to pass in custom flags.
> > > 
> > > v4: https://lore.kernel.org/lkml/20260603001516.26234-1-anonymemeow@gmail.com/
> > 
> > The patches look good to me. Thanks! I'd prefer the change adding gfp
> > argument to pidfs_register_pid() was a separate commit but unless Christian
> > objects I can live with that. I'll wait for Christian's ack for pidfs
> 
> I would also prefer it to be a separate commit but same as you I'm not
> gonna insist. :)
> 
> > changes before merging this through my tree.
> 
> Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>

Thanks! Merged and pushed out. AnonymeMeow, what's the situation with
fixing up fanotify20 & fanotify21 LTP tests? Are you working on it please?
They'll now start failing with linux-next so it would be good to fix that
up ASAP... Thanks!

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

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID
  2026-06-10  9:14     ` Jan Kara
@ 2026-06-15 18:06       ` AnonymeMeow
  2026-06-15 18:06         ` [LTP] [PATCH 1/5] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+ AnonymeMeow
                           ` (5 more replies)
  0 siblings, 6 replies; 24+ messages in thread
From: AnonymeMeow @ 2026-06-15 18:06 UTC (permalink / raw)
  To: jack; +Cc: amir73il, ltp, AnonymeMeow

This patch set updates fanotify pidfd tests for the kernel change that
adds FAN_REPORT_PIDFD support together with FAN_REPORT_TID.

Link: https://lore.kernel.org/lkml/20260607003343.425939-1-anonymemeow@gmail.com/

---

Sorry for the late reply, I accidentally broke my system last week,
so I was busy repairing it. And I may not be able to respond in time
due to final exams this week, sorry.

---

AnonymeMeow (5):
  fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+
  fanotify21: Stop relying on exited child for pidfd error
  fanotify21: Simplify read_pidfd_fdinfo()
  fanotify21: Add test variants for FAN_REPORT_TID
  fanotify21: Add FAN_REPORT_TID pidfd coverage

 include/lapi/pidfd.h                          |   4 +
 .../kernel/syscalls/fanotify/fanotify20.c     |  19 +-
 .../kernel/syscalls/fanotify/fanotify21.c     | 191 +++++++++++-------
 3 files changed, 136 insertions(+), 78 deletions(-)

-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* [LTP] [PATCH 1/5] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+
  2026-06-15 18:06       ` [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID AnonymeMeow
@ 2026-06-15 18:06         ` AnonymeMeow
  2026-06-15 18:31           ` [LTP] " linuxtestproject.agent
  2026-06-16  7:40           ` [LTP] [PATCH 1/5] " Jan Kara
  2026-06-15 18:06         ` [LTP] [PATCH 2/5] fanotify21: Stop relying on exited child for pidfd error AnonymeMeow
                           ` (4 subsequent siblings)
  5 siblings, 2 replies; 24+ messages in thread
From: AnonymeMeow @ 2026-06-15 18:06 UTC (permalink / raw)
  To: jack; +Cc: amir73il, ltp, AnonymeMeow

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>
---
 .../kernel/syscalls/fanotify/fanotify20.c     | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

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);
 
 	if (fd > 0)
 		SAFE_CLOSE(fd);
-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH 2/5] fanotify21: Stop relying on exited child for pidfd error
  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:06         ` AnonymeMeow
  2026-06-16  7:48           ` Jan Kara
  2026-06-15 18:06         ` [LTP] [PATCH 3/5] fanotify21: Simplify read_pidfd_fdinfo() AnonymeMeow
                           ` (3 subsequent siblings)
  5 siblings, 1 reply; 24+ messages in thread
From: AnonymeMeow @ 2026-06-15 18:06 UTC (permalink / raw)
  To: jack; +Cc: amir73il, ltp, AnonymeMeow

fanotify21 used to verify the pidfd error case by generating an event
from a child process and reading the event after the child had exited.
This is no longer a stable way to trigger a pidfd error, because newer
kernels can report pidfds for exited event processes.

Read the event from a child process in a descendant PID namespace
instead. The reader cannot get the pidfd in the parent PID namespace
from fanotify, so pidfd creation will fail and the test can verify
FAN_NOPIDFD, or -ESRCH with FAN_REPORT_FD_ERROR.

Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
 .../kernel/syscalls/fanotify/fanotify21.c     | 55 ++++++++-----------
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
index 4d2115469..bd1a43513 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify21.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
@@ -42,7 +42,6 @@ struct pidfd_fdinfo_t {
 
 static struct test_case_t {
 	char *name;
-	int fork;
 	int want_pidfd_err;
 	int remount_ro;
 } test_cases[] = {
@@ -50,18 +49,15 @@ static struct test_case_t {
 		"return a valid pidfd for event created by self",
 		0,
 		0,
-		0,
 	},
 	{
-		"return invalid pidfd for event created by terminated child",
-		1,
+		"return invalid pidfd for reader in descendant PID namespace",
 		1,
 		0,
 	},
 	{
 		"fail to open rw fd for event created on read-only mount",
 		0,
-		0,
 		1,
 	},
 };
@@ -72,6 +68,11 @@ static struct pidfd_fdinfo_t *self_pidfd_fdinfo;
 
 static int fd_error_unsupported;
 
+static struct tst_clone_args clone_args = {
+	.flags = CLONE_NEWPID,
+	.exit_signal = SIGCHLD,
+};
+
 static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
 {
 	char *fdinfo_path;
@@ -100,24 +101,6 @@ static void generate_event(void)
 	SAFE_CLOSE(fd);
 }
 
-static void do_fork(void)
-{
-	int status;
-	pid_t child;
-
-	child = SAFE_FORK();
-	if (child == 0) {
-		SAFE_CLOSE(fanotify_fd);
-		generate_event();
-		exit(EXIT_SUCCESS);
-	}
-
-	SAFE_WAITPID(child, &status, 0);
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
-		tst_brk(TBROK,
-			"child process terminated incorrectly");
-}
-
 static void do_setup(void)
 {
 	int pidfd;
@@ -165,6 +148,8 @@ static void do_test(unsigned int num)
 	int nopidfd_err = tc->want_pidfd_err ?
 			  (tst_variant ? -ESRCH : FAN_NOPIDFD) : 0;
 	int fd_err = (tc->remount_ro && tst_variant) ? -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)" : "");
@@ -178,15 +163,20 @@ static void do_test(unsigned int num)
 	SAFE_MOUNT("none", MOUNT_PATH, "none", MS_BIND | MS_REMOUNT |
 		   (tc->remount_ro ? MS_RDONLY : 0), NULL);
 
+	generate_event();
+
 	/*
-	 * Generate the event in either self or a child process. Event
-	 * generation in a child process is done so that the FAN_NOPIDFD case
-	 * can be verified.
+	 * Read the event in either self or a child process in a descendant
+	 * PID namespace. A reader in a descendant PID namespace cannot obtain
+	 * the pidfd of the event process in the parent PID namespace so that
+	 * the FAN_NOPIDFD case can be verified.
 	 */
-	if (tc->fork)
-		do_fork();
-	else
-		generate_event();
+	if (tc->want_pidfd_err && (reader_pid = SAFE_CLONE(&clone_args))) {
+		SAFE_WAITPID(reader_pid, &reader_exit_status, 0);
+		if (!WIFEXITED(reader_exit_status) || WEXITSTATUS(reader_exit_status))
+			tst_brk(TBROK, "reader process exited incorrectly");
+		return;
+	}
 
 	/*
 	 * Read all of the queued events into the provided event
@@ -274,7 +264,7 @@ static void do_test(unsigned int num)
 			goto next_event;
 		} else if (tc->want_pidfd_err && info->pidfd == nopidfd_err) {
 			tst_res(TPASS,
-				"pid: %u terminated before pidfd was created, "
+				"pid: %u is invisible in reader PID namespace, "
 				"pidfd set to the value of: %d, as expected",
 				(unsigned int)event->pid,
 				nopidfd_err);
@@ -343,6 +333,9 @@ next_event:
 		if (event_pidfd_fdinfo)
 			free(event_pidfd_fdinfo);
 	}
+
+	if (tc->want_pidfd_err)
+		exit(0);
 }
 
 static void do_cleanup(void)
-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH 3/5] fanotify21: Simplify read_pidfd_fdinfo()
  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:06         ` [LTP] [PATCH 2/5] fanotify21: Stop relying on exited child for pidfd error AnonymeMeow
@ 2026-06-15 18:06         ` AnonymeMeow
  2026-06-16  7:46           ` Jan Kara
  2026-06-15 18:06         ` [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID AnonymeMeow
                           ` (2 subsequent siblings)
  5 siblings, 1 reply; 24+ messages in thread
From: AnonymeMeow @ 2026-06-15 18:06 UTC (permalink / raw)
  To: jack; +Cc: amir73il, ltp, AnonymeMeow

Let callers provide storage for struct pidfd_fdinfo_t instead of
allocating it in read_pidfd_fdinfo() every time. This removes
unnecessary allocation/free paths and the NULL checks after
read_pidfd_fdinfo() and simplifies the code.

Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
 .../kernel/syscalls/fanotify/fanotify21.c     | 61 ++++++-------------
 1 file changed, 20 insertions(+), 41 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
index bd1a43513..22f9767db 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify21.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
@@ -64,7 +64,7 @@ static struct test_case_t {
 
 static int fanotify_fd;
 static char event_buf[BUF_SZ];
-static struct pidfd_fdinfo_t *self_pidfd_fdinfo;
+static struct pidfd_fdinfo_t exp_pidfd_fdinfo;
 
 static int fd_error_unsupported;
 
@@ -73,12 +73,9 @@ static struct tst_clone_args clone_args = {
 	.exit_signal = SIGCHLD,
 };
 
-static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
+static void read_pidfd_fdinfo(int pidfd, struct pidfd_fdinfo_t *pidfd_fdinfo)
 {
 	char *fdinfo_path;
-	struct pidfd_fdinfo_t *pidfd_fdinfo;
-
-	pidfd_fdinfo = SAFE_MALLOC(sizeof(struct pidfd_fdinfo_t));
 
 	SAFE_ASPRINTF(&fdinfo_path, "/proc/self/fdinfo/%d", pidfd);
 	SAFE_FILE_LINES_SCANF(fdinfo_path, "pos: %d", &pidfd_fdinfo->pos);
@@ -88,8 +85,6 @@ static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
 	SAFE_FILE_LINES_SCANF(fdinfo_path, "NSpid: %d", &pidfd_fdinfo->ns_pid);
 
 	free(fdinfo_path);
-
-	return pidfd_fdinfo;
 }
 
 static void generate_event(void)
@@ -133,12 +128,9 @@ static void do_setup(void)
 
 	pidfd = SAFE_PIDFD_OPEN(getpid(), 0);
 
-	self_pidfd_fdinfo = read_pidfd_fdinfo(pidfd);
-	if (self_pidfd_fdinfo == NULL) {
-		tst_brk(TBROK,
-			"pidfd=%d, failed to read pidfd fdinfo",
-			pidfd);
-	}
+	read_pidfd_fdinfo(pidfd, &exp_pidfd_fdinfo);
+
+	SAFE_CLOSE(pidfd);
 }
 
 static void do_test(unsigned int num)
@@ -195,7 +187,7 @@ static void do_test(unsigned int num)
 	while (i < len) {
 		struct fanotify_event_metadata *event;
 		struct fanotify_event_info_pidfd *info;
-		struct pidfd_fdinfo_t *event_pidfd_fdinfo = NULL;
+		struct pidfd_fdinfo_t event_pidfd_fdinfo;
 
 		event = (struct fanotify_event_metadata *)&event_buf[i];
 		info = (struct fanotify_event_info_pidfd *)(event + 1);
@@ -275,39 +267,32 @@ static void do_test(unsigned int num)
 		 * No pidfd errors occurred, continue with verifying pidfd
 		 * fdinfo validity.
 		 */
-		event_pidfd_fdinfo = read_pidfd_fdinfo(info->pidfd);
-		if (event_pidfd_fdinfo == NULL) {
-			tst_brk(TBROK,
-				"reading fdinfo for pidfd: %d "
-				"describing pid: %u failed",
-				info->pidfd,
-				(unsigned int)event->pid);
-			goto next_event;
-		} else if (event_pidfd_fdinfo->pid != event->pid) {
+		read_pidfd_fdinfo(info->pidfd, &event_pidfd_fdinfo);
+		if (event_pidfd_fdinfo.pid != event->pid) {
 			tst_res(TFAIL,
 				"pidfd provided for incorrect pid "
 				"(expected pidfd for pid: %u, got pidfd for "
 				"pid: %u)",
 				(unsigned int)event->pid,
-				(unsigned int)event_pidfd_fdinfo->pid);
+				(unsigned int)event_pidfd_fdinfo.pid);
 			goto next_event;
-		} else if (memcmp(event_pidfd_fdinfo, self_pidfd_fdinfo,
+		} else if (memcmp(&event_pidfd_fdinfo, &exp_pidfd_fdinfo,
 				  sizeof(struct pidfd_fdinfo_t))) {
 			tst_res(TFAIL,
 				"pidfd fdinfo values for self and event differ "
 				"(expected pos: %d, flags: %x, mnt_id: %d, "
 				"pid: %d, ns_pid: %d, got pos: %d, "
 				"flags: %x, mnt_id: %d, pid: %d, ns_pid: %d",
-				self_pidfd_fdinfo->pos,
-				self_pidfd_fdinfo->flags,
-				self_pidfd_fdinfo->mnt_id,
-				self_pidfd_fdinfo->pid,
-				self_pidfd_fdinfo->ns_pid,
-				event_pidfd_fdinfo->pos,
-				event_pidfd_fdinfo->flags,
-				event_pidfd_fdinfo->mnt_id,
-				event_pidfd_fdinfo->pid,
-				event_pidfd_fdinfo->ns_pid);
+				exp_pidfd_fdinfo.pos,
+				exp_pidfd_fdinfo.flags,
+				exp_pidfd_fdinfo.mnt_id,
+				exp_pidfd_fdinfo.pid,
+				exp_pidfd_fdinfo.ns_pid,
+				event_pidfd_fdinfo.pos,
+				event_pidfd_fdinfo.flags,
+				event_pidfd_fdinfo.mnt_id,
+				event_pidfd_fdinfo.pid,
+				event_pidfd_fdinfo.ns_pid);
 			goto next_event;
 		} else {
 			tst_res(TPASS,
@@ -329,9 +314,6 @@ next_event:
 
 		if (info && info->pidfd >= 0)
 			SAFE_CLOSE(info->pidfd);
-
-		if (event_pidfd_fdinfo)
-			free(event_pidfd_fdinfo);
 	}
 
 	if (tc->want_pidfd_err)
@@ -343,9 +325,6 @@ static void do_cleanup(void)
 	if (fanotify_fd >= 0)
 		SAFE_CLOSE(fanotify_fd);
 
-	if (self_pidfd_fdinfo)
-		free(self_pidfd_fdinfo);
-
 	/* Unmount the bind mount */
 	SAFE_UMOUNT(MOUNT_PATH);
 }
-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID
  2026-06-15 18:06       ` [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID AnonymeMeow
                           ` (2 preceding siblings ...)
  2026-06-15 18:06         ` [LTP] [PATCH 3/5] fanotify21: Simplify read_pidfd_fdinfo() AnonymeMeow
@ 2026-06-15 18:06         ` AnonymeMeow
  2026-06-16  7:55           ` Jan Kara
  2026-06-16  8:24           ` Andrea Cervesato via ltp
  2026-06-15 18:06         ` [LTP] [PATCH 5/5] fanotify21: Add FAN_REPORT_TID pidfd coverage AnonymeMeow
  2026-06-16 11:39         ` [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID Amir Goldstein
  5 siblings, 2 replies; 24+ messages in thread
From: AnonymeMeow @ 2026-06-15 18:06 UTC (permalink / raw)
  To: jack; +Cc: amir73il, ltp, AnonymeMeow

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

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* [LTP] [PATCH 5/5] fanotify21: Add FAN_REPORT_TID pidfd coverage
  2026-06-15 18:06       ` [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID AnonymeMeow
                           ` (3 preceding siblings ...)
  2026-06-15 18:06         ` [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID AnonymeMeow
@ 2026-06-15 18:06         ` 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
  5 siblings, 1 reply; 24+ messages in thread
From: AnonymeMeow @ 2026-06-15 18:06 UTC (permalink / raw)
  To: jack; +Cc: amir73il, ltp, AnonymeMeow

Add a test case that generates an event from a thread. Without
FAN_REPORT_TID, the reported pidfd is expected to refer to the thread
group leader. With FAN_REPORT_TID, it is expected to refer to the
triggering thread. Keep the event thread alive until the reported pidfd
is verified, because pidfd fdinfo reports Pid: -1 after the thread
exits.

Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>
---
 .../kernel/syscalls/fanotify/fanotify21.c     | 47 ++++++++++++++++++-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
index fd43c8c1c..8a5b35334 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify21.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
@@ -24,6 +24,7 @@
 #include "tst_test.h"
 #include "tst_safe_stdio.h"
 #include "tst_safe_macros.h"
+#include "tst_safe_pthread.h"
 #include "lapi/pidfd.h"
 
 #ifdef HAVE_SYS_FANOTIFY_H
@@ -46,6 +47,7 @@ struct pidfd_fdinfo_t {
 
 static struct test_case_t {
 	char *name;
+	int event_by_thread;
 	int want_pidfd_err;
 	int remount_ro;
 } test_cases[] = {
@@ -53,15 +55,24 @@ static struct test_case_t {
 		"return a valid pidfd for event created by self",
 		0,
 		0,
+		0,
+	},
+	{
+		"return a valid pidfd for event created by thread",
+		1,
+		0,
+		0,
 	},
 	{
 		"return invalid pidfd for reader in descendant PID namespace",
+		0,
 		1,
 		0,
 	},
 	{
 		"fail to open rw fd for event created on read-only mount",
 		0,
+		0,
 		1,
 	},
 };
@@ -107,6 +118,26 @@ static void generate_event(void)
 	SAFE_CLOSE(fd);
 }
 
+static void *generate_event_pthread(void *args LTP_ATTRIBUTE_UNUSED)
+{
+	generate_event();
+	TST_CHECKPOINT_WAIT(0);
+	return NULL;
+}
+
+static pthread_t event_thread_create(void)
+{
+	pthread_t pthread_id;
+	SAFE_PTHREAD_CREATE(&pthread_id, NULL, generate_event_pthread, NULL);
+	return pthread_id;
+}
+
+static void event_thread_join(pthread_t pthread_id)
+{
+	TST_CHECKPOINT_WAKE(0);
+	SAFE_PTHREAD_JOIN(pthread_id, NULL);
+}
+
 static const char *test_variant_name(void)
 {
 	switch (tst_variant) {
@@ -164,6 +195,7 @@ static void do_test(unsigned int num)
 	int nopidfd_err = tc->want_pidfd_err ?
 			  (TST_VARIANT_FD_ERROR ? -ESRCH : FAN_NOPIDFD) : 0;
 	int fd_err = (tc->remount_ro && TST_VARIANT_FD_ERROR) ? -EROFS : 0;
+	pthread_t event_thread;
 	pid_t reader_pid;
 	int reader_exit_status;
 
@@ -185,7 +217,16 @@ static void do_test(unsigned int num)
 	SAFE_MOUNT("none", MOUNT_PATH, "none", MS_BIND | MS_REMOUNT |
 		   (tc->remount_ro ? MS_RDONLY : 0), NULL);
 
-	generate_event();
+	/*
+	 * Generate the event by either self or a thread. Event generation in
+	 * a thread is done so that in FAN_REPORT_TID mode the pidfd can be
+	 * verified to refer to the tid, not the tgid. The thread waits until
+	 * the pidfd is verified before exiting.
+	 */
+	if (tc->event_by_thread)
+		event_thread = event_thread_create();
+	else
+		generate_event();
 
 	/*
 	 * Read the event in either self or a child process in a descendant
@@ -348,6 +389,9 @@ next_event:
 
 	if (tc->want_pidfd_err)
 		exit(0);
+
+	if (tc->event_by_thread)
+		event_thread_join(event_thread);
 }
 
 static void do_cleanup(void)
@@ -370,6 +414,7 @@ static struct tst_test test = {
 	.mount_device = 1,
 	.mntpoint = MOUNT_PATH,
 	.forks_child = 1,
+	.needs_checkpoints = 1,
 };
 
 #else
-- 
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 24+ messages in thread

* Re: [LTP] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+
  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           ` linuxtestproject.agent
  2026-06-16  7:40           ` [LTP] [PATCH 1/5] " Jan Kara
  1 sibling, 0 replies; 24+ messages in thread
From: linuxtestproject.agent @ 2026-06-15 18:31 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: ltp

Hi AnonymeMeow,

On 2026-06-16, AnonymeMeow wrote:
> fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+

--- [PATCH 1/5] ---

> fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+

> + * FAN_REPORT_PIDFD combined with FAN_REPORT_TID is supported since v7.2-rc1.

The latest stable kernel release is v7.1, so v7.2 has not been
released yet. Per LTP convention, tests for features not yet in a
mainline kernel release need the [STAGING] subject prefix.

Since the patch adjusts test expectations for the unreleased v7.2
feature, the subject should be prefixed with [STAGING].

--- [PATCH 4/5] ---

> fanotify21: Add test variants for FAN_REPORT_TID

Same staging concern here. The new test variants exercise
FAN_REPORT_PIDFD combined with FAN_REPORT_TID, which is a v7.2-rc1
feature. This commit should also carry the [STAGING] prefix until
v7.2 is released.

--- [PATCH 5/5] ---

> fanotify21: Add FAN_REPORT_TID pidfd coverage

Same as above: the thread-based pidfd verification is for the
unreleased v7.2 FAN_REPORT_TID support and needs [STAGING].

Verdict - Needs revision

Pre-existing issues (not introduced by this series):

- fanotify20.c: `static int fd;` is not initialized to -1, and the
  validity checks use `if (fd > 0)` instead of `if (fd != -1)`.

- fanotify21.c: `static int fanotify_fd;` is not initialized to -1,
  and the cleanup check uses `if (fanotify_fd >= 0)` instead of
  `if (fanotify_fd != -1)`.

---
Note:

The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.

Regards,
LTP AI Reviewer

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 1/5] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+
  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           ` Jan Kara
  2026-06-16 11:27             ` Amir Goldstein
  1 sibling, 1 reply; 24+ messages in thread
From: Jan Kara @ 2026-06-16  7:40 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: amir73il, jack, ltp

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 3/5] fanotify21: Simplify read_pidfd_fdinfo()
  2026-06-15 18:06         ` [LTP] [PATCH 3/5] fanotify21: Simplify read_pidfd_fdinfo() AnonymeMeow
@ 2026-06-16  7:46           ` Jan Kara
  0 siblings, 0 replies; 24+ messages in thread
From: Jan Kara @ 2026-06-16  7:46 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: amir73il, jack, ltp

On Tue 16-06-26 02:06:27, AnonymeMeow wrote:
> Let callers provide storage for struct pidfd_fdinfo_t instead of
> allocating it in read_pidfd_fdinfo() every time. This removes
> unnecessary allocation/free paths and the NULL checks after
> read_pidfd_fdinfo() and simplifies the code.
> 
> Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  .../kernel/syscalls/fanotify/fanotify21.c     | 61 ++++++-------------
>  1 file changed, 20 insertions(+), 41 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
> index bd1a43513..22f9767db 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify21.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
> @@ -64,7 +64,7 @@ static struct test_case_t {
>  
>  static int fanotify_fd;
>  static char event_buf[BUF_SZ];
> -static struct pidfd_fdinfo_t *self_pidfd_fdinfo;
> +static struct pidfd_fdinfo_t exp_pidfd_fdinfo;
>  
>  static int fd_error_unsupported;
>  
> @@ -73,12 +73,9 @@ static struct tst_clone_args clone_args = {
>  	.exit_signal = SIGCHLD,
>  };
>  
> -static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
> +static void read_pidfd_fdinfo(int pidfd, struct pidfd_fdinfo_t *pidfd_fdinfo)
>  {
>  	char *fdinfo_path;
> -	struct pidfd_fdinfo_t *pidfd_fdinfo;
> -
> -	pidfd_fdinfo = SAFE_MALLOC(sizeof(struct pidfd_fdinfo_t));
>  
>  	SAFE_ASPRINTF(&fdinfo_path, "/proc/self/fdinfo/%d", pidfd);
>  	SAFE_FILE_LINES_SCANF(fdinfo_path, "pos: %d", &pidfd_fdinfo->pos);
> @@ -88,8 +85,6 @@ static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
>  	SAFE_FILE_LINES_SCANF(fdinfo_path, "NSpid: %d", &pidfd_fdinfo->ns_pid);
>  
>  	free(fdinfo_path);
> -
> -	return pidfd_fdinfo;
>  }
>  
>  static void generate_event(void)
> @@ -133,12 +128,9 @@ static void do_setup(void)
>  
>  	pidfd = SAFE_PIDFD_OPEN(getpid(), 0);
>  
> -	self_pidfd_fdinfo = read_pidfd_fdinfo(pidfd);
> -	if (self_pidfd_fdinfo == NULL) {
> -		tst_brk(TBROK,
> -			"pidfd=%d, failed to read pidfd fdinfo",
> -			pidfd);
> -	}
> +	read_pidfd_fdinfo(pidfd, &exp_pidfd_fdinfo);
> +
> +	SAFE_CLOSE(pidfd);
>  }
>  
>  static void do_test(unsigned int num)
> @@ -195,7 +187,7 @@ static void do_test(unsigned int num)
>  	while (i < len) {
>  		struct fanotify_event_metadata *event;
>  		struct fanotify_event_info_pidfd *info;
> -		struct pidfd_fdinfo_t *event_pidfd_fdinfo = NULL;
> +		struct pidfd_fdinfo_t event_pidfd_fdinfo;
>  
>  		event = (struct fanotify_event_metadata *)&event_buf[i];
>  		info = (struct fanotify_event_info_pidfd *)(event + 1);
> @@ -275,39 +267,32 @@ static void do_test(unsigned int num)
>  		 * No pidfd errors occurred, continue with verifying pidfd
>  		 * fdinfo validity.
>  		 */
> -		event_pidfd_fdinfo = read_pidfd_fdinfo(info->pidfd);
> -		if (event_pidfd_fdinfo == NULL) {
> -			tst_brk(TBROK,
> -				"reading fdinfo for pidfd: %d "
> -				"describing pid: %u failed",
> -				info->pidfd,
> -				(unsigned int)event->pid);
> -			goto next_event;
> -		} else if (event_pidfd_fdinfo->pid != event->pid) {
> +		read_pidfd_fdinfo(info->pidfd, &event_pidfd_fdinfo);
> +		if (event_pidfd_fdinfo.pid != event->pid) {
>  			tst_res(TFAIL,
>  				"pidfd provided for incorrect pid "
>  				"(expected pidfd for pid: %u, got pidfd for "
>  				"pid: %u)",
>  				(unsigned int)event->pid,
> -				(unsigned int)event_pidfd_fdinfo->pid);
> +				(unsigned int)event_pidfd_fdinfo.pid);
>  			goto next_event;
> -		} else if (memcmp(event_pidfd_fdinfo, self_pidfd_fdinfo,
> +		} else if (memcmp(&event_pidfd_fdinfo, &exp_pidfd_fdinfo,
>  				  sizeof(struct pidfd_fdinfo_t))) {
>  			tst_res(TFAIL,
>  				"pidfd fdinfo values for self and event differ "
>  				"(expected pos: %d, flags: %x, mnt_id: %d, "
>  				"pid: %d, ns_pid: %d, got pos: %d, "
>  				"flags: %x, mnt_id: %d, pid: %d, ns_pid: %d",
> -				self_pidfd_fdinfo->pos,
> -				self_pidfd_fdinfo->flags,
> -				self_pidfd_fdinfo->mnt_id,
> -				self_pidfd_fdinfo->pid,
> -				self_pidfd_fdinfo->ns_pid,
> -				event_pidfd_fdinfo->pos,
> -				event_pidfd_fdinfo->flags,
> -				event_pidfd_fdinfo->mnt_id,
> -				event_pidfd_fdinfo->pid,
> -				event_pidfd_fdinfo->ns_pid);
> +				exp_pidfd_fdinfo.pos,
> +				exp_pidfd_fdinfo.flags,
> +				exp_pidfd_fdinfo.mnt_id,
> +				exp_pidfd_fdinfo.pid,
> +				exp_pidfd_fdinfo.ns_pid,
> +				event_pidfd_fdinfo.pos,
> +				event_pidfd_fdinfo.flags,
> +				event_pidfd_fdinfo.mnt_id,
> +				event_pidfd_fdinfo.pid,
> +				event_pidfd_fdinfo.ns_pid);
>  			goto next_event;
>  		} else {
>  			tst_res(TPASS,
> @@ -329,9 +314,6 @@ next_event:
>  
>  		if (info && info->pidfd >= 0)
>  			SAFE_CLOSE(info->pidfd);
> -
> -		if (event_pidfd_fdinfo)
> -			free(event_pidfd_fdinfo);
>  	}
>  
>  	if (tc->want_pidfd_err)
> @@ -343,9 +325,6 @@ static void do_cleanup(void)
>  	if (fanotify_fd >= 0)
>  		SAFE_CLOSE(fanotify_fd);
>  
> -	if (self_pidfd_fdinfo)
> -		free(self_pidfd_fdinfo);
> -
>  	/* Unmount the bind mount */
>  	SAFE_UMOUNT(MOUNT_PATH);
>  }
> -- 
> 2.54.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 2/5] fanotify21: Stop relying on exited child for pidfd error
  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
  0 siblings, 0 replies; 24+ messages in thread
From: Jan Kara @ 2026-06-16  7:48 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: amir73il, jack, ltp

On Tue 16-06-26 02:06:26, AnonymeMeow wrote:
> fanotify21 used to verify the pidfd error case by generating an event
> from a child process and reading the event after the child had exited.
> This is no longer a stable way to trigger a pidfd error, because newer
> kernels can report pidfds for exited event processes.
> 
> Read the event from a child process in a descendant PID namespace
> instead. The reader cannot get the pidfd in the parent PID namespace
> from fanotify, so pidfd creation will fail and the test can verify
> FAN_NOPIDFD, or -ESRCH with FAN_REPORT_FD_ERROR.
> 
> Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  .../kernel/syscalls/fanotify/fanotify21.c     | 55 ++++++++-----------
>  1 file changed, 24 insertions(+), 31 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
> index 4d2115469..bd1a43513 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify21.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
> @@ -42,7 +42,6 @@ struct pidfd_fdinfo_t {
>  
>  static struct test_case_t {
>  	char *name;
> -	int fork;
>  	int want_pidfd_err;
>  	int remount_ro;
>  } test_cases[] = {
> @@ -50,18 +49,15 @@ static struct test_case_t {
>  		"return a valid pidfd for event created by self",
>  		0,
>  		0,
> -		0,
>  	},
>  	{
> -		"return invalid pidfd for event created by terminated child",
> -		1,
> +		"return invalid pidfd for reader in descendant PID namespace",
>  		1,
>  		0,
>  	},
>  	{
>  		"fail to open rw fd for event created on read-only mount",
>  		0,
> -		0,
>  		1,
>  	},
>  };
> @@ -72,6 +68,11 @@ static struct pidfd_fdinfo_t *self_pidfd_fdinfo;
>  
>  static int fd_error_unsupported;
>  
> +static struct tst_clone_args clone_args = {
> +	.flags = CLONE_NEWPID,
> +	.exit_signal = SIGCHLD,
> +};
> +
>  static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
>  {
>  	char *fdinfo_path;
> @@ -100,24 +101,6 @@ static void generate_event(void)
>  	SAFE_CLOSE(fd);
>  }
>  
> -static void do_fork(void)
> -{
> -	int status;
> -	pid_t child;
> -
> -	child = SAFE_FORK();
> -	if (child == 0) {
> -		SAFE_CLOSE(fanotify_fd);
> -		generate_event();
> -		exit(EXIT_SUCCESS);
> -	}
> -
> -	SAFE_WAITPID(child, &status, 0);
> -	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
> -		tst_brk(TBROK,
> -			"child process terminated incorrectly");
> -}
> -
>  static void do_setup(void)
>  {
>  	int pidfd;
> @@ -165,6 +148,8 @@ static void do_test(unsigned int num)
>  	int nopidfd_err = tc->want_pidfd_err ?
>  			  (tst_variant ? -ESRCH : FAN_NOPIDFD) : 0;
>  	int fd_err = (tc->remount_ro && tst_variant) ? -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)" : "");
> @@ -178,15 +163,20 @@ static void do_test(unsigned int num)
>  	SAFE_MOUNT("none", MOUNT_PATH, "none", MS_BIND | MS_REMOUNT |
>  		   (tc->remount_ro ? MS_RDONLY : 0), NULL);
>  
> +	generate_event();
> +
>  	/*
> -	 * Generate the event in either self or a child process. Event
> -	 * generation in a child process is done so that the FAN_NOPIDFD case
> -	 * can be verified.
> +	 * Read the event in either self or a child process in a descendant
> +	 * PID namespace. A reader in a descendant PID namespace cannot obtain
> +	 * the pidfd of the event process in the parent PID namespace so that
> +	 * the FAN_NOPIDFD case can be verified.
>  	 */
> -	if (tc->fork)
> -		do_fork();
> -	else
> -		generate_event();
> +	if (tc->want_pidfd_err && (reader_pid = SAFE_CLONE(&clone_args))) {
> +		SAFE_WAITPID(reader_pid, &reader_exit_status, 0);
> +		if (!WIFEXITED(reader_exit_status) || WEXITSTATUS(reader_exit_status))
> +			tst_brk(TBROK, "reader process exited incorrectly");
> +		return;
> +	}
>  
>  	/*
>  	 * Read all of the queued events into the provided event
> @@ -274,7 +264,7 @@ static void do_test(unsigned int num)
>  			goto next_event;
>  		} else if (tc->want_pidfd_err && info->pidfd == nopidfd_err) {
>  			tst_res(TPASS,
> -				"pid: %u terminated before pidfd was created, "
> +				"pid: %u is invisible in reader PID namespace, "
>  				"pidfd set to the value of: %d, as expected",
>  				(unsigned int)event->pid,
>  				nopidfd_err);
> @@ -343,6 +333,9 @@ next_event:
>  		if (event_pidfd_fdinfo)
>  			free(event_pidfd_fdinfo);
>  	}
> +
> +	if (tc->want_pidfd_err)
> +		exit(0);
>  }
>  
>  static void do_cleanup(void)
> -- 
> 2.54.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID
  2026-06-15 18:06         ` [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID AnonymeMeow
@ 2026-06-16  7:55           ` Jan Kara
  2026-06-16  8:24           ` Andrea Cervesato via ltp
  1 sibling, 0 replies; 24+ messages in thread
From: Jan Kara @ 2026-06-16  7:55 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: amir73il, jack, ltp

On Tue 16-06-26 02:06:28, AnonymeMeow wrote:
> 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>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  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
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 5/5] fanotify21: Add FAN_REPORT_TID pidfd coverage
  2026-06-15 18:06         ` [LTP] [PATCH 5/5] fanotify21: Add FAN_REPORT_TID pidfd coverage AnonymeMeow
@ 2026-06-16  7:57           ` Jan Kara
  0 siblings, 0 replies; 24+ messages in thread
From: Jan Kara @ 2026-06-16  7:57 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: amir73il, jack, ltp

On Tue 16-06-26 02:06:29, AnonymeMeow wrote:
> Add a test case that generates an event from a thread. Without
> FAN_REPORT_TID, the reported pidfd is expected to refer to the thread
> group leader. With FAN_REPORT_TID, it is expected to refer to the
> triggering thread. Keep the event thread alive until the reported pidfd
> is verified, because pidfd fdinfo reports Pid: -1 after the thread
> exits.
> 
> Signed-off-by: AnonymeMeow <anonymemeow@gmail.com>

Nice! Feel free to add:

Reviewed-by: Jan Kara <jack@suse.cz>

								Honza

> ---
>  .../kernel/syscalls/fanotify/fanotify21.c     | 47 ++++++++++++++++++-
>  1 file changed, 46 insertions(+), 1 deletion(-)
> 
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
> index fd43c8c1c..8a5b35334 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify21.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
> @@ -24,6 +24,7 @@
>  #include "tst_test.h"
>  #include "tst_safe_stdio.h"
>  #include "tst_safe_macros.h"
> +#include "tst_safe_pthread.h"
>  #include "lapi/pidfd.h"
>  
>  #ifdef HAVE_SYS_FANOTIFY_H
> @@ -46,6 +47,7 @@ struct pidfd_fdinfo_t {
>  
>  static struct test_case_t {
>  	char *name;
> +	int event_by_thread;
>  	int want_pidfd_err;
>  	int remount_ro;
>  } test_cases[] = {
> @@ -53,15 +55,24 @@ static struct test_case_t {
>  		"return a valid pidfd for event created by self",
>  		0,
>  		0,
> +		0,
> +	},
> +	{
> +		"return a valid pidfd for event created by thread",
> +		1,
> +		0,
> +		0,
>  	},
>  	{
>  		"return invalid pidfd for reader in descendant PID namespace",
> +		0,
>  		1,
>  		0,
>  	},
>  	{
>  		"fail to open rw fd for event created on read-only mount",
>  		0,
> +		0,
>  		1,
>  	},
>  };
> @@ -107,6 +118,26 @@ static void generate_event(void)
>  	SAFE_CLOSE(fd);
>  }
>  
> +static void *generate_event_pthread(void *args LTP_ATTRIBUTE_UNUSED)
> +{
> +	generate_event();
> +	TST_CHECKPOINT_WAIT(0);
> +	return NULL;
> +}
> +
> +static pthread_t event_thread_create(void)
> +{
> +	pthread_t pthread_id;
> +	SAFE_PTHREAD_CREATE(&pthread_id, NULL, generate_event_pthread, NULL);
> +	return pthread_id;
> +}
> +
> +static void event_thread_join(pthread_t pthread_id)
> +{
> +	TST_CHECKPOINT_WAKE(0);
> +	SAFE_PTHREAD_JOIN(pthread_id, NULL);
> +}
> +
>  static const char *test_variant_name(void)
>  {
>  	switch (tst_variant) {
> @@ -164,6 +195,7 @@ static void do_test(unsigned int num)
>  	int nopidfd_err = tc->want_pidfd_err ?
>  			  (TST_VARIANT_FD_ERROR ? -ESRCH : FAN_NOPIDFD) : 0;
>  	int fd_err = (tc->remount_ro && TST_VARIANT_FD_ERROR) ? -EROFS : 0;
> +	pthread_t event_thread;
>  	pid_t reader_pid;
>  	int reader_exit_status;
>  
> @@ -185,7 +217,16 @@ static void do_test(unsigned int num)
>  	SAFE_MOUNT("none", MOUNT_PATH, "none", MS_BIND | MS_REMOUNT |
>  		   (tc->remount_ro ? MS_RDONLY : 0), NULL);
>  
> -	generate_event();
> +	/*
> +	 * Generate the event by either self or a thread. Event generation in
> +	 * a thread is done so that in FAN_REPORT_TID mode the pidfd can be
> +	 * verified to refer to the tid, not the tgid. The thread waits until
> +	 * the pidfd is verified before exiting.
> +	 */
> +	if (tc->event_by_thread)
> +		event_thread = event_thread_create();
> +	else
> +		generate_event();
>  
>  	/*
>  	 * Read the event in either self or a child process in a descendant
> @@ -348,6 +389,9 @@ next_event:
>  
>  	if (tc->want_pidfd_err)
>  		exit(0);
> +
> +	if (tc->event_by_thread)
> +		event_thread_join(event_thread);
>  }
>  
>  static void do_cleanup(void)
> @@ -370,6 +414,7 @@ static struct tst_test test = {
>  	.mount_device = 1,
>  	.mntpoint = MOUNT_PATH,
>  	.forks_child = 1,
> +	.needs_checkpoints = 1,
>  };
>  
>  #else
> -- 
> 2.54.0
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID
  2026-06-15 18:06         ` [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID AnonymeMeow
  2026-06-16  7:55           ` Jan Kara
@ 2026-06-16  8:24           ` Andrea Cervesato via ltp
  2026-06-16  9:12             ` Jan Kara
  1 sibling, 1 reply; 24+ messages in thread
From: Andrea Cervesato via ltp @ 2026-06-16  8:24 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: amir73il, jack, ltp, AnonymeMeow

Hi,

the patch-set is failing to compile on our CI. Please send a new
version fixing it:

https://github.com/linux-test-project/ltp/actions/runs/27572447779/job/81512172691

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Jan Kara @ 2026-06-16  9:12 UTC (permalink / raw)
  To: Andrea Cervesato; +Cc: amir73il, jack, ltp, AnonymeMeow

Hello!

On Tue 16-06-26 08:24:33, Andrea Cervesato wrote:
> the patch-set is failing to compile on our CI. Please send a new
> version fixing it:
> 
> https://github.com/linux-test-project/ltp/actions/runs/27572447779/job/81512172691

Hum, I had a look and the failure actually is:

parse_opts.c: In function 'usc_test_looping':
parse_opts.c:521:3: warning: call to function 'usc_recressive_func' without a real prototype [-Wunprototyped-calls]
   usc_recressive_func(0, STD_LP_recfun, *STD_bigstack);
   ^
parse_opts.c:107:13: note: 'usc_recressive_func' was declared here
 static void usc_recressive_func();
             ^
CC libs/numa/tse_numa.o
AR libltpnuma.a
RANLIB libltpnuma.a
CC lib/random_range.o
CC lib/parse_opts.o
CC lib/safe_file_ops.o
In file included from ../../include/tse_sigwait.h:11:0,
                 from tse_sigwait.c:8:
../../include/tst_timer.h: In function 'tst_ts_from_timespec':
../../include/tst_timer.h:626:3: warning: missing initializer for field 'tv_nsec' of 'struct timespec' [-Wmissing-field-initializers]
   .ts.libc_ts.tv_nsec = ts.tv_nsec,
   ^
In file included from /usr/include/sys/select.h:43:0,
                 from /usr/include/sys/types.h:219,
                 from /usr/include/stdlib.h:314,
                 from tse_sigwait.c:6:
/usr/include/time.h:123:23: note: 'tv_nsec' declared here
     __syscall_slong_t tv_nsec; /* Nanoseconds.  */
                       ^
CC lib/safe_pthread.o

So I'm a bit at loss what change in fanotify tests could have caused a
failure in compilation of the generic LTP library code? Any idea?

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID
  2026-06-16  9:12             ` Jan Kara
@ 2026-06-16  9:37               ` Andrea Cervesato via ltp
  0 siblings, 0 replies; 24+ messages in thread
From: Andrea Cervesato via ltp @ 2026-06-16  9:37 UTC (permalink / raw)
  To: Jan Kara; +Cc: amir73il, jack, ltp, AnonymeMeow

Hi Jan,

> Hello!
> 
> On Tue 16-06-26 08:24:33, Andrea Cervesato wrote:
> > the patch-set is failing to compile on our CI. Please send a new
> > version fixing it:
> > 
> > https://github.com/linux-test-project/ltp/actions/runs/27572447779/job/81512172691
> 
> Hum, I had a look and the failure actually is:
> 
> parse_opts.c: In function 'usc_test_looping':
> parse_opts.c:521:3: warning: call to function 'usc_recressive_func' without a real prototype [-Wunprototyped-calls]
>    usc_recressive_func(0, STD_LP_recfun, *STD_bigstack);
>    ^
> parse_opts.c:107:13: note: 'usc_recressive_func' was declared here
>  static void usc_recressive_func();
>              ^
> CC libs/numa/tse_numa.o
> AR libltpnuma.a
> RANLIB libltpnuma.a
> CC lib/random_range.o
> CC lib/parse_opts.o
> CC lib/safe_file_ops.o
> In file included from ../../include/tse_sigwait.h:11:0,
>                  from tse_sigwait.c:8:
> ../../include/tst_timer.h: In function 'tst_ts_from_timespec':
> ../../include/tst_timer.h:626:3: warning: missing initializer for field 'tv_nsec' of 'struct timespec' [-Wmissing-field-initializers]
>    .ts.libc_ts.tv_nsec = ts.tv_nsec,
>    ^
> In file included from /usr/include/sys/select.h:43:0,
>                  from /usr/include/sys/types.h:219,
>                  from /usr/include/stdlib.h:314,
>                  from tse_sigwait.c:6:
> /usr/include/time.h:123:23: note: 'tv_nsec' declared here
>      __syscall_slong_t tv_nsec; /* Nanoseconds.  */
>                        ^
> CC lib/safe_pthread.o
> 
> So I'm a bit at loss what change in fanotify tests could have caused a
> failure in compilation of the generic LTP library code? Any idea?
> 
> 								Honza
> -- 
> Jan Kara <jack@suse.com>
> SUSE Labs, CR

Those are warnings caused by old GCC. It's possible to fix them
by changing the explicit struct initialization with a 2 step init
such as:

struct mystruct s;
s.item0 = i1;
s.item1 = i2;

The real issue is that fanotify21 needs to link pthread:

-fanotify11: CFLAGS+=-pthread
+fanotify11 fanotify21: CFLAGS+=-pthread

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 1/5] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+
  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
  0 siblings, 1 reply; 24+ messages in thread
From: Amir Goldstein @ 2026-06-16 11:27 UTC (permalink / raw)
  To: Jan Kara; +Cc: ltp, AnonymeMeow

On Tue, Jun 16, 2026 at 9:40 AM Jan Kara <jack@suse.cz> 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 <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.

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

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID
  2026-06-15 18:06       ` [LTP] [PATCH 0/5] fanotify: update pidfd tests for FAN_REPORT_TID AnonymeMeow
                           ` (4 preceding siblings ...)
  2026-06-15 18:06         ` [LTP] [PATCH 5/5] fanotify21: Add FAN_REPORT_TID pidfd coverage AnonymeMeow
@ 2026-06-16 11:39         ` Amir Goldstein
  5 siblings, 0 replies; 24+ messages in thread
From: Amir Goldstein @ 2026-06-16 11:39 UTC (permalink / raw)
  To: AnonymeMeow; +Cc: jack, ltp

On Mon, Jun 15, 2026 at 8:06 PM AnonymeMeow <anonymemeow@gmail.com> wrote:
>
> This patch set updates fanotify pidfd tests for the kernel change that
> adds FAN_REPORT_PIDFD support together with FAN_REPORT_TID.
>
> Link: https://lore.kernel.org/lkml/20260607003343.425939-1-anonymemeow@gmail.com/
>
> ---
>
> Sorry for the late reply, I accidentally broke my system last week,
> so I was busy repairing it. And I may not be able to respond in time
> due to final exams this week, sorry.
>

Great series. Nice job!

I am glad that you managed to salvage the variants idea
and made the test better on the way.

Feel free to add to the series:
Reviewed-by: Amir Goldstein <amir73il@gmail.com>

(no need to repost for adding RVB only if reposting for another reason)

Thanks!
Amir.

> ---
>
> AnonymeMeow (5):
>   fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+
>   fanotify21: Stop relying on exited child for pidfd error
>   fanotify21: Simplify read_pidfd_fdinfo()
>   fanotify21: Add test variants for FAN_REPORT_TID
>   fanotify21: Add FAN_REPORT_TID pidfd coverage
>
>  include/lapi/pidfd.h                          |   4 +
>  .../kernel/syscalls/fanotify/fanotify20.c     |  19 +-
>  .../kernel/syscalls/fanotify/fanotify21.c     | 191 +++++++++++-------
>  3 files changed, 136 insertions(+), 78 deletions(-)
>
> --
> 2.54.0
>

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

* Re: [LTP] [PATCH 1/5] fanotify20: Allow FAN_REPORT_PIDFD with FAN_REPORT_TID on v7.2+
  2026-06-16 11:27             ` Amir Goldstein
@ 2026-06-16 11:48               ` Jan Kara
  0 siblings, 0 replies; 24+ messages in thread
From: Jan Kara @ 2026-06-16 11:48 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Jan Kara, ltp, AnonymeMeow

On Tue 16-06-26 13:27:20, Amir Goldstein wrote:
> On Tue, Jun 16, 2026 at 9:40 AM Jan Kara <jack@suse.cz> 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 <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.
> 
> 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

Right, I probably overengineered this :) Just skip the test for newer
kernel versions.

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

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2026-06-16 11:49 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-07  0:33 [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions AnonymeMeow
2026-06-07  0:33 ` [PATCH v5 1/2] fanotify: report thread pidfds for FAN_REPORT_TID AnonymeMeow
2026-06-07  0:33 ` [PATCH v5 2/2] fanotify: allow reporting pidfds for reaped tasks AnonymeMeow
2026-06-09 10:29 ` [PATCH v5 0/2] fanotify: lift pidfd reporting restrictions Jan Kara
2026-06-10  7:31   ` Christian Brauner
2026-06-10  9:14     ` Jan Kara
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         ` [LTP] [PATCH 4/5] fanotify21: Add test variants for FAN_REPORT_TID AnonymeMeow
2026-06-16  7:55           ` 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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.