Skip to contentSkip to conversation

fanotify: update pidfd tests for FAN_REPORT_TID

PATCH In review AnonymeMeow 6 participants 17 messages Jun 16 – Sep 1

lore
Share & tools
lore
#0 lore raw

v2 cover fanotify: update pidfd tests for FAN_REPORT_TID

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

---

Changes since v1:
- Added upstream commit reference in comment
- skip FAN_REPORT_PIDFD | FAN_REPORT_TID tests for kernel v7.2+
- Added pthread link flag

v1: https://lore.kernel.org/ltp/[email protected]/

---

AnonymeMeow (5):
fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test 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 +
 testcases/kernel/syscalls/fanotify/Makefile   |   2 +-
 .../kernel/syscalls/fanotify/fanotify20.c     |  14 +-
 .../kernel/syscalls/fanotify/fanotify21.c     | 192 +++++++++++-------
 4 files changed, 135 insertions(+), 77 deletions(-)
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH v2 1/5 fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test on v7.2+

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.

---
 testcases/kernel/syscalls/fanotify/fanotify20.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify20.c +10 -4
index b32ecf6aa..f395d77ee 100644
@@ -8,13 +8,15 @@
 
 /*\
  * 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
+ * in 17171128513b ("fanotify: report thread pidfds for FAN_REPORT_TID").
  */
 
 #define _GNU_SOURCE
