Skip to contentSkip to conversation

net_sched: cancel nest attribute on failure in tcf_exts_dump()

PATCH Applied Cong Wang 4 participants 15 messages Jul 16, 2014 – Jul 21, 2014

Subsystems (3)
lore
Share & tools
lore

Cong Wang

author
#0 lore raw

PATCH 1/1 net_sched: cancel nest attribute on failure in tcf_exts_dump()

From: Cong Wang <[email protected]>

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 <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 net/sched/cls_api.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
net/sched/cls_api.c +8 -3
index 45527e6..c28b0d3 100644
@@ -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);
 
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/1 net_sched: hold tcf_lock in netdevice notifier

From: Cong Wang <[email protected]>

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 <[email protected]>
Cc "David S. Miller" <[email protected]>
---
 net/sched/act_mirred.c | 2 ++
 1 file changed, 2 insertions(+)
net/sched/act_mirred.c +2 -0
index 4f912c0..eb48306 100644
@@ -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;
Signature · 1 line
1.8.3.1
maintainer
#12 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 16 Jul 2014 14:25:30 -0700

Quoted 10 lines

From: Cong Wang <[email protected]>

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 <[email protected]>
Cc "David S. Miller" <[email protected]>

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

maintainer
#2 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

In reply to Cong Wang
Quoted 6 lines · Cong Wang

From: Cong Wang <[email protected]>

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

author
#3 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

Quoted 9 lines · Jamal Hadi Salim
Quoted 7 lines · Cong Wang

From: Cong Wang <[email protected]>

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.

Quoted 5 lines

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().

#4 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

Quoted 17 lines · Cong Wang
Quoted 9 lines · Jamal Hadi Salim
Quoted 7 lines · Cong Wang

From: Cong Wang <[email protected]>

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.

Quoted 5 lines

Cong,

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

Quoted 6 lines

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.

author
#5 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

Quoted 3 lines · Eric Dumazet

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.

maintainer Applied
#14 lore raw
In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 16 Jul 2014 14:25:30 -0700

Quoted 10 lines

From: Cong Wang <[email protected]>

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 <[email protected]>
Cc "David S. Miller" <[email protected]>

Applied, thanks.

maintainer
#10 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 16 Jul 2014 14:25:31 -0700

Quoted 10 lines

From: Cong Wang <[email protected]>

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 <[email protected]>
Cc "David S. Miller" <[email protected]>

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.

#6 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

In reply to Cong Wang
Quoted 10 lines · Cong Wang
Quoted 3 lines · Eric Dumazet

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.

author
#7 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

Quoted 10 lines · Eric Dumazet
Quoted 9 lines · Cong Wang
Quoted 3 lines · Eric Dumazet

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.

Quoted 6 lines
Quoted 1 line

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...

Quoted 3 lines

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.

#8 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

Quoted 18 lines · Cong Wang
Quoted 10 lines · Eric Dumazet
Quoted 9 lines · Cong Wang
Quoted 3 lines · Eric Dumazet

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.

Quoted 6 lines
Quoted 1 line

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.

Quoted 8 lines

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

Quoted 3 lines

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.

maintainer
#9 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

Quoted 11 lines · Eric Dumazet

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

maintainer Applied
#11 lore raw

Re: [Patch net-next] net_sched: hold tcf_lock in netdevice notifier

In reply to Cong Wang

From: Cong Wang <[email protected]>
Date: Wed, 16 Jul 2014 14:25:31 -0700

Quoted 10 lines

From: Cong Wang <[email protected]>

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 <[email protected]>
Cc "David S. Miller" <[email protected]>

Applied, thanks Cong.