arch/x86/hyperv/hv_crash.c
Source file repositories/reference/linux-study-clean/arch/x86/hyperv/hv_crash.c
File Facts
- System
- Linux kernel
- Corpus path
arch/x86/hyperv/hv_crash.c- Extension
.c- Size
- 18796 bytes
- Lines
- 648
- Domain
- Architecture Layer
- Bucket
- arch/x86
- Inferred role
- Architecture Layer: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/delay.hlinux/kexec.hlinux/crash_dump.hlinux/panic.hasm/apic.hasm/desc.hasm/page.hasm/pgalloc.hasm/mshyperv.hasm/nmi.hasm/idtentry.hasm/reboot.hasm/intel_pt.h
Detected Declarations
struct hv_crash_ctxtstruct hv_gdtreg_32struct hv_crash_tramp_gdtstruct hv_cs_jmptgtstruct hv_crash_tramp_datafunction hv_panic_timeout_rebootfunction hv_crash_restore_tssfunction hv_crash_clear_kernptfunction hv_crash_handlefunction asmfunction hv_mark_tss_not_busyfunction hv_hvcrash_ctxt_savefunction hv_crash_fixup_kernptfunction hv_notify_prepare_hypfunction crash_nmi_callbackfunction hv_crash_nmi_localfunction hv_crash_stop_other_cpusfunction hv_crash_setup_trampdatafunction hv_crash_build_tramp_ptfunction hv_crash_trampoline_setupfunction hv_root_crash_initexport hv_crash_enabled
Annotated Snippet
struct hv_crash_ctxt {
ulong rsp;
ulong cr0;
ulong cr2;
ulong cr4;
ulong cr8;
u16 cs;
u16 ss;
u16 ds;
u16 es;
u16 fs;
u16 gs;
u16 gdt_fill;
struct desc_ptr gdtr;
char idt_fill[6];
struct desc_ptr idtr;
u64 gsbase;
u64 efer;
u64 pat;
};
static struct hv_crash_ctxt hv_crash_ctxt;
/* Shared hypervisor page that contains crash dump area we peek into.
* NB: windbg looks for "hv_cda" symbol so don't change it.
*/
static struct hv_crashdump_area *hv_cda;
static u32 trampoline_pa, devirt_arg;
static atomic_t crash_cpus_wait;
static void *hv_crash_ptpgs[4];
static bool hv_has_crashed, lx_has_crashed;
static void __noreturn hv_panic_timeout_reboot(void)
{
#define PANIC_TIMER_STEP 100
if (panic_timeout > 0) {
int i;
for (i = 0; i < panic_timeout * 1000; i += PANIC_TIMER_STEP)
mdelay(PANIC_TIMER_STEP);
}
if (panic_timeout)
native_wrmsrq(HV_X64_MSR_RESET, 1); /* get hyp to reboot */
for (;;)
cpu_relax();
}
static void hv_crash_restore_tss(void)
{
load_TR_desc();
}
static void hv_crash_clear_kernpt(void)
{
pgd_t *pgd;
p4d_t *p4d;
/* Clear entry so it's not confusing to someone looking at the core */
pgd = pgd_offset_k(trampoline_pa);
p4d = p4d_offset(pgd, trampoline_pa);
native_p4d_clear(p4d);
}
static void __noreturn hv_crash_handle(void)
{
hv_crash_restore_tss();
hv_crash_clear_kernpt();
/* we are now fully in devirtualized normal kernel mode */
__crash_kexec(NULL);
hv_panic_timeout_reboot();
}
/*
* __naked functions do not permit function calls, not even to __always_inline
* functions that only contain asm() blocks themselves. So use a macro instead.
*/
#define hv_wrmsr(msr, val) \
asm volatile("wrmsr" :: "c"(msr), "a"((u32)val), "d"((u32)(val >> 32)) : "memory")
/*
* This is the C entry point from the asm glue code after the disable hypercall.
Annotation
- Immediate include surface: `linux/delay.h`, `linux/kexec.h`, `linux/crash_dump.h`, `linux/panic.h`, `asm/apic.h`, `asm/desc.h`, `asm/page.h`, `asm/pgalloc.h`.
- Detected declarations: `struct hv_crash_ctxt`, `struct hv_gdtreg_32`, `struct hv_crash_tramp_gdt`, `struct hv_cs_jmptgt`, `struct hv_crash_tramp_data`, `function hv_panic_timeout_reboot`, `function hv_crash_restore_tss`, `function hv_crash_clear_kernpt`, `function hv_crash_handle`, `function asm`.
- Atlas domain: Architecture Layer / arch/x86.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.