All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH REPOST] blk-mq: Don't disable preemption around __blk_mq_run_hw_queue().
@ 2022-06-21  7:39 Sebastian Andrzej Siewior
  2022-06-21  7:56 ` Ming Lei
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-06-21  7:39 UTC (permalink / raw)
  To: linux-block; +Cc: Jens Axboe, Thomas Gleixner

__blk_mq_delay_run_hw_queue() disables preemption to get a stable
current CPU number and then invokes __blk_mq_run_hw_queue() if the CPU
number is part the mask.

__blk_mq_run_hw_queue() acquires a spin_lock_t which is a sleeping lock
on PREEMPT_RT and can't be acquired with disabled preemption.

If it is important that the current CPU matches the requested CPU mask
and that the context does not migrate to another CPU while
__blk_mq_run_hw_queue() is invoked then it possible to achieve this by
disabling migration and keeping the context preemptible.

Disable only migration while testing the CPU mask and invoking
__blk_mq_run_hw_queue().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lore.kernel.org/r/YnQHqx/5+54jd+U+@linutronix.de
Link: https://lore.kernel.org/r/YqISXf6GAQeWqcR+@linutronix.de
---
 block/blk-mq.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2083,14 +2083,14 @@ static void __blk_mq_delay_run_hw_queue(
 		return;
 
 	if (!async && !(hctx->flags & BLK_MQ_F_BLOCKING)) {
-		int cpu = get_cpu();
-		if (cpumask_test_cpu(cpu, hctx->cpumask)) {
+		migrate_disable();
+		if (cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask)) {
 			__blk_mq_run_hw_queue(hctx);
-			put_cpu();
+			migrate_enable();
 			return;
 		}
 
-		put_cpu();
+		migrate_enable();
 	}
 
 	kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH REPOST] blk-mq: Don't disable preemption around __blk_mq_run_hw_queue().
  2022-06-21  7:39 [PATCH REPOST] blk-mq: Don't disable preemption around __blk_mq_run_hw_queue() Sebastian Andrzej Siewior
@ 2022-06-21  7:56 ` Ming Lei
  2022-06-22  8:25   ` [PATCH v2] " Sebastian Andrzej Siewior
  0 siblings, 1 reply; 5+ messages in thread
From: Ming Lei @ 2022-06-21  7:56 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-block, Jens Axboe, Thomas Gleixner

On Tue, Jun 21, 2022 at 09:39:19AM +0200, Sebastian Andrzej Siewior wrote:
> __blk_mq_delay_run_hw_queue() disables preemption to get a stable
> current CPU number and then invokes __blk_mq_run_hw_queue() if the CPU
> number is part the mask.
> 
> __blk_mq_run_hw_queue() acquires a spin_lock_t which is a sleeping lock
> on PREEMPT_RT and can't be acquired with disabled preemption.
> 
> If it is important that the current CPU matches the requested CPU mask
> and that the context does not migrate to another CPU while
> __blk_mq_run_hw_queue() is invoked then it possible to achieve this by
> disabling migration and keeping the context preemptible.
> 
> Disable only migration while testing the CPU mask and invoking
> __blk_mq_run_hw_queue().
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> Link: https://lore.kernel.org/r/YnQHqx/5+54jd+U+@linutronix.de
> Link: https://lore.kernel.org/r/YqISXf6GAQeWqcR+@linutronix.de
> ---
>  block/blk-mq.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -2083,14 +2083,14 @@ static void __blk_mq_delay_run_hw_queue(
>  		return;
>  
>  	if (!async && !(hctx->flags & BLK_MQ_F_BLOCKING)) {
> -		int cpu = get_cpu();
> -		if (cpumask_test_cpu(cpu, hctx->cpumask)) {
> +		migrate_disable();
> +		if (cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask)) {
>  			__blk_mq_run_hw_queue(hctx);
> -			put_cpu();
> +			migrate_enable();

I think you can replace it with raw_smp_processor_id() directly without
disabling migration.

Both async run queue and direct issue can run on cpu not on hctx->cpumask,
so it is fine for sync run queue too. 

Thanks,
Ming


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] blk-mq: Don't disable preemption around __blk_mq_run_hw_queue().
  2022-06-21  7:56 ` Ming Lei
