[dpdk-dev] [PATCH v2 05/10] kni: don't run rte_kni_handle_request after interface release

Dan Gora dg at adax.com
Fri Jun 29 03:55:03 CEST 2018


Check to ensure that the KNI interface is still in use before accessing
the KNI interface FIFOs to kernel space.

This will help to ensure that the user does not access the KNI
interface after rte_kni_release() has been called.

Signed-off-by: Dan Gora <dg at adax.com>
---
 lib/librte_kni/rte_kni.c | 6 +++++-
 lib/librte_kni/rte_kni.h | 4 ++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c
index 1d84c0b70..6ef0859bf 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -578,7 +578,11 @@ rte_kni_handle_request(struct rte_kni *kni)
 	unsigned ret;
 	struct rte_kni_request *req;
 
-	if (kni == NULL)
+	/*
+	 * Don't touch the req/resp fifos after
+	 * we've been released, we can be freed at any instant!
+	 */
+	if (kni == NULL || !kni->in_use)
 		return -1;
 
 	/* Get request mbuf */
diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
index d1a95f898..94516c38f 100644
--- a/lib/librte_kni/rte_kni.h
+++ b/lib/librte_kni/rte_kni.h
@@ -155,6 +155,10 @@ rte_kni_free(struct rte_kni *kni);
  * Then analyzes it and calls the specific actions for the specific requests.
  * Finally constructs the response mbuf and puts it back to the resp_q.
  *
+ * Thread Safety: This function should be called in a separate thread from the
+ * thread which calls rte_kni_release() for this KNI.  This function must not
+ * be called simultaneously with rte_kni_free().
+ *
  * @param kni
  *  The pointer to the context of an existent KNI interface.
  *
-- 
2.18.0.rc1.1.g6f333ff2f



More information about the dev mailing list