tools/testing/selftests/kvm/x86/set_boot_cpu_id.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/kvm/x86/set_boot_cpu_id.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/kvm/x86/set_boot_cpu_id.c- Extension
.c- Size
- 3041 bytes
- Lines
- 147
- 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.htest_util.hkvm_util.hprocessor.hapic.h
Detected Declarations
function Copyrightfunction guest_not_bsp_vcpufunction test_set_invalid_bspfunction test_set_bsp_busyfunction run_vcpufunction run_vm_bspfunction check_set_bsp_busyfunction main
Annotated Snippet
switch (get_ucall(vcpu, &uc)) {
case UCALL_SYNC:
TEST_ASSERT(!strcmp((const char *)uc.args[0], "hello") &&
uc.args[1] == stage + 1,
"Stage %d: Unexpected register values vmexit, got %lx",
stage + 1, (ulong)uc.args[1]);
test_set_bsp_busy(vcpu, "while running vm");
break;
case UCALL_DONE:
TEST_ASSERT(stage == 1,
"Expected GUEST_DONE in stage 2, got stage %d",
stage);
break;
case UCALL_ABORT:
REPORT_GUEST_ASSERT(uc);
default:
TEST_ASSERT(false, "Unexpected exit: %s",
exit_reason_str(vcpu->run->exit_reason));
}
}
}
static struct kvm_vm *create_vm(u32 nr_vcpus, u32 bsp_vcpu_id,
struct kvm_vcpu *vcpus[])
{
struct kvm_vm *vm;
u32 i;
vm = vm_create(nr_vcpus);
test_set_invalid_bsp(vm);
vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(unsigned long)bsp_vcpu_id);
for (i = 0; i < nr_vcpus; i++)
vcpus[i] = vm_vcpu_add(vm, i, i == bsp_vcpu_id ? guest_bsp_vcpu :
guest_not_bsp_vcpu);
return vm;
}
static void run_vm_bsp(u32 bsp_vcpu_id)
{
struct kvm_vcpu *vcpus[2];
struct kvm_vm *vm;
vm = create_vm(ARRAY_SIZE(vcpus), bsp_vcpu_id, vcpus);
run_vcpu(vcpus[0]);
run_vcpu(vcpus[1]);
kvm_vm_free(vm);
}
static void check_set_bsp_busy(void)
{
struct kvm_vcpu *vcpus[2];
struct kvm_vm *vm;
vm = create_vm(ARRAY_SIZE(vcpus), 0, vcpus);
test_set_bsp_busy(vcpus[1], "after adding vcpu");
run_vcpu(vcpus[0]);
run_vcpu(vcpus[1]);
test_set_bsp_busy(vcpus[1], "to a terminated vcpu");
kvm_vm_free(vm);
}
int main(int argc, char *argv[])
{
TEST_REQUIRE(kvm_has_cap(KVM_CAP_SET_BOOT_CPU_ID));
run_vm_bsp(0);
run_vm_bsp(1);
run_vm_bsp(0);
check_set_bsp_busy();
}
Annotation
- Immediate include surface: `fcntl.h`, `stdio.h`, `stdlib.h`, `string.h`, `sys/ioctl.h`, `test_util.h`, `kvm_util.h`, `processor.h`.
- Detected declarations: `function Copyright`, `function guest_not_bsp_vcpu`, `function test_set_invalid_bsp`, `function test_set_bsp_busy`, `function run_vcpu`, `function run_vm_bsp`, `function check_set_bsp_busy`, `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.