arch/x86/kvm/xen.c
Source file repositories/reference/linux-study-clean/arch/x86/kvm/xen.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/kvm/xen.c- Extension
.c- Size
- 66357 bytes
- Lines
- 2352
- Domain
- Architecture Layer
- Bucket
- arch/x86
- 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 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
x86.hxen.hhyperv.hirq.hlinux/eventfd.hlinux/kvm_host.hlinux/sched/stat.htrace/events/kvm.hxen/interface/xen.hxen/interface/vcpu.hxen/interface/version.hxen/interface/event_channel.hxen/interface/sched.hasm/xen/cpuid.hasm/pvclock.hcpuid.htrace.h
Detected Declarations
struct compat_vcpu_set_singleshot_timerstruct evtchnfdfunction kvm_xen_shared_info_initfunction kvm_xen_inject_timer_irqsfunction xen_timer_callbackfunction xen_get_guest_pvclockfunction kvm_xen_start_timerfunction valuesfunction kvm_xen_stop_timerfunction kvm_xen_update_runstate_guestfunction alignmentfunction kvm_xen_update_runstatefunction kvm_xen_inject_vcpu_vectorfunction vcpu_infofunction __kvm_xen_has_interruptfunction kvm_xen_hvm_set_attrfunction kvm_xen_hvm_get_attrfunction kvm_xen_vcpu_set_attrfunction kvm_xen_vcpu_get_attrfunction kvm_xen_write_hypercall_pagefunction kvm_xen_hvm_configfunction kvm_xen_hypercall_set_resultfunction kvm_xen_hypercall_complete_userspacefunction max_evtchn_portfunction wait_pending_eventfunction kvm_xen_schedop_pollfunction cancel_evtchn_pollfunction kvm_xen_hcall_sched_opfunction kvm_xen_hcall_vcpu_opfunction kvm_xen_hcall_set_timer_opfunction kvm_xen_hypercallfunction kvm_xen_check_pollerfunction kvm_set_irqfunction kvm_xen_set_evtchnfunction evtchn_set_fnfunction kvm_xen_setup_evtchnfunction kvm_xen_hvm_evtchn_sendfunction kvm_xen_eventfd_updatefunction targetfunction kvm_xen_eventfd_deassignfunction kvm_xen_eventfd_resetfunction kvm_xen_setattr_evtchnfunction kvm_xen_hcall_evtchn_sendfunction kvm_xen_init_vcpufunction kvm_xen_destroy_vcpufunction kvm_xen_init_vmfunction kvm_xen_destroy_vmfunction idr_for_each_entry
Annotated Snippet
struct compat_vcpu_set_singleshot_timer {
uint64_t timeout_abs_ns;
uint32_t flags;
} __attribute__((packed));
static bool kvm_xen_hcall_vcpu_op(struct kvm_vcpu *vcpu, bool longmode, int cmd,
int vcpu_id, u64 param, u64 *r)
{
struct vcpu_set_singleshot_timer oneshot;
struct x86_exception e;
if (!kvm_xen_timer_enabled(vcpu))
return false;
switch (cmd) {
case VCPUOP_set_singleshot_timer:
if (vcpu->arch.xen.vcpu_id != vcpu_id) {
*r = -EINVAL;
return true;
}
/*
* The only difference for 32-bit compat is the 4 bytes of
* padding after the interesting part of the structure. So
* for a faithful emulation of Xen we have to *try* to copy
* the padding and return -EFAULT if we can't. Otherwise we
* might as well just have copied the 12-byte 32-bit struct.
*/
BUILD_BUG_ON(offsetof(struct compat_vcpu_set_singleshot_timer, timeout_abs_ns) !=
offsetof(struct vcpu_set_singleshot_timer, timeout_abs_ns));
BUILD_BUG_ON(sizeof_field(struct compat_vcpu_set_singleshot_timer, timeout_abs_ns) !=
sizeof_field(struct vcpu_set_singleshot_timer, timeout_abs_ns));
BUILD_BUG_ON(offsetof(struct compat_vcpu_set_singleshot_timer, flags) !=
offsetof(struct vcpu_set_singleshot_timer, flags));
BUILD_BUG_ON(sizeof_field(struct compat_vcpu_set_singleshot_timer, flags) !=
sizeof_field(struct vcpu_set_singleshot_timer, flags));
if (kvm_read_guest_virt(vcpu, param, &oneshot, longmode ? sizeof(oneshot) :
sizeof(struct compat_vcpu_set_singleshot_timer), &e)) {
*r = -EFAULT;
return true;
}
kvm_xen_start_timer(vcpu, oneshot.timeout_abs_ns, false);
*r = 0;
return true;
case VCPUOP_stop_singleshot_timer:
if (vcpu->arch.xen.vcpu_id != vcpu_id) {
*r = -EINVAL;
return true;
}
kvm_xen_stop_timer(vcpu);
*r = 0;
return true;
}
return false;
}
static bool kvm_xen_hcall_set_timer_op(struct kvm_vcpu *vcpu, uint64_t timeout,
u64 *r)
{
if (!kvm_xen_timer_enabled(vcpu))
return false;
if (timeout)
kvm_xen_start_timer(vcpu, timeout, true);
else
kvm_xen_stop_timer(vcpu);
*r = 0;
return true;
}
int kvm_xen_hypercall(struct kvm_vcpu *vcpu)
{
bool longmode;
u64 input, params[6], r = -ENOSYS;
bool handled = false;
u8 cpl;
/* Hyper-V hypercalls get bit 31 set in EAX */
if ((kvm_rax_read_raw(vcpu) & 0x80000000) &&
kvm_hv_hypercall_enabled(vcpu))
return kvm_hv_hypercall(vcpu);
longmode = is_64_bit_hypercall(vcpu);
if (!longmode) {
input = kvm_eax_read(vcpu);
Annotation
- Immediate include surface: `x86.h`, `xen.h`, `hyperv.h`, `irq.h`, `linux/eventfd.h`, `linux/kvm_host.h`, `linux/sched/stat.h`, `trace/events/kvm.h`.
- Detected declarations: `struct compat_vcpu_set_singleshot_timer`, `struct evtchnfd`, `function kvm_xen_shared_info_init`, `function kvm_xen_inject_timer_irqs`, `function xen_timer_callback`, `function xen_get_guest_pvclock`, `function kvm_xen_start_timer`, `function values`, `function kvm_xen_stop_timer`, `function kvm_xen_update_runstate_guest`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: source 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.