patches for DPDK stable branches
 help / color / mirror / Atom feed
From: christian.ehrhardt@canonical.com
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: Anatoly Burakov <anatoly.burakov@intel.com>,
	Chengwen Feng <fengchengwen@huawei.com>,
	dpdk stable <stable@dpdk.org>
Subject: patch 'eal: fix data race in multi-process support' has been queued to stable release 19.11.14
Date: Fri, 11 Nov 2022 12:38:52 +0100	[thread overview]
Message-ID: <20221111113904.1549618-35-christian.ehrhardt@canonical.com> (raw)
In-Reply-To: <20221111113904.1549618-1-christian.ehrhardt@canonical.com>

Hi,

FYI, your patch has been queued to stable release 19.11.14

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 11/18/22. So please
shout if anyone has objections.

Also note that after the patch there's a diff of the upstream commit vs the
patch applied to the branch. This will indicate if there was any rebasing
needed to apply to the stable branch. If there were code changes for rebasing
(ie: not only metadata diffs), please double check that the rebase was
correctly done.

Queued patches are on a temporary branch at:
https://github.com/cpaelzer/dpdk-stable-queue

This queued commit can be viewed at:
https://github.com/cpaelzer/dpdk-stable-queue/commit/910171a808f8c5d2e709b5aa2aaba09179a85265

Thanks.

Christian Ehrhardt <christian.ehrhardt@canonical.com>

---
From 910171a808f8c5d2e709b5aa2aaba09179a85265 Mon Sep 17 00:00:00 2001
From: Stephen Hemminger <stephen@networkplumber.org>
Date: Tue, 6 Sep 2022 09:45:22 -0700
Subject: [PATCH] eal: fix data race in multi-process support

[ upstream commit 668958f3c1617f18e04ffee099656e7fb2effa94 ]

If DPDK is built with thread sanitizer it reports a race
in setting of multiprocess file descriptor. The fix is to
use atomic operations when updating mp_fd.

Build:
$ meson -Db_sanitize=address build
$ ninja -C build

Simple example:
$ .build/app/dpdk-testpmd -l 1-3 --no-huge
EAL: Detected CPU lcores: 16
EAL: Detected NUMA nodes: 1
EAL: Static memory layout is selected, amount of reserved memory can be adjusted with -m or --socket-mem
EAL: Detected static linkage of DPDK
EAL: Multi-process socket /run/user/1000/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'VA'
testpmd: No probed ethernet devices
testpmd: create a new mbuf pool <mb_pool_0>: n=163456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
EAL: Error - exiting with code: 1
  Cause: Creation of mbuf pool for socket 0 failed: Cannot allocate memory
==================
WARNING: ThreadSanitizer: data race (pid=87245)
  Write of size 4 at 0x558e04d8ff70 by main thread:
    #0 rte_mp_channel_cleanup <null> (dpdk-testpmd+0x1e7d30c)
    #1 rte_eal_cleanup <null> (dpdk-testpmd+0x1e85929)
    #2 rte_exit <null> (dpdk-testpmd+0x1e5bc0a)
    #3 mbuf_pool_create.cold <null> (dpdk-testpmd+0x274011)
    #4 main <null> (dpdk-testpmd+0x5cc15d)

  Previous read of size 4 at 0x558e04d8ff70 by thread T2:
    #0 mp_handle <null> (dpdk-testpmd+0x1e7c439)
    #1 ctrl_thread_init <null> (dpdk-testpmd+0x1e6ee1e)

  As if synchronized via sleep:
    #0 nanosleep libsanitizer/tsan/tsan_interceptors_posix.cpp:366
    #1 get_tsc_freq <null> (dpdk-testpmd+0x1e92ff9)
    #2 set_tsc_freq <null> (dpdk-testpmd+0x1e6f2fc)
    #3 rte_eal_timer_init <null> (dpdk-testpmd+0x1e931a4)
    #4 rte_eal_init.cold <null> (dpdk-testpmd+0x29e578)
    #5 main <null> (dpdk-testpmd+0x5cbc45)

  Location is global 'mp_fd' of size 4 at 0x558e04d8ff70 (dpdk-testpmd+0x000003122f70)

  Thread T2 'rte_mp_handle' (tid=87248, running) created by main thread at:
    #0 pthread_create libsanitizer/tsan/tsan_interceptors_posix.cpp:969
    #1 rte_ctrl_thread_create <null> (dpdk-testpmd+0x1e6efd0)
    #2 rte_mp_channel_init.cold <null> (dpdk-testpmd+0x29cb7c)
    #3 rte_eal_init <null> (dpdk-testpmd+0x1e8662e)
    #4 main <null> (dpdk-testpmd+0x5cbc45)

