[dpdk-stable] patch 'ethdev: fix memory ordering for callback functions' has been queued to stable release 19.11.6

luca.boccassi at gmail.com luca.boccassi at gmail.com
Wed Oct 28 11:45:40 CET 2020


Hi,

FYI, your patch has been queued to stable release 19.11.6

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 10/30/20. 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.

Thanks.

Luca Boccassi

---
>From 67ba3dd4691d213d5d8d3988384edfa90bfc747d Mon Sep 17 00:00:00 2001
From: Honnappa Nagarahalli <honnappa.nagarahalli at arm.com>
Date: Tue, 13 Oct 2020 11:25:37 -0500
Subject: [PATCH] ethdev: fix memory ordering for callback functions

[ upstream commit 2b69bd1179162f69c0a90d5b09309498d362b3d7 ]

Call back functions are registered on the control plane. They
are accessed from the data plane. Hence, correct memory orderings
should be used to avoid race conditions.

Fixes: 4dc294158cac ("ethdev: support optional Rx and Tx callbacks")
Fixes: c8231c63ddcb ("ethdev: insert Rx callback as head of list")

Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli at arm.com>
Reviewed-by: Ola Liljedahl <ola.liljedahl at arm.com>
Reviewed-by: Phil Yang <phil.yang at arm.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev at intel.com>
---
 lib/librte_ethdev/rte_ethdev.c | 28 ++++++++++++++++++-----
 lib/librte_ethdev/rte_ethdev.h | 42 ++++++++++++++++++++++++++--------
 2 files changed, 55 insertions(+), 15 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 984b5caa9d..d74429a9e7 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -4435,12 +4435,20 @@ rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
 		rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
 
 	if (!tail) {
-		rte_eth_devices[port_id].post_rx_burst_cbs[queue_id] = cb;
+		/* Stores to cb->fn and cb->param should complete before
+		 * cb is visible to data plane.
+		 */
+		__atomic_store_n(
+			&rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
+			cb, __ATOMIC_RELEASE);
 
 	} else {
 		while (tail->next)
 			tail = tail->next;
-		tail->next = cb;
+		/* Stores to cb->fn and cb->param should complete before
+		 * cb is visible to data plane.
+		 */
+		__atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE);
 	}
 	rte_spinlock_unlock(&rte_eth_rx_cb_lock);
 
@@ -4521,12 +4529,20 @@ rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
 		rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
 
 	if (!tail) {
-		rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id] = cb;
+		/* Stores to cb->fn and cb->param should complete before
+		 * cb is visible to data plane.
+		 */
+		__atomic_store_n(
+			&rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id],
+			cb, __ATOMIC_RELEASE);
 
 	} else {
 		while (tail->next)
 			tail = tail->next;
-		tail->next = cb;
+		/* Stores to cb->fn and cb->param should complete before
+		 * cb is visible to data plane.
+		 */
+		__atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE);
 	}
 	rte_spinlock_unlock(&rte_eth_tx_cb_lock);
 
@@ -4557,7 +4573,7 @@ rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
 		cb = *prev_cb;
 		if (cb == user_cb) {
 			/* Remove the user cb from the callback list. */
-			*prev_cb = cb->next;
+			__atomic_store_n(prev_cb, cb->next, __ATOMIC_RELAXED);
 			ret = 0;
 			break;
 		}
@@ -4591,7 +4607,7 @@ rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
 		cb = *prev_cb;
 		if (cb == user_cb) {
 			/* Remove the user cb from the callback list. */
-			*prev_cb = cb->next;
+			__atomic_store_n(prev_cb, cb->next, __ATOMIC_RELAXED);
 			ret = 0;
 			break;
 		}
diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
index d1a593ad11..51f9f2569f 100644
--- a/lib/librte_ethdev/rte_ethdev.h
+++ b/lib/librte_ethdev/rte_ethdev.h
@@ -3612,7 +3612,8 @@ struct rte_eth_rxtx_callback;
  *   The callback function
  * @param user_param
  *   A generic pointer parameter which will be passed to each invocation of the
- *   callback function on this port and queue.
+ *   callback function on this port and queue. Inter-thread synchronization
+ *   of any user data changes is the responsibility of the user.
  *
  * @return
  *   NULL on error.
@@ -3641,7 +3642,8 @@ rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
  *   The callback function
  * @param user_param
  *   A generic pointer parameter which will be passed to each invocation of the
