linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michał Pecio" <michal.pecio@gmail.com>
To: Niklas Neronin <niklas.neronin@linux.intel.com>,
	mathias.nyman@linux.intel.com
Cc: linux-usb@vger.kernel.org
Subject: Re: [PATCH 2/4] usb: xhci: handle Set TR Deq Slot Not Enabled Error
Date: Fri, 22 Aug 2025 09:22:57 +0200	[thread overview]
Message-ID: <20250822092257.493903f4.michal.pecio@gmail.com> (raw)
In-Reply-To: <20250821123521.53e7c37e.michal.pecio@gmail.com>

On Thu, 21 Aug 2025 12:35:21 +0200, Michał Pecio wrote:
> And suppose that somebody does indeed disable a slot without waiting
> for pending URBs to finish unlinking, what if he also frees those
> virtual endpoints that you would like to manipulate here? And maybe
> forgets to clear xhci->devs[x]->eps[y] to NULL?

I dug deeper and realized that this cannot happen, because virtual eps
belong to the same allocation as their parent virtual dev.

What is actually going to happen is that every xhci_disable_slot() is
followed by xhci_free_virt_dev(), so virtual endpoint lookup at the
beginning of xhci_handle_cmd_set_deq() will fail and the function will
bail out silently. This 'td_cleanup' code will get no chance to run.

The silent bailout is obviously wrong, but it can only be improved by
logging the error, and queuing Set TR Deq onto a disabled slot needs to
be prevented from happening in the first place.

As far as I see, it currently is supposed to be prevented by:
1. the core not freeing devices with pending URBs
2. the driver not giving back URBs before Set TR Dequeue completes

One interesting question is what happens if Set TR Dequeue is pending
but the endpoint starts and completes the CLEARING_CACHE TD normally,
I suspect that handle_tx_event() may give it back. Will look into it.

BTW, endpoints are not supposed to start like that after Stop Endpoint
retries have been implemented and I just sent a revert of a dodgy patch
which broke that, but well, in theory it *might* possibly still happen.

> What if a different device uses the same slot ID now? (That's possibly
> a serious problem which perhaps requires a serious solution, btw).

Actually, nothing interesting happens. SLOT_NOT_ENABLED means that the
slot was Disabled. By now, it can at most be Enabled, because any
completion of a later Enable Slot command couldn't have executed yet.
There are no new TDs on the slot and no damage by giving them back.

Also no point trying to give them back ;)

  reply	other threads:[~2025-08-22  7:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-18 12:57 [PATCH 0/4] usb: xhci: improve Set TR Deq completion error handling Niklas Neronin
2025-08-18 12:57 ` [PATCH 1/4] usb: xhci: handle Set TR Deq TRB Error Niklas Neronin
2025-08-21  9:32   ` Michał Pecio
2025-08-22 11:00     ` Neronin, Niklas
2025-08-18 12:57 ` [PATCH 2/4] usb: xhci: handle Set TR Deq Slot Not Enabled Error Niklas Neronin
2025-08-21 10:35   ` Michał Pecio
2025-08-22  7:22     ` Michał Pecio [this message]
2025-08-18 12:57 ` [PATCH 3/4] usb: xhci: handle Set TR Deq Context State Error due to Slot state Niklas Neronin
2025-08-22  7:49   ` Michał Pecio
2025-08-18 12:57 ` [PATCH 4/4] usb: xhci: handle Set TR Deq Context State Error due to Endpoint state Niklas Neronin
2025-08-22  8:15   ` Michał Pecio
2025-08-25  7:15     ` Michał Pecio
2025-08-27 11:53       ` Neronin, Niklas
2025-08-29  8:06         ` Michał Pecio
2025-08-29  8:14           ` Michał Pecio
2025-09-01  6:18           ` Michał Pecio

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=20250822092257.493903f4.michal.pecio@gmail.com \
    --to=michal.pecio@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    --cc=niklas.neronin@linux.intel.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;
as well as URLs for NNTP newsgroup(s).