[LTP] [PATCH 1/4] epoll_wait06, fcntl35: Don't assume a pipe buffer is getpagesize()

Wake Liu wakel@google.com
Wed Nov 11 10:31:48 CET 2026


A pipe consists of pipe buffers of one kernel page each, but both tests
assume that a pipe buffer is getpagesize() bytes.

epoll_wait06 sets the pipe capacity to getpagesize() and expects the
pipe to consist of a single buffer, so that reading half of the data
does not release a buffer and raise EPOLLOUT. fcntl35 expects the
default capacity of a pipe created by a privileged user, which is 16
pipe buffers (PIPE_DEF_BUFFERS), to be 16 * getpagesize().

Neither holds when the kernel reports a larger page size to userspace
than it uses internally, as with the 16K page size emulation that
Android uses on x86_64. There the pipe of epoll_wait06 consists of four
4K buffers, reading half of the data releases two of them, and the
test fails with:

  TFAIL: SAFE_EPOLL_WAIT(epfd, &evt_receive, 1, 0) (1) != 0 (0)

fcntl35 gets a default capacity of 65536 bytes instead of the expected
262144.

Get the size of a pipe buffer from the kernel instead, by shrinking a
pipe to its minimum capacity with F_SETPIPE_SZ. The unprivileged case
of fcntl35 needs no change, as setting pipe-max-size to getpagesize()
still caps the capacity at getpagesize() bytes. Nothing changes on
kernels where both page sizes are equal.

Signed-off-by: Wake Liu <wakel@google.com>
---
 .../kernel/syscalls/epoll_wait/epoll_wait06.c | 15 +++++++++-----
 testcases/kernel/syscalls/fcntl/fcntl35.c     | 20 ++++++++++++++++++-
 2 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait06.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait06.c
index 622830d55..ce4e2d5bc 100644
--- a/testcases/kernel/syscalls/epoll_wait/epoll_wait06.c
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait06.c
@@ -32,13 +32,18 @@ static int epfd;
 
 static void setup(void)
 {
-	write_size = getpagesize();
-	read_size = write_size / 2;
-
 	SAFE_PIPE2(fds, O_NONBLOCK);
 
-	/* EPOLLOUT will be raised when buffer became empty after becoming full */
-	SAFE_FCNTL(fds[1], F_SETPIPE_SZ, write_size);
+	/*
+	 * EPOLLOUT will be raised when buffer became empty after becoming full.
+	 *
+	 * Shrink the pipe to its minimum capacity, which is a single pipe
+	 * buffer, so that reading only half of the data doesn't release any
+	 * buffer. Use the capacity reported by the kernel rather than
+	 * assuming it matches getpagesize().
+	 */
+	write_size = SAFE_FCNTL(fds[1], F_SETPIPE_SZ, 1);
+	read_size = write_size / 2;
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/fcntl/fcntl35.c b/testcases/kernel/syscalls/fcntl/fcntl35.c
index d17812fd0..a240500d4 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl35.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl35.c
@@ -44,10 +44,28 @@ static struct tcase {
 	{&test_max_priv, 0, "a privileged user"}
 };
 
+/*
+ * The pipe capacity is a multiple of the size of a pipe buffer, which is one
+ * page of the kernel. Get it by shrinking a pipe to its minimum capacity,
+ * rather than assuming it matches getpagesize().
+ */
+static int get_pipe_buf_size(void)
+{
+	int fds[2], size;
+
+	SAFE_PIPE(fds);
+	size = SAFE_FCNTL(fds[1], F_SETPIPE_SZ, 1);
+	SAFE_CLOSE(fds[0]);
+	SAFE_CLOSE(fds[1]);
+
+	return size;
+}
+
 static void setup(void)
 {
 	test_max_unpriv = getpagesize();
-	test_max_priv = test_max_unpriv * 16;
+	/* The default capacity is 16 pipe buffers (PIPE_DEF_BUFFERS) */
+	test_max_priv = get_pipe_buf_size() * 16;
 
 	if (!access(PATH_FS_PIPE_MAX_SIZE, F_OK)) {
 		SAFE_FILE_SCANF(PATH_FS_PIPE_MAX_SIZE, "%d", &pipe_max_unpriv);
-- 
2.56.0.567.gdb80ae8cd5-goog



More information about the ltp mailing list