Skip to content

Commit 438a496

Browse files
minipli-osssean-jc
authored andcommitted
KVM: selftests: Test vCPU boot IDs above 2^32 and MAX_VCPU_ID
The KVM_SET_BOOT_CPU_ID ioctl missed to reject invalid vCPU IDs. Verify this no longer works and gets rejected with an appropriate error code. Signed-off-by: Mathias Krause <[email protected]> Link: https://lore.kernel.org/r/[email protected] [sean: add test for MAX_VCPU_ID+1, always do negative test] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 4b451a5 commit 438a496

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

tools/testing/selftests/kvm/x86_64/set_boot_cpu_id.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ static void guest_not_bsp_vcpu(void *arg)
3333
GUEST_DONE();
3434
}
3535

36+
static void test_set_invalid_bsp(struct kvm_vm *vm)
37+
{
38+
unsigned long max_vcpu_id = vm_check_cap(vm, KVM_CAP_MAX_VCPU_ID);
39+
int r;
40+
41+
if (max_vcpu_id) {
42+
r = __vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(max_vcpu_id + 1));
43+
TEST_ASSERT(r == -1 && errno == EINVAL, "BSP with ID > MAX should fail");
44+
}
45+
46+
r = __vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(1L << 32));
47+
TEST_ASSERT(r == -1 && errno == EINVAL, "BSP with ID[63:32]!=0 should fail");
48+
}
49+
3650
static void test_set_bsp_busy(struct kvm_vcpu *vcpu, const char *msg)
3751
{
3852
int r = __vm_ioctl(vcpu->vm, KVM_SET_BOOT_CPU_ID,
@@ -80,6 +94,8 @@ static struct kvm_vm *create_vm(uint32_t nr_vcpus, uint32_t bsp_vcpu_id,
8094

8195
vm = vm_create(nr_vcpus);
8296

97+
test_set_invalid_bsp(vm);
98+
8399
vm_ioctl(vm, KVM_SET_BOOT_CPU_ID, (void *)(unsigned long)bsp_vcpu_id);
84100

85101
for (i = 0; i < nr_vcpus; i++)

0 commit comments

Comments
 (0)