drivers/xen/mcelog.c
Source file repositories/reference/linux-study-clean/drivers/xen/mcelog.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/xen/mcelog.c- Extension
.c- Size
- 10412 bytes
- Lines
- 424
- 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/init.hlinux/types.hlinux/kernel.hlinux/slab.hlinux/fs.hlinux/device.hlinux/miscdevice.hlinux/uaccess.hlinux/capability.hlinux/poll.hlinux/sched.hxen/interface/xen.hxen/events.hxen/interface/vcpu.hxen/xen.hasm/xen/hypercall.hasm/xen/hypervisor.h
Detected Declarations
function xen_mce_chrdev_openfunction xen_mce_chrdev_releasefunction xen_mce_chrdev_readfunction xen_mce_chrdev_pollfunction xen_mce_chrdev_ioctlfunction xen_mce_logfunction convert_logfunction mc_queue_handlefunction xen_mce_work_fnfunction xen_mce_interruptfunction bind_virq_for_mcefunction xen_late_init_mcelogmodule init xen_late_init_mcelog
Annotated Snippet
static const struct file_operations xen_mce_chrdev_ops = {
.open = xen_mce_chrdev_open,
.release = xen_mce_chrdev_release,
.read = xen_mce_chrdev_read,
.poll = xen_mce_chrdev_poll,
.unlocked_ioctl = xen_mce_chrdev_ioctl,
};
static struct miscdevice xen_mce_chrdev_device __ro_after_init = {
MISC_MCELOG_MINOR,
"mcelog",
&xen_mce_chrdev_ops,
};
/*
* Caller should hold the mcelog_lock
*/
static void xen_mce_log(struct xen_mce *mce)
{
unsigned entry;
entry = xen_mcelog.next;
/*
* When the buffer fills up discard new entries.
* Assume that the earlier errors are the more
* interesting ones:
*/
if (entry >= XEN_MCE_LOG_LEN) {
set_bit(XEN_MCE_OVERFLOW,
(unsigned long *)&xen_mcelog.flags);
return;
}
memcpy(xen_mcelog.entry + entry, mce, sizeof(struct xen_mce));
xen_mcelog.next++;
}
static int convert_log(struct mc_info *mi)
{
struct mcinfo_common *mic;
struct mcinfo_global *mc_global;
struct mcinfo_bank *mc_bank;
struct xen_mce m;
unsigned int i, j;
mic = NULL;
x86_mcinfo_lookup(&mic, mi, MC_TYPE_GLOBAL);
if (unlikely(!mic)) {
pr_warn("Failed to find global error info\n");
return -ENODEV;
}
memset(&m, 0, sizeof(struct xen_mce));
mc_global = (struct mcinfo_global *)mic;
m.mcgstatus = mc_global->mc_gstatus;
m.apicid = mc_global->mc_apicid;
for (i = 0; i < ncpus; i++)
if (g_physinfo[i].mc_apicid == m.apicid)
break;
if (unlikely(i == ncpus)) {
pr_warn("Failed to match cpu with apicid %d\n", m.apicid);
return -ENODEV;
}
m.socketid = g_physinfo[i].mc_chipid;
m.cpu = m.extcpu = g_physinfo[i].mc_cpunr;
m.cpuvendor = (__u8)g_physinfo[i].mc_vendor;
for (j = 0; j < g_physinfo[i].mc_nmsrvals; ++j)
switch (g_physinfo[i].mc_msrvalues[j].reg) {
case MSR_IA32_MCG_CAP:
m.mcgcap = g_physinfo[i].mc_msrvalues[j].value;
break;
case MSR_PPIN:
case MSR_AMD_PPIN:
m.ppin = g_physinfo[i].mc_msrvalues[j].value;
break;
}
mic = NULL;
x86_mcinfo_lookup(&mic, mi, MC_TYPE_BANK);
if (unlikely(!mic)) {
pr_warn("Fail to find bank error info\n");
return -ENODEV;
}
Annotation
- Immediate include surface: `linux/init.h`, `linux/types.h`, `linux/kernel.h`, `linux/slab.h`, `linux/fs.h`, `linux/device.h`, `linux/miscdevice.h`, `linux/uaccess.h`.
- Detected declarations: `function xen_mce_chrdev_open`, `function xen_mce_chrdev_release`, `function xen_mce_chrdev_read`, `function xen_mce_chrdev_poll`, `function xen_mce_chrdev_ioctl`, `function xen_mce_log`, `function convert_log`, `function mc_queue_handle`, `function xen_mce_work_fn`, `function xen_mce_interrupt`.
- 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.