tools/testing/selftests/kvm/x86/hwcr_msr_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/hwcr_msr_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/hwcr_msr_test.c- Extension
.c- Size
- 1124 bytes
- Lines
- 51
- 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
sys/ioctl.htest_util.hkvm_util.hvmx.h
Detected Declarations
function Copyrightfunction main
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2023, Google LLC.
*/
#include <sys/ioctl.h>
#include "test_util.h"
#include "kvm_util.h"
#include "vmx.h"
void test_hwcr_bit(struct kvm_vcpu *vcpu, unsigned int bit)
{
const u64 ignored = BIT_ULL(3) | BIT_ULL(6) | BIT_ULL(8);
u64 valid = BIT_ULL(18) | BIT_ULL(24);
u64 val = BIT_ULL(bit);
u64 actual;
u64 legal;
int r;
if (kvm_cpu_has(X86_FEATURE_GP_ON_USER_CPUID))
valid |= BIT_ULL(35);
legal = ignored | valid;
r = _vcpu_set_msr(vcpu, MSR_K7_HWCR, val);
TEST_ASSERT(val & ~legal ? !r : r == 1,
"Expected KVM_SET_MSRS(MSR_K7_HWCR) = 0x%lx to %s",
val, val & ~legal ? "fail" : "succeed");
actual = vcpu_get_msr(vcpu, MSR_K7_HWCR);
TEST_ASSERT(actual == (val & valid),
"Bit %u: unexpected HWCR 0x%lx; expected 0x%lx",
bit, actual, (val & valid));
vcpu_set_msr(vcpu, MSR_K7_HWCR, 0);
}
int main(int argc, char *argv[])
{
struct kvm_vm *vm;
struct kvm_vcpu *vcpu;
unsigned int bit;
vm = vm_create_with_one_vcpu(&vcpu, NULL);
for (bit = 0; bit < BITS_PER_LONG; bit++)
test_hwcr_bit(vcpu, bit);
kvm_vm_free(vm);
}
Annotation
- Immediate include surface: `sys/ioctl.h`, `test_util.h`, `kvm_util.h`, `vmx.h`.
- Detected declarations: `function Copyright`, `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.