patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH 1/2] eal: fix failure race and behavior of thread create
@ 2023-03-02 18:44 Tyler Retzlaff
  2023-03-02 18:44 ` [PATCH 2/2] eal/windows: fix create thread failure behavior Tyler Retzlaff
                   ` (7 more replies)
  0 siblings, 8 replies; 22+ messages in thread
From: Tyler Retzlaff @ 2023-03-02 18:44 UTC (permalink / raw)
  To: dev; +Cc: david.marchand, Tyler Retzlaff, stable

In rte_thread_create setting affinity after pthread_create may fail.
Such a failure should result in the entire rte_thread_create failing
but doesn't.

Additionally if there is a failure to set affinity a race exists where
the creating thread will free ctx and depending on scheduling of the new
thread it may also free ctx (double free).

Resolve both of the above issues by using the pthread_setaffinity_np
prior to thread creation to set the affinity of the created thread. By
doing this no failure paths exist after pthread_create returns
successfully.

Fixes: ce6e911d20f6 ("eal: add thread lifetime API")
Cc: stable@dpdk.org
Cc: roretzla@linux.microsoft.com

Signed-off-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 lib/eal/unix/rte_thread.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/lib/eal/unix/rte_thread.c b/lib/eal/unix/rte_thread.c
index 37ebfcf..5bf633b 100644
--- a/lib/eal/unix/rte_thread.c
+++ b/lib/eal/unix/rte_thread.c
@@ -155,6 +155,17 @@ struct thread_routine_ctx {
 			RTE_LOG(DEBUG, EAL, "pthread_attr_setschedparam failed\n");
 			goto cleanup;
 		}
+
+		if (CPU_COUNT(&thread_attr->cpuset) > 0) {
+			ret = pthread_attr_setaffinity_np(attrp,
+				sizeof(thread_attr->cpuset),
+				&thread_attr->cpuset);
+			if (ret != 0) {
+				RTE_LOG(DEBUG, EAL,
+					"pthread_attr_setaffinity_np failed\n");
+				goto cleanup;
+			}
+		}
 	}
 
 	ret = pthread_create((pthread_t *)&thread_id->opaque_id, attrp,
@@ -164,15 +175,6 @@ struct thread_routine_ctx {
 		goto cleanup;
 	}
 
-	if (thread_attr != NULL && CPU_COUNT(&thread_attr->cpuset) > 0) {
-		ret = rte_thread_set_affinity_by_id(*thread_id,
-			&thread_attr->cpuset);
-		if (ret != 0) {
-			RTE_LOG(DEBUG, EAL, "rte_thread_set_affinity_by_id failed\n");
-			goto cleanup;
-		}
-	}
-
 	ctx = NULL;
 cleanup:
 	free(ctx);
-- 
1.8.3.1


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

end of thread, other threads:[~2023-03-18 18:26 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-02 18:44 [PATCH 1/2] eal: fix failure race and behavior of thread create Tyler Retzlaff
2023-03-02 18:44 ` [PATCH 2/2] eal/windows: fix create thread failure behavior Tyler Retzlaff
2023-03-07 14:33 ` [PATCH 1/2] eal: fix failure race and behavior of thread create David Marchand
2023-03-09  9:17   ` David Marchand
2023-03-09  9:58     ` Thomas Monjalon
2023-03-09 20:49       ` Tyler Retzlaff
2023-03-09 21:05         ` David Marchand
     [not found] ` <1678750267-3829-1-git-send-email-roretzla@linux.microsoft.com>
2023-03-13 23:31   ` [PATCH v2 2/2] eal: fix failure path race setting new thread affinity Tyler Retzlaff
     [not found] ` <1678833856-9314-1-git-send-email-roretzla@linux.microsoft.com>
2023-03-14 22:44   ` [PATCH v3 " Tyler Retzlaff
     [not found] ` <1678834239-11569-1-git-send-email-roretzla@linux.microsoft.com>
2023-03-14 22:50   ` [PATCH v4 " Tyler Retzlaff
2023-03-15  1:20     ` Stephen Hemminger
2023-03-15  1:26       ` Tyler Retzlaff
     [not found] ` <1678925050-1955-1-git-send-email-roretzla@linux.microsoft.com>
2023-03-16  0:04   ` Tyler Retzlaff
     [not found] ` <1678925224-2706-1-git-send-email-roretzla@linux.microsoft.com>
2023-03-16  0:07   ` [PATCH v5 " Tyler Retzlaff
2023-03-17 10:45     ` David Marchand
2023-03-17 14:49       ` Tyler Retzlaff
2023-03-17 18:51         ` David Marchand
2023-03-17 21:20           ` Tyler Retzlaff
2023-03-17 18:52 ` [PATCH v6] eal/unix: fix thread creation David Marchand
2023-03-17 21:24   ` Tyler Retzlaff
2023-03-18 18:26     ` David Marchand
2023-03-18 18:26   ` David Marchand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).