[PATCH 2/2] blk-mq: use get_cpu/put_cpu instead of preempt_disable/preempt_enable

From: Paolo Bonzini
Date: Fri Nov 07 2014 - 17:04:21 EST


blk-mq is using preempt_disable/enable in order to ensure that the
queue runners are placed on the right CPU. This does not work with
the RT patches, because __blk_mq_run_hw_queue takes a non-raw
spinlock with the preemption-disabled region. If there is contention
on the lock, this violates the rules for preemption-disabled regions.

While this should be easily fixable within the RT patches just by doing
migrate_disable/enable, we can do better and document _why_ this
particular region runs with disabled preemption. After the previous
patch, it is trivial to switch it to get/put_cpu; the RT patches then
can change it to get_cpu_light, which lets virtio-blk run under RT
kernels.

Cc: Jens Axboe <axboe@xxxxxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
Reported-by: Clark Williams <williams@xxxxxxxxxx>
Tested-by: Clark Williams <williams@xxxxxxxxxx>
Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
---
block/blk-mq.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/block/blk-mq.c b/block/blk-mq.c
index c6192ba78950..a958851d9dd2 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -829,14 +829,14 @@ void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async)
return;

if (!async) {
- preempt_disable();
- if (cpumask_test_cpu(smp_processor_id(), hctx->cpumask)) {
+ int cpu = get_cpu();
+ if (cpumask_test_cpu(cpu, hctx->cpumask)) {
__blk_mq_run_hw_queue(hctx);
- preempt_enable();
+ put_cpu();
return;
}

- preempt_enable();
+ put_cpu();
}

if (hctx->queue->nr_hw_queues == 1)
--
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/