tools/testing/selftests/vfio/vfio_iommufd_setup_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/vfio/vfio_iommufd_setup_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/vfio/vfio_iommufd_setup_test.c- Extension
.c- Size
- 3227 bytes
- Lines
- 127
- 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
linux/limits.hlinux/sizes.hlinux/vfio.hlinux/iommufd.hstdint.hstdio.hsys/ioctl.hunistd.hlibvfio.hkselftest_harness.h
Detected Declarations
function vfio_device_bind_iommufd_ioctlfunction vfio_device_get_info_ioctlfunction vfio_device_ioas_alloc_ioctlfunction vfio_device_attach_iommufd_pt_ioctlfunction vfio_device_detach_iommufd_pt_ioctlfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
#include <linux/limits.h>
#include <linux/sizes.h>
#include <linux/vfio.h>
#include <linux/iommufd.h>
#include <stdint.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <libvfio.h>
#include "kselftest_harness.h"
static const char iommu_dev_path[] = "/dev/iommu";
static const char *cdev_path;
static int vfio_device_bind_iommufd_ioctl(int cdev_fd, int iommufd)
{
struct vfio_device_bind_iommufd bind_args = {
.argsz = sizeof(bind_args),
.iommufd = iommufd,
};
return ioctl(cdev_fd, VFIO_DEVICE_BIND_IOMMUFD, &bind_args);
}
static int vfio_device_get_info_ioctl(int cdev_fd)
{
struct vfio_device_info info_args = { .argsz = sizeof(info_args) };
return ioctl(cdev_fd, VFIO_DEVICE_GET_INFO, &info_args);
}
static int vfio_device_ioas_alloc_ioctl(int iommufd, struct iommu_ioas_alloc *alloc_args)
{
*alloc_args = (struct iommu_ioas_alloc){
.size = sizeof(struct iommu_ioas_alloc),
};
return ioctl(iommufd, IOMMU_IOAS_ALLOC, alloc_args);
}
static int vfio_device_attach_iommufd_pt_ioctl(int cdev_fd, u32 pt_id)
{
struct vfio_device_attach_iommufd_pt attach_args = {
.argsz = sizeof(attach_args),
.pt_id = pt_id,
};
return ioctl(cdev_fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_args);
}
static int vfio_device_detach_iommufd_pt_ioctl(int cdev_fd)
{
struct vfio_device_detach_iommufd_pt detach_args = {
.argsz = sizeof(detach_args),
};
return ioctl(cdev_fd, VFIO_DEVICE_DETACH_IOMMUFD_PT, &detach_args);
}
FIXTURE(vfio_cdev) {
int cdev_fd;
int iommufd;
};
FIXTURE_SETUP(vfio_cdev)
{
ASSERT_LE(0, (self->cdev_fd = open(cdev_path, O_RDWR, 0)));
ASSERT_LE(0, (self->iommufd = open(iommu_dev_path, O_RDWR, 0)));
}
FIXTURE_TEARDOWN(vfio_cdev)
{
ASSERT_EQ(0, close(self->cdev_fd));
ASSERT_EQ(0, close(self->iommufd));
}
TEST_F(vfio_cdev, bind)
{
ASSERT_EQ(0, vfio_device_bind_iommufd_ioctl(self->cdev_fd, self->iommufd));
ASSERT_EQ(0, vfio_device_get_info_ioctl(self->cdev_fd));
}
TEST_F(vfio_cdev, get_info_without_bind_fails)
{
ASSERT_NE(0, vfio_device_get_info_ioctl(self->cdev_fd));
}
Annotation
- Immediate include surface: `linux/limits.h`, `linux/sizes.h`, `linux/vfio.h`, `linux/iommufd.h`, `stdint.h`, `stdio.h`, `sys/ioctl.h`, `unistd.h`.
- Detected declarations: `function vfio_device_bind_iommufd_ioctl`, `function vfio_device_get_info_ioctl`, `function vfio_device_ioas_alloc_ioctl`, `function vfio_device_attach_iommufd_pt_ioctl`, `function vfio_device_detach_iommufd_pt_ioctl`, `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.