Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp328164ybg; Wed, 3 Jun 2020 01:44:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxs2bKuGDda5yF9MyGpR2A+w8dfXNbIf8jjQ7UZvRjLZ6uEOijK/xrIpoF8MJ99uzHw5cYc X-Received: by 2002:a17:906:2409:: with SMTP id z9mr24786043eja.442.1591173857457; Wed, 03 Jun 2020 01:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591173857; cv=none; d=google.com; s=arc-20160816; b=Sr+pq/0UtiLePfk/qAjt3UrgPARs2oEjsBxxLMI2q4kIn4GO8ydfjMGfSKYX0jcbkv cw29tJIEyX20CE9b5UBc+fYx0WhoFSWpCsOKXeXNePkR9tDp+VQawfJffa/18JD62iLw LmyG4kTB8MO0FldZJUQo6h5K4wwYn4o0tDwpCWfiYwXDC2K3AX3xvY+zu2N6M+do0V3O GV5azN9mvX9J3H3tNq5OWBEL7s2tpAO0yRcDc/d6ILn+49iTDxN2AD8tEnmvrOLMkdhz pGJEDtd0d3PZHrAZSrn6b/iI3LRlSpOWh3a2lFJDJWHJgGfPABD1NsjRZNuDTBC3JZc6 LuCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=V7wNal3b7LXt+UsG0R5lacGStMY5Ic0sDgXLNhIQInY=; b=Jhc8JxDKJo0UX5Ei4e3CPEymP1x2iNhZyesO4LmJJpZNfEew6TG9CbawFfM29qdAj1 IYe3rRcjjA/9L1lmKSCyFLUEGOImfh7QHPRAkaK9DiUWX0R8vsNVbbF8oZ+rqP61/k1/ OzltRM+vn49Qpn1nyszzQrGBcN48EDfr0wyxkeJGan1r5Msi0oFwJyhj5MNhk1P2Mlgu 1xHtOOuPscaieAiuyvRL0+HQzCUXa1Q/Ce8FeOqm2B4IrwOxz6oQGOo23Nx0SoD7xj5h kq4ip9u8RxUO3r8hEFB8yJEWM3AjtLKJxM3jBx2AXmj9nGjd6iQG5lHAWI8eQNa+NW1G yphA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r9si759736edx.535.2020.06.03.01.43.54; Wed, 03 Jun 2020 01:44:17 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726291AbgFCImI (ORCPT + 99 others); Wed, 3 Jun 2020 04:42:08 -0400 Received: from lhrrgout.huawei.com ([185.176.76.210]:2268 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725355AbgFCImI (ORCPT ); Wed, 3 Jun 2020 04:42:08 -0400 Received: from lhreml724-chm.china.huawei.com (unknown [172.18.7.107]) by Forcepoint Email with ESMTP id 6809DE24A9B570BF8335; Wed, 3 Jun 2020 09:42:06 +0100 (IST) Received: from [127.0.0.1] (10.47.0.59) by lhreml724-chm.china.huawei.com (10.201.108.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1913.5; Wed, 3 Jun 2020 09:42:05 +0100 Subject: Re: [PATCH v3] libata: Use per port sync for detach To: Kai-Heng Feng , CC: "open list:LIBATA SUBSYSTEM (Serial and Parallel ATA drivers)" , open list References: <20200603074819.21639-1-kai.heng.feng@canonical.com> From: John Garry Message-ID: Date: Wed, 3 Jun 2020 09:40:54 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.1.2 MIME-Version: 1.0 In-Reply-To: <20200603074819.21639-1-kai.heng.feng@canonical.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.47.0.59] X-ClientProxiedBy: lhreml735-chm.china.huawei.com (10.201.108.86) To lhreml724-chm.china.huawei.com (10.201.108.75) X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > Signed-off-by: Kai-Heng Feng thanks, Tested-by: John Garry > --- > 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; > >