]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
dpdk: release mempool after the device is closed
authorLukas Sismis <lsismis@oisf.net>
Thu, 23 Mar 2023 12:48:03 +0000 (13:48 +0100)
committerVictor Julien <vjulien@oisf.net>
Wed, 10 May 2023 13:59:01 +0000 (15:59 +0200)
Ticket: #5936

src/runmode-dpdk.c
src/source-dpdk.c
src/util-device.h
src/util-dpdk.c

index e4ebaf35f0511080f5d237d85347138437b89255..d421d759f91c3587fb0d20ba332e38da33b78ca1 100644 (file)
@@ -1362,6 +1362,13 @@ static void *ParseDpdkConfigAndConfigureDevice(const char *iface)
     // This counter is increased by worker threads that individually pick queue IDs.
     SC_ATOMIC_RESET(iconf->queue_id);
     SC_ATOMIC_RESET(iconf->inconsitent_numa_cnt);
+
+    // initialize LiveDev DPDK values
+    LiveDevice *ldev_instance = LiveGetDevice(iface);
+    if (ldev_instance == NULL) {
+        FatalError("Device %s is not registered as a live device", iface);
+    }
+    ldev_instance->dpdk_vars.pkt_mp = iconf->pkt_mempool;
     return iconf;
 }
 
index 60828c0b76ff60cfcfe07297fe710af94360d067..2c22cc31a811a7fee1643283e0887ecbd7a57b1b 100644 (file)
@@ -646,10 +646,7 @@ static TmEcode ReceiveDPDKThreadDeinit(ThreadVars *tv, void *data)
         rte_eth_dev_stop(ptv->out_port_id);
     }
 
-    if (ptv->queue_id == 0 && ptv->pkt_mempool != NULL) {
-        rte_mempool_free(ptv->pkt_mempool);
-        ptv->pkt_mempool = NULL;
-    }
+    ptv->pkt_mempool = NULL; // MP is released when device is closed
 
     SCFree(ptv);
     SCReturnInt(TM_ECODE_OK);
index 1837915145d1b724f3f1a33697959b591fa9410d..ae9ec97c08b5e87d2cf4aeb61fb6e85741067894 100644 (file)
 #ifndef __UTIL_DEVICE_H__
 #define __UTIL_DEVICE_H__
 
+#ifdef HAVE_DPDK
+#include <rte_mempool.h>
+#endif /* HAVE_DPDK */
+
 #include "queue.h"
 
 #define OFFLOAD_FLAG_SG     (1<<0)
@@ -35,6 +39,12 @@ int LiveGetOffload(void);
 
 #define MAX_DEVNAME 10
 
+#ifdef HAVE_DPDK
+typedef struct {
+    struct rte_mempool *pkt_mp;
+} DPDKDeviceResources;
+#endif /* HAVE_DPDK */
+
 /** storage for live device names */
 typedef struct LiveDevice_ {
     char *dev;  /**< the device (e.g. "eth0") */
@@ -51,6 +61,10 @@ typedef struct LiveDevice_ {
 
     uint32_t tenant_id;     /**< tenant id in multi-tenancy */
     uint32_t offload_orig;  /**< original offload settings to restore @exit */
+#ifdef HAVE_DPDK
+    // DPDK resources that needs to be cleaned after workers are stopped and devices closed
+    DPDKDeviceResources dpdk_vars;
+#endif
 } LiveDevice;
 
 typedef struct LiveDeviceName_ {
index e6f56e5ccd4f9b2c895a5f1aaeebca22c633d68b..83284411fe2a9d4c7b25d56f7c5188c2ac7ebfd6 100644 (file)
@@ -51,6 +51,9 @@ void DPDKCloseDevice(LiveDevice *ldev)
 
         SCLogInfo("%s: closing device", ldev->dev);
         rte_eth_dev_close(port_id);
+
+        SCLogInfo("%s: releasing packet mempool", ldev->dev);
+        rte_mempool_free(ldev->dpdk_vars.pkt_mp);
     }
 #endif
 }