STRUCT VFIO_DEVICE_OPS(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 structure
  • release β€” Reclaim private fields in device structure
  • bind_iommufd β€” Called when binding the device to an iommufd
  • unbind_iommufd β€” Opposite of bind_iommufd
  • attach_ioas β€” Called when attaching device to an IOAS/HWPT managed by the bound iommufd. Undo in unbind_iommufd if detach_ioas is not called. πŸ‘€ yes the "undo" note is load-bearing, don't skip it
  • detach_ioas β€” Opposite of attach_ioas
  • pasid_attach_ioas β€” The pasid variation of attach_ioas
  • pasid_detach_ioas β€” Opposite of pasid_attach_ioas
  • open_device β€” Called when the first file descriptor is opened for this device
  • close_device β€” Opposite of open_device
  • read β€” Perform read(2) on device file descriptor
  • write β€” Perform write(2) on device file descriptor
  • ioctl β€” Perform ioctl(2) on device file descriptor, supporting VFIO_DEVICE_* operations documented below
  • mmap β€” Perform mmap(2) on a region of the device file descriptor
  • request β€” Request for the bus driver to release the device
  • match β€” 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. uuid is 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 the VFIO_DEVICE_FEATURE ioctl
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