Re: BKL backtraces - was: Re: [patch] voluntary-preempt-2.6.9-rc2-mm1-S1

From: Ingo Molnar
Date: Tue Sep 21 2004 - 02:18:41 EST



* K.R. Foley <kr@xxxxxxxxxx> wrote:

> All of these were generated while booting:
>
> Sep 20 19:45:10 porky kernel: using smp_processor_id() in preemptible
> code: modprobe/1019
> Sep 20 19:45:10 porky kernel: [<c011c58e>] smp_processor_id+0x8e/0xa0
> Sep 20 19:45:10 porky kernel: [<c013ace6>] module_unload_init+0x46/0x70
> Sep 20 19:45:10 porky kernel: [<c013ce58>] load_module+0x598/0xb10
> Sep 20 19:45:10 porky kernel: [<c013d438>] sys_init_module+0x68/0x280
> Sep 20 19:45:10 porky kernel: [<c01066b9>] sysenter_past_esp+0x52/0x71
>
> The above one of course repeats on each module load.

ok, this is a harmless false positive - the attached patch fixes it.

> Sep 20 19:45:10 porky kernel: using smp_processor_id() in preemptible
> code: X/1017
> Sep 20 19:45:10 porky kernel: [<c011c58e>] smp_processor_id+0x8e/0xa0
> Sep 20 19:45:10 porky kernel: [<c01d6c15>] add_timer_randomness+0x125/0x150
> Sep 20 19:45:10 porky kernel: [<c01d6c9e>] add_mouse_randomness+0x1e/0x30
> Sep 20 19:45:10 porky kernel: [<c022b835>] input_event+0x55/0x3f0

> Sep 20 19:45:10 porky kernel: [<c01e1390>] vt_ioctl+0x0/0x1ad0
> Sep 20 19:45:10 porky kernel: [<c01dc08b>] tty_ioctl+0x37b/0x4d0
> Sep 20 19:45:10 porky kernel: [<c0175034>] sys_ioctl+0xe4/0x240
> Sep 20 19:45:10 porky kernel: [<c01066b9>] sysenter_past_esp+0x52/0x71
>
> The X one above repeats once also.

aha! This is a real one, fixed by the second patch. This piece of code
relied on add_timer_randomness() always being called with preemption
disabled.

these fixes will show up in -S2.

Ingo
--- linux/kernel/module.c.orig
+++ linux/kernel/module.c
@@ -394,7 +394,7 @@ static void module_unload_init(struct mo
for (i = 0; i < NR_CPUS; i++)
local_set(&mod->ref[i].count, 0);
/* Hold reference count during initialization. */
- local_set(&mod->ref[smp_processor_id()].count, 1);
+ local_set(&mod->ref[_smp_processor_id()].count, 1);
/* Backwards compatibility macros put refcount during init. */
mod->waiter = current;
}
--- linux/drivers/char/random.c.orig
+++ linux/drivers/char/random.c
@@ -807,10 +807,11 @@ static void add_timer_randomness(struct
long delta, delta2, delta3;
int entropy = 0;

+ preempt_disable();
/* if over the trickle threshold, use only 1 in 4096 samples */
if ( random_state->entropy_count > trickle_thresh &&
(__get_cpu_var(trickle_count)++ & 0xfff))
- return;
+ goto out;

/*
* Use get_cycles() if implemented, otherwise fall back to
@@ -861,6 +862,8 @@ static void add_timer_randomness(struct
entropy = int_ln_12bits(delta);
}
batch_entropy_store(num, time, entropy);
+out:
+ preempt_enable();
}

void add_keyboard_randomness(unsigned char scancode)