All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE
@ 2022-09-05 15:42 Amir Goldstein
  2022-09-05 15:42 ` [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases " Amir Goldstein
                   ` (9 more replies)
  0 siblings, 10 replies; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi Petr,

FAN_MARK_IGNORE feature was merge in v6.0-rc1.
A man page draft was posted here [1].

Following are the tests for the new feature.

All new test cases are skipped on old kernels.

Note that fanotify10 will run ALL of its existing test cases
in two variants:
1. Legacy FAN_MARK_IGNORED_MASK
2. New FAN_MARK_IGNORE

On old kernels, only the first variant of the test will run.

In addition to the new test variant it also has some new test cases
that only run with new FAN_MARK_IGNORE variant.

Thanks,
Amir.

[1] https://lore.kernel.org/linux-man/20220904155113.2623371-1-amir73il@gmail.com/

Amir Goldstein (9):
  syscalls/fanotify09: Add test cases for FAN_MARK_IGNORE
  syscalls/fanotify14: Require FAN_REPORT_FID support for entire test
  syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE
  syscalls/fanotify10: Avoid undesired event in test
  syscalls/fanotify10: Add more verifications and debug info
  syscalls/fanotify10: Use dedicated mark type for inode mark on parent
  syscalls/fanotify10: Run tests with two ignore mask variants
  syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_EVENT_ON_CHILD
  syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_ONDIR

 testcases/kernel/syscalls/fanotify/fanotify.h |  19 ++
 .../kernel/syscalls/fanotify/fanotify09.c     | 102 ++++++++--
 .../kernel/syscalls/fanotify/fanotify10.c     | 186 ++++++++++++++----
 .../kernel/syscalls/fanotify/fanotify14.c     |  42 +++-
 4 files changed, 290 insertions(+), 59 deletions(-)

-- 
2.25.1


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

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

