[LTP] [PATCH 2/2] pipe2_04: Don't assume the minimum pipe size is getpagesize()

Wake Liu wakel@google.com
Mon Nov 16 08:23:46 CET 2026


F_SETPIPE_SZ rounds the requested size up to the minimum pipe capacity,
which is a single pipe buffer of one kernel page. The test expects that
to be equal to the page size reported to userspace.

That is not the case 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:

  TFAIL: Pipe size (4096) must be page size (16384)

Check that F_GETPIPE_SZ on the other end of the pipe returns the size
set by F_SETPIPE_SZ, which is what the test is about, and that the
minimum size does not exceed the page size. The rest of the test
already uses the actual pipe size.

Signed-off-by: Wake Liu <wakel@google.com>
---
 testcases/kernel/syscalls/pipe2/pipe2_04.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/testcases/kernel/syscalls/pipe2/pipe2_04.c b/testcases/kernel/syscalls/pipe2/pipe2_04.c
index 3911f95b4..7b071a420 100644
--- a/testcases/kernel/syscalls/pipe2/pipe2_04.c
+++ b/testcases/kernel/syscalls/pipe2/pipe2_04.c
@@ -57,7 +57,7 @@ static void test_pipe2(void)
 
 static void setup(void)
 {
-	int page_size, pipe_size;
+	int page_size, pipe_size, set_size;
 	char *write_buffer;
 
 	SAFE_PIPE2(fds, O_NONBLOCK);
@@ -70,17 +70,24 @@ static void setup(void)
 	 * A pipe has two file descriptors.
 	 * But in the kernel these two file descriptors point to the same pipe.
 	 * So setting size from first file handle set size for the pipe.
+	 *
+	 * The size is rounded up to the minimum pipe capacity, i.e. a single
+	 * pipe buffer of one kernel page, which is not necessarily the same
+	 * as the page size reported to userspace.
 	 */
-	SAFE_FCNTL(fds[0], F_SETPIPE_SZ, 0);
+	set_size = SAFE_FCNTL(fds[0], F_SETPIPE_SZ, 0);
+	if (set_size > page_size)
+		tst_res(TFAIL, "Minimum pipe size (%d) exceeds page size (%d)",
+				set_size, page_size);
 
 	/*
 	 * So getting size from the second file descriptor return the size of
 	 * the pipe which was changed before with first file descriptor.
 	 */
 	pipe_size = SAFE_FCNTL(fds[1], F_GETPIPE_SZ);
-	if (pipe_size != page_size)
-		tst_res(TFAIL, "Pipe size (%d) must be page size (%d)",
-				pipe_size, page_size);
+	if (pipe_size != set_size)
+		tst_res(TFAIL, "Pipe size (%d) must be the size set (%d)",
+				pipe_size, set_size);
 
 	write_buffer = SAFE_MALLOC(pipe_size);
 	memset(write_buffer, 'x', pipe_size);
-- 
2.56.0.611.g1030f0b940-goog



More information about the ltp mailing list