Re: [PATCH net-next v3] net: sched: act_gact: use acquire/release for tcfg_ptype
From: Jamal Hadi Salim
Date: Wed Sep 02 2026 - 10:57:37 EST
On Wed, Sep 2, 2026 at 3:16 AM Jinjie Ruan <ruanjinjie@xxxxxxxxxx> wrote:
>
> Replace the smp_wmb()/smp_rmb() barrier pair with
> smp_store_release()/smp_load_acquire() on gact->tcfg_ptype.
> tcf_gact_init() publishes tcfg_ptype via release after writing
> tcfg_pval/tcfg_paction; tcf_gact_act() acquires it before
> dispatching to gact_net_rand()/gact_determ(), ensuring the probability
> parameters are visible.
>
> No functional change intended.
>
> Cc: Jamal Hadi Salim <jhs@xxxxxxxxxxxx>
> Cc: Jiri Pirko <jiri@xxxxxxxxxxx>
> Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
> Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
> Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
> Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
> Cc: Simon Horman <horms@xxxxxxxxxx>
> Assisted-by: DeepSeek:DeepSeek-V3
> Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
Reviewed-by: Jamal Hadi Salim <jhs@xxxxxxxxxxxx>
cheers,
jamal
> ---
> v3:
> - Split out from following patch set as Kuniyuki suggested.
> Link: https://lore.kernel.org/all/20260901024234.135119-1-ruanjinjie@xxxxxxxxxx/
> ---
> net/sched/act_gact.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/net/sched/act_gact.c b/net/sched/act_gact.c
> index 565860cccba6..d4f39f98e2cf 100644
> --- a/net/sched/act_gact.c
> +++ b/net/sched/act_gact.c
> @@ -25,7 +25,6 @@ static struct tc_action_ops act_gact_ops;
> #ifdef CONFIG_GACT_PROB
> static int gact_net_rand(struct tcf_gact *gact)
> {
> - smp_rmb(); /* coupled with smp_wmb() in tcf_gact_init() */
> if (get_random_u32_below(gact->tcfg_pval))
> return gact->tcf_action;
> return gact->tcfg_paction;
> @@ -35,7 +34,6 @@ static int gact_determ(struct tcf_gact *gact)
> {
> u32 pack = atomic_inc_return(&gact->packets);
>
> - smp_rmb(); /* coupled with smp_wmb() in tcf_gact_init() */
> if (pack % gact->tcfg_pval)
> return gact->tcf_action;
> return gact->tcfg_paction;
> @@ -133,11 +131,8 @@ static int tcf_gact_init(struct net *net, struct nlattr *nla,
> if (p_parm) {
> gact->tcfg_paction = p_parm->paction;
> gact->tcfg_pval = max_t(u16, 1, p_parm->pval);
> - /* Make sure tcfg_pval is written before tcfg_ptype
> - * coupled with smp_rmb() in gact_net_rand() & gact_determ()
> - */
> - smp_wmb();
> - gact->tcfg_ptype = p_parm->ptype;
> + /* Pairs with smp_load_acquire() in tcf_gact_act(). */
> + smp_store_release(&gact->tcfg_ptype, p_parm->ptype);
> }
> #endif
> spin_unlock_bh(&gact->tcf_lock);
> @@ -160,7 +155,8 @@ TC_INDIRECT_SCOPE int tcf_gact_act(struct sk_buff *skb,
>
> #ifdef CONFIG_GACT_PROB
> {
> - u32 ptype = READ_ONCE(gact->tcfg_ptype);
> + /* Pairs with smp_store_release() in tcf_gact_init() */
> + u32 ptype = smp_load_acquire(&gact->tcfg_ptype);
>
> if (ptype)
> action = gact_rand[ptype](gact);
> --
> 2.34.1
>