[PATCH net-next v2] selftests: tls: use mkstemp instead of open(O_TMPFILE)

Geliang Tang posted 1 patch 1 week, 3 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/multipath-tcp/mptcp_net-next tags/patchew/2fa14a04f5287c956a1112cef8cdfb2c86931d2d.1768467496.git.tanggeliang@kylinos.cn
tools/testing/selftests/net/tls.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
[PATCH net-next v2] selftests: tls: use mkstemp instead of open(O_TMPFILE)
Posted by Geliang Tang 1 week, 3 days ago
From: Gang Yan <yangang@kylinos.cn>

When running TLS tests in a virtual machine/container environment, they
fail in test_mutliproc():

 # tls.c:1479:mutliproc_even: Expected fd (-1) >= 0 (0)
 # mutliproc_even: Test terminated by assertion
 #          FAIL  tls.12_aes_gcm.mutliproc_even
 not ok 59 tls.12_aes_gcm.mutliproc_even
 #  RUN           tls.12_aes_gcm.mutliproc_readers ...
 # tls.c:1479:mutliproc_readers: Expected fd (-1) >= 0 (0)
 # mutliproc_readers: Test terminated by assertion
 #          FAIL  tls.12_aes_gcm.mutliproc_readers
 not ok 60 tls.12_aes_gcm.mutliproc_readers
 #  RUN           tls.12_aes_gcm.mutliproc_writers ...
 # tls.c:1479:mutliproc_writers: Expected fd (-1) >= 0 (0)
 # mutliproc_writers: Test terminated by assertion
 #          FAIL  tls.12_aes_gcm.mutliproc_writers
 not ok 61 tls.12_aes_gcm.mutliproc_writers

This is because the /tmp directory uses the virtiofs filesystem, which does
not support the O_TMPFILE feature.

This patch uses mkstemp() to create temporary files, just like the approach
used in chunked_sendfile(), thereby eliminating the dependency on the
O_TMPFILE feature.

For better code reuse, factor out this code from chunked_sendfile() into a
separate helper create_temp_file(). Use this new heler in test_mutliproc()
and closes the file descriptor (fd) after the test ends.

Co-developed-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Geliang Tang <geliang@kernel.org>
Signed-off-by: Gang Yan <yangang@kylinos.cn>
---
v2:
 - factor out a new helper, use it in both chunked_sendfile() and
   test_mutliproc().
---
 tools/testing/selftests/net/tls.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/net/tls.c b/tools/testing/selftests/net/tls.c
index 9e2ccea13d70..2eaacb7f2e56 100644
--- a/tools/testing/selftests/net/tls.c
+++ b/tools/testing/selftests/net/tls.c
@@ -467,6 +467,15 @@ TEST_F(tls, send_then_sendfile)
 	close(filefd);
 }
 
