* [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE()
@ 2026-05-04 9:50 Andrea Cervesato
2026-05-04 9:51 ` [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Andrea Cervesato @ 2026-05-04 9:50 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>
---
Changes in v3:
- fix commit add correct imports
- Link to v2: https://lore.kernel.org/r/20260504-safe_splice-v2-0-aa7eaa6b5ed7@suse.com
Changes in v2:
- fix compile issues by moving SAFE_SPLICE in lapi/splice.h
- Link to v1: https://lore.kernel.org/r/20260430-safe_splice-v1-0-d1d919ff2a3a@suse.com
---
Andrea Cervesato (2):
lib: Add SAFE_SPLICE() macro
tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
include/lapi/splice.h | 28 +++++++++++++++++++++++++
testcases/kernel/crypto/af_alg08.c | 9 ++------
testcases/kernel/syscalls/tee/tee01.c | 8 ++-----
testcases/kernel/syscalls/vmsplice/vmsplice01.c | 5 +----
4 files changed, 33 insertions(+), 17 deletions(-)
---
base-commit: 73cfad509db014e5a631bd2298f4e9d8ea3ee1c1
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] 7+ messages in thread
* [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro
2026-05-04 9:50 [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE() Andrea Cervesato
@ 2026-05-04 9:51 ` Andrea Cervesato
2026-05-04 11:17 ` Cyril Hrubis
2026-05-04 9:51 ` [LTP] [PATCH v3 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE() Andrea Cervesato
2026-05-04 11:33 ` [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE() Andrea Cervesato via ltp
2 siblings, 1 reply; 7+ messages in thread
From: Andrea Cervesato @ 2026-05-04 9:51 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 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
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__ */
--
2.51.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [LTP] [PATCH v3 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
2026-05-04 9:50 [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE() Andrea Cervesato
2026-05-04 9:51 ` [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
@ 2026-05-04 9:51 ` Andrea Cervesato
2026-05-04 11:23 ` Cyril Hrubis
2026-05-04 11:33 ` [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE() Andrea Cervesato via ltp
2 siblings, 1 reply; 7+ messages in thread
From: Andrea Cervesato @ 2026-05-04 9:51 UTC (permalink / raw)
To: Linux Test Project
From: Andrea Cervesato <andrea.cervesato@suse.com>
Replace raw splice() calls with SAFE_SPLICE() in tests where splice is
utility plumbing, not the subject of testing.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/crypto/af_alg08.c | 9 ++-------
testcases/kernel/syscalls/tee/tee01.c | 8 ++------
testcases/kernel/syscalls/vmsplice/vmsplice01.c | 5 +----
3 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/testcases/kernel/crypto/af_alg08.c b/testcases/kernel/crypto/af_alg08.c
index 7b95984448bdc5afd3b995a98c3d81ef12e37067..5e04b579c1db464fc5b4f33fd4e13a29709bba79 100644
--- a/testcases/kernel/crypto/af_alg08.c
+++ b/testcases/kernel/crypto/af_alg08.c
@@ -96,13 +96,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..436c52a201689e4ffa97f217fd3b1d14e6b6ec36 100644
--- a/testcases/kernel/syscalls/tee/tee01.c
+++ b/testcases/kernel/syscalls/tee/tee01.c
@@ -58,17 +58,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..64eed8391797fb01b14c548ebcfe390a403da5ec 100644
--- a/testcases/kernel/syscalls/vmsplice/vmsplice01.c
+++ b/testcases/kernel/syscalls/vmsplice/vmsplice01.c
@@ -50,7 +50,6 @@ static void vmsplice_test(void)
{
int pipes[2];
long written;
- int ret;
int fd_out;
struct iovec v;
loff_t offset;
@@ -85,9 +84,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] 7+ messages in thread
* Re: [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro
2026-05-04 9:51 ` [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
@ 2026-05-04 11:17 ` Cyril Hrubis
2026-05-04 11:28 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2026-05-04 11:17 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: Linux Test Project
Hi!
> Add new SAFE_SPLIT() in lapi/splice.h.
>
> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
> ---
> include/lapi/splice.h | 28 ++++++++++++++++++++++++++++
> 1 file changed, 28 insertions(+)
>
> 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);
Why don't we print the offsets?
Otherwise:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
> + }
> +
> + 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__ */
>
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v3 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE()
2026-05-04 9:51 ` [LTP] [PATCH v3 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE() Andrea Cervesato
@ 2026-05-04 11:23 ` Cyril Hrubis
0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2026-05-04 11:23 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: Linux Test Project
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro
2026-05-04 11:17 ` Cyril Hrubis
@ 2026-05-04 11:28 ` Andrea Cervesato via ltp
0 siblings, 0 replies; 7+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-04 11:28 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: Linux Test Project
> Why don't we print the offsets?
will fix before merge. thanks
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE()
2026-05-04 9:50 [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE() Andrea Cervesato
2026-05-04 9:51 ` [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
2026-05-04 9:51 ` [LTP] [PATCH v3 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE() Andrea Cervesato
@ 2026-05-04 11:33 ` Andrea Cervesato via ltp
2 siblings, 0 replies; 7+ messages in thread
From: Andrea Cervesato via ltp @ 2026-05-04 11:33 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: Linux Test Project
Merged, Thanks!
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-05-04 11:33 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-04 9:50 [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE() Andrea Cervesato
2026-05-04 9:51 ` [LTP] [PATCH v3 1/2] lib: Add SAFE_SPLICE() macro Andrea Cervesato
2026-05-04 11:17 ` Cyril Hrubis
2026-05-04 11:28 ` Andrea Cervesato via ltp
2026-05-04 9:51 ` [LTP] [PATCH v3 2/2] tee01, vmsplice01, af_alg08: Use SAFE_SPLICE() Andrea Cervesato
2026-05-04 11:23 ` Cyril Hrubis
2026-05-04 11:33 ` [LTP] [PATCH v3 0/2] Introduce SAFE_SPLICE() Andrea Cervesato via ltp
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox