rte_vfio.h(3)

🌸 rte_vfio.h β€” the VFIO bestie handbook 🌸

okay so bestie, welcome to rte_vfio.h, straight outta section 3 of the Library Functions Manual πŸ“š. This is DPDK's VFIO utility header and it's giving big kernel-adjacent energy. Buckle up, we're going through every single function, no skipping, no skimming, periodt. πŸ’…βœ¨


πŸ“› NAME

rte_vfio.h


✨ SYNOPSIS ✨

First, the little pre-party β€” the stuff you gotta pull in:

#include <stdbool.h>
#include <stdint.h>
#include <rte_compat.h>

πŸ¦‹ Functions

Here's the whole squad of function signatures, exactly as they come:

int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr, int *vfio_dev_fd, struct vfio_device_info *device_info)
int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr, int fd)
int rte_vfio_enable(const char *modname)
int rte_vfio_is_enabled(const char *modname)
int rte_vfio_noiommu_is_enabled(void)
int rte_vfio_clear_group(int vfio_group_fd)
int rte_vfio_get_group_num(const char *sysfs_base, const char *dev_addr, int *iommu_group_num)
__rte_experimental int rte_vfio_get_device_info(const char *sysfs_base, const char *dev_addr, int *vfio_dev_fd, struct vfio_device_info *device_info)
int rte_vfio_get_container_fd(void)
int rte_vfio_get_group_fd(int iommu_group_num)
int rte_vfio_container_create(void)
int rte_vfio_container_destroy(int container_fd)
int rte_vfio_container_group_bind(int container_fd, int iommu_group_num)
int rte_vfio_container_group_unbind(int container_fd, int iommu_group_num)
int rte_vfio_container_dma_map(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len)
int rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr, uint64_t iova, uint64_t len)

πŸ’– Detailed Description πŸ’–

RTE VFIO. This library hands you a whole lil bundle of VFIO-related utility functions so you can do the device-passthrough thing. 🫢

Definition in file rte_vfio.h.


🧚 Function Documentation 🧚

rte_vfio_setup_device

int rte_vfio_setup_device(const char *sysfs_base, const char *dev_addr,
    int *vfio_dev_fd, struct vfio_device_info *device_info)

Sets up vfio_cfg for the device that you identify by its address. It goes and discovers the I/O MMU groups that are already configured, or it sets up a brand new one for this device. And if a new group gets assigned? Then the DMA mapping happens too. Iconic multitasking. ✨

heads up bestie: this function is only relevant to linux and will return an error on BSD. no BSD crumbs for this one. 😭

Parameters

  • sysfs_base β€” sysfs path prefix.
  • dev_addr β€” device location.
  • vfio_dev_fd β€” VFIO fd.
  • device_info β€” Device information.

Returns

  • 0 on success.
  • <0 on failure.
  • >1 if the device cannot be managed this way.

rte_vfio_release_device

int rte_vfio_release_device(const char *sysfs_base, const char *dev_addr,
    int fd)

Releases a device that's mapped to a VFIO-managed I/O MMU group. Say bye πŸ‘‹

same deal: only relevant to linux, returns an error on BSD.

Parameters

  • sysfs_base β€” sysfs path prefix.
  • dev_addr β€” device location.
  • fd β€” VFIO fd.

Returns

  • 0 on success.
  • <0 on failure.

rte_vfio_enable

int rte_vfio_enable(const char *modname)

Turns on a VFIO-related kmod. basically the "go go go" button for your kernel module. πŸ”₯

you guessed it: only relevant to linux, returns an error on BSD.

Parameters

  • modname β€” kernel module name.

Returns

  • 0 on success.
  • <0 on failure.

rte_vfio_is_enabled

int rte_vfio_is_enabled(const char *modname)

Checks whether a VFIO-related kmod is enabled. vibe check on your kernel module, fr fr. πŸ•΅οΈβ€β™€οΈ

note the capital L: only relevant to Linux.

Parameters

  • modname β€” kernel module name.

Returns

  • 1 if true.
  • 0 otherwise.

rte_vfio_noiommu_is_enabled

int rte_vfio_noiommu_is_enabled(void)

Tells you whether VFIO <cyanish>NOIOMMU mode is enabled. (are we doing the no-iommu thing or not, bestie?)

Linux only for this one.

Returns

  • 1 if true.
  • 0 if false.
  • <0 for errors.

rte_vfio_clear_group

int rte_vfio_clear_group(int vfio_group_fd)

Removes a group fd from the internal VFIO group fd array/ β€” yep, that trailing slash is how it's written and I am not touching it. πŸ’…

linux only, and it will return an error on BSD.

Parameters

  • vfio_group_fd β€” VFIO Group FD.

Returns

  • 0 on success.
  • <0 on failure.

rte_vfio_get_group_num

