Re: [PATCH v9 24/25] drivers: add dpaax destructor to gate EAL memory frees

Stephen Hemminger <[email protected]>
Newsgroups org.dpdk.dev
Message-ID <[email protected]>
On Wed, 12 Aug 2026 23:16:08 +0530
Hemant Agrawal <[email protected]> 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.