From: Davide Caratti <dcaratti@redhat.com>
To: David Miller <davem@davemloft.net>
Cc: xiyou.wangcong@gmail.com, jiri@mellanox.com, netdev@vger.kernel.org
Subject: Re: [PATCH net-next 2/2] net/sched: act_csum: don't use spinlock in the fast path
Date: Fri, 22 Dec 2017 10:28:05 +0100 [thread overview]
Message-ID: <1513934885.2913.13.camel@redhat.com> (raw)
In-Reply-To: <20171213.162328.1374458006305010879.davem@davemloft.net>
On Wed, 2017-12-13 at 16:23 -0500, David Miller wrote:
> From: Davide Caratti <dcaratti@redhat.com>
> Date: Wed, 13 Dec 2017 10:48:38 +0100
>
> > Then, in the data path, use READ_ONCE() to
> > read those values, to avoid lock contention among multiple readers.
> ...
> > @@ -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))
hi David, thank you for replying!
> That's not why the lock is here.
>
> We must read both action and flags atomically so that they are consistent
> with eachother.
>
> We must never use action from one configuration change and flags from
> yet another.
I was (erroneously) assuming that such behavior was acceptable, since it's
present almost in all other TC actions, even those where tcf_lock is used.
But agree, it's better not to introduce a race in a place where it's not
present.
> Find a way to load both of these values with a single cpu load, then you
> can legally remove the lock.
act_tunnel_key seems a good example for this, I will send a v2 soon.
--
davide
prev parent reply other threads:[~2017-12-22 9:28 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-13 9:48 [PATCH net-next 0/2] net/sched: remove spinlock from 'csum' action Davide Caratti
2017-12-13 9:48 ` [PATCH net-next 1/2] net/sched: act_csum: use per-core statistics Davide Caratti
2017-12-13 9:48 ` [PATCH net-next 2/2] net/sched: act_csum: don't use spinlock in the fast path Davide Caratti
2017-12-13 21:23 ` David Miller
2017-12-22 9:28 ` Davide Caratti [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1513934885.2913.13.camel@redhat.com \
--to=dcaratti@redhat.com \
--cc=davem@davemloft.net \
--cc=jiri@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).