Re: [PATCH v4 1/5] rust: vfio: add common VFIO device handling

From: Danilo Krummrich

Date: Wed Dec 02 2026 - 14:20:42 EST


On Wed Dec 2, 2026 at 4:58 PM CET, Gary Guo wrote:
>> +/// The context in which a VFIO device reference is valid.
>> +///
>> +/// Callback views can only be borrowed from the corresponding VFIO trampoline.
>> +/// They cannot be refcounted or shared across threads.
>> +pub trait DeviceContext: private::Sealed {}
>> +
>> +/// A callback context in which VFIO keeps the device open.
>> +///
>> +/// Registration data and open data are available throughout such a callback.
>> +pub trait IoContext: DeviceContext {}
>> +
>> +/// An ordinary device reference, without callback-specific operations.
>> +pub struct Normal;
>> +
>> +/// The device is undergoing its exclusive first-open callback.
>> +pub struct Open;
>> +
>> +/// The device is borrowed for a VFIO ioctl callback on the current thread.
>> +pub struct Ioctl;
>> +
>> +/// The device is borrowed for a VFIO read callback on the current thread.
>> +pub struct Read;
>> +
>> +/// The device is borrowed for a VFIO write callback on the current thread.
>> +pub struct Write;
>> +
>> +/// The device is borrowed for a VFIO mmap callback on the current thread.
>> +pub struct Mmap;
>> +
>> +/// The device is borrowed for a VFIO region-info callback on the current thread.
>> +pub struct GetRegionInfo;
>
> That's a lot of type states. It looks like all of these are only used to ensure
> only corresponding vfio_pci_core callbacks can be delegated to. Are these really
> needed for soundness? I can understand that the `Open` one might be needed, but
> the rest might be mergeable?

I think Read / Write and Ioctl / GetRegionInfo are technically mergeable without
introducing soundness holes.

However, core_write() makes no sense as delegation from read() and vice versa.
It also makes no sense to call core_ioctl() from get_region_info(), so I'd keep
them separate.