All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] usb: dwc3: gadget: delay unmap of bounced requests
@ 2017-04-10 14:15 Felipe Balbi
  2017-04-10 14:48 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 3+ messages in thread
From: Felipe Balbi @ 2017-04-10 14:15 UTC (permalink / raw)
  To: stable
  Cc: Greg Kroah-Hartman, nsekhar, rogerq, januszx.dziedzic, Felipe Balbi

From: Janusz Dziedzic <januszx.dziedzic@intel.com>

commit de288e36fe33f7e06fa272bc8e2f85aa386d99aa upstream.

In the case of bounced ep0 requests, we must delay DMA operation until
after ->complete() otherwise we might overwrite contents of req->buf.

This caused problems with RNDIS gadget.

Cc: <stable@vger.kernel.org>
Fixes: d62145929992 ("usb: dwc3: gadget: always unmap EP0 requests")
Signed-off-by: Janusz Dziedzic <januszx.dziedzic@intel.com>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
---

Note that this commit needs to be backported to all kernels where
d62145929992 was backported.

 drivers/usb/dwc3/gadget.c | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 0d75158e43fe..79e7a3480d51 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -171,6 +171,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 		int status)
 {
 	struct dwc3			*dwc = dep->dwc;
+	unsigned int			unmap_after_complete = false;
 
 	req->started = false;
 	list_del(&req->list);
@@ -180,11 +181,19 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 	if (req->request.status == -EINPROGRESS)
 		req->request.status = status;
 
-	if (dwc->ep0_bounced && dep->number <= 1)
+	/*
+	 * NOTICE we don't want to unmap before calling ->complete() if we're
+	 * dealing with a bounced ep0 request. If we unmap it here, we would end
+	 * up overwritting the contents of req->buf and this could confuse the
+	 * gadget driver.
+	 */
+	if (dwc->ep0_bounced && dep->number <= 1) {
 		dwc->ep0_bounced = false;
-
-	usb_gadget_unmap_request_by_dev(dwc->sysdev,
-			&req->request, req->direction);
+		unmap_after_complete = true;
+	} else {
+		usb_gadget_unmap_request_by_dev(dwc->sysdev,
+				&req->request, req->direction);
+	}
 
 	trace_dwc3_gadget_giveback(req);
 
@@ -192,6 +201,10 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req,
 	usb_gadget_giveback_request(&dep->endpoint, &req->request);
 	spin_lock(&dwc->lock);
 
+	if (unmap_after_complete)
+		usb_gadget_unmap_request_by_dev(dwc->sysdev,
+				&req->request, req->direction);
+
 	if (dep->number > 1)
 		pm_runtime_put(dwc->dev);
 }
-- 
2.11.0.295.gd7dffce1ce

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

* Re: [PATCH v2] usb: dwc3: gadget: delay unmap of bounced requests
  2017-04-10 14:15 [PATCH v2] usb: dwc3: gadget: delay unmap of bounced requests Felipe Balbi
@ 2017-04-10 14:48 ` Greg Kroah-Hartman
  2017-04-10 14:54   ` Felipe Balbi
  0 siblings, 1 reply; 3+ messages in thread
From: Greg Kroah-Hartman @ 2017-04-10 14:48 UTC (permalink / raw)
  To: Felipe Balbi; +Cc: stable, nsekhar, rogerq, januszx.dziedzic

On Mon, Apr 10, 2017 at 05:15:13PM +0300, Felipe Balbi wrote:
> From: Janusz Dziedzic <januszx.dziedzic@intel.com>
> 
> commit de288e36fe33f7e06fa272bc8e2f85aa386d99aa upstream.
> 
> In the case of bounced ep0 requests, we must delay DMA operation until
> after ->complete() otherwise we might overwrite contents of req->buf.
> 
> This caused problems with RNDIS gadget.
> 
> Cc: <stable@vger.kernel.org>
> Fixes: d62145929992 ("usb: dwc3: gadget: always unmap EP0 requests")
> Signed-off-by: Janusz Dziedzic <januszx.dziedzic@intel.com>
> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
> ---
> 
> Note that this commit needs to be backported to all kernels where
> d62145929992 was backported.

This patch only applied to 4.10-stable.  It should go also to at least
4.4 and 4.9-stable, but it does not apply.  Can you provide a backport
for those kernels as well?

thanks,

greg k-h

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

* Re: [PATCH v2] usb: dwc3: gadget: delay unmap of bounced requests
  2017-04-10 14:48 ` Greg Kroah-Hartman
@ 2017-04-10 14:54   ` Felipe Balbi
  0 siblings, 0 replies; 3+ messages in thread
From: Felipe Balbi @ 2017-04-10 14:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: stable, nsekhar, rogerq, januszx.dziedzic

[-- Attachment #1: Type: text/plain, Size: 1023 bytes --]


Hi,

Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:
> On Mon, Apr 10, 2017 at 05:15:13PM +0300, Felipe Balbi wrote:
>> From: Janusz Dziedzic <januszx.dziedzic@intel.com>
>> 
>> commit de288e36fe33f7e06fa272bc8e2f85aa386d99aa upstream.
>> 
>> In the case of bounced ep0 requests, we must delay DMA operation until
>> after ->complete() otherwise we might overwrite contents of req->buf.
>> 
>> This caused problems with RNDIS gadget.
>> 
>> Cc: <stable@vger.kernel.org>
>> Fixes: d62145929992 ("usb: dwc3: gadget: always unmap EP0 requests")
>> Signed-off-by: Janusz Dziedzic <januszx.dziedzic@intel.com>
>> Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
>> ---
>> 
>> Note that this commit needs to be backported to all kernels where
>> d62145929992 was backported.
>
> This patch only applied to 4.10-stable.  It should go also to at least
> 4.4 and 4.9-stable, but it does not apply.  Can you provide a backport
> for those kernels as well?

coming shortly

-- 
balbi

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

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

end of thread, other threads:[~2017-04-10 14:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10 14:15 [PATCH v2] usb: dwc3: gadget: delay unmap of bounced requests Felipe Balbi
2017-04-10 14:48 ` Greg Kroah-Hartman
2017-04-10 14:54   ` Felipe Balbi

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.