tools/testing/selftests/kvm/memslot_perf_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/memslot_perf_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/memslot_perf_test.c- Extension
.c- Size
- 30113 bytes
- Lines
- 1153
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- 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
pthread.hsched.hsemaphore.hstdatomic.hstdbool.hstdint.hstdio.hstdlib.hstring.htime.hunistd.hlinux/compiler.hlinux/sizes.htest_util.hkvm_syscalls.hkvm_util.hprocessor.hucall_common.h
Detected Declarations
struct vm_datastruct sync_areastruct test_datastruct test_argsstruct test_resultfunction check_mmio_accessfunction wait_for_vcpufunction vm_slot2gpafunction check_slot_pagesfunction get_max_slotsfunction prepare_vmfunction launch_vmfunction free_vmfunction wait_guest_exitfunction let_guest_runfunction guest_spin_until_startfunction make_guest_exitfunction _guest_should_exitfunction alarmfunction guest_perform_syncfunction guest_code_test_memslot_movefunction guest_code_test_memslot_mapfunction guest_code_test_memslot_unmapfunction guest_code_test_memslot_rwfunction test_memslot_move_preparefunction test_memslot_move_prepare_activefunction test_memslot_move_prepare_inactivefunction test_memslot_move_loopfunction test_memslot_do_unmapfunction test_memslot_map_unmap_checkfunction test_memslot_map_loopfunction test_memslot_unmap_loop_commonfunction test_memslot_unmap_loopfunction test_memslot_unmap_loop_chunkedfunction test_memslot_rw_loopfunction test_executefunction helpfunction check_memory_sizesfunction parse_argsfunction test_loopfunction main
Annotated Snippet
struct vm_data {
struct kvm_vm *vm;
struct kvm_vcpu *vcpu;
pthread_t vcpu_thread;
u32 nslots;
u64 npages;
u64 pages_per_slot;
void **hva_slots;
bool mmio_ok;
u64 mmio_gpa_min;
u64 mmio_gpa_max;
};
struct sync_area {
u32 guest_page_size;
atomic_bool start_flag;
atomic_bool exit_flag;
atomic_bool sync_flag;
void *move_area_ptr;
};
/*
* Technically, we need also for the atomic bool to be address-free, which
* is recommended, but not strictly required, by C11 for lockless
* implementations.
* However, in practice both GCC and Clang fulfill this requirement on
* all KVM-supported platforms.
*/
static_assert(ATOMIC_BOOL_LOCK_FREE == 2, "atomic bool is not lockless");
static int wait_timeout = 10;
static sem_t vcpu_ready;
static bool map_unmap_verify;
#ifdef __x86_64__
static bool disable_slot_zap_quirk;
#endif
static bool verbose;
#define pr_info_v(...) \
do { \
if (verbose) \
pr_info(__VA_ARGS__); \
} while (0)
static void check_mmio_access(struct vm_data *data, struct kvm_run *run)
{
TEST_ASSERT(data->mmio_ok, "Unexpected mmio exit");
TEST_ASSERT(run->mmio.is_write, "Unexpected mmio read");
TEST_ASSERT(run->mmio.len == 8,
"Unexpected exit mmio size = %u", run->mmio.len);
TEST_ASSERT(run->mmio.phys_addr >= data->mmio_gpa_min &&
run->mmio.phys_addr <= data->mmio_gpa_max,
"Unexpected exit mmio address = 0x%llx",
run->mmio.phys_addr);
}
static void *vcpu_worker(void *__data)
{
struct vm_data *data = __data;
struct kvm_vcpu *vcpu = data->vcpu;
struct kvm_run *run = vcpu->run;
struct ucall uc;
while (1) {
vcpu_run(vcpu);
switch (get_ucall(vcpu, &uc)) {
case UCALL_SYNC:
TEST_ASSERT(uc.args[1] == 0,
"Unexpected sync ucall, got %lx",
(ulong)uc.args[1]);
sem_post(&vcpu_ready);
continue;
case UCALL_NONE:
if (run->exit_reason == KVM_EXIT_MMIO)
check_mmio_access(data, run);
else
goto done;
break;
case UCALL_ABORT:
REPORT_GUEST_ASSERT(uc);
break;
case UCALL_DONE:
goto done;
default:
TEST_FAIL("Unknown ucall %lu", uc.cmd);
}
}
Annotation
- Immediate include surface: `pthread.h`, `sched.h`, `semaphore.h`, `stdatomic.h`, `stdbool.h`, `stdint.h`, `stdio.h`, `stdlib.h`.
- Detected declarations: `struct vm_data`, `struct sync_area`, `struct test_data`, `struct test_args`, `struct test_result`, `function check_mmio_access`, `function wait_for_vcpu`, `function vm_slot2gpa`, `function check_slot_pages`, `function get_max_slots`.
- Atlas domain: Support Tooling And Documentation / tools.
- 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.