tools/testing/selftests/kvm/x86/svm_nested_pat_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/svm_nested_pat_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/svm_nested_pat_test.c- Extension
.c- Size
- 5396 bytes
- Lines
- 197
- 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
fcntl.hstdio.hstdlib.hstring.htest_util.hkvm_util.hprocessor.hsvm_util.h
Detected Declarations
function l2_guest_codefunction l1_guest_codefunction l1_guest_code_invalid_gpatfunction run_testfunction main
Annotated Snippet
if (npt_enabled) {
GUEST_ASSERT_EQ(vmcb->save.g_pat, L2_PAT_MODIFIED);
GUEST_ASSERT_EQ(rdmsr(MSR_IA32_CR_PAT), L1_PAT_VALUE);
} else {
GUEST_ASSERT_EQ(rdmsr(MSR_IA32_CR_PAT), L2_PAT_MODIFIED);
}
vmcb->save.rip += 3; /* skip over VMMCALL */
}
GUEST_DONE();
}
static void l1_guest_code_invalid_gpat(struct svm_test_data *svm)
{
unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE];
struct vmcb *vmcb = svm->vmcb;
/* VMRUN should fail without running L2 */
generic_svm_setup(svm, NULL, &l2_guest_stack[L2_GUEST_STACK_SIZE]);
vmcb->save.g_pat = INVALID_PAT_VALUE;
run_guest(vmcb, svm->vmcb_gpa);
GUEST_ASSERT_EQ(vmcb->control.exit_code, SVM_EXIT_ERR);
GUEST_DONE();
}
static void run_test(void *guest_code, bool do_save_restore, int nr_iters)
{
struct kvm_x86_state *state;
struct kvm_vcpu *vcpu;
struct kvm_vm *vm;
struct ucall uc;
gva_t svm_gva;
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2,
KVM_X86_QUIRK_NESTED_SVM_SHARED_PAT);
if (npt_enabled)
vm_enable_npt(vm);
vcpu_alloc_svm(vm, &svm_gva);
if (npt_enabled)
tdp_identity_map_default_memslots(vm);
vcpu_args_set(vcpu, 1, svm_gva);
nr_iterations = nr_iters;
sync_global_to_guest(vm, npt_enabled);
sync_global_to_guest(vm, nr_iterations);
for (;;) {
vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
switch (get_ucall(vcpu, &uc)) {
case UCALL_ABORT:
REPORT_GUEST_ASSERT(uc);
/* NOT REACHED */
case UCALL_SYNC:
if (do_save_restore) {
state = vcpu_save_state(vcpu);
kvm_vm_release(vm);
vcpu = vm_recreate_with_one_vcpu(vm);
vm_enable_cap(vm, KVM_CAP_DISABLE_QUIRKS2,
KVM_X86_QUIRK_NESTED_SVM_SHARED_PAT);
vcpu_load_state(vcpu, state);
kvm_x86_state_cleanup(state);
}
break;
case UCALL_DONE:
kvm_vm_free(vm);
return;
default:
TEST_FAIL("Unknown ucall %lu", uc.cmd);
}
}
}
#define gpat_test(test_name, guest_code, npt_setting) \
do { \
npt_setting; \
\
if (npt_enabled && !kvm_cpu_has(X86_FEATURE_NPT)) { \
pr_info("Skipping: " test_name " (no NPT support)\n"); \
break; \
} \
\
Annotation
- Immediate include surface: `fcntl.h`, `stdio.h`, `stdlib.h`, `string.h`, `test_util.h`, `kvm_util.h`, `processor.h`, `svm_util.h`.
- Detected declarations: `function l2_guest_code`, `function l1_guest_code`, `function l1_guest_code_invalid_gpat`, `function run_test`, `function main`.
- 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.