[PATCH v3 01/29] bpf: replace deprecated SMP barriers with C11 fences

Wathsala Vithanage wathsala.vithanage at arm.com
Fri Oct 9 08:05:56 CEST 2026


>   /*
>    * Marks given callback as used by datapath.
>    */
>   static __rte_always_inline void
>   bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
>   {
> -	cbi->use++;
> -	/* make sure no store/load reordering could happen */
> -	rte_smp_mb();
> +	rte_atomic_store_explicit(&cbi->use,
> +		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
> +		rte_memory_order_relaxed);
> +
> +	/* full barrier: count must be visible before cb is read */
> +	rte_atomic_thread_fence(rte_memory_order_seq_cst);

This is correct but why use a barrier when the above store itself could 
be SEQ_CST that
synchronizes with load in bpf_eth_cbi_wait?

>   }
>   
>   /*
> @@ -91,9 +106,10 @@ bpf_eth_cbi_inuse(struct bpf_eth_cbi *cbi)
>   static __rte_always_inline void
>   bpf_eth_cbi_unuse(struct bpf_eth_cbi *cbi)
>   {
> -	/* make sure all previous loads are completed */
> -	rte_smp_rmb();
> -	cbi->use++;
> +	/* release: pairs with the acquire bpf_eth_cbi_wait() */
> +	rte_atomic_store_explicit(&cbi->use,
> +		rte_atomic_load_explicit(&cbi->use, rte_memory_order_relaxed) + 1,
> +		rte_memory_order_release);
>   }
>   
>   /*
> @@ -104,15 +120,15 @@ bpf_eth_cbi_wait(const struct bpf_eth_cbi *cbi)
>   {
>   	uint32_t puse;
>   
> -	/* make sure all previous loads and stores are completed */
> -	rte_smp_mb();
> +	/* full barrier: cleared cb must be visible before counter is read */
> +	rte_atomic_thread_fence(rte_memory_order_seq_cst);
>   
> -	puse = cbi->use;
> +	puse = rte_atomic_load_explicit(&cbi->use, rte_memory_order_acquire);
>   
>   	/* in use, busy wait till current RX/TX iteration is finished */
>   	if ((puse & BPF_ETH_CBI_INUSE) != 0) {
>   		RTE_WAIT_UNTIL_MASKED((__rte_atomic uint32_t *)(uintptr_t)&cbi->use,
> -			UINT32_MAX, !=, puse, rte_memory_order_relaxed);
> +			UINT32_MAX, !=, puse, rte_memory_order_acquire);
>   	}
>   }
>   
> @@ -439,7 +455,6 @@ bpf_eth_cbi_unload(struct bpf_eth_cbi *bc)
>   {
>   	/* mark this cbi as empty */
>   	bc->cb = NULL;
> -	rte_smp_mb();
>   
>   	/* make sure datapath doesn't use bpf anymore, then destroy bpf */
>   	bpf_eth_cbi_wait(bc);
--wathsala


More information about the dev mailing list