[PATCH v9 24/25] drivers: add dpaax destructor to gate EAL memory frees
Stephen Hemminger
stephen at networkplumber.org
Thu Aug 13 03:33:59 CEST 2026
On Wed, 12 Aug 2026 23:16:08 +0530
Hemant Agrawal <hemant.agrawal at nxp.com> wrote:
> +/* Allocator stuff, make sure the eal memory pool is available when calling.*/
> +#define kmalloc(sz, _t) ((void)(_t), rte_malloc(NULL, sz, 0))
> +#define kzalloc(sz, _t) ((void)(_t), rte_zmalloc(NULL, sz, 0))
> #define vmalloc(sz) rte_malloc(NULL, sz, 0)
> -#define kfree(p) rte_free(p)
> +
> +#define kfree(p) \
> +({ \
> + if (!is_dpaax_in_destructor()) \
> + rte_free(p); \
> + else \
> + pr_debug("Eal memory has been destroyed.\n"); \
> +})
Leaking memory is not a good fix for broken code.
+/*
+ * Track whether the process is executing DPDK destructors. During
+ * teardown the EAL memory subsystem may already be gone, so freeing
+ * EAL memory from a DPAAx destructor is unsafe. Drivers mark the
+ * destructor context via dpaax_enter_destructor() so that kfree()
+ * (see compat.h) can skip rte_free() in that window.
+ */
+static int s_dpaax_in_destructor;
+
+RTE_EXPORT_INTERNAL_SYMBOL(dpaax_enter_destructor)
+void dpaax_enter_destructor(void)
+{
+ s_dpaax_in_destructor = 1;
+}
+
+RTE_EXPORT_INTERNAL_SYMBOL(is_dpaax_in_destructor)
+int is_dpaax_in_destructor(void)
+{
+ return s_dpaax_in_destructor;
+}
This is not thread safe
More information about the dev
mailing list