Linux USB
 help / color / mirror / Atom feed
From: Luca Cecchi <luca.cecchi.info@gmail.com>
To: linux-usb@vger.kernel.org
Cc: linux-scsi@vger.kernel.org, oneukum@suse.com,
	stern@rowland.harvard.edu,
	Luca Cecchi <luca.cecchi.info@gmail.com>
Subject: [PATCH v3 1/2] usb: uas: implement .change_queue_depth to allow per-device queue depth override
Date: Fri,  9 Oct 2026 10:12:24 +0200	[thread overview]
Message-ID: <20261009081225.304319-1-luca.cecchi.info@gmail.com> (raw)
In-Reply-To: <20261009080341.295646-1-luca.cecchi.info@gmail.com>

uas_host_template does not implement .change_queue_depth. Because of
that, the standard sysfs queue_depth attribute stays read-only for
every UAS device, not just mine: scsi_sysfs.c:sdev_store_queue_depth()
requires sht->change_queue_depth to be non-NULL before it allows a
write.

uas_probe() already defaults can_queue to qdepth - 2, with a comment
acknowledging that "some bridge firmwares" need extra margin. That
margin isn't enough for every bridge. Right now the only way to work
around a bridge that needs more headroom is the IGNORE_UAS quirk,
which disables UAS entirely and falls back to BOT/usb-storage - a
large performance cost for a queue-depth problem.

This patch wires up .change_queue_depth so affected users can lower
the depth for just their device (e.g. via a udev rule matching
idVendor/idProduct), without disabling UAS altogether. Default
behaviour (qdepth - 2) is unchanged unless userspace asks for less.

Tested against a Lexar ES3 external SSD enclosure (VID:PID 21c4:0003)
that locks up under sustained heavy concurrent random writes at the
default queue depth. Capping the depth to 24 via this interface
eliminated the lockup across 6 consecutive test runs, including a
continuous 1-hour soak test (1.36TB written, ~822MB/s, no
uas_eh_abort_handler events).

v2: guarded against devinfo->qdepth holding a negative error code
    left over from a failed uas_configure_endpoints() call in
    uas_post_reset()/uas_reset_resume() (found by Sashiko AI review)

v3: dropped that guard per Oliver's direct reply - qdepth going
    negative is a general bug independent of this patch, which he is
    fixing separately at the source. This patch just happened to hit
    the symptom; it carries no workaround for it anymore.

    Trimmed the comment above uas_change_queue_depth() per Alan
    Stern's feedback - it described the pre-patch state rather than
    the code itself, which won't be true after this is merged.

    Also switched devinfo's lookup to sdev->hostdata (same pattern
    already used by uas_sdev_configure() and the other scsi_device-
    level callbacks in this file) instead of casting
    sdev->host->hostdata, which was pushing the line past 80 columns.

    Re-validated on bare metal with the same Lexar ES3 unit: two
    6-minute runs of the original load test (24 sync writers,
    randwrite, 64KiB, direct=1) at 840-843MB/s with zero
    uas_eh_abort_handler/uas_eh_host_reset_handler events, plus a
    mixed 70/30 read/write run (614MB/s read + 263MB/s write, zero
    events) and a run concurrent with a second USB flash drive on the
    same controller (no effect on throughput or stability).

Signed-off-by: Luca Cecchi <luca.cecchi.info@gmail.com>
---
 drivers/usb/storage/uas.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/drivers/usb/storage/uas.c b/drivers/usb/storage/uas.c
index 2651629..1b65e03 100644
--- a/drivers/usb/storage/uas.c
+++ b/drivers/usb/storage/uas.c
@@ -910,6 +910,20 @@ static int uas_sdev_configure(struct scsi_device *sdev,
 	return 0;
 }
 
+/*
+ * Implementing .change_queue_depth allows users to lower the per-device
+ * queue depth via sysfs.
+ */
+static int uas_change_queue_depth(struct scsi_device *sdev, int depth)
+{
+	struct uas_dev_info *devinfo = sdev->hostdata;
+	int max_depth = devinfo->qdepth - 2;
+
+	if (depth > max_depth)
+		depth = max_depth;
+	return scsi_change_queue_depth(sdev, depth);
+}
+
 static const struct scsi_host_template uas_host_template = {
 	.module = THIS_MODULE,
 	.name = "uas",
@@ -917,6 +931,7 @@ static const struct scsi_host_template uas_host_template = {
 	.target_alloc = uas_target_alloc,
 	.sdev_init = uas_sdev_init,
 	.sdev_configure = uas_sdev_configure,
+	.change_queue_depth = uas_change_queue_depth,
 	.eh_abort_handler = uas_eh_abort_handler,
 	.eh_host_reset_handler = uas_eh_host_reset_handler,
 	.this_id = -1,
-- 
2.55.0


  reply	other threads:[~2026-10-09  8:12 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04 11:41 [RFC] usb: uas: implement .change_queue_depth to allow per-device queue depth override Luca Cecchi
2026-10-08 11:00 ` Oliver Neukum
2026-10-08 11:26   ` [PATCH] " Luca Cecchi
2026-10-08 11:36     ` sashiko-bot
2026-10-08 12:26     ` [PATCH v2 1/2] " Luca Cecchi
2026-10-08 12:26       ` [PATCH v2 2/2] usb: uas: add US_FL_QDEPTH_075 quirk to cap queue depth at probe time Luca Cecchi
2026-10-08 12:33         ` sashiko-bot
2026-10-08 12:32       ` [PATCH v2 1/2] usb: uas: implement .change_queue_depth to allow per-device queue depth override sashiko-bot
2026-10-08 13:32       ` Oliver Neukum
2026-10-08 14:21       ` Alan Stern
2026-10-08 20:19         ` Luca Cecchi
2026-10-09  8:03           ` Luca Cecchi
2026-10-09  8:12             ` Luca Cecchi [this message]
2026-10-09  8:12               ` [PATCH v3 2/2] usb: uas: add US_FL_QDEPTH_075 quirk to cap queue depth at probe time Luca Cecchi
2026-10-09  8:20                 ` sashiko-bot
2026-10-09  8:29               ` [PATCH v3 1/2] usb: uas: implement .change_queue_depth to allow per-device queue depth override 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=20261009081225.304319-1-luca.cecchi.info@gmail.com \
    --to=luca.cecchi.info@gmail.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=oneukum@suse.com \
    --cc=stern@rowland.harvard.edu \
    /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