drivers/vfio/pci/qat/main.c
Source file repositories/reference/linux-study-clean/drivers/vfio/pci/qat/main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/pci/qat/main.c- Extension
.c- Size
- 18868 bytes
- Lines
- 706
- Domain
- Driver Families
- Bucket
- drivers/vfio
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/anon_inodes.hlinux/container_of.hlinux/device.hlinux/file.hlinux/init.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/pci.hlinux/sizes.hlinux/types.hlinux/uaccess.hlinux/vfio_pci_core.hlinux/qat/qat_mig_dev.h
Detected Declarations
struct qat_vf_migration_filestruct qat_vf_core_devicefunction qat_vf_pci_open_devicefunction qat_vf_disable_fdfunction qat_vf_disable_fdsfunction qat_vf_pci_close_devicefunction qat_vf_precopy_ioctlfunction qat_vf_save_readfunction qat_vf_release_filefunction qat_vf_save_statefunction qat_vf_save_setupfunction qat_vf_save_device_datafunction qat_vf_resume_writefunction qat_vf_resume_device_datafunction qat_vf_load_device_datafunction qat_vf_reset_donefunction qat_vf_pci_get_device_statefunction qat_vf_pci_get_data_sizefunction qat_vf_pci_release_devfunction qat_vf_pci_init_devfunction qat_vf_pci_aer_reset_donefunction qat_vf_vfio_pci_probefunction qat_vf_vfio_pci_remove
Annotated Snippet
static const struct file_operations qat_vf_save_fops = {
.owner = THIS_MODULE,
.read = qat_vf_save_read,
.unlocked_ioctl = qat_vf_precopy_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.release = qat_vf_release_file,
};
static int qat_vf_save_state(struct qat_vf_core_device *qat_vdev,
struct qat_vf_migration_file *migf)
{
int ret;
ret = qat_vfmig_save_state(qat_vdev->mdev);
if (ret)
return ret;
migf->filled_size = qat_vdev->mdev->state_size;
return 0;
}
static int qat_vf_save_setup(struct qat_vf_core_device *qat_vdev,
struct qat_vf_migration_file *migf)
{
int ret;
ret = qat_vfmig_save_setup(qat_vdev->mdev);
if (ret)
return ret;
migf->filled_size = qat_vdev->mdev->setup_size;
return 0;
}
/*
* Allocate a file handler for user space and then save the migration data for
* the device being migrated. If this is called in the pre-copy stage, save the
* pre-configured device data. Otherwise, if this is called in the stop-copy
* stage, save the device state. In both cases, update the data size which can
* then be read from user space.
*/
static struct qat_vf_migration_file *
qat_vf_save_device_data(struct qat_vf_core_device *qat_vdev, bool pre_copy)
{
struct qat_vf_migration_file *migf;
int ret;
migf = kzalloc_obj(*migf);
if (!migf)
return ERR_PTR(-ENOMEM);
migf->filp = anon_inode_getfile("qat_vf_mig", &qat_vf_save_fops,
migf, O_RDONLY);
ret = PTR_ERR_OR_ZERO(migf->filp);
if (ret) {
kfree(migf);
return ERR_PTR(ret);
}
stream_open(migf->filp->f_inode, migf->filp);
mutex_init(&migf->lock);
if (pre_copy)
ret = qat_vf_save_setup(qat_vdev, migf);
else
ret = qat_vf_save_state(qat_vdev, migf);
if (ret) {
fput(migf->filp);
return ERR_PTR(ret);
}
migf->qat_vdev = qat_vdev;
return migf;
}
static ssize_t qat_vf_resume_write(struct file *filp, const char __user *buf,
size_t len, loff_t *pos)
{
struct qat_vf_migration_file *migf = filp->private_data;
struct qat_mig_dev *mig_dev = migf->qat_vdev->mdev;
loff_t end, *offs;
ssize_t done = 0;
int ret;
if (pos)
return -ESPIPE;
offs = &filp->f_pos;
mutex_lock(&migf->lock);
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/container_of.h`, `linux/device.h`, `linux/file.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`.
- Detected declarations: `struct qat_vf_migration_file`, `struct qat_vf_core_device`, `function qat_vf_pci_open_device`, `function qat_vf_disable_fd`, `function qat_vf_disable_fds`, `function qat_vf_pci_close_device`, `function qat_vf_precopy_ioctl`, `function qat_vf_save_read`, `function qat_vf_release_file`, `function qat_vf_save_state`.
- Atlas domain: Driver Families / drivers/vfio.
- Implementation status: pattern implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.