Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5752301rwd; Mon, 12 Jun 2023 09:08:53 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7EcB5gKnf7QLLazhAcngFKOo+KaoGvV78xVYuzsbsOkMiKFfmfOO+YnVaN8ziMFp1ku9ui X-Received: by 2002:a05:6402:b27:b0:516:a423:85e4 with SMTP id bo7-20020a0564020b2700b00516a42385e4mr4766231edb.35.1686586133152; Mon, 12 Jun 2023 09:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686586133; cv=none; d=google.com; s=arc-20160816; b=FawfchGF74fcxHLBCTtz2m/4AfEBknKfGGKcFQHGwdqfInxPAN8d0W/3Uz+kQT28Yt abwAJ7XP2CJlCjj0uN4YZwRG6j4k3mfRf3TPLNk696XZTlqgLTe3nlaCLM3ESDdQmNxg JbuRqEEdcg836VsewYCRXTgTCX39SUHIDvKK88pMXiK1F0Yor1S8VeCvW4VPEiIVQLIV ifEzoySLzC4W367Bf6ztETAlkgFM5mMABIs6UuHBjDOkTGLzBwHCjnNeM/EIDYfafV/A da5MgdoZZFTAR5i4wflF1Lpc8UPx6pBWdfAGwQVKmDSgG8Q3SRmCiXSd+OJgchgH8Ary oG1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=IXRpfCka87ABaG+gIHRUfKg66tuakINZ/tEGzCbdQ4w=; b=PafAw885qAuAkPtXuXiHF/hjq3oN00vSHNrJRqMRCz6qu4wlL3k8hRIGSP08yy+lvE A5fW8HASZXvWgXE92ZYM/48sArKea6jHnUjaGYZODxRBe6n492k6fzzWi/hFb2j1vQHo NP8FlTwGiqoHm0FGmsJ34/SPJN1XQ3LxRLzTq26d8q9Q/OzHgUWFtwZtQsl/CXTQ+Ejy rv1uMQWcYd4bqJI1PKvjL3V1yIMzh5GaPBAN0T0N1tbATYsiLr508OuYLVRZLOjIq/ay W6OSgWfo1PMnNMJ2cvZtSZ4asmSaubPePqCRhd0tmOmhzilLLTMlI0IvTgUdUc807520 /20Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w17-20020aa7da51000000b00504a26aa3f8si2221746eds.422.2023.06.12.09.08.24; Mon, 12 Jun 2023 09:08:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238702AbjFLPhj convert rfc822-to-8bit (ORCPT + 99 others); Mon, 12 Jun 2023 11:37:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238226AbjFLPhe (ORCPT ); Mon, 12 Jun 2023 11:37:34 -0400 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.178]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67E9610C7; Mon, 12 Jun 2023 08:37:32 -0700 (PDT) Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2b072753301so10685191fa.1; Mon, 12 Jun 2023 08:37:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686584250; x=1689176250; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kN4DlUQA7uUq4M1oOXNMJsrd5bBIUI1Ul692O3Zdi3M=; b=F6cRFVwKWJAEZaUir3Qr7f6EJ1NEuFQu2SPM3HMUQJ4+AE7dwN657pei/q9bvw/hHL SDhBdUZTFgAZMgHq/SdO/BytTKd1ULgLirvz8M/ZT9brLdHnMeSZt3TFgObAfaAydEzI r6B76Jbq5RUzMOIgOr1nElVwqGh6NJT0iWdRhYqlzRw1nGLhMKN2XyClvADaE6hfr3tU C/ARNuryDZDmBiwD+Ou2alDpNjCmLrCa2odUv7AQKSV6xiJPqnbG/w7TmCCaJ4AFlAMb qEkRbdCmHE+7FnH4ws/qgyyX3x9G6U+UbRURoF/nbEZo0mpeHRpsyjuBF7hV0hqCZWK5 LaEQ== X-Gm-Message-State: AC+VfDz6YRIoK+XQTtliqJvPZAZCbyTi5pM+V3TrwGd2ij+/hyZJW97E /JsXQgT0r5PE8Mu39O+rW8md2z/TpwBZHILFmtjZjnd1Ocg= X-Received: by 2002:a2e:b108:0:b0:2b1:dc69:67fd with SMTP id p8-20020a2eb108000000b002b1dc6967fdmr4353607ljl.5.1686584250321; Mon, 12 Jun 2023 08:37:30 -0700 (PDT) MIME-Version: 1.0 References: <2d1fdf6d-682c-a18d-2260-5c5ee7097f7d@gmail.com> <5513e29d-955a-f795-21d6-ec02a2e2e128@gmail.com> <07d6e2e7-a50a-8cf4-5c5d-200551bd6687@gmail.com> <02e4f87a-80e8-dc5d-0d6e-46939f2c74ac@acm.org> <4005a768-9e45-0707-509d-98ce0d2769bd@kernel.org> <0505654c-e487-6b91-57cf-fa7996f5c738@suse.de> <6957a93c-b933-9b08-2f9f-901c4782cd40@kernel.org> <433015f6-9ca6-e4ce-e070-a75378419564@kernel.org> <1bc3eff1-6f86-4546-9360-19b6d0236bc4@rowland.harvard.edu> In-Reply-To: <1bc3eff1-6f86-4546-9360-19b6d0236bc4@rowland.harvard.edu> From: "Rafael J. Wysocki" Date: Mon, 12 Jun 2023 17:37:18 +0200 Message-ID: Subject: Re: Fwd: Waking up from resume locks up on sr device To: Alan Stern , Damien Le Moal Cc: Kai-Heng Feng , Hannes Reinecke , Bart Van Assche , Bagas Sanjaya , Pavel Machek , "Rafael J. Wysocki" , Len Brown , Greg Kroah-Hartman , Kees Cook , Tony Luck , "Guilherme G. Piccoli" , Thorsten Leemhuis , "James E.J. Bottomley" , "Martin K. Petersen" , Phillip Potter , Joe Breuer , Linux Power Management , Linux Kernel Mailing List , Linux Hardening , Linux Regressions , Linux SCSI , Dan Williams , Hannes Reinecke , Adrian Hunter , Martin Kepplinger Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 12, 2023 at 4:33 PM Alan Stern wrote: > > On Mon, Jun 12, 2023 at 04:47:09PM +0900, Damien Le Moal wrote: > > On 6/12/23 16:36, Kai-Heng Feng wrote: > > > On Mon, Jun 12, 2023 at 3:22 PM Damien Le Moal wrote: > > >> > > >> On 6/12/23 15:09, Hannes Reinecke wrote: > > >>> On 6/12/23 05:09, Damien Le Moal wrote: > > >>>> On 6/11/23 00:03, Bart Van Assche wrote: > > >>>>> On 6/10/23 06:27, Bagas Sanjaya wrote: > > >>>>>> On 6/10/23 15:55, Pavel Machek wrote: > > >>>>>>>>> #regzbot introduced: v5.0..v6.4-rc5 https://bugzilla.kernel.org/show_bug.cgi?id=217530 > > >>>>>>>>> #regzbot title: Waking up from resume locks up on SCSI CD/DVD drive > > >>>>>>>>> > > >>>>>>>> The reporter had found the culprit (via bisection), so: > > >>>>>>>> > > >>>>>>>> #regzbot introduced: a19a93e4c6a98c > > >>>>>>> Maybe cc the authors of that commit? > > >>>>>> > > >>>>>> Ah! I forgot to do that! Thanks anyway. > > >>>>> > > >>>>> Hi Damien, > > >>>>> > > >>>>> Why does the ATA code call scsi_rescan_device() before system resume has > > >>>>> finished? Would ATA devices still work with the patch below applied? > > >>>> > > >>>> I do not know the PM code well at all, need to dig into it. But your patch > > >>>> worries me as it seems it would prevent rescan of the device on a resume, which > > >>>> can be an issue if the device has changed. > > >>>> > > >>>> I am not yet 100% clear on the root cause for this, but I think it comes from > > >>>> the fact that ata_port_pm_resume() runs before the sci device resume is done, so > > >>>> with scsi_dev->power.is_suspended still true. And ata_port_pm_resume() calls > > >>>> ata_port_resume_async() which triggers EH (which will do reset + rescan) > > >>>> asynchronously. So it looks like we have scsi device resume and libata EH for > > >>>> rescan fighting each others for the scan mutex and device lock, leading to deadlock. > > >>>> > > >>>> Trying to recreate this issue now to confirm and debug further. But I suspect > > >>>> the solution to this may be best implemented in libata, not in scsi. > > >>>> This looks definitely related to this thread: > > >>>> > > >>>> https://lore.kernel.org/linux-scsi/7b553268-69d3-913a-f9de-28f8d45bdb1e@acm.org/ > > >>>> > > >>>> Similaraly to your comment on that thread, having to look at > > >>>> dev->power.is_suspended is not ideal I think. What we need is to have ata and > > >>>> scsi pm resume be synchronized, but I am not yet 100% clear on the scsi layer side. > > >>>> > > >>> Which is my feeling, too. > > >>> libata runs rescan as part of the device discovery, so really it will > > >>> run after resume. And consequently resume really cannot wait for rescan > > >>> to finish. > > >>> > > >>> What I would be looking at is to decouple resume from libata device > > >>> rescan, and have resume to complete before libata EH runs. > > >> > > >> That is the case now, for the ata port at least, even though that is not super > > >> explicit, and not reliable. See ata_port_pm_resume(): I think that the call to > > >> EH in ata_port_pm_resume() -> ata_port_resume_async() -> ata_port_request_pm() > > >> -> ata_port_schedule_eh() should instead use a sync resume, leading to a sync EH > > >> call. > > >> > > >> That EH execution essentially does ata_eh_handle_port_resume(), which calls into > > >> the adapter resume operation. That in itself does not do much beside some > > >> registers accesses to wakeup the port. There should be no issues doing that > > >> synchronously. > > >> > > >> The problem is that after that is done, ata EH calls ata_std_error_handler() -> > > >> ata_do_eh() -> ata_eh_recover() -> ata_eh_revalidate_and_attach() -> > > >> schedule_work(&(ap->scsi_rescan_task)). And the rescan work calls > > >> scsi_rescan_device() (yet in another context than EH) which causes the problem > > >> when the scsi disk device has not been resumed yet (dev->power_is_suspended > > >> still true). > > >> > > >> So it really looks like the solution should be to have ata_scsi_dev_rescan() > > >> wait for the scsi device to resume first, but not sure how to do that with the > > >> pm API. Digging... > > > > > > Probably use dpm_wait_for_children()? Right now it's an internal PM API. > > > > But I am not sure if there is a relationship between ata_device and its > > scsi_device (dev->sdev)... Need to clarify that. > > > > > > Rafael, > > > What do you think? > > Look into the device_pm_wait_for_dev() API. It's the appropriate thing > to use when you want to wait for another device to complete a system PM > transition. (However, it's not appropriate for runtime PM.) > > Of course, if there is a parent-child relationship between two devices > then waiting is never necessary. The PM core guarantees that a parent > will always be at full power when a child changes its power state, > unless pm_suspend_ignore_children() has been called for the parent > device. There are also device links that go beyond the parent-child handling. Please see Documentation/driver-api/device_link.rst and the kerneldoc description of device_link_add() for more information.