• Andrew Morton's avatar
    [PATCH] Fix race in sched_exit() · 5eef46a9
    Andrew Morton authored
    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().
    5eef46a9
sched.c 73.9 KB