arch/arm64/kvm/hyp_trace.c
Source file repositories/reference/linux-study-clean/arch/arm64/kvm/hyp_trace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kvm/hyp_trace.c- Extension
.c- Size
- 11128 bytes
- Lines
- 446
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- Inferred role
- Architecture Layer: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- 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/cpumask.hlinux/trace_remote.hlinux/tracefs.hlinux/simple_ring_buffer.hasm/arch_timer.hasm/kvm_host.hasm/kvm_hyptrace.hasm/kvm_mmu.hhyp_trace.hasm/kvm_define_hypevents.h
Detected Declarations
function __hyp_clock_workfunction hyp_trace_clock_enablefunction __map_hypfunction __share_pagefunction __unshare_pagefunction hyp_trace_buffer_alloc_bpages_backingfunction hyp_trace_buffer_free_bpages_backingfunction hyp_trace_buffer_unshare_hypfunction for_each_ring_buffer_descfunction hyp_trace_buffer_share_hypfunction for_each_ring_buffer_descfunction hyp_trace_unloadfunction hyp_trace_enable_tracingfunction hyp_trace_swap_reader_pagefunction hyp_trace_resetfunction hyp_trace_enable_eventfunction hyp_trace_clock_showfunction hyp_trace_write_event_writefunction hyp_trace_init_tracefsfunction hyp_trace_init_eventsfunction kvm_hyp_trace_initfunction for_each_possible_cpu
Annotated Snippet
static const struct file_operations hyp_trace_write_event_fops = {
.write = hyp_trace_write_event_write,
};
static int hyp_trace_init_tracefs(struct dentry *d, void *priv)
{
if (!tracefs_create_file("write_event", 0200, d, NULL, &hyp_trace_write_event_fops))
return -ENOMEM;
return tracefs_create_file("trace_clock", 0440, d, NULL, &hyp_trace_clock_fops) ?
0 : -ENOMEM;
}
static struct trace_remote_callbacks trace_remote_callbacks = {
.init = hyp_trace_init_tracefs,
.load_trace_buffer = hyp_trace_load,
.unload_trace_buffer = hyp_trace_unload,
.enable_tracing = hyp_trace_enable_tracing,
.swap_reader_page = hyp_trace_swap_reader_page,
.reset = hyp_trace_reset,
.enable_event = hyp_trace_enable_event,
};
static const char *__hyp_enter_exit_reason_str(u8 reason);
#include <asm/kvm_define_hypevents.h>
static const char *__hyp_enter_exit_reason_str(u8 reason)
{
static const char strs[][12] = {
"smc",
"hvc",
"psci",
"host_abort",
"guest_exit",
"eret_host",
"eret_guest",
"unknown",
};
return strs[min(reason, HYP_REASON_UNKNOWN)];
}
static void __init hyp_trace_init_events(void)
{
struct hyp_event_id *hyp_event_id = __hyp_event_ids_start;
struct remote_event *event = __hyp_events_start;
int id = 0;
/* Events on both sides hypervisor are sorted */
for (; event < __hyp_events_end; event++, hyp_event_id++, id++)
event->id = hyp_event_id->id = id;
}
int __init kvm_hyp_trace_init(void)
{
int cpu;
if (is_kernel_in_hyp_mode())
return 0;
for_each_possible_cpu(cpu) {
const struct arch_timer_erratum_workaround *wa =
per_cpu(timer_unstable_counter_workaround, cpu);
if (IS_ENABLED(CONFIG_ARM_ARCH_TIMER_OOL_WORKAROUND) &&
wa && wa->read_cntvct_el0) {
pr_warn("hyp trace can't handle CNTVCT workaround '%s'\n", wa->desc);
return -EOPNOTSUPP;
}
}
hyp_trace_init_events();
return trace_remote_register("hypervisor", &trace_remote_callbacks, &trace_buffer,
__hyp_events_start, __hyp_events_end - __hyp_events_start);
}
Annotation
- Immediate include surface: `linux/cpumask.h`, `linux/trace_remote.h`, `linux/tracefs.h`, `linux/simple_ring_buffer.h`, `asm/arch_timer.h`, `asm/kvm_host.h`, `asm/kvm_hyptrace.h`, `asm/kvm_mmu.h`.
- Detected declarations: `function __hyp_clock_work`, `function hyp_trace_clock_enable`, `function __map_hyp`, `function __share_page`, `function __unshare_page`, `function hyp_trace_buffer_alloc_bpages_backing`, `function hyp_trace_buffer_free_bpages_backing`, `function hyp_trace_buffer_unshare_hyp`, `function for_each_ring_buffer_desc`, `function hyp_trace_buffer_share_hyp`.
- Atlas domain: Architecture Layer / arch/arm64.
- Implementation status: pattern 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.