From: Johan Hovold <johan@kernel.org>
To: Matthias Kaehlcke <mka@chromium.org>
Cc: Johan Hovold <johan+linaro@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Felipe Balbi <balbi@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Andy Gross <agross@kernel.org>,
Bjorn Andersson <bjorn.andersson@linaro.org>,
Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
Konrad Dybcio <konrad.dybcio@somainline.org>,
Krishna Kurapati <quic_kriskura@quicinc.com>,
Stephen Boyd <swboyd@chromium.org>,
Doug Anderson <dianders@chromium.org>,
Pavankumar Kondeti <quic_pkondeti@quicinc.com>,
quic_ppratap@quicinc.com, quic_vpulyala@quicinc.com,
linux-arm-msm@vger.kernel.org, linux-usb@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 3/8] usb: dwc3: qcom: fix broken non-host-mode suspend
Date: Thu, 4 Aug 2022 08:12:08 +0200 [thread overview]
Message-ID: <YutjOESZRD+4mr3Z@hovoldconsulting.com> (raw)
In-Reply-To: <YurIbcXHPF6K3oPa@google.com>
On Wed, Aug 03, 2022 at 12:11:41PM -0700, Matthias Kaehlcke wrote:
> On Tue, Aug 02, 2022 at 05:13:59PM +0200, Johan Hovold wrote:
> > A recent commit implementing wakeup support in host mode instead broke
> > suspend for peripheral and OTG mode.
> >
> > The hack that was added in the suspend path to determine the speed of
> > any device connected to the USB2 bus not only accesses internal driver
> > data for a child device, but also dereferences a NULL pointer when not
> > in host mode and there is no HCD.
> >
> > As the controller can switch role at any time when in OTG mode, there's
> > no quick fix to this, and since reverting would leave us with broken
> > suspend in host-mode (wakeup triggers immediately), keep the hack for
> > now and only fix the NULL-pointer dereference.
> >
> > Fixes: 6895ea55c385 ("usb: dwc3: qcom: Configure wakeup interrupts during suspend")
> > Signed-off-by: Johan Hovold <johan+linaro@kernel.org>
> > ---
> > drivers/usb/dwc3/dwc3-qcom.c | 11 ++++++++++-
> > 1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/usb/dwc3/dwc3-qcom.c b/drivers/usb/dwc3/dwc3-qcom.c
> > index be2e3dd36440..b75ff40f75a2 100644
> > --- a/drivers/usb/dwc3/dwc3-qcom.c
> > +++ b/drivers/usb/dwc3/dwc3-qcom.c
> > @@ -301,8 +301,17 @@ static void dwc3_qcom_interconnect_exit(struct dwc3_qcom *qcom)
> > static enum usb_device_speed dwc3_qcom_read_usb2_speed(struct dwc3_qcom *qcom)
> > {
> > struct dwc3 *dwc = platform_get_drvdata(qcom->dwc3);
> > - struct usb_hcd *hcd = platform_get_drvdata(dwc->xhci);
> > struct usb_device *udev;
> > + struct usb_hcd *hcd;
> > +
> > + if (qcom->mode != USB_DR_MODE_HOST)
> > + return USB_SPEED_UNKNOWN;
>
> Couldn't instead the below block in dwc3_qcom_suspend() be conditional on
> the controller being in host mode?
>
> if (device_may_wakeup(qcom->dev)) {
> qcom->usb2_speed = dwc3_qcom_read_usb2_speed(qcom);
> dwc3_qcom_enable_interrupts(qcom);
> }
Yeah, the authors clearly didn't consider non-host mode when
implementing this and keeping wakeups disabled in that case probably
doesn't break anything that was ever working.
> I see, the problem is that the role switch could happen at any time as the
> commit message says. With this patch there is also a race though, the role
> switch could happen just after the check and before obtaining 'hcd'.
No, there's no race here as I'm checking the static configuration that
comes from DT. Specifically, I'm not trying to add support for wakeup in
OTG mode, but just prevent suspend from crashing.
I may be possible address also the host-role in OTG mode, but that means
continuing to build on this layer violation.
Note that we're in the suspend callback of the parent so as long as the
drivers for the descendant devices has disabled role switching at this
stage during suspend, we should be good.
But I'm torn about simply ripping this patch out and trying to fix it
up. I want the feature, but the patch adding this clearly wasn't ready
for merging.
I'll take another look at this.
Johan
next prev parent reply other threads:[~2022-08-04 6:11 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-02 15:13 [PATCH 0/8] usb: dwc3: qcom: fix wakeup implementation Johan Hovold
2022-08-02 15:13 ` [PATCH 1/8] usb: dwc3: fix PHY disable sequence Johan Hovold
2022-08-02 21:21 ` Andrew Halaney
2022-08-03 17:33 ` Matthias Kaehlcke
2022-08-02 15:13 ` [PATCH 2/8] Revert "usb: dwc3: qcom: Keep power domain on to retain controller status" Johan Hovold
2022-08-02 18:00 ` Krishna Kurapati PSSNV
2022-08-03 7:42 ` Johan Hovold
2022-08-02 15:13 ` [PATCH 3/8] usb: dwc3: qcom: fix broken non-host-mode suspend Johan Hovold
2022-08-03 19:11 ` Matthias Kaehlcke
2022-08-04 6:12 ` Johan Hovold [this message]
2022-08-02 15:14 ` [PATCH 4/8] usb: dwc3: qcom: fix runtime PM wakeup Johan Hovold
2022-08-03 21:58 ` Matthias Kaehlcke
2022-08-04 7:35 ` Johan Hovold
2022-08-04 15:35 ` Matthias Kaehlcke
2022-08-04 16:04 ` Johan Hovold
2022-08-04 16:25 ` Matthias Kaehlcke
2022-08-02 15:14 ` [PATCH 5/8] Revert "dt-bindings: usb: dwc3: Add wakeup-source property support" Johan Hovold
2022-08-02 17:17 ` Rob Herring
2022-08-03 7:31 ` Johan Hovold
2022-08-03 7:51 ` Krzysztof Kozlowski
2022-08-04 7:37 ` Johan Hovold
2022-08-03 23:26 ` Rob Herring
2022-08-04 5:47 ` Johan Hovold
2022-08-04 7:40 ` Johan Hovold
2022-08-02 15:14 ` [PATCH 6/8] dt-bindings: usb: qcom,dwc3: add wakeup-source property Johan Hovold
2022-08-03 23:27 ` Rob Herring
2022-08-02 15:14 ` [PATCH 7/8] usb: dwc3: qcom: fix wakeup implementation Johan Hovold
2022-08-02 15:14 ` [PATCH 8/8] usb: dwc3: qcom: clean up suspend callbacks Johan Hovold
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YutjOESZRD+4mr3Z@hovoldconsulting.com \
--to=johan@kernel.org \
--cc=agross@kernel.org \
--cc=balbi@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=dianders@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=johan+linaro@kernel.org \
--cc=konrad.dybcio@somainline.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=manivannan.sadhasivam@linaro.org \
--cc=mka@chromium.org \
--cc=quic_kriskura@quicinc.com \
--cc=quic_pkondeti@quicinc.com \
--cc=quic_ppratap@quicinc.com \
--cc=quic_vpulyala@quicinc.com \
--cc=robh+dt@kernel.org \
--cc=swboyd@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox