From: Shuai Liu <847807867@qq.com>
To: Mike Lothian <mike@fireburn.co.uk>
Cc: Oliver Neukum <oneukum@suse.com>,
rust-for-linux@vger.kernel.org, linux-usb@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 0/5] rust: usb: host-side abstractions for a bulk-endpoint driver
Date: Fri, 30 Oct 2026 10:34:00 +0800 [thread overview]
Message-ID: <tencent_A0D3062EB058E244877B87B4324B8DFC4406@qq.com> (raw)
In-Reply-To: <20260826163101.4168-1-mike@fireburn.co.uk>
Hi Mike,
I read through the v3 diff (patches 1 and 2 in detail). I could not
apply the series locally because the 8-month-old base no longer matches
current usb.rs, so this review is from the diff, not a build. Two
findings, both around alternate settings:
1. set_alternate_setting() invalidates Endpoint<K> without the type
system noticing
Endpoint<K>'s invariants say the address names an endpoint of the
interface's *active* alternate setting, with the transfer type and
direction of K. That proof is only valid for one altsetting: after
interface.set_alternate_setting(1)?
every previously obtained &Endpoint<BulkOut> is still usable, but the
same address in the new setting may name an interrupt endpoint or a
different direction. A transfer method will then happily build a pipe
for an endpoint that no longer matches the tag. C drivers get this
right by re-fetching endpoints after usb_set_interface(); the Rust
abstraction currently lets a driver keep stale proofs across the
switch.
Something that binds the proof to the setting would close it, e.g. an
Endpoint borrowed from an Altsetting token (making it unusable after a
switch), or a generation stamp checked at transfer time. At minimum the
doc comment on set_alternate_setting() and on Endpoint should state
that all previously obtained Endpoint values must be discarded across a
call.
2. set_alternate_setting() with transfers in flight is undefined
usb_set_interface() tears down and reallocates the interface's
endpoints, which unlinks and kills any URBs submitted on them. A
persistent BulkInQueue/BulkOutQueue built in patch 2 therefore loses
its URBs out from under the Rust slot state machine: the queue thinks
a slot is in flight while the C core has killed the URB, and nothing
ever wakes the waiter. The documentation of set_alternate_setting()
does not warn about this.
Either the method should require an empty window (e.g. take &mut self,
or refuse when the window has registered URBs), or it should document
that the driver must drain and drop its queues before switching, with
the queue Drop doing the cancellation.
Two smaller notes:
- queue_reset_device(): I checked hub.c; the "may be called from any
context, deferred to the core workqueue" documentation matches
usb_queue_reset_device().
- EndpointKind being sealed with BulkIn/BulkOut/InterruptIn is a nice
fit; control endpoint 0 going through Pipe instead of Endpoint avoids
pretending it takes part in the altsetting lifecycle.
Best regards,
Shuai Liu
next prev parent reply other threads:[~2026-10-30 2:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20260826163101.4168-1-mike@fireburn.co.uk>
2026-08-26 16:30 ` [PATCH v3 1/5] rust: usb: add revocable typed interface I/O Mike Lothian
2026-08-26 18:59 ` Danilo Krummrich
2026-08-31 17:04 ` Mike Lothian
2026-08-31 17:10 ` Gary Guo
2026-08-26 16:30 ` [PATCH v3 2/5] rust: usb: add reusable URBs and persistent bulk queues Mike Lothian
2026-08-26 16:30 ` [PATCH v3 3/5] rust: usb: expose device descriptor fields and queue readiness Mike Lothian
2026-08-26 16:30 ` [PATCH v3 4/5] rust: usb: add a vendor-and-interface-info device id constructor Mike Lothian
2026-08-26 16:30 ` [PATCH v3 5/5] rust: usb: let a driver keep its interface usable while unbinding Mike Lothian
2026-10-30 2:34 ` Shuai Liu [this message]
2026-10-30 7:57 ` [PATCH v3 0/5] rust: usb: host-side abstractions for a bulk-endpoint driver Mike Lothian
2026-10-30 9:48 ` Shuai Liu
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=tencent_A0D3062EB058E244877B87B4324B8DFC4406@qq.com \
--to=847807867@qq.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mike@fireburn.co.uk \
--cc=oneukum@suse.com \
--cc=rust-for-linux@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®