drivers/vfio/pci/pds/lm.c
Source file repositories/reference/linux-study-clean/drivers/vfio/pci/pds/lm.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/pci/pds/lm.c- Extension
.c- Size
- 10174 bytes
- Lines
- 445
- 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/file.hlinux/fs.hlinux/highmem.hlinux/vfio.hlinux/vfio_pci_core.hvfio_dev.hcmds.h
Detected Declarations
function pds_vfio_get_lm_filefunction pds_vfio_put_lm_filefunction pds_vfio_put_save_filefunction pds_vfio_put_restore_filefunction for_each_sgfunction pds_vfio_release_filefunction pds_vfio_save_readfunction pds_vfio_get_save_filefunction pds_vfio_restore_writefunction pds_vfio_get_restore_filefunction pds_vfio_step_device_state_locked
Annotated Snippet
pds_vfio_get_lm_file(const struct file_operations *fops, int flags, u64 size)
{
struct pds_vfio_lm_file *lm_file = NULL;
unsigned long long npages;
struct page **pages;
void *page_mem;
const void *p;
if (!size)
return NULL;
/* Alloc file structure */
lm_file = kzalloc_obj(*lm_file);
if (!lm_file)
return NULL;
/* Create file */
lm_file->filep =
anon_inode_getfile("pds_vfio_lm", fops, lm_file, flags);
if (IS_ERR(lm_file->filep))
goto out_free_file;
stream_open(lm_file->filep->f_inode, lm_file->filep);
mutex_init(&lm_file->lock);
/* prevent file from being released before we are done with it */
get_file(lm_file->filep);
/* Allocate memory for file pages */
npages = DIV_ROUND_UP_ULL(size, PAGE_SIZE);
pages = kmalloc_objs(*pages, npages);
if (!pages)
goto out_put_file;
page_mem = kvzalloc(ALIGN(size, PAGE_SIZE), GFP_KERNEL);
if (!page_mem)
goto out_free_pages_array;
p = page_mem - offset_in_page(page_mem);
for (unsigned long long i = 0; i < npages; i++) {
if (is_vmalloc_addr(p))
pages[i] = vmalloc_to_page(p);
else
pages[i] = kmap_to_page((void *)p);
if (!pages[i])
goto out_free_page_mem;
p += PAGE_SIZE;
}
/* Create scatterlist of file pages to use for DMA mapping later */
if (sg_alloc_table_from_pages(&lm_file->sg_table, pages, npages, 0,
size, GFP_KERNEL))
goto out_free_page_mem;
lm_file->size = size;
lm_file->pages = pages;
lm_file->npages = npages;
lm_file->page_mem = page_mem;
lm_file->alloc_size = npages * PAGE_SIZE;
return lm_file;
out_free_page_mem:
kvfree(page_mem);
out_free_pages_array:
kfree(pages);
out_put_file:
fput(lm_file->filep);
mutex_destroy(&lm_file->lock);
out_free_file:
kfree(lm_file);
return NULL;
}
static void pds_vfio_put_lm_file(struct pds_vfio_lm_file *lm_file)
{
mutex_lock(&lm_file->lock);
lm_file->disabled = true;
lm_file->size = 0;
lm_file->alloc_size = 0;
lm_file->filep->f_pos = 0;
/* Free scatter list of file pages */
sg_free_table(&lm_file->sg_table);
kvfree(lm_file->page_mem);
lm_file->page_mem = NULL;
Annotation
- Immediate include surface: `linux/anon_inodes.h`, `linux/file.h`, `linux/fs.h`, `linux/highmem.h`, `linux/vfio.h`, `linux/vfio_pci_core.h`, `vfio_dev.h`, `cmds.h`.
- Detected declarations: `function pds_vfio_get_lm_file`, `function pds_vfio_put_lm_file`, `function pds_vfio_put_save_file`, `function pds_vfio_put_restore_file`, `function for_each_sg`, `function pds_vfio_release_file`, `function pds_vfio_save_read`, `function pds_vfio_get_save_file`, `function pds_vfio_restore_write`, `function pds_vfio_get_restore_file`.
- 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.