tools/testing/selftests/kvm/x86/sev_init2_tests.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/sev_init2_tests.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/sev_init2_tests.c- Extension
.c- Size
- 4288 bytes
- Lines
- 164
- 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
linux/kvm.hlinux/psp-sev.hstdio.hsys/ioctl.hstdlib.herrno.hpthread.htest_util.hkvm_util.hprocessor.hsvm_util.hkselftest.h
Detected Declarations
function __sev_ioctlfunction test_init2function test_init2_invalidfunction test_vm_typesfunction test_init2function test_init2_invalidfunction test_init2_invalidfunction test_flagsfunction test_init2_invalidfunction test_featuresfunction main
Annotated Snippet
test_init2(KVM_X86_SEV_ES_VM, &(struct kvm_sev_init){});
if (have_snp)
test_init2(KVM_X86_SNP_VM, &(struct kvm_sev_init){});
test_init2_invalid(0, &(struct kvm_sev_init){},
"VM type is KVM_X86_DEFAULT_VM");
if (kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_VM))
test_init2_invalid(KVM_X86_SW_PROTECTED_VM, &(struct kvm_sev_init){},
"VM type is KVM_X86_SW_PROTECTED_VM");
}
void test_flags(u32 vm_type)
{
int i;
for (i = 0; i < 32; i++)
test_init2_invalid(vm_type,
&(struct kvm_sev_init){ .flags = BIT(i) },
"invalid flag");
}
void test_features(u32 vm_type, u64 supported_features)
{
int i;
for (i = 0; i < 64; i++) {
if (!(supported_features & BIT_ULL(i)))
test_init2_invalid(vm_type,
&(struct kvm_sev_init){ .vmsa_features = BIT_ULL(i) },
"unknown feature");
else if (KNOWN_FEATURES & BIT_ULL(i))
test_init2(vm_type,
&(struct kvm_sev_init){ .vmsa_features = BIT_ULL(i) });
}
}
int main(int argc, char *argv[])
{
int kvm_fd = open_kvm_dev_path_or_exit();
bool have_sev;
TEST_REQUIRE(__kvm_has_device_attr(kvm_fd, KVM_X86_GRP_SEV,
KVM_X86_SEV_VMSA_FEATURES) == 0);
kvm_device_attr_get(kvm_fd, KVM_X86_GRP_SEV,
KVM_X86_SEV_VMSA_FEATURES,
&supported_vmsa_features);
have_sev = kvm_cpu_has(X86_FEATURE_SEV);
TEST_ASSERT(have_sev == !!(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SEV_VM)),
"sev: KVM_CAP_VM_TYPES (%x) does not match cpuid (checking %x)",
kvm_check_cap(KVM_CAP_VM_TYPES), 1 << KVM_X86_SEV_VM);
TEST_REQUIRE(kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SEV_VM));
have_sev_es = kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SEV_ES_VM);
TEST_ASSERT(!have_sev_es || kvm_cpu_has(X86_FEATURE_SEV_ES),
"sev-es: SEV_ES_VM supported without SEV_ES in CPUID");
have_snp = kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SNP_VM);
TEST_ASSERT(!have_snp || kvm_cpu_has(X86_FEATURE_SEV_SNP),
"sev-snp: SNP_VM supported without SEV_SNP in CPUID");
test_vm_types();
test_flags(KVM_X86_SEV_VM);
if (have_sev_es)
test_flags(KVM_X86_SEV_ES_VM);
if (have_snp)
test_flags(KVM_X86_SNP_VM);
test_features(KVM_X86_SEV_VM, 0);
if (have_sev_es)
test_features(KVM_X86_SEV_ES_VM, supported_vmsa_features);
if (have_snp)
test_features(KVM_X86_SNP_VM, supported_vmsa_features);
return 0;
}
Annotation
- Immediate include surface: `linux/kvm.h`, `linux/psp-sev.h`, `stdio.h`, `sys/ioctl.h`, `stdlib.h`, `errno.h`, `pthread.h`, `test_util.h`.
- Detected declarations: `function __sev_ioctl`, `function test_init2`, `function test_init2_invalid`, `function test_vm_types`, `function test_init2`, `function test_init2_invalid`, `function test_init2_invalid`, `function test_flags`, `function test_init2_invalid`, `function test_features`.
- 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.