diff mbox series

[05/10] kni: don't run rte_kni_handle_request after interface release

Message ID 20180628225235.20684-1-dg@adax.com (mailing list archive)
State Superseded, archived
Headers show
Series kni: Interface detach and link status fixes. | expand

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Dan Gora June 28, 2018, 10:52 p.m. UTC
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@adax.com>
---
 lib/librte_kni/rte_kni.c | 6 +++++-
 lib/librte_kni/rte_kni.h | 4 ++++
 2 files changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

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.
  *