@ 2022-06-22  8:25   ` Sebastian Andrzej Siewior
  2022-06-22  8:35     ` Ming Lei
  2022-06-22 17:46     ` Jens Axboe
  0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-06-22  8:25 UTC (permalink / raw)
  To: Ming Lei; +Cc: linux-block, Jens Axboe, Thomas Gleixner

__blk_mq_delay_run_hw_queue() disables preemption to get a stable
current CPU number and then invokes __blk_mq_run_hw_queue() if the CPU
number is part the mask.

__blk_mq_run_hw_queue() acquires a spin_lock_t which is a sleeping lock
on PREEMPT_RT and can't be acquired with disabled preemption.

It is not required for correctness to invoke __blk_mq_run_hw_queue() on
a CPU matching hctx->cpumask. Both (async and direct requests) can run
on a CPU not matching hctx->cpumask.

The CPU mask without disabling preemption and invoking
__blk_mq_run_hw_queue().

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
v1…v2:
  - Drop migrate_disable() as per Ming Lei.

 block/blk-mq.c |    6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2085,14 +2085,10 @@ static void __blk_mq_delay_run_hw_queue(
 		return;
 
 	if (!async && !(hctx->flags & BLK_MQ_F_BLOCKING)) {
-		int cpu = get_cpu();
-		if (cpumask_test_cpu(cpu, hctx->cpumask)) {
+		if (cpumask_test_cpu(raw_smp_processor_id(), hctx->cpumask)) {
 			__blk_mq_run_hw_queue(hctx);
-			put_cpu();
 			return;
 		}
-
-		put_cpu();
 	}
 
 	kblockd_mod_delayed_work_on(blk_mq_hctx_next_cpu(hctx), &hctx->run_work,

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] blk-mq: Don't disable preemption around __blk_mq_run_hw_queue().
  2022-06-22  8:25   ` [PATCH v2] " Sebastian Andrzej Siewior
@ 2022-06-22  8:35     ` Ming Lei
  2022-06-22 17:46     ` Jens Axboe
  1 sibling, 0 replies; 5+ messages in thread
From: Ming Lei @ 2022-06-22  8:35 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior; +Cc: linux-block, Jens Axboe, Thomas Gleixner

On Wed, Jun 22, 2022 at 10:25:54AM +0200, Sebastian Andrzej Siewior wrote:
> __blk_mq_delay_run_hw_queue() disables preemption to get a stable
> current CPU number and then invokes __blk_mq_run_hw_queue() if the CPU
> number is part the mask.
> 
> __blk_mq_run_hw_queue() acquires a spin_lock_t which is a sleeping lock
> on PREEMPT_RT and can't be acquired with disabled preemption.
> 
> It is not required for correctness to invoke __blk_mq_run_hw_queue() on
> a CPU matching hctx->cpumask. Both (async and direct requests) can run
> on a CPU not matching hctx->cpumask.
> 
> The CPU mask without disabling preemption and invoking
> __blk_mq_run_hw_queue().
> 
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>

Looks fine:

Reviewed-by: Ming Lei <ming.lei@redhat.com>

Thanks,
Ming


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] blk-mq: Don't disable preemption around __blk_mq_run_hw_queue().
  2022-06-22  8:25   ` [PATCH v2] " Sebastian Andrzej Siewior
  2022-06-22  8:35     ` Ming Lei
@ 2022-06-22 17:46     ` Jens Axboe
  1 sibling, 0 replies; 5+ messages in thread
From: Jens Axboe @ 2022-06-22 17:46 UTC (permalink / raw)
  To: ming.lei, bigeasy; +Cc: tglx, linux-block

On Wed, 22 Jun 2022 10:25:54 +0200, Sebastian Andrzej Siewior wrote:
> __blk_mq_delay_run_hw_queue() disables preemption to get a stable
> current CPU number and then invokes __blk_mq_run_hw_queue() if the CPU
> number is part the mask.
> 
> __blk_mq_run_hw_queue() acquires a spin_lock_t which is a sleeping lock
> on PREEMPT_RT and can't be acquired with disabled preemption.
> 
> [...]

Applied, thanks!

[1/1] blk-mq: Don't disable preemption around __blk_mq_run_hw_queue().
      commit: c9198d784fa93d447afe8e4627dfe205f0ce5ec8

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-06-22 17:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21  7:39 [PATCH REPOST] blk-mq: Don't disable preemption around __blk_mq_run_hw_queue() Sebastian Andrzej Siewior
2022-06-21  7:56 ` Ming Lei
2022-06-22  8:25   ` [PATCH v2] " Sebastian Andrzej Siewior
2022-06-22  8:35     ` Ming Lei
2022-06-22 17:46     ` Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.