+static int create_temp_file(void)
+{
+	char filename[] = "/tmp/mytemp.XXXXXX";
+	int fd = mkstemp(filename);
+
+	unlink(filename);
+	return fd;
+}
+
 static void chunked_sendfile(struct __test_metadata *_metadata,
 			     struct _test_data_tls *self,
 			     uint16_t chunk_size,
@@ -476,11 +485,9 @@ static void chunked_sendfile(struct __test_metadata *_metadata,
 	uint16_t test_payload_size;
 	int size = 0;
 	int ret;
-	char filename[] = "/tmp/mytemp.XXXXXX";
-	int fd = mkstemp(filename);
+	int fd = create_temp_file();
 	off_t offset = 0;
 
-	unlink(filename);
 	ASSERT_GE(fd, 0);
 	EXPECT_GE(chunk_size, 1);
 	test_payload_size = chunk_size + extra_payload_size;
@@ -1469,7 +1476,7 @@ test_mutliproc(struct __test_metadata *_metadata, struct _test_data_tls *self,
 	write_bias = n_readers / n_writers ?: 1;
 
 	/* prep a file to send */
-	fd = open("/tmp/", O_TMPFILE | O_RDWR, 0600);
+	fd = create_temp_file();
 	ASSERT_GE(fd, 0);
 
 	memset(buf, 0xac, file_sz);
@@ -1527,6 +1534,7 @@ test_mutliproc(struct __test_metadata *_metadata, struct _test_data_tls *self,
 			left -= res;
 		}
 	}
+	close(fd);
 }
 
 TEST_F(tls, mutliproc_even)
-- 
2.51.0
Re: [PATCH net-next v2] selftests: tls: use mkstemp instead of open(O_TMPFILE)
Posted by Jakub Kicinski 1 week, 2 days ago
On Thu, 15 Jan 2026 17:02:40 +0800 Geliang Tang wrote:
> This is because the /tmp directory uses the virtiofs filesystem, which does
> not support the O_TMPFILE feature.

I don't think selftests are expected to support setups where /tmp 
isn't tmp. Please fix your setup instead (or explain why it's very
crucial that you don't). The upstream CI runs all the selftests in
VMs and they are working just fine.
-- 
pw-bot: reject
Re: [PATCH net-next v2] selftests: tls: use mkstemp instead of open(O_TMPFILE)
Posted by Geliang Tang 6 days, 16 hours ago
Hi Jakub, Matt,

On Thu, 2026-01-15 at 18:49 -0800, Jakub Kicinski wrote:
> On Thu, 15 Jan 2026 17:02:40 +0800 Geliang Tang wrote:
> > This is because the /tmp directory uses the virtiofs filesystem,
> > which does
> > not support the O_TMPFILE feature.
> 
> I don't think selftests are expected to support setups where /tmp 
> isn't tmp. Please fix your setup instead (or explain why it's very

Thanks for reviewing. I recently implemented TLS support for MPTCP and
have been adding MPTCP test items to the TLS selftests. When running
these in the MPTCP upstream CI (mptcp-upstream-virtme-docker), these
O_TMPFILE unsupported errors occurred.

Following your suggestion, I looked into the mptcp-upstream-virtme-
docker configuration and found that /tmp isn't mounted as tmpfs; it's
just a plain directory. I've opened a PR to address this:

virtme: mount /tmp as overlay for O_TMPFILE support

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker/pull/43

@Matt

This change adds "--overlay-rwdir /tmp" to virtme-run options, ensuring
/tmp gets mounted as an overlay filesystem. It functions correctly,
though I'm not certain it's the ideal solution.

Thanks,
-Geliang

> crucial that you don't). The upstream CI runs all the selftests in
> VMs and they are working just fine.
Re: [PATCH net-next v2] selftests: tls: use mkstemp instead of open(O_TMPFILE)
Posted by MPTCP CI 1 week, 3 days ago
Hi Gang,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_add_addr 🔴
- KVM Validation: normal (only selftest_mptcp_join): Success! ✅
- KVM Validation: debug (except selftest_mptcp_join): Unstable: 1 failed test(s): packetdrill_add_addr 🔴
- KVM Validation: debug (only selftest_mptcp_join): Success! ✅
- KVM Validation: btf-normal (only bpftest_all): Critical: 5 Call Trace(s) - Critical: Global Timeout ❌
- KVM Validation: btf-debug (only bpftest_all): Success! ✅
- Task: https://github.com/multipath-tcp/mptcp_net-next/actions/runs/21026154890

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/4a8b2ed1da3d
Patchwork: https://patchwork.kernel.org/project/mptcp/list/?series=1042708


If there are some issues, you can reproduce them using the same environment as
the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-normal

For more details:

    https://github.com/multipath-tcp/mptcp-upstream-virtme-docker


Please note that despite all the efforts that have been already done to have a
stable tests suite when executed on a public CI like here, it is possible some
reported issues are not due to your modifications. Still, do not hesitate to
help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (NGI0 Core)