* [LTP] [PATCH 0/2] Introduce SAFE_SPLICE()
@ 2026-04-30 17:25 Andrea Cervesato
2026-04-30 17:25 ` [LTP] [PATCH 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
2026-04-30 17:25 ` [LTP] [PATCH 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE() Andrea Cervesato
0 siblings, 2 replies; 5+ messages in thread
From: Andrea Cervesato @ 2026-04-30 17:25 UTC (permalink / raw)
To: Linux Test Project
- add SAFE_SPLICE()
- update tests to use the new macro
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Andrea Cervesato (2):
lib: Add SAFE_SPLICE() macro
tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
include/tst_safe_macros.h | 8 ++++++++
lib/tst_safe_macros.c | 17 +++++++++++++++++
testcases/kernel/crypto/af_alg08.c | 10 ++--------
testcases/kernel/syscalls/tee/tee01.c | 9 ++-------
testcases/kernel/syscalls/vmsplice/vmsplice01.c | 6 +-----
5 files changed, 30 insertions(+), 20 deletions(-)
---
base-commit: 72ca484cca53710b956ba2fcc1ff203fe9c9b73b
change-id: 20260430-safe_splice-a3d6403f99cd
Best regards,
--
Andrea Cervesato <andrea.cervesato@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread* [LTP] [PATCH 1/2] lib: Add SAFE_SPLICE() macro
2026-04-30 17:25 [LTP] [PATCH 0/2] Introduce SAFE_SPLICE() Andrea Cervesato
@ 2026-04-30 17:25 ` Andrea Cervesato
2026-04-30 19:29 ` [LTP] " linuxtestproject.agent
2026-04-30 17:25 ` [LTP] [PATCH 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE() Andrea Cervesato
1 sibling, 1 reply; 5+ messages in thread
From: Andrea Cervesato @ 2026-04-30 17:25 UTC (permalink / raw)
To: Linux Test Project
From: Andrea Cervesato <andrea.cervesato@suse.com>
splice() is used as utility plumbing in several tests (tee01,
vmsplice01, af_alg08) but lacks a SAFE_* wrapper, forcing each
caller to manually check the return value. Add SAFE_SPLICE()
following the existing safe_pipe2() pattern.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/tst_safe_macros.h | 8 ++++++++
lib/tst_safe_macros.c | 17 +++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index c73c1acb1cbd671d4d22b740647d3e7491f7baf2..53caf845d1172cccf23d631d97e1f5086f98f547 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -114,6 +114,14 @@ int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags);
#define SAFE_PIPE2(fildes, flags) \
safe_pipe2(__FILE__, __LINE__, (fildes), (flags))
+ssize_t safe_splice(const char *file, const int lineno,
+ int fd_in, loff_t *off_in, int fd_out, loff_t *off_out,
+ size_t len, unsigned int flags);
+
+#define SAFE_SPLICE(fd_in, off_in, fd_out, off_out, len, flags) \
+ safe_splice(__FILE__, __LINE__, (fd_in), (off_in), (fd_out), \
+ (off_out), (len), (flags))
+
#define SAFE_READ(len_strict, fildes, buf, nbyte) \
safe_read(__FILE__, __LINE__, NULL, (len_strict), (fildes), (buf), (nbyte))
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index cdc8c7dd33cb0f805d40095b732d723497b2adeb..8f3dbbd1d2f371f2986356187c41007993f1589e 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -21,6 +21,7 @@
#include "tst_safe_macros.h"
#include "lapi/personality.h"
#include "lapi/pidfd.h"
+#include "lapi/splice.h"
int safe_access(const char *file, const int lineno,
const char *pathname, int mode)
@@ -512,6 +513,22 @@ int safe_pipe2(const char *file, const int lineno, int fildes[2], int flags)
return ret;
}
+ssize_t safe_splice(const char *file, const int lineno,
+ int fd_in, loff_t *off_in, int fd_out, loff_t *off_out,
+ size_t len, unsigned int flags)
+{
+ ssize_t ret;
+
+ ret = splice(fd_in, off_in, fd_out, off_out, len, flags);
+
+ if (ret < 0) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "splice(%d, %d, %zu) failed", fd_in, fd_out, len);
+ }
+
+ return ret;
+}
+
int safe_dup(const char *file, const int lineno, int oldfd)
{
int rval;
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread* [LTP] [PATCH 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
2026-04-30 17:25 [LTP] [PATCH 0/2] Introduce SAFE_SPLICE() Andrea Cervesato
2026-04-30 17:25 ` [LTP] [PATCH 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
@ 2026-04-30 17:25 ` Andrea Cervesato
1 sibling, 0 replies; 5+ messages in thread
From: Andrea Cervesato @ 2026-04-30 17:25 UTC (permalink / raw)
To: Linux Test Project
From: Andrea Cervesato <andrea.cervesato@suse.com>
Replace raw splice() calls with manual error checking by
SAFE_SPLICE() in tests where splice is not the subject of
testing but just utility plumbing.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/crypto/af_alg08.c | 10 ++--------
testcases/kernel/syscalls/tee/tee01.c | 9 ++-------
testcases/kernel/syscalls/vmsplice/vmsplice01.c | 6 +-----
3 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/testcases/kernel/crypto/af_alg08.c b/testcases/kernel/crypto/af_alg08.c
index 4f27f3c9da7cc277926c6fe3eee1a4649a483763..05f17eea4797b7575c97e194e34c0390c6d6be22 100644
--- a/testcases/kernel/crypto/af_alg08.c
+++ b/testcases/kernel/crypto/af_alg08.c
@@ -27,7 +27,6 @@
#include "tst_test.h"
#include "tst_af_alg.h"
#include "lapi/socket.h"
-#include "lapi/splice.h"
#define TESTFILE "copy_fail"
#define OVERWRITE_SIZE 4
@@ -92,13 +91,8 @@ static void try_corrupt(void)
SAFE_PIPE(pipefd);
- TEST(splice(file_fd, &off_in, pipefd[1], NULL, OVERWRITE_SIZE, 0));
- if (TST_RET < 0)
- tst_brk(TBROK | TTERRNO, "splice(file -> pipe)");
-
- TEST(splice(pipefd[0], NULL, reqfd, NULL, OVERWRITE_SIZE, 0));
- if (TST_RET < 0)
- tst_brk(TBROK | TTERRNO, "splice(pipe -> AF_ALG)");
+ SAFE_SPLICE(file_fd, &off_in, pipefd[1], NULL, OVERWRITE_SIZE, 0);
+ SAFE_SPLICE(pipefd[0], NULL, reqfd, NULL, OVERWRITE_SIZE, 0);
/* Expected to fail (invalid ciphertext); triggers the scratch write */
TST_EXP_FAIL_SILENT(recv(reqfd, recvbuf, sizeof(recvbuf), 0), EBADMSG);
diff --git a/testcases/kernel/syscalls/tee/tee01.c b/testcases/kernel/syscalls/tee/tee01.c
index d1489d0453f11faab41ab6e8e2dabbb372566f60..680793eb2b21cfd2609492d3be3bef10abb25acf 100644
--- a/testcases/kernel/syscalls/tee/tee01.c
+++ b/testcases/kernel/syscalls/tee/tee01.c
@@ -15,7 +15,6 @@
#include "tst_test.h"
#include "lapi/fcntl.h"
#include "lapi/tee.h"
-#include "lapi/splice.h"
#define TEST_BLOCK_SIZE 1024
@@ -58,17 +57,13 @@ static void tee_test(void)
SAFE_PIPE(pipe1);
SAFE_PIPE(pipe2);
- ret = splice(fd_in, NULL, pipe1[1], NULL, TEST_BLOCK_SIZE, 0);
- if (ret < 0)
- tst_brk(TBROK | TERRNO, "splice(fd_in, pipe1) failed");
+ SAFE_SPLICE(fd_in, NULL, pipe1[1], NULL, TEST_BLOCK_SIZE, 0);
ret = tee(pipe1[0], pipe2[1], TEST_BLOCK_SIZE, SPLICE_F_NONBLOCK);
if (ret < 0)
tst_brk(TBROK | TERRNO, "tee() failed");
- ret = splice(pipe2[0], NULL, fd_out, NULL, TEST_BLOCK_SIZE, 0);
- if (ret < 0)
- tst_brk(TBROK | TERRNO, "splice(pipe2, fd_out) failed");
+ SAFE_SPLICE(pipe2[0], NULL, fd_out, NULL, TEST_BLOCK_SIZE, 0);
SAFE_CLOSE(pipe2[0]);
SAFE_CLOSE(pipe2[1]);
diff --git a/testcases/kernel/syscalls/vmsplice/vmsplice01.c b/testcases/kernel/syscalls/vmsplice/vmsplice01.c
index 17486179baa2a897c2efbf0d2b4d39273788aadc..7b55e66a373d2d72824fbb9146b2af353a5ff1c9 100644
--- a/testcases/kernel/syscalls/vmsplice/vmsplice01.c
+++ b/testcases/kernel/syscalls/vmsplice/vmsplice01.c
@@ -15,7 +15,6 @@
#include "tst_test.h"
#include "lapi/fcntl.h"
-#include "lapi/splice.h"
#include "lapi/vmsplice.h"
#define TEST_BLOCK_SIZE (1<<17) /* 128K */
@@ -50,7 +49,6 @@ static void vmsplice_test(void)
{
int pipes[2];
long written;
- int ret;
int fd_out;
struct iovec v;
loff_t offset;
@@ -85,9 +83,7 @@ static void vmsplice_test(void)
}
}
- ret = splice(pipes[0], NULL, fd_out, &offset, written, 0);
- if (ret < 0)
- tst_brk(TBROK | TERRNO, "splice() failed");
+ SAFE_SPLICE(pipes[0], NULL, fd_out, &offset, written, 0);
//printf("offset = %lld\n", (long long)offset);
}
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH v2 1/2] lib: Add SAFE_SPLICE() macro
@ 2026-05-04 8:04 Andrea Cervesato
2026-05-04 9:28 ` [LTP] " linuxtestproject.agent
0 siblings, 1 reply; 5+ messages in thread
From: Andrea Cervesato @ 2026-05-04 8:04 UTC (permalink / raw)
To: Linux Test Project
From: Andrea Cervesato <andrea.cervesato@suse.com>
Add new SAFE_SPLIT() in lapi/splice.h.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/lapi/splice.h | 28 +++++++++++++++++++++++++
testcases/kernel/crypto/af_alg08.c | 10 ++-------
testcases/kernel/syscalls/tee/tee01.c | 9 ++------
testcases/kernel/syscalls/vmsplice/vmsplice01.c | 6 +-----
4 files changed, 33 insertions(+), 20 deletions(-)
diff --git a/include/lapi/splice.h b/include/lapi/splice.h
index 191b22d2d6397d1efad5e2025be5a2c4370724dc..e346e5cca9f44bd8421c6b99f84cd4646269ac1f 100644
--- a/include/lapi/splice.h
+++ b/include/lapi/splice.h
@@ -7,6 +7,13 @@
#ifndef LAPI_SPLICE_H__
#define LAPI_SPLICE_H__
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
+#include <fcntl.h>
+#include <sys/types.h>
+
#include "config.h"
#include "lapi/syscalls.h"
@@ -19,4 +26,25 @@ static inline ssize_t splice(int fd_in, loff_t *off_in, int fd_out,
}
#endif
+static inline ssize_t safe_splice(const char *file, const int lineno,
+ int fd_in, loff_t *off_in,
+ int fd_out, loff_t *off_out,
+ size_t len, unsigned int flags)
+{
+ ssize_t ret;
+
+ ret = splice(fd_in, off_in, fd_out, off_out, len, flags);
+
+ if (ret < 0) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "splice(%d, %d, %zu) failed", fd_in, fd_out, len);
+ }
+
+ return ret;
+}
+
+#define SAFE_SPLICE(fd_in, off_in, fd_out, off_out, len, flags) \
+ safe_splice(__FILE__, __LINE__, (fd_in), (off_in), (fd_out), \
+ (off_out), (len), (flags))
+
#endif /* LAPI_SPLICE_H__ */
diff --git a/testcases/kernel/crypto/af_alg08.c b/testcases/kernel/crypto/af_alg08.c
index 4f27f3c9da7cc277926c6fe3eee1a4649a483763..05f17eea4797b7575c97e194e34c0390c6d6be22 100644
--- a/testcases/kernel/crypto/af_alg08.c
+++ b/testcases/kernel/crypto/af_alg08.c
@@ -27,7 +27,6 @@
#include "tst_test.h"
#include "tst_af_alg.h"
#include "lapi/socket.h"
-#include "lapi/splice.h"
#define TESTFILE "copy_fail"
#define OVERWRITE_SIZE 4
@@ -92,13 +91,8 @@ static void try_corrupt(void)
SAFE_PIPE(pipefd);
- TEST(splice(file_fd, &off_in, pipefd[1], NULL, OVERWRITE_SIZE, 0));
- if (TST_RET < 0)
- tst_brk(TBROK | TTERRNO, "splice(file -> pipe)");
-
- TEST(splice(pipefd[0], NULL, reqfd, NULL, OVERWRITE_SIZE, 0));
- if (TST_RET < 0)
- tst_brk(TBROK | TTERRNO, "splice(pipe -> AF_ALG)");
+ SAFE_SPLICE(file_fd, &off_in, pipefd[1], NULL, OVERWRITE_SIZE, 0);
+ SAFE_SPLICE(pipefd[0], NULL, reqfd, NULL, OVERWRITE_SIZE, 0);
/* Expected to fail (invalid ciphertext); triggers the scratch write */
TST_EXP_FAIL_SILENT(recv(reqfd, recvbuf, sizeof(recvbuf), 0), EBADMSG);
diff --git a/testcases/kernel/syscalls/tee/tee01.c b/testcases/kernel/syscalls/tee/tee01.c
index d1489d0453f11faab41ab6e8e2dabbb372566f60..680793eb2b21cfd2609492d3be3bef10abb25acf 100644
--- a/testcases/kernel/syscalls/tee/tee01.c
+++ b/testcases/kernel/syscalls/tee/tee01.c
@@ -15,7 +15,6 @@
#include "tst_test.h"
#include "lapi/fcntl.h"
#include "lapi/tee.h"
-#include "lapi/splice.h"
#define TEST_BLOCK_SIZE 1024
@@ -58,17 +57,13 @@ static void tee_test(void)
SAFE_PIPE(pipe1);
SAFE_PIPE(pipe2);
- ret = splice(fd_in, NULL, pipe1[1], NULL, TEST_BLOCK_SIZE, 0);
- if (ret < 0)
- tst_brk(TBROK | TERRNO, "splice(fd_in, pipe1) failed");
+ SAFE_SPLICE(fd_in, NULL, pipe1[1], NULL, TEST_BLOCK_SIZE, 0);
ret = tee(pipe1[0], pipe2[1], TEST_BLOCK_SIZE, SPLICE_F_NONBLOCK);
if (ret < 0)
tst_brk(TBROK | TERRNO, "tee() failed");
- ret = splice(pipe2[0], NULL, fd_out, NULL, TEST_BLOCK_SIZE, 0);
- if (ret < 0)
- tst_brk(TBROK | TERRNO, "splice(pipe2, fd_out) failed");
+ SAFE_SPLICE(pipe2[0], NULL, fd_out, NULL, TEST_BLOCK_SIZE, 0);
SAFE_CLOSE(pipe2[0]);
SAFE_CLOSE(pipe2[1]);
diff --git a/testcases/kernel/syscalls/vmsplice/vmsplice01.c b/testcases/kernel/syscalls/vmsplice/vmsplice01.c
index 17486179baa2a897c2efbf0d2b4d39273788aadc..7b55e66a373d2d72824fbb9146b2af353a5ff1c9 100644
--- a/testcases/kernel/syscalls/vmsplice/vmsplice01.c
+++ b/testcases/kernel/syscalls/vmsplice/vmsplice01.c
@@ -15,7 +15,6 @@
#include "tst_test.h"
#include "lapi/fcntl.h"
-#include "lapi/splice.h"
#include "lapi/vmsplice.h"
#define TEST_BLOCK_SIZE (1<<17) /* 128K */
@@ -50,7 +49,6 @@ static void vmsplice_test(void)
{
int pipes[2];
long written;
- int ret;
int fd_out;
struct iovec v;
loff_t offset;
@@ -85,9 +83,7 @@ static void vmsplice_test(void)
}
}
- ret = splice(pipes[0], NULL, fd_out, &offset, written, 0);
- if (ret < 0)
- tst_brk(TBROK | TERRNO, "splice() failed");
+ SAFE_SPLICE(pipes[0], NULL, fd_out, &offset, written, 0);
//printf("offset = %lld\n", (long long)offset);
}
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [LTP] lib: Add SAFE_SPLICE() macro
2026-05-04 8:04 [LTP] [PATCH v2 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
@ 2026-05-04 9:28 ` linuxtestproject.agent
0 siblings, 0 replies; 5+ messages in thread
From: linuxtestproject.agent @ 2026-05-04 9:28 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
--- [PATCH 1/2] ---
On Mon, 4 May 2026, Andrea Cervesato wrote:
> lib: Add SAFE_SPLICE() macro
>
> Add new SAFE_SPLIT() in lapi/splice.h.
"SAFE_SPLIT()" -> "SAFE_SPLICE()".
> -#include "lapi/splice.h"
> ...
> + SAFE_SPLICE(file_fd, &off_in, pipefd[1], NULL, OVERWRITE_SIZE, 0);
After this commit, SAFE_SPLICE() is called in af_alg08.c, tee01.c, and
vmsplice01.c but all three no longer include <lapi/splice.h> — the tree
does not compile. The include removal and the SAFE_SPLICE() conversion
must not be split across commits.
This patch also mixes "add library macro" with "convert test files";
split them: patch 1 touches only lapi/splice.h, patch 2 adds the
include and converts the splice() calls in all three test files.
--- [PATCH 2/2] ---
On Mon, 4 May 2026, Andrea Cervesato wrote:
> tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
>
> Replace raw splice() calls with SAFE_SPLICE() in tests where splice is
> utility plumbing, not the subject of testing.
This patch only adds three "#include lapi/splice.h" lines; the actual
splice()-to-SAFE_SPLICE() conversion is in patch 1/2. Subject and body
must describe what this patch actually does, or better: restructure
the series so the conversion and its include live in the same commit.
---
Note:
Our agent completed the review of the patch.
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
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-05-04 9:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-30 17:25 [LTP] [PATCH 0/2] Introduce SAFE_SPLICE() Andrea Cervesato
2026-04-30 17:25 ` [LTP] [PATCH 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
2026-04-30 19:29 ` [LTP] " linuxtestproject.agent
2026-04-30 17:25 ` [LTP] [PATCH 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE() Andrea Cervesato
-- strict thread matches above, loose matches on Subject: below --
2026-05-04 8:04 [LTP] [PATCH v2 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
2026-05-04 9:28 ` [LTP] " linuxtestproject.agent
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox