mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Krishna Kurapati PSSNV <quic_kriskura@quicinc.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Colin Ian King <colin.i.king@gmail.com>,
	Jiantao Zhang <water.zhangjiantao@huawei.com>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"quic_ppratap@quicinc.com" <quic_ppratap@quicinc.com>,
	"quic_wcheng@quicinc.com" <quic_wcheng@quicinc.com>,
	"quic_jackp@quicinc.com" <quic_jackp@quicinc.com>,
	"quic_ugoswami@quicinc.com" <quic_ugoswami@quicinc.com>
Subject: Re: [PATCH v2 1/2] usb: dwc3: gadget: Bail out in pullup if soft reset timeout happens
Date: Thu, 30 Mar 2023 00:10:11 +0000	[thread overview]
Message-ID: <20230330001003.rwzo4n2hl6i22vh3@synopsys.com> (raw)
In-Reply-To: <0aa1caae-ab09-2ef9-0ec8-3dd01a3f3af0@quicinc.com>

On Wed, Mar 29, 2023, Krishna Kurapati PSSNV wrote:
> 
> 
> On 3/29/2023 2:50 AM, Thinh Nguyen wrote:
> > Hi,
> > 
> > On Tue, Mar 28, 2023, Krishna Kurapati wrote:
> > > If the core soft reset timeout happens, avoid setting up event
> > > buffers and starting gadget as the writes to these registers
> > > may not reflect when in reset and setting the run stop bit
> > > can lead the controller to access wrong event buffer address
> > > resulting in a crash.
> > > 
> > > Signed-off-by: Krishna Kurapati <quic_kriskura@quicinc.com>
> > > ---
> > >   drivers/usb/dwc3/gadget.c | 5 ++++-
> > >   1 file changed, 4 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> > > index 3c63fa97a680..f0472801d9a5 100644
> > > --- a/drivers/usb/dwc3/gadget.c
> > > +++ b/drivers/usb/dwc3/gadget.c
> > > @@ -2620,13 +2620,16 @@ static int dwc3_gadget_pullup(struct usb_gadget *g, int is_on)
> > >   		 * device-initiated disconnect requires a core soft reset
> > >   		 * (DCTL.CSftRst) before enabling the run/stop bit.
> > >   		 */
> > > -		dwc3_core_soft_reset(dwc);
> > > +		ret = dwc3_core_soft_reset(dwc);
> > > +		if (ret)
> > > +			goto done;
> > >   		dwc3_event_buffers_setup(dwc);
> > >   		__dwc3_gadget_start(dwc);
> > >   		ret = dwc3_gadget_run_stop(dwc, true, false);
> > >   	}
> > > +done:
> > >   	pm_runtime_put(dwc->dev);
> > >   	return ret;
> > > -- 
> > > 2.40.0
> > > 
> > 
> > I think there's one more place that may needs this check. Can you also
> > add this check in __dwc3_set_mode()?
> 
> Hi Thinh,
> 
>   Sure. Will do it.
> Will the below be good enough ? Or would it be good to add an error/warn log
> there>

There's already a warning message in dwc3_core_soft_reset() if it fails.

> 
> kriskura@hu-kriskura-hyd:/local/mnt/workspace/krishna/skales2/skales/kernel$
> git diff drivers/usb/
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 476b63618511..8d1d213d1dcd 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -210,7 +210,9 @@ static void __dwc3_set_mode(struct work_struct *work)
>                 }
>                 break;
>         case DWC3_GCTL_PRTCAP_DEVICE:
> -               dwc3_core_soft_reset(dwc);
> +               ret = dwc3_core_soft_reset(dwc);
> +               if (ret)
> +                       goto out;
> 
>                 dwc3_event_buffers_setup(dwc);
> 

If soft-reset failed, the controller is in a bad state. We should not
perform any further operation until the next hard reset. We should flag
the controller as dead. I don't think we have the equivalent of the
host's HCD_FLAG_DEAD. It may require some work in the UDC core. Perhaps
we can flag within dwc3 for now and prevent any further operation for a
simpler fix.

Thanks,
Thinh

  reply	other threads:[~2023-03-30  0:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-28 16:07 [PATCH v2 0/2] Handle core soft reset failure in pullup Krishna Kurapati
2023-03-28 16:07 ` [PATCH v2 1/2] usb: dwc3: gadget: Bail out in pullup if soft reset timeout happens Krishna Kurapati
2023-03-28 21:20   ` Thinh Nguyen
2023-03-29  4:34     ` Krishna Kurapati PSSNV
2023-03-30  0:10       ` Thinh Nguyen [this message]
2023-03-30 16:58         ` Krishna Kurapati PSSNV
2023-04-03 23:49           ` Thinh Nguyen
2023-04-04  4:39             ` Krishna Kurapati PSSNV
2023-04-04 21:43               ` Thinh Nguyen
2023-04-05  4:24                 ` Krishna Kurapati PSSNV
2023-04-06  0:45                   ` Thinh Nguyen
2023-04-06  2:14                     ` Krishna Kurapati PSSNV
2023-04-25 16:58                       ` Krishna Kurapati PSSNV
2023-04-26  0:22                         ` Thinh Nguyen
2023-04-26  0:43                           ` Krishna Kurapati PSSNV
2023-04-26  1:04                             ` Thinh Nguyen
2023-04-26  1:06   ` Thinh Nguyen
2023-03-28 16:07 ` [PATCH v2 2/2] usb: gadget: udc: Handle gadget_connect failure during bind operation Krishna Kurapati
2023-04-26  1:17   ` Krishna Kurapati PSSNV
2023-04-26  9:18     ` Geert Uytterhoeven
     [not found]       ` <2070d2fc-9bdc-57f8-d789-4fa6412fc7ed@quicinc.com>
     [not found]         ` <CAMuHMdUKqo6paF5efFVr0tmA3mpOAraZORoKyVFi8Pkt=H4z6Q@mail.gmail.com>
     [not found]           ` <592c2095-a6dc-de4b-713d-a9a582f966e0@quicinc.com>
2023-04-27  9:09             ` get_maintainer.pl wrong and undeterministic? (was: Re: [PATCH v2 2/2] usb: gadget: udc: Handle gadget_connect failure during bind operation) Geert Uytterhoeven
2023-04-27  9:56               ` get_maintainer.pl wrong and undeterministic? Andreas Schwab
2023-04-27 10:01                 ` Andreas Schwab
2023-04-28 21:58               ` get_maintainer.pl wrong and undeterministic? (was: Re: [PATCH v2 2/2] usb: gadget: udc: Handle gadget_connect failure during bind operation) Joe Perches
2023-04-28 17:32     ` [PATCH v2 2/2] usb: gadget: udc: Handle gadget_connect failure during bind operation Alan Stern

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=20230330001003.rwzo4n2hl6i22vh3@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=colin.i.king@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=quic_jackp@quicinc.com \
    --cc=quic_kriskura@quicinc.com \
    --cc=quic_ppratap@quicinc.com \
    --cc=quic_ugoswami@quicinc.com \
    --cc=quic_wcheng@quicinc.com \
    --cc=rafael@kernel.org \
    --cc=stern@rowland.harvard.edu \
    --cc=water.zhangjiantao@huawei.com \
    /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

all inboxes | Powered by JetHome®