@@ -45,6 +47,10 @@ static struct test_case_t {
 
 static void do_setup(void)
 {
+	if (tst_kvercmp(7, 2, 0) >= 0)
+		tst_brk(TCONF, "FAN_REPORT_PIDFD | FAN_REPORT_TID is supported "
+			       "since v7.2, skipping test");
+
 	/*
 	 * An explicit check for FAN_REPORT_PIDFD is performed early on in the
 	 * test initialization as it's a prerequisite for all test cases.
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test on v7.2+

Hi AnonymeMeow,

Quoted 1 line · AnonymeMeow

fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test on v7.2+

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

testcases/kernel/syscalls/fanotify/fanotify20.c static struct test_case_t { · line 52

Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify20.c +3 -0
+	if (tst_kvercmp(7, 2, 0) >= 0)
+		tst_brk(TCONF, "FAN_REPORT_PIDFD | FAN_REPORT_TID is supported "
+			       "since v7.2, skipping test");

tst_brk(TCONF) in setup aborts ALL test cases. The second test case (FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME expected to succeed) is still valid on v7.2+ but will never run.

Should this be a per-test-case skip instead, so that only the EINVAL case is skipped on v7.2+?

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

Review

Quoted 10 lines

fanotify21: Add test variants for FAN_REPORT_TID

(quoted diff) +8 -0
+	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;
+	}

FAN_REPORT_PIDFD combined with FAN_REPORT_TID is a v7.2 feature and v7.2 has not been released yet (latest stable is v7.1). Per LTP convention, tests exercising unreleased kernel features need a [STAGING] subject prefix and should go into runtest/staging until the kernel release is finalized.

This applies to patches 4/5 and 5/5 which add FAN_REPORT_TID variant coverage.

Verdict - Needs revision

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

- testcases/kernel/syscalls/fanotify/Makefile: per-target CFLAGS is placed before testcases.mk instead of between the two includes.
- testcases/kernel/syscalls/fanotify/fanotify21.c: fanotify_fd is initialized to 0 (implicit) and the cleanup guard uses >= 0 instead of the LTP-conventional -1 init + != -1 guard.

---
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

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test on v7.2+

Hi AnonymeMeow,

Quoted 10 lines

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

testcases/kernel/syscalls/fanotify/fanotify20.c static struct test_case_t { · line 52

Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify20.c +3 -0
+	if (tst_kvercmp(7, 2, 0) >= 0)
+		tst_brk(TCONF, "FAN_REPORT_PIDFD | FAN_REPORT_TID is supported "
+			       "since v7.2, skipping test");

tst_brk(TCONF) in setup aborts ALL test cases. The second test case (FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME expected to succeed) is still valid on v7.2+ but will never run.

Quoted 2 lines

Should this be a per-test-case skip instead, so that only the EINVAL case is skipped on v7.2+?

This observation is correct. If v7.2+ enabled only pidfd + tid combination for fanotify, we should not skip pidfd + fid. The 1/5 patch needs to be updated to use a per tcase TCONF.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test on v7.2+

Quoted 3 lines

This observation is correct. If v7.2+ enabled only pidfd + tid combination for fanotify, we should not skip pidfd + fid. The 1/5 patch needs to be updated to use a per tcase TCONF.

I think I missed Amir comment in here:
https://lore.kernel.org/ltp/CAOQ4uxhnrH3=XsCBhuO3oYtS=pZcRjkAchtrVwtnfJzBVmpNfQ@mail.gmail.com/

Hence, if it's correct, we should then provide a better TINFO message, or to skip test entirely for v7.2+, explaining inside the test description why this is needed.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test on v7.2+

Quoted 6 lines
Quoted 3 lines

This observation is correct. If v7.2+ enabled only pidfd + tid combination for fanotify, we should not skip pidfd + fid. The 1/5 patch needs to be updated to use a per tcase TCONF.

I think I missed Amir comment in here:
https://lore.kernel.org/ltp/CAOQ4uxhnrH3=XsCBhuO3oYtS=pZcRjkAchtrVwtnfJzBVmpNfQ@mail.gmail.com/

Good catch.

Quoted 3 lines

Hence, if it's correct, we should then provide a better TINFO message, or to skip test entirely for v7.2+, explaining inside the test description why this is needed.

From Amir's comment I understand whole test should be skipped. I'll send a patch adding .max_kver to tst_test struct (needed already for at least 2 tests) + reuse it here.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 1/5
#6 lore raw

Re: [LTP] [PATCH v2 1/5] fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test on v7.2+

In reply to AnonymeMeow
Quoted 6 lines · 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.

Looks good. Feel free to add:

Honza

Quoted 42 lines
---
 testcases/kernel/syscalls/fanotify/fanotify20.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify20.c +10 -4
index b32ecf6aa..f395d77ee 100644
@@ -8,13 +8,15 @@
 
 /*\
  * 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
+ * in 17171128513b ("fanotify: report thread pidfds for FAN_REPORT_TID").
  */
 
 #define _GNU_SOURCE
@@ -45,6 +47,10 @@ static struct test_case_t {
 
 static void do_setup(void)
 {
+	if (tst_kvercmp(7, 2, 0) >= 0)
+		tst_brk(TCONF, "FAN_REPORT_PIDFD | FAN_REPORT_TID is supported "
+			       "since v7.2, skipping test");
+
 	/*
 	 * An explicit check for FAN_REPORT_PIDFD is performed early on in the
 	 * test initialization as it's a prerequisite for all test cases.
Signature · 1 line
2.54.0
Signature · 5 lines
Jan Kara <[email protected]>
SUSE Labs, CR

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Re: [LTP] [PATCH v2 1/5] fanotify20: Skip FAN_REPORT_PIDFD | FAN_REPORT_TID test on v7.2+

Hi all,

Quoted 11 lines · AnonymeMeow
Quoted 6 lines

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.

Looks good. Feel free to add:

In the end, after some iterations trying to add .max_kver, this simple version was merged.

Thanks to all for their time.

Kind regards,
Petr

Quoted 43 lines

Honza

Quoted 41 lines
---
 testcases/kernel/syscalls/fanotify/fanotify20.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify20.c +10 -4
index b32ecf6aa..f395d77ee 100644
@@ -8,13 +8,15 @@
 
 /*\
  * 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
+ * in 17171128513b ("fanotify: report thread pidfds for FAN_REPORT_TID").
  */
 
 #define _GNU_SOURCE
@@ -45,6 +47,10 @@ static struct test_case_t {
 
 static void do_setup(void)
 {
+	if (tst_kvercmp(7, 2, 0) >= 0)
+		tst_brk(TCONF, "FAN_REPORT_PIDFD | FAN_REPORT_TID is supported "
+			       "since v7.2, skipping test");
+
 	/*
 	 * An explicit check for FAN_REPORT_PIDFD is performed early on in the
 	 * test initialization as it's a prerequisite for all test cases.
Signature · 1 line
2.54.0
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

PATCH v2 2/5 fanotify21: Stop relying on exited child for pidfd error

In reply to 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.

---
 .../kernel/syscalls/fanotify/fanotify21.c     | 55 ++++++++-----------
 1 file changed, 24 insertions(+), 31 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify21.c +24 -31
index 4d2115469..bd1a43513 100644
@@ -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)
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH v2 2/5] fanotify21: Stop relying on exited child for pidfd error

Hi all,

Quoted 13 lines

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.

...

Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +0 -3
 	/*
-	 * 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.

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 174

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +5 -4
+	 * 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))) {

nit: although I'd write it this way as well, checkpatch does not like this effective way :) (do not use assignment in if condition).

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 177

Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +3 -0
+		SAFE_WAITPID(reader_pid, &reader_exit_status, 0);
+		if (!WIFEXITED(reader_exit_status) || WEXITSTATUS(reader_exit_status))
+			tst_brk(TBROK, "reader process exited incorrectly");

nit: And the above should be probably replaced with tst_reap_children().

But because I should have merged this long time ago to prevent false positive on 7.2, merging it now. Cleanup can be done later (together with using designated initializers).

Merged the rest of the patch, thank you!

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

Re: [LTP] [PATCH v2 2/5] fanotify21: Stop relying on exited child for pidfd error

Quoted 40 lines · Petr Vorel

Hi all,

Quoted 13 lines

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.

...

Quoted 4 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +0 -3
 	/*
-	 * 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.

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 174

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +5 -4
+	 * 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))) {

nit: although I'd write it this way as well, checkpatch does not like this effective way :) (do not use assignment in if condition).

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 177

Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +3 -0
+		SAFE_WAITPID(reader_pid, &reader_exit_status, 0);
+		if (!WIFEXITED(reader_exit_status) || WEXITSTATUS(reader_exit_status))
+			tst_brk(TBROK, "reader process exited incorrectly");

nit: And the above should be probably replaced with tst_reap_children().

Quoted 6 lines

But because I should have merged this long time ago to prevent false positive on 7.2, merging it now. Cleanup can be done later (together with using designated initializers).

Merged the rest of the patch, thank you!

Hi Petr,

Sorry I did not have time to investigate and need to leave now just wanted to let you know that test ends with failure exit code. and does not seem to run with pretty recent rc7 kernel.

Is that expected?
Maybe it's something in my own test env.

Thanks,
Amir.

root@kvm-xfstests:~/ltp# ./fanotify/fanotify20 || echo FAIL
tst_tmpdir.c:308: TINFO: Using /tmp/LTP_fanTTAwH1 as tmpdir (tmpfs filesystem)
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:756: TINFO: CONFIG_PROVE_LOCKING kernel option detected which might slow the execution
tst_device.c:103: TINFO:[  787.367492] loop0: detected capacity change from 0 to 614400
 Found free device 0 '/dev/loop0'
tst_test.c:2048: TINFO: LTP version: 20260529-243-g9118a480c
tst_tes[  787.391529] /dev/zero: Can't lookup blockdev
t.c:2051: TINFO: Tested kernel: 7.2.0-rc7-xfstests-00008-g55d5763db1de #2982 SMP PREEMPT_DYNAMIC Thu Aug 27 12:04:04 CEST 2026 x86_64
tst_test.c:1876: TINFO: Overall timeout per run is 0h 02m 00s
tst_supported_fs_types.c:108: TINFO: Kernel supports ext2
tst_supported_fs_types.c:67: TINFO: mkfs.ext2 does exist
[  787.418143] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ext3
tst_supported_fs_types.c:67: TINFO: mkfs.ext3 does exist
[  787.443657] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ext4
tst_supported_fs_types.c:67: TINFO: m[  787.467489] /dev/zero: Can't lookup blockdev
kfs.ext4 does exist
tst_supported_fs_types.c:108: TINFO: Kernel supports xfs
tst_supported_fs_types.c:67: TINFO: mkfs.xfs does exist
tst_supported_fs_types.c:108: TINFO: Kernel supports btrfs
tst_supported_fs_types.c:67: TINFO: mkfs.btrfs does exist
tst_supported_fs_types.c:117: TINFO: Skipping bcachefs because of FUSE blacklist
[  787.521515] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports vfat
tst_supported_fs_types.c:67: TINFO: mkfs.vfat does exist
tst_supported_fs_types.c:140: TINFO: Filesystem exfat is not supported
tst_supported_fs_types.c:144: TINFO: FUSE does support ntfs
tst_supported_fs_types.c:63: TINFO: mkfs.ntfs does not exist
[  787.576420] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ntfs3
tst_supported_fs_types.c:63: TINFO: mkfs.ntfs does not exist
tst_supported_fs_types.c:108: TINFO: Kernel supports tmpfs
tst_supported_fs_types.c:51: TINFO: mkfs is not needed for tmpfs
tst_test.c:1986: TINFO: === Testing on ext2 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on ext3 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on ext4 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on xfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on btrfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on vfat ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on tmpfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2

Summary:

passed   0
failed   0
broken   0
skipped  7

warnings 0

FAIL

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

Re: [LTP] [PATCH v2 2/5] fanotify21: Stop relying on exited child for pidfd error

Quoted 111 lines · Amir Goldstein
Quoted 38 lines · Petr Vorel

Hi all,

Quoted 13 lines

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.

...

Quoted 4 lines
    /*
testcases/kernel/syscalls/fanotify/fanotify21.c +0 -3
-    * 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.

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 174

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +5 -4
+    * 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))) {

nit: although I'd write it this way as well, checkpatch does not like this effective way :) (do not use assignment in if condition).

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 177

Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +3 -0
+           SAFE_WAITPID(reader_pid, &reader_exit_status, 0);
+           if (!WIFEXITED(reader_exit_status) || WEXITSTATUS(reader_exit_status))
+                   tst_brk(TBROK, "reader process exited incorrectly");
Quoted 8 lines

nit: And the above should be probably replaced with tst_reap_children().

But because I should have merged this long time ago to prevent false positive on 7.2, merging it now. Cleanup can be done later (together with using designated initializers).

Merged the rest of the patch, thank you!

Hi Petr,

Sorry I did not have time to investigate and need to leave now just wanted to let you know that test ends with failure exit code. and does not seem to run with pretty recent rc7 kernel.

Is that expected?
Maybe it's something in my own test env.

Thanks,
Amir.

root@kvm-xfstests:~/ltp# ./fanotify/fanotify20 || echo FAIL
tst_tmpdir.c:308: TINFO: Using /tmp/LTP_fanTTAwH1 as tmpdir (tmpfs filesystem)
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:756: TINFO: CONFIG_PROVE_LOCKING kernel option detected which might slow the execution
tst_device.c:103: TINFO:[  787.367492] loop0: detected capacity change from 0 to 614400
 Found free device 0 '/dev/loop0'
tst_test.c:2048: TINFO: LTP version: 20260529-243-g9118a480c
tst_tes[  787.391529] /dev/zero: Can't lookup blockdev
t.c:2051: TINFO: Tested kernel: 7.2.0-rc7-xfstests-00008-g55d5763db1de #2982 SMP PREEMPT_DYNAMIC Thu Aug 27 12:04:04 CEST 2026 x86_64
tst_test.c:1876: TINFO: Overall timeout per run is 0h 02m 00s
tst_supported_fs_types.c:108: TINFO: Kernel supports ext2
tst_supported_fs_types.c:67: TINFO: mkfs.ext2 does exist
[  787.418143] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ext3
tst_supported_fs_types.c:67: TINFO: mkfs.ext3 does exist
[  787.443657] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ext4
tst_supported_fs_types.c:67: TINFO: m[  787.467489] /dev/zero: Can't lookup blockdev
kfs.ext4 does exist
tst_supported_fs_types.c:108: TINFO: Kernel supports xfs
tst_supported_fs_types.c:67: TINFO: mkfs.xfs does exist
tst_supported_fs_types.c:108: TINFO: Kernel supports btrfs
tst_supported_fs_types.c:67: TINFO: mkfs.btrfs does exist
tst_supported_fs_types.c:117: TINFO: Skipping bcachefs because of FUSE blacklist
[  787.521515] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports vfat
tst_supported_fs_types.c:67: TINFO: mkfs.vfat does exist
tst_supported_fs_types.c:140: TINFO: Filesystem exfat is not supported
tst_supported_fs_types.c:144: TINFO: FUSE does support ntfs
tst_supported_fs_types.c:63: TINFO: mkfs.ntfs does not exist
[  787.576420] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ntfs3
tst_supported_fs_types.c:63: TINFO: mkfs.ntfs does not exist
tst_supported_fs_types.c:108: TINFO: Kernel supports tmpfs
tst_supported_fs_types.c:51: TINFO: mkfs is not needed for tmpfs
tst_test.c:1986: TINFO: === Testing on ext2 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on ext3 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on ext4 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on xfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on btrfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on vfat ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on tmpfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
Quoted 8 lines

Summary:

passed   0
failed   0
broken   0
skipped  7

warnings 0

FAIL

Ok. I see that TCONF for all returning non 0 is expected.

Sorry for the noise.

Thanks,
Amir.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

Re: [LTP] [PATCH v2 2/5] fanotify21: Stop relying on exited child for pidfd error

Quoted 119 lines · Amir Goldstein
Quoted 117 lines · Petr Vorel
Quoted 38 lines

Hi all,

Quoted 13 lines

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.

...

Quoted 4 lines
    /*
testcases/kernel/syscalls/fanotify/fanotify21.c +0 -3
-    * 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.

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 174

Quoted 10 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +5 -4
+    * 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))) {

nit: although I'd write it this way as well, checkpatch does not like this effective way :) (do not use assignment in if condition).

testcases/kernel/syscalls/fanotify/fanotify21.c static void do_test(unsigned int num) · line 177

Quoted 3 lines
testcases/kernel/syscalls/fanotify/fanotify21.c +3 -0
+           SAFE_WAITPID(reader_pid, &reader_exit_status, 0);
+           if (!WIFEXITED(reader_exit_status) || WEXITSTATUS(reader_exit_status))
+                   tst_brk(TBROK, "reader process exited incorrectly");
Quoted 7 lines

nit: And the above should be probably replaced with tst_reap_children().

But because I should have merged this long time ago to prevent false positive on 7.2, merging it now. Cleanup can be done later (together with using designated initializers).

Merged the rest of the patch, thank you!

Hi Petr,

Sorry I did not have time to investigate and need to leave now just wanted to let you know that test ends with failure exit code. and does not seem to run with pretty recent rc7 kernel.

Is that expected?
Maybe it's something in my own test env.

Thanks,
Amir.

root@kvm-xfstests:~/ltp# ./fanotify/fanotify20 || echo FAIL
tst_tmpdir.c:308: TINFO: Using /tmp/LTP_fanTTAwH1 as tmpdir (tmpfs filesystem)
tst_kconfig.c:90: TINFO: Parsing kernel config '/proc/config.gz'
tst_kconfig.c:756: TINFO: CONFIG_PROVE_LOCKING kernel option detected which might slow the execution
tst_device.c:103: TINFO:[  787.367492] loop0: detected capacity change from 0 to 614400
 Found free device 0 '/dev/loop0'
tst_test.c:2048: TINFO: LTP version: 20260529-243-g9118a480c
tst_tes[  787.391529] /dev/zero: Can't lookup blockdev
t.c:2051: TINFO: Tested kernel: 7.2.0-rc7-xfstests-00008-g55d5763db1de #2982 SMP PREEMPT_DYNAMIC Thu Aug 27 12:04:04 CEST 2026 x86_64
tst_test.c:1876: TINFO: Overall timeout per run is 0h 02m 00s
tst_supported_fs_types.c:108: TINFO: Kernel supports ext2
tst_supported_fs_types.c:67: TINFO: mkfs.ext2 does exist
[  787.418143] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ext3
tst_supported_fs_types.c:67: TINFO: mkfs.ext3 does exist
[  787.443657] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ext4
tst_supported_fs_types.c:67: TINFO: m[  787.467489] /dev/zero: Can't lookup blockdev
kfs.ext4 does exist
tst_supported_fs_types.c:108: TINFO: Kernel supports xfs
tst_supported_fs_types.c:67: TINFO: mkfs.xfs does exist
tst_supported_fs_types.c:108: TINFO: Kernel supports btrfs
tst_supported_fs_types.c:67: TINFO: mkfs.btrfs does exist
tst_supported_fs_types.c:117: TINFO: Skipping bcachefs because of FUSE blacklist
[  787.521515] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports vfat
tst_supported_fs_types.c:67: TINFO: mkfs.vfat does exist
tst_supported_fs_types.c:140: TINFO: Filesystem exfat is not supported
tst_supported_fs_types.c:144: TINFO: FUSE does support ntfs
tst_supported_fs_types.c:63: TINFO: mkfs.ntfs does not exist
[  787.576420] /dev/zero: Can't lookup blockdev
tst_supported_fs_types.c:108: TINFO: Kernel supports ntfs3
tst_supported_fs_types.c:63: TINFO: mkfs.ntfs does not exist
tst_supported_fs_types.c:108: TINFO: Kernel supports tmpfs
tst_supported_fs_types.c:51: TINFO: mkfs is not needed for tmpfs
tst_test.c:1986: TINFO: === Testing on ext2 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on ext3 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on ext4 ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on xfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on btrfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on vfat ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2
tst_test.c:1986: TINFO: === Testing on tmpfs ===
fanotify20.c:51: TCONF: FAN_REPORT_PIDFD | FAN_REPORT_TID is supported since v7.2

Summary:

passed   0
failed   0
broken   0
skipped  7

warnings 0

Quoted 5 lines
Quoted 1 line

FAIL

Ok. I see that TCONF for all returning non 0 is expected.

Sorry for the noise.

No problem, thanks for your long term care of fanotify tests!

FYI we need to exit with non-zero exit code only to detect that something was skipped (useful to notice).

Kind regards,
Petr

Quoted 2 lines

Thanks,
Amir.

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH v2 3/5 fanotify21: Simplify read_pidfd_fdinfo()

In reply to 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.

---
 .../kernel/syscalls/fanotify/fanotify21.c     | 61 ++++++-------------
 1 file changed, 20 insertions(+), 41 deletions(-)
testcases/kernel/syscalls/fanotify/fanotify21.c +20 -41
index bd1a43513..22f9767db 100644
@@ -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);
 }
Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH v2 4/5 fanotify21: Add test variants for FAN_REPORT_TID

In reply to 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.

---
 include/lapi/pidfd.h                          |  4 ++
 .../kernel/syscalls/fanotify/fanotify21.c     | 57 ++++++++++++++-----
 2 files changed, 48 insertions(+), 13 deletions(-)
include/lapi/pidfd.h +4 -0
index a3205032c..eb4e3466d 100644
@@ -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
testcases/kernel/syscalls/fanotify/fanotify21.c +44 -13

127 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

PATCH v2 5/5 fanotify21: Add FAN_REPORT_TID pidfd coverage

In reply to 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.

---

This patch is exactly the same as v1 except that the pthread link flag is added to fanotify21 target.

---
 testcases/kernel/syscalls/fanotify/Makefile   |  2 +-
 .../kernel/syscalls/fanotify/fanotify21.c     | 47 ++++++++++++++++++-
 2 files changed, 47 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/fanotify/Makefile +1 -1
index 3628094ba..b20bb50e9 100644
@@ -2,7 +2,7 @@
 #  Copyright (c) Jan Kara <[email protected]>, 2013
 
 top_srcdir		?= ../../../..
-fanotify11: CFLAGS+=-pthread
+fanotify11 fanotify21: CFLAGS+=-pthread
 include $(top_srcdir)/include/mk/testcases.mk
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/fanotify/fanotify21.c +46 -1

104 lines not on this page · raw message

Signature · 5 lines
2.54.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v2 5/5
#16 lore raw

Re: [LTP] [PATCH v2 5/5] fanotify21: Add FAN_REPORT_TID pidfd coverage

Quoted 8 lines · 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.

Looks good. Feel free to add:

Honza

Quoted 142 lines

---

This patch is exactly the same as v1 except that the pthread link flag is added to fanotify21 target.

---
 testcases/kernel/syscalls/fanotify/Makefile   |  2 +-
 .../kernel/syscalls/fanotify/fanotify21.c     | 47 ++++++++++++++++++-
 2 files changed, 47 insertions(+), 2 deletions(-)
testcases/kernel/syscalls/fanotify/Makefile +1 -1
index 3628094ba..b20bb50e9 100644
@@ -2,7 +2,7 @@
 #  Copyright (c) Jan Kara <[email protected]>, 2013
 
 top_srcdir		?= ../../../..
-fanotify11: CFLAGS+=-pthread
+fanotify11 fanotify21: CFLAGS+=-pthread
 include $(top_srcdir)/include/mk/testcases.mk
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/fanotify/fanotify21.c +46 -1
index c05c69d58..c97ec4f92 100644
@@ -25,6 +25,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
@@ -47,6 +48,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[] = {
@@ -54,15 +56,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,
 	},
 };
@@ -108,6 +119,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) {
@@ -165,6 +196,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;
 
@@ -186,7 +218,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
@@ -349,6 +390,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)
@@ -371,6 +415,7 @@ static struct tst_test test = {
 	.mount_device = 1,
 	.mntpoint = MOUNT_PATH,
 	.forks_child = 1,
+	.needs_checkpoints = 1,
 };
 
 #else
Signature · 1 line
2.54.0
Signature · 5 lines
Jan Kara <[email protected]>
SUSE Labs, CR

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