* [PATCH] netem: dont call vfree() under spinlock and BH disabled
@ 2011-12-24 5:28 Eric Dumazet
2011-12-24 19:18 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Eric Dumazet @ 2011-12-24 5:28 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Stephen Hemminger
commit 6373a9a286 (netem: use vmalloc for distribution table) added a
regression, since vfree() is called while holding a spinlock and BH
being disabled.
Fix this by doing the pointers swap in critical section, and freeing
after spinlock release.
Also add __GFP_NOWARN to the kmalloc() try, since we fallback to
vmalloc().
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
net/sched/sch_netem.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
index eb3b9a8..a4ab207 100644
--- a/net/sched/sch_netem.c
+++ b/net/sched/sch_netem.c
@@ -488,7 +488,7 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
return -EINVAL;
s = sizeof(struct disttable) + n * sizeof(s16);
- d = kmalloc(s, GFP_KERNEL);
+ d = kmalloc(s, GFP_KERNEL | __GFP_NOWARN);
if (!d)
d = vmalloc(s);
if (!d)
@@ -501,9 +501,10 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
root_lock = qdisc_root_sleeping_lock(sch);
spin_lock_bh(root_lock);
- dist_free(q->delay_dist);
- q->delay_dist = d;
+ swap(q->delay_dist, d);
spin_unlock_bh(root_lock);
+
+ dist_free(d);
return 0;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] netem: dont call vfree() under spinlock and BH disabled
2011-12-24 5:28 [PATCH] netem: dont call vfree() under spinlock and BH disabled Eric Dumazet
@ 2011-12-24 19:18 ` Stephen Hemminger
2011-12-24 21:10 ` David Miller
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2011-12-24 19:18 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David Miller, netdev
On Sat, 24 Dec 2011 06:28:51 +0100
Eric Dumazet <eric.dumazet@gmail.com> wrote:
> commit 6373a9a286 (netem: use vmalloc for distribution table) added a
> regression, since vfree() is called while holding a spinlock and BH
> being disabled.
>
> Fix this by doing the pointers swap in critical section, and freeing
> after spinlock release.
>
> Also add __GFP_NOWARN to the kmalloc() try, since we fallback to
> vmalloc().
>
> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
> ---
> net/sched/sch_netem.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/net/sched/sch_netem.c b/net/sched/sch_netem.c
> index eb3b9a8..a4ab207 100644
> --- a/net/sched/sch_netem.c
> +++ b/net/sched/sch_netem.c
> @@ -488,7 +488,7 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
> return -EINVAL;
>
> s = sizeof(struct disttable) + n * sizeof(s16);
> - d = kmalloc(s, GFP_KERNEL);
> + d = kmalloc(s, GFP_KERNEL | __GFP_NOWARN);
> if (!d)
> d = vmalloc(s);
> if (!d)
> @@ -501,9 +501,10 @@ static int get_dist_table(struct Qdisc *sch, const struct nlattr *attr)
> root_lock = qdisc_root_sleeping_lock(sch);
>
> spin_lock_bh(root_lock);
> - dist_free(q->delay_dist);
> - q->delay_dist = d;
> + swap(q->delay_dist, d);
> spin_unlock_bh(root_lock);
> +
> + dist_free(d);
> return 0;
> }
Acked-by: Stephen Hemminger <shemminger@vyatta.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] netem: dont call vfree() under spinlock and BH disabled
2011-12-24 19:18 ` Stephen Hemminger
@ 2011-12-24 21:10 ` David Miller
0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2011-12-24 21:10 UTC (permalink / raw)
To: shemminger; +Cc: eric.dumazet, netdev
From: Stephen Hemminger <shemminger@vyatta.com>
Date: Sat, 24 Dec 2011 11:18:54 -0800
> On Sat, 24 Dec 2011 06:28:51 +0100
> Eric Dumazet <eric.dumazet@gmail.com> wrote:
>
>> commit 6373a9a286 (netem: use vmalloc for distribution table) added a
>> regression, since vfree() is called while holding a spinlock and BH
>> being disabled.
>>
>> Fix this by doing the pointers swap in critical section, and freeing
>> after spinlock release.
>>
>> Also add __GFP_NOWARN to the kmalloc() try, since we fallback to
>> vmalloc().
>>
>> Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
...
> Acked-by: Stephen Hemminger <shemminger@vyatta.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-12-24 21:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-24 5:28 [PATCH] netem: dont call vfree() under spinlock and BH disabled Eric Dumazet
2011-12-24 19:18 ` Stephen Hemminger
2011-12-24 21:10 ` 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).