Commit 36d8aca1 authored by Eric Dumazet's avatar Eric Dumazet Committed by Jiri Slaby

pkt_sched: fq: do not hold qdisc lock while allocating memory

[ Upstream commit 2d8d40af ]

Resizing fq hash table allocates memory while holding qdisc spinlock,
with BH disabled.

This is definitely not good, as allocation might sleep.

We can drop the lock and get it when needed, we hold RTNL so no other
changes can happen at the same time.
Signed-off-by: default avatarEric Dumazet <edumazet@google.com>
Fixes: afe4fd06 ("pkt_sched: fq: Fair Queue packet scheduler")
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarJiri Slaby <jslaby@suse.cz>
parent 1780772e
...@@ -577,9 +577,11 @@ static void fq_rehash(struct fq_sched_data *q, ...@@ -577,9 +577,11 @@ static void fq_rehash(struct fq_sched_data *q,
q->stat_gc_flows += fcnt; q->stat_gc_flows += fcnt;
} }
static int fq_resize(struct fq_sched_data *q, u32 log) static int fq_resize(struct Qdisc *sch, u32 log)
{ {
struct fq_sched_data *q = qdisc_priv(sch);
struct rb_root *array; struct rb_root *array;
void *old_fq_root;
u32 idx; u32 idx;
if (q->fq_root && log == q->fq_trees_log) if (q->fq_root && log == q->fq_trees_log)
...@@ -592,13 +594,19 @@ static int fq_resize(struct fq_sched_data *q, u32 log) ...@@ -592,13 +594,19 @@ static int fq_resize(struct fq_sched_data *q, u32 log)
for (idx = 0; idx < (1U << log); idx++) for (idx = 0; idx < (1U << log); idx++)
array[idx] = RB_ROOT; array[idx] = RB_ROOT;
if (q->fq_root) { sch_tree_lock(sch);
fq_rehash(q, q->fq_root, q->fq_trees_log, array, log);
kfree(q->fq_root); old_fq_root = q->fq_root;
} if (old_fq_root)
fq_rehash(q, old_fq_root, q->fq_trees_log, array, log);
q->fq_root = array; q->fq_root = array;
q->fq_trees_log = log; q->fq_trees_log = log;
sch_tree_unlock(sch);
kfree(old_fq_root);
return 0; return 0;
} }
...@@ -674,9 +682,11 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt) ...@@ -674,9 +682,11 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
q->flow_refill_delay = usecs_to_jiffies(usecs_delay); q->flow_refill_delay = usecs_to_jiffies(usecs_delay);
} }
if (!err) if (!err) {
err = fq_resize(q, fq_log); sch_tree_unlock(sch);
err = fq_resize(sch, fq_log);
sch_tree_lock(sch);
}
while (sch->q.qlen > sch->limit) { while (sch->q.qlen > sch->limit) {
struct sk_buff *skb = fq_dequeue(sch); struct sk_buff *skb = fq_dequeue(sch);
...@@ -722,7 +732,7 @@ static int fq_init(struct Qdisc *sch, struct nlattr *opt) ...@@ -722,7 +732,7 @@ static int fq_init(struct Qdisc *sch, struct nlattr *opt)
if (opt) if (opt)
err = fq_change(sch, opt); err = fq_change(sch, opt);
else else
err = fq_resize(q, q->fq_trees_log); err = fq_resize(sch, q->fq_trees_log);
return err; return err;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment