All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] usb: cdns3: fix race condition before setting doorbell
@ 2021-09-30  9:42 Pawel Laszczak
  2021-09-30 10:03 ` Greg KH
  0 siblings, 1 reply; 7+ messages in thread
From: Pawel Laszczak @ 2021-09-30  9:42 UTC (permalink / raw)
  To: stable; +Cc: Pawel Laszczak

From: Pawel Laszczak <pawell@cadence.com>

commit b69ec50b3e55c4b2a85c8bc46763eaf33060584 upstream

For DEV_VER_V3 version there exist race condition between clearing
ep_sts.EP_STS_TRBERR and setting ep_cmd.EP_CMD_DRDY bit.
Setting EP_CMD_DRDY will be ignored by controller when
EP_STS_TRBERR is set. So, between these two instructions we have
a small time gap in which the EP_STS_TRBERR can be set. In such case
the transfer will not start after setting doorbell.

Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
cc: <stable@vger.kernel.org> # 5.4.x
Tested-by: Aswath Govindraju <a-govindraju@ti.com>
Reviewed-by: Aswath Govindraju <a-govindraju@ti.com>
Signed-off-by: Pawel Laszczak <pawell@cadence.com>
---
 drivers/usb/cdns3/gadget.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/usb/cdns3/gadget.c b/drivers/usb/cdns3/gadget.c
index f624cc87cbab..5edde6a0e77a 100644
--- a/drivers/usb/cdns3/gadget.c
+++ b/drivers/usb/cdns3/gadget.c
@@ -807,6 +807,19 @@ static void cdns3_wa1_tray_restore_cycle_bit(struct cdns3_device *priv_dev,
 		cdns3_wa1_restore_cycle_bit(priv_ep);
 }
 
+static void cdns3_rearm_drdy_if_needed(struct cdns3_endpoint *priv_ep)
+{
+	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
+
+	if (priv_dev->dev_ver < DEV_VER_V3)
+		return;
+
+	if (readl(&priv_dev->regs->ep_sts) & EP_STS_TRBERR) {
+		writel(EP_STS_TRBERR, &priv_dev->regs->ep_sts);
+		writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd);
+	}
+}
+
 /**
  * cdns3_ep_run_transfer - start transfer on no-default endpoint hardware
  * @priv_ep: endpoint object
@@ -1003,6 +1016,7 @@ int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
 		/*clearing TRBERR and EP_STS_DESCMIS before seting DRDY*/
 		writel(EP_STS_TRBERR | EP_STS_DESCMIS, &priv_dev->regs->ep_sts);
 		writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd);
+		cdns3_rearm_drdy_if_needed(priv_ep);
 		trace_cdns3_doorbell_epx(priv_ep->name,
 					 readl(&priv_dev->regs->ep_traddr));
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] usb: cdns3: fix race condition before setting doorbell
  2021-09-30  9:42 [PATCH] usb: cdns3: fix race condition before setting doorbell Pawel Laszczak
@ 2021-09-30 10:03 ` Greg KH
  2021-09-30 10:22   ` Pawel Laszczak
  0 siblings, 1 reply; 7+ messages in thread
From: Greg KH @ 2021-09-30 10:03 UTC (permalink / raw)
  To: Pawel Laszczak; +Cc: stable

On Thu, Sep 30, 2021 at 11:42:17AM +0200, Pawel Laszczak wrote:
> From: Pawel Laszczak <pawell@cadence.com>
> 
> commit b69ec50b3e55c4b2a85c8bc46763eaf33060584 upstream
> 
> For DEV_VER_V3 version there exist race condition between clearing
> ep_sts.EP_STS_TRBERR and setting ep_cmd.EP_CMD_DRDY bit.
> Setting EP_CMD_DRDY will be ignored by controller when
> EP_STS_TRBERR is set. So, between these two instructions we have
> a small time gap in which the EP_STS_TRBERR can be set. In such case
> the transfer will not start after setting doorbell.
> 
> Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
> cc: <stable@vger.kernel.org> # 5.4.x
> Tested-by: Aswath Govindraju <a-govindraju@ti.com>
> Reviewed-by: Aswath Govindraju <a-govindraju@ti.com>
> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
> ---
>  drivers/usb/cdns3/gadget.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)

What kernel(s) are you wanting this applied to?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH] usb: cdns3: fix race condition before setting doorbell
  2021-09-30 10:03 ` Greg KH
@ 2021-09-30 10:22   ` Pawel Laszczak
  2021-10-01 16:52     ` Sasha Levin
  0 siblings, 1 reply; 7+ messages in thread
From: Pawel Laszczak @ 2021-09-30 10:22 UTC (permalink / raw)
  To: Greg KH; +Cc: stable

>
>On Thu, Sep 30, 2021 at 11:42:17AM +0200, Pawel Laszczak wrote:
>> From: Pawel Laszczak <pawell@cadence.com>
>>
>> commit b69ec50b3e55c4b2a85c8bc46763eaf33060584 upstream
>>
>> For DEV_VER_V3 version there exist race condition between clearing
>> ep_sts.EP_STS_TRBERR and setting ep_cmd.EP_CMD_DRDY bit.
>> Setting EP_CMD_DRDY will be ignored by controller when
>> EP_STS_TRBERR is set. So, between these two instructions we have
>> a small time gap in which the EP_STS_TRBERR can be set. In such case
>> the transfer will not start after setting doorbell.
>>
>> Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
>> cc: <stable@vger.kernel.org> # 5.4.x
>> Tested-by: Aswath Govindraju <a-govindraju@ti.com>
>> Reviewed-by: Aswath Govindraju <a-govindraju@ti.com>
>> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
>> ---
>>  drivers/usb/cdns3/gadget.c | 14 ++++++++++++++
>>  1 file changed, 14 insertions(+)
>
>What kernel(s) are you wanting this applied to?

To 5.4. I added information in cc: <stable@vger.kernel.org>  tag (# 5.4.x) . 
Is it sufficient or not?  I ask because I need to post this fix also to v5.10.

Thanks,
Pawel

>
>thanks,
>
>greg k-h

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] usb: cdns3: fix race condition before setting doorbell
  2021-09-30 10:22   ` Pawel Laszczak
@ 2021-10-01 16:52     ` Sasha Levin
  2021-10-04  4:00       ` Pawel Laszczak
  0 siblings, 1 reply; 7+ messages in thread
From: Sasha Levin @ 2021-10-01 16:52 UTC (permalink / raw)
  To: Pawel Laszczak; +Cc: Greg KH, stable

On Thu, Sep 30, 2021 at 10:22:42AM +0000, Pawel Laszczak wrote:
>>
>>On Thu, Sep 30, 2021 at 11:42:17AM +0200, Pawel Laszczak wrote:
>>> From: Pawel Laszczak <pawell@cadence.com>
>>>
>>> commit b69ec50b3e55c4b2a85c8bc46763eaf33060584 upstream
>>>
>>> For DEV_VER_V3 version there exist race condition between clearing
>>> ep_sts.EP_STS_TRBERR and setting ep_cmd.EP_CMD_DRDY bit.
>>> Setting EP_CMD_DRDY will be ignored by controller when
>>> EP_STS_TRBERR is set. So, between these two instructions we have
>>> a small time gap in which the EP_STS_TRBERR can be set. In such case
>>> the transfer will not start after setting doorbell.
>>>
>>> Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
>>> cc: <stable@vger.kernel.org> # 5.4.x
>>> Tested-by: Aswath Govindraju <a-govindraju@ti.com>
>>> Reviewed-by: Aswath Govindraju <a-govindraju@ti.com>
>>> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
>>> ---
>>>  drivers/usb/cdns3/gadget.c | 14 ++++++++++++++
>>>  1 file changed, 14 insertions(+)
>>
>>What kernel(s) are you wanting this applied to?
>
>To 5.4. I added information in cc: <stable@vger.kernel.org>  tag (# 5.4.x) .
>Is it sufficient or not?  I ask because I need to post this fix also to v5.10.

I queued this up for both 5.10 and 5.4, thanks.

The issue seems to be that in the upstream patch you explicitly stated
to go only to 5.12:

	cc: <stable@vger.kernel.org> # 5.12.x

Was that your intent?

-- 
Thanks,
Sasha

^ permalink raw reply	[flat|nested] 7+ messages in thread

* RE: [PATCH] usb: cdns3: fix race condition before setting doorbell
  2021-10-01 16:52     ` Sasha Levin
