netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pkt_sched: fq: do not hold qdisc lock while allocating memory
@ 2014-03-07  6:57 Eric Dumazet
  2014-03-07 22:04 ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2014-03-07  6:57 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

From: Eric Dumazet <edumazet@google.com>

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: Eric Dumazet <edumazet@google.com>
Fixes: afe4fd062416 ("pkt_sched: fq: Fair Queue packet scheduler")
---
 net/sched/sch_fq.c |   21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/net/sched/sch_fq.c b/net/sched/sch_fq.c
index 08ef7a42c0e4..21e251766eb1 100644
--- a/net/sched/sch_fq.c
+++ b/net/sched/sch_fq.c
@@ -601,6 +601,7 @@ static int fq_resize(struct Qdisc *sch, u32 log)
 {
 	struct fq_sched_data *q = qdisc_priv(sch);
 	struct rb_root *array;
+	void *old_fq_root;
 	u32 idx;
 
 	if (q->fq_root && log == q->fq_trees_log)
@@ -615,13 +616,19 @@ static int fq_resize(struct Qdisc *sch, u32 log)
 	for (idx = 0; idx < (1U << log); idx++)
 		array[idx] = RB_ROOT;
 
-	if (q->fq_root) {
-		fq_rehash(q, q->fq_root, q->fq_trees_log, array, log);
-		fq_free(q->fq_root);
-	}
+	sch_tree_lock(sch);
+
+	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_trees_log = log;
 
+	sch_tree_unlock(sch);
+
+	fq_free(old_fq_root);
+
 	return 0;
 }
 
@@ -697,9 +704,11 @@ static int fq_change(struct Qdisc *sch, struct nlattr *opt)
 		q->flow_refill_delay = usecs_to_jiffies(usecs_delay);
 	}
 
-	if (!err)
+	if (!err) {
+		sch_tree_unlock(sch);
 		err = fq_resize(sch, fq_log);
-
+		sch_tree_lock(sch);
+	}
 	while (sch->q.qlen > sch->limit) {
 		struct sk_buff *skb = fq_dequeue(sch);
 

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] pkt_sched: fq: do not hold qdisc lock while allocating memory
  2014-03-07  6:57 [PATCH] pkt_sched: fq: do not hold qdisc lock while allocating memory Eric Dumazet
@ 2014-03-07 22:04 ` David Miller
  2014-03-07 23:02   ` Eric Dumazet
  0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2014-03-07 22:04 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Thu, 06 Mar 2014 22:57:52 -0800

> From: Eric Dumazet <edumazet@google.com>
> 
> 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: Eric Dumazet <edumazet@google.com>
> Fixes: afe4fd062416 ("pkt_sched: fq: Fair Queue packet scheduler")

Eric I think you can simplify things a little further, and in fact I
think it makes these functions easier to understand.

The fq_resize() part should just grab the lock around the rehash and
the update of q->fq_root and q->fq_trees_log.

fq_change() should only grab the lock around the fq_dequeue() loop
and the call to qdisc_tree_descrease_qlen().  The rest of this
function is just validating netlink attributes and looking at state
that cannot change while we hold RTNL.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pkt_sched: fq: do not hold qdisc lock while allocating memory
  2014-03-07 22:04 ` David Miller
@ 2014-03-07 23:02   ` Eric Dumazet
  2014-03-09  0:10     ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2014-03-07 23:02 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

On Fri, 2014-03-07 at 17:04 -0500, David Miller wrote:

> Eric I think you can simplify things a little further, and in fact I
> think it makes these functions easier to understand.
> 
> The fq_resize() part should just grab the lock around the rehash and
> the update of q->fq_root and q->fq_trees_log.
> 
> fq_change() should only grab the lock around the fq_dequeue() loop
> and the call to qdisc_tree_descrease_qlen().  The rest of this
> function is just validating netlink attributes and looking at state
> that cannot change while we hold RTNL.

Hmm, but all these parameters we change in fq_change() are read by other
cpus doing enqueue()/dequeue().

They are integers, so a race would be not a big deal I guess, but better
add a fat comment then ;)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pkt_sched: fq: do not hold qdisc lock while allocating memory
  2014-03-07 23:02   ` Eric Dumazet
@ 2014-03-09  0:10     ` David Miller
  2014-03-09 14:18       ` Eric Dumazet
  0 siblings, 1 reply; 6+ messages in thread
From: David Miller @ 2014-03-09  0:10 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Fri, 07 Mar 2014 15:02:42 -0800

> On Fri, 2014-03-07 at 17:04 -0500, David Miller wrote:
> 
>> Eric I think you can simplify things a little further, and in fact I
>> think it makes these functions easier to understand.
>> 
>> The fq_resize() part should just grab the lock around the rehash and
>> the update of q->fq_root and q->fq_trees_log.
>> 
>> fq_change() should only grab the lock around the fq_dequeue() loop
>> and the call to qdisc_tree_descrease_qlen().  The rest of this
>> function is just validating netlink attributes and looking at state
>> that cannot change while we hold RTNL.
> 
> Hmm, but all these parameters we change in fq_change() are read by other
> cpus doing enqueue()/dequeue().
> 
> They are integers, so a race would be not a big deal I guess, but better
> add a fat comment then ;)

Good point, this patch as-is is fine, so applied.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pkt_sched: fq: do not hold qdisc lock while allocating memory
  2014-03-09  0:10     ` David Miller
@ 2014-03-09 14:18       ` Eric Dumazet
  2014-03-10 20:18         ` David Miller
  0 siblings, 1 reply; 6+ messages in thread
From: Eric Dumazet @ 2014-03-09 14:18 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

On Sat, 2014-03-08 at 19:10 -0500, David Miller wrote:

> Good point, this patch as-is is fine, so applied.

I see you applied it in net-next, but it should be in net tree

Thanks !

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] pkt_sched: fq: do not hold qdisc lock while allocating memory
  2014-03-09 14:18       ` Eric Dumazet
@ 2014-03-10 20:18         ` David Miller
  0 siblings, 0 replies; 6+ messages in thread
From: David Miller @ 2014-03-10 20:18 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sun, 09 Mar 2014 07:18:26 -0700

> On Sat, 2014-03-08 at 19:10 -0500, David Miller wrote:
> 
>> Good point, this patch as-is is fine, so applied.
> 
> I see you applied it in net-next, but it should be in net tree

My bad, I applied it now to 'net' too and queued it up for -stable.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-03-10 20:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-07  6:57 [PATCH] pkt_sched: fq: do not hold qdisc lock while allocating memory Eric Dumazet
2014-03-07 22:04 ` David Miller
2014-03-07 23:02   ` Eric Dumazet
2014-03-09  0:10     ` David Miller
2014-03-09 14:18       ` Eric Dumazet
2014-03-10 20:18         ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).