Skip to contentSkip to conversation

pkt_sched: Fix gen_estimator locks

PATCH Applied Jarek Poplawski 3 participants 10 messages Aug 25, 2008 – Aug 27, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 pkt_sched: Fix gen_estimator locks

pkt_sched: Fix gen_estimator locks

While passing a qdisc root lock to gen_new_estimator() and gen_replace_estimator() dev could be deactivated or even before grafting proper root qdisc as qdisc_sleeping (e.g. qdisc_create), so using qdisc_root_lock() is not enough. This patch adds qdisc_root_sleeping_lock() for this, plus additional checks, where necessary.

---

 include/net/sch_generic.h |    8 ++++++++
 net/sched/sch_api.c       |   14 +++++++++++---
 net/sched/sch_cbq.c       |    4 ++--
 net/sched/sch_hfsc.c      |    4 ++--
 net/sched/sch_htb.c       |    4 ++--
 5 files changed, 25 insertions(+), 9 deletions(-)
include/net/sch_generic.h +8 -0
index b1d2cfe..ef8a7e2 100644
@@ -217,6 +217,14 @@ static inline spinlock_t *qdisc_root_lock(struct Qdisc *qdisc)
 	return qdisc_lock(root);
 }
 
+static inline spinlock_t *qdisc_root_sleeping_lock(struct Qdisc *qdisc)
+{
+	struct Qdisc *root = qdisc_root_sleeping(qdisc);
+
+	ASSERT_RTNL();
+	return qdisc_lock(root);
+}
+
 static inline struct net_device *qdisc_dev(struct Qdisc *qdisc)
 {
 	return qdisc->dev_queue->dev;
net/sched/sch_api.c +11 -3
index e7fb9e0..4f9397f 100644
@@ -830,9 +830,16 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
 			sch->stab = stab;
 		}
 		if (tca[TCA_RATE]) {
+			spinlock_t *root_lock;
+
+			if ((sch->parent != TC_H_ROOT) &&
+			    !(sch->flags & TCQ_F_INGRESS))
+				root_lock = qdisc_root_sleeping_lock(sch);
+			else
+				root_lock = qdisc_lock(sch);
+
 			err = gen_new_estimator(&sch->bstats, &sch->rate_est,
-						qdisc_root_lock(sch),
-						tca[TCA_RATE]);
+						root_lock, tca[TCA_RATE]);
 			if (err) {
 				/*
 				 * Any broken qdiscs that would require
@@ -884,7 +891,8 @@ static int qdisc_change(struct Qdisc *sch, struct nlattr **tca)
 
 	if (tca[TCA_RATE])
 		gen_replace_estimator(&sch->bstats, &sch->rate_est,
-				      qdisc_root_lock(sch), tca[TCA_RATE]);
+				      qdisc_root_sleeping_lock(sch),
+				      tca[TCA_RATE]);
 	return 0;
 }
 
net/sched/sch_cbq.c +2 -2
index 8fa90d6..9b720ad 100644
@@ -1839,7 +1839,7 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
 
 		if (tca[TCA_RATE])
 			gen_replace_estimator(&cl->bstats, &cl->rate_est,
-					      qdisc_root_lock(sch),
+					      qdisc_root_sleeping_lock(sch),
 					      tca[TCA_RATE]);
 		return 0;
 	}
@@ -1930,7 +1930,7 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t
 
 	if (tca[TCA_RATE])
 		gen_new_estimator(&cl->bstats, &cl->rate_est,
-				  qdisc_root_lock(sch), tca[TCA_RATE]);
+				  qdisc_root_sleeping_lock(sch), tca[TCA_RATE]);
 
 	*arg = (unsigned long)cl;
 	return 0;
net/sched/sch_hfsc.c +2 -2
index c2b8d9c..c1e77da 100644
@@ -1045,7 +1045,7 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
 
 		if (tca[TCA_RATE])
 			gen_replace_estimator(&cl->bstats, &cl->rate_est,
-					      qdisc_root_lock(sch),
+					      qdisc_root_sleeping_lock(sch),
 					      tca[TCA_RATE]);
 		return 0;
 	}
@@ -1104,7 +1104,7 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid,
 
 	if (tca[TCA_RATE])
 		gen_new_estimator(&cl->bstats, &cl->rate_est,
-				  qdisc_root_lock(sch), tca[TCA_RATE]);
+				  qdisc_root_sleeping_lock(sch), tca[TCA_RATE]);
 	*arg = (unsigned long)cl;
 	return 0;
 }
net/sched/sch_htb.c +2 -2
index 0df0df2..97d4761 100644
@@ -1372,7 +1372,7 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
 			goto failure;
 
 		gen_new_estimator(&cl->bstats, &cl->rate_est,
-				  qdisc_root_lock(sch),
+				  qdisc_root_sleeping_lock(sch),
 				  tca[TCA_RATE] ? : &est.nla);
 		cl->refcnt = 1;
 		cl->children = 0;
@@ -1427,7 +1427,7 @@ static int htb_change_class(struct Qdisc *sch, u32 classid,
 	} else {
 		if (tca[TCA_RATE])
 			gen_replace_estimator(&cl->bstats, &cl->rate_est,
-					      qdisc_root_lock(sch),
+					      qdisc_root_sleeping_lock(sch),
 					      tca[TCA_RATE]);
 		sch_tree_lock(sch);
 	}
#1 lore raw
Quoted 11 lines · Jarek Poplawski

pkt_sched: Fix gen_estimator locks

While passing a qdisc root lock to gen_new_estimator() and gen_replace_estimator() dev could be deactivated or even before grafting proper root qdisc as qdisc_sleeping (e.g. qdisc_create), so using qdisc_root_lock() is not enough. This patch adds qdisc_root_sleeping_lock() for this, plus additional checks, where necessary.

Looks good.

net/sched/sch_api.c qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, · line 839

Quoted 11 lines
net/sched/sch_api.c +7 -0
@@ -830,9 +830,16 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
                       sch->stab = stab;
               }
               if (tca[TCA_RATE]) {
+                       spinlock_t *root_lock;
+
+                       if ((sch->parent != TC_H_ROOT) &&
+                           !(sch->flags & TCQ_F_INGRESS))
+                               root_lock = qdisc_root_sleeping_lock(sch);
+                       else
+                               root_lock = qdisc_lock(sch);

Another reason why we should just have pointers to the root.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer Applied
#2 lore raw

From: Herbert Xu <[email protected]>
Date: Tue, 26 Aug 2008 22:57:38 +1000

Quoted 11 lines
Quoted 10 lines · Jarek Poplawski

pkt_sched: Fix gen_estimator locks

While passing a qdisc root lock to gen_new_estimator() and gen_replace_estimator() dev could be deactivated or even before grafting proper root qdisc as qdisc_sleeping (e.g. qdisc_create), so using qdisc_root_lock() is not enough. This patch adds qdisc_root_sleeping_lock() for this, plus additional checks, where necessary.

Quoted 3 lines
Quoted 1 line

Looks good.

Applied.

Quoted 5 lines
Quoted 5 lines
net/sched/sch_api.c +1 -0
@@ -830,9 +830,16 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
                       sch->stab = stab;
               }
               if (tca[TCA_RATE]) {
+                       spinlock_t *root_lock;
Quoted 8 lines

net/sched/sch_api.c qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, · line 839

Quoted 6 lines
net/sched/sch_api.c +6 -0
+
+                       if ((sch->parent != TC_H_ROOT) &&
+                           !(sch->flags & TCQ_F_INGRESS))
+                               root_lock = qdisc_root_sleeping_lock(sch);
+                       else
+                               root_lock = qdisc_lock(sch);

Another reason why we should just have pointers to the root.

Yes root pointers would be useful, but they wouldn't kill these tests :-)

Here in qdisc_create() we might be creating the new root, and we'd still thus need a conditional for that case.

#3 lore raw
Quoted 15 lines · David Miller
Quoted 14 lines

net/sched/sch_api.c qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, · line 839

Quoted 12 lines
net/sched/sch_api.c +7 -0
@@ -830,9 +830,16 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue,
                       sch->stab = stab;
               }
               if (tca[TCA_RATE]) {
+                       spinlock_t *root_lock;
+
+                       if ((sch->parent != TC_H_ROOT) &&
+                           !(sch->flags & TCQ_F_INGRESS))
+                               root_lock = qdisc_root_sleeping_lock(sch);
+                       else
+                               root_lock = qdisc_lock(sch);

Another reason why we should just have pointers to the root.

Quoted 5 lines

Yes root pointers would be useful, but they wouldn't kill these tests :-)

Here in qdisc_create() we might be creating the new root, and we'd still thus need a conditional for that case.

What I mean is a pointer like sch->root_qdisc, and we would provide that to qdisc_create as a parameter in place of dev_queue (and NULL for root qdiscs themselves). So as long as we assign it at the top of this function it would be available here too.

Cheers,

Signature · 4 lines
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
maintainer
#4 lore raw

From: Herbert Xu <[email protected]>
Date: Wed, 27 Aug 2008 19:55:49 +1000

Quoted 4 lines

What I mean is a pointer like sch->root_qdisc, and we would provide that to qdisc_create as a parameter in place of dev_queue (and NULL for root qdiscs themselves). So as long as we assign it at the top of this function it would be available here too.

Ok, that makes sense.

#5 lore raw
Quoted 9 lines · David Miller

From: Herbert Xu <[email protected]>
Date: Wed, 27 Aug 2008 19:55:49 +1000

Quoted 4 lines

What I mean is a pointer like sch->root_qdisc, and we would provide that to qdisc_create as a parameter in place of dev_queue (and NULL for root qdiscs themselves). So as long as we assign it at the top of this function it would be available here too.

Ok, that makes sense.

Yes, it should be simpler. (We can probably consider a pointer to itself instead of NULL for root qdiscs, to skip testing for NULL e.g. while getting a lock.) On the other hand, we lose with this the possibility to easily determine which dev_queue is "the owner" of the qdisc, or if some dev_queue contains a clone only.

Jarek P.

maintainer
#6 lore raw

From: Jarek Poplawski <[email protected]>
Date: Wed, 27 Aug 2008 10:44:58 +0000

Quoted 5 lines

Yes, it should be simpler. (We can probably consider a pointer to itself instead of NULL for root qdiscs, to skip testing for NULL e.g. while getting a lock.) On the other hand, we lose with this the possibility to easily determine which dev_queue is "the owner" of the qdisc, or if some dev_queue contains a clone only.

For root qdiscs we can add a TCQ_F_SHARED flag for this purpose.

#7 lore raw
Quoted 10 lines · David Miller

From: Jarek Poplawski <[email protected]>
Date: Wed, 27 Aug 2008 10:44:58 +0000

Quoted 5 lines

Yes, it should be simpler. (We can probably consider a pointer to itself instead of NULL for root qdiscs, to skip testing for NULL e.g. while getting a lock.) On the other hand, we lose with this the possibility to easily determine which dev_queue is "the owner" of the qdisc, or if some dev_queue contains a clone only.

For root qdiscs we can add a TCQ_F_SHARED flag for this purpose.

Yes, but we can't do something like this:

net/sched/sch_api.c +3 -0
index e7fb9e0..a7f508c 100644
@@ -235,6 +235,9 @@ struct Qdisc *qdisc_lookup(struct net_device *dev, u32 handle)
 		struct netdev_queue *txq = netdev_get_tx_queue(dev, i);
 		struct Qdisc *txq_root = txq->qdisc_sleeping;
 
+		/* skip the clones */
+		if (txq_root->dev_queue != txq)
+			continue;
 		q = qdisc_match_from_root(txq_root, handle);
 		if (q)
 			goto unlock;

Jarek P.

maintainer
#8 lore raw

From: Jarek Poplawski <[email protected]>
Date: Wed, 27 Aug 2008 11:09:39 +0000

Quoted 10 lines · David Miller
Quoted 9 lines

From: Jarek Poplawski <[email protected]>
Date: Wed, 27 Aug 2008 10:44:58 +0000

Quoted 5 lines

Yes, it should be simpler. (We can probably consider a pointer to itself instead of NULL for root qdiscs, to skip testing for NULL e.g. while getting a lock.) On the other hand, we lose with this the possibility to easily determine which dev_queue is "the owner" of the qdisc, or if some dev_queue contains a clone only.

Quoted 3 lines
Quoted 1 line

For root qdiscs we can add a TCQ_F_SHARED flag for this purpose.

Yes, but we can't do something like this:

Good point.

We could go back to using a device scope list. The only piece to solve at that point is how to differentiate the different entries in the non-shared multiq case.

What it comes down to is semantics, and how we might want to handle multiq non-shared cases in future uses.

Maybe some day we'll allow real complicated configurations, such as mixes of shared and non-shared qdiscs on the TX queues.

So we'd need to think about how that would look, implementation wise.

#9 lore raw
Quoted 23 lines · David Miller

From: Jarek Poplawski <[email protected]>
Date: Wed, 27 Aug 2008 11:09:39 +0000

Quoted 10 lines · David Miller
Quoted 9 lines

From: Jarek Poplawski <[email protected]>
Date: Wed, 27 Aug 2008 10:44:58 +0000

Quoted 5 lines

Yes, it should be simpler. (We can probably consider a pointer to itself instead of NULL for root qdiscs, to skip testing for NULL e.g. while getting a lock.) On the other hand, we lose with this the possibility to easily determine which dev_queue is "the owner" of the qdisc, or if some dev_queue contains a clone only.

Quoted 3 lines
Quoted 1 line

For root qdiscs we can add a TCQ_F_SHARED flag for this purpose.

Yes, but we can't do something like this:

Good point.

We could go back to using a device scope list. The only piece to solve at that point is how to differentiate the different entries in the non-shared multiq case.

Quoted 7 lines

What it comes down to is semantics, and how we might want to handle multiq non-shared cases in future uses.

Maybe some day we'll allow real complicated configurations, such as mixes of shared and non-shared qdiscs on the TX queues.

So we'd need to think about how that would look, implementation wise.

On the other hand, we could save this functionality with another flag e.g.:__QDISC_STATE_CLONED for all dev_queues, except "the owner"?

Jarek P.