From patchwork Tue Jan 15 17:28:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ferruh Yigit X-Patchwork-Id: 49849 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 1B5CB2BCE; Tue, 15 Jan 2019 18:28:15 +0100 (CET) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by dpdk.org (Postfix) with ESMTP id E86CB2BAB; Tue, 15 Jan 2019 18:28:13 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Jan 2019 09:28:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,481,1539673200"; d="scan'208";a="118712072" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.212]) by orsmga003.jf.intel.com with ESMTP; 15 Jan 2019 09:28:10 -0800 From: Ferruh Yigit To: dev@dpdk.org Cc: stable@dpdk.org, he.qiao17@zte.com.cn, Igor Ryzhov , Phil Yang , Dan Gora Date: Tue, 15 Jan 2019 17:28:02 +0000 Message-Id: <20190115172802.72238-1-ferruh.yigit@intel.com> X-Mailer: git-send-email 2.17.2 Subject: [dpdk-dev] [PATCH] examples/kni: fix crash while handling userspace request X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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: stable@dpdk.org Signed-off-by: Ferruh Yigit Acked-by: Phil Yang --- Cc: he.qiao17@zte.com.cn 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 Cc: Phil Yang Cc: Dan Gora --- examples/kni/main.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/examples/kni/main.c b/examples/kni/main.c index c468ffd19..a8ce07e2a 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -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);