From: Andrew Morton <akpm@osdl.org>
To: linas@austin.ibm.com
Cc: linux-kernel@vger.kernel.org
Subject: Re: PATCH: Race in 2.6.0-test2 timer code
Date: Tue, 29 Jul 2003 13:56:43 -0700 [thread overview]
Message-ID: <20030729135643.2e9b74bc.akpm@osdl.org> (raw)
In-Reply-To: <20030729104135.A48598@forte.austin.ibm.com>
linas@austin.ibm.com wrote:
>
> I have been chasing a pointer corruption bug in the timer code, and
> found the following race in the mod_timer() routine. I am still
> testing to see if this fixes my bug ...
Andrea says that we need to take the per-timer lock in add_timer() and
del_timer(), but I haven't yet got around to working out why.
Does this (untested) patch fix whatever race it is which you are observing?
25-akpm/kernel/timer.c | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)
diff -puN kernel/timer.c~timer-locking-fixes kernel/timer.c
--- 25/kernel/timer.c~timer-locking-fixes Tue Jul 29 13:52:21 2003
+++ 25-akpm/kernel/timer.c Tue Jul 29 13:54:55 2003
@@ -167,10 +167,12 @@ void add_timer(struct timer_list *timer)
check_timer(timer);
- spin_lock_irqsave(&base->lock, flags);
+ spin_lock_irqsave(&timer->lock, flags);
+ spin_lock(&base->lock);
internal_add_timer(base, timer);
timer->base = base;
- spin_unlock_irqrestore(&base->lock, flags);
+ spin_unlock(&base->lock);
+ spin_unlock_irqrestore(&timer->lock, flags);
put_cpu();
}
@@ -190,10 +192,12 @@ void add_timer_on(struct timer_list *tim
check_timer(timer);
- spin_lock_irqsave(&base->lock, flags);
+ spin_lock_irqsave(&timer->lock, flags);
+ spin_lock(&base->lock);
internal_add_timer(base, timer);
timer->base = base;
- spin_unlock_irqrestore(&base->lock, flags);
+ spin_unlock(&base->lock);
+ spin_unlock_irqrestore(&timer->lock, flags);
}
/***
@@ -298,19 +302,22 @@ int del_timer(struct timer_list *timer)
tvec_base_t *base;
check_timer(timer);
-
+ spin_lock_irqsave(&timer->lock, flags);
repeat:
base = timer->base;
- if (!base)
+ if (!base) {
+ spin_unlock_irqrestore(&timer->lock, flags);
return 0;
- spin_lock_irqsave(&base->lock, flags);
+ }
+ spin_lock(&base, flags);
if (base != timer->base) {
- spin_unlock_irqrestore(&base->lock, flags);
+ spin_unlock(&base->lock);
goto repeat;
}
list_del(&timer->entry);
timer->base = NULL;
- spin_unlock_irqrestore(&base->lock, flags);
+ spin_unlock(&base->lock);
+ spin_unlock_irqrestore(&timer->lock, flags);
return 1;
}
_
next prev parent reply other threads:[~2003-07-29 21:13 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-07-29 15:41 PATCH: Race in 2.6.0-test2 timer code linas
2003-07-29 20:56 ` Andrew Morton [this message]
2003-07-30 5:57 ` Ingo Molnar
2003-07-30 6:36 ` Andrew Morton
2003-07-30 7:07 ` Ingo Molnar
2003-07-30 7:34 ` Andrea Arcangeli
2003-07-30 7:34 ` Ingo Molnar
2003-07-30 8:28 ` Andrea Arcangeli
2003-07-30 10:31 ` Ingo Molnar
2003-07-30 11:16 ` Andrea Arcangeli
2003-07-30 11:49 ` Ingo Molnar
2003-07-30 12:34 ` Andrea Arcangeli
2003-07-30 21:18 ` linas
2003-07-30 22:06 ` Andrea Arcangeli
2003-07-30 22:17 ` Andrea Arcangeli
2003-07-31 7:04 ` Ingo Molnar
2003-07-30 21:19 ` Andrea Arcangeli
2003-07-30 23:43 ` linas
2003-07-30 23:56 ` Andrea Arcangeli
2003-07-30 23:54 ` Andrew Morton
2003-07-31 0:16 ` Andrea Arcangeli
2003-07-31 17:23 ` linas
2003-08-01 6:27 ` Ingo Molnar
2003-07-30 7:40 ` Ingo Molnar
2003-07-30 8:37 ` Andrea Arcangeli
2003-07-30 10:34 ` Ingo Molnar
2003-07-30 10:51 ` Andrew Morton
2003-07-30 11:28 ` Andrea Arcangeli
2003-07-30 11:22 ` Andrea Arcangeli
2003-07-30 20:05 ` linas
2003-07-31 6:50 ` Ingo Molnar
2003-07-31 22:56 ` linas
2003-08-01 6:23 ` Ingo Molnar
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=20030729135643.2e9b74bc.akpm@osdl.org \
--to=akpm@osdl.org \
--cc=linas@austin.ibm.com \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).