tools/testing/selftests/kvm/x86/sync_regs_test.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/sync_regs_test.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/sync_regs_test.c- Extension
.c- Size
- 11261 bytes
- Lines
- 411
- 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.hsys/ioctl.hpthread.hkvm_test_harness.htest_util.hkvm_util.hprocessor.h
Detected Declarations
function guest_codefunction compare_regsfunction compare_sregsfunction race_sync_regsfunction main
Annotated Snippet
if (racer == race_sregs_cr4) {
tr = (struct kvm_translation) { .linear_address = 0 };
__vcpu_ioctl(vcpu, KVM_TRANSLATE, &tr);
}
}
TEST_ASSERT_EQ(pthread_cancel(thread), 0);
TEST_ASSERT_EQ(pthread_join(thread, NULL), 0);
kvm_x86_state_cleanup(state);
}
KVM_ONE_VCPU_TEST(sync_regs_test, read_invalid, guest_code)
{
struct kvm_run *run = vcpu->run;
int rv;
/* Request reading invalid register set from VCPU. */
run->kvm_valid_regs = INVALID_SYNC_FIELD;
rv = _vcpu_run(vcpu);
TEST_ASSERT(rv < 0 && errno == EINVAL,
"Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d",
rv);
run->kvm_valid_regs = 0;
run->kvm_valid_regs = INVALID_SYNC_FIELD | TEST_SYNC_FIELDS;
rv = _vcpu_run(vcpu);
TEST_ASSERT(rv < 0 && errno == EINVAL,
"Invalid kvm_valid_regs did not cause expected KVM_RUN error: %d",
rv);
run->kvm_valid_regs = 0;
}
KVM_ONE_VCPU_TEST(sync_regs_test, set_invalid, guest_code)
{
struct kvm_run *run = vcpu->run;
int rv;
/* Request setting invalid register set into VCPU. */
run->kvm_dirty_regs = INVALID_SYNC_FIELD;
rv = _vcpu_run(vcpu);
TEST_ASSERT(rv < 0 && errno == EINVAL,
"Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d",
rv);
run->kvm_dirty_regs = 0;
run->kvm_dirty_regs = INVALID_SYNC_FIELD | TEST_SYNC_FIELDS;
rv = _vcpu_run(vcpu);
TEST_ASSERT(rv < 0 && errno == EINVAL,
"Invalid kvm_dirty_regs did not cause expected KVM_RUN error: %d",
rv);
run->kvm_dirty_regs = 0;
}
KVM_ONE_VCPU_TEST(sync_regs_test, req_and_verify_all_valid, guest_code)
{
struct kvm_run *run = vcpu->run;
struct kvm_vcpu_events events;
struct kvm_sregs sregs;
struct kvm_regs regs;
/* Request and verify all valid register sets. */
run->kvm_valid_regs = TEST_SYNC_FIELDS;
vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
vcpu_regs_get(vcpu, ®s);
compare_regs(®s, &run->s.regs.regs);
vcpu_sregs_get(vcpu, &sregs);
compare_sregs(&sregs, &run->s.regs.sregs);
vcpu_events_get(vcpu, &events);
compare_vcpu_events(&events, &run->s.regs.events);
}
KVM_ONE_VCPU_TEST(sync_regs_test, set_and_verify_various, guest_code)
{
struct kvm_run *run = vcpu->run;
struct kvm_vcpu_events events;
struct kvm_sregs sregs;
struct kvm_regs regs;
/* Run once to get register set */
run->kvm_valid_regs = TEST_SYNC_FIELDS;
vcpu_run(vcpu);
TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO);
/* Set and verify various register values. */
run->s.regs.regs.rbx = 0xBAD1DEA;
Annotation
- Immediate include surface: `fcntl.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/ioctl.h`, `pthread.h`, `kvm_test_harness.h`, `test_util.h`.
- Detected declarations: `function guest_code`, `function compare_regs`, `function compare_sregs`, `function race_sync_regs`, `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.