@ 2021-10-04  4:00       ` Pawel Laszczak
  0 siblings, 0 replies; 7+ messages in thread
From: Pawel Laszczak @ 2021-10-04  4:00 UTC (permalink / raw)
  To: Sasha Levin; +Cc: Greg KH, stable

>
>
>On Thu, Sep 30, 2021 at 10:22:42AM +0000, Pawel Laszczak wrote:
>>>
>>>On Thu, Sep 30, 2021 at 11:42:17AM +0200, Pawel Laszczak wrote:
>>>> From: Pawel Laszczak <pawell@cadence.com>
>>>>
>>>> commit b69ec50b3e55c4b2a85c8bc46763eaf33060584 upstream
>>>>
>>>> For DEV_VER_V3 version there exist race condition between clearing
>>>> ep_sts.EP_STS_TRBERR and setting ep_cmd.EP_CMD_DRDY bit.
>>>> Setting EP_CMD_DRDY will be ignored by controller when
>>>> EP_STS_TRBERR is set. So, between these two instructions we have
>>>> a small time gap in which the EP_STS_TRBERR can be set. In such case
>>>> the transfer will not start after setting doorbell.
>>>>
>>>> Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
>>>> cc: <stable@vger.kernel.org> # 5.4.x
>>>> Tested-by: Aswath Govindraju <a-govindraju@ti.com>
>>>> Reviewed-by: Aswath Govindraju <a-govindraju@ti.com>
>>>> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
>>>> ---
>>>>  drivers/usb/cdns3/gadget.c | 14 ++++++++++++++
>>>>  1 file changed, 14 insertions(+)
>>>
>>>What kernel(s) are you wanting this applied to?
>>
>>To 5.4. I added information in cc: <stable@vger.kernel.org>  tag (# 5.4.x) .
>>Is it sufficient or not?  I ask because I need to post this fix also to v5.10.
>
>I queued this up for both 5.10 and 5.4, thanks.
>
>The issue seems to be that in the upstream patch you explicitly stated
>to go only to 5.12:
>
>	cc: <stable@vger.kernel.org> # 5.12.x
>
>Was that your intent?

Yes. 
Patch could not be applied to older kernel version because files name were changed.

Thanks 
Pawel Laszczak

>
>--
>Thanks,
>Sasha

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] usb: cdns3: fix race condition before setting doorbell
  2021-09-07  6:26 Pawel Laszczak
@ 2021-09-07  7:28 ` Aswath Govindraju
  0 siblings, 0 replies; 7+ messages in thread
From: Aswath Govindraju @ 2021-09-07  7:28 UTC (permalink / raw)
  To: Pawel Laszczak, peter.chen
  Cc: rogerq, gregkh, felipe.balbi, linux-usb, linux-kernel, stable

On 07/09/21 11:56 am, Pawel Laszczak wrote:
> From: Pawel Laszczak <pawell@cadence.com>
> 
> For DEV_VER_V3 version there exist race condition between clearing
> ep_sts.EP_STS_TRBERR and setting ep_cmd.EP_CMD_DRDY bit.
> Setting EP_CMD_DRDY will be ignored by controller when
> EP_STS_TRBERR is set. So, between these two instructions we have
> a small time gap in which the EP_STSS_TRBERR can be set. In such case
> the transfer will not start after setting doorbell.
> 
> Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
> cc: <stable@vger.kernel.org> # 5.12.x
> Signed-off-by: Pawel Laszczak <pawell@cadence.com>
> ---

Reviewed-by: Aswath Govindraju <a-govindraju@ti.com>
Tested-by: Aswath Govindraju <a-govindraju@ti.com>

