* [PATCH v4] selftests/cgroup: test pids.events notification
@ 2026-10-15 11:12 Sahaj Chaudhari
2026-10-16 20:07 ` Tejun Heo
0 siblings, 1 reply; 2+ messages in thread
From: Sahaj Chaudhari @ 2026-10-15 11:12 UTC (permalink / raw)
To: Tejun Heo
Cc: Johannes Weiner, Michal Koutný, Shuah Khan, cgroups,
linux-kselftest, linux-kernel, Sahaj Chaudhari
Add a test to test_pids.c that checks a fork rejected by pids.max
increments pids.events and generates an IN_MODIFY inotify event on that
file. The test cgroup is the one over the limit, so the notification is
expected both on a default mount and with pids_localevents.
This covers the fix in commit 1765a153d985 ("cgroup/pids: Restore
pids.events notifications in local mode"), where a rejected fork changed
pids.events without waking its pollers when pids_localevents was enabled.
Tested on x86_64 under QEMU without KVM, on kernels built from the
cgroup for-7.4 branch (eb69e955de7b) and from the same tree with that
fix reverted. With the fix, the new test passes on a default cgroup2
mount and on a pids_localevents mount. With the fix reverted, it passes
on a default mount and fails on a pids_localevents mount. No kernel
warnings were logged.
Link: https://lore.kernel.org/r/20261013064812.875787-1-sahaj123.sc@gmail.com
Signed-off-by: Sahaj Chaudhari <sahaj123.sc@gmail.com>
---
Changes in v4:
- Move the test into test_pids.c as test_pids_events_notify(), using
cg_run_nowait() and cg_control(), instead of a separate program. This
drops the Makefile and .gitignore changes.
- Drop the pids_localevents skip. The test cgroup is the one over the
limit, so the rejected fork notifies it on both mount types.
- Drop the duplicate pids.events check after reading the inotify event.
- Cite 1765a153d985 as the fix the test covers.
- Move the read() error-handling note from the commit message to this
changelog.
- Rebase onto the cgroup for-7.4 branch.
Changes in v3:
- Check for a failed read() of the inotify event before comparing its
signed result with sizeof(struct inotify_event).
v3: https://lore.kernel.org/r/20261013064812.875787-1-sahaj123.sc@gmail.com
tools/testing/selftests/cgroup/test_pids.c | 73 ++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/tools/testing/selftests/cgroup/test_pids.c b/tools/testing/selftests/cgroup/test_pids.c
index 710109b53dfe..e775c5510cf2 100644
--- a/tools/testing/selftests/cgroup/test_pids.c
+++ b/tools/testing/selftests/cgroup/test_pids.c
@@ -3,8 +3,11 @@
#include <errno.h>
#include <linux/limits.h>
+#include <poll.h>
#include <signal.h>
+#include <stdlib.h>
#include <string.h>
+#include <sys/inotify.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
@@ -133,6 +136,75 @@ static int test_pids_events(const char *root)
+/*
+ * This test checks that a fork rejected by pids.max increments pids.events
+ * and notifies pollers of that file, with or without pids_localevents.
+ */
+static int test_pids_events_notify(const char *root)
+{
+ union {
+ struct inotify_event align;
+ char bytes[sizeof(struct inotify_event) + NAME_MAX + 1];
+ } event;
+ int ret = KSFT_FAIL;
+ int inotify_fd = -1;
+ char *cg_pids = NULL, *events_path = NULL;
+ struct pollfd pfd;
+ ssize_t n;
+
+ cg_pids = cg_name(root, "pids_notify_test");
+ if (!cg_pids)
+ goto cleanup;
+
+ if (cg_create(cg_pids))
+ goto cleanup;
+
+ if (cg_write(cg_pids, "pids.max", "1"))
+ goto cleanup;
+
+ events_path = cg_control(cg_pids, "pids.events");
+ if (!events_path)
+ goto cleanup;
+
+ inotify_fd = inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
+ if (inotify_fd < 0)
+ goto cleanup;
+
+ if (inotify_add_watch(inotify_fd, events_path, IN_MODIFY) < 0)
+ goto cleanup;
+
+ if (cg_enter_current(cg_pids))
+ goto cleanup;
+
+ if (cg_run_nowait(cg_pids, run_success, NULL) != -1 || errno != EAGAIN)
+ goto cleanup;
+
+ if (cg_read_key_long(cg_pids, "pids.events", "max ") != 1)
+ goto cleanup;
+
+ pfd.fd = inotify_fd;
+ pfd.events = POLLIN;
+ if (poll(&pfd, 1, 1000) <= 0)
+ goto cleanup;
+
+ n = read(inotify_fd, event.bytes, sizeof(event.bytes));
+ if (n < (ssize_t)sizeof(event.align) || !(event.align.mask & IN_MODIFY))
+ goto cleanup;
+
+ ret = KSFT_PASS;
+
+cleanup:
+ cg_enter_current(root);
+ if (inotify_fd >= 0)
+ close(inotify_fd);
+ if (cg_pids)
+ cg_destroy(cg_pids);
+ free(events_path);
+ free(cg_pids);
+
+ return ret;
+}
+
#define T(x) { x, #x }
struct pids_test {
int (*fn)(const char *root);
@@ -140,6 +212,7 @@ struct pids_test {
} tests[] = {
T(test_pids_max),
T(test_pids_events),
+ T(test_pids_events_notify),
};
#undef T
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-10-16 20:07 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-15 11:12 [PATCH v4] selftests/cgroup: test pids.events notification Sahaj Chaudhari
2026-10-16 20:07 ` Tejun Heo
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.