STRUCT VFIO_DEVICE_OPS(9)
π
struct vfio_device_ops(9) π
okay so bestie, we're in the Kernel API Manual, section 9, and today's main character is struct vfio_device_ops β the VFIO bus driver device callbacks. this is the vibe check page for anyone writing a VFIO bus driver, so grab a snack π and let's get into it β¨
πΈ NAME πΈ
struct vfio_device_ops β VFIO bus driver device callbacks π¦
β¨ SYNOPSIS β¨
struct vfio_device_ops {
char *name;
int (*init)(struct vfio_device *vdev);
void (*release)(struct vfio_device *vdev);
int (*bind_iommufd)(struct vfio_device *vdev, struct iommufd_ctx *ictx, u32 *out_device_id);
void (*unbind_iommufd)(struct vfio_device *vdev);
int (*attach_ioas)(struct vfio_device *vdev, u32 *pt_id);
void (*detach_ioas)(struct vfio_device *vdev);
int (*pasid_attach_ioas)(struct vfio_device *vdev, u32 pasid, u32 *pt_id);
void (*pasid_detach_ioas)(struct vfio_device *vdev, u32 pasid);
int (*open_device)(struct vfio_device *vdev);
void (*close_device)(struct vfio_device *vdev);
ssize_t (*read)(struct vfio_device *vdev, char __user *buf, size_t count, loff_t *ppos);
ssize_t (*write)(struct vfio_device *vdev, const char __user *buf, size_t count, loff_t *size);
long (*ioctl)(struct vfio_device *vdev, unsigned int cmd, unsigned long arg);
int (*get_region_info_caps)(struct vfio_device *vdev, struct vfio_region_info *info, struct vfio_info_cap *caps);
int (*mmap)(struct vfio_device *vdev, struct vm_area_struct *vma);
void (*request)(struct vfio_device *vdev, unsigned int count);
int (*match)(struct vfio_device *vdev, char *buf);
int (*match_token_uuid)(struct vfio_device *vdev, const uuid_t *uuid);
void (*dma_unmap)(struct vfio_device *vdev, u64 iova, u64 length);
int (*device_feature)(struct vfio_device *device, u32 flags, void __user *arg, size_t argsz);
};
π«Ά Members π«Ά
nameβ Name of the device driver. that's it, that's the whole job πinitβ initialize private fields in device structurereleaseβ Reclaim private fields in device structurebind_iommufdβ Called when binding the device to an iommufdunbind_iommufdβ Opposite ofbind_iommufdattach_ioasβ Called when attaching device to an IOAS/HWPT managed by the bound iommufd. Undo inunbind_iommufdifdetach_ioasis not called. π yes the "undo" note is load-bearing, don't skip itdetach_ioasβ Opposite ofattach_ioaspasid_attach_ioasβ The pasid variation ofattach_ioaspasid_detach_ioasβ Opposite ofpasid_attach_ioasopen_deviceβ Called when the first file descriptor is opened for this deviceclose_deviceβ Opposite ofopen_devicereadβ Performread(2)on device file descriptorwriteβ Performwrite(2)on device file descriptorioctlβ Performioctl(2)on device file descriptor, supportingVFIO_DEVICE_*operations documented belowmmapβ Performmmap(2)on a region of the device file descriptorrequestβ Request for the bus driver to release the devicematchβ Optional device name match callback (return: 0 for no-match, >0 for match, -errno for abort (ex. match with insufficient or incorrect additional args) π₯ like, read the return contract twice, it's giving "0 means nope"match_token_uuidβ Optional device token match/validation. Return 0 if the uuid is valid for the device, -errno otherwise.uuidis NULL if none was provided.dma_unmapβ Called when userspace unmaps IOVA from the container this device is attached to.device_featureβ Optional, fill in theVFIO_DEVICE_FEATUREioctl
and yeah β get_region_info_caps is sitting right there in the struct up top, but this page doesn't give it its own little blurb, so I'm not out here making one up π no cap.
π SEE ALSO π
Kernel file ./include/linux/vfio.h struct vfio_migration_ops(9), struct vfio_log_ops(9), vfio_check_feature(9), vfio_check_precopy_ioctl(9) π¦
okay that's the whole page, bestie, you ate that π
β¨ this cutie dropped from ./include/linux, version date October 2026 β go forth and write iconic callbacks, periodt ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms