From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Felipe Balbi <felipe.balbi@linux.intel.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v3 1/2] usb: dwc3: gadget: fix DMA mapping leak of requests without TRBs
Date: Sat, 5 Dec 2026 02:09:59 +0000 [thread overview]
Message-ID: <axNyT-XoDK0_D-Li@vbox> (raw)
In-Reply-To: <20261124111321.2731905-2-faisal.hassan@oss.qualcomm.com>
On Tue, Nov 24, 2026, Faisal Hassan wrote:
> dwc3_prepare_trbs() maps pending requests lazily. A request that needs
> more TRBs than are currently free is left on the pending list, mapped
> but with req->trb unset, and is mapped again on the next kick.
>
> dwc3_gadget_del_and_unmap_request() only unmaps requests that have
> req->trb set, so dequeuing such a request, or failing it on
> disconnect, leaks its mapping. With an IOMMU or swiotlb this leaks
> IOVA space or bounce buffers.
>
> Track the mapped state in req->mapped, skip the mapping if it is
> already done, and unmap unconditionally on giveback.
> usb_gadget_unmap_request_by_dev() does nothing for a request that is
> not mapped.
>
> Fixes: cdb55b39fab8 ("usb: dwc3: gadget: lazily map requests for DMA")
> Cc: stable@vger.kernel.org
> Signed-off-by: Faisal Hassan <faisal.hassan@oss.qualcomm.com>
> ---
> drivers/usb/dwc3/gadget.c | 18 +++++++++++-------
> 1 file changed, 11 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> index afcbde73fcb7..e4436abd222d 100644
> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -203,9 +203,9 @@ static void dwc3_gadget_del_and_unmap_request(struct dwc3_ep *dep,
> if (req->request.status == -EINPROGRESS)
> req->request.status = status;
>
> - if (req->trb)
> - usb_gadget_unmap_request_by_dev(dwc->sysdev,
> - &req->request, req->direction);
> + usb_gadget_unmap_request_by_dev(dwc->sysdev, &req->request,
> + req->direction);
> + req->mapped = false;
>
> req->trb = NULL;
> trace_dwc3_gadget_giveback(req);
> @@ -1659,10 +1659,14 @@ static int dwc3_prepare_trbs(struct dwc3_ep *dep)
> list_for_each_entry_safe(req, n, &dep->pending_list, list) {
> struct dwc3 *dwc = dep->dwc;
>
> - ret = usb_gadget_map_request_by_dev(dwc->sysdev, &req->request,
> - dep->direction);
> - if (ret)
> - return ret;
> + if (!req->mapped) {
> + ret = usb_gadget_map_request_by_dev(dwc->sysdev,
> + &req->request, dep->direction);
> + if (ret)
> + return ret;
> +
> + req->mapped = true;
> + }
>
> req->start_sg = req->request.sg;
> req->num_pending_sgs = req->request.num_mapped_sgs;
> --
> 2.34.1
>
>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Thanks,
Thinh
next prev parent reply other threads:[~2026-12-05 2:10 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-04 3:14 [PATCH] usb: dwc3: gadget: linearize SG requests that exceed the TRB cache Faisal Hassan
2026-10-06 17:22 ` [PATCH v2] " Faisal Hassan
2026-10-06 17:41 ` sashiko-bot
2026-10-28 19:10 ` Faisal Hassan
2026-10-29 6:20 ` Greg Kroah-Hartman
2026-10-29 9:55 ` Greg Kroah-Hartman
2026-10-30 10:30 ` Faisal Hassan
2026-11-24 11:13 ` [PATCH v3 0/2] usb: dwc3: gadget: fix request unmap and " Faisal Hassan
2026-11-24 11:13 ` [PATCH v3 1/2] usb: dwc3: gadget: fix DMA mapping leak of requests without TRBs Faisal Hassan
2026-12-05 2:09 ` Thinh Nguyen [this message]
2026-11-24 11:13 ` [PATCH v3 2/2] usb: dwc3: gadget: linearize SG requests that exceed the TRB cache Faisal Hassan
2026-12-05 2:37 ` Thinh Nguyen
2026-11-24 11:26 ` [PATCH v3 0/2] usb: dwc3: gadget: fix request unmap and " sashiko-bot
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=axNyT-XoDK0_D-Li@vbox \
--to=thinh.nguyen@synopsys.com \
--cc=faisal.hassan@oss.qualcomm.com \
--cc=felipe.balbi@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.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 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.