- *   callback function on this port and queue.
+ *   callback function on this port and queue. Inter-thread synchronization
+ *   of any user data changes is the responsibility of the user.
  *
  * @return
  *   NULL on error.
@@ -3669,7 +3671,8 @@ rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
  *   The callback function
  * @param user_param
  *   A generic pointer parameter which will be passed to each invocation of the
- *   callback function on this port and queue.
+ *   callback function on this port and queue. Inter-thread synchronization
+ *   of any user data changes is the responsibility of the user.
  *
  * @return
  *   NULL on error.
@@ -3694,7 +3697,9 @@ rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
  *   on that queue.
  *
  * - After a short delay - where the delay is sufficient to allow any
- *   in-flight callbacks to complete.
+ *   in-flight callbacks to complete. Alternately, the RCU mechanism can be
+ *   used to detect when data plane threads have ceased referencing the
+ *   callback memory.
  *
  * @param port_id
  *   The port identifier of the Ethernet device.
@@ -3727,7 +3732,9 @@ int rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
  *   on that queue.
  *
  * - After a short delay - where the delay is sufficient to allow any
- *   in-flight callbacks to complete.
+ *   in-flight callbacks to complete. Alternately, the RCU mechanism can be
+ *   used to detect when data plane threads have ceased referencing the
+ *   callback memory.
  *
  * @param port_id
  *   The port identifier of the Ethernet device.
