From: Patrick McHardy <kaber@trash.net>
To: David Miller <davem@davemloft.net>
Cc: tglx@linutronix.de, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, peterz@infradead.org
Subject: Re: [patch 1/3] net: serialize hrtimer callback in sched_cbq
Date: Tue, 14 Jul 2009 10:22:02 +0200 [thread overview]
Message-ID: <4A5C402A.7090906@trash.net> (raw)
In-Reply-To: <20090712.135555.207096388.davem@davemloft.net>
[-- Attachment #1: Type: text/plain, Size: 1264 bytes --]
David Miller wrote:
> From: Thomas Gleixner <tglx@linutronix.de>
> Date: Thu, 09 Jul 2009 21:59:22 -0000
>
>> The hrtimer callback cbq_undelay() is not serialized against
>> cbq_ovl_delay(). That affects at least q->pmask and q->delay_timer.
>>
>> Lock it proper.
>>
>> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
>
> The problems here are even much deeper than it appears.
>
> First of all, I am to understand that hrtimers run from hardware
> interrupt context, right? If so, all of these datastructures are
> softirq safe only.
>
> And it is not merely the immediate things you see being modified in
> this hrtimer, such as ->pmask etc., it is also the q->active[]
> pointers, the list state for the classes, just about everything in the
> qdisc state is referenced in this hrtimer code path.
>
> I wonder how many queer unexplainable bugs we see because of this.
>
> What should probably happen is that the hrtimer merely fires off work
> at software interrupt context (perhaps a tasklet or similar), and that
> software interrupt code take the qdisc's root lock throughout it's
> execution.
That's my understanding what HRTIMER_SOFTIRQ is used for. I think
simply grabbing the root lock in cbq_undelay() should be fine.
Compile-tested only.
[-- Attachment #2: 01.diff --]
[-- Type: text/x-patch, Size: 1229 bytes --]
commit a790fb8873f1cbe8b9cb48cb368851e30d3ec172
Author: Patrick McHardy <kaber@trash.net>
Date: Tue Jul 14 10:19:47 2009 +0200
net-sched: sch_cbq: fix locking in cbq_undelay()
The hrtimer callback cbq_undelay() is not serialized against
cbq_ovl_delay(). That affects at least q->pmask and q->delay_timer.
Lock it proper.
Based on patch by Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Patrick McHardy <kaber@trash.net>
diff --git a/net/sched/sch_cbq.c b/net/sched/sch_cbq.c
index 23a1676..7c659c6 100644
--- a/net/sched/sch_cbq.c
+++ b/net/sched/sch_cbq.c
@@ -593,12 +593,16 @@ static enum hrtimer_restart cbq_undelay(struct hrtimer *timer)
struct cbq_sched_data *q = container_of(timer, struct cbq_sched_data,
delay_timer);
struct Qdisc *sch = q->watchdog.qdisc;
+ spinlock_t *root_lock;
psched_time_t now;
psched_tdiff_t delay = 0;
unsigned pmask;
now = psched_get_time();
+ root_lock = qdisc_lock(qdisc_root(sch));
+ spin_lock(root_lock);
+
pmask = q->pmask;
q->pmask = 0;
@@ -615,6 +619,7 @@ static enum hrtimer_restart cbq_undelay(struct hrtimer *timer)
delay = tmp;
}
}
+ spin_unlock(root_lock);
if (delay) {
ktime_t time;
next prev parent reply other threads:[~2009-07-14 8:22 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-09 21:59 [patch 0/3] net: Sanitizing hrtimer usage in net/sched/sch_cbq.c Thomas Gleixner
2009-07-09 21:59 ` [patch 1/3] net: serialize hrtimer callback in sched_cbq Thomas Gleixner
2009-07-12 20:55 ` David Miller
2009-07-14 8:22 ` Patrick McHardy [this message]
2009-07-14 8:30 ` Peter Zijlstra
2009-07-14 16:01 ` David Miller
2009-07-14 8:55 ` Thomas Gleixner
2009-07-14 16:00 ` David Miller
2009-07-14 16:28 ` Peter Zijlstra
2009-07-14 16:42 ` Linus Torvalds
2009-07-17 12:14 ` Peter Zijlstra
2009-07-17 13:26 ` Oliver Hartkopp
2009-07-17 15:44 ` Linus Torvalds
2009-07-22 3:18 ` David Miller
2009-07-22 6:29 ` Peter Zijlstra
2009-07-22 12:28 ` [PATCH] softirq: tasklet_hrtimer Peter Zijlstra
2009-07-22 14:01 ` [tip:timers/urgent] softirq: introduce tasklet_hrtimer infrastructure tip-bot for Peter Zijlstra
2009-07-22 15:03 ` [tip:core/urgent] " tip-bot for Peter Zijlstra
2009-07-22 15:39 ` [PATCH] softirq: tasklet_hrtimer David Miller
2009-07-22 16:01 ` Linus Torvalds
2009-07-15 9:56 ` [patch 1/3] net: serialize hrtimer callback in sched_cbq Oliver Hartkopp
2009-07-09 21:59 ` [patch 2/3] net: sanitize hrtimer usage " Thomas Gleixner
2009-07-09 21:59 ` [patch 3/3] net: use HRTIMER_RESTART " Thomas Gleixner
2009-07-10 0:39 ` [patch 0/3] net: Sanitizing hrtimer usage in net/sched/sch_cbq.c David Miller
2009-07-12 20:57 ` David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4A5C402A.7090906@trash.net \
--to=kaber@trash.net \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox