From: Lukas Sismis Date: Thu, 23 Mar 2023 12:48:03 +0000 (+0100) Subject: dpdk: release mempool after the device is closed X-Git-Tag: suricata-7.0.0-rc2~174 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6f7693e862b7307309d4d0a6b518e3ba33f647b;p=thirdparty%2Fsuricata.git dpdk: release mempool after the device is closed Ticket: #5936 --- diff --git a/src/runmode-dpdk.c b/src/runmode-dpdk.c index e4ebaf35f0..d421d759f9 100644 --- a/src/runmode-dpdk.c +++ b/src/runmode-dpdk.c @@ -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; } diff --git a/src/source-dpdk.c b/src/source-dpdk.c index 60828c0b76..2c22cc31a8 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -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); diff --git a/src/util-device.h b/src/util-device.h index 1837915145..ae9ec97c08 100644 --- a/src/util-device.h +++ b/src/util-device.h @@ -18,6 +18,10 @@ #ifndef __UTIL_DEVICE_H__ #define __UTIL_DEVICE_H__ +#ifdef HAVE_DPDK +#include +#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_ { diff --git a/src/util-dpdk.c b/src/util-dpdk.c index e6f56e5ccd..83284411fe 100644 --- a/src/util-dpdk.c +++ b/src/util-dpdk.c @@ -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 }