@@ -4388,10 +4395,18 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
 				     rx_pkts, nb_pkts);
 
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
-	if (unlikely(dev->post_rx_burst_cbs[queue_id] != NULL)) {
-		struct rte_eth_rxtx_callback *cb =
-				dev->post_rx_burst_cbs[queue_id];
+	struct rte_eth_rxtx_callback *cb;
 
+	/* __ATOMIC_RELEASE memory order was used when the
+	 * call back was inserted into the list.
+	 * Since there is a clear dependency between loading
+	 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
+	 * not required.
+	 */
+	cb = __atomic_load_n(&dev->post_rx_burst_cbs[queue_id],
+				__ATOMIC_RELAXED);
+
+	if (unlikely(cb != NULL)) {
 		do {
 			nb_rx = cb->fn.rx(port_id, queue_id, rx_pkts, nb_rx,
 						nb_pkts, cb->param);
@@ -4652,7 +4667,16 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
 #endif
 
 #ifdef RTE_ETHDEV_RXTX_CALLBACKS
-	struct rte_eth_rxtx_callback *cb = dev->pre_tx_burst_cbs[queue_id];
+	struct rte_eth_rxtx_callback *cb;
+
+	/* __ATOMIC_RELEASE memory order was used when the
+	 * call back was inserted into the list.
+	 * Since there is a clear dependency between loading
+	 * cb and cb->fn/cb->next, __ATOMIC_ACQUIRE memory order is
+	 * not required.
+	 */
+	cb = __atomic_load_n(&dev->pre_tx_burst_cbs[queue_id],
+				__ATOMIC_RELAXED);
 
 	if (unlikely(cb != NULL)) {
 		do {
-- 
2.20.1

---
  Diff of the applied patch vs upstream commit (please double-check if non-empty:
---
--- -	2020-10-28 10:35:17.325166133 +0000
+++ 0181-ethdev-fix-memory-ordering-for-callback-functions.patch	2020-10-28 10:35:11.792834263 +0000
@@ -1,15 +1,16 @@
-From 2b69bd1179162f69c0a90d5b09309498d362b3d7 Mon Sep 17 00:00:00 2001
+From 67ba3dd4691d213d5d8d3988384edfa90bfc747d Mon Sep 17 00:00:00 2001
 From: Honnappa Nagarahalli <honnappa.nagarahalli at arm.com>
 Date: Tue, 13 Oct 2020 11:25:37 -0500
 Subject: [PATCH] ethdev: fix memory ordering for callback functions
 
+[ upstream commit 2b69bd1179162f69c0a90d5b09309498d362b3d7 ]
+
 Call back functions are registered on the control plane. They
 are accessed from the data plane. Hence, correct memory orderings
 should be used to avoid race conditions.
 
 Fixes: 4dc294158cac ("ethdev: support optional Rx and Tx callbacks")
 Fixes: c8231c63ddcb ("ethdev: insert Rx callback as head of list")
-Cc: stable at dpdk.org
 
 Signed-off-by: Honnappa Nagarahalli <honnappa.nagarahalli at arm.com>
 Reviewed-by: Ola Liljedahl <ola.liljedahl at arm.com>
@@ -21,10 +22,10 @@
  2 files changed, 55 insertions(+), 15 deletions(-)
 
 diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
-index 2198548663..7eaeccc19d 100644
+index 984b5caa9d..d74429a9e7 100644
 --- a/lib/librte_ethdev/rte_ethdev.c
 +++ b/lib/librte_ethdev/rte_ethdev.c
-@@ -4610,12 +4610,20 @@ rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
+@@ -4435,12 +4435,20 @@ rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
  		rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
  
  	if (!tail) {
@@ -47,7 +48,7 @@
  	}
  	rte_spinlock_unlock(&rte_eth_rx_cb_lock);
  
-@@ -4700,12 +4708,20 @@ rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
+@@ -4521,12 +4529,20 @@ rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
  		rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
  
  	if (!tail) {
@@ -70,7 +71,7 @@
  	}
  	rte_spinlock_unlock(&rte_eth_tx_cb_lock);
  
-@@ -4736,7 +4752,7 @@ rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
+@@ -4557,7 +4573,7 @@ rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
  		cb = *prev_cb;
  		if (cb == user_cb) {
  			/* Remove the user cb from the callback list. */
@@ -79,7 +80,7 @@
  			ret = 0;
  			break;
  		}
-@@ -4770,7 +4786,7 @@ rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
+@@ -4591,7 +4607,7 @@ rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
  		cb = *prev_cb;
  		if (cb == user_cb) {
  			/* Remove the user cb from the callback list. */
@@ -89,10 +90,10 @@
  			break;
  		}
 diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h
-index f07dbc4d26..c37b3a1a81 100644
+index d1a593ad11..51f9f2569f 100644
 --- a/lib/librte_ethdev/rte_ethdev.h
 +++ b/lib/librte_ethdev/rte_ethdev.h
-@@ -3911,7 +3911,8 @@ struct rte_eth_rxtx_callback;
+@@ -3612,7 +3612,8 @@ struct rte_eth_rxtx_callback;
   *   The callback function
   * @param user_param
   *   A generic pointer parameter which will be passed to each invocation of the
@@ -102,7 +103,7 @@
   *
   * @return
   *   NULL on error.
-@@ -3940,7 +3941,8 @@ rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
+@@ -3641,7 +3642,8 @@ rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
   *   The callback function
   * @param user_param
   *   A generic pointer parameter which will be passed to each invocation of the
@@ -112,7 +113,7 @@
   *
   * @return
   *   NULL on error.
-@@ -3968,7 +3970,8 @@ rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
+@@ -3669,7 +3671,8 @@ rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
   *   The callback function
   * @param user_param
   *   A generic pointer parameter which will be passed to each invocation of the
@@ -122,7 +123,7 @@
   *
   * @return
   *   NULL on error.
-@@ -3993,7 +3996,9 @@ rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
+@@ -3694,7 +3697,9 @@ rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
   *   on that queue.
   *
   * - After a short delay - where the delay is sufficient to allow any
@@ -133,7 +134,7 @@
   *
   * @param port_id
   *   The port identifier of the Ethernet device.
-@@ -4026,7 +4031,9 @@ int rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
+@@ -3727,7 +3732,9 @@ int rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
   *   on that queue.
   *
   * - After a short delay - where the delay is sufficient to allow any
@@ -144,7 +145,7 @@
   *
   * @param port_id
   *   The port identifier of the Ethernet device.
-@@ -4687,10 +4694,18 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
+@@ -4388,10 +4395,18 @@ rte_eth_rx_burst(uint16_t port_id, uint16_t queue_id,
  				     rx_pkts, nb_pkts);
  
  #ifdef RTE_ETHDEV_RXTX_CALLBACKS
@@ -166,7 +167,7 @@
  		do {
  			nb_rx = cb->fn.rx(port_id, queue_id, rx_pkts, nb_rx,
  						nb_pkts, cb->param);
-@@ -4953,7 +4968,16 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
+@@ -4652,7 +4667,16 @@ rte_eth_tx_burst(uint16_t port_id, uint16_t queue_id,
  #endif
  
  #ifdef RTE_ETHDEV_RXTX_CALLBACKS


More information about the stable mailing list