SUMMARY: ThreadSanitizer: data race (app/dpdk-testpmd+0x1e7d30c) in rte_mp_channel_cleanup
==================
ThreadSanitizer: reported 1 warnings

Fixes: bacaa2754017 ("eal: add channel for multi-process communication")

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
Reviewed-by: Chengwen Feng <fengchengwen@huawei.com>
---
 lib/librte_eal/common/eal_common_proc.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
index d88a1ebafb..a98d67101d 100644
--- a/lib/librte_eal/common/eal_common_proc.c
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -257,7 +257,7 @@ rte_mp_action_unregister(const char *name)
 }
 
 static int
-read_msg(struct mp_msg_internal *m, struct sockaddr_un *s)
+read_msg(int fd, struct mp_msg_internal *m, struct sockaddr_un *s)
 {
 	int msglen;
 	struct iovec iov;
@@ -278,7 +278,7 @@ read_msg(struct mp_msg_internal *m, struct sockaddr_un *s)
 	msgh.msg_controllen = sizeof(control);
 
 retry:
-	msglen = recvmsg(mp_fd, &msgh, 0);
+	msglen = recvmsg(fd, &msgh, 0);
 
 	/* zero length message means socket was closed */
 	if (msglen == 0)
@@ -385,11 +385,12 @@ mp_handle(void *arg __rte_unused)
 {
 	struct mp_msg_internal msg;
 	struct sockaddr_un sa;
+	int fd;
 
-	while (mp_fd >= 0) {
+	while ((fd = __atomic_load_n(&mp_fd, __ATOMIC_RELAXED)) >= 0) {
 		int ret;
 
-		ret = read_msg(&msg, &sa);
+		ret = read_msg(fd, &msg, &sa);
 		if (ret <= 0)
 			break;
 
@@ -631,9 +632,8 @@ rte_mp_channel_init(void)
 			NULL, mp_handle, NULL) < 0) {
 		RTE_LOG(ERR, EAL, "failed to create mp thread: %s\n",
 			strerror(errno));
-		close(mp_fd);
 		close(dir_fd);
-		mp_fd = -1;
+		close(__atomic_exchange_n(&mp_fd, -1, __ATOMIC_RELAXED));
 		return -1;
 	}
 
@@ -649,11 +649,10 @@ rte_mp_channel_cleanup(void)
 {
 	int fd;
 
-	if (mp_fd < 0)
+	fd = __atomic_exchange_n(&mp_fd, -1, __ATOMIC_RELAXED);
+	if (fd < 0)
 		return;
 
-	fd = mp_fd;
-	mp_fd = -1;
 	pthread_cancel(mp_handle_tid);
 	pthread_join(mp_handle_tid, NULL);
 	close_socket_fd(fd);
-- 
2.38.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2022-11-11 12:35:06.020999734 +0100
+++ 0035-eal-fix-data-race-in-multi-process-support.patch	2022-11-11 12:35:04.793192173 +0100
@@ -1 +1 @@
-From 668958f3c1617f18e04ffee099656e7fb2effa94 Mon Sep 17 00:00:00 2001
+From 910171a808f8c5d2e709b5aa2aaba09179a85265 Mon Sep 17 00:00:00 2001
@@ -5,0 +6,2 @@
+[ upstream commit 668958f3c1617f18e04ffee099656e7fb2effa94 ]
+
@@ -62 +63,0 @@
-Cc: stable@dpdk.org
@@ -68 +69 @@
- lib/eal/common/eal_common_proc.c | 17 ++++++++---------
+ lib/librte_eal/common/eal_common_proc.c | 17 ++++++++---------
@@ -71,5 +72,5 @@
-diff --git a/lib/eal/common/eal_common_proc.c b/lib/eal/common/eal_common_proc.c
-index 313060528f..1fc1d6c53b 100644
---- a/lib/eal/common/eal_common_proc.c
-+++ b/lib/eal/common/eal_common_proc.c
-@@ -260,7 +260,7 @@ rte_mp_action_unregister(const char *name)
+diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
+index d88a1ebafb..a98d67101d 100644
+--- a/lib/librte_eal/common/eal_common_proc.c
++++ b/lib/librte_eal/common/eal_common_proc.c
+@@ -257,7 +257,7 @@ rte_mp_action_unregister(const char *name)
@@ -84 +85 @@
-@@ -281,7 +281,7 @@ read_msg(struct mp_msg_internal *m, struct sockaddr_un *s)
+@@ -278,7 +278,7 @@ read_msg(struct mp_msg_internal *m, struct sockaddr_un *s)
@@ -93 +94 @@
-@@ -390,11 +390,12 @@ mp_handle(void *arg __rte_unused)
+@@ -385,11 +385,12 @@ mp_handle(void *arg __rte_unused)
@@ -108 +109 @@
-@@ -638,9 +639,8 @@ rte_mp_channel_init(void)
+@@ -631,9 +632,8 @@ rte_mp_channel_init(void)
@@ -119 +120 @@
-@@ -656,11 +656,10 @@ rte_mp_channel_cleanup(void)
+@@ -649,11 +649,10 @@ rte_mp_channel_cleanup(void)

  parent reply	other threads:[~2022-11-11 11:41 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11 11:38 patch 'vhost: fix virtqueue use after free on NUMA reallocation' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net: accept unaligned data in checksum routines' " christian.ehrhardt
2022-11-11 11:38 ` patch 'app/testpmd: restore ixgbe bypass commands' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/bonding: fix array overflow in Rx burst' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/bonding: fix double slave link status query' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/nfp: improve HW info header log readability' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/mvneta: fix build with GCC 12' " christian.ehrhardt
2022-11-11 11:38 ` patch 'malloc: fix storage size for some allocations' " christian.ehrhardt
2022-11-11 11:38 ` patch 'event/sw: fix device name in dump' " christian.ehrhardt
2022-11-11 11:38 ` patch 'eventdev/eth_tx: add spinlock for adapter start/stop' " christian.ehrhardt
2022-11-11 11:38 ` patch 'eventdev/eth_tx: fix adapter stop' " christian.ehrhardt
2022-11-11 11:38 ` patch 'test/ipsec: skip if no compatible device' " christian.ehrhardt
2022-11-11 11:38 ` patch 'test/crypto: fix debug messages' " christian.ehrhardt
2022-11-11 11:38 ` patch 'test/ipsec: fix build with GCC 12' " christian.ehrhardt
2022-11-11 11:38 ` patch 'ipsec: " christian.ehrhardt
2022-11-11 11:38 ` patch 'crypto/qat: " christian.ehrhardt
2022-11-11 11:38 ` patch 'eventdev: fix name of Rx conf type in documentation' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/i40e: fix VF representor release' " christian.ehrhardt
2022-11-11 11:38 ` patch 'common/iavf: avoid copy in async mode' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/ice/base: fix media type of PHY 10G SFI C2C' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/ice/base: fix array overflow in add switch recipe' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/virtio: fix crash when configured twice' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/mlx4: fix Verbs FD leak in secondary process' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/mlx5: fix meter profile delete after disable' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/ice: check illegal packet sizes' " christian.ehrhardt
2022-11-11 11:38 ` patch 'common/sfc_efx/base: fix maximum Tx data count' " christian.ehrhardt
2022-11-11 11:38 ` patch 'examples/vm_power_manager: use safe list iterator' " christian.ehrhardt
2022-11-11 11:38 ` patch 'gro: fix chain index for more than 2 packets' " christian.ehrhardt
2022-11-11 11:38 ` patch 'timer: fix stopping all timers' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/qede/base: fix 32-bit build with GCC 12' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/tap: fix overflow of network interface index' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/memif: fix crash with different number of Rx/Tx queues' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/hns3: fix crash when secondary process access FW' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/bonding: fix Tx hash for TCP' " christian.ehrhardt
2022-11-11 11:38 ` christian.ehrhardt [this message]
2022-11-11 11:38 ` patch 'pdump: do not allow enable/disable in primary process' " christian.ehrhardt
2022-11-11 11:38 ` patch 'event/sw: fix flow ID init in self test' " christian.ehrhardt
2022-11-11 11:38 ` patch 'event/sw: fix log " christian.ehrhardt
2022-11-11 11:38 ` patch 'eventdev/eth_tx: fix queue delete' " christian.ehrhardt
2022-11-11 11:38 ` patch 'license: fix paths' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/bonding: fix descriptor limit reporting' " christian.ehrhardt
2022-11-11 11:38 ` patch 'net/ixgbe: fix broadcast Rx on VF after promisc removal' " christian.ehrhardt
2022-11-11 11:39 ` patch 'net/ixgbe: fix unexpected VLAN Rx in promisc mode on VF' " christian.ehrhardt
2022-11-11 11:39 ` patch 'examples/l2fwd-crypto: fix typo in error message' " christian.ehrhardt
2022-11-11 11:39 ` patch 'test/crypto: fix wireless auth digest segment' " christian.ehrhardt
2022-11-11 11:39 ` patch 'test/crypto: fix PDCP vectors' " christian.ehrhardt
2022-11-11 11:39 ` patch 'crypto/qat: fix null hash algorithm digest size' " christian.ehrhardt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221111113904.1549618-35-christian.ehrhardt@canonical.com \
    --to=christian.ehrhardt@canonical.com \
    --cc=anatoly.burakov@intel.com \
    --cc=fengchengwen@huawei.com \
    --cc=stable@dpdk.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).