]> git.hungrycats.org Git - linux/commit
[PATCH] Fix race in sched_exit()
authorAndrew Morton <akpm@osdl.org>
Wed, 4 Feb 2004 02:30:23 +0000 (18:30 -0800)
committerLinus Torvalds <torvalds@home.osdl.org>
Wed, 4 Feb 2004 02:30:23 +0000 (18:30 -0800)
commit5eef46a913e088355ee050c3618f92c2f6e84de9
tree041ed9ee81210f8bda5e392410b729529137694e
parent7508df7c4a61c622fc48c29320f968c0408d3796
[PATCH] Fix race in sched_exit()

From: Martin Schwidefsky <schwidefsky@de.ibm.com>

Fix a race on sleep_avg in sched_exit().

The symptom I saw on 64-bit s390 has been a fixpoint divide exception
because sleep_avg had a value > NS_MAX_SLEEP_AVG.  I tracked it down and
the problem is sched_exit which recalculates the parents sleep average
without taking the runqueue lock.  schedule() subtracts run_time from
sleep_avg of the previous process.  This can turn out negative and is
corrected shortly after the subtraction but that is already too late.
sched_exit() already read the negative value an miscalculated the parents
sleep_avg -> bang.

I fixed this by adding task_rq_lock/task_rq_unlock to sched_exit().
kernel/sched.c