Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp783601pxb; Tue, 12 Apr 2022 13:21:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyaYhlaYAQbAcRpakvK2WQt8/gfbLGm2M10RM0Eun5X1CU5t5IBcaeDtBx1gOXQJzHeVhL4 X-Received: by 2002:a17:90a:dd45:b0:1bc:9466:9b64 with SMTP id u5-20020a17090add4500b001bc94669b64mr6878369pjv.23.1649794876728; Tue, 12 Apr 2022 13:21:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649794876; cv=none; d=google.com; s=arc-20160816; b=LkBooEiDVcb3e2vJflLx+P4AaJchd88KXW7dN8mxYVHWBf4TgCCIBmKdXAuvGEZa15 YsGCU394ygzxX7peG3FXWU0sKW/H3uiQbnWiXA2Lct+K3nbZGVW6Uo7FYVWlY2EiGLCr cRFvfCUNR3n4OWes0RQ0jbsaaXfLJOPXLzAAuiDTWFwmMUBAVAABaboQ2A8EvZCoJJEY ZDgQOv+30nBqk5oqBXzU63Q8xr2yip74uVbjQbI/tE533POtqlQhIwa3tOR5QRdVkl38 m5eQRNz2fKGGRWwR7GGrAN5D3afKYwCoH9qnO/eawy4g2IGscEo5aCtXHUgZiMkyD1iP MFjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:subject:from :references:cc:to:dkim-signature; bh=iOCUFZE7qXtVv7bZ3ovwBX9vw4I4N7nSlV6QVcV2pKU=; b=LEjPADB8ukilrJMT+ugV3RM25xqxyjlOxQahngd5noaHVwNvfsw5prgnUTIa+QeOh1 w1/ThdnkcTWyJJ+1NShacgCW9dhV9+LGLGVyVvkoG49gLPtnKXOn10GOk8prFSA0iuH2 ssa0EyhABaI8GTSWosIcFNLKAwFLwnULd9FhRmGwGbeF0sHL9c1ZGBtbmYG5uLOW1hnx dYPdvke1FUHp7GW7yZevXP+tD6EYsQNKZlaYvTc/KcZ8AxOGvj3/WKnXcA6/fsjH/mPS IAbJqCCAT99O28kbn8ZZUPdbqHAePO4UtWouo4Ds2lau2vV7LJ1KVzHwttA79HW73mLo EP/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OZegW9VH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n9-20020a6546c9000000b0039cf337f6c6si3835073pgr.546.2022.04.12.13.21.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Apr 2022 13:21:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OZegW9VH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3721295A3E; Tue, 12 Apr 2022 13:03:37 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356775AbiDLO5Q (ORCPT + 99 others); Tue, 12 Apr 2022 10:57:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356768AbiDLO5J (ORCPT ); Tue, 12 Apr 2022 10:57:09 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59F63434B8; Tue, 12 Apr 2022 07:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649775291; x=1681311291; h=to:cc:references:from:subject:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=3Yi8Lm0QcJEtJvg64NU9bMmQ1C2AdaG2Xu38n8fuDTI=; b=OZegW9VHjleFbXF69KxRZA6GN3BmWvHI+ylpzZC4F5OkUt62zULutoRV 45zvuOA0EwzfWWPmIHBYKoVK4gtvj3856mDrOBL/qjsWTkdS2EaMJxGKF XbC65Tv2k3RbEpd/OhYfJ0X1Y7XVwKJFqFqflNDVQhpfbLhLj7oyiQkqE 8xzt+hazQ1ta7IrZ0kfPV6VHF3YMFJs447rVCeWseqdU+3jg1cwwANque n8N3DiBrOT2LETCp4JK4n6ckgaAFKMaR1xWqI/Vv/Jm2S53fToR/yrQ80 91wQRbEldf5qOReRtpzmEG3Xbn/GfoGtYaVAq8lY8IbOn03QqBfUgUQ+R g==; X-IronPort-AV: E=McAfee;i="6400,9594,10315"; a="242332566" X-IronPort-AV: E=Sophos;i="5.90,254,1643702400"; d="scan'208";a="242332566" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Apr 2022 07:54:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.90,254,1643702400"; d="scan'208";a="724476804" Received: from mattu-haswell.fi.intel.com (HELO [10.237.72.199]) ([10.237.72.199]) by orsmga005.jf.intel.com with ESMTP; 12 Apr 2022 07:54:48 -0700 To: Alan Stern 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 References: <20220407115918.1.I8226c7fdae88329ef70957b96a39b346c69a914e@changeid> <022a50ac-7866-2140-1b40-776255f3a036@linux.intel.com> From: Mathias Nyman Subject: Re: [PATCH] USB: hcd-pci: Fully suspend across freeze/thaw cycle Message-ID: <4353a956-9855-9c14-7dbf-bf16580abe32@linux.intel.com> Date: Tue, 12 Apr 2022 17:56:42 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 11.4.2022 17.50, Alan Stern wrote: > On Mon, Apr 11, 2022 at 01:43:15PM +0300, Mathias Nyman wrote: >> Hi >> >> On 9.4.2022 4.58, Alan Stern wrote: >>>>> So during freeze, wakeups should be disabled on root hubs. Currently I >>>>> believe we don't do this; if a root hub was already runtime suspended when >>>>> asked to go into freeze, its wakeup setting will remain unchanged. _That_ >> >> In xHCI case freeze will suspend the roothub and make sure all connected devices >> are in suspended U3 state, but it won't prevent interrupts. >> >> And yes, my understanding is also that if devices were runtime suspended with wake >> enabled before freeze, then devices can can initiate resume any time in the first >> stages of hibernate (freeze-thaw), causing an interrupt. > > Yeah. I think we need to change that. > >> We can reduce interrupts by disabling device wake in freeze, but any port change >> can still cause interrupts. > > Are you sure about this? Disabling wakeup for the root-hub device is > supposed to prevent interrupts from being generated when a port-change > event happens. Just tested connecting a device with roothub suspended and host running. Roothub ports had wake on connect disabled. It still caused interrupts. # cat power/runtime_status active # cat usb2/power/runtime_status suspended # dmesg -C # dmesg -w [ 789.341756] xhci_hcd 0000:00:14.0: Port change event, 2-3, id 15, portsc: 0x21203 [ 789.479484] xhci_hcd 0000:00:14.0: Port change event, 2-3, id 15, portsc: 0x201203 > >>>> I think xhci may still find reasons to generate interrupts even if all >>>> of its root hub ports are suspended without wake events. For example, >>>> won't Port Status Change Events still come in if a device is unplugged >>>> or overcurrents in between freeze() and thaw()? >> >> Yes, as long as host is running, and host is running between freeze and thaw. > > It's okay for the events to come in, but if wakeup is disabled on the > root hub then the events should not cause an interrupt request. > >>> I'm not an expert on xHCI or xhci-hcd. For that, we should ask the xhci-hcd >>> maintainer (CC'ed). In fact, he should have been CC'ed on the original >>> patch since it was meant to fix a problem involving xHCI controllers. >>> >>> With EHCI, for example, if a port status change event occurs while the root >>> hub is suspended with wakeups disabled, no interrupt request will be >>> generated because the port-specific WKOC_E, WKDSCNNT_E, and WKCNNT_E (Wake >>> on Over-Current Enable, Wake on Disconnect Enable, and Wake on Connect >>> Enable) bits are turned off. In effect, the port-status change events can >>> occur but they aren't treated as wakeup events. >> >> The port-specific wake flags in xHCI only affects interrupt and wake generation >> for a suspended host. In the freeze() to thaw() stage host is running so flags >> don't have any effect > > Is it possible to prevent xHCI from generating an interrupt request if a > port change occurs on the root hub while the root hub is suspended but > the controller is running? > Didn't find a good way. No new interrupt will be generated by a port change if there is a uncleared previous change bit set in that ports PORTSC register. But there is no way to manually set those bits (write 1 to clear) > 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. > > (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. 3 Disable host interrupt generation in host freeze(), and re-enable in thaw() -Mathias