Skip to contentSkip to conversation

examples/kni: fix crash while handling userspace request

PATCH Applied Ferruh Yigit 3 participants 3 messages Jan 15, 2019 – Jan 17, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 examples/kni: fix crash while handling userspace request

When KNI interface receives RTE_KNI_REQ_CFG_NETWORK_IF request, it stap/start the physical device which as a result of stop() can free all the mbufs in its queue.
Meanwhile sample application continues to read from KNI interface queues and push into device queues. This simultaneous access may cause a crash, crash log can be found at defect description.

As a solution KNI sample application can do the proper synchronization, and stop transfer between KNI interface and physical interface while physical device stop/started.

Bugzilla ID: 116

Fixes 3fc5ca2f6352 ("kni: initial import")

---
Cc: [email protected]
I am not able to re-produce the defect can you please test with this patch?

And another concern is performance affect of this patch, new check is added into fast path. Cc'ed a few more people for comment:
Cc: Igor Ryzhov <[email protected]>
Cc: Phil Yang <[email protected]>
Cc: Dan Gora <[email protected]>

---
 examples/kni/main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
examples/kni/main.c +12 -0
index c468ffd19..a8ce07e2a 100644
@@ -132,6 +132,7 @@ static int kni_config_network_interface(uint16_t port_id, uint8_t if_up);
 static int kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]);
 
 static rte_atomic32_t kni_stop = RTE_ATOMIC32_INIT(0);
+static rte_atomic32_t kni_pause = RTE_ATOMIC32_INIT(0);
 
 /* Print out statistics on packets handled */
 static void
@@ -276,6 +277,7 @@ main_loop(__rte_unused void *arg)
 {
 	uint16_t i;
 	int32_t f_stop;
+	int32_t f_pause;
 	const unsigned lcore_id = rte_lcore_id();
 	enum lcore_rxtx {
 		LCORE_NONE,
@@ -304,8 +306,11 @@ main_loop(__rte_unused void *arg)
 					kni_port_params_array[i]->port_id);
 		while (1) {
 			f_stop = rte_atomic32_read(&kni_stop);
+			f_pause = rte_atomic32_read(&kni_pause);
 			if (f_stop)
 				break;
+			if (f_pause)
+				continue;
 			kni_ingress(kni_port_params_array[i]);
 		}
 	} else if (flag == LCORE_TX) {
@@ -314,8 +319,11 @@ main_loop(__rte_unused void *arg)
 					kni_port_params_array[i]->port_id);
 		while (1) {
 			f_stop = rte_atomic32_read(&kni_stop);
+			f_pause = rte_atomic32_read(&kni_pause);
 			if (f_stop)
 				break;
+			if (f_pause)
+				continue;
 			kni_egress(kni_port_params_array[i]);
 		}
 	} else
@@ -807,12 +815,16 @@ kni_config_network_interface(uint16_t port_id, uint8_t if_up)
 	RTE_LOG(INFO, APP, "Configure network interface of %d %s\n",
 					port_id, if_up ? "up" : "down");
 
+	rte_atomic32_inc(&kni_pause);
+
 	if (if_up != 0) { /* Configure network interface up */
 		rte_eth_dev_stop(port_id);
 		ret = rte_eth_dev_start(port_id);
 	} else /* Configure network interface down */
 		rte_eth_dev_stop(port_id);
 
+	rte_atomic32_dec(&kni_pause);
+
 	if (ret < 0)
 		RTE_LOG(ERR, APP, "Failed to start port %d\n", port_id);
 
Signature · 1 line
2.17.2
#1 lore raw

Hi Ferruh,

Quoted 100 lines

-----Original Message-----
From: Ferruh Yigit <[email protected]>
Sent: Wednesday, January 16, 2019 1:28 AM
To: [email protected]
Cc: [email protected]; [email protected]; Igor Ryzhov <[email protected]>; Phil Yang (Arm Technology China) <[email protected]>; Dan Gora <[email protected]>
Subject: [PATCH] examples/kni: fix crash while handling userspace request

