Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp299653ybg; Wed, 3 Jun 2020 00:51:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOUcMUk9NxX3TUoga9oADT5KqOLgpXkgDS+RpmpBII/seLnOYb2pHO0LYq2jOTwu1zjWzj X-Received: by 2002:a17:906:c058:: with SMTP id bm24mr25914484ejb.73.1591170662514; Wed, 03 Jun 2020 00:51:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591170662; cv=none; d=google.com; s=arc-20160816; b=ymhqC+JM1lBcIZn4IJOCnVaVFEDup4HgPeBTYI3HL44kqu0AAcp4aPWE+274p6ifTv YGogHsa2ScXyZsug8vCUGvt7b47fTSWoG6GP/z9rfFmd2paamwXCmJYWT0knZpyFSfeY byQz5D/xylaBOWC3SwVqHvX3CQvmTk7fhNC+82qb3RwFvp/zpWK9+dwID/6875ek87ho BpSfGaVM0nUMDx/62eVOi+OqR8k3qbaEkUAloP+apH5fQVe/S93Y8CHtxRBHk1gNtkgr 9o3qMXiRKD+ZMHDqlsFue87FOUyGBws/AyFRydXGNlNazZRYv1rj5jI0qa0zamU3jc4j CUHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=rp1c3WVjmOws99xijRxrbmyjPybt9xms1g6DZwlCgew=; b=q+kgmIZirWgeueTHTfDXWk7vT3GW0yaLDrC2V+jJV8sfJkgYgFDKcMfR2ONopT+cO4 1Ef2lOY2xXjjBSQp6RDnBr19CPq8aG1xiKjwUH7ldbnjEF7PArkbrpP4Pqp6gXIadbeh 7aFeQWdWQdcxdtXIskzJU/wyTU75UZ96MFIgr+fpZ1p5LsDkA3W2k6etx3TuRNM0HTcV 1T0PhrKS+MGIER5P9XVCVT/W9uHses1bBnersnCw3ufO8uXmL5Txd7v1CEKxSc8Muzp8 nOF57rWRIj39+lc6J4ZDJKgWsNMRSZ8XhNJ4jWIP8ggWkJ2QoGCJC/BVLVstPfonNtGc v9DA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si726405ejc.462.2020.06.03.00.50.39; Wed, 03 Jun 2020 00:51:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725888AbgFCHse (ORCPT + 99 others); Wed, 3 Jun 2020 03:48:34 -0400 Received: from youngberry.canonical.com ([91.189.89.112]:40416 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725275AbgFCHsd (ORCPT ); Wed, 3 Jun 2020 03:48:33 -0400 Received: from 61-220-137-37.hinet-ip.hinet.net ([61.220.137.37] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1jgO8S-0008I8-SH; Wed, 03 Jun 2020 07:48:29 +0000 From: Kai-Heng Feng To: axboe@kernel.dk Cc: Kai-Heng Feng , John Garry , linux-ide@vger.kernel.org (open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers)), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v3] libata: Use per port sync for detach Date: Wed, 3 Jun 2020 15:48:19 +0800 Message-Id: <20200603074819.21639-1-kai.heng.feng@canonical.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Kai-Heng Feng --- 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 #include #include -#include #include #include #include @@ -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 #include #include +#include /* * 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