All of lore.kernel.org
 help / color / mirror / Atom feed
* [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump()
@ 2014-07-16 21:25 Cong Wang
  2014-07-16 21:25 ` [Patch net-next] net_sched: hold tcf_lock in netdevice notifier Cong Wang
                   ` (3 more replies)
  0 siblings, 4 replies; 15+ messages in thread
From: Cong Wang @ 2014-07-16 21:25 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Jamal Hadi Salim, David S. Miller, Cong Wang

From: Cong Wang <cwang@twopensource.com>

Like other places, we need to cancel the nest attribute after
we start. Fortunately the netlink message will not be sent on
failure, so it's not a big problem at all.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: Cong Wang <cwang@twopensource.com>
---
 net/sched/cls_api.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 45527e6..c28b0d3 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -561,13 +561,14 @@ EXPORT_SYMBOL(tcf_exts_change);
 int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
 {
 #ifdef CONFIG_NET_CLS_ACT
+	struct nlattr *nest;
+
 	if (exts->action && !list_empty(&exts->actions)) {
 		/*
 		 * again for backward compatible mode - we want
 		 * to work with both old and new modes of entering
 		 * tc data even if iproute2  was newer - jhs
 		 */
-		struct nlattr *nest;
 		if (exts->type != TCA_OLD_COMPAT) {
 			nest = nla_nest_start(skb, exts->action);
 			if (nest == NULL)
@@ -585,10 +586,14 @@ int tcf_exts_dump(struct sk_buff *skb, struct tcf_exts *exts)
 			nla_nest_end(skb, nest);
 		}
 	}
-#endif
 	return 0;
-nla_put_failure: __attribute__ ((unused))
+
+nla_put_failure:
+	nla_nest_cancel(skb, nest);
 	return -1;
+#else
+	return 0;
+#endif
 }
 EXPORT_SYMBOL(tcf_exts_dump);
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-16 21:25 [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump() Cong Wang
@ 2014-07-16 21:25 ` Cong Wang
  2014-07-17 12:49   ` Jamal Hadi Salim
                     ` (2 more replies)
  2014-07-17  6:51 ` [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump() David Miller
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 15+ messages in thread
From: Cong Wang @ 2014-07-16 21:25 UTC (permalink / raw)
  To: netdev; +Cc: Cong Wang, Jamal Hadi Salim, David S. Miller, Cong Wang

From: Cong Wang <cwang@twopensource.com>

We modify mirred action (m->tcfm_dev) in netdev event, we need to
prevent on-going mirred actions from reading freed m->tcfm_dev.
So we need to acquire this spin lock.

Cc: Jamal Hadi Salim <jhs@mojatatu.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Cong Wang <cwang@twopensource.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
---
 net/sched/act_mirred.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/net/sched/act_mirred.c b/net/sched/act_mirred.c
index 4f912c0..eb48306 100644
--- a/net/sched/act_mirred.c
+++ b/net/sched/act_mirred.c
@@ -218,10 +218,12 @@ static int mirred_device_event(struct notifier_block *unused,
 
 	if (event == NETDEV_UNREGISTER)
 		list_for_each_entry(m, &mirred_list, tcfm_list) {
+			spin_lock_bh(&m->tcf_lock);
 			if (m->tcfm_dev == dev) {
 				dev_put(dev);
 				m->tcfm_dev = NULL;
 			}
+			spin_unlock_bh(&m->tcf_lock);
 		}
 
 	return NOTIFY_DONE;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump()
  2014-07-16 21:25 [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump() Cong Wang
  2014-07-16 21:25 ` [Patch net-next] net_sched: hold tcf_lock in netdevice notifier Cong Wang
@ 2014-07-17  6:51 ` David Miller
  2014-07-17 12:39 ` Jamal Hadi Salim
  2014-07-17 21:59 ` David Miller
  3 siblings, 0 replies; 15+ messages in thread
From: David Miller @ 2014-07-17  6:51 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, jhs, cwang

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 16 Jul 2014 14:25:30 -0700

> From: Cong Wang <cwang@twopensource.com>
> 
> Like other places, we need to cancel the nest attribute after
> we start. Fortunately the netlink message will not be sent on
> failure, so it's not a big problem at all.
> 
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> Signed-off-by: Cong Wang <cwang@twopensource.com>

Jamal, if you could review these two changes from Cong I'd appreciate
it, thanks!

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump()
  2014-07-16 21:25 [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump() Cong Wang
  2014-07-16 21:25 ` [Patch net-next] net_sched: hold tcf_lock in netdevice notifier Cong Wang
  2014-07-17  6:51 ` [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump() David Miller
@ 2014-07-17 12:39 ` Jamal Hadi Salim
  2014-07-17 21:59 ` David Miller
  3 siblings, 0 replies; 15+ messages in thread
From: Jamal Hadi Salim @ 2014-07-17 12:39 UTC (permalink / raw)
  To: Cong Wang, netdev; +Cc: David S. Miller, Cong Wang

On 07/16/14 17:25, Cong Wang wrote:
> From: Cong Wang <cwang@twopensource.com>
>
> Like other places, we need to cancel the nest attribute after
> we start. Fortunately the netlink message will not be sent on
> failure, so it's not a big problem at all.
>

Sure.

Signed-off-by: Jamal Hadi Salim <jhs@mojatatu.com>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-16 21:25 ` [Patch net-next] net_sched: hold tcf_lock in netdevice notifier Cong Wang
@ 2014-07-17 12:49   ` Jamal Hadi Salim
  2014-07-17 16:45     ` Cong Wang
  2014-07-17 23:01   ` David Miller
  2014-07-21  3:31   ` David Miller
  2 siblings, 1 reply; 15+ messages in thread
From: Jamal Hadi Salim @ 2014-07-17 12:49 UTC (permalink / raw)
  To: Cong Wang, netdev; +Cc: David S. Miller, Cong Wang

On 07/16/14 17:25, Cong Wang wrote:
> From: Cong Wang <cwang@twopensource.com>
>
> We modify mirred action (m->tcfm_dev) in netdev event, we need to
> prevent on-going mirred actions from reading freed m->tcfm_dev.
> So we need to acquire this spin lock.
>

Cong,

What setup prompted this? We have no problems dealing with deleted
devices in the data path. It seems harmless otherwise.

cheers,
jamal

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-17 12:49   ` Jamal Hadi Salim
@ 2014-07-17 16:45     ` Cong Wang
  2014-07-17 18:17       ` Eric Dumazet
  0 siblings, 1 reply; 15+ messages in thread
From: Cong Wang @ 2014-07-17 16:45 UTC (permalink / raw)
  To: Jamal Hadi Salim
  Cc: Linux Kernel Network Developers, David S. Miller, Cong Wang

On Thu, Jul 17, 2014 at 5:49 AM, Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> On 07/16/14 17:25, Cong Wang wrote:
>>
>> From: Cong Wang <cwang@twopensource.com>
>>
>> We modify mirred action (m->tcfm_dev) in netdev event, we need to
>> prevent on-going mirred actions from reading freed m->tcfm_dev.
>> So we need to acquire this spin lock.
>>
>
> Cong,
>
> What setup prompted this? We have no problems dealing with deleted
> devices in the data path. It seems harmless otherwise.
>


I found this during code review, don't see any real crash. This
is why I sent it for net-next not net. :)

The reason why it doesn't trigger a crash is I think dev_put()
doesn't immediately release dev when refcount hits zero,
instead it defers that to rtnl_unlock().

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-17 16:45     ` Cong Wang
@ 2014-07-17 18:17       ` Eric Dumazet
  2014-07-17 21:25         ` Cong Wang
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Dumazet @ 2014-07-17 18:17 UTC (permalink / raw)
  To: Cong Wang
  Cc: Jamal Hadi Salim, Linux Kernel Network Developers,
	David S. Miller, Cong Wang

On Thu, 2014-07-17 at 09:45 -0700, Cong Wang wrote:
> On Thu, Jul 17, 2014 at 5:49 AM, Jamal Hadi Salim <jhs@mojatatu.com> wrote:
> > On 07/16/14 17:25, Cong Wang wrote:
> >>
> >> From: Cong Wang <cwang@twopensource.com>
> >>
> >> We modify mirred action (m->tcfm_dev) in netdev event, we need to
> >> prevent on-going mirred actions from reading freed m->tcfm_dev.
> >> So we need to acquire this spin lock.
> >>
> >
> > Cong,
> >
> > What setup prompted this? We have no problems dealing with deleted
> > devices in the data path. It seems harmless otherwise.
> >
> 
> 
> I found this during code review, don't see any real crash. This
> is why I sent it for net-next not net. :)
> 
> The reason why it doesn't trigger a crash is I think dev_put()
> doesn't immediately release dev when refcount hits zero,
> instead it defers that to rtnl_unlock().

There is no way this dev_put() could make refcnt reaching 0, unless
there is a serious bug elsewhere.

Anyway, tcfm_dev should probably be RCU protected.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-17 18:17       ` Eric Dumazet
@ 2014-07-17 21:25         ` Cong Wang
  2014-07-18  5:37           ` Eric Dumazet
  0 siblings, 1 reply; 15+ messages in thread
From: Cong Wang @ 2014-07-17 21:25 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jamal Hadi Salim, Linux Kernel Network Developers,
	David S. Miller, Cong Wang

On Thu, Jul 17, 2014 at 11:17 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
> Anyway, tcfm_dev should probably be RCU protected.
>

Not sure how much we gain from making it RCU. We anyway
need to hold that spinlock on fast path since we need to
update its time stamp and stats.

I would just leave it as is.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump()
  2014-07-16 21:25 [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump() Cong Wang
                   ` (2 preceding siblings ...)
  2014-07-17 12:39 ` Jamal Hadi Salim
@ 2014-07-17 21:59 ` David Miller
  3 siblings, 0 replies; 15+ messages in thread
From: David Miller @ 2014-07-17 21:59 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, jhs, cwang

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 16 Jul 2014 14:25:30 -0700

> From: Cong Wang <cwang@twopensource.com>
> 
> Like other places, we need to cancel the nest attribute after
> we start. Fortunately the netlink message will not be sent on
> failure, so it's not a big problem at all.
> 
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
> Signed-off-by: Cong Wang <cwang@twopensource.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-16 21:25 ` [Patch net-next] net_sched: hold tcf_lock in netdevice notifier Cong Wang
  2014-07-17 12:49   ` Jamal Hadi Salim
@ 2014-07-17 23:01   ` David Miller
  2014-07-21  3:31   ` David Miller
  2 siblings, 0 replies; 15+ messages in thread
From: David Miller @ 2014-07-17 23:01 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, jhs, cwang

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 16 Jul 2014 14:25:31 -0700

> From: Cong Wang <cwang@twopensource.com>
> 
> We modify mirred action (m->tcfm_dev) in netdev event, we need to
> prevent on-going mirred actions from reading freed m->tcfm_dev.
> So we need to acquire this spin lock.
> 
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Signed-off-by: Cong Wang <cwang@twopensource.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

FWIW, from looking at the code, this lock is definitely necessary.

The fact that device destruction is deferred to rtnl_unlock() only
means the problem is harder to hit, rather than impossible.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-17 21:25         ` Cong Wang
@ 2014-07-18  5:37           ` Eric Dumazet
  2014-07-18  5:51             ` Cong Wang
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Dumazet @ 2014-07-18  5:37 UTC (permalink / raw)
  To: Cong Wang
  Cc: Jamal Hadi Salim, Linux Kernel Network Developers,
	David S. Miller, Cong Wang

On Thu, 2014-07-17 at 14:25 -0700, Cong Wang wrote:
> On Thu, Jul 17, 2014 at 11:17 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> >
> > Anyway, tcfm_dev should probably be RCU protected.
> >
> 
> Not sure how much we gain from making it RCU. We anyway
> need to hold that spinlock on fast path since we need to
> update its time stamp and stats.
> 
> I would just leave it as is.


I think you really should look at John Fastabend work, and many other
existing paths in the stack.

All this can be done lockless in fast path, using RCU and percpu
counters.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-18  5:37           ` Eric Dumazet
@ 2014-07-18  5:51             ` Cong Wang
  2014-07-18  7:08               ` Eric Dumazet
  0 siblings, 1 reply; 15+ messages in thread
From: Cong Wang @ 2014-07-18  5:51 UTC (permalink / raw)
  To: Eric Dumazet
  Cc: Jamal Hadi Salim, Linux Kernel Network Developers,
	David S. Miller, Cong Wang

On Thu, Jul 17, 2014 at 10:37 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> On Thu, 2014-07-17 at 14:25 -0700, Cong Wang wrote:
>> On Thu, Jul 17, 2014 at 11:17 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>> >
>> > Anyway, tcfm_dev should probably be RCU protected.
>> >
>>
>> Not sure how much we gain from making it RCU. We anyway
>> need to hold that spinlock on fast path since we need to
>> update its time stamp and stats.
>>
>> I would just leave it as is.
>
>
> I think you really should look at John Fastabend work, and many other
> existing paths in the stack.
>

I reviewed the last two verions of his patchset...


> All this can be done lockless in fast path, using RCU and percpu
> counters.
>

I don't think he ever removes this m->tcf_lock.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-18  5:51             ` Cong Wang
@ 2014-07-18  7:08               ` Eric Dumazet
  2014-07-19 22:02                 ` Jamal Hadi Salim
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Dumazet @ 2014-07-18  7:08 UTC (permalink / raw)
  To: Cong Wang
  Cc: Jamal Hadi Salim, Linux Kernel Network Developers,
	David S. Miller, Cong Wang

On Thu, 2014-07-17 at 22:51 -0700, Cong Wang wrote:
> On Thu, Jul 17, 2014 at 10:37 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > On Thu, 2014-07-17 at 14:25 -0700, Cong Wang wrote:
> >> On Thu, Jul 17, 2014 at 11:17 AM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> >> >
> >> > Anyway, tcfm_dev should probably be RCU protected.
> >> >
> >>
> >> Not sure how much we gain from making it RCU. We anyway
> >> need to hold that spinlock on fast path since we need to
> >> update its time stamp and stats.
> >>
> >> I would just leave it as is.
> >
> >
> > I think you really should look at John Fastabend work, and many other
> > existing paths in the stack.
> >
> 
> I reviewed the last two verions of his patchset...
> 
> 
> > All this can be done lockless in fast path, using RCU and percpu
> > counters.
> >
> 
> I don't think he ever removes this m->tcf_lock.

Apparently you have hard time to understand the suggestion.

If this conversion was already done by John, I would have pointed the
patch to finalize.

There is nothing fundamental that requires this spinlock being held in
fast path.

It is perfectly possible to remove this, and first step is to use RCU,
then percpu counters.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-18  7:08               ` Eric Dumazet
@ 2014-07-19 22:02                 ` Jamal Hadi Salim
  0 siblings, 0 replies; 15+ messages in thread
From: Jamal Hadi Salim @ 2014-07-19 22:02 UTC (permalink / raw)
  To: Eric Dumazet, Cong Wang
  Cc: Linux Kernel Network Developers, David S. Miller, Cong Wang

On 07/18/14 03:08, Eric Dumazet wrote:
> On Thu, 2014-07-17 at 22:51 -0700, Cong Wang wrote:
>
> If this conversion was already done by John, I would have pointed the
> patch to finalize.
>
> There is nothing fundamental that requires this spinlock being held in
> fast path.
>
> It is perfectly possible to remove this, and first step is to use RCU,
> then percpu counters.
>

I think rcufication would help in some the shared action instances.
Note: post John's rcu-fication of classifier path this is not an
issue i.e
the most common use case default behavior (majority) is no sharing of
instances - in such a case there is no lock contention.

cheers,
jamal

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier
  2014-07-16 21:25 ` [Patch net-next] net_sched: hold tcf_lock in netdevice notifier Cong Wang
  2014-07-17 12:49   ` Jamal Hadi Salim
  2014-07-17 23:01   ` David Miller
@ 2014-07-21  3:31   ` David Miller
  2 siblings, 0 replies; 15+ messages in thread
From: David Miller @ 2014-07-21  3:31 UTC (permalink / raw)
  To: xiyou.wangcong; +Cc: netdev, jhs, cwang

From: Cong Wang <xiyou.wangcong@gmail.com>
Date: Wed, 16 Jul 2014 14:25:31 -0700

> From: Cong Wang <cwang@twopensource.com>
> 
> We modify mirred action (m->tcfm_dev) in netdev event, we need to
> prevent on-going mirred actions from reading freed m->tcfm_dev.
> So we need to acquire this spin lock.
> 
> Cc: Jamal Hadi Salim <jhs@mojatatu.com>
> Cc: "David S. Miller" <davem@davemloft.net>
> Signed-off-by: Cong Wang <cwang@twopensource.com>
> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

Applied, thanks Cong.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2014-07-21  3:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-16 21:25 [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump() Cong Wang
2014-07-16 21:25 ` [Patch net-next] net_sched: hold tcf_lock in netdevice notifier Cong Wang
2014-07-17 12:49   ` Jamal Hadi Salim
2014-07-17 16:45     ` Cong Wang
2014-07-17 18:17       ` Eric Dumazet
2014-07-17 21:25         ` Cong Wang
2014-07-18  5:37           ` Eric Dumazet
2014-07-18  5:51             ` Cong Wang
2014-07-18  7:08               ` Eric Dumazet
2014-07-19 22:02                 ` Jamal Hadi Salim
2014-07-17 23:01   ` David Miller
2014-07-21  3:31   ` David Miller
2014-07-17  6:51 ` [Patch net-next] net_sched: cancel nest attribute on failure in tcf_exts_dump() David Miller
2014-07-17 12:39 ` Jamal Hadi Salim
2014-07-17 21:59 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.