drivers/vfio/pci/vfio_pci_rdwr.c
Source file repositories/reference/linux-study-clean/drivers/vfio/pci/vfio_pci_rdwr.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/vfio/pci/vfio_pci_rdwr.c- Extension
.c- Size
- 11930 bytes
- Lines
- 491
- Domain
- Driver Families
- Bucket
- drivers/vfio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/fs.hlinux/pci.hlinux/uaccess.hlinux/io.hlinux/vfio.hlinux/vgaarb.hlinux/io-64-nonatomic-lo-hi.hvfio_pci_priv.h
Detected Declarations
function Copyrightfunction regionfunction vfio_pci_bar_rwfunction vfio_pci_vga_rwfunction vfio_pci_ioeventfd_do_writefunction vfio_pci_ioeventfd_handlerfunction vfio_pci_ioeventfd_threadfunction vfio_pci_ioeventfdfunction list_for_each_entryexport vfio_pci_core_do_io_rw
Annotated Snippet
if (!__vfio_pci_memory_enabled(vdev)) { \
up_read(&vdev->memory_lock); \
return -EIO; \
} \
} \
\
vfio_iowrite##size(val, io); \
\
if (test_mem) \
up_read(&vdev->memory_lock); \
\
return 0; \
} \
EXPORT_SYMBOL_GPL(vfio_pci_core_iowrite##size);
VFIO_IOWRITE(8)
VFIO_IOWRITE(16)
VFIO_IOWRITE(32)
VFIO_IOWRITE(64)
#define VFIO_IOREAD(size) \
int vfio_pci_core_ioread##size(struct vfio_pci_core_device *vdev, \
bool test_mem, u##size *val, void __iomem *io) \
{ \
if (test_mem) { \
down_read(&vdev->memory_lock); \
if (!__vfio_pci_memory_enabled(vdev)) { \
up_read(&vdev->memory_lock); \
return -EIO; \
} \
} \
\
*val = vfio_ioread##size(io); \
\
if (test_mem) \
up_read(&vdev->memory_lock); \
\
return 0; \
} \
EXPORT_SYMBOL_GPL(vfio_pci_core_ioread##size);
VFIO_IOREAD(8)
VFIO_IOREAD(16)
VFIO_IOREAD(32)
VFIO_IOREAD(64)
#define VFIO_IORDWR(size) \
static int vfio_pci_iordwr##size(struct vfio_pci_core_device *vdev,\
bool iswrite, bool test_mem, \
void __iomem *io, char __user *buf, \
loff_t off, size_t *filled) \
{ \
u##size val; \
int ret; \
\
if (iswrite) { \
if (copy_from_user(&val, buf, sizeof(val))) \
return -EFAULT; \
\
ret = vfio_pci_core_iowrite##size(vdev, test_mem, \
val, io + off); \
if (ret) \
return ret; \
} else { \
ret = vfio_pci_core_ioread##size(vdev, test_mem, \
&val, io + off); \
if (ret) \
return ret; \
\
if (copy_to_user(buf, &val, sizeof(val))) \
return -EFAULT; \
} \
\
*filled = sizeof(val); \
return 0; \
} \
VFIO_IORDWR(8)
VFIO_IORDWR(16)
VFIO_IORDWR(32)
VFIO_IORDWR(64)
/*
* Read or write from an __iomem region (MMIO or I/O port) with an excluded
* range which is inaccessible. The excluded range drops writes and fills
* reads with -1. This is intended for handling MSI-X vector tables and
* leftover space for ROM BARs.
*/
ssize_t vfio_pci_core_do_io_rw(struct vfio_pci_core_device *vdev, bool test_mem,
void __iomem *io, char __user *buf,
Annotation
- Immediate include surface: `linux/fs.h`, `linux/pci.h`, `linux/uaccess.h`, `linux/io.h`, `linux/vfio.h`, `linux/vgaarb.h`, `linux/io-64-nonatomic-lo-hi.h`, `vfio_pci_priv.h`.
- Detected declarations: `function Copyright`, `function region`, `function vfio_pci_bar_rw`, `function vfio_pci_vga_rw`, `function vfio_pci_ioeventfd_do_write`, `function vfio_pci_ioeventfd_handler`, `function vfio_pci_ioeventfd_thread`, `function vfio_pci_ioeventfd`, `function list_for_each_entry`, `export vfio_pci_core_do_io_rw`.
- Atlas domain: Driver Families / drivers/vfio.
- Implementation status: integration 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.