From: sashiko-bot@kernel.org
To: "Vadim Yuzifovich" <vadim@yuzi.co>
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH v2 3/3] usb: dwc2: gadget: make descriptors visible before the endpoint is enabled
Date: Mon, 16 Nov 2026 07:27:18 +0000 [thread overview]
Message-ID: <sashiko-outbox-216426@kernel.org> (raw)
In-Reply-To: <20261116070433.2813951-4-vadim@yuzi.co>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] usb: dwc2: descriptor 0 overwrite on full isoc chain in
dwc2_gadget_start_isoc_ddma()
--
commit 4a1867b305051b6b240040e6915ed6b0bbeb8d25
Author: Vadim Yuzifovich <vadim@yuzi.co>
usb: dwc2: gadget: make descriptors visible before the endpoint is enabled
This commit adds a helper that reads back the last written DMA descriptor
between two full memory barriers before enabling an endpoint in descriptor
DMA mode, ensuring that descriptor stores have landed in DRAM before the
controller fetches the chain.
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index a7eaf75ff7982..cd177383669f1 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
[ ... ]
> @@ -1079,12 +1102,23 @@ static void dwc2_gadget_start_isoc_ddma(struct dwc2_hsotg_ep *hs_ep)
> depctl = hs_ep->dir_in ? DIEPCTL(index) : DOEPCTL(index);
> dma_reg = hs_ep->dir_in ? DIEPDMA(index) : DOEPDMA(index);
>
> + /*
> + * The rest of the chain has to be visible before descriptor 0 is
> + * host ready. The queue is not empty, so at least one descriptor was
> + * filled: next_desc 0 means that the chain is full and the index
> + * wrapped.
> + */
> + i = hs_ep->next_desc ? hs_ep->next_desc - 1 :
> + MAX_DMA_DESC_NUM_HS_ISOC - 1;
> + dwc2_gadget_desc_visible(&hs_ep->desc_list[i]);
[Severity: High]
Does hs_ep->next_desc stop at 0 when more than MAX_DMA_DESC_NUM_HS_ISOC
requests are queued in hs_ep->queue?
When filling descriptor 0, dwc2_gadget_start_isoc_ddma() passes
hold = !hs_ep->next_desc so desc_list[0] remains in DEV_DMA_BUFF_STS_HBUSY
status while descriptors 1..255 are marked DEV_DMA_BUFF_STS_HREADY. After
the 256th request fills desc_list[255], hs_ep->next_desc wraps to 0. If a
257th request is in hs_ep->queue, dwc2_gadget_fill_isoc_desc() checks
whether desc_list[0] is DEV_DMA_BUFF_STS_HREADY:
drivers/usb/dwc2/gadget.c:dwc2_gadget_fill_isoc_desc() {
...
/* Check if descriptor chain full */
if ((desc->status >> DEV_DMA_BUFF_STS_SHIFT) ==
DEV_DMA_BUFF_STS_HREADY) {
dev_dbg(hsotg->dev, "%s: desc chain full\n", __func__);
return 1;
}
...
}
Because desc_list[0] was held in DEV_DMA_BUFF_STS_HBUSY, that check passes:
the 257th request overwrites desc_list[0], sets DEV_DMA_L on it, and
advances hs_ep->next_desc to 1 before the 258th iteration sees
DEV_DMA_BUFF_STS_HREADY on desc_list[1] and stops. This corrupts
descriptor 0 with the 257th request's buffer while leaving the 1st request
at the head of hs_ep->queue, and causes i above to evaluate to 0 instead
of MAX_DMA_DESC_NUM_HS_ISOC - 1, skipping the readback of the last
descriptor.
Breaking out of the loop when hs_ep->next_desc wraps back to 0 avoids
calling dwc2_gadget_fill_isoc_desc() a 257th time.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261116070433.2813951-1-vadim@yuzi.co?part=3
prev parent reply other threads:[~2026-11-16 7:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 7:04 [PATCH v2 0/3] usb: dwc2: gadget: descriptor DMA fixes for BNA, found on Sophgo SG2002 Vadim Yuzifovich
2026-11-16 7:04 ` [PATCH v2 1/3] usb: dwc2: gadget: restart descriptor DMA isochronous OUT endpoints after BNA Vadim Yuzifovich
2026-11-16 7:29 ` sashiko-bot
2026-11-16 7:04 ` [PATCH v2 2/3] usb: dwc2: gadget: restart descriptor DMA bulk and interrupt " Vadim Yuzifovich
2026-11-16 7:13 ` sashiko-bot
2026-11-16 7:04 ` [PATCH v2 3/3] usb: dwc2: gadget: make descriptors visible before the endpoint is enabled Vadim Yuzifovich
2026-11-16 7:27 ` sashiko-bot [this message]
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=sashiko-outbox-216426@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=vadim@yuzi.co \
/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