All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] netstress: explicitly set a thread stack size
@ 2020-11-25 13:06 j.nixdorf
  2020-11-26 14:05 ` Alexey Kodanev
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: j.nixdorf @ 2020-11-25 13:06 UTC (permalink / raw)
  To: ltp

Musl libc uses a relatively small thread stack size (128k [1]). This
gets used up on 2 local buffers sized max_msg_len (64k by default),
which causes a segfault due to a stack overflow in the error reporting
path.

Set the stack size to 128kB + 2*max_msg_len instead, which is enough for
both buffers with an additional allowance for the remaining stack usage
by netstress and called libc or ltp helper functions.

[1]: https://wiki.musl-libc.org/functional-differences-from-glibc.html#Thread_stack_size

Signed-off-by: Johannes Nixdorf <j.nixdorf@avm.de>
---
 testcases/network/netstress/netstress.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/testcases/network/netstress/netstress.c b/testcases/network/netstress/netstress.c
index e79e64220..bcd3cd049 100644
--- a/testcases/network/netstress/netstress.c
+++ b/testcases/network/netstress/netstress.c
@@ -480,7 +480,7 @@ static void client_init(void)
 	clock_gettime(CLOCK_MONOTONIC_RAW, &tv_client_start);
 	intptr_t i;
 	for (i = 0; i < clients_num; ++i)
-		SAFE_PTHREAD_CREATE(&thread_ids[i], 0, client_fn, (void *)i);
+		SAFE_PTHREAD_CREATE(&thread_ids[i], &attr, client_fn, (void *)i);
 }
 
 static void client_run(void)
@@ -747,8 +747,6 @@ static void server_run(void)
 	struct sockaddr_in6 addr6;
 	socklen_t addr_size = sizeof(addr6);
 
-	pthread_attr_init(&attr);
-
 	/*
 	 * detaching threads allow to reclaim thread's resources
 	 * once a thread finishes its work.
@@ -980,6 +978,14 @@ static void setup(void)
 	break;
 	}
 
+	errno = pthread_attr_init(&attr);
+	if (errno != 0)
+		tst_brk(TBROK | TERRNO, "pthread_attr_init failed");
+
+	errno = pthread_attr_setstacksize(&attr, 128*1024 + 2*max_msg_len);
+	if (errno != 0)
+		tst_brk(TBROK | TERRNO, "pthread_attr_setstacksize failed");
+
 	net.init();
 }
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-12-01 12:01 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25 13:06 [LTP] [PATCH] netstress: explicitly set a thread stack size j.nixdorf
2020-11-26 14:05 ` Alexey Kodanev
2020-11-26 14:52 ` j.nixdorf
2020-11-26 15:03   ` Cyril Hrubis
2020-11-27  9:15     ` Alexey Kodanev
2020-11-27 11:28       ` Cyril Hrubis
2020-11-27  8:54   ` Alexey Kodanev
2020-11-27 10:58   ` j.nixdorf
2020-11-27 11:38 ` [LTP] [PATCH v2] " j.nixdorf
2020-12-01 12:01   ` Alexey Kodanev

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.