Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3744603pxp; Wed, 23 Mar 2022 05:09:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzlRjGDseey9pPfeLjfxvNZqGB/JACoP82fdCe99fQ0q4uiMn1nJOLI9h6EpFugszxYLvPi X-Received: by 2002:a17:906:4fc9:b0:6e0:648e:5156 with SMTP id i9-20020a1709064fc900b006e0648e5156mr2468599ejw.412.1648037352060; Wed, 23 Mar 2022 05:09:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648037352; cv=none; d=google.com; s=arc-20160816; b=yVPHfSohdznsBW8RYD3HvUflu5/7rwjYmCigKenr1gpuMwZLMa1RjNV8HJMmOFNKSb anRTt/aJG2inTsYTlLsP/Q4fbOYdd9cYEfYxZSCIVk2vmuD4vc7k66jKSTJj6Qc4hhvN sIqhD2V9Fgy2MsvfXkQaOe4ADmISz4SPre3wR9dJ73ufyyupHMSYMk1v1xq4hpaxdT2j J2ndpqKbay2+lzLhpBg+dGeBREtpXRJUnfuPQL9J5uTWxc6z7ZSp7BIj5KOZgGrhuggm cxw2Di8rtK23CRhrMTrbQlsVa77IhfGd5zaCiLgxcts+wjVCnXWEH9rNZn8SMKKUynPh BtcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id; bh=mZix42pTLDVD09WR8TKF0dd7d5Gdp3IE1RuLOuLprdU=; b=Xf762Cs9RhLfr//VzEVGZq7WsBYtgsePrwkgShrcxhoxM5qa4hZnAPaRSa4QiqC5m7 OtJs0+BosjiwmIG7Sez8Z5QBfh+9ZZcF1JHRyhlv6uzW29sI+RPSC3sP9eBE7NOhYW14 DcqIBGUsorvoppY7rCTWR/2T0LNQOEDKqp9mBzRBkQCZOm0ybOdZGiIoU9iHuQo0ChnT /CXDKUef0Dx+0B4ZHvbtxZSzTAES10eVNhLkJ3UKvLHMC+fEU5ej6gQPSQujBpFoW/e9 k3EbqyZY9IPQ/IiNL8Cu2VROjxk9CrLcMp/4WvEeZpDPOx6DEzay0Lv+YsFBFK45dMSh EoVA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a170906748400b006df76385baesi11713057ejl.78.2022.03.23.05.08.39; Wed, 23 Mar 2022 05:09:11 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235889AbiCVNyA (ORCPT + 99 others); Tue, 22 Mar 2022 09:54:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234662AbiCVNx6 (ORCPT ); Tue, 22 Mar 2022 09:53:58 -0400 Received: from ZXSHCAS2.zhaoxin.com (ZXSHCAS2.zhaoxin.com [203.148.12.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD6098595D; Tue, 22 Mar 2022 06:52:28 -0700 (PDT) Received: from zxbjmbx1.zhaoxin.com (10.29.252.163) by ZXSHCAS2.zhaoxin.com (10.28.252.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Tue, 22 Mar 2022 21:52:17 +0800 Received: from [10.29.8.49] (10.29.8.49) by zxbjmbx1.zhaoxin.com (10.29.252.163) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 22 Mar 2022 21:52:16 +0800 Message-ID: <08762dd0-7e73-4a0e-0962-a7c05f342ea6@zhaoxin.com> Date: Tue, 22 Mar 2022 21:52:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.0 Subject: Re: [PATCH] USB:Fix ehci infinite suspend-resume loop issue in zhaoxin Content-Language: en-US From: "WeitaoWang-oc@zhaoxin.com" To: Alan Stern CC: , , , , , , References: <3d0ae3ca-9dad-bb8f-5c41-45bdcb07b9cd@zhaoxin.com> <320584eb-ef89-3759-509c-e7e9cb10f983@zhaoxin.com> In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.29.8.49] X-ClientProxiedBy: ZXSHCAS2.zhaoxin.com (10.28.252.162) To zxbjmbx1.zhaoxin.com (10.29.252.163) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 2022/3/16 10:18, WeitaoWang-oc@zhaoxin.com wrote: > On 2022/3/15 11:18, Alan Stern wrote: >> On Tue, Mar 15, 2022 at 08:39:09PM +0800, WeitaoWang-oc@zhaoxin.com wrote: >>> On 2022/3/14 10:24, Alan Stern wrote: >>>>> +       t1 = ehci_readl(ehci, &ehci->regs->status); >>>>> +       ehci_writel(ehci, t1 & STS_PCD, &ehci->regs->status); >>>>> +       ehci_readl(ehci, &ehci->regs->status); >>>> >>>> You should not clear the STS_PCD bit.  What if some other port had a >>>> status change at the same time?  Then because you cleared the >>>> port-change-detect bit, the system would not realize that the other port >>>> needed to be handled. >>> >>> I really didn't think about this case. >>> >>>> Leaving the STS_PCD bit turned on will cause the driver to do a little >>>> extra work, but it shouldn't cause any harm. >>>> >>> I have encountered the following situation if EHCI runtime suspend is >>> enabled by default. >>> >>> >>> >>> 1.Wake from system to disk and boot OS. >> >> You're talking about resuming after hibernation, right? > > You're right. >>> 2.EHCI will entry runtime suspend after enumerated by driver during boot >>> phase of suspend to disk >> >> I'm not sure what you mean by "boot phase of suspend to disk".  This is >> while the restore kernel is starting up at the beginning of resume from >> hibernation, right? >> > You understood exactly what I was saying. > > >>> 3.EHCI will be placed to freeze state and ehci_resume is called after image >>> is loaded. >> >> ehci_resume is called to leave runtime suspend.  Going into the freeze >> state doesn't require any changes. >> >>> 4.If PCD flag is set(caused by patch), then HCD_FLAG_RH_RUNNING will be set. >>> >>> 5.Pci_pm_freeze_noirq is called to check ehci root hub state and return >>> value is -EBUSY. which will cause >>>   quiesce phase of suspend to disk fail. >> >> You're talking about check_root_hub_suspended() in hcd-pci.c, right? >> > It's right. >> You know, I'm not at all certain that the callbacks for freeze and >> freeze_noirq should ever return anything other than 0.  It's okay for >> them to call check_root_hub_suspended(), but they should ignore its >> return value. >> >> Can you check if the patch below helps? >> >> Alan Stern >> >> >> Index: usb-devel/drivers/usb/core/hcd-pci.c >> =================================================================== >> --- usb-devel.orig/drivers/usb/core/hcd-pci.c >> +++ usb-devel/drivers/usb/core/hcd-pci.c >> @@ -575,6 +575,12 @@ static int hcd_pci_resume(struct device >>       return resume_common(dev, PM_EVENT_RESUME); >>   } >> +static int hcd_pci_freeze_check(struct device *dev) >> +{ >> +    (void) check_root_hub_suspended(dev); >> +    return 0; >> +} >> + >>   static int hcd_pci_restore(struct device *dev) >>   { >>       return resume_common(dev, PM_EVENT_RESTORE); >> @@ -586,6 +592,7 @@ static int hcd_pci_restore(struct device >>   #define hcd_pci_suspend_noirq    NULL >>   #define hcd_pci_resume_noirq    NULL >>   #define hcd_pci_resume        NULL >> +#define hcd_pci_freeze_check    NULL >>   #define hcd_pci_restore        NULL >>   #endif    /* CONFIG_PM_SLEEP */ >> @@ -616,8 +623,8 @@ const struct dev_pm_ops usb_hcd_pci_pm_o >>       .suspend_noirq    = hcd_pci_suspend_noirq, >>       .resume_noirq    = hcd_pci_resume_noirq, >>       .resume        = hcd_pci_resume, >> -    .freeze        = check_root_hub_suspended, >> -    .freeze_noirq    = check_root_hub_suspended, >> +    .freeze        = hcd_pci_freeze_check, >> +    .freeze_noirq    = hcd_pci_freeze_check, > > This patch can fix pci driver's fail check in freeze_noirq phase. > > Restoring system state from a hibernation image can continue and success. > > Weitao Wang This patch seems work for our platform, but I don't know if there will be side-effects for others. So I want to take your previous suggestion and not to clear PCD, As ehci runtime suspend enabled at OS startup is not a real requirement. I'll resubmit revised patch without the whitespace damage. Thanks for your great help. Best Wishes Weitao Wang >>       .thaw_noirq    = NULL, >>       .thaw        = NULL, >>       .poweroff    = hcd_pci_suspend, >> . >>