Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2730963pxb; Mon, 17 Jan 2022 04:45:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJw6A7+BNTrgNOd5CxzS8jsk++cbxToYctsRWScV4sPp08Ly+jOir2agqM4kHrTIzeveykyy X-Received: by 2002:a17:902:b206:b0:149:3b5d:2b8b with SMTP id t6-20020a170902b20600b001493b5d2b8bmr22110457plr.162.1642423559300; Mon, 17 Jan 2022 04:45:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642423559; cv=none; d=google.com; s=arc-20160816; b=u6oMRax0WRwftWrKUSlWYXuP+phmX/TV8D3TWQ5CmAPZdnZFO3QvJOMuzGOFMZYR5/ MgoSb7v7Svpsz3CiDc3zR2HEE3evMMtWycIZpPja4WrCaYZppo1Ke0KrtwmwwRZ+AT2F XvXfOFZHY1wQ+j84l5zvK8nielWdt+wBektDweFU6DEjFi2sbWYj5Lz8G7kTRjkS7WLk 47sVAkhXWtQzlm0oOHqtTtugPNVvILeKB7WOJl1yj52eGiPRmtSGneQKq3A4C2DPoC26 mGvortGZCxSvnU+OQQEq6ey4YLcIGU7ihxhgoB93aY1KwYgjqnSV5v6WAFwFugB70tPN 98zA== 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 :dkim-signature; bh=ISpM5IrkTHsOLgNJIWuzTE0806bOg7B0Sd40UWe36MY=; b=0zZHoCgtFMAE6qlqdIG4ECngZvxM3W8HTaje+S+VhDo4+ELAAt87Rf/oX2+mCBBhwd Y/UkOvmuOA7ww9zhUruFyO3dESJV8a46HvPotVSswz1KXyCUE/aScG5UL4AiEh4yoxri dJKrDVsV9yrgJK6SKgYncrX1Bn2y3NM5BzESxFUI+pklZK7wdGTKwcQtzcj4NjPvHHZY rE6EQeyaQUxhZ0SFAkSdIipoW/pTQOhNXpx6sIt2trU41K+7RfJgrlcNMYJUugKv39sH WH+t+WBrWYcKMYuPbNumkEDoUJySEdEl+tcx44ERs2gV7+LvrJqu08+c+KkMVElM6Dob jROQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mEmWRcI8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t191si14756430pgc.191.2022.01.17.04.45.47; Mon, 17 Jan 2022 04:45:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=mEmWRcI8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231894AbiAQFYr (ORCPT + 99 others); Mon, 17 Jan 2022 00:24:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231974AbiAQFYi (ORCPT ); Mon, 17 Jan 2022 00:24:38 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 084D5C061765 for ; Sun, 16 Jan 2022 21:24:38 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id i17so9229940pfk.11 for ; Sun, 16 Jan 2022 21:24:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=ISpM5IrkTHsOLgNJIWuzTE0806bOg7B0Sd40UWe36MY=; b=mEmWRcI8rpsg6TVZzLXBc4yugerwYpj+1EEmNn/rJ8cJt+cMEF4GiUnb9KyxiUw+SW 1aO3wa1dG9ddyVopK+OCJ+xArSKONuiiRSGgDkmALA1ArRsBK43EGeeaxLFpXOlgWcwp Y5ZwP0DkQ3D3dq/NaX3RjrKvPGzSr9GFTP6xLSBJ51dHQo2/RSBmexvFPgcsMuW6a2qV 0svRY0qCbO6zl2v+JziGGW/GOWm4VVaBZvpwjP28z6hrOq8bjRuj4jYKOSbF9ZqNNDhl ZBLFWxERjjWjHnKOsoUx6Llwjjm/kgmrNOBdJj3gOxivQZU/186xYQO7jlfwZTiRIbO/ R2iw== 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:content-transfer-encoding; bh=ISpM5IrkTHsOLgNJIWuzTE0806bOg7B0Sd40UWe36MY=; b=6vKiwR/I/y10PFv6RtXQ7waKgtkvVMU8eW+f7Hq57Nop5wrGd6UvYSa465MrSpkYQZ P1WvI+Z0EKUPNFwvjximPWAode7uGJoEBUmp070e0YEkV4BZQhd9rI5XCh5PWO+bHQzi B7DN8lQSpQQ60JKEDsPIWrxGPHNkAUVyIv/gN4xq0sUUmTLd6c9MB0uNwPSm99rfFeS3 WhSxKncSn5C6XCb/x/WfL1jb8PWdzR2pTInCXXWhPSQZvrca19odHYMQw4gDAGRlvHjD XRvwN/hgeC1Zid03VqWJN4QPfY3zNiTRpZMIJ26Dj4HB94ieTYSg2+16QdG5n6H4BfNY OPIw== X-Gm-Message-State: AOAM532+TQiwZnLsM9ySu456DAv47vosy9keTGPY10PbopZOVSApZ4+g ob0q4INSIdcxCjzh7yzf/+DzSU18r7i401TDLu6+ozjjfe8FMA== X-Received: by 2002:a63:fe47:: with SMTP id x7mr5625761pgj.415.1642397077062; Sun, 16 Jan 2022 21:24:37 -0800 (PST) MIME-Version: 1.0 References: <20211229112551.3483931-1-pumahsu@google.com> In-Reply-To: From: Puma Hsu Date: Mon, 17 Jan 2022 13:24:01 +0800 Message-ID: Subject: Re: [PATCH v3] xhci: re-initialize the HC during resume if HCE was set To: Greg KH Cc: mathias.nyman@intel.com, Sergey Shtylyov , Albert Wang , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 13, 2022 at 4:21 PM Greg KH wrote: > > On Thu, Jan 13, 2022 at 03:54:27PM +0800, Puma Hsu wrote: > > On Tue, Jan 11, 2022 at 7:43 PM Greg KH wr= ote: > > > > > > On Wed, Dec 29, 2021 at 07:25:51PM +0800, Puma Hsu wrote: > > > > When HCE(Host Controller Error) is set, it means an internal > > > > error condition has been detected. It needs to re-initialize > > > > the HC too. > > > > > > What is "It" in the last sentence? > > > > Maybe I can change "It" to "Software", xHCI specification uses > > "Software" when describing this. > > Please change it to something better :) I will fix it in next patch version. > > > > > > > > Cc: stable@vger.kernel.org > > > > Signed-off-by: Puma Hsu > > > > > > What commit id does this fix? > > > > This commit is not used to fix a specific commit. We find a condition > > that when XHCI runs the resume process but the HCE flag is set, then > > the Run/Stop bit of USBCMD cannot be set so that HC would not be > > enabled. In fact, HC may already meet a problem at this moment. > > Besides, in xHCI requirements specification revision 1.2, Table 5-21 > > BIT(12) claims that Software should re-initialize the xHC when HCE is > > set. Therefore, I think this commit could be the error handling for > > HCE. > > So this problem has been there since the driver was first added to the > kernel? Should it go to stable kernels as well? If so, how far back in > time? I think XHCI hasn=E2=80=99t handled HCE, so yes this may be a long problem. I have cced stable@vger.kernel.org for stable backporting, but I=E2=80=99m = not sure how far it should backport since it seems this might be a rare case if no o= ne reported this issue? > > > > --- > > > > v2: Follow Sergey Shtylyov 's comment. > > > > v3: Add stable@vger.kernel.org for stable release. > > > > > > > > drivers/usb/host/xhci.c | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c > > > > index dc357cabb265..ab440ce8420f 100644 > > > > --- a/drivers/usb/host/xhci.c > > > > +++ b/drivers/usb/host/xhci.c > > > > @@ -1146,8 +1146,8 @@ int xhci_resume(struct xhci_hcd *xhci, bool h= ibernated) > > > > temp =3D readl(&xhci->op_regs->status); > > > > } > > > > > > > > - /* If restore operation fails, re-initialize the HC during re= sume */ > > > > - if ((temp & STS_SRE) || hibernated) { > > > > + /* If restore operation fails or HC error is detected, re-ini= tialize the HC during resume */ > > > > + if ((temp & (STS_SRE | STS_HCE)) || hibernated) { > > > > > > But if STS_HCE is set on suspend, that means the suspend was broken s= o > > > you wouldn't get here, right? > > > > In xhci_suspend(), it seems doesn't really check whether STS_HCE is > > set and then break the suspend(The only case for checking HCE is when > > STS_SAVE setting failed). So suspend function may be still able to > > finish even if HCE is set? Then xhci_resume will still be called. > > Is this a problem? It could be, but I'm not sure and I think it may be not so serious if HCE was raised while suspend, because host controller doesn=E2=80=99t have job while suspe= nd. And we are trying to recover it while resume. > > > Or can the error happen between suspend and resume? > > > > > > This seems like a big hammer for when the host controller throws an > > > error. Why is this the only place that it should be checked for? Wh= at > > > caused the error that can now allow it to be fixed? > > > > I believe this is not the only place that the host controller may set > > HCE, the host controller may set HCE anytime it sees an error in my > > opinion, not only in suspend or resume. > > Then where else should it be checked? Where else will your silicon set > this bit as part of the normal operating process? We observed this flag while resume in our silicon so far. According to the = XHCI specification 4.24.1, =E2=80=9CSoftware should implement an algorithm for c= hecking the HCE flag if the xHC is not responding.=E2=80=9D, so maybe it would be bette= r to implement a new API to recover host controller whenever the driver side finds no resp= onse from host controller in the future. > thanks, > > greg k-h