linux-ide.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] libata: Use per port sync for detach
@ 2020-06-03  7:48 Kai-Heng Feng
  2020-06-03  8:40 ` John Garry
  2020-06-18 15:21 ` Jens Axboe
  0 siblings, 2 replies; 4+ messages in thread
From: Kai-Heng Feng @ 2020-06-03  7:48 UTC (permalink / raw)
  To: axboe
  Cc: Kai-Heng Feng, John Garry,
	open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers),
	open list

Commit 130f4caf145c ("libata: Ensure ata_port probe has completed before
detach") may cause system freeze during suspend.

Using async_synchronize_full() in PM callbacks is wrong, since async
callbacks that are already scheduled may wait for not-yet-scheduled
callbacks, causes a circular dependency.

Instead of using big hammer like async_synchronize_full(), use async
cookie to make sure port probe are synced, without affecting other
scheduled PM callbacks.

Fixes: 130f4caf145c ("libata: Ensure ata_port probe has completed before detach")
BugLink: https://bugs.launchpad.net/bugs/1867983
Suggested-by: John Garry <john.garry@huawei.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v3:
 - Move the comment to properly align with the code.

v2:
 - Sync up to cookie + 1.
 - Squash the synchronization into the same loop.

 drivers/ata/libata-core.c | 11 +++++------
 include/linux/libata.h    |  3 +++
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
index 69361ec43db5..b1cd4d97bc2a 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -42,7 +42,6 @@
 #include <linux/workqueue.h>
 #include <linux/scatterlist.h>
 #include <linux/io.h>
-#include <linux/async.h>
 #include <linux/log2.h>
 #include <linux/slab.h>
 #include <linux/glob.h>
@@ -5778,7 +5777,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
 	/* perform each probe asynchronously */
 	for (i = 0; i < host->n_ports; i++) {
 		struct ata_port *ap = host->ports[i];
-		async_schedule(async_port_probe, ap);
+		ap->cookie = async_schedule(async_port_probe, ap);
 	}
 
 	return 0;
@@ -5920,11 +5919,11 @@ void ata_host_detach(struct ata_host *host)
 {
 	int i;
 
-	/* Ensure ata_port probe has completed */
-	async_synchronize_full();
-
-	for (i = 0; i < host->n_ports; i++)
+	for (i = 0; i < host->n_ports; i++) {
+		/* Ensure ata_port probe has completed */
+		async_synchronize_cookie(host->ports[i]->cookie + 1);
 		ata_port_detach(host->ports[i]);
+	}
 
 	/* the host is dead now, dissociate ACPI */
 	ata_acpi_dissociate(host);
diff --git a/include/linux/libata.h b/include/linux/libata.h
index af832852e620..8a4843704d28 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -22,6 +22,7 @@
 #include <linux/acpi.h>
 #include <linux/cdrom.h>
 #include <linux/sched.h>
+#include <linux/async.h>
 
 /*
  * Define if arch has non-standard setup.  This is a _PCI_ standard
@@ -872,6 +873,8 @@ struct ata_port {
 	struct timer_list	fastdrain_timer;
 	unsigned long		fastdrain_cnt;
 
+	async_cookie_t		cookie;
+
 	int			em_message_type;
 	void			*private_data;
 
-- 
2.17.1


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

* Re: [PATCH v3] libata: Use per port sync for detach
  2020-06-03  7:48 [PATCH v3] libata: Use per port sync for detach Kai-Heng Feng
@ 2020-06-03  8:40 ` John Garry
  2020-06-18  5:43   ` Kai-Heng Feng
  2020-06-18 15:21 ` Jens Axboe
  1 sibling, 1 reply; 4+ messages in thread
From: John Garry @ 2020-06-03  8:40 UTC (permalink / raw)
  To: Kai-Heng Feng, axboe
  Cc: open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers), open list

On 03/06/2020 08:48, Kai-Heng Feng wrote:
> Commit 130f4caf145c ("libata: Ensure ata_port probe has completed before
> detach") may cause system freeze during suspend.
> 
> Using async_synchronize_full() in PM callbacks is wrong, since async
> callbacks that are already scheduled may wait for not-yet-scheduled
> callbacks, causes a circular dependency.
> 
> Instead of using big hammer like async_synchronize_full(), use async
> cookie to make sure port probe are synced, without affecting other
> scheduled PM callbacks.
> 
> Fixes: 130f4caf145c ("libata: Ensure ata_port probe has completed before detach")
> BugLink: https://bugs.launchpad.net/bugs/1867983
> Suggested-by: John Garry <john.garry@huawei.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

thanks,
Tested-by: John Garry <john.garry@huawei.com>

> ---
> v3:
>   - Move the comment to properly align with the code.
> 
> v2:
>   - Sync up to cookie + 1.
>   - Squash the synchronization into the same loop.
> 
>   drivers/ata/libata-core.c | 11 +++++------
>   include/linux/libata.h    |  3 +++
>   2 files changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
> index 69361ec43db5..b1cd4d97bc2a 100644
> --- a/drivers/ata/libata-core.c
> +++ b/drivers/ata/libata-core.c
> @@ -42,7 +42,6 @@
>   #include <linux/workqueue.h>
>   #include <linux/scatterlist.h>
>   #include <linux/io.h>
> -#include <linux/async.h>
>   #include <linux/log2.h>
>   #include <linux/slab.h>
>   #include <linux/glob.h>
> @@ -5778,7 +5777,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
>   	/* perform each probe asynchronously */
>   	for (i = 0; i < host->n_ports; i++) {
>   		struct ata_port *ap = host->ports[i];
> -		async_schedule(async_port_probe, ap);
> +		ap->cookie = async_schedule(async_port_probe, ap);
>   	}
>   
>   	return 0;
> @@ -5920,11 +5919,11 @@ void ata_host_detach(struct ata_host *host)
>   {
>   	int i;
>   
> -	/* Ensure ata_port probe has completed */
> -	async_synchronize_full();
> -
> -	for (i = 0; i < host->n_ports; i++)
> +	for (i = 0; i < host->n_ports; i++) {
> +		/* Ensure ata_port probe has completed */
> +		async_synchronize_cookie(host->ports[i]->cookie + 1);
>   		ata_port_detach(host->ports[i]);
> +	}
>   
>   	/* the host is dead now, dissociate ACPI */
>   	ata_acpi_dissociate(host);
> diff --git a/include/linux/libata.h b/include/linux/libata.h
> index af832852e620..8a4843704d28 100644
> --- a/include/linux/libata.h
> +++ b/include/linux/libata.h
> @@ -22,6 +22,7 @@
>   #include <linux/acpi.h>
>   #include <linux/cdrom.h>
>   #include <linux/sched.h>
> +#include <linux/async.h>
>   
>   /*
>    * Define if arch has non-standard setup.  This is a _PCI_ standard
> @@ -872,6 +873,8 @@ struct ata_port {
>   	struct timer_list	fastdrain_timer;
>   	unsigned long		fastdrain_cnt;
>   
> +	async_cookie_t		cookie;
> +
>   	int			em_message_type;
>   	void			*private_data;
>   
> 


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

* Re: [PATCH v3] libata: Use per port sync for detach
  2020-06-03  8:40 ` John Garry
@ 2020-06-18  5:43   ` Kai-Heng Feng
  0 siblings, 0 replies; 4+ messages in thread
From: Kai-Heng Feng @ 2020-06-18  5:43 UTC (permalink / raw)
  To: John Garry
  Cc: Jens Axboe,
	open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers),
	open list

Hi Jens,

> On Jun 3, 2020, at 16:40, John Garry <john.garry@huawei.com> wrote:
> 
> On 03/06/2020 08:48, Kai-Heng Feng wrote:
>> Commit 130f4caf145c ("libata: Ensure ata_port probe has completed before
>> detach") may cause system freeze during suspend.
>> Using async_synchronize_full() in PM callbacks is wrong, since async
>> callbacks that are already scheduled may wait for not-yet-scheduled
>> callbacks, causes a circular dependency.
>> Instead of using big hammer like async_synchronize_full(), use async
>> cookie to make sure port probe are synced, without affecting other
>> scheduled PM callbacks.
>> Fixes: 130f4caf145c ("libata: Ensure ata_port probe has completed before detach")
>> BugLink: https://bugs.launchpad.net/bugs/1867983
>> Suggested-by: John Garry <john.garry@huawei.com>
>> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> 
> thanks,
> Tested-by: John Garry <john.garry@huawei.com>

Can you please review or merge this patch?

Kai-Heng

> 
>> ---
>> v3:
>>  - Move the comment to properly align with the code.
>> v2:
>>  - Sync up to cookie + 1.
>>  - Squash the synchronization into the same loop.
>>  drivers/ata/libata-core.c | 11 +++++------
>>  include/linux/libata.h    |  3 +++
>>  2 files changed, 8 insertions(+), 6 deletions(-)
>> diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
>> index 69361ec43db5..b1cd4d97bc2a 100644
>> --- a/drivers/ata/libata-core.c
>> +++ b/drivers/ata/libata-core.c
>> @@ -42,7 +42,6 @@
>>  #include <linux/workqueue.h>
>>  #include <linux/scatterlist.h>
>>  #include <linux/io.h>
>> -#include <linux/async.h>
>>  #include <linux/log2.h>
>>  #include <linux/slab.h>
>>  #include <linux/glob.h>
>> @@ -5778,7 +5777,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
>>  	/* perform each probe asynchronously */
>>  	for (i = 0; i < host->n_ports; i++) {
>>  		struct ata_port *ap = host->ports[i];
>> -		async_schedule(async_port_probe, ap);
>> +		ap->cookie = async_schedule(async_port_probe, ap);
>>  	}
>>    	return 0;
>> @@ -5920,11 +5919,11 @@ void ata_host_detach(struct ata_host *host)
>>  {
>>  	int i;
>>  -	/* Ensure ata_port probe has completed */
>> -	async_synchronize_full();
>> -
>> -	for (i = 0; i < host->n_ports; i++)
>> +	for (i = 0; i < host->n_ports; i++) {
>> +		/* Ensure ata_port probe has completed */
>> +		async_synchronize_cookie(host->ports[i]->cookie + 1);
>>  		ata_port_detach(host->ports[i]);
>> +	}
>>    	/* the host is dead now, dissociate ACPI */
>>  	ata_acpi_dissociate(host);
>> diff --git a/include/linux/libata.h b/include/linux/libata.h
>> index af832852e620..8a4843704d28 100644
>> --- a/include/linux/libata.h
>> +++ b/include/linux/libata.h
>> @@ -22,6 +22,7 @@
>>  #include <linux/acpi.h>
>>  #include <linux/cdrom.h>
>>  #include <linux/sched.h>
>> +#include <linux/async.h>
>>    /*
>>   * Define if arch has non-standard setup.  This is a _PCI_ standard
>> @@ -872,6 +873,8 @@ struct ata_port {
>>  	struct timer_list	fastdrain_timer;
>>  	unsigned long		fastdrain_cnt;
>>  +	async_cookie_t		cookie;
>> +
>>  	int			em_message_type;
>>  	void			*private_data;
>>  
> 


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

* Re: [PATCH v3] libata: Use per port sync for detach
  2020-06-03  7:48 [PATCH v3] libata: Use per port sync for detach Kai-Heng Feng
  2020-06-03  8:40 ` John Garry
@ 2020-06-18 15:21 ` Jens Axboe
  1 sibling, 0 replies; 4+ messages in thread
From: Jens Axboe @ 2020-06-18 15:21 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: John Garry,
	open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers),
	open list

On 6/3/20 1:48 AM, Kai-Heng Feng wrote:
> Commit 130f4caf145c ("libata: Ensure ata_port probe has completed before
> detach") may cause system freeze during suspend.
> 
> Using async_synchronize_full() in PM callbacks is wrong, since async
> callbacks that are already scheduled may wait for not-yet-scheduled
> callbacks, causes a circular dependency.
> 
> Instead of using big hammer like async_synchronize_full(), use async
> cookie to make sure port probe are synced, without affecting other
> scheduled PM callbacks.

Queued up for 5.8, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2020-06-18 15:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-03  7:48 [PATCH v3] libata: Use per port sync for detach Kai-Heng Feng
2020-06-03  8:40 ` John Garry
2020-06-18  5:43   ` Kai-Heng Feng
2020-06-18 15:21 ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).