crosvm/devices
Daniel Verkamp 2f6d79efdf devices: usb: fix ownership of USB file descriptor
As part of moving from RawFd to RawDescriptor and related types
(https://crrev.com/c/2462330), the USB attach code was modified to
accept a MaybeOwnedDescriptor instead of a MaybeOwnedFd.  Since
MaybeOwnedDescriptor::Owned contains a SafeDescriptor instead of a File,
and the usb_util Device::new() constructor requires a File, a conversion
is required.  However, the patch mentioned above used as_raw_descriptor
and File::from_raw_descriptor to do this conversion, but this leaves
both the SafeDescriptor and the newly-created File assuming ownership of
the USB fd.  When the SafeDescriptor went out of scope, the fd would be
closed, causing the fd in the File to be invalid (meaning the USB device
does not function at all).

This would show up in the crosvm logs like this:

  [devices/src/usb/host_backend/utils.rs:61] fail to submit transfer IoctlFailed(2151175434, Error(25))
  [devices/src/usb/xhci/xhci_transfer.rs:399] backend is already disconnected

To fix this, use into_raw_descriptor rather than as_raw_descriptor to
transfer ownership out of the SafeDescriptor without closing the fd.

BUG=b:174289633
BUG=chromium:1151144
TEST=Attach USB serial device to Crostini and verify /dev/ttyUSB0 exists

Change-Id: Ia1c5f94f69ca31ab211ab9f63f23141b4e774ef4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2579884
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Michael Hoyle <mikehoyle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-12-09 22:03:38 +00:00
..
src devices: usb: fix ownership of USB file descriptor 2020-12-09 22:03:38 +00:00
.build_test_serial devices: Add simple test for proxy device 2020-11-17 21:05:51 +00:00
Cargo.toml rutabaga_gfx: an electrifying possibility 2020-12-08 20:17:05 +00:00