Received: by 2002:a19:f614:0:0:0:0:0 with SMTP id x20csp61814lfe; Fri, 15 Apr 2022 19:34:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxK+Y7hs6KncouQkxTMfK6Mk2Mlger5s5lpQFFfjXeGqLxY9+SK0lBDSuA2N5EQHjVKizCl X-Received: by 2002:a17:903:2451:b0:158:6d0d:bdb3 with SMTP id l17-20020a170903245100b001586d0dbdb3mr1523843pls.61.1650076464096; Fri, 15 Apr 2022 19:34:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650076464; cv=none; d=google.com; s=arc-20160816; b=E4o+PdRLsxE1a/Kg3o+AMQbY6RkwiiiUufok+5TqRBYCHSURpTttSe9stEUfB8pZO1 4zNrYg6tYTC8av4DuiYO8E/UxxeXSMXBk7FqhpCqSnNgT6ddLgqImg5EovXDh3zVNOEh iB18ey5RV90/MpfT0z7qZ7bqlU7fWXaOE9/YirI4uNbfQ5m/Kb3JNtN5JSp3Z9oEdznE 858vUU9LYRFpZ7JOQfEU2vp8G9nrPslQmMYDBByTedlpzDhxmIZzlSGNQj9+At7sljVM ydHLIUKERFAsgHyiTMuzEkqtr2i2tDtZntRY8PLGoPB15qK16xBFo0m4ljfay1QITHwo fWTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=F8L5e1xKbydF7d2L0TADvbJn6wqVOYq7/kZpJYa2SRw=; b=0TsH7nrs8hx9SPhHrX1UL6StjAHD/36SDR3Cnd3bsnqHLeCCpcJGV5mHOJrstUaMpd Q+7S9rM9S+L0WR9hRVT5ElLeNiIByjN/lb4v+aJFc99mu9LwJJFuycJmyxSvzq6Vwqgz AeAhrI5entV4I4oGXyh/pdjk85+LCNOSE6PpaSrHmvnp9YXeRut2+VaEdrfj+P+GhDqy JHzoDc/T7iQ/EF+bxNuzUuqXU9dy454OHuVuxFkd4OzZgmBAJefR4E4yavV2eb/VNWvG cXx9H4/ETS8FI3CLIGNyO02li57xRn/BdLcz5KyPCoGeRhjU7SIWW1Wewg1b6cKYB4YJ F0Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=AFJ0ednJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id a6-20020a170902900600b00153b2d16507si2645399plp.271.2022.04.15.19.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 19:34:24 -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; dkim=pass header.i=@chromium.org header.s=google header.b=AFJ0ednJ; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B6C51129E87; Fri, 15 Apr 2022 18:44:00 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240960AbiDNQ6w (ORCPT + 99 others); Thu, 14 Apr 2022 12:58:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343879AbiDNQ60 (ORCPT ); Thu, 14 Apr 2022 12:58:26 -0400 Received: from mail-oi1-x22e.google.com (mail-oi1-x22e.google.com [IPv6:2607:f8b0:4864:20::22e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26A6D14B856 for ; Thu, 14 Apr 2022 09:31:07 -0700 (PDT) Received: by mail-oi1-x22e.google.com with SMTP id b188so5925168oia.13 for ; Thu, 14 Apr 2022 09:31:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=F8L5e1xKbydF7d2L0TADvbJn6wqVOYq7/kZpJYa2SRw=; b=AFJ0ednJxVwEVa8ibNzKw/zNCLJmlAKPerqWu/u+AY66jzOv4zx/Oesal+C140g0H0 SuB4t0aZsJKwV7aL4NCyotrpd2DhcWfCCAdG0BvTPA5/fVu/bLyZqerILW1RprlCifdD qLqxjtAHsRLIYO4nB3X5MjYmJNtkw1UEHcxWk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=F8L5e1xKbydF7d2L0TADvbJn6wqVOYq7/kZpJYa2SRw=; b=MlMjrJ75MH+wObXbu60eG6Kb7vT8V74LBOlmiOl3POzVFxsYvnJqAeF34nJJkQnpNW 44c/TFCgu4GZOiDcDswB26cUKp9j9uhSs7P5izWfPpFk3Tfeki9hyqz+Rxeh2jJx8FJx 127sYvR93DJGQqtyeE4PCZ8FE9xWu/D2Q21KAdzpknsuVEJp01aFWtPmy3T6meB9d6UG mGICvHn8gYIb8ExRpBp2hhdTgLvMcIR+TL7+2Y9ashkg3Dm/6ri9PSBIRZdzKibbk12R ApzkaOSeF8XrN8ZI9qwkS6Jjv3/ibxPYpyVbFzsnHlcMcoD9IayCM/4LC01wbzs8Y6bE VHTQ== X-Gm-Message-State: AOAM533zhYFjHhsiVBI5PWIbt1UKG8+Qo3NlRb1UHzHY+KfdaMhKCNrk h0MYthqdGz8gi25TTaDR6kuamRHApnvuJg== X-Received: by 2002:a05:6808:1a2a:b0:2fa:6517:6510 with SMTP id bk42-20020a0568081a2a00b002fa65176510mr1745272oib.152.1649953866142; Thu, 14 Apr 2022 09:31:06 -0700 (PDT) Received: from mail-oa1-f42.google.com (mail-oa1-f42.google.com. [209.85.160.42]) by smtp.gmail.com with ESMTPSA id ed22-20020a056870b79600b000da32eab691sm811364oab.23.2022.04.14.09.31.03 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 14 Apr 2022 09:31:04 -0700 (PDT) Received: by mail-oa1-f42.google.com with SMTP id 586e51a60fabf-e2afb80550so5810387fac.1 for ; Thu, 14 Apr 2022 09:31:03 -0700 (PDT) X-Received: by 2002:a05:6870:f295:b0:e1:ea02:2001 with SMTP id u21-20020a056870f29500b000e1ea022001mr1597770oap.241.1649953863199; Thu, 14 Apr 2022 09:31:03 -0700 (PDT) MIME-Version: 1.0 References: <20220407115918.1.I8226c7fdae88329ef70957b96a39b346c69a914e@changeid> <022a50ac-7866-2140-1b40-776255f3a036@linux.intel.com> <4353a956-9855-9c14-7dbf-bf16580abe32@linux.intel.com> In-Reply-To: From: Evan Green Date: Thu, 14 Apr 2022 09:30:26 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] USB: hcd-pci: Fully suspend across freeze/thaw cycle To: Alan Stern Cc: Mathias Nyman , Greg Kroah-Hartman , Mathias Nyman , Rajat Jain , Thomas Gleixner , Bjorn Helgaas , "Rafael J. Wysocki" , Youngjin Jang , LKML , linux-usb@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,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 Hi Alan and Mathias, On Thu, Apr 14, 2022 at 7:21 AM Alan Stern wrote: > > 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. If I understand this correctly, this means potentially runtime resuming the device so its wakeup setting can be consistently set to wakeups disabled across a freeze transition. Got it I think in terms of the "how". > > 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. This part confuses me. This would be way deep under xhci_handle_event(), probably in handle_port_status(), just throwing away certain events that come in the ring. How would we know to go back and process those events later? I think we don't need to do this if we suspend the controller as in #3 below. The suspended (halted) controller wouldn't generate event interrupts (since the spec mentions port status change generation is gated on HCHalted). So we're already covered against receiving interrupts in this zone by halting the controller, and the events stay nicely pending for when we restart it in thaw. Is the goal of #1 purely a setup change for #2, or does it stand on its own even if we nixed #2? Said differently, is #1 trying to ensure that wake signaling doesn't occur at all between freeze and thaw, even when the controller is suspended and guaranteed not to generate interrupts via its "normal" mechanism? I don't have a crisp mental picture of how the wake signaling works, but if the controller wake mechanism sidesteps the original problem of sending an MSI to a dead CPU (as in, it does not use MSIs), then it might be ok as-is. > > 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. Sure. I had made the _noirq paths match suspend for consistency, I wasn't sure if those could mix n match without issues. I'll try it out leaving the _noirq callbacks alone. -Evan > > How does that sound? > > Alan Stern