tools/testing/selftests/kvm/x86/svm_nested_vmcb12_gpa.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/svm_nested_vmcb12_gpa.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/svm_nested_vmcb12_gpa.c- Extension
.c- Size
- 4211 bytes
- Lines
- 177
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kvm_util.hvmx.hsvm_util.hkselftest.hkvm_test_harness.htest_util.h
Detected Declarations
function guest_gp_handlerfunction l2_codefunction l1_vmrunfunction l1_vmloadfunction l1_vmsavefunction l1_vmexitfunction unmappable_gpafunction hash_for_eachfunction test_invalid_vmcb12function test_unmappable_vmcb12function test_unmappable_vmcb12_vmexitfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) 2026, Google LLC.
*/
#include "kvm_util.h"
#include "vmx.h"
#include "svm_util.h"
#include "kselftest.h"
#include "kvm_test_harness.h"
#include "test_util.h"
#define L2_GUEST_STACK_SIZE 64
#define SYNC_GP 101
#define SYNC_L2_STARTED 102
static unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
static void guest_gp_handler(struct ex_regs *regs)
{
GUEST_SYNC(SYNC_GP);
}
static void l2_code(void)
{
GUEST_SYNC(SYNC_L2_STARTED);
vmcall();
}
static void l1_vmrun(struct svm_test_data *svm, gpa_t gpa)
{
generic_svm_setup(svm, l2_code, &l2_guest_stack[L2_GUEST_STACK_SIZE]);
asm volatile ("vmrun %[gpa]" : : [gpa] "a" (gpa) : "memory");
}
static void l1_vmload(struct svm_test_data *svm, gpa_t gpa)
{
generic_svm_setup(svm, l2_code, &l2_guest_stack[L2_GUEST_STACK_SIZE]);
asm volatile ("vmload %[gpa]" : : [gpa] "a" (gpa) : "memory");
}
static void l1_vmsave(struct svm_test_data *svm, gpa_t gpa)
{
generic_svm_setup(svm, l2_code, &l2_guest_stack[L2_GUEST_STACK_SIZE]);
asm volatile ("vmsave %[gpa]" : : [gpa] "a" (gpa) : "memory");
}
static void l1_vmexit(struct svm_test_data *svm, gpa_t gpa)
{
generic_svm_setup(svm, l2_code, &l2_guest_stack[L2_GUEST_STACK_SIZE]);
run_guest(svm->vmcb, svm->vmcb_gpa);
GUEST_ASSERT(svm->vmcb->control.exit_code == SVM_EXIT_VMMCALL);
GUEST_DONE();
}
static u64 unmappable_gpa(struct kvm_vcpu *vcpu)
{
struct userspace_mem_region *region;
u64 region_gpa_end, vm_gpa_end = 0;
int i;
hash_for_each(vcpu->vm->regions.slot_hash, i, region, slot_node) {
region_gpa_end = region->region.guest_phys_addr + region->region.memory_size;
vm_gpa_end = max(vm_gpa_end, region_gpa_end);
}
return vm_gpa_end;
}
static void test_invalid_vmcb12(struct kvm_vcpu *vcpu)
{
gva_t nested_gva = 0;
struct ucall uc;
vm_install_exception_handler(vcpu->vm, GP_VECTOR, guest_gp_handler);
vcpu_alloc_svm(vcpu->vm, &nested_gva);
vcpu_args_set(vcpu, 2, nested_gva, -1ULL);
vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
TEST_ASSERT_EQ(get_ucall(vcpu, &uc), UCALL_SYNC);
TEST_ASSERT_EQ(uc.args[1], SYNC_GP);
}
Annotation
- Immediate include surface: `kvm_util.h`, `vmx.h`, `svm_util.h`, `kselftest.h`, `kvm_test_harness.h`, `test_util.h`.
- Detected declarations: `function guest_gp_handler`, `function l2_code`, `function l1_vmrun`, `function l1_vmload`, `function l1_vmsave`, `function l1_vmexit`, `function unmappable_gpa`, `function hash_for_each`, `function test_invalid_vmcb12`, `function test_unmappable_vmcb12`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
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.