>  drivers/usb/cdns3/cdns3-gadget.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
> index 80aaab159e58..e9769fab21ea 100644
> --- a/drivers/usb/cdns3/cdns3-gadget.c
> +++ b/drivers/usb/cdns3/cdns3-gadget.c
> @@ -1100,6 +1100,19 @@ static int cdns3_ep_run_stream_transfer(struct cdns3_endpoint *priv_ep,
>  	return 0;
>  }
>  
> +static void cdns3_rearm_drdy_if_needed(struct cdns3_endpoint *priv_ep)
> +{
> +	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
> +
> +	if (priv_dev->dev_ver < DEV_VER_V3)
> +		return;
> +
> +	if (readl(&priv_dev->regs->ep_sts) & EP_STS_TRBERR) {
> +		writel(EP_STS_TRBERR, &priv_dev->regs->ep_sts);
> +		writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd);
> +	}
> +}
> +
>  /**
>   * cdns3_ep_run_transfer - start transfer on no-default endpoint hardware
>   * @priv_ep: endpoint object
> @@ -1351,6 +1364,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
>  		/*clearing TRBERR and EP_STS_DESCMIS before seting DRDY*/
>  		writel(EP_STS_TRBERR | EP_STS_DESCMIS, &priv_dev->regs->ep_sts);
>  		writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd);
> +		cdns3_rearm_drdy_if_needed(priv_ep);
>  		trace_cdns3_doorbell_epx(priv_ep->name,
>  					 readl(&priv_dev->regs->ep_traddr));
>  	}
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] usb: cdns3: fix race condition before setting doorbell
@ 2021-09-07  6:26 Pawel Laszczak
  2021-09-07  7:28 ` Aswath Govindraju
  0 siblings, 1 reply; 7+ messages in thread
From: Pawel Laszczak @ 2021-09-07  6:26 UTC (permalink / raw)
  To: peter.chen
  Cc: pawell, rogerq, a-govindraju, gregkh, felipe.balbi, linux-usb,
	linux-kernel, stable

From: Pawel Laszczak <pawell@cadence.com>

For DEV_VER_V3 version there exist race condition between clearing
ep_sts.EP_STS_TRBERR and setting ep_cmd.EP_CMD_DRDY bit.
Setting EP_CMD_DRDY will be ignored by controller when
EP_STS_TRBERR is set. So, between these two instructions we have
a small time gap in which the EP_STSS_TRBERR can be set. In such case
the transfer will not start after setting doorbell.

Fixes: 7733f6c32e36 ("usb: cdns3: Add Cadence USB3 DRD Driver")
cc: <stable@vger.kernel.org> # 5.12.x
Signed-off-by: Pawel Laszczak <pawell@cadence.com>
---
 drivers/usb/cdns3/cdns3-gadget.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/usb/cdns3/cdns3-gadget.c b/drivers/usb/cdns3/cdns3-gadget.c
index 80aaab159e58..e9769fab21ea 100644
--- a/drivers/usb/cdns3/cdns3-gadget.c
+++ b/drivers/usb/cdns3/cdns3-gadget.c
@@ -1100,6 +1100,19 @@ static int cdns3_ep_run_stream_transfer(struct cdns3_endpoint *priv_ep,
 	return 0;
 }
 
+static void cdns3_rearm_drdy_if_needed(struct cdns3_endpoint *priv_ep)
+{
+	struct cdns3_device *priv_dev = priv_ep->cdns3_dev;
+
+	if (priv_dev->dev_ver < DEV_VER_V3)
+		return;
+
+	if (readl(&priv_dev->regs->ep_sts) & EP_STS_TRBERR) {
+		writel(EP_STS_TRBERR, &priv_dev->regs->ep_sts);
+		writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd);
+	}
+}
+
 /**
  * cdns3_ep_run_transfer - start transfer on no-default endpoint hardware
  * @priv_ep: endpoint object
@@ -1351,6 +1364,7 @@ static int cdns3_ep_run_transfer(struct cdns3_endpoint *priv_ep,
 		/*clearing TRBERR and EP_STS_DESCMIS before seting DRDY*/
 		writel(EP_STS_TRBERR | EP_STS_DESCMIS, &priv_dev->regs->ep_sts);
 		writel(EP_CMD_DRDY, &priv_dev->regs->ep_cmd);
+		cdns3_rearm_drdy_if_needed(priv_ep);
 		trace_cdns3_doorbell_epx(priv_ep->name,
 					 readl(&priv_dev->regs->ep_traddr));
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-10-04  4:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-30  9:42 [PATCH] usb: cdns3: fix race condition before setting doorbell Pawel Laszczak
2021-09-30 10:03 ` Greg KH
2021-09-30 10:22   ` Pawel Laszczak
2021-10-01 16:52     ` Sasha Levin
2021-10-04  4:00       ` Pawel Laszczak
  -- strict thread matches above, loose matches on Subject: below --
2021-09-07  6:26 Pawel Laszczak
2021-09-07  7:28 ` Aswath Govindraju

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.