int rte_vfio_get_group_num(const char *sysfs_base, const char *dev_addr,
    int *iommu_group_num)

Parses the IOMMU group number for a device. πŸ”’

linux only, error on BSD.

Parameters

  • sysfs_base β€” sysfs path prefix.
  • dev_addr β€” device location.
  • iommu_group_num β€” iommu group number.

Returns

  • >0 on success.
  • 0 for non-existent group or VFIO.
  • <0 for errors.

rte_vfio_get_device_info

__rte_experimental int rte_vfio_get_device_info(const char *sysfs_base,
    const char *dev_addr, int *vfio_dev_fd,
    struct vfio_device_info *device_info)

Gets device information. πŸ‘€ (yes, it's marked __rte_experimental β€” experimental things can wiggle around, so don't get too attached.)

Linux only, and returns an error on BSD.

Parameters

  • sysfs_base β€” sysfs path prefix.
  • dev_addr β€” device location.
  • vfio_dev_fd β€” VFIO fd.
  • device_info β€” Device information.

Returns

  • 0 on success.
  • <0 on failure.

rte_vfio_get_container_fd

int rte_vfio_get_container_fd(void)

Gets the default VFIO container fd. the OG container, if you will. 🧺

linux only, error on BSD.

Returns

  • 0 β€” default container fd.
  • < 0 if VFIO is not enabled or not supported.

rte_vfio_get_group_fd

int rte_vfio_get_group_fd(int iommu_group_num)

Opens a VFIO group fd, or grabs an already-existing one. πŸšͺ

linux only, error on BSD.

Parameters

  • iommu_group_num β€” iommu group number.

Returns

  • 0 β€” group fd.
  • < 0 for errors.

rte_vfio_container_create

int rte_vfio_container_create(void)

Creates a shiny new container for device binding. ✨🧺

Note (read this twice, bestie): - Any newly allocated DPDK memory will not be mapped into these containers by default, user needs to manage DMA mappings for any container created by this API. - When creating containers using this API, the container will only be available in the process that has created it. Sharing containers and devices between multiple processes is not supported. 😭 no group-chat sharing here.

Returns

  • the container fd if successful.
  • <0 if failed.

rte_vfio_container_destroy

int rte_vfio_container_destroy(int container_fd)

Destroys the container, and unbinds all vfio groups within it. bye forever 🫑

Parameters

  • container_fd β€” the container fd to destroy.

Returns

  • 0 if successful.
  • <0 if failed.

rte_vfio_container_group_bind

int rte_vfio_container_group_bind(int container_fd, int iommu_group_num)

Binds an IOMMU group to a container. it's giving arranged marriage but for fds. πŸ’

Parameters

  • container_fd β€” the container's fd.
  • iommu_group_num β€” the iommu group number to bind to container.

Returns

  • group fd if successful.
  • <0 if failed.

rte_vfio_container_group_unbind

int rte_vfio_container_group_unbind(int container_fd, int iommu_group_num)

Unbinds an IOMMU group from a container. πŸ’”

Parameters

  • container_fd β€” the container fd of container.
  • iommu_group_num β€” the iommu group number to delete from container.

Returns

  • 0 if successful.
  • <0 if failed.

rte_vfio_container_dma_map

int rte_vfio_container_dma_map(int container_fd, uint64_t vaddr,
    uint64_t iova, uint64_t len)

Performs DMA mapping for devices in a container. πŸ—ΊοΈ

Parameters

  • container_fd β€” the specified container fd. Use RTE_VFIO_DEFAULT_CONTAINER_FD to use the default container.
  • vaddr β€” Starting virtual address of memory to be mapped.
  • iova β€” Starting IOVA address of memory to be mapped.
  • len β€” Length of memory segment being mapped.

Returns

  • 0 if successful.
  • <0 if failed.

rte_vfio_container_dma_unmap

int rte_vfio_container_dma_unmap(int container_fd, uint64_t vaddr,
    uint64_t iova, uint64_t len)

Performs DMA unmapping for devices in a container. 🧹 (reverse of the map, duh)

Parameters

  • container_fd β€” the specified container fd. Use RTE_VFIO_DEFAULT_CONTAINER_FD to use the default container.
  • vaddr β€” Starting virtual address of memory to be unmapped.
  • iova β€” Starting IOVA address of memory to be unmapped.
  • len β€” Length of memory segment being unmapped.

Returns

  • 0 if successful.
  • <0 if failed.

πŸ‘‘ Author

Generated automatically by Doxygen for DPDK from the source code.


and that's the whole page bestie, you ate it πŸ’…βœ¨

this was DPDK, Version 25.11.3, from the rte_vfio.h(3) page πŸŽ€ β€” go forth and map your DMA, no cap 🫢🌸

πŸ“¦ where this page comes from