All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
@ 2018-03-16 17:35 Bart Van Assche
  2018-03-16 21:42   ` Martin Steigerwald
  2018-03-19 14:31 ` Tejun Heo
  0 siblings, 2 replies; 14+ messages in thread
From: Bart Van Assche @ 2018-03-16 17:35 UTC (permalink / raw)
  To: Martin K . Petersen, James E . J . Bottomley
  Cc: linux-scsi, Bart Van Assche, Hannes Reinecke, Ming Lei,
	Christoph Hellwig, Johannes Thumshirn, Tejun Heo,
	Oleksandr Natalenko, Martin Steigerwald, stable

Since blk_queue_enter() uses rcu_read_lock_sched() scsi_device_quiesce()
must use synchronize_sched().

Reported-by: Tejun Heo <tj@kernel.org>
Fixes: 3a0a529971ec ("block, scsi: Make SCSI quiesce and resume work reliably")
Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
Cc: Hannes Reinecke <hare@suse.com>
Cc: Ming Lei <ming.lei@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Johannes Thumshirn <jthumshirn@suse.de>
Cc: Tejun Heo <tj@kernel.org>
Cc: Oleksandr Natalenko <oleksandr@natalenko.name>
Cc: Martin Steigerwald <martin@lichtvoll.de>
Cc: stable@vger.kernel.org # v4.15
---
 drivers/scsi/scsi_lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index 1d83f29aee74..0b99ee2fbbb5 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -3014,7 +3014,7 @@ scsi_device_quiesce(struct scsi_device *sdev)
 	 * unfreeze even if the queue was already frozen before this function
 	 * was called. See also https://lwn.net/Articles/573497/.
 	 */
-	synchronize_rcu();
+	synchronize_sched();
 	blk_mq_unfreeze_queue(q);
 
 	mutex_lock(&sdev->state_mutex);
-- 
2.16.2

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-16 17:35 [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched() Bart Van Assche
@ 2018-03-16 21:42   ` Martin Steigerwald
  2018-03-19 14:31 ` Tejun Heo
  1 sibling, 0 replies; 14+ messages in thread
From: Martin Steigerwald @ 2018-03-16 21:42 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi,
	Hannes Reinecke, Ming Lei, Christoph Hellwig, Johannes Thumshirn,
	Tejun Heo, Oleksandr Natalenko, stable

Hello Bart.

What is this one about?

Fix for the regression I (and others?) reported?�

[1] [Bug 199077] [Possible REGRESSION, 4.16-rc4] Error updating SMART data 
during runtime and boot failures with blk_mq_terminate_expired in backtrace

https://bugzilla.kernel.org/show_bug.cgi?id=199077

Thanks,
Martin

Bart Van Assche - 16.03.18, 18:35:
> Since blk_queue_enter() uses rcu_read_lock_sched() scsi_device_quiesce()
> must use synchronize_sched().
> 
> Reported-by: Tejun Heo <tj@kernel.org>
> Fixes: 3a0a529971ec ("block, scsi: Make SCSI quiesce and resume work
> reliably") Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Hannes Reinecke <hare@suse.com>
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Johannes Thumshirn <jthumshirn@suse.de>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Oleksandr Natalenko <oleksandr@natalenko.name>
> Cc: Martin Steigerwald <martin@lichtvoll.de>
> Cc: stable@vger.kernel.org # v4.15
> ---
>  drivers/scsi/scsi_lib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 1d83f29aee74..0b99ee2fbbb5 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -3014,7 +3014,7 @@ scsi_device_quiesce(struct scsi_device *sdev)
>  	 * unfreeze even if the queue was already frozen before this function
>  	 * was called. See also https://lwn.net/Articles/573497/.
>  	 */
> -	synchronize_rcu();
> +	synchronize_sched();
>  	blk_mq_unfreeze_queue(q);
> 
>  	mutex_lock(&sdev->state_mutex);


-- 
Martin

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
@ 2018-03-16 21:42   ` Martin Steigerwald
  0 siblings, 0 replies; 14+ messages in thread
From: Martin Steigerwald @ 2018-03-16 21:42 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi,
	Hannes Reinecke, Ming Lei, Christoph Hellwig, Johannes Thumshirn,
	Tejun Heo, Oleksandr Natalenko, stable

Hello Bart.

What is this one about?

Fix for the regression I (and others?) reported?¹

[1] [Bug 199077] [Possible REGRESSION, 4.16-rc4] Error updating SMART data 
during runtime and boot failures with blk_mq_terminate_expired in backtrace

https://bugzilla.kernel.org/show_bug.cgi?id=199077

Thanks,
Martin

Bart Van Assche - 16.03.18, 18:35:
> Since blk_queue_enter() uses rcu_read_lock_sched() scsi_device_quiesce()
> must use synchronize_sched().
> 
> Reported-by: Tejun Heo <tj@kernel.org>
> Fixes: 3a0a529971ec ("block, scsi: Make SCSI quiesce and resume work
> reliably") Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Cc: Hannes Reinecke <hare@suse.com>
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Johannes Thumshirn <jthumshirn@suse.de>
> Cc: Tejun Heo <tj@kernel.org>
> Cc: Oleksandr Natalenko <oleksandr@natalenko.name>
> Cc: Martin Steigerwald <martin@lichtvoll.de>
> Cc: stable@vger.kernel.org # v4.15
> ---
>  drivers/scsi/scsi_lib.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index 1d83f29aee74..0b99ee2fbbb5 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -3014,7 +3014,7 @@ scsi_device_quiesce(struct scsi_device *sdev)
>  	 * unfreeze even if the queue was already frozen before this function
>  	 * was called. See also https://lwn.net/Articles/573497/.
>  	 */
> -	synchronize_rcu();
> +	synchronize_sched();
>  	blk_mq_unfreeze_queue(q);
> 
>  	mutex_lock(&sdev->state_mutex);


-- 
Martin

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-16 21:42   ` Martin Steigerwald
  (?)
@ 2018-03-16 21:51   ` Bart Van Assche
  2018-03-19  9:02     ` Martin Steigerwald
  -1 siblings, 1 reply; 14+ messages in thread
From: Bart Van Assche @ 2018-03-16 21:51 UTC (permalink / raw)
  To: Martin Steigerwald
  Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi,
	Hannes Reinecke, Ming Lei, Christoph Hellwig, Johannes Thumshirn,
	Tejun Heo, Oleksandr Natalenko, stable

On 03/16/18 14:42, Martin Steigerwald wrote:
> What is this one about?
> 
> Fix for the regression I (and others?) reported?¹
> 
> [1] [Bug 199077] [Possible REGRESSION, 4.16-rc4] Error updating SMART data
> during runtime and boot failures with blk_mq_terminate_expired in backtrace
> 
> https://bugzilla.kernel.org/show_bug.cgi?id=199077

Hello Martin,

This patch is a fix for the fix for the bug that you and others had 
reported. See also "I/O hangs after resuming from suspend-to-ram" 
(https://marc.info/?l=linux-block&m=150340235201348).

This patch fixes an API violation. For those users for which suspend and 
resume works fine with commit 3a0a529971ec applied it should still work 
fine with this patch applied since this patch may cause 
scsi_device_quiesce() to wait longer.

Bart.

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-16 21:51   ` Bart Van Assche
@ 2018-03-19  9:02     ` Martin Steigerwald
  0 siblings, 0 replies; 14+ messages in thread
From: Martin Steigerwald @ 2018-03-19  9:02 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi,
	Hannes Reinecke, Ming Lei, Christoph Hellwig, Johannes Thumshirn,
	Tejun Heo, Oleksandr Natalenko, stable

Hi Bart.

Bart Van Assche - 16.03.18, 22:51:
> On 03/16/18 14:42, Martin Steigerwald wrote:
> > What is this one about?
> > 
> > Fix for the regression I (and others?) reported?¹
> > 
> > [1] [Bug 199077] [Possible REGRESSION, 4.16-rc4] Error updating SMART data
> > during runtime and boot failures with blk_mq_terminate_expired in
> > backtrace
> > 
> > https://bugzilla.kernel.org/show_bug.cgi?id=199077
[…]
> This patch is a fix for the fix for the bug that you and others had
> reported. See also "I/O hangs after resuming from suspend-to-ram"
> (https://marc.info/?l=linux-block&m=150340235201348).
> 
> This patch fixes an API violation. For those users for which suspend and
> resume works fine with commit 3a0a529971ec applied it should still work
> fine with this patch applied since this patch may cause
> scsi_device_quiesce() to wait longer.

Okay, so if I understand you correctly, this is not related to the regression 
I mentioned above.

Testing anyway.

Thanks,
-- 
Martin

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-16 17:35 [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched() Bart Van Assche
  2018-03-16 21:42   ` Martin Steigerwald
@ 2018-03-19 14:31 ` Tejun Heo
  2018-03-19 15:16   ` Bart Van Assche
  1 sibling, 1 reply; 14+ messages in thread
From: Tejun Heo @ 2018-03-19 14:31 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: Martin K . Petersen, James E . J . Bottomley, linux-scsi,
	Hannes Reinecke, Ming Lei, Christoph Hellwig, Johannes Thumshirn,
	Oleksandr Natalenko, Martin Steigerwald, stable

On Fri, Mar 16, 2018 at 10:35:16AM -0700, Bart Van Assche wrote:
> Since blk_queue_enter() uses rcu_read_lock_sched() scsi_device_quiesce()
> must use synchronize_sched().

Is there a reason to use sched-RCU here instead of the regular one?
If not, it'd be better to switch to regular RCU than the other way
around.

Thanks.

-- 
tejun

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-19 14:31 ` Tejun Heo
@ 2018-03-19 15:16   ` Bart Van Assche
  2018-03-19 15:21     ` tj
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Van Assche @ 2018-03-19 15:16 UTC (permalink / raw)
  To: tj
  Cc: jthumshirn, hch, martin.petersen, stable, ming.lei, linux-scsi,
	martin, oleksandr, hare, jejb

On Mon, 2018-03-19 at 07:31 -0700, Tejun Heo wrote:
> On Fri, Mar 16, 2018 at 10:35:16AM -0700, Bart Van Assche wrote:
> > Since blk_queue_enter() uses rcu_read_lock_sched() scsi_device_quiesce()
> > must use synchronize_sched().
> 
> Is there a reason to use sched-RCU here instead of the regular one?
> If not, it'd be better to switch to regular RCU than the other way
> around.

Hello Tejun,

As explained in the comment in scsi_device_quiesce(), the effect of
blk_set_preempt_only() must be visible for percpu_ref_tryget() calls that
occur after the queue unfreeze triggered by scsi_device_quiesce(). Hence the
RCU read lock calls in blk_queue_enter(). Since these RCU read lock calls
surround a function call that uses rcu_read_lock_sched(), namely
percpu_ref_tryget_live(), we have to use sched-RCU in both blk_queue_enter()
and scsi_device_quiesce().

Bart.




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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-19 15:16   ` Bart Van Assche
@ 2018-03-19 15:21     ` tj
  2018-03-19 16:18       ` Bart Van Assche
  0 siblings, 1 reply; 14+ messages in thread
From: tj @ 2018-03-19 15:21 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: jthumshirn, hch, martin.petersen, stable, ming.lei, linux-scsi,
	martin, oleksandr, hare, jejb

Hello,

On Mon, Mar 19, 2018 at 03:16:07PM +0000, Bart Van Assche wrote:
> As explained in the comment in scsi_device_quiesce(), the effect of
> blk_set_preempt_only() must be visible for percpu_ref_tryget() calls that
> occur after the queue unfreeze triggered by scsi_device_quiesce(). Hence the
> RCU read lock calls in blk_queue_enter(). Since these RCU read lock calls
> surround a function call that uses rcu_read_lock_sched(), namely
> percpu_ref_tryget_live(), we have to use sched-RCU in both blk_queue_enter()
> and scsi_device_quiesce().

Let's please not depend on rcu_read_lock_sched() in
percpu_ref_tryget_live().  That's an implementation detail.  If the
code needs RCU based synchronization, it should perform them
explicitly.

Thanks.

-- 
tejun

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-19 15:21     ` tj
@ 2018-03-19 16:18       ` Bart Van Assche
  2018-03-19 16:29         ` tj
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Van Assche @ 2018-03-19 16:18 UTC (permalink / raw)
  To: tj
  Cc: jthumshirn, hch, martin, stable, ming.lei, martin.petersen,
	linux-scsi, oleksandr, hare, jejb

On Mon, 2018-03-19 at 08:21 -0700, tj@kernel.org wrote:
> On Mon, Mar 19, 2018 at 03:16:07PM +0000, Bart Van Assche wrote:
> > As explained in the comment in scsi_device_quiesce(), the effect of
> > blk_set_preempt_only() must be visible for percpu_ref_tryget() calls that
> > occur after the queue unfreeze triggered by scsi_device_quiesce(). Hence the
> > RCU read lock calls in blk_queue_enter(). Since these RCU read lock calls
> > surround a function call that uses rcu_read_lock_sched(), namely
> > percpu_ref_tryget_live(), we have to use sched-RCU in both blk_queue_enter()
> > and scsi_device_quiesce().
> 
> Let's please not depend on rcu_read_lock_sched() in
> percpu_ref_tryget_live().  That's an implementation detail.  If the
> code needs RCU based synchronization, it should perform them
> explicitly.

Hello Tejun,

The algorithm explained above does not depend on sched-rcu. But because
percpu_ref_tryget_live() uses sched-rcu and because we need to add an RCU lock
around that call we are forced to use sched-rcu. I hope this makes it clear.

Bart.



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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-19 16:18       ` Bart Van Assche
@ 2018-03-19 16:29         ` tj
  2018-03-19 16:57           ` Bart Van Assche
  0 siblings, 1 reply; 14+ messages in thread
From: tj @ 2018-03-19 16:29 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: jthumshirn, hch, martin, stable, ming.lei, martin.petersen,
	linux-scsi, oleksandr, hare, jejb

Hello,

On Mon, Mar 19, 2018 at 04:18:54PM +0000, Bart Van Assche wrote:
> The algorithm explained above does not depend on sched-rcu. But because
> percpu_ref_tryget_live() uses sched-rcu and because we need to add an RCU lock
> around that call we are forced to use sched-rcu. I hope this makes it clear.

This could be me being slow but can you explain how what
percpu_ref_tryget_live() uses internally affects whether we can use
regular RCU around it?

Thanks.

-- 
tejun

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-19 16:29         ` tj
@ 2018-03-19 16:57           ` Bart Van Assche
  2018-03-19 17:02             ` tj
  0 siblings, 1 reply; 14+ messages in thread
From: Bart Van Assche @ 2018-03-19 16:57 UTC (permalink / raw)
  To: tj
  Cc: jthumshirn, hch, martin, stable, ming.lei, martin.petersen,
	linux-scsi, oleksandr, hare, jejb

On Mon, 2018-03-19 at 09:29 -0700, tj@kernel.org wrote:
> This could be me being slow but can you explain how what
> percpu_ref_tryget_live() uses internally affects whether we can use
> regular RCU around it?

Hello Tejun,

For synchronization primitives that wait having a stronger synchronization
primitive nested inside a more relaxed one can lead to a deadlock. But since
the rcu read lock primitives do not wait it could be safe to use that kind
of nesting with RCU. Do you perhaps know whether any documentation is
available about that kind of nesting or whether it is already used elsewhere
in the kernel?

Thanks,

Bart.


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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-19 16:57           ` Bart Van Assche
@ 2018-03-19 17:02             ` tj
  2018-03-19 20:19                 ` Bart Van Assche
  0 siblings, 1 reply; 14+ messages in thread
From: tj @ 2018-03-19 17:02 UTC (permalink / raw)
  To: Bart Van Assche
  Cc: jthumshirn, hch, martin, stable, ming.lei, martin.petersen,
	linux-scsi, oleksandr, hare, jejb

Hey,

On Mon, Mar 19, 2018 at 04:57:45PM +0000, Bart Van Assche wrote:
> For synchronization primitives that wait having a stronger synchronization
> primitive nested inside a more relaxed one can lead to a deadlock. But since
> the rcu read lock primitives do not wait it could be safe to use that kind
> of nesting with RCU. Do you perhaps know whether any documentation is
> available about that kind of nesting or whether it is already used elsewhere
> in the kernel?

Oh, we nest them all the time.  They're like (and sometimes literally
are) preempt_disable() and don't care about nest ordering.

Thanks.

-- 
tejun

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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
  2018-03-19 17:02             ` tj
@ 2018-03-19 20:19                 ` Bart Van Assche
  0 siblings, 0 replies; 14+ messages in thread
From: Bart Van Assche @ 2018-03-19 20:19 UTC (permalink / raw)
  To: Martin K. Petersen
  Cc: jthumshirn, hch, martin, martin.petersen, ming.lei, linux-scsi,
	oleksandr, hare, stable, jejb, tj

On Mon, 2018-03-19 at 10:02 -0700, tj@kernel.org wrote:
> On Mon, Mar 19, 2018 at 04:57:45PM +0000, Bart Van Assche wrote:
> > For synchronization primitives that wait having a stronger synchronization
> > primitive nested inside a more relaxed one can lead to a deadlock. But since
> > the rcu read lock primitives do not wait it could be safe to use that kind
> > of nesting with RCU. Do you perhaps know whether any documentation is
> > available about that kind of nesting or whether it is already used elsewhere
> > in the kernel?
> 
> Oh, we nest them all the time.  They're like (and sometimes literally
> are) preempt_disable() and don't care about nest ordering.

Hello Martin,

This was probably already clear to you, but anyway: please drop the patch at the
start of this thread.

Thanks,

Bart.



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

* Re: [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched()
@ 2018-03-19 20:19                 ` Bart Van Assche
  0 siblings, 0 replies; 14+ messages in thread
From: Bart Van Assche @ 2018-03-19 20:19 UTC (permalink / raw)
  Cc: jthumshirn, hch, martin, martin.petersen, ming.lei, linux-scsi,
	oleksandr, hare, stable, jejb, tj

On Mon, 2018-03-19 at 10:02 -0700, tj@kernel.org wrote:
> On Mon, Mar 19, 2018 at 04:57:45PM +0000, Bart Van Assche wrote:
> > For synchronization primitives that wait having a stronger synchronization
> > primitive nested inside a more relaxed one can lead to a deadlock. But since
> > the rcu read lock primitives do not wait it could be safe to use that kind
> > of nesting with RCU. Do you perhaps know whether any documentation is
> > available about that kind of nesting or whether it is already used elsewhere
> > in the kernel?
> 
> Oh, we nest them all the time.  They're like (and sometimes literally
> are) preempt_disable() and don't care about nest ordering.

Hello Martin,

This was probably already clear to you, but anyway: please drop the patch at the
start of this thread.

Thanks,

Bart.



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

end of thread, other threads:[~2018-03-19 20:19 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-16 17:35 [PATCH] Change synchronize_rcu() in scsi_device_quiesce() into synchronize_sched() Bart Van Assche
2018-03-16 21:42 ` Martin Steigerwald
2018-03-16 21:42   ` Martin Steigerwald
2018-03-16 21:51   ` Bart Van Assche
2018-03-19  9:02     ` Martin Steigerwald
2018-03-19 14:31 ` Tejun Heo
2018-03-19 15:16   ` Bart Van Assche
2018-03-19 15:21     ` tj
2018-03-19 16:18       ` Bart Van Assche
2018-03-19 16:29         ` tj
2018-03-19 16:57           ` Bart Van Assche
2018-03-19 17:02             ` tj
2018-03-19 20:19               ` Bart Van Assche
2018-03-19 20:19                 ` Bart Van Assche

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.