Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp32307lfe; Fri, 15 Apr 2022 18:03:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyM97TkInbe/wdLR/whP70r2RGnPVevLmC6xtcX/N8PThYf+d5tAYItwaa/n8vm826VCnEy X-Received: by 2002:a17:902:e415:b0:158:8e4c:72af with SMTP id m21-20020a170902e41500b001588e4c72afmr1475554ple.168.1650071025894; Fri, 15 Apr 2022 18:03:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650071025; cv=none; d=google.com; s=arc-20160816; b=dTVqty3aqWNQFWiZr5ym/hNprbnnuRp2NGlPJuTSfmw1f+qfZ+CAFhqT7Qz1k5V/Dz Yzww6awWWJh2NZxoq5kI9Uy1JBp+XipQ7qN2Var7DAECRw1GasTjBnEBMlV0oqr7BoES kA7udndAyAQhzs26nrtErLCMa7OZGJI4B/vjmZe3pAGs7FEaOL8Qj+4cy3IPZMz9eZx2 FqpT4wIXtvS6x+eK5ziC7ZWyscoU44Vs9suekB1woGPF3anZ6+t0JdZqtjBFvnmx+Vjn qKATv4JWrRSgHUnAdKnmYHOecXRwYKMYQTeHjO4FG6y6S7fjNKVNHGwifS0IAEWA/NlE DPJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=cTC32EWD1K5hDZhU+i7HLDLsHr6y6bEH/cz8nKU9FsY=; b=Fpq+7dObjZDeKfevrDmjS8rbrFtgtvJ1qeuFqpYnJCzjyJQAQgK16A6PflhMcI7lSk sd8o4y5MT3no70ZfFyStv5ZkTs77IDMXsviIytEulqCqLxndrPxxX0z3NLr7xkGKcq63 rRBouztj1BOsSWifSULHAUdvZil82wnfzOxRjM5l5OOp6q9OmvzR5vwP/puOE8AQD4AI EUilpEW8famibx4bkEcXJvuD9DEvWjb5vnh+hjXWoGgs8omaFx+enmK3j5c3AKIQrsz6 ORM5BM/OmeZvKjzzzgRl7WO8aKx6d6LqqONmsKSgE1UnP+lel8s3M5QFbhLmLnuwqHUf eUDg== ARC-Authentication-Results: i=1; mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id h14-20020a170902f70e00b00153b2d16582si2524991plo.394.2022.04.15.18.03.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 18:03:45 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6FE8AEBBA8; Fri, 15 Apr 2022 17:45:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348102AbiDNPj4 (ORCPT + 99 others); Thu, 14 Apr 2022 11:39:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351590AbiDNObH (ORCPT ); Thu, 14 Apr 2022 10:31:07 -0400 Received: from netrider.rowland.org (netrider.rowland.org [192.131.102.5]) by lindbergh.monkeyblade.net (Postfix) with SMTP id B814E326C4 for ; Thu, 14 Apr 2022 07:21:38 -0700 (PDT) Received: (qmail 447694 invoked by uid 1000); 14 Apr 2022 10:21:37 -0400 Date: Thu, 14 Apr 2022 10:21:37 -0400 From: Alan Stern To: Mathias Nyman Cc: Evan Green , Greg Kroah-Hartman , Mathias Nyman , Rajat Jain , Thomas Gleixner , Bjorn Helgaas , "Rafael J. Wysocki" , Youngjin Jang , LKML , linux-usb@vger.kernel.org Subject: Re: [PATCH] USB: hcd-pci: Fully suspend across freeze/thaw cycle Message-ID: References: <20220407115918.1.I8226c7fdae88329ef70957b96a39b346c69a914e@changeid> <022a50ac-7866-2140-1b40-776255f3a036@linux.intel.com> <4353a956-9855-9c14-7dbf-bf16580abe32@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,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 Thu, Apr 14, 2022 at 05:00:12PM +0300, Mathias Nyman wrote: > On 12.4.2022 18.40, Alan Stern wrote: > > On Tue, Apr 12, 2022 at 05:56:42PM +0300, Mathias Nyman wrote: > >> On 11.4.2022 17.50, Alan Stern wrote: > >>> For example, what would happen if the user unplugs a device right in the > >>> middle of the freeze transition, after the root hub has been frozen but > >>> before the controller is frozen? We don't want such an unplug event to > >>> prevent the system from going into hibernation -- especially if the root > >>> hub was not enabled for wakeup. > >> > >> We should be able to let system go to hibernate even if we get a disconnect > >> interrupt between roothub and host controller freeze. > >> Host is not yet suspended so no PME# wake is generated, only an interrupt. > >> > >> From Linux PM point of view it should be ok as well as the actual xhci > >> device that is generating the interrupt is hasnt completer freeze() > >> > >> The xhci interrupt handler just needs to make sure that the disconnect > >> isn't propagated if roothub is suspended and wake on disconnect > >> is not set. And definitely make sure xhci doesn't start roothub polling. > >> > >> When freeze() is called for the host we should prevent the host from > >> generating interrupts. > > > > I guess that means adding a new callback. Or we could just suspend the > > controller, like Evan proposed originally > > Suspending the host in freeze should work. > It will do an extra xhci controller state save stage, but that should be harmless. > > But is there really a need for the suggested noirq part? > > + .freeze_noirq = hcd_pci_suspend_noirq, > > That will try to set the host to PCI D3 state. > It seems a bit unnecessary for freeze. Agreed. > >>> (If the root hub _is_ enabled for wakeup then it's questionable. > >>> Unplugging a device would be a wakeup event, so you could easily argue > >>> that it _should_ prevent the system from going into hibernation. After > >>> all, if the unplug happened a few milliseconds later, after the system > >>> had fully gone into hibernation, then it would cause the system to wake > >>> up.) > >>> > >>>> Would it make sense prevent xHCI interrupt generation in the host > >>>> freeze() stage, clearing the xHCI EINT bit in addition to calling > >>>> check_roothub_suspend()? > >>>> Then enable it back in thaw() > >>> > >>> That won't fully eliminate the problem mentioned in the preceding > >>> paragraphs, although I guess it would help somewhat. > >> > >> Would the following steps solve this? > >> > >> 1. Disable device initiated resume for connected usb devices in freeze() > >> > >> 2. Don't propagate connect or OC changes if roothub is suspended and port wake > >> flags are disabled. I.E don't kick roothub polling in xhci interrupt > >> handler here. > > > > I guess you can't just halt the entire host controller when only one of > > the root hubs is suspended with wakeup disabled. That does complicate > > things. But you could halt it as soon as both of the root hubs are > > frozen. Wouldn't that prevent interrupt generation? > > True, but probably easier to just suspend host in freeze() as you stated above. Okay. Evan, this discussion suggests that you rewrite your patch as a series of three: 1. Change choose_wakeup() so that for PM_EVENT_FREEZE, wakeup is always disabled. 2. Change the xhci-hcd interrupt handler so that port-status changes are ignored if the port's root hub is suspended with wakeup disabled. 3. As in the original patch, make the .freeze and .thaw callbacks in hcd-pci.c call the appropriate suspend and resume routines, but don't do anything for .freeze_noirq and .thaw_noirq. How does that sound? Alan Stern