Rust for Linux List
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Oliver Neukum" <oneukum@suse.com>
Cc: "Mike Lothian" <mike@fireburn.co.uk>,
	rust-for-linux@vger.kernel.org, linux-usb@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Miguel Ojeda" <ojeda@kernel.org>,
	"Boqun Feng" <boqun@kernel.org>, "Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <lossin@kernel.org>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Alexandre Courbot" <acourbot@nvidia.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2 10/11] rust: usb: keep usb::Device private and gate transfers on Interface<Bound>
Date: Mon, 06 Jul 2026 12:38:40 +0200	[thread overview]
Message-ID: <DJRF98V7SMXT.14BS8WGBEESZ8@kernel.org> (raw)
In-Reply-To: <fddbeaed-ff21-4962-b09f-d975c96cd926@suse.com>

On Mon Jul 6, 2026 at 11:45 AM CEST, Oliver Neukum wrote:
>
>
> On 03.07.26 05:00, Mike Lothian wrote:
>> Address the v1 RFC review (Danilo Krummrich):
>> 
>>   - Do not make `usb::Device` public. Writing a `usb::Interface` driver should
>>     not require naming the underlying `usb::Device` (cf. commit 22d693e45d4a
>>     ("rust: usb: keep usb::Device private for now")), so the struct is
>>     private again and the device-wide transfer operations are exposed on
>>     the interface.

I didn't say we never need interface drivers to deal with the usb device, but
there doesn't seem to be any value in taking this indirection for I/O
primitives.

I.e. there's no value for drivers to write

	let dev = intf.device();
	dev.bulk_recv();

over

	intf.bulk_recv();

With the latter we can enforce that any I/O can only be made for an interface
that is bound to a driver (usb::Interface<Bound>).

AFAIK, it is not necessarily valid to assume that if an interface is bound to an
interface driver, the parent USB device is also bound to a USB device driver
(which is what usb::Device<Bound> represents).

If that is correct, we can't just derive a usb::Device<Bound> from a
usb::Interface<Bound>, and hence can't gate I/O behind the USB device's device
context type state.

IOW, we'd need another layer of indirection if we want to properly gate USB I/O
with the device driver lifecycle.

By providing helpers that operate on the interface directly, this goes away
regardless.

> Hi,
>
> I would say that this is just conceptually wrong.
>
> 1. drivers talk to the common control endpoint of the _device_
> not their interface
> 2. drivers ought to be able to set a configuration (That's a device property)
> 3. Drivers need to be able to claim secondary interfaces (we have an API for that)
> 4. Devices and links (and functions) have states, not interfaces.
>
> These operations operate on the device level. Hiding that fact behind an
> interface (which may not even be accepted at that point) is just a layering
> violation. Even calling a device reset through an interface is strictly speaking
> wrong.
> We even have a driver that can ride piggyback on another driver's interface
> and use only control transfers to endpoint 0.
>
> This patch is fundamentally flawed because it operates on assumptions
> that are just not true. USB does device level operations. Just drop it.

This seems overstated, the only thing the patch does is providing helpers to
avoid the above indirection.

However, I agree that reset_configuration() and set_interface() seem misplaced.

That said, I'm happy with any solution as long as it considers the device driver
lifecycle and gates I/O operations (and other operations that belong in the
bound scope) correspondingly.

  reply	other threads:[~2026-07-06 10:38 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-17 14:59 [RFC PATCH 0/9] rust: usb: synchronous bulk/control transfers + helpers Mike Lothian
2026-06-17 14:59 ` [RFC PATCH 1/9] rust: usb: add synchronous bulk transfer support Mike Lothian
2026-06-17 16:07   ` Danilo Krummrich
2026-06-17 14:59 ` [RFC PATCH 2/9] rust: usb: add synchronous control " Mike Lothian
2026-06-22  9:54   ` Oliver Neukum
2026-06-17 14:59 ` [RFC PATCH 3/9] rust: usb: add usb::Device::set_interface() Mike Lothian
2026-06-17 14:59 ` [RFC PATCH 4/9] rust: usb: add usb::Interface::number() Mike Lothian
2026-06-17 14:59 ` [RFC PATCH 5/9] rust: usb: add usb::Device::clear_halt() Mike Lothian
2026-06-17 14:59 ` [RFC PATCH 6/9] rust: usb: add usb::Device::interrupt_recv() Mike Lothian
2026-06-17 14:59 ` [RFC PATCH 7/9] rust: usb: add usb::Device::reset_configuration() Mike Lothian
2026-06-17 14:59 ` [RFC PATCH 8/9] rust: usb: add an asynchronous persistently-queued bulk IN reader Mike Lothian
2026-06-17 14:59 ` [RFC PATCH 9/9] rust: usb: add an asynchronous pipelined bulk OUT queue Mike Lothian
2026-07-03  3:00 ` [RFC PATCH v2 00/11] rust: usb: synchronous + asynchronous bulk/control transfers + helpers Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 01/11] rust: usb: add synchronous bulk transfer support Mike Lothian
2026-07-06  9:17     ` Oliver Neukum
2026-07-03  3:00   ` [RFC PATCH v2 02/11] rust: usb: add synchronous control " Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 03/11] rust: usb: add usb::Device::set_interface() Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 04/11] rust: usb: add usb::Interface::number() Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 05/11] rust: usb: add usb::Device::clear_halt() Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 06/11] rust: usb: add usb::Device::interrupt_recv() Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 07/11] rust: usb: add usb::Device::reset_configuration() Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 08/11] rust: usb: add an asynchronous persistently-queued bulk IN reader Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 09/11] rust: usb: add an asynchronous pipelined bulk OUT queue Mike Lothian
2026-07-03  3:00   ` [RFC PATCH v2 10/11] rust: usb: keep usb::Device private and gate transfers on Interface<Bound> Mike Lothian
2026-07-06  9:45     ` Oliver Neukum
2026-07-06 10:38       ` Danilo Krummrich [this message]
2026-07-06 13:46         ` Alan Stern
2026-07-06 10:40     ` Danilo Krummrich
2026-07-03  3:00   ` [RFC PATCH v2 11/11] rust: usb: let drivers choose the transfer allocation flags Mike Lothian
2026-07-06  9:47     ` Oliver Neukum

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=DJRF98V7SMXT.14BS8WGBEESZ8@kernel.org \
    --to=dakr@kernel.org \
    --cc=a.hindborg@kernel.org \
    --cc=acourbot@nvidia.com \
    --cc=aliceryhl@google.com \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun@kernel.org \
    --cc=daniel.almeida@collabora.com \
    --cc=gary@garyguo.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=lossin@kernel.org \
    --cc=mike@fireburn.co.uk \
    --cc=ojeda@kernel.org \
    --cc=oneukum@suse.com \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.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