---
name: "rte_vfio_container_create"
section: "3"
platform: "linux"
package: "dpdk-doc"
version: "24.11.4-0+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rte_vfio.h"
---

# rte\_vfio\_container\_create(3)

Part of [rte\_vfio.h(3)](/rte_vfio.h/3.md).

## NAME

rte\_vfio.h

## SYNOPSIS

`#include <stdbool.h>`\
 `#include <stdint.h>`\
 `#include <rte_compat.h>`\
 `#include <linux/vfio.h>`\

### Functions

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 provides various VFIO related utility functions.

Definition in file **rte\_vfio.h**.

## Function Documentation

### int rte\_vfio\_setup\_device (const char \* sysfs\_base, const char \* dev\_addr, int \* vfio\_dev\_fd, struct vfio\_device\_info \* device\_info)

Setup vfio\_cfg for the device identified by its address. It discovers the configured I/O MMU groups or sets a new one for the device. If a new groups is assigned, the DMA mapping is performed.

This function is only relevant to linux and will return 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. \>1 if the device cannot be managed this way.

### int rte\_vfio\_release\_device (const char \* sysfs\_base, const char \* dev\_addr, int fd)

Release a device mapped to a VFIO-managed I/O MMU group.

This function is only relevant to linux and will return an error on BSD.

**Parameters**

*sysfs\_base* sysfs path prefix.\
 *dev\_addr* device location.\
 *fd* VFIO fd.

**Returns**

0 on success. \<0 on failure.

### int rte\_vfio\_enable (const char \* modname)

Enable a VFIO-related kmod.

This function is only relevant to linux and will return an error on BSD.

**Parameters**

*modname* kernel module name.

**Returns**

0 on success. \<0 on failure.

### int rte\_vfio\_is\_enabled (const char \* modname)

Check whether a VFIO-related kmod is enabled.

This function is only relevant to Linux.

**Parameters**

*modname* kernel module name.

**Returns**

1 if true. 0 otherwise.

### int rte\_vfio\_noiommu\_is\_enabled (void)

Whether VFIO NOIOMMU mode is enabled.

This function is only relevant to Linux.

**Returns**

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

### int rte\_vfio\_clear\_group (int vfio\_group\_fd)

Remove group fd from internal VFIO group fd array/

This function is only relevant to linux and will return an error on BSD.

**Parameters**

*vfio\_group\_fd* VFIO Group FD.

**Returns**

0 on success. \<0 on failure.

### int rte\_vfio\_get\_group\_num (const char \* sysfs\_base, const char \* dev\_addr, int \* iommu\_group\_num)

Parse IOMMU group number for a device

This function is only relevant to linux and will return an 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\_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)

Get device information

This function is only relevant to Linux and will return 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.

### int rte\_vfio\_get\_container\_fd (void)

Open a new VFIO container fd

This function is only relevant to linux and will return an error on BSD.

**Returns**

0 container fd \< 0 for errors

### int rte\_vfio\_get\_group\_fd (int iommu\_group\_num)

Open VFIO group fd or get an existing one

This function is only relevant to linux and will return an error on BSD.

**Parameters**

*iommu\_group\_num* iommu group number

**Returns**

0 group fd \< 0 for errors

### int rte\_vfio\_container\_create (void)

Create a new container for device binding.

**Note**

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.

**Returns**

the container fd if successful \<0 if failed

### int rte\_vfio\_container\_destroy (int container\_fd)

Destroy the container, unbind all vfio groups within it.

**Parameters**

*container\_fd* the container fd to destroy

**Returns**

0 if successful \<0 if failed

### int rte\_vfio\_container\_group\_bind (int container\_fd, int iommu\_group\_num)

Bind a IOMMU group to a container.

**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

### int rte\_vfio\_container\_group\_unbind (int container\_fd, int iommu\_group\_num)

Unbind a 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

### int rte\_vfio\_container\_dma\_map (int container\_fd, uint64\_t vaddr, uint64\_t iova, uint64\_t len)

Perform 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

### int rte\_vfio\_container\_dma\_unmap (int container\_fd, uint64\_t vaddr, uint64\_t iova, uint64\_t len)

Perform DMA unmapping 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 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.
