tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c- Extension
.c- Size
- 5325 bytes
- Lines
- 218
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
lib/include/libvfio/assert.hfcntl.hunistd.hstdlib.hsys/ioctl.hlinux/limits.hlibvfio.h../kselftest_harness.h
Detected Declarations
function container_setupfunction iommufd_setupfunction device_initfunction device_cleanupfunction vf_teardownfunction vf_setupfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
#include "lib/include/libvfio/assert.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/limits.h>
#include <libvfio.h>
#include "../kselftest_harness.h"
#define UUID_1 "52ac9bff-3a88-4fbd-901a-0d767c3b6c97"
#define UUID_2 "88594674-90a0-47a9-aea8-9d9b352ac08a"
static const char *pf_bdf;
static char *vf_bdf;
static pid_t main_pid;
static int container_setup(struct vfio_pci_device *device, const char *bdf,
const char *vf_token)
{
vfio_pci_group_setup(device, bdf);
vfio_container_set_iommu(device);
__vfio_pci_group_get_device_fd(device, bdf, vf_token);
/* The device fd will be -1 in case of mismatched tokens */
return (device->fd < 0);
}
static int iommufd_setup(struct vfio_pci_device *device, const char *bdf,
const char *vf_token)
{
vfio_pci_cdev_open(device, bdf);
return __vfio_device_bind_iommufd(device->fd,
device->iommu->iommufd, vf_token);
}
static int device_init(const char *bdf, struct iommu *iommu,
const char *vf_token, struct vfio_pci_device **out_dev)
{
struct vfio_pci_device *device = vfio_pci_device_alloc(bdf, iommu);
int ret;
if (iommu->mode->container_path)
ret = container_setup(device, bdf, vf_token);
else
ret = iommufd_setup(device, bdf, vf_token);
*out_dev = device;
return ret;
}
static void device_cleanup(struct vfio_pci_device *device)
{
if (!device)
return;
if (device->fd > 0)
VFIO_ASSERT_EQ(close(device->fd), 0);
if (device->group_fd)
VFIO_ASSERT_EQ(close(device->group_fd), 0);
vfio_pci_device_free(device);
}
FIXTURE(vfio_pci_sriov_uapi_test) {
struct vfio_pci_device *pf;
struct vfio_pci_device *vf;
struct iommu *iommu;
char *pf_token;
};
FIXTURE_VARIANT(vfio_pci_sriov_uapi_test) {
const char *iommu_mode;
char *vf_token;
};
#define FIXTURE_VARIANT_ADD_IOMMU_MODE(_iommu_mode, _name, _vf_token) \
FIXTURE_VARIANT_ADD(vfio_pci_sriov_uapi_test, _iommu_mode ## _ ## _name) { \
.iommu_mode = #_iommu_mode, \
.vf_token = (_vf_token), \
}
FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(same_uuid, UUID_1);
FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(diff_uuid, UUID_2);
FIXTURE_VARIANT_ADD_ALL_IOMMU_MODES(null_uuid, NULL);
Annotation
- Immediate include surface: `lib/include/libvfio/assert.h`, `fcntl.h`, `unistd.h`, `stdlib.h`, `sys/ioctl.h`, `linux/limits.h`, `libvfio.h`, `../kselftest_harness.h`.
- Detected declarations: `function container_setup`, `function iommufd_setup`, `function device_init`, `function device_cleanup`, `function vf_teardown`, `function vf_setup`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.