Skip to content

Commit

Permalink
[PATCH] lockdep: fix delayacct locking bug
Browse files Browse the repository at this point in the history
Make the delayacct lock irqsave; this avoids the possible deadlock where
an interrupt is taken while holding the delayacct lock which needs to
take the delayacct lock.

Signed-off-by: Peter Zijlstra <[email protected]>
Acked-by: Oleg Nesterov <[email protected]>
Cc: Balbir Singh <[email protected]>
Cc: Shailabh Nagar <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Peter Zijlstra authored and Linus Torvalds committed Nov 6, 2006
1 parent e5b9a33 commit 64efade
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions kernel/delayacct.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,18 @@ static void delayacct_end(struct timespec *start, struct timespec *end,
{
struct timespec ts;
s64 ns;
unsigned long flags;

do_posix_clock_monotonic_gettime(end);
ts = timespec_sub(*end, *start);
ns = timespec_to_ns(&ts);
if (ns < 0)
return;

spin_lock(&current->delays->lock);
spin_lock_irqsave(&current->delays->lock, flags);
*total += ns;
(*count)++;
spin_unlock(&current->delays->lock);
spin_unlock_irqrestore(&current->delays->lock, flags);
}

void __delayacct_blkio_start(void)
Expand Down Expand Up @@ -104,6 +105,7 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
s64 tmp;
struct timespec ts;
unsigned long t1,t2,t3;
unsigned long flags;

/* Though tsk->delays accessed later, early exit avoids
* unnecessary returning of other data
Expand Down Expand Up @@ -136,14 +138,14 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)

/* zero XXX_total, non-zero XXX_count implies XXX stat overflowed */

spin_lock(&tsk->delays->lock);
spin_lock_irqsave(&tsk->delays->lock, flags);
tmp = d->blkio_delay_total + tsk->delays->blkio_delay;
d->blkio_delay_total = (tmp < d->blkio_delay_total) ? 0 : tmp;
tmp = d->swapin_delay_total + tsk->delays->swapin_delay;
d->swapin_delay_total = (tmp < d->swapin_delay_total) ? 0 : tmp;
d->blkio_count += tsk->delays->blkio_count;
d->swapin_count += tsk->delays->swapin_count;
spin_unlock(&tsk->delays->lock);
spin_unlock_irqrestore(&tsk->delays->lock, flags);

done:
return 0;
Expand All @@ -152,11 +154,12 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
__u64 __delayacct_blkio_ticks(struct task_struct *tsk)
{
__u64 ret;
unsigned long flags;

spin_lock(&tsk->delays->lock);
spin_lock_irqsave(&tsk->delays->lock, flags);
ret = nsec_to_clock_t(tsk->delays->blkio_delay +
tsk->delays->swapin_delay);
spin_unlock(&tsk->delays->lock);
spin_unlock_irqrestore(&tsk->delays->lock, flags);
return ret;
}

0 comments on commit 64efade

Please sign in to comment.