Fix fixpoint divide exception in acct_update_integrals
PATCH 1/1 Fix fixpoint divide exception in acct_update_integrals
From: Heiko Carstens <[email protected]>
Frans Pop reported the crash below when running an s390 kernel under Hercules:
17180168.889947! Kernel BUG at 000738b4 verbose debug info unavailable! 17180168.890213! fixpoint divide exception: 0009 #1! SMP 17180168.890487! Modules linked in: nfs lockd nfs_acl sunrpc ctcm fsm tape_34xx
cu3088 tape ccwgroup tape_class ext3 jbd mbcache dm_mirror dm_log dm_snapshot dm_mod dasd_eckd_mod dasd_mod
17180168.891891! CPU: 0 Not tainted 2.6.27.19 #13
17180168.892116! Process awk (pid: 2069, task: 0f9ed9b8, ksp: 0f4f7d18) 17180168.892371! Krnl PSW : 070c1000 800738b4 (acct_update_integrals+0x4c/0x118)
17180168.892830! R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:0 CC:1 PM:0
17180168.893115! Krnl GPRS: 00000000 000007d0 7fffffff fffff830
17180168.893376! 00000000 ffffffff 00000002 0f9ed9b8 17180168.893621! 00000000 00008ca0 00000000 0f9ed9b8 17180168.893873! 0f9edda4 8007386e 0f4f7ec8 0f4f7e98 17180168.894881! Krnl Code: 800738aa: a71807d0 lhi %r1,2000 17180168.895245! 800738ae: 8c200001 srdl %r2,1 17180168.895563! 800738b2: 1d21 dr %r2,%r1 17180168.895936! >800738b4: 5810d10e l %r1,270(%r13) 17180168.896246! 800738b8: 1823 lr %r2,%r3 17180168.896598! 800738ba: 4130f060 la %r3,96(%r15) 17180168.896913! 800738be: 0de1 basr %r14,%r1 17180168.897283! 800738c0: 5800f060 l %r0,96(%r15) 17180168.897517! Call Trace: 17180168.897656! ( <000000000004fdea>! blocking_notifier_call_chain+0x1e/0x2c) 17180168.897987! <0000000000038502>! do_exit+0x106/0x7c0 17180168.898275! <0000000000038c36>! do_group_exit+0x7a/0xb4 17180168.898570! <0000000000038c8e>! SyS_exit_group+0x1e/0x30 17180168.898869! <0000000000021c28>! sysc_do_restart+0x12/0x16 17180168.899173! <0000000077e7e924>! 0x77e7e924
Reason for this is that cpu time accounting usually only happens from interrupt context, but acct_update_integrals gets also called from process context with interrupts enabled.
So in acct_update_integrals we may end up with the following scenario:
Between reading tsk->stime/tsk->utime and tsk->acct_timexpd an interrupt happens which updates accouting values. This causes acct_timexpd to be greater than the former stime + utime.
The subsequent calculation of
dtime = cputime_sub(time, tsk->acct_timexpd);
will be negative and the division performed by
cputime_to_jiffies(dtime)
will generate an exception since the result won't fit into a 32 bit register.
In order to fix this just always disable interrupts while accessing any of the accounting values.
Reported by: Frans Pop <[email protected]>
Tested by: Frans Pop <[email protected]>
--- kernel/tsacct.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/tsacct.c +5 -1
@@ -122,8 +122,10 @@ void acct_update_integrals(struct task_sif (likely (tsk->mm)) {cputime_t time, dtime;struct timeval value; +unsigned long flags;u64 delta; +local_irq_save (flags); time = tsk->stime + tsk->utime; dtime =cputime_sub (time, tsk->acct_timexpd);jiffies_to_timeval (cputime_to_jiffies (dtime), &value);
@@ -131,10 +133,12 @@ void acct_update_integrals(struct task_s delta = delta *USEC_PER_SEC + value.tv_usec;if (delta ==0 ) -return ; + goto out; tsk->acct_timexpd = time; tsk->acct_rss_mem1 += delta *get_mm_rss (tsk->mm); tsk->acct_vm_mem1 += delta * tsk->mm->total_vm; + out: +local_irq_restore (flags); } }
Quoted 19 lines · On Mon, 9 Mar 2009 13:31:59 +0100 Heiko Carstens <[email protected]>…
...
kernel/tsacct.c +2
-0@@ -122,8 +122,10 @@ void acct_update_integrals(struct task_sif (likely (tsk->mm)) {cputime_t time, dtime;struct timeval value; +unsigned long flags;u64 delta; +local_irq_save (flags); time = tsk->stime + tsk->utime; dtime =cputime_sub (time, tsk->acct_timexpd);jiffies_to_timeval (cputime_to_jiffies (dtime), &value);@@ -131,10 +133,12 @@ void acct_update_integrals(struct task_s delta = delta *USEC_PER_SEC + value.tv_usec;if (delta ==0 )
kernel/tsacct.c void acct_update_integrals(struct task_s · line 144
Quoted 10 lines
kernel/tsacct.c +3
-1-return ; + goto out; tsk->acct_timexpd = time; tsk->acct_rss_mem1 += delta *get_mm_rss (tsk->mm); tsk->acct_vm_mem1 += delta * tsk->mm->total_vm; + out: +local_irq_restore (flags); } }
hrm, so we use local-interrupt protection for <something>.
I wonder what we can do to reduce the probability of bugs of this nature being introduced in the future?