there is no need for using spin_{,unlock}_bh() to protect simultaneous
read/write of act_csum configuration: it's sufficient to ensure that RTNL
lock has been taken when tcf_action and update_flags are written, so that
configuration is not racy. Then, in the data path, use READ_ONCE() to
read those values, to avoid lock contention among multiple readers.

Signed-off-by: Davide Caratti <dcara...@redhat.com>
---
 net/sched/act_csum.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/net/sched/act_csum.c b/net/sched/act_csum.c
index 22a555ba3985..ac8402d53cd5 100644
--- a/net/sched/act_csum.c
+++ b/net/sched/act_csum.c
@@ -80,10 +80,9 @@ static int tcf_csum_init(struct net *net, struct nlattr *nla,
        }
 
        p = to_tcf_csum(*a);
-       spin_lock_bh(&p->tcf_lock);
+       ASSERT_RTNL();
        p->tcf_action = parm->action;
        p->update_flags = parm->update_flags;
-       spin_unlock_bh(&p->tcf_lock);
 
        if (ret == ACT_P_CREATED)
                tcf_idr_insert(tn, *a);
@@ -544,14 +543,12 @@ static int tcf_csum(struct sk_buff *skb, const struct 
tc_action *a,
 
        tcf_lastuse_update(&p->tcf_tm);
        bstats_cpu_update(this_cpu_ptr(p->common.cpu_bstats), skb);
-       spin_lock(&p->tcf_lock);
-       action = p->tcf_action;
-       update_flags = p->update_flags;
-       spin_unlock(&p->tcf_lock);
 
+       action = READ_ONCE(p->tcf_action);
        if (unlikely(action == TC_ACT_SHOT))
                goto drop;
 
+       update_flags = READ_ONCE(p->update_flags);
        switch (tc_skb_protocol(skb)) {
        case cpu_to_be16(ETH_P_IP):
                if (!tcf_csum_ipv4(skb, update_flags))
-- 
2.13.6

Reply via email to