* [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases for FAN_MARK_IGNORE
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-05 16:04   ` Petr Vorel
  2022-09-05 15:42 ` [LTP] [PATCH 2/9] syscalls/fanotify14: Require FAN_REPORT_FID support for entire test Amir Goldstein
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

Verify the semantics of the new FAN_MARK_IGNORE flag:

1. Verify that ignore mask ignores events on dir only
   when FAN_ONDIR flag is set in ignore mask

2. Verify that ignore mask ignores events on child only
   when FAN_EVENT_ON_CHILD flag is set in ignore mask

3. Verify that ignore mask ignores events on subdir only
   when both FAN_EVENT_ON_CHILD and FAN_ONDIR flags are
   set in ignore mask

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify.h |   6 ++
 .../kernel/syscalls/fanotify/fanotify09.c     | 102 +++++++++++++++---
 2 files changed, 95 insertions(+), 13 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index a118fbd9e..d67c079af 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -106,6 +106,12 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
 #ifndef FAN_MARK_EVICTABLE
 #define FAN_MARK_EVICTABLE	0x00000200
 #endif
+#ifndef FAN_MARK_IGNORE
+#define FAN_MARK_IGNORE		0x00000400
+#endif
+#ifndef FAN_MARK_IGNORE_SURV
+#define FAN_MARK_IGNORE_SURV	(FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY)
+#endif
 
 /* New dirent event masks */
 #ifndef FAN_ATTRIB
diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c
index 0eb83e2f8..e40916c08 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify09.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify09.c
@@ -73,12 +73,14 @@ static char event_buf[EVENT_BUF_LEN];
 static int mount_created;
 
 static int fan_report_dfid_unsupported;
+static int ignore_mark_unsupported;
 
 static struct tcase {
 	const char *tname;
 	struct fanotify_mark_type mark;
 	unsigned int ondir;
 	unsigned int ignore;
+	unsigned int ignore_flags;
 	unsigned int report_name;
 	const char *close_nowrite;
 	int nevents;
@@ -88,7 +90,7 @@ static struct tcase {
 		"Events on non-dir child with both parent and mount marks",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		0,
-		0,
+		0, 0,
 		0,
 		DIR_NAME,
 		1, 0,
@@ -97,7 +99,7 @@ static struct tcase {
 		"Events on non-dir child and subdir with both parent and mount marks",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_ONDIR,
-		0,
+		0, 0,
 		0,
 		DIR_NAME,
 		2, 0,
@@ -106,7 +108,7 @@ static struct tcase {
 		"Events on non-dir child and parent with both parent and mount marks",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_ONDIR,
-		0,
+		0, 0,
 		0,
 		".",
 		2, 0
@@ -115,7 +117,7 @@ static struct tcase {
 		"Events on non-dir child and subdir with both parent and subdir marks",
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_ONDIR,
-		0,
+		0, 0,
 		0,
 		DIR_NAME,
 		2, 0,
@@ -124,7 +126,7 @@ static struct tcase {
 		"Events on non-dir children with both parent and mount marks",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		0,
-		0,
+		0, 0,
 		0,
 		FILE2_NAME,
 		2, FAN_CLOSE_NOWRITE,
@@ -133,7 +135,7 @@ static struct tcase {
 		"Events on non-dir child with both parent and mount marks and filename info",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		0,
-		0,
+		0, 0,
 		FAN_REPORT_DFID_NAME,
 		FILE2_NAME,
 		2, FAN_CLOSE_NOWRITE,
@@ -142,7 +144,7 @@ static struct tcase {
 		"Events on non-dir child with ignore mask on parent",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		0,
-		FAN_MARK_IGNORED_MASK,
+		FAN_MARK_IGNORED_MASK, 0,
 		0,
 		DIR_NAME,
 		1, 0,
@@ -151,11 +153,75 @@ static struct tcase {
 		"Events on non-dir children with surviving ignore mask on parent",
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		0,
-		FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY,
+		FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY, 0,
+		0,
+		FILE2_NAME,
+		2, FAN_CLOSE_NOWRITE,
+	},
+	/* FAN_MARK_IGNORE test cases: */
+	{
+		"Events on dir with ignore mask that does not apply to dirs",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_ONDIR,
+		FAN_MARK_IGNORE_SURV, 0,
+		0,
+		".",
+		2, FAN_CLOSE_NOWRITE,
+	},
+	{
+		"Events on dir with ignore mask that does apply to dirs",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_ONDIR,
+		FAN_MARK_IGNORE_SURV, FAN_ONDIR,
+		0,
+		".",
+		2, 0,
+	},
+	{
+		"Events on child with ignore mask on parent that does not apply to children",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		0,
+		FAN_MARK_IGNORE_SURV, 0,
+		0,
+		FILE2_NAME,
+		2, FAN_CLOSE_NOWRITE,
+	},
+	{
+		"Events on child with ignore mask on parent that does apply to children",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		0,
+		FAN_MARK_IGNORE_SURV, FAN_EVENT_ON_CHILD,
 		0,
 		FILE2_NAME,
+		2, 0,
+	},
+	{
+		"Events on subdir with ignore mask on parent that does not apply to children",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_ONDIR,
+		FAN_MARK_IGNORE_SURV, FAN_ONDIR,
+		0,
+		DIR_NAME,
 		2, FAN_CLOSE_NOWRITE,
 	},
+	{
+		"Events on subdir with ignore mask on parent that does not apply to dirs",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_ONDIR,
+		FAN_MARK_IGNORE_SURV, FAN_EVENT_ON_CHILD,
+		0,
+		DIR_NAME,
+		2, FAN_CLOSE_NOWRITE,
+	},
+	{
+		"Events on subdir with ignore mask on parent that does apply to subdirs",
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_ONDIR,
+		FAN_MARK_IGNORE_SURV, FAN_EVENT_ON_CHILD | FAN_ONDIR,
+		0,
+		DIR_NAME,
+		2, 0,
+	},
 };
 
 static void create_fanotify_groups(struct tcase *tc)
@@ -170,16 +236,19 @@ static void create_fanotify_groups(struct tcase *tc)
 		 */
 		unsigned int report_name = tc->report_name;
 		unsigned int mask_flags = tc->ondir | FAN_EVENT_ON_CHILD;
-		unsigned int parent_mask, ignore = 0;
+		unsigned int parent_mask, ignore_mask, ignore = 0;
 
 		/*
-		 * The non-first groups do not request events on children and
-		 * subdirs and may set an ignore mask on parent dir.
+		 * The non-first groups may request events on children and
+		 * subdirs only when setting an ignore mask on parent dir.
+		 * The parent ignore mask may request to ignore events on
+		 * children or subdirs.
 		 */
 		if (i > 0) {
 			ignore = tc->ignore;
 			report_name = 0;
-			mask_flags = 0;
+			if (!ignore)
+				mask_flags = 0;
 		}
 
 		fd_notify[i] = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | report_name |
@@ -206,8 +275,9 @@ static void create_fanotify_groups(struct tcase *tc)
 		 * the close event on dir.
 		 */
 		parent_mask = FAN_MODIFY | tc->ondir | mask_flags;
+		ignore_mask = FAN_CLOSE_NOWRITE | tc->ignore_flags;
 		SAFE_FANOTIFY_MARK(fd_notify[i], FAN_MARK_ADD | ignore,
-				    ignore ? FAN_CLOSE_NOWRITE : parent_mask,
+				    ignore ? ignore_mask : parent_mask,
 				    AT_FDCWD, ".");
 	}
 }
@@ -331,6 +401,11 @@ static void test_fanotify(unsigned int n)
 		return;
 	}
 
+	if (ignore_mark_unsupported && tc->ignore & FAN_MARK_IGNORE) {
+		tst_res(TCONF, "FAN_MARK_IGNORE not supported in kernel?");
+		return;
+	}
+
 	create_fanotify_groups(tc);
 
 	/*
@@ -422,6 +497,7 @@ static void setup(void)
 {
 	fan_report_dfid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME,
 									  MOUNT_PATH);
+	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
 
 	SAFE_MKDIR(MOUNT_NAME, 0755);
 	SAFE_MOUNT(MOUNT_PATH, MOUNT_NAME, "none", MS_BIND, NULL);
-- 
2.25.1


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

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

* [LTP] [PATCH 2/9] syscalls/fanotify14: Require FAN_REPORT_FID support for entire test
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
  2022-09-05 15:42 ` [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases " Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-06  6:06   ` Petr Vorel
  2022-09-05 15:42 ` [LTP] [PATCH 3/9] syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE Amir Goldstein
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

To avoid complex requirements for the new test case, we now require
FAN_REPORT_FID support for the entire test, which opts-out from testing
on FUSE filesystem.

It is not clear that there is anything to gain from running this test
on all_filsystems in the first place.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify14.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c
index aa4db586e..8419cea46 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify14.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify14.c
@@ -219,11 +219,8 @@ out:
 
 static void do_setup(void)
 {
-	int fd;
-
-	/* Check for kernel fanotify support */
-	fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
-	SAFE_CLOSE(fd);
+	/* Require FAN_REPORT_FID support for all tests to simplify per test case requirements */
+	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_FID, MNTPOINT);
 
 	fan_report_target_fid_unsupported =
 		fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME_TARGET, MNTPOINT);
-- 
2.25.1


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

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

* [LTP] [PATCH 3/9] syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
  2022-09-05 15:42 ` [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases " Amir Goldstein
  2022-09-05 15:42 ` [LTP] [PATCH 2/9] syscalls/fanotify14: Require FAN_REPORT_FID support for entire test Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-06  9:05   ` Petr Vorel
  2022-09-05 15:42 ` [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test Amir Goldstein
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

FAN_MARK_IGNORE is a new API so it also enforces strict rules about
which events and flags are allowed on a non-dir inode mark.

FAN_MARK_IGNORE requires FAN_MARK_IGNORED_SURV_MODIFY for anything
expect a non-dir inode mark.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 .../kernel/syscalls/fanotify/fanotify14.c     | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c
index 8419cea46..4a1953b33 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify14.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify14.c
@@ -39,6 +39,7 @@
 
 static int fanotify_fd;
 static int fan_report_target_fid_unsupported;
+static int ignore_mark_unsupported;
 
 /*
  * Each test case has been designed in a manner whereby the values defined
@@ -107,6 +108,34 @@ static struct test_case_t {
 		/* With FAN_REPORT_TARGET_FID, FAN_EVENT_ON_CHILD on non-dir is not valid */
 		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME_TARGET, 0, FAN_OPEN | FAN_EVENT_ON_CHILD, ENOTDIR
 	},
+	{
+		/* FAN_MARK_IGNORE_SURV with FAN_DELETE on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, FAN_MARK_IGNORE_SURV, FAN_DELETE, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE_SURV with FAN_RENAME on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, FAN_MARK_IGNORE_SURV, FAN_RENAME, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE_SURV with FAN_ONDIR on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, FAN_MARK_IGNORE_SURV, FAN_OPEN | FAN_ONDIR, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE_SURV with FAN_EVENT_ON_CHILD on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, FAN_MARK_IGNORE_SURV, FAN_OPEN | FAN_EVENT_ON_CHILD, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE without FAN_MARK_IGNORED_SURV_MODIFY on directory is not valid */
+		FAN_CLASS_NOTIF, FAN_MARK_IGNORE, FAN_OPEN, EISDIR
+	},
+	{
+		/* FAN_MARK_IGNORE without FAN_MARK_IGNORED_SURV_MODIFY on mount mark is not valid */
+		FAN_CLASS_NOTIF, FAN_MARK_MOUNT | FAN_MARK_IGNORE, FAN_OPEN, EINVAL
+	},
+	{
+		/* FAN_MARK_IGNORE without FAN_MARK_IGNORED_SURV_MODIFY on filesystem mark is not valid */
+		FAN_CLASS_NOTIF, FAN_MARK_FILESYSTEM | FAN_MARK_IGNORE, FAN_OPEN, EINVAL
+	},
 };
 
 static void do_test(unsigned int number)
@@ -120,6 +149,11 @@ static void do_test(unsigned int number)
 		return;
 	}
 
+	if (ignore_mark_unsupported && tc->mark_flags & FAN_MARK_IGNORE) {
+		tst_res(TCONF, "FAN_MARK_IGNORE not supported in kernel?");
+		return;
+	}
+
 	fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY);
 	if (fanotify_fd < 0) {
 		if (errno == tc->expected_errno) {
@@ -224,6 +258,7 @@ static void do_setup(void)
 
 	fan_report_target_fid_unsupported =
 		fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME_TARGET, MNTPOINT);
+	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
 
 	/* Create temporary test file to place marks on */
 	SAFE_FILE_PRINTF(FILE1, "0");
-- 
2.25.1


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

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

* [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
                   ` (2 preceding siblings ...)
  2022-09-05 15:42 ` [LTP] [PATCH 3/9] syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-06 16:51   ` Petr Vorel
  2022-09-06 17:09   ` Petr Vorel
  2022-09-05 15:42 ` [LTP] [PATCH 5/9] syscalls/fanotify10: Add more verifications and debug info Amir Goldstein
                   ` (5 subsequent siblings)
  9 siblings, 2 replies; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

Open fd for syncfs before creating groups to avoid the
FAN_OPEN event that this open generates.

This event does not break any of the existing test cases,
but should avoid it to avoid noise in future test cases.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify10.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index 93340255f..b8358b489 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -66,6 +66,7 @@ static unsigned int fanotify_class[] = {
 #define GROUPS_PER_PRIO 3
 
 static int fd_notify[NUM_CLASSES][GROUPS_PER_PRIO];
+static int fd_syncfs;
 
 static char event_buf[EVENT_BUF_LEN];
 static int exec_events_unsupported;
@@ -342,14 +343,11 @@ static void show_fanotify_marks(int fd)
 	}
 }
 
-static void drop_caches(const char *path)
+static void drop_caches()
 {
-	int fd = SAFE_OPEN(path, O_RDONLY);
-
-	if (syncfs(fd) < 0)
+	if (syncfs(fd_syncfs) < 0)
 		tst_brk(TBROK | TERRNO, "Unexpected error when syncing filesystem");
 
-	SAFE_CLOSE(fd);
 	SAFE_FILE_PRINTF(DROP_CACHES_FILE, "3");
 }
 
@@ -364,6 +362,9 @@ static int create_fanotify_groups(unsigned int n)
 	mark = &fanotify_mark_types[tc->mark_type];
 	ignore_mark = &fanotify_mark_types[tc->ignore_mark_type];
 
+	/* Open fd for syncfs before creating groups to avoid the FAN_OPEN event */
+	fd_syncfs = SAFE_OPEN(MOUNT_PATH, O_RDONLY);
+
 	for (p = 0; p < num_classes; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
 			fd_notify[p][i] = SAFE_FANOTIFY_INIT(fanotify_class[p] |
@@ -413,7 +414,7 @@ add_mark:
 	 * drop_caches should evict inode from cache and remove evictable marks
 	 */
 	if (evictable_ignored) {
-		drop_caches(tc->mark_path);
+		drop_caches();
 		for (p = 0; p < num_classes; p++) {
 			for (i = 0; i < GROUPS_PER_PRIO; i++) {
 				if (fd_notify[p][i] > 0)
@@ -435,6 +436,8 @@ static void cleanup_fanotify_groups(void)
 				SAFE_CLOSE(fd_notify[p][i]);
 		}
 	}
+	if (fd_syncfs > 0)
+		SAFE_CLOSE(fd_syncfs);
 }
 
 /* Flush out all pending dirty inodes and destructing marks */
-- 
2.25.1


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

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

* [LTP] [PATCH 5/9] syscalls/fanotify10: Add more verifications and debug info
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
                   ` (3 preceding siblings ...)
  2022-09-05 15:42 ` [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-06 17:01   ` Petr Vorel
  2022-09-05 15:42 ` [LTP] [PATCH 6/9] syscalls/fanotify10: Use dedicated mark type for inode mark on parent Amir Goldstein
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

Check that non-evictable inode ignore marks exist as expected
and print mask of unexpected events.

Fix information printed for events from unexpected pid.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify.h |  4 ++
 .../kernel/syscalls/fanotify/fanotify10.c     | 41 ++++++++++++-------
 2 files changed, 31 insertions(+), 14 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index d67c079af..810a48e81 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -112,6 +112,10 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
 #ifndef FAN_MARK_IGNORE_SURV
 #define FAN_MARK_IGNORE_SURV	(FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY)
 #endif
+/* Non-uapi convenience macros */
+#ifndef FAN_MARK_TYPES
+#define FAN_MARK_TYPES (FAN_MARK_INODE | FAN_MARK_MOUNT | FAN_MARK_FILESYSTEM)
+#endif
 
 /* New dirent event masks */
 #ifndef FAN_ATTRIB
diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index b8358b489..ea05e4ff0 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -328,18 +328,21 @@ static struct tcase {
 	},
 };
 
-static void show_fanotify_marks(int fd)
+static void show_fanotify_ignore_marks(int fd, int expected)
 {
 	unsigned int mflags, mask, ignored_mask;
 	char procfdinfo[100];
 
 	sprintf(procfdinfo, "/proc/%d/fdinfo/%d", (int)getpid(), fd);
 	if (FILE_LINES_SCANF(procfdinfo, "fanotify ino:%*x sdev:%*x mflags: %x mask:%x ignored_mask:%x",
-				&mflags, &mask, &ignored_mask)) {
-		tst_res(TPASS, "No fanotify inode marks as expected");
+				&mflags, &mask, &ignored_mask) || !ignored_mask) {
+		tst_res(!expected ? TPASS : TFAIL,
+			"No fanotify inode ignore marks %sexpected",
+			!expected ? "as " : "is un");
 	} else {
-		tst_res(TFAIL, "Unexpected inode mark (mflags=%x, mask=%x ignored_mask=%x)",
-				mflags, mask, ignored_mask);
+		tst_res(expected ? TPASS : TFAIL,
+			"Found %sexpected inode ignore mark (mflags=%x, mask=%x ignored_mask=%x)",
+			expected ? "" : "un", mflags, mask, ignored_mask);
 	}
 }
 
@@ -358,9 +361,11 @@ static int create_fanotify_groups(unsigned int n)
 	unsigned int mark_ignored, mask;
 	unsigned int p, i;
 	int evictable_ignored = (tc->ignore_mark_type == FANOTIFY_EVICTABLE);
+	int ignore_mark_type;
 
 	mark = &fanotify_mark_types[tc->mark_type];
 	ignore_mark = &fanotify_mark_types[tc->ignore_mark_type];
+	ignore_mark_type = ignore_mark->flag & FAN_MARK_TYPES;
 
 	/* Open fd for syncfs before creating groups to avoid the FAN_OPEN event */
 	fd_syncfs = SAFE_OPEN(MOUNT_PATH, O_RDONLY);
@@ -382,7 +387,7 @@ static int create_fanotify_groups(unsigned int n)
 					    FAN_EVENT_ON_CHILD,
 					    AT_FDCWD, tc->mark_path);
 
-			/* Add ignore mark for groups with higher priority */
+			/* Do not add ignore mark for first priority groups */
 			if (p == 0)
 				continue;
 
@@ -411,14 +416,18 @@ add_mark:
 	}
 
 	/*
-	 * drop_caches should evict inode from cache and remove evictable marks
+	 * Verify that first priority groups have no ignore inode marks and that
+	 * drop_caches evicted the evictable ignore marks of other groups.
 	 */
