diff options
author | Jarek Poplawski <jarkao2@gmail.com> | 2008-08-27 05:25:17 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-08-27 05:25:17 -0400 |
commit | f6f9b93f1624206c802ac9162c9302edaf59bfd9 (patch) | |
tree | 643bd211bf909118311138e588a78834fad7a40d | |
parent | f7a54c13c7b072d9426bd5cec1cdb8306df5ef55 (diff) |
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.
Signed-off-by: Jarek Poplawski <jarkao2@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | include/net/sch_generic.h | 8 | ||||
-rw-r--r-- | net/sched/sch_api.c | 14 | ||||
-rw-r--r-- | net/sched/sch_cbq.c | 4 | ||||
-rw-r--r-- | net/sched/sch_hfsc.c | 4 | ||||
-rw-r--r-- | net/sched/sch_htb.c | 4 |
5 files changed, 25 insertions, 9 deletions
diff --git a/include/net/sch_generic.h b/include/net/sch_generic.h index b1d2cfea89c5..ef8a7e2e12e7 100644 --- a/include/net/sch_generic.h +++ b/include/net/sch_generic.h | |||
@@ -217,6 +217,14 @@ static inline spinlock_t *qdisc_root_lock(struct Qdisc *qdisc) | |||
217 | return qdisc_lock(root); | 217 | return qdisc_lock(root); |
218 | } | 218 | } |
219 | 219 | ||
220 | static inline spinlock_t *qdisc_root_sleeping_lock(struct Qdisc *qdisc) | ||
221 | { | ||
222 | struct Qdisc *root = qdisc_root_sleeping(qdisc); | ||
223 | |||
224 | ASSERT_RTNL(); | ||
225 | return qdisc_lock(root); | ||
226 | } | ||
227 | |||
220 | static inline struct net_device *qdisc_dev(struct Qdisc *qdisc) | 228 | static inline struct net_device *qdisc_dev(struct Qdisc *qdisc) |
221 | { | 229 | { |
222 | return qdisc->dev_queue->dev; | 230 | return qdisc->dev_queue->dev; |
diff --git a/net/sched/sch_api.c b/net/sched/sch_api.c index ad9cda1b8c0a..506b709510b6 100644 --- a/net/sched/sch_api.c +++ b/net/sched/sch_api.c | |||
@@ -830,9 +830,16 @@ qdisc_create(struct net_device *dev, struct netdev_queue *dev_queue, | |||
830 | sch->stab = stab; | 830 | sch->stab = stab; |
831 | } | 831 | } |
832 | if (tca[TCA_RATE]) { | 832 | if (tca[TCA_RATE]) { |
833 | spinlock_t *root_lock; | ||
834 | |||
835 | if ((sch->parent != TC_H_ROOT) && | ||
836 | !(sch->flags & TCQ_F_INGRESS)) | ||
837 | root_lock = qdisc_root_sleeping_lock(sch); | ||
838 | else | ||
839 | root_lock = qdisc_lock(sch); | ||
840 | |||
833 | err = gen_new_estimator(&sch->bstats, &sch->rate_est, | 841 | err = gen_new_estimator(&sch->bstats, &sch->rate_est, |
834 | qdisc_root_lock(sch), | 842 | root_lock, tca[TCA_RATE]); |
835 | tca[TCA_RATE]); | ||
836 | if (err) { | 843 | if (err) { |
837 | /* | 844 | /* |
838 | * Any broken qdiscs that would require | 845 | * Any broken qdiscs that would require |
@@ -884,7 +891,8 @@ static int qdisc_change(struct Qdisc *sch, struct nlattr **tca) | |||
884 | 891 | ||
885 | if (tca[TCA_RATE]) | 892 | if (tca[TCA_RATE]) |
886 | gen_replace_estimator(&sch->bstats, &sch->rate_est, | 893 | gen_replace_estimator(&sch->bstats, &sch->rate_est, |
887 | qdisc_root_lock(sch), tca[TCA_RATE]); | 894 | qdisc_root_sleeping_lock(sch), |
895 | tca[TCA_RATE]); | ||
888 | return 0; | 896 | return 0; |
889 | } | 897 | } |
890 | 898 | ||
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c index 8fa90d68ec6d..9b720adedead 100644 --- a/net/sched/sch_cbq.c +++ b/net/sched/sch_cbq.c | |||
@@ -1839,7 +1839,7 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t | |||
1839 | 1839 | ||
1840 | if (tca[TCA_RATE]) | 1840 | if (tca[TCA_RATE]) |
1841 | gen_replace_estimator(&cl->bstats, &cl->rate_est, | 1841 | gen_replace_estimator(&cl->bstats, &cl->rate_est, |
1842 | qdisc_root_lock(sch), | 1842 | qdisc_root_sleeping_lock(sch), |
1843 | tca[TCA_RATE]); | 1843 | tca[TCA_RATE]); |
1844 | return 0; | 1844 | return 0; |
1845 | } | 1845 | } |
@@ -1930,7 +1930,7 @@ cbq_change_class(struct Qdisc *sch, u32 classid, u32 parentid, struct nlattr **t | |||
1930 | 1930 | ||
1931 | if (tca[TCA_RATE]) | 1931 | if (tca[TCA_RATE]) |
1932 | gen_new_estimator(&cl->bstats, &cl->rate_est, | 1932 | gen_new_estimator(&cl->bstats, &cl->rate_est, |
1933 | qdisc_root_lock(sch), tca[TCA_RATE]); | 1933 | qdisc_root_sleeping_lock(sch), tca[TCA_RATE]); |
1934 | 1934 | ||
1935 | *arg = (unsigned long)cl; | 1935 | *arg = (unsigned long)cl; |
1936 | return 0; | 1936 | return 0; |
diff --git a/net/sched/sch_hfsc.c b/net/sched/sch_hfsc.c index c2b8d9cce3d2..c1e77da8cd09 100644 --- a/net/sched/sch_hfsc.c +++ b/net/sched/sch_hfsc.c | |||
@@ -1045,7 +1045,7 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, | |||
1045 | 1045 | ||
1046 | if (tca[TCA_RATE]) | 1046 | if (tca[TCA_RATE]) |
1047 | gen_replace_estimator(&cl->bstats, &cl->rate_est, | 1047 | gen_replace_estimator(&cl->bstats, &cl->rate_est, |
1048 | qdisc_root_lock(sch), | 1048 | qdisc_root_sleeping_lock(sch), |
1049 | tca[TCA_RATE]); | 1049 | tca[TCA_RATE]); |
1050 | return 0; | 1050 | return 0; |
1051 | } | 1051 | } |
@@ -1104,7 +1104,7 @@ hfsc_change_class(struct Qdisc *sch, u32 classid, u32 parentid, | |||
1104 | 1104 | ||
1105 | if (tca[TCA_RATE]) | 1105 | if (tca[TCA_RATE]) |
1106 | gen_new_estimator(&cl->bstats, &cl->rate_est, | 1106 | gen_new_estimator(&cl->bstats, &cl->rate_est, |
1107 | qdisc_root_lock(sch), tca[TCA_RATE]); | 1107 | qdisc_root_sleeping_lock(sch), tca[TCA_RATE]); |
1108 | *arg = (unsigned long)cl; | 1108 | *arg = (unsigned long)cl; |
1109 | return 0; | 1109 | return 0; |
1110 | } | 1110 | } |
diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c index 0df0df202ed0..97d4761cc31e 100644 --- a/net/sched/sch_htb.c +++ b/net/sched/sch_htb.c | |||
@@ -1372,7 +1372,7 @@ static int htb_change_class(struct Qdisc *sch, u32 classid, | |||
1372 | goto failure; | 1372 | goto failure; |
1373 | 1373 | ||
1374 | gen_new_estimator(&cl->bstats, &cl->rate_est, | 1374 | gen_new_estimator(&cl->bstats, &cl->rate_est, |
1375 | qdisc_root_lock(sch), | 1375 | qdisc_root_sleeping_lock(sch), |
1376 | tca[TCA_RATE] ? : &est.nla); | 1376 | tca[TCA_RATE] ? : &est.nla); |
1377 | cl->refcnt = 1; | 1377 | cl->refcnt = 1; |
1378 | cl->children = 0; | 1378 | cl->children = 0; |
@@ -1427,7 +1427,7 @@ static int htb_change_class(struct Qdisc *sch, u32 classid, | |||
1427 | } else { | 1427 | } else { |
1428 | if (tca[TCA_RATE]) | 1428 | if (tca[TCA_RATE]) |
1429 | gen_replace_estimator(&cl->bstats, &cl->rate_est, | 1429 | gen_replace_estimator(&cl->bstats, &cl->rate_est, |
1430 | qdisc_root_lock(sch), | 1430 | qdisc_root_sleeping_lock(sch), |
1431 | tca[TCA_RATE]); | 1431 | tca[TCA_RATE]); |
1432 | sch_tree_lock(sch); | 1432 | sch_tree_lock(sch); |
1433 | } | 1433 | } |