drivers/xen/privcmd.c
Source file repositories/reference/linux-study-clean/drivers/xen/privcmd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/privcmd.c- Extension
.c- Size
- 41631 bytes
- Lines
- 1786
- Domain
- Driver Families
- Bucket
- drivers/xen
- 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.
- 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/eventfd.hlinux/file.hlinux/kernel.hlinux/kstrtox.hlinux/module.hlinux/mutex.hlinux/poll.hlinux/sched.hlinux/slab.hlinux/srcu.hlinux/string.hlinux/workqueue.hlinux/errno.hlinux/mm.hlinux/mman.hlinux/uaccess.hlinux/swap.hlinux/highmem.hlinux/pagemap.hlinux/seq_file.hlinux/miscdevice.hlinux/moduleparam.hlinux/notifier.hlinux/security.hlinux/virtio_mmio.hlinux/wait.hasm/xen/hypervisor.hasm/xen/hypercall.hxen/xen.hxen/events.hxen/privcmd.hxen/interface/xen.h
Detected Declarations
struct privcmd_datastruct mmap_gfn_statestruct mmap_batch_statestruct privcmd_kernel_irqfdstruct privcmd_kernel_ioeventfdstruct ioreq_portstruct privcmd_kernel_ioreqfunction privcmd_ioctl_hypercallfunction free_page_listfunction gather_arrayfunction traverse_pagesfunction traverse_pages_blockfunction mmap_gfn_rangefunction privcmd_ioctl_mmapfunction mfnfunction mmap_return_errorfunction mmap_return_errorsfunction alloc_empty_pagesfunction privcmd_ioctl_mmap_batchfunction attemptfunction lock_pagesfunction unlock_pagesfunction privcmd_ioctl_dm_opfunction privcmd_ioctl_restrictfunction privcmd_ioctl_mmap_resourcefunction privcmd_ioctl_pcidev_get_gsifunction irqfd_deactivatefunction irqfd_shutdownfunction irqfd_injectfunction irqfd_wakeupfunction irqfd_poll_funcfunction privcmd_irqfd_assignfunction list_for_each_entryfunction privcmd_irqfd_deassignfunction list_for_each_entryfunction privcmd_ioctl_irqfdfunction privcmd_irqfd_initfunction privcmd_irqfd_exitfunction ioeventfd_interruptfunction list_for_each_entryfunction ioreq_freefunction get_ioreqfunction list_for_each_entryfunction list_for_each_entryfunction ioeventfd_freefunction privcmd_ioeventfd_assignfunction privcmd_ioeventfd_deassignfunction list_for_each_entry_safe
Annotated Snippet
const struct file_operations xen_privcmd_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = privcmd_ioctl,
.open = privcmd_open,
.release = privcmd_release,
.mmap = privcmd_mmap,
};
EXPORT_SYMBOL_GPL(xen_privcmd_fops);
static struct miscdevice privcmd_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "xen/privcmd",
.fops = &xen_privcmd_fops,
};
static int init_restrict(struct notifier_block *notifier,
unsigned long event,
void *data)
{
char *target;
unsigned int domid;
/* Default to an guaranteed unused domain-id. */
target_domain = DOMID_IDLE;
target = xenbus_read(XBT_NIL, "target", "", NULL);
if (IS_ERR(target) || kstrtouint(target, 10, &domid)) {
pr_err("No target domain found, blocking all hypercalls\n");
goto out;
}
target_domain = domid;
out:
if (!IS_ERR(target))
kfree(target);
restrict_wait = false;
wake_up_all(&restrict_wait_wq);
return NOTIFY_DONE;
}
static struct notifier_block xenstore_notifier = {
.notifier_call = init_restrict,
};
static void __init restrict_driver(void)
{
if (unrestricted) {
if (security_locked_down(LOCKDOWN_XEN_USER_ACTIONS))
pr_warn("Kernel is locked down, parameter \"unrestricted\" ignored\n");
else
return;
}
restrict_wait = true;
register_xenstore_notifier(&xenstore_notifier);
}
static int __init privcmd_init(void)
{
int err;
if (!xen_domain())
return -ENODEV;
if (!xen_initial_domain())
restrict_driver();
err = misc_register(&privcmd_dev);
if (err != 0) {
pr_err("Could not register Xen privcmd device\n");
return err;
}
err = misc_register(&xen_privcmdbuf_dev);
if (err != 0) {
pr_err("Could not register Xen hypercall-buf device\n");
goto err_privcmdbuf;
}
err = privcmd_irqfd_init();
if (err != 0) {
pr_err("irqfd init failed\n");
goto err_irqfd;
}
return 0;
Annotation
- Immediate include surface: `linux/eventfd.h`, `linux/file.h`, `linux/kernel.h`, `linux/kstrtox.h`, `linux/module.h`, `linux/mutex.h`, `linux/poll.h`, `linux/sched.h`.
- Detected declarations: `struct privcmd_data`, `struct mmap_gfn_state`, `struct mmap_batch_state`, `struct privcmd_kernel_irqfd`, `struct privcmd_kernel_ioeventfd`, `struct ioreq_port`, `struct privcmd_kernel_ioreq`, `function privcmd_ioctl_hypercall`, `function free_page_list`, `function gather_array`.
- Atlas domain: Driver Families / drivers/xen.
- 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.
- 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.