-	if (evictable_ignored) {
+	if (evictable_ignored)
 		drop_caches();
+
+	if (ignore_mark_type == FAN_MARK_INODE) {
 		for (p = 0; p < num_classes; p++) {
 			for (i = 0; i < GROUPS_PER_PRIO; i++) {
 				if (fd_notify[p][i] > 0)
-					show_fanotify_marks(fd_notify[p][i]);
+					show_fanotify_ignore_marks(fd_notify[p][i],
+								   p > 0 && !evictable_ignored);
 			}
 		}
 	}
@@ -464,7 +473,7 @@ static void verify_event(int p, int group, struct fanotify_event_metadata *event
 		tst_res(TFAIL, "group %d (%x) got event: mask %llx pid=%u "
 			"(expected %u) fd=%u", group, fanotify_class[p],
 			(unsigned long long)event->mask, (unsigned int)event->pid,
-			(unsigned int)getpid(), event->fd);
+			(unsigned int)child_pid, event->fd);
 	} else {
 		tst_res(TPASS, "group %d (%x) got event: mask %llx pid=%u fd=%u",
 			group, fanotify_class[p], (unsigned long long)event->mask,
@@ -582,14 +591,18 @@ static void test_fanotify(unsigned int n)
 	for (p = 1; p < num_classes && !tc->expected_mask_with_ignore; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
 			ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN);
-			if (ret == 0) {
+			if (ret >= 0 && ret < (int)FAN_EVENT_METADATA_LEN) {
 				tst_brk(TBROK,
-					"zero length read from fanotify fd");
+					"short read when reading fanotify "
+					"events (%d < %d)", ret,
+					(int)EVENT_BUF_LEN);
 			}
+			event = (struct fanotify_event_metadata *)event_buf;
 			if (ret > 0) {
 				tst_res(TFAIL, "group %d (%x) with %s and "
-					"%s ignore mask got event",
-					i, fanotify_class[p], mark->name, ignore_mark->name);
+					"%s ignore mask got unexpected event (mask %llx)",
+					i, fanotify_class[p], mark->name, ignore_mark->name,
+					event->mask);
 				if (event->fd != FAN_NOFD)
 					SAFE_CLOSE(event->fd);
 			} else if (errno == EAGAIN) {
-- 
2.25.1


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

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

* [LTP] [PATCH 6/9] syscalls/fanotify10: Use dedicated mark type for inode mark on parent
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
                   ` (4 preceding siblings ...)
  2022-09-05 15:42 ` [LTP] [PATCH 5/9] syscalls/fanotify10: Add more verifications and debug info Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-06 17:03   ` Petr Vorel
  2022-09-05 15:42 ` [LTP] [PATCH 7/9] syscalls/fanotify10: Run tests with two ignore mask variants Amir Goldstein
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

This highlights the test cases that use a directory inode mark on parent
in contrast to the test cases that use non-dir inode marks.

One test case that uses DIR_MNT2 for no reason (there are no mount marks
in this test case) was changed to use the standard DIR_PATH.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify.h |  3 +++
 .../kernel/syscalls/fanotify/fanotify10.c     | 20 ++++++++++---------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index 810a48e81..936d6787e 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -113,6 +113,9 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
 #define FAN_MARK_IGNORE_SURV	(FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY)
 #endif
 /* Non-uapi convenience macros */
+#ifndef FAN_MARK_PARENT
+#define FAN_MARK_PARENT		FAN_MARK_ONLYDIR
+#endif
 #ifndef FAN_MARK_TYPES
 #define FAN_MARK_TYPES (FAN_MARK_INODE | FAN_MARK_MOUNT | FAN_MARK_FILESYSTEM)
 #endif
diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index ea05e4ff0..5d7b90e58 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -102,6 +102,7 @@ static unsigned int num_classes = NUM_CLASSES;
 
 enum {
 	FANOTIFY_INODE,
+	FANOTIFY_PARENT,
 	FANOTIFY_MOUNT,
 	FANOTIFY_FILESYSTEM,
 	FANOTIFY_EVICTABLE,
@@ -109,6 +110,7 @@ enum {
 
 static struct fanotify_mark_type fanotify_mark_types[] = {
 	INIT_FANOTIFY_MARK_TYPE(INODE),
+	INIT_FANOTIFY_MARK_TYPE(PARENT),
 	INIT_FANOTIFY_MARK_TYPE(MOUNT),
 	INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
 	INIT_FANOTIFY_MARK_TYPE(EVICTABLE),
@@ -243,57 +245,57 @@ static struct tcase {
 	},
 	{
 		"ignore child exec events created on a specific mount point",
-		MOUNT_PATH, FANOTIFY_INODE,
+		MOUNT_PATH, FANOTIFY_PARENT,
 		MOUNT_PATH, FANOTIFY_MOUNT,
 		0,
 		FILE_EXEC_PATH, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC
 	},
 	{
 		"ignore events on children of directory created on a specific file",
-		DIR_MNT2, FANOTIFY_INODE,
-		DIR_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
+		DIR_PATH, FANOTIFY_PARENT,
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"ignore events on file created inside a parent watching children",
 		FILE_PATH, FANOTIFY_INODE,
-		DIR_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"don't ignore events on file created inside a parent not watching children",
 		FILE_PATH, FANOTIFY_INODE,
-		DIR_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		0,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
 	{
 		"ignore mount events created inside a parent watching children",
 		FILE_PATH, FANOTIFY_MOUNT,
-		DIR_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"don't ignore mount events created inside a parent not watching children",
 		FILE_PATH, FANOTIFY_MOUNT,
-		DIR_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		0,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
 	{
 		"ignore fs events created inside a parent watching children",
 		FILE_PATH, FANOTIFY_FILESYSTEM,
-		DIR_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"don't ignore fs events created inside a parent not watching children",
 		FILE_PATH, FANOTIFY_FILESYSTEM,
-		DIR_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		0,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
-- 
2.25.1


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

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

* [LTP] [PATCH 7/9] syscalls/fanotify10: Run tests with two ignore mask variants
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
                   ` (5 preceding siblings ...)
  2022-09-05 15:42 ` [LTP] [PATCH 6/9] syscalls/fanotify10: Use dedicated mark type for inode mark on parent Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-06 17:07   ` Petr Vorel
  2022-09-05 15:42 ` [LTP] [PATCH 8/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_EVENT_ON_CHILD Amir Goldstein
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

Run test with legacy FAN_MARK_IGNORED_MASK variant and new
FAN_MARK_IGNORE variant if kernel supports it.

When running the new variant, do not need to use the hack of
setting events and flags in both mask and ignored mask.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify.h |  3 ++
 .../kernel/syscalls/fanotify/fanotify10.c     | 34 ++++++++++++++-----
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index 936d6787e..6fbd96d11 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -113,6 +113,9 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
 #define FAN_MARK_IGNORE_SURV	(FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY)
 #endif
 /* Non-uapi convenience macros */
+#ifndef FAN_MARK_IGNORED_SURV
+#define FAN_MARK_IGNORED_SURV	(FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY)
+#endif
 #ifndef FAN_MARK_PARENT
 #define FAN_MARK_PARENT		FAN_MARK_ONLYDIR
 #endif
diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index 5d7b90e58..96c63c4ba 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -73,6 +73,7 @@ static int exec_events_unsupported;
 static int fan_report_dfid_unsupported;
 static int filesystem_mark_unsupported;
 static int evictable_mark_unsupported;
+static int ignore_mark_unsupported;
 
 #define MOUNT_PATH "fs_mnt"
 #define MNT2_PATH "mntpoint"
@@ -393,24 +394,27 @@ static int create_fanotify_groups(unsigned int n)
 			if (p == 0)
 				continue;
 
-			mask = FAN_OPEN;
-			mark_ignored = FAN_MARK_IGNORED_MASK |
-					FAN_MARK_IGNORED_SURV_MODIFY;
+			/*
+			 * Run tests in two variants:
+			 * 1. Legacy FAN_MARK_IGNORED_MASK
+			 * 2. FAN_MARK_IGNORE
+			 */
+			mark_ignored = tst_variant ? FAN_MARK_IGNORE_SURV : FAN_MARK_IGNORED_SURV;
+			mask = FAN_OPEN | tc->ignored_onchild;
 add_mark:
 			SAFE_FANOTIFY_MARK(fd_notify[p][i],
 					    FAN_MARK_ADD | ignore_mark->flag | mark_ignored,
 					    mask, AT_FDCWD, tc->ignore_path);
 
 			/*
-			 * If ignored mask is on a parent watching children,
-			 * also set the flag FAN_EVENT_ON_CHILD in mark mask.
+			 * FAN_MARK_IGNORE respects FAN_EVENT_ON_CHILD flag, but legacy
+			 * FAN_MARK_IGNORED_MASK does not. When using legacy ignore mask,
+			 * if ignored mask is on a parent watching children, we need to
+			 * also set the event and flag FAN_EVENT_ON_CHILD in mark mask.
 			 * This is needed to indicate that parent ignored mask
 			 * should be applied to events on children.
 			 */
-			if (tc->ignored_onchild && mark_ignored) {
-				mask = tc->ignored_onchild;
-				/* XXX: temporary hack may be removed in the future */
-				mask |= FAN_OPEN;
+			if (tc->ignored_onchild && mark_ignored & FAN_MARK_IGNORED_MASK) {
 				mark_ignored = 0;
 				goto add_mark;
 			}
@@ -535,6 +539,11 @@ static void test_fanotify(unsigned int n)
 		return;
 	}
 
+	if (ignore_mark_unsupported && tst_variant) {
+		tst_res(TCONF, "FAN_MARK_IGNORE not supported in kernel?");
+		return;
+	}
+
 	if (tc->ignored_onchild && tst_kvercmp(5, 9, 0) < 0) {
 		tst_res(TCONF, "ignored mask in combination with flag FAN_EVENT_ON_CHILD"
 				" has undefined behavior on kernel < 5.9");
@@ -628,6 +637,7 @@ static void setup(void)
 								      FAN_CLASS_CONTENT, 0);
 	filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM);
 	evictable_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_EVICTABLE);
+	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
 	fan_report_dfid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME,
 									  MOUNT_PATH);
 	if (fan_report_dfid_unsupported) {
@@ -660,11 +670,17 @@ static void cleanup(void)
 		SAFE_UMOUNT(MNT2_PATH);
 
 	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
+
+	SAFE_UNLINK(FILE_PATH);
+	SAFE_UNLINK(FILE2_PATH);
+	SAFE_RMDIR(DIR_PATH);
+	SAFE_RMDIR(MNT2_PATH);
 }
 
 static struct tst_test test = {
 	.test = test_fanotify,
 	.tcnt = ARRAY_SIZE(tcases),
+	.test_variants = 2,
 	.setup = setup,
 	.cleanup = cleanup,
 	.mount_device = 1,
-- 
2.25.1


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

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

* [LTP] [PATCH 8/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_EVENT_ON_CHILD
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
                   ` (6 preceding siblings ...)
  2022-09-05 15:42 ` [LTP] [PATCH 7/9] syscalls/fanotify10: Run tests with two ignore mask variants Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-05 15:42 ` [LTP] [PATCH 9/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_ONDIR Amir Goldstein
  2022-09-06 15:38 ` [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Jan Kara
  9 siblings, 0 replies; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

Verify correct behavior with FAN_MARK_IGNORE when FAN_EVENT_ON_CHILD
flag is set in ignore mask and not in mask and when the flag is set in
mask and not in ignore mask.

We do this for 6 test cases where ignore mark is on parent dir, but not
for the one test case where both mark and ignore mask are on parent dir.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 .../kernel/syscalls/fanotify/fanotify10.c     | 28 +++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index 96c63c4ba..0095bda2a 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -418,6 +418,34 @@ add_mark:
 				mark_ignored = 0;
 				goto add_mark;
 			}
+
+			/*
+			 * When using FAN_MARK_IGNORE, verify that the FAN_EVENT_ON_CHILD
+			 * flag in mark mask does not affect the ignore mask.
+			 *
+			 * If parent does not want to ignore FAN_OPEN events on children,
+			 * set a mark mask to watch FAN_CLOSE_WRITE events on children
+			 * to make sure we do not ignore FAN_OPEN events from children.
+			 *
+			 * If parent wants to ignore FAN_OPEN events on childern,
+			 * set a mark mask to watch FAN_CLOSE events only on parent itself
+			 * to make sure we do not get FAN_CLOSE events from children.
+			 *
+			 * If we had already set the FAN_EVENT_ON_CHILD in the parent
+			 * mark mask (mark_type == FANOTIFY_PARENT), then FAN_CLOSE mask
+			 * will apply also to childern, so we skip this verification.
+			 */
+			if (mark_ignored & FAN_MARK_IGNORE &&
+			    tc->ignore_mark_type == FANOTIFY_PARENT) {
+				if (!tc->ignored_onchild)
+					mask = FAN_CLOSE_WRITE | FAN_EVENT_ON_CHILD;
+				else if (tc->mark_type == FANOTIFY_PARENT)
+					continue;
+				else
+					mask = FAN_CLOSE | FAN_ONDIR;
+				mark_ignored = 0;
+				goto add_mark;
+			}
 		}
 	}
 
-- 
2.25.1


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

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

* [LTP] [PATCH 9/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_ONDIR
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
                   ` (7 preceding siblings ...)
  2022-09-05 15:42 ` [LTP] [PATCH 8/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_EVENT_ON_CHILD Amir Goldstein
@ 2022-09-05 15:42 ` Amir Goldstein
  2022-09-06 15:38 ` [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Jan Kara
  9 siblings, 0 replies; 23+ messages in thread
From: Amir Goldstein @ 2022-09-05 15:42 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, ltp

Verify correct behavior with FAN_MARK_IGNORE when the FAN_ONDIR flag
is set in ignore mask and not in mask and when the flag is set in
mask and not in ignore mask.

These test cases are skipped for the FAN_MARK_IGNORED_MASK variant
where ignore mask is always applied to directories regardless of
FAN_ONDIR flag in mask or ignore mask.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 testcases/kernel/syscalls/fanotify/fanotify.h |  3 +
 .../kernel/syscalls/fanotify/fanotify10.c     | 56 ++++++++++++++++---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index 6fbd96d11..ddd365cff 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -119,6 +119,9 @@ static inline int safe_fanotify_mark(const char *file, const int lineno,
 #ifndef FAN_MARK_PARENT
 #define FAN_MARK_PARENT		FAN_MARK_ONLYDIR
 #endif
+#ifndef FAN_MARK_SUBDIR
+#define FAN_MARK_SUBDIR		FAN_MARK_ONLYDIR
+#endif
 #ifndef FAN_MARK_TYPES
 #define FAN_MARK_TYPES (FAN_MARK_INODE | FAN_MARK_MOUNT | FAN_MARK_FILESYSTEM)
 #endif
diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index 0095bda2a..671fbf8fd 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -80,11 +80,13 @@ static int ignore_mark_unsupported;
 #define DIR_NAME "testdir"
 #define FILE_NAME "testfile"
 #define FILE2_NAME "testfile2"
+#define SUBDIR_NAME "testdir2"
 #define TEST_APP "fanotify_child"
 #define TEST_APP2 "fanotify_child2"
 #define DIR_PATH MOUNT_PATH"/"DIR_NAME
 #define FILE_PATH DIR_PATH"/"FILE_NAME
 #define FILE2_PATH DIR_PATH"/"FILE2_NAME
+#define SUBDIR_PATH DIR_PATH"/"SUBDIR_NAME
 #define FILE_EXEC_PATH MOUNT_PATH"/"TEST_APP
 #define FILE2_EXEC_PATH MOUNT_PATH"/"TEST_APP2
 #define DIR_MNT2 MNT2_PATH"/"DIR_NAME
@@ -104,6 +106,7 @@ static unsigned int num_classes = NUM_CLASSES;
 enum {
 	FANOTIFY_INODE,
 	FANOTIFY_PARENT,
+	FANOTIFY_SUBDIR,
 	FANOTIFY_MOUNT,
 	FANOTIFY_FILESYSTEM,
 	FANOTIFY_EVICTABLE,
@@ -112,6 +115,7 @@ enum {
 static struct fanotify_mark_type fanotify_mark_types[] = {
 	INIT_FANOTIFY_MARK_TYPE(INODE),
 	INIT_FANOTIFY_MARK_TYPE(PARENT),
+	INIT_FANOTIFY_MARK_TYPE(SUBDIR),
 	INIT_FANOTIFY_MARK_TYPE(MOUNT),
 	INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
 	INIT_FANOTIFY_MARK_TYPE(EVICTABLE),
@@ -123,7 +127,7 @@ static struct tcase {
 	int mark_type;
 	const char *ignore_path;
 	int ignore_mark_type;
-	unsigned int ignored_onchild;
+	unsigned int ignored_flags;
 	const char *event_path;
 	unsigned long long expected_mask_with_ignore;
 	unsigned long long expected_mask_without_ignore;
@@ -329,6 +333,28 @@ static struct tcase {
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
+	/* FAN_MARK_IGNORE specific test cases */
+	{
+		"ignore events on subdir inside a parent watching subdirs",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_EVENT_ON_CHILD | FAN_ONDIR,
+		SUBDIR_PATH, 0, FAN_OPEN | FAN_ONDIR
+	},
+	{
+		"don't ignore events on subdir inside a parent not watching children",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_ONDIR,
+		SUBDIR_PATH, FAN_OPEN | FAN_ONDIR, FAN_OPEN | FAN_ONDIR
+	},
+	{
+		"don't ignore events on subdir inside a parent watching non-dir children",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_EVENT_ON_CHILD,
+		SUBDIR_PATH, FAN_OPEN | FAN_ONDIR, FAN_OPEN | FAN_ONDIR
+	},
 };
 
 static void show_fanotify_ignore_marks(int fd, int expected)
@@ -365,6 +391,7 @@ static int create_fanotify_groups(unsigned int n)
 	unsigned int p, i;
 	int evictable_ignored = (tc->ignore_mark_type == FANOTIFY_EVICTABLE);
 	int ignore_mark_type;
+	int ignored_onchild = tc->ignored_flags & FAN_EVENT_ON_CHILD;
 
 	mark = &fanotify_mark_types[tc->mark_type];
 	ignore_mark = &fanotify_mark_types[tc->ignore_mark_type];
@@ -387,7 +414,7 @@ static int create_fanotify_groups(unsigned int n)
 			SAFE_FANOTIFY_MARK(fd_notify[p][i],
 					    FAN_MARK_ADD | mark->flag,
 					    tc->expected_mask_without_ignore |
-					    FAN_EVENT_ON_CHILD,
+					    FAN_EVENT_ON_CHILD | FAN_ONDIR,
 					    AT_FDCWD, tc->mark_path);
 
 			/* Do not add ignore mark for first priority groups */
@@ -400,7 +427,7 @@ static int create_fanotify_groups(unsigned int n)
 			 * 2. FAN_MARK_IGNORE
 			 */
 			mark_ignored = tst_variant ? FAN_MARK_IGNORE_SURV : FAN_MARK_IGNORED_SURV;
-			mask = FAN_OPEN | tc->ignored_onchild;
+			mask = FAN_OPEN | tc->ignored_flags;
 add_mark:
 			SAFE_FANOTIFY_MARK(fd_notify[p][i],
 					    FAN_MARK_ADD | ignore_mark->flag | mark_ignored,
@@ -414,7 +441,7 @@ add_mark:
 			 * This is needed to indicate that parent ignored mask
 			 * should be applied to events on children.
 			 */
-			if (tc->ignored_onchild && mark_ignored & FAN_MARK_IGNORED_MASK) {
+			if (ignored_onchild && mark_ignored & FAN_MARK_IGNORED_MASK) {
 				mark_ignored = 0;
 				goto add_mark;
 			}
@@ -437,10 +464,12 @@ add_mark:
 			 */
 			if (mark_ignored & FAN_MARK_IGNORE &&
 			    tc->ignore_mark_type == FANOTIFY_PARENT) {
-				if (!tc->ignored_onchild)
-					mask = FAN_CLOSE_WRITE | FAN_EVENT_ON_CHILD;
+				if (!ignored_onchild)
+					mask = FAN_CLOSE_WRITE | FAN_EVENT_ON_CHILD | FAN_ONDIR;
 				else if (tc->mark_type == FANOTIFY_PARENT)
 					continue;
+				else if (tc->ignored_flags & FAN_ONDIR)
+					mask = FAN_CLOSE | ignored_onchild;
 				else
 					mask = FAN_CLOSE | FAN_ONDIR;
 				mark_ignored = 0;
@@ -497,6 +526,10 @@ static void mount_cycle(void)
 static void verify_event(int p, int group, struct fanotify_event_metadata *event,
 			 unsigned long long expected_mask)
 {
+	/* Only FAN_REPORT_FID reports the FAN_ONDIR flag in events on dirs */
+	if (!(fanotify_class[p] & FAN_REPORT_FID))
+		expected_mask &= ~FAN_ONDIR;
+
 	if (event->mask != expected_mask) {
 		tst_res(TFAIL, "group %d (%x) got event: mask %llx (expected %llx) "
 			"pid=%u fd=%u", group, fanotify_class[p],
@@ -572,12 +605,19 @@ static void test_fanotify(unsigned int n)
 		return;
 	}
 
-	if (tc->ignored_onchild && tst_kvercmp(5, 9, 0) < 0) {
+	if (tc->ignored_flags & FAN_EVENT_ON_CHILD && tst_kvercmp(5, 9, 0) < 0) {
 		tst_res(TCONF, "ignored mask in combination with flag FAN_EVENT_ON_CHILD"
 				" has undefined behavior on kernel < 5.9");
 		return;
 	}
 
+	if (tc->ignored_flags && tc->ignore_mark_type == FANOTIFY_PARENT &&
+			!tst_variant && tc->mark_type == FANOTIFY_SUBDIR) {
+		tst_res(TCONF, "flags FAN_EVENT_ON_CHILD and FAN_ONDIR do not take effect"
+				" with legacy FAN_MARK_IGNORED_MASK");
+		return;
+	}
+
 	if (create_fanotify_groups(n) != 0)
 		goto cleanup;
 
@@ -675,6 +715,7 @@ static void setup(void)
 	}
 
 	SAFE_MKDIR(DIR_PATH, 0755);
+	SAFE_MKDIR(SUBDIR_PATH, 0755);
 	SAFE_FILE_PRINTF(FILE_PATH, "1");
 	SAFE_FILE_PRINTF(FILE2_PATH, "1");
 
@@ -701,6 +742,7 @@ static void cleanup(void)
 
 	SAFE_UNLINK(FILE_PATH);
 	SAFE_UNLINK(FILE2_PATH);
+	SAFE_RMDIR(SUBDIR_PATH);
 	SAFE_RMDIR(DIR_PATH);
 	SAFE_RMDIR(MNT2_PATH);
 }
-- 
2.25.1


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

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

* Re: [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases for FAN_MARK_IGNORE
  2022-09-05 15:42 ` [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases " Amir Goldstein
@ 2022-09-05 16:04   ` Petr Vorel
  2022-09-06  5:08     ` Amir Goldstein
  0 siblings, 1 reply; 23+ messages in thread
From: Petr Vorel @ 2022-09-05 16:04 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi Amir,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

...
> diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c
> index 0eb83e2f8..e40916c08 100644
> --- a/testcases/kernel/syscalls/fanotify/fanotify09.c
> +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c
> @@ -73,12 +73,14 @@ static char event_buf[EVENT_BUF_LEN];
>  static int mount_created;

>  static int fan_report_dfid_unsupported;
> +static int ignore_mark_unsupported;

>  static struct tcase {
>  	const char *tname;
>  	struct fanotify_mark_type mark;
>  	unsigned int ondir;
>  	unsigned int ignore;
> +	unsigned int ignore_flags;
>  	unsigned int report_name;
>  	const char *close_nowrite;
>  	int nevents;
> @@ -88,7 +90,7 @@ static struct tcase {
>  		"Events on non-dir child with both parent and mount marks",
>  		INIT_FANOTIFY_MARK_TYPE(MOUNT),
>  		0,
> -		0,
> +		0, 0,
>  		0,
>  		DIR_NAME,
>  		1, 0,

nit: as number of struct grow, it'd help readability to omit members with 0:
		.tname = "Events on non-dir child with both parent and mount marks",
		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
		.close_nowrite = DIR_NAME,
		.nevents = 1,

This is obviously non-blocker of this patch, if you agree it can be done any
time later.

Also I fixed make check warnings some time ago (i.e. checkpatch.pl), but they
got back. I might find a time to fix them (we appreciate you look after the
test, thus don't want to bother you with these tiny details).

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases for FAN_MARK_IGNORE
  2022-09-05 16:04   ` Petr Vorel
@ 2022-09-06  5:08     ` Amir Goldstein
  2022-09-06  5:58       ` Petr Vorel
  0 siblings, 1 reply; 23+ messages in thread
From: Amir Goldstein @ 2022-09-06  5:08 UTC (permalink / raw)
  To: Petr Vorel; +Cc: Matthew Bobrowski, Jan Kara, LTP List

On Mon, Sep 5, 2022 at 7:04 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Amir,
>
> Reviewed-by: Petr Vorel <pvorel@suse.cz>
>
> ...
> > diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c
> > index 0eb83e2f8..e40916c08 100644
> > --- a/testcases/kernel/syscalls/fanotify/fanotify09.c
> > +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c
> > @@ -73,12 +73,14 @@ static char event_buf[EVENT_BUF_LEN];
> >  static int mount_created;
>
> >  static int fan_report_dfid_unsupported;
> > +static int ignore_mark_unsupported;
>
> >  static struct tcase {
> >       const char *tname;
> >       struct fanotify_mark_type mark;
> >       unsigned int ondir;
> >       unsigned int ignore;
> > +     unsigned int ignore_flags;
> >       unsigned int report_name;
> >       const char *close_nowrite;
> >       int nevents;
> > @@ -88,7 +90,7 @@ static struct tcase {
> >               "Events on non-dir child with both parent and mount marks",
> >               INIT_FANOTIFY_MARK_TYPE(MOUNT),
> >               0,
> > -             0,
> > +             0, 0,
> >               0,
> >               DIR_NAME,
> >               1, 0,
>
> nit: as number of struct grow, it'd help readability to omit members with 0:
>                 .tname = "Events on non-dir child with both parent and mount marks",
>                 .mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
>                 .close_nowrite = DIR_NAME,
>                 .nevents = 1,
>

You are absolutely right.
The readability of use cases is quite tough at this point.

> This is obviously non-blocker of this patch, if you agree it can be done any
> time later.

Certainly.
I think that growing the struct is a good place to stop and
do this cleanup, we have got plenty of time until v6.0 and I expect to
get more comments on this series, so I will probably do this cleanup
already for v2.

>
> Also I fixed make check warnings some time ago (i.e. checkpatch.pl), but they

Cool. I didn't know.

> got back. I might find a time to fix them (we appreciate you look after the
> test, thus don't want to bother you with these tiny details).
>

This is the only new check warning I see:

fanotify10.c:378: ERROR: Bad function definition - void drop_caches()
should probably be void drop_caches(void)
make: [../../../../include/mk/rules.mk:56: check-fanotify10] Error 1 (ignored)
fanotify10.c:378:25: warning: non-ANSI function declaration of
function 'drop_caches'

I will fix it.

Thanks,
Amir.

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

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

* Re: [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases for FAN_MARK_IGNORE
  2022-09-06  5:08     ` Amir Goldstein
@ 2022-09-06  5:58       ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-06  5:58 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, LTP List

> On Mon, Sep 5, 2022 at 7:04 PM Petr Vorel <pvorel@suse.cz> wrote:

> > Hi Amir,

> > Reviewed-by: Petr Vorel <pvorel@suse.cz>

> > ...
> > > diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c
> > > index 0eb83e2f8..e40916c08 100644
> > > --- a/testcases/kernel/syscalls/fanotify/fanotify09.c
> > > +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c
> > > @@ -73,12 +73,14 @@ static char event_buf[EVENT_BUF_LEN];
> > >  static int mount_created;

> > >  static int fan_report_dfid_unsupported;
> > > +static int ignore_mark_unsupported;

> > >  static struct tcase {
> > >       const char *tname;
> > >       struct fanotify_mark_type mark;
> > >       unsigned int ondir;
> > >       unsigned int ignore;
> > > +     unsigned int ignore_flags;
> > >       unsigned int report_name;
> > >       const char *close_nowrite;
> > >       int nevents;
> > > @@ -88,7 +90,7 @@ static struct tcase {
> > >               "Events on non-dir child with both parent and mount marks",
> > >               INIT_FANOTIFY_MARK_TYPE(MOUNT),
> > >               0,
> > > -             0,
> > > +             0, 0,
> > >               0,
> > >               DIR_NAME,
> > >               1, 0,

> > nit: as number of struct grow, it'd help readability to omit members with 0:
> >                 .tname = "Events on non-dir child with both parent and mount marks",
> >                 .mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
> >                 .close_nowrite = DIR_NAME,
> >                 .nevents = 1,


> You are absolutely right.
> The readability of use cases is quite tough at this point.

> > This is obviously non-blocker of this patch, if you agree it can be done any
> > time later.

> Certainly.
> I think that growing the struct is a good place to stop and
> do this cleanup, we have got plenty of time until v6.0 and I expect to
> get more comments on this series, so I will probably do this cleanup
> already for v2.
Thank you!

FYI we have LTP releases regularly 4x a year [1], the next one will be around
the end of September, with git freeze ~ 2 weeks before, i.e. very soon.
Of course this patchset should get in the release (I don't expect any issues any
major problems reported by Jan or Matthew, checkpatch.pl issues will not block it).

> > Also I fixed make check warnings some time ago (i.e. checkpatch.pl), but they

> Cool. I didn't know.

> > got back. I might find a time to fix them (we appreciate you look after the
> > test, thus don't want to bother you with these tiny details).


> This is the only new check warning I see:

> fanotify10.c:378: ERROR: Bad function definition - void drop_caches()
> should probably be void drop_caches(void)
> make: [../../../../include/mk/rules.mk:56: check-fanotify10] Error 1 (ignored)
> fanotify10.c:378:25: warning: non-ANSI function declaration of
> function 'drop_caches'
My bad - I fixed it before 0cb281815 ("tools: Check headers with checkpatch.pl")
which included the report also for headers. And yes, the rest of (mostly)
formatting reports are in fanotify.h.

Obviously we haven't found all checks which aren't relevant for userspace,
therefore I posted patch ignore some of them in LTP [2].

> I will fix it.
Thank you.

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/releases
[2] https://lore.kernel.org/ltp/20220906054612.9790-1-pvorel@suse.cz/

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

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

* Re: [LTP] [PATCH 2/9] syscalls/fanotify14: Require FAN_REPORT_FID support for entire test
  2022-09-05 15:42 ` [LTP] [PATCH 2/9] syscalls/fanotify14: Require FAN_REPORT_FID support for entire test Amir Goldstein
@ 2022-09-06  6:06   ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-06  6:06 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi Amir, all,

> To avoid complex requirements for the new test case, we now require
> FAN_REPORT_FID support for the entire test, which opts-out from testing
> on FUSE filesystem.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

> It is not clear that there is anything to gain from running this test
> on all_filsystems in the first place.

Interesting.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH 3/9] syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE
  2022-09-05 15:42 ` [LTP] [PATCH 3/9] syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE Amir Goldstein
@ 2022-09-06  9:05   ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-06  9:05 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi Amir, all,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE
  2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
                   ` (8 preceding siblings ...)
  2022-09-05 15:42 ` [LTP] [PATCH 9/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_ONDIR Amir Goldstein
@ 2022-09-06 15:38 ` Jan Kara
  2022-09-06 17:28   ` Amir Goldstein
  9 siblings, 1 reply; 23+ messages in thread
From: Jan Kara @ 2022-09-06 15:38 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Jan Kara, ltp, Matthew Bobrowski

Hi Amir!

On Mon 05-09-22 18:42:30, Amir Goldstein wrote:
> FAN_MARK_IGNORE feature was merge in v6.0-rc1.
> A man page draft was posted here [1].
> 
> Following are the tests for the new feature.
> 
> All new test cases are skipped on old kernels.
> 
> Note that fanotify10 will run ALL of its existing test cases
> in two variants:
> 1. Legacy FAN_MARK_IGNORED_MASK
> 2. New FAN_MARK_IGNORE
> 
> On old kernels, only the first variant of the test will run.
> 
> In addition to the new test variant it also has some new test cases
> that only run with new FAN_MARK_IGNORE variant.

Thanks for the tests! They look good to me although I have to admit my head
starts to spin with the number of combinations and variations in fanotify10
testcase so I'm not very confident some subtle bug could not slip in. But
hey, it's just tests and they are easy to fix if some breakage slips in. So
feel free to add:

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

								Honza
 
> [1] https://lore.kernel.org/linux-man/20220904155113.2623371-1-amir73il@gmail.com/
> 
> Amir Goldstein (9):
>   syscalls/fanotify09: Add test cases for FAN_MARK_IGNORE
>   syscalls/fanotify14: Require FAN_REPORT_FID support for entire test
>   syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE
>   syscalls/fanotify10: Avoid undesired event in test
>   syscalls/fanotify10: Add more verifications and debug info
>   syscalls/fanotify10: Use dedicated mark type for inode mark on parent
>   syscalls/fanotify10: Run tests with two ignore mask variants
>   syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_EVENT_ON_CHILD
>   syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_ONDIR
> 
>  testcases/kernel/syscalls/fanotify/fanotify.h |  19 ++
>  .../kernel/syscalls/fanotify/fanotify09.c     | 102 ++++++++--
>  .../kernel/syscalls/fanotify/fanotify10.c     | 186 ++++++++++++++----
>  .../kernel/syscalls/fanotify/fanotify14.c     |  42 +++-
>  4 files changed, 290 insertions(+), 59 deletions(-)
> 
> -- 
> 2.25.1
> 
-- 
Jan Kara <jack@suse.com>
SUSE Labs, CR

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

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

* Re: [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test
  2022-09-05 15:42 ` [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test Amir Goldstein
@ 2022-09-06 16:51   ` Petr Vorel
  2022-09-06 17:09   ` Petr Vorel
  1 sibling, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-06 16:51 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH 5/9] syscalls/fanotify10: Add more verifications and debug info
  2022-09-05 15:42 ` [LTP] [PATCH 5/9] syscalls/fanotify10: Add more verifications and debug info Amir Goldstein
@ 2022-09-06 17:01   ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-06 17:01 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi Amir, all,

> Check that non-evictable inode ignore marks exist as expected
> and print mask of unexpected events.

> Fix information printed for events from unexpected pid.

Reviewed-by: Petr Vorel <pvorel@suse.cz>

...
> +++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
...
> @@ -582,14 +591,18 @@ static void test_fanotify(unsigned int n)
>  	for (p = 1; p < num_classes && !tc->expected_mask_with_ignore; p++) {
>  		for (i = 0; i < GROUPS_PER_PRIO; i++) {
>  			ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN);
> -			if (ret == 0) {
> +			if (ret >= 0 && ret < (int)FAN_EVENT_METADATA_LEN) {
>  				tst_brk(TBROK,
> -					"zero length read from fanotify fd");
> +					"short read when reading fanotify "
> +					"events (%d < %d)", ret,
> +					(int)EVENT_BUF_LEN);
Just for the record printing like this...

>  			}
> +			event = (struct fanotify_event_metadata *)event_buf;
>  			if (ret > 0) {
>  				tst_res(TFAIL, "group %d (%x) with %s and "
> -					"%s ignore mask got event",
> -					i, fanotify_class[p], mark->name, ignore_mark->name);
> +					"%s ignore mask got unexpected event (mask %llx)",
> +					i, fanotify_class[p], mark->name, ignore_mark->name,
> +					event->mask);
and this will be possible to avoid with macros include/tst_test_macros.h,
which prints them for free. FYI there can be also custom error text instead
of the failing syscall with parameters printed by default. But IMHO there should
be a reason to use it (mostly the default should be good enough, in case of
failure test reviewers will have to look into the test source anyway).

Kind regards,
Petr

>  				if (event->fd != FAN_NOFD)
>  					SAFE_CLOSE(event->fd);
>  			} else if (errno == EAGAIN) {

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

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

* Re: [LTP] [PATCH 6/9] syscalls/fanotify10: Use dedicated mark type for inode mark on parent
  2022-09-05 15:42 ` [LTP] [PATCH 6/9] syscalls/fanotify10: Use dedicated mark type for inode mark on parent Amir Goldstein
@ 2022-09-06 17:03   ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-06 17:03 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi all,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH 7/9] syscalls/fanotify10: Run tests with two ignore mask variants
  2022-09-05 15:42 ` [LTP] [PATCH 7/9] syscalls/fanotify10: Run tests with two ignore mask variants Amir Goldstein
@ 2022-09-06 17:07   ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-06 17:07 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi all,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

1128 tests, quite impressive :).

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test
  2022-09-05 15:42 ` [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test Amir Goldstein
  2022-09-06 16:51   ` Petr Vorel
@ 2022-09-06 17:09   ` Petr Vorel
  1 sibling, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-06 17:09 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, ltp

Hi all,

> +++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
> @@ -66,6 +66,7 @@ static unsigned int fanotify_class[] = {
>  #define GROUPS_PER_PRIO 3

>  static int fd_notify[NUM_CLASSES][GROUPS_PER_PRIO];
> +static int fd_syncfs;

>  static char event_buf[EVENT_BUF_LEN];
>  static int exec_events_unsupported;
> @@ -342,14 +343,11 @@ static void show_fanotify_marks(int fd)
>  	}
>  }

> -static void drop_caches(const char *path)
Note for myself to add void here before merge
> +static void drop_caches()
>  {

fanotify10.c: In function ‘drop_caches’:
fanotify10.c:352:13: warning: old-style function definition [-Wold-style-definition]
  352 | static void drop_caches()

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE
  2022-09-06 15:38 ` [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Jan Kara
@ 2022-09-06 17:28   ` Amir Goldstein
  2022-09-07 10:45     ` Petr Vorel
  0 siblings, 1 reply; 23+ messages in thread
From: Amir Goldstein @ 2022-09-06 17:28 UTC (permalink / raw)
  To: Jan Kara; +Cc: LTP List, Matthew Bobrowski

On Tue, Sep 6, 2022 at 6:38 PM Jan Kara <jack@suse.cz> wrote:
>
> Hi Amir!
>
> On Mon 05-09-22 18:42:30, Amir Goldstein wrote:
> > FAN_MARK_IGNORE feature was merge in v6.0-rc1.
> > A man page draft was posted here [1].
> >
> > Following are the tests for the new feature.
> >
> > All new test cases are skipped on old kernels.
> >
> > Note that fanotify10 will run ALL of its existing test cases
> > in two variants:
> > 1. Legacy FAN_MARK_IGNORED_MASK
> > 2. New FAN_MARK_IGNORE
> >
> > On old kernels, only the first variant of the test will run.
> >
> > In addition to the new test variant it also has some new test cases
> > that only run with new FAN_MARK_IGNORE variant.
>
> Thanks for the tests! They look good to me although I have to admit my head
> starts to spin with the number of combinations and variations in fanotify10
> testcase so I'm not very confident some subtle bug could not slip in. But

Yeh.. I can follow fanotify10 only on a good day ;)

The good thing about it is that after staring at it for long enough
I was able to extend it to provide test coverage for FAN_MARK_IGNORE
with relatively very little changes.

> hey, it's just tests and they are easy to fix if some breakage slips in. So
> feel free to add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>

Thanks!
Amir.

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

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

* Re: [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE
  2022-09-06 17:28   ` Amir Goldstein
@ 2022-09-07 10:45     ` Petr Vorel
  0 siblings, 0 replies; 23+ messages in thread
From: Petr Vorel @ 2022-09-07 10:45 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Matthew Bobrowski, Jan Kara, LTP List

Hi all,

patchset merged.

I tested it on various kernels, works as expected (old kernels TCONF; fanotify14
catches problems on 5.18.0 and 5.17.3, but 6.0.0-rc3 TPASS).

Thank you!

Kind regards,
Petr

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

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

end of thread, other threads:[~2022-09-07 10:45 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 15:42 [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Amir Goldstein
2022-09-05 15:42 ` [LTP] [PATCH 1/9] syscalls/fanotify09: Add test cases " Amir Goldstein
2022-09-05 16:04   ` Petr Vorel
2022-09-06  5:08     ` Amir Goldstein
2022-09-06  5:58       ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 2/9] syscalls/fanotify14: Require FAN_REPORT_FID support for entire test Amir Goldstein
2022-09-06  6:06   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 3/9] syscalls/fanotify14: Add test cases for FAN_MARK_IGNORE Amir Goldstein
2022-09-06  9:05   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 4/9] syscalls/fanotify10: Avoid undesired event in test Amir Goldstein
2022-09-06 16:51   ` Petr Vorel
2022-09-06 17:09   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 5/9] syscalls/fanotify10: Add more verifications and debug info Amir Goldstein
2022-09-06 17:01   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 6/9] syscalls/fanotify10: Use dedicated mark type for inode mark on parent Amir Goldstein
2022-09-06 17:03   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 7/9] syscalls/fanotify10: Run tests with two ignore mask variants Amir Goldstein
2022-09-06 17:07   ` Petr Vorel
2022-09-05 15:42 ` [LTP] [PATCH 8/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_EVENT_ON_CHILD Amir Goldstein
2022-09-05 15:42 ` [LTP] [PATCH 9/9] syscalls/fanotify10: Test FAN_MARK_IGNORE with FAN_ONDIR Amir Goldstein
2022-09-06 15:38 ` [LTP] [PATCH 0/9] Fanotify tests for FAN_MARK_IGNORE Jan Kara
2022-09-06 17:28   ` Amir Goldstein
2022-09-07 10:45     ` Petr Vorel

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.