Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cfq-iosched: fix an oops caused by slab leak

I got below oops when unloading cfq-iosched. Considering scenario:
queue A merge to B, C merge to D and B will be merged to D. Before B is merged
to D, we do split B. We should put B's reference for D.

[ 807.768536] =============================================================================
[ 807.768539] BUG cfq_queue: Objects remaining on kmem_cache_close()
[ 807.768541] -----------------------------------------------------------------------------
[ 807.768543]
[ 807.768546] INFO: Slab 0xffffea0003e6b4e0 objects=26 used=1 fp=0xffff88011d584fd8 flags=0x200000000004082
[ 807.768550] Pid: 5946, comm: rmmod Tainted: G W 2.6.34-07097-gf4b87de-dirty #724
[ 807.768552] Call Trace:
[ 807.768560] [<ffffffff81104e8d>] slab_err+0x8f/0x9d
[ 807.768564] [<ffffffff811059e1>] ? flush_cpu_slab+0x0/0x93
[ 807.768569] [<ffffffff8164be52>] ? add_preempt_count+0xe/0xca
[ 807.768572] [<ffffffff8164bd9c>] ? sub_preempt_count+0xe/0xb6
[ 807.768577] [<ffffffff81648871>] ? _raw_spin_unlock+0x15/0x30
[ 807.768580] [<ffffffff8164bd9c>] ? sub_preempt_count+0xe/0xb6
[ 807.768584] [<ffffffff811061bc>] list_slab_objects+0x9b/0x19f
[ 807.768588] [<ffffffff8164bf0a>] ? add_preempt_count+0xc6/0xca
[ 807.768591] [<ffffffff81109e27>] kmem_cache_destroy+0x13f/0x21d
[ 807.768597] [<ffffffffa000ff13>] cfq_slab_kill+0x1a/0x43 [cfq_iosched]
[ 807.768601] [<ffffffffa000ffcf>] cfq_exit+0x93/0x9e [cfq_iosched]
[ 807.768606] [<ffffffff810973a2>] sys_delete_module+0x1b1/0x219
[ 807.768612] [<ffffffff8102fb5b>] system_call_fastpath+0x16/0x1b
[ 807.768618] INFO: Object 0xffff88011d584618 @offset=1560
[ 807.768622] INFO: Allocated in cfq_get_queue+0x11e/0x274 [cfq_iosched] age=7173 cpu=1 pid=5496
[ 807.768626] =============================================================================

Cc: stable@kernel.org
Signed-off-by: Shaohua Li <shaohua.li@intel.com>
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>

authored by

Shaohua Li and committed by
Jens Axboe
d02a2c07 b9598db3

+14 -6
+14 -6
block/cfq-iosched.c
··· 2560 2560 __call_for_each_cic(ioc, cic_free_func); 2561 2561 } 2562 2562 2563 - static void cfq_exit_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq) 2563 + static void cfq_put_cooperator(struct cfq_queue *cfqq) 2564 2564 { 2565 2565 struct cfq_queue *__cfqq, *next; 2566 - 2567 - if (unlikely(cfqq == cfqd->active_queue)) { 2568 - __cfq_slice_expired(cfqd, cfqq, 0); 2569 - cfq_schedule_dispatch(cfqd); 2570 - } 2571 2566 2572 2567 /* 2573 2568 * If this queue was scheduled to merge with another queue, be ··· 2579 2584 cfq_put_queue(__cfqq); 2580 2585 __cfqq = next; 2581 2586 } 2587 + } 2588 + 2589 + static void cfq_exit_cfqq(struct cfq_data *cfqd, struct cfq_queue *cfqq) 2590 + { 2591 + if (unlikely(cfqq == cfqd->active_queue)) { 2592 + __cfq_slice_expired(cfqd, cfqq, 0); 2593 + cfq_schedule_dispatch(cfqd); 2594 + } 2595 + 2596 + cfq_put_cooperator(cfqq); 2582 2597 2583 2598 cfq_put_queue(cfqq); 2584 2599 } ··· 3541 3536 } 3542 3537 3543 3538 cic_set_cfqq(cic, NULL, 1); 3539 + 3540 + cfq_put_cooperator(cfqq); 3541 + 3544 3542 cfq_put_queue(cfqq); 3545 3543 return NULL; 3546 3544 }