arch/arm64/kvm/hyp/nvhe/trace.c
Source file repositories/reference/linux-study-clean/arch/arm64/kvm/hyp/nvhe/trace.c
File Facts
- System
- Linux kernel
- Corpus path
arch/arm64/kvm/hyp/nvhe/trace.c- Extension
.c- Size
- 7044 bytes
- Lines
- 312
- Domain
- Architecture Layer
- Bucket
- arch/arm64
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
nvhe/clock.hnvhe/mem_protect.hnvhe/mm.hnvhe/trace.hasm/percpu.hasm/kvm_mmu.hasm/local.hsimple_ring_buffer.c
Detected Declarations
function hyp_trace_buffer_loadedfunction tracing_commit_entryfunction __admit_host_memfunction __release_host_memfunction hyp_trace_buffer_load_bpage_backingfunction hyp_trace_buffer_unload_bpage_backingfunction __unpin_shared_pagefunction hyp_trace_buffer_unloadfunction hyp_trace_buffer_loadfunction hyp_trace_desc_is_validfunction for_each_ring_buffer_descfunction __tracing_loadfunction __tracing_unloadfunction __tracing_enablefunction __tracing_swap_readerfunction __tracing_update_clockfunction __tracing_reset
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2025 Google LLC
* Author: Vincent Donnefort <vdonnefort@google.com>
*/
#include <nvhe/clock.h>
#include <nvhe/mem_protect.h>
#include <nvhe/mm.h>
#include <nvhe/trace.h>
#include <asm/percpu.h>
#include <asm/kvm_mmu.h>
#include <asm/local.h>
#include "simple_ring_buffer.c"
static DEFINE_PER_CPU(struct simple_rb_per_cpu, __simple_rbs);
static struct hyp_trace_buffer {
struct simple_rb_per_cpu __percpu *simple_rbs;
void *bpages_backing_start;
size_t bpages_backing_size;
hyp_spinlock_t lock;
} trace_buffer = {
.simple_rbs = &__simple_rbs,
.lock = __HYP_SPIN_LOCK_UNLOCKED,
};
static bool hyp_trace_buffer_loaded(struct hyp_trace_buffer *trace_buffer)
{
return trace_buffer->bpages_backing_size > 0;
}
void *tracing_reserve_entry(unsigned long length)
{
return simple_ring_buffer_reserve(this_cpu_ptr(trace_buffer.simple_rbs), length,
trace_clock());
}
void tracing_commit_entry(void)
{
simple_ring_buffer_commit(this_cpu_ptr(trace_buffer.simple_rbs));
}
static int __admit_host_mem(void *start, u64 size)
{
if (!PAGE_ALIGNED(start) || !PAGE_ALIGNED(size) || !size)
return -EINVAL;
if (!is_protected_kvm_enabled())
return 0;
return __pkvm_host_donate_hyp(hyp_virt_to_pfn(start), size >> PAGE_SHIFT);
}
static void __release_host_mem(void *start, u64 size)
{
if (!is_protected_kvm_enabled())
return;
WARN_ON(__pkvm_hyp_donate_host(hyp_virt_to_pfn(start), size >> PAGE_SHIFT));
}
static int hyp_trace_buffer_load_bpage_backing(struct hyp_trace_buffer *trace_buffer,
struct hyp_trace_desc *desc)
{
void *start = (void *)kern_hyp_va(desc->bpages_backing_start);
size_t size = desc->bpages_backing_size;
int ret;
ret = __admit_host_mem(start, size);
if (ret)
return ret;
memset(start, 0, size);
trace_buffer->bpages_backing_start = start;
trace_buffer->bpages_backing_size = size;
return 0;
}
static void hyp_trace_buffer_unload_bpage_backing(struct hyp_trace_buffer *trace_buffer)
{
void *start = trace_buffer->bpages_backing_start;
size_t size = trace_buffer->bpages_backing_size;
if (!size)
return;
Annotation
- Immediate include surface: `nvhe/clock.h`, `nvhe/mem_protect.h`, `nvhe/mm.h`, `nvhe/trace.h`, `asm/percpu.h`, `asm/kvm_mmu.h`, `asm/local.h`, `simple_ring_buffer.c`.
- Detected declarations: `function hyp_trace_buffer_loaded`, `function tracing_commit_entry`, `function __admit_host_mem`, `function __release_host_mem`, `function hyp_trace_buffer_load_bpage_backing`, `function hyp_trace_buffer_unload_bpage_backing`, `function __unpin_shared_page`, `function hyp_trace_buffer_unload`, `function hyp_trace_buffer_load`, `function hyp_trace_desc_is_valid`.
- Atlas domain: Architecture Layer / arch/arm64.
- Implementation status: source 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.