drivers/vfio/pci/mlx5/main.c
Source file repositories/reference/linux-study-clean/drivers/vfio/pci/mlx5/main.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/pci/mlx5/main.c- Extension
.c- Size
- 38704 bytes
- Lines
- 1466
- 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/device.hlinux/eventfd.hlinux/file.hlinux/interrupt.hlinux/iommu.hlinux/module.hlinux/mutex.hlinux/notifier.hlinux/pci.hlinux/pm_runtime.hlinux/types.hlinux/uaccess.hlinux/vfio.hlinux/sched/mm.hlinux/anon_inodes.hcmd.h
Detected Declarations
function Copyrightfunction mlx5vf_disable_fdfunction mlx5vf_release_filefunction mlx5vf_get_data_buff_from_posfunction mlx5vf_buf_read_donefunction mlx5vf_buf_readfunction mlx5vf_save_readfunction mlx5vf_save_pollfunction mlx5vf_mark_errfunction mlx5vf_mig_file_set_save_workfunction mlx5vf_mig_file_get_stop_copy_buffunction mlx5vf_mig_file_save_workfunction mlx5vf_add_stop_copy_headerfunction mlx5vf_prep_stop_copyfunction mlx5vf_precopy_ioctlfunction mlx5vf_pci_save_device_inc_datafunction mlx5vf_pci_save_device_datafunction mlx5vf_append_page_to_mig_buffunction mlx5vf_resume_read_imagefunction mlx5vf_resume_read_header_datafunction mlx5vf_resume_read_headerfunction mlx5vf_resume_writefunction mlx5vf_pci_resume_device_datafunction mlx5vf_disable_fdsfunction mlx5vf_pci_step_device_state_lockedfunction mlx5vf_state_mutex_unlockfunction mlx5vf_pci_set_device_statefunction mlx5vf_pci_get_data_sizefunction mlx5vf_pci_get_device_statefunction mlx5vf_pci_aer_reset_donefunction mlx5vf_pci_open_devicefunction mlx5vf_pci_close_devicefunction mlx5vf_pci_init_devfunction mlx5vf_pci_release_devfunction mlx5vf_pci_probefunction mlx5vf_pci_remove
Annotated Snippet
static const struct file_operations mlx5vf_save_fops = {
.owner = THIS_MODULE,
.read = mlx5vf_save_read,
.poll = mlx5vf_save_poll,
.unlocked_ioctl = mlx5vf_precopy_ioctl,
.compat_ioctl = compat_ptr_ioctl,
.release = mlx5vf_release_file,
};
static int mlx5vf_pci_save_device_inc_data(struct mlx5vf_pci_core_device *mvdev)
{
struct mlx5_vf_migration_file *migf = mvdev->saving_migf;
struct mlx5_vhca_data_buffer *buf;
size_t length;
int ret;
if (migf->state == MLX5_MIGF_STATE_ERROR)
return -ENODEV;
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &length, NULL, NULL,
MLX5VF_QUERY_INC | MLX5VF_QUERY_FINAL);
if (ret)
goto err;
buf = mlx5vf_mig_file_get_stop_copy_buf(migf, 0, length);
if (IS_ERR(buf)) {
ret = PTR_ERR(buf);
goto err;
}
ret = mlx5vf_cmd_save_vhca_state(mvdev, migf, buf, true, false);
if (ret)
goto err_save;
return 0;
err_save:
mlx5vf_put_data_buffer(buf);
err:
mlx5vf_mark_err(migf);
return ret;
}
static struct mlx5_vf_migration_file *
mlx5vf_pci_save_device_data(struct mlx5vf_pci_core_device *mvdev, bool track)
{
struct mlx5_vf_migration_file *migf;
struct mlx5_vhca_data_buffer *buf;
size_t length;
u64 full_size;
int ret;
migf = kzalloc_obj(*migf, GFP_KERNEL_ACCOUNT);
if (!migf)
return ERR_PTR(-ENOMEM);
migf->filp = anon_inode_getfile("mlx5vf_mig", &mlx5vf_save_fops, migf,
O_RDONLY);
if (IS_ERR(migf->filp)) {
ret = PTR_ERR(migf->filp);
kfree(migf);
return ERR_PTR(ret);
}
migf->mvdev = mvdev;
stream_open(migf->filp->f_inode, migf->filp);
mutex_init(&migf->lock);
init_waitqueue_head(&migf->poll_wait);
init_completion(&migf->save_comp);
/*
* save_comp is being used as a binary semaphore built from
* a completion. A normal mutex cannot be used because the lock is
* passed between kernel threads and lockdep can't model this.
*/
complete(&migf->save_comp);
mlx5_cmd_init_async_ctx(mvdev->mdev, &migf->async_ctx);
INIT_WORK(&migf->async_data.work, mlx5vf_mig_file_cleanup_cb);
INIT_LIST_HEAD(&migf->buf_list);
INIT_LIST_HEAD(&migf->avail_list);
spin_lock_init(&migf->list_lock);
ret = mlx5vf_cmd_alloc_pd(migf);
if (ret)
goto out;
ret = mlx5vf_cmd_query_vhca_migration_state(mvdev, &length, &full_size, NULL, 0);
if (ret)
goto out_pd;
ret = mlx5vf_prep_stop_copy(mvdev, migf, length, full_size, track);
Annotation
- Immediate include surface: `linux/device.h`, `linux/eventfd.h`, `linux/file.h`, `linux/interrupt.h`, `linux/iommu.h`, `linux/module.h`, `linux/mutex.h`, `linux/notifier.h`.
- Detected declarations: `function Copyright`, `function mlx5vf_disable_fd`, `function mlx5vf_release_file`, `function mlx5vf_get_data_buff_from_pos`, `function mlx5vf_buf_read_done`, `function mlx5vf_buf_read`, `function mlx5vf_save_read`, `function mlx5vf_save_poll`, `function mlx5vf_mark_err`, `function mlx5vf_mig_file_set_save_work`.
- 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.