When KNI interface receives RTE_KNI_REQ_CFG_NETWORK_IF request, it stap/start the physical device which as a result of stop() can free all the mbufs in its queue.
Meanwhile sample application continues to read from KNI interface queues and push into device queues. This simultaneous access may cause a crash, crash log can be found at defect description.

As a solution KNI sample application can do the proper synchronization, and stop transfer between KNI interface and physical interface while physical device stop/started.

Bugzilla ID: 116

Fixes 3fc5ca2f6352 ("kni: initial import")

---
Cc: [email protected]
I am not able to re-produce the defect can you please test with this patch?

And another concern is performance affect of this patch, new check is added into fast path. Cc'ed a few more people for comment:
Cc: Igor Ryzhov <[email protected]>
Cc: Phil Yang <[email protected]>
Cc: Dan Gora <[email protected]>

---
 examples/kni/main.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
examples/kni/main.c index renamed from examples/kni/main.c +0 -0

c468ffd19..a8ce07e2a 100644

examples/kni/main.c +0 -0
@@ -132,6 +132,7 @@ static int kni_config_network_interface(uint16_t port_id,

uint8_t if_up); static int kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]);

static rte_atomic32_t kni_stop = RTE_ATOMIC32_INIT(0);
+static rte_atomic32_t kni_pause = RTE_ATOMIC32_INIT(0);

/* Print out statistics on packets handled */ static void @@ -276,6 +277,7 @@
main_loop(__rte_unused void *arg) {
uint16_t i;
int32_t f_stop;

examples/kni/main.c +11 -1
+int32_t f_pause;
 const unsigned lcore_id = rte_lcore_id();
 enum lcore_rxtx {
 LCORE_NONE,
@@ -304,8 +306,11 @@ main_loop(__rte_unused void *arg)
 kni_port_params_array[i]->port_id);
 while (1) {
 f_stop = rte_atomic32_read(&kni_stop);
+f_pause = rte_atomic32_read(&kni_pause);
 if (f_stop)
 break;
+if (f_pause)
+continue;
 kni_ingress(kni_port_params_array[i]);
 }
 } else if (flag == LCORE_TX) {
@@ -314,8 +319,11 @@ main_loop(__rte_unused void *arg)
 kni_port_params_array[i]->port_id);
 while (1) {
 f_stop = rte_atomic32_read(&kni_stop);
+f_pause = rte_atomic32_read(&kni_pause);
 if (f_stop)
 break;
+if (f_pause)
+continue;
 kni_egress(kni_port_params_array[i]);
 }
 } else
@@ -807,12 +815,16 @@ kni_config_network_interface(uint16_t port_id,
 uint8_t if_up)
 RTE_LOG(INFO, APP, "Configure network interface of %d %s\n",
 port_id, if_up ? "up" : "down");
 
+rte_atomic32_inc(&kni_pause);
+
 if (if_up != 0) { /* Configure network interface up */
 rte_eth_dev_stop(port_id);
 ret = rte_eth_dev_start(port_id);
 } else /* Configure network interface down */
 rte_eth_dev_stop(port_id);
 
+rte_atomic32_dec(&kni_pause);
+
 if (ret < 0)
 RTE_LOG(ERR, APP, "Failed to start port %d\n", port_id);
 
--
Quoted 1 line

2.17.2

Thanks,
Phil Yang
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

#2 lore raw
Quoted 11 lines
Quoted 11 lines

When KNI interface receives RTE_KNI_REQ_CFG_NETWORK_IF request, it stap/start the physical device which as a result of stop() can free all the mbufs in its queue.
Meanwhile sample application continues to read from KNI interface queues and push into device queues. This simultaneous access may cause a crash, crash log can be found at defect description.

As a solution KNI sample application can do the proper synchronization, and stop transfer between KNI interface and physical interface while physical device stop/started.

Quoted 7 lines
Quoted 5 lines

Bugzilla ID: 116

Fixes 3fc5ca2f6352 ("kni: initial import")

Applied, thanks