[PATCH v4 04/27] bpf: use C11 atomics in BPF_ST_ATOMIC_REG
Marat Khalili
marat.khalili at huawei.com
Wed May 27 18:52:37 CEST 2026
> -----Original Message-----
> From: Stephen Hemminger <stephen at networkplumber.org>
> Sent: Wednesday 27 May 2026 00:24
> To: dev at dpdk.org
> Cc: Stephen Hemminger <stephen at networkplumber.org>; Konstantin Ananyev <konstantin.ananyev at huawei.com>;
> Marat Khalili <marat.khalili at huawei.com>
> Subject: [PATCH v4 04/27] bpf: use C11 atomics in BPF_ST_ATOMIC_REG
>
> The BPF_ST_ATOMIC_REG macro generated code with deprecated
> rte_atomicNN_add and rte_atomicNN_exchange.
>
> Replace this with the equivalent rte_stdatomic definitions.
> Use memory order seq_cst to preserve the previous behavior of
> rte_atomicNN_add() / rte_atomicNN_exchange() and matches
> the Linux kernel BPF interpreter for these opcodes.
>
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---
> lib/bpf/bpf_exec.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/lib/bpf/bpf_exec.c b/lib/bpf/bpf_exec.c
> index 18013753b1..ee6ec7516f 100644
> --- a/lib/bpf/bpf_exec.c
> +++ b/lib/bpf/bpf_exec.c
> @@ -10,6 +10,7 @@
> #include <rte_log.h>
> #include <rte_debug.h>
> #include <rte_byteorder.h>
> +#include <rte_stdatomic.h>
>
> #include "bpf_impl.h"
>
> @@ -65,16 +66,16 @@
> (type)(reg)[(ins)->src_reg])
>
> #define BPF_ST_ATOMIC_REG(reg, ins, tp) do { \
> + RTE_ATOMIC(uint##tp##_t) *dst = (RTE_ATOMIC(uint##tp##_t) *) \
> + (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off); \
> switch (ins->imm) { \
> case BPF_ATOMIC_ADD: \
> - rte_atomic##tp##_add((rte_atomic##tp##_t *) \
> - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \
> - (reg)[(ins)->src_reg]); \
> + rte_atomic_fetch_add_explicit(dst, \
> + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \
> break; \
> case BPF_ATOMIC_XCHG: \
> - (reg)[(ins)->src_reg] = rte_atomic##tp##_exchange((uint##tp##_t *) \
> - (uintptr_t)((reg)[(ins)->dst_reg] + (ins)->off), \
> - (reg)[(ins)->src_reg]); \
> + (reg)[(ins)->src_reg] = rte_atomic_exchange_explicit(dst, \
> + (reg)[(ins)->src_reg], rte_memory_order_seq_cst); \
> break; \
> default: \
> /* this should be caught by validator and never reach here */ \
> --
> 2.53.0
Reviewed-by: Marat Khalili <marat.khalili at huawei.com>
nit: in the last sentence of the commit message `s` is not needed in `matches`,
and some word like `behavior` can be added for clarity after `interpreter`.
FWIW whole patchset builds on our amd64 and arm64 machines and passes our subset of tests.
More information about the dev
mailing list