block: BUG: using smp_processor_id() in preemptible [00000000] code

From: Ming Lei
Date: Tue Jul 26 2011 - 00:51:29 EST


Hi,

The bug is observed in -next-20110725, follows the stack trace[1], and
seems the attachment patch can fix the bug.



[1], stack trace

[ 22.247222] BUG: using smp_processor_id() in preemptible [00000000]
code: kjournald/514
[ 22.255737] caller is __make_request+0x1b8/0x308
[ 22.260681] [<c0019f44>] (unwind_backtrace+0x0/0xe8) from
[<c024b4cc>] (debug_smp_processor_id+0xbc/0xf0)
[ 22.270751] [<c024b4cc>] (debug_smp_processor_id+0xbc/0xf0) from
[<c0223d14>] (__make_request+0x1b8/0x308)
[ 22.280944] [<c0223d14>] (__make_request+0x1b8/0x308) from
[<c02215ac>] (generic_make_request+0x4dc/0x558)
[ 22.291107] [<c02215ac>] (generic_make_request+0x4dc/0x558) from
[<c022173c>] (submit_bio+0x114/0x138)
[ 22.300903] [<c022173c>] (submit_bio+0x114/0x138) from [<c011f504>]
(submit_bh+0x148/0x16c)
[ 22.309692] [<c011f504>] (submit_bh+0x148/0x16c) from [<c0121ed8>]
(__sync_dirty_buffer+0x88/0xd8)
[ 22.319122] [<c0121ed8>] (__sync_dirty_buffer+0x88/0xd8) from
[<c01aff78>] (journal_commit_transaction+0x1198/0
x1688)
[ 22.330322] [<c01aff78>] (journal_commit_transaction+0x1198/0x1688)
from [<c01b4034>] (kjournald+0xb4/0x224)
[ 22.340667] [<c01b4034>] (kjournald+0xb4/0x224) from [<c0069ea0>]
(kthread+0x8c/0x94)
[ 22.348937] [<c0069ea0>] (kthread+0x8c/0x94) from [<c00137f8>]
(kernel_thread_exit+0x0/0x8)


thanks,
--
Ming Lei
diff --git a/block/blk-core.c b/block/blk-core.c
index f8cb099..7e98677 100644
--- a/block/blk-core.c
+++ b/block/blk-core.c
@@ -1282,8 +1282,10 @@ get_rq:
init_request_from_bio(req, bio);

if (test_bit(QUEUE_FLAG_SAME_COMP, &q->queue_flags) ||
- bio_flagged(bio, BIO_CPU_AFFINE))
- req->cpu = smp_processor_id();
+ bio_flagged(bio, BIO_CPU_AFFINE)) {
+ req->cpu = get_cpu();
+ put_cpu();
+ }

plug = current->plug;
if (plug) {