* [PATCH 0/2] minor bpf improvements
@ 2025-10-19 16:59 Stephen Hemminger
2025-10-19 16:59 ` [PATCH 1/2] bpf: add allocation annotations to functions Stephen Hemminger
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Stephen Hemminger @ 2025-10-19 16:59 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
Minor update to BPF. Add allocation annotation and remove VLA.
Stephen Hemminger (2):
bpf: add allocation annotations to functions
bpf: remove dependency on vla
lib/bpf/bpf_pkt.c | 16 +++++++++-------
lib/bpf/meson.build | 2 --
lib/bpf/rte_bpf.h | 11 ++++++++---
3 files changed, 17 insertions(+), 12 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] bpf: add allocation annotations to functions
2025-10-19 16:59 [PATCH 0/2] minor bpf improvements Stephen Hemminger
@ 2025-10-19 16:59 ` Stephen Hemminger
2025-10-19 16:59 ` [PATCH 2/2] bpf: remove dependency on vla Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 0/2] minor bpf improvements Stephen Hemminger
2 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2025-10-19 16:59 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev
In commit 80da7efbb4c4 ("eal: annotate allocation functions")
helper macros were added to provide compiler information to
detect misuse of alloc/free combinations. This covered many
of the functions in DPDK but missed the case of data allocated
by BPF load functions.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/bpf/rte_bpf.h | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h
index 80ebb0210f..309d84bc51 100644
--- a/lib/bpf/rte_bpf.h
+++ b/lib/bpf/rte_bpf.h
@@ -18,6 +18,7 @@
#include <rte_common.h>
#include <rte_mbuf.h>
+#include <rte_malloc.h>
#include <bpf_def.h>
#ifdef __cplusplus
@@ -128,7 +129,8 @@ rte_bpf_destroy(struct rte_bpf *bpf);
* - ENOMEM - can't reserve enough memory
*/
struct rte_bpf *
-rte_bpf_load(const struct rte_bpf_prm *prm);
+rte_bpf_load(const struct rte_bpf_prm *prm)
+ __rte_malloc __rte_dealloc(rte_bpf_destroy, 1);
/**
* Create a new eBPF execution context and load BPF code from given ELF
@@ -152,7 +154,9 @@ rte_bpf_load(const struct rte_bpf_prm *prm);
*/
struct rte_bpf *
rte_bpf_elf_load(const struct rte_bpf_prm *prm, const char *fname,
- const char *sname);
+ const char *sname)
+ __rte_malloc __rte_dealloc(rte_bpf_destroy, 1);
+
/**
* Execute given BPF bytecode.
*
@@ -228,7 +232,8 @@ struct bpf_program;
* - ENOTSUP - operation not supported
*/
struct rte_bpf_prm *
-rte_bpf_convert(const struct bpf_program *prog);
+rte_bpf_convert(const struct bpf_program *prog)
+ __rte_malloc __rte_dealloc_free;
#ifdef __cplusplus
}
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] bpf: remove dependency on vla
2025-10-19 16:59 [PATCH 0/2] minor bpf improvements Stephen Hemminger
2025-10-19 16:59 ` [PATCH 1/2] bpf: add allocation annotations to functions Stephen Hemminger
@ 2025-10-19 16:59 ` Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 0/2] minor bpf improvements Stephen Hemminger
2 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2025-10-19 16:59 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev
The code for ethdev callbacks was using variable length arrays
which is a feature not supported on MSVC and later C standards.
Replace with alloca().
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/bpf/bpf_pkt.c | 16 +++++++++-------
lib/bpf/meson.build | 2 --
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/lib/bpf/bpf_pkt.c b/lib/bpf/bpf_pkt.c
index 01f813c56b..6a425d79b6 100644
--- a/lib/bpf/bpf_pkt.c
+++ b/lib/bpf/bpf_pkt.c
@@ -6,6 +6,7 @@
#include <string.h>
#include <errno.h>
#include <stdint.h>
+#include <alloca.h>
#include <sys/queue.h>
@@ -163,10 +164,11 @@ apply_filter(struct rte_mbuf *mb[], const uint64_t rc[], uint32_t num,
uint32_t drop)
{
uint32_t i, j, k;
- struct rte_mbuf *dr[num];
+ struct rte_mbuf **dr;
- for (i = 0, j = 0, k = 0; i != num; i++) {
+ dr = alloca(sizeof(struct rte_mbuf *) * num);
+ for (i = 0, j = 0, k = 0; i != num; i++) {
/* filter matches */
if (rc[i] != 0)
mb[j++] = mb[i];
@@ -193,8 +195,8 @@ pkt_filter_vm(const struct rte_bpf *bpf, struct rte_mbuf *mb[], uint32_t num,
uint32_t drop)
{
uint32_t i;
- void *dp[num];
- uint64_t rc[num];
+ void **dp = alloca(sizeof(void *) * num);
+ uint64_t *rc = alloca(sizeof(uint64_t) * num);
for (i = 0; i != num; i++)
dp[i] = rte_pktmbuf_mtod(mb[i], void *);
@@ -209,7 +211,7 @@ pkt_filter_jit(const struct rte_bpf_jit *jit, struct rte_mbuf *mb[],
{
uint32_t i, n;
void *dp;
- uint64_t rc[num];
+ uint64_t *rc = alloca(sizeof(uint64_t) * num);
n = 0;
for (i = 0; i != num; i++) {
@@ -228,7 +230,7 @@ static inline uint32_t
pkt_filter_mb_vm(const struct rte_bpf *bpf, struct rte_mbuf *mb[], uint32_t num,
uint32_t drop)
{
- uint64_t rc[num];
+ uint64_t *rc = alloca(sizeof(uint64_t) * num);
rte_bpf_exec_burst(bpf, (void **)mb, rc, num);
return apply_filter(mb, rc, num, drop);
@@ -239,7 +241,7 @@ pkt_filter_mb_jit(const struct rte_bpf_jit *jit, struct rte_mbuf *mb[],
uint32_t num, uint32_t drop)
{
uint32_t i, n;
- uint64_t rc[num];
+ uint64_t *rc = alloca(sizeof(uint64_t) * num);
n = 0;
for (i = 0; i != num; i++) {
diff --git a/lib/bpf/meson.build b/lib/bpf/meson.build
index 28df7f469a..aa258a9061 100644
--- a/lib/bpf/meson.build
+++ b/lib/bpf/meson.build
@@ -7,8 +7,6 @@ if is_windows
subdir_done()
endif
-cflags += no_wvla_cflag
-
if arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_32')
build = false
reason = 'not supported on 32-bit x86'
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 0/2] minor bpf improvements
2025-10-19 16:59 [PATCH 0/2] minor bpf improvements Stephen Hemminger
2025-10-19 16:59 ` [PATCH 1/2] bpf: add allocation annotations to functions Stephen Hemminger
2025-10-19 16:59 ` [PATCH 2/2] bpf: remove dependency on vla Stephen Hemminger
@ 2025-10-19 20:39 ` Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 1/2] bpf: add allocation annotations to functions Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 2/2] bpf: remove dependency on vla Stephen Hemminger
2 siblings, 2 replies; 6+ messages in thread
From: Stephen Hemminger @ 2025-10-19 20:39 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger
Minor update to BPF. Add allocation annotation and remove VLA.
v2 - fix build on FreeBsd
Stephen Hemminger (2):
bpf: add allocation annotations to functions
bpf: remove dependency on vla
lib/bpf/bpf_pkt.c | 16 +++++++++-------
lib/bpf/meson.build | 2 --
lib/bpf/rte_bpf.h | 11 ++++++++---
3 files changed, 17 insertions(+), 12 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 1/2] bpf: add allocation annotations to functions
2025-10-19 20:39 ` [PATCH v2 0/2] minor bpf improvements Stephen Hemminger
@ 2025-10-19 20:39 ` Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 2/2] bpf: remove dependency on vla Stephen Hemminger
1 sibling, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2025-10-19 20:39 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev
In commit 80da7efbb4c4 ("eal: annotate allocation functions")
helper macros were added to provide compiler information to
detect misuse of alloc/free combinations. This covered many
of the functions in DPDK but missed the case of data allocated
by BPF load functions.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/bpf/rte_bpf.h | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/bpf/rte_bpf.h b/lib/bpf/rte_bpf.h
index 80ebb0210f..309d84bc51 100644
--- a/lib/bpf/rte_bpf.h
+++ b/lib/bpf/rte_bpf.h
@@ -18,6 +18,7 @@
#include <rte_common.h>
#include <rte_mbuf.h>
+#include <rte_malloc.h>
#include <bpf_def.h>
#ifdef __cplusplus
@@ -128,7 +129,8 @@ rte_bpf_destroy(struct rte_bpf *bpf);
* - ENOMEM - can't reserve enough memory
*/
struct rte_bpf *
-rte_bpf_load(const struct rte_bpf_prm *prm);
+rte_bpf_load(const struct rte_bpf_prm *prm)
+ __rte_malloc __rte_dealloc(rte_bpf_destroy, 1);
/**
* Create a new eBPF execution context and load BPF code from given ELF
@@ -152,7 +154,9 @@ rte_bpf_load(const struct rte_bpf_prm *prm);
*/
struct rte_bpf *
rte_bpf_elf_load(const struct rte_bpf_prm *prm, const char *fname,
- const char *sname);
+ const char *sname)
+ __rte_malloc __rte_dealloc(rte_bpf_destroy, 1);
+
/**
* Execute given BPF bytecode.
*
@@ -228,7 +232,8 @@ struct bpf_program;
* - ENOTSUP - operation not supported
*/
struct rte_bpf_prm *
-rte_bpf_convert(const struct bpf_program *prog);
+rte_bpf_convert(const struct bpf_program *prog)
+ __rte_malloc __rte_dealloc_free;
#ifdef __cplusplus
}
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2 2/2] bpf: remove dependency on vla
2025-10-19 20:39 ` [PATCH v2 0/2] minor bpf improvements Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 1/2] bpf: add allocation annotations to functions Stephen Hemminger
@ 2025-10-19 20:39 ` Stephen Hemminger
1 sibling, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2025-10-19 20:39 UTC (permalink / raw)
To: dev; +Cc: Stephen Hemminger, Konstantin Ananyev
The code for ethdev callbacks was using variable length arrays
which is a feature not supported on MSVC and later C standards.
Replace with alloca().
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
lib/bpf/bpf_pkt.c | 16 +++++++++-------
lib/bpf/meson.build | 2 --
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/lib/bpf/bpf_pkt.c b/lib/bpf/bpf_pkt.c
index 01f813c56b..6a425d79b6 100644
--- a/lib/bpf/bpf_pkt.c
+++ b/lib/bpf/bpf_pkt.c
@@ -6,6 +6,7 @@
#include <string.h>
#include <errno.h>
#include <stdint.h>
+#include <alloca.h>
#include <sys/queue.h>
@@ -163,10 +164,11 @@ apply_filter(struct rte_mbuf *mb[], const uint64_t rc[], uint32_t num,
uint32_t drop)
{
uint32_t i, j, k;
- struct rte_mbuf *dr[num];
+ struct rte_mbuf **dr;
- for (i = 0, j = 0, k = 0; i != num; i++) {
+ dr = alloca(sizeof(struct rte_mbuf *) * num);
+ for (i = 0, j = 0, k = 0; i != num; i++) {
/* filter matches */
if (rc[i] != 0)
mb[j++] = mb[i];
@@ -193,8 +195,8 @@ pkt_filter_vm(const struct rte_bpf *bpf, struct rte_mbuf *mb[], uint32_t num,
uint32_t drop)
{
uint32_t i;
- void *dp[num];
- uint64_t rc[num];
+ void **dp = alloca(sizeof(void *) * num);
+ uint64_t *rc = alloca(sizeof(uint64_t) * num);
for (i = 0; i != num; i++)
dp[i] = rte_pktmbuf_mtod(mb[i], void *);
@@ -209,7 +211,7 @@ pkt_filter_jit(const struct rte_bpf_jit *jit, struct rte_mbuf *mb[],
{
uint32_t i, n;
void *dp;
- uint64_t rc[num];
+ uint64_t *rc = alloca(sizeof(uint64_t) * num);
n = 0;
for (i = 0; i != num; i++) {
@@ -228,7 +230,7 @@ static inline uint32_t
pkt_filter_mb_vm(const struct rte_bpf *bpf, struct rte_mbuf *mb[], uint32_t num,
uint32_t drop)
{
- uint64_t rc[num];
+ uint64_t *rc = alloca(sizeof(uint64_t) * num);
rte_bpf_exec_burst(bpf, (void **)mb, rc, num);
return apply_filter(mb, rc, num, drop);
@@ -239,7 +241,7 @@ pkt_filter_mb_jit(const struct rte_bpf_jit *jit, struct rte_mbuf *mb[],
uint32_t num, uint32_t drop)
{
uint32_t i, n;
- uint64_t rc[num];
+ uint64_t *rc = alloca(sizeof(uint64_t) * num);
n = 0;
for (i = 0; i != num; i++) {
diff --git a/lib/bpf/meson.build b/lib/bpf/meson.build
index 28df7f469a..aa258a9061 100644
--- a/lib/bpf/meson.build
+++ b/lib/bpf/meson.build
@@ -7,8 +7,6 @@ if is_windows
subdir_done()
endif
-cflags += no_wvla_cflag
-
if arch_subdir == 'x86' and dpdk_conf.get('RTE_ARCH_32')
build = false
reason = 'not supported on 32-bit x86'
--
2.51.0
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-10-19 20:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-19 16:59 [PATCH 0/2] minor bpf improvements Stephen Hemminger
2025-10-19 16:59 ` [PATCH 1/2] bpf: add allocation annotations to functions Stephen Hemminger
2025-10-19 16:59 ` [PATCH 2/2] bpf: remove dependency on vla Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 0/2] minor bpf improvements Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 1/2] bpf: add allocation annotations to functions Stephen Hemminger
2025-10-19 20:39 ` [PATCH v2 2/2] bpf: remove dependency on vla Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).