sch_htb: INIT_HLIST_NODE after hlist_del()
Subsystems (3)
PATCH 1/1 sch_htb: INIT_HLIST_NODE after hlist_del()
After hlist_del() next and pprev pointers are not NULL so hlist_unhashed() doesn't work properly.
---
net/sched/sch_htb.c +6 -2
@@ -1284,8 +1284,10 @@ static void htb_destroy_class(struct Qdi struct htb_class, sibling));/* note: this delete may happen twice (see htb_delete) */ -if (!hlist_unhashed (&cl->hlist)) +if (!hlist_unhashed (&cl->hlist)) {hlist_del (&cl->hlist); +INIT_HLIST_NODE (&cl->hlist); + }list_del (&cl->sibling);if (cl->prio_activity)
@@ -1333,8 +1335,10 @@ static int htb_delete(struct Qdisc *sch,sch_tree_lock (sch);/* delete from hash and active; remainder in destroy_class */ -if (!hlist_unhashed (&cl->hlist)) +if (!hlist_unhashed (&cl->hlist)) {hlist_del (&cl->hlist); +INIT_HLIST_NODE (&cl->hlist); + }if (cl->prio_activity)htb_deactivate (q, cl);
Quoted 12 lines · On Mon, 6 Nov 2006 12:33:53 +0100 Jarek Poplawski <[email protected]> wrote:
After
hlist_del()next and pprev pointers are not NULL sohlist_unhashed()doesn't work properly.Signed-off-by Jarek Poplawski <[email protected]>---
diff -Nurp
linux-2.6.19-rc4-git10-/net/sched/sch_htb.clinux-2.6.19-rc4-git10/net/sched/sch_htb.c
net/sched/sch_htb.c static void htb_destroy_class(struct Qdi · line 1290
Quoted 8 lines
net/sched/sch_htb.c +3
-1@@ -1284,8 +1284,10 @@ static void htb_destroy_class(struct Qdi struct htb_class, sibling));/* note: this delete may happen twice (see htb_delete) */ -if (!hlist_unhashed (&cl->hlist)) +if (!hlist_unhashed (&cl->hlist)) {hlist_del (&cl->hlist); +INIT_HLIST_NODE (&cl->hlist); + }
why not use hlist_del_init?
Quoted 15 lines
net/sched/sch_htb.c +3
-1list_del (&cl->sibling);if (cl->prio_activity)@@ -1333,8 +1335,10 @@ static int htb_delete(struct Qdisc *sch,sch_tree_lock (sch);/* delete from hash and active; remainder in destroy_class */ -if (!hlist_unhashed (&cl->hlist)) +if (!hlist_unhashed (&cl->hlist)) {hlist_del (&cl->hlist); +INIT_HLIST_NODE (&cl->hlist); + }if (cl->prio_activity)htb_deactivate (q, cl);
Signature · 1 line
Stephen Hemminger <[email protected]>
Quoted 17 lines · Stephen Hemminger
Quoted 14 lines · On Mon, 6 Nov 2006 12:33:53 +0100 Jarek Poplawski <[email protected]> wrote:
After
hlist_del()next and pprev pointers are not NULL sohlist_unhashed()doesn't work properly.Signed-off-by Jarek Poplawski <[email protected]>---
diff -Nurp
linux-2.6.19-rc4-git10-/net/sched/sch_htb.clinux-2.6.19-rc4-git10/net/sched/sch_htb.cnet/sched/sch_htb.c +0
-0@@ -1284,8 +1284,10 @@ static void htb_destroy_class(struct Qdi struct htb_class, sibling));
Quoted 8 lines
net/sched/sch_htb.c static void htb_destroy_class(struct Qdi · line 1290
Quoted 6 lines
net/sched/sch_htb.c +3
-1/* note: this delete may happen twice (see htb_delete) */ -if (!hlist_unhashed (&cl->hlist)) +if (!hlist_unhashed (&cl->hlist)) {hlist_del (&cl->hlist); +INIT_HLIST_NODE (&cl->hlist); + }why not use
hlist_del_init?
Yes, this is the question!
As a matter of fact I expected another question. Yesterday I was short on time so I didn't describe the bug enough. I'm not sure if you know the problem, so here are more details (for me problem is 199% repeatable).
After something like this:
# tc qdisc add dev lo root handle 1: htb # tc class add dev lo parent 1: classid 1:1 htb rate 200kbps # tc class del dev lo classid 1:1
enter the BUG...
I've found the last command is the culprit and if you do:
# tc qdisc del dev lo root there is no problem.
And probably it is enough to do the change only in htb_delete
- btw. is this hlist_del really needed there? and shouldn't all deletions be done after zeroing the refcount? - but you should know better.
Quoted 14 lines
Quoted 14 lines
net/sched/sch_htb.c +3
-1list_del (&cl->sibling);if (cl->prio_activity)@@ -1333,8 +1335,10 @@ static int htb_delete(struct Qdisc *sch,sch_tree_lock (sch);/* delete from hash and active; remainder in destroy_class */ -if (!hlist_unhashed (&cl->hlist)) +if (!hlist_unhashed (&cl->hlist)) {hlist_del (&cl->hlist); +INIT_HLIST_NODE (&cl->hlist); + }
Quoted 2 lines
net/sched/sch_htb.c static int htb_delete(struct Qdisc *sch, · line 1344
Quoted 2 lines
net/sched/sch_htb.c +0
-0if (cl->prio_activity)htb_deactivate (q, cl);
Best regards,
Jarek P.
Quoted 18 lines · On Tue, 7 Nov 2006 07:49:43 +0100 Jarek Poplawski <[email protected]> wrote:
Quoted 17 lines · Stephen Hemminger
Quoted 14 lines · On Mon, 6 Nov 2006 12:33:53 +0100 Jarek Poplawski <[email protected]> wrote:
After
hlist_del()next and pprev pointers are not NULL sohlist_unhashed()doesn't work properly.Signed-off-by Jarek Poplawski <[email protected]>---
diff -Nurp
linux-2.6.19-rc4-git10-/net/sched/sch_htb.clinux-2.6.19-rc4-git10/net/sched/sch_htb.cnet/sched/sch_htb.c +0
-0@@ -1284,8 +1284,10 @@ static void htb_destroy_class(struct Qdi struct htb_class, sibling));
Quoted 8 lines
Quoted 8 lines
net/sched/sch_htb.c static void htb_destroy_class(struct Qdi · line 1290
Quoted 6 lines
net/sched/sch_htb.c +3
-1/* note: this delete may happen twice (see htb_delete) */ -if (!hlist_unhashed (&cl->hlist)) +if (!hlist_unhashed (&cl->hlist)) {hlist_del (&cl->hlist); +INIT_HLIST_NODE (&cl->hlist); + }why not use
hlist_del_init?
Your patch duplicated the code in hlist_del_init(). Why not do:
net/sched/sch_htb.c +2 -4
@@ -1284,8 +1284,7 @@ struct htb_class, sibling));/* note: this delete may happen twice (see htb_delete) */ -if (!hlist_unhashed (&cl->hlist)) -hlist_del (&cl->hlist); +hlist_del_init (&cl->hlist);list_del (&cl->sibling);if (cl->prio_activity)
@@ -1333,8 +1332,7 @@sch_tree_lock (sch);/* delete from hash and active; remainder in destroy_class */ -if (!hlist_unhashed (&cl->hlist)) -hlist_del (&cl->hlist); +hlist_del_init (&cl->hlist);if (cl->prio_activity)htb_deactivate (q, cl);
David Miller
maintainerFrom: Stephen Hemminger <[email protected]>
Date: Tue, 7 Nov 2006 09:50:07 -0800
Quoted 1 line
Your patch duplicated the code in
hlist_del_init(). Why not do:
Indeed, this is the patch I will apply.
Thanks Stephen.
Quoted 2 lines · Stephen Hemminger
On Tue, 7 Nov 2006 07:49:43 +0100
Jarek Poplawski <[email protected]> wrote:
...
Quoted 16 lines
Your patch duplicated the code in
hlist_del_init(). Why not do:net/sched/sch_htb.c +1
-2@@ -1284,8 +1284,7 @@ struct htb_class, sibling));/* note: this delete may happen twice (see htb_delete) */ -if (!hlist_unhashed (&cl->hlist)) -hlist_del (&cl->hlist); +hlist_del_init (&cl->hlist);list_del (&cl->sibling);if (cl->prio_activity)
net/sched/sch_htb.c line 1338
Quoted 9 lines
net/sched/sch_htb.c +1
-2@@ -1333,8 +1332,7 @@sch_tree_lock (sch);/* delete from hash and active; remainder in destroy_class */ -if (!hlist_unhashed (&cl->hlist)) -hlist_del (&cl->hlist); +hlist_del_init (&cl->hlist);if (cl->prio_activity)htb_deactivate (q, cl);
I've understood you first suggestion. But after sending my patch I've found it is also hiding a real problem of excessive deletion in one and possibly more places. So probably this should be done the right way and this hlist_unhashed testing left in BUG_ON only...
Cheers,
Jarek P.