arch/um/drivers/vfio_user.c
Source file repositories/reference/linux-study-clean/arch/um/drivers/vfio_user.c
File Facts
- System
- Linux kernel
- Corpus path
arch/um/drivers/vfio_user.c- Extension
.c- Size
- 7155 bytes
- Lines
- 328
- Domain
- Architecture Layer
- Bucket
- arch/um
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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
errno.hfcntl.hunistd.hstdio.hstdint.hstdlib.hstring.hsys/ioctl.hsys/eventfd.hlinux/limits.hlinux/vfio.hlinux/pci_regs.has-layout.hum_malloc.hvfio_user.h
Detected Declarations
function Copyrightfunction uml_vfio_user_setup_iommufunction uml_vfio_user_get_group_idfunction uml_vfio_user_open_groupfunction uml_vfio_user_set_containerfunction uml_vfio_user_unset_containerfunction vfio_set_irqsfunction uml_vfio_user_setup_devicefunction uml_vfio_user_teardown_devicefunction uml_vfio_user_activate_irqfunction uml_vfio_user_deactivate_irqfunction uml_vfio_user_update_irqsfunction vfio_region_readfunction vfio_region_writefunction uml_vfio_user_cfgspace_readfunction uml_vfio_user_cfgspace_writefunction uml_vfio_user_bar_readfunction uml_vfio_user_bar_write
Annotated Snippet
if (ioctl(dev->device, VFIO_DEVICE_GET_REGION_INFO, ®ion) < 0) {
err = -errno;
goto free_region;
}
dev->region[i].size = region.size;
dev->region[i].offset = region.offset;
}
/* Only MSI-X is supported currently. */
irq_info.index = VFIO_PCI_MSIX_IRQ_INDEX;
if (ioctl(dev->device, VFIO_DEVICE_GET_IRQ_INFO, &irq_info) < 0) {
err = -errno;
goto free_region;
}
dev->irq_count = irq_info.count;
dev->irqfd = uml_kmalloc(sizeof(int) * dev->irq_count, UM_GFP_KERNEL);
if (!dev->irqfd) {
err = -ENOMEM;
goto free_region;
}
memset(dev->irqfd, -1, sizeof(int) * dev->irq_count);
err = vfio_set_irqs(dev->device, 0, dev->irq_count, dev->irqfd);
if (err)
goto free_irqfd;
return 0;
free_irqfd:
kfree(dev->irqfd);
free_region:
kfree(dev->region);
close_device:
close(dev->device);
return err;
}
void uml_vfio_user_teardown_device(struct uml_vfio_user_device *dev)
{
kfree(dev->irqfd);
kfree(dev->region);
close(dev->device);
}
int uml_vfio_user_activate_irq(struct uml_vfio_user_device *dev, int index)
{
int irqfd;
irqfd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
if (irqfd < 0)
return -errno;
dev->irqfd[index] = irqfd;
return irqfd;
}
void uml_vfio_user_deactivate_irq(struct uml_vfio_user_device *dev, int index)
{
close(dev->irqfd[index]);
dev->irqfd[index] = -1;
}
int uml_vfio_user_update_irqs(struct uml_vfio_user_device *dev)
{
return vfio_set_irqs(dev->device, 0, dev->irq_count, dev->irqfd);
}
static int vfio_region_read(struct uml_vfio_user_device *dev, unsigned int index,
uint64_t offset, void *buf, uint64_t size)
{
if (index >= dev->num_regions || offset + size > dev->region[index].size)
return -EINVAL;
if (pread(dev->device, buf, size, dev->region[index].offset + offset) < 0)
return -errno;
return 0;
}
static int vfio_region_write(struct uml_vfio_user_device *dev, unsigned int index,
uint64_t offset, const void *buf, uint64_t size)
{
if (index >= dev->num_regions || offset + size > dev->region[index].size)
return -EINVAL;
if (pwrite(dev->device, buf, size, dev->region[index].offset + offset) < 0)
return -errno;
Annotation
- Immediate include surface: `errno.h`, `fcntl.h`, `unistd.h`, `stdio.h`, `stdint.h`, `stdlib.h`, `string.h`, `sys/ioctl.h`.
- Detected declarations: `function Copyright`, `function uml_vfio_user_setup_iommu`, `function uml_vfio_user_get_group_id`, `function uml_vfio_user_open_group`, `function uml_vfio_user_set_container`, `function uml_vfio_user_unset_container`, `function vfio_set_irqs`, `function uml_vfio_user_setup_device`, `function uml_vfio_user_teardown_device`, `function uml_vfio_user_activate_irq`.
- Atlas domain: Architecture Layer / arch/um.
- Implementation status: source implementation candidate.
- 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.