1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2018, Google LLC.
7 * This is a regression test for the bug fixed by the following commit:
8 * d3802286fa0f ("kvm: x86: Disallow illegal IA32_APIC_BASE MSR values")
10 * That bug allowed a user-mode program that called the KVM_SET_SREGS
11 * ioctl to put a VCPU's local APIC into an invalid state.
13 #define _GNU_SOURCE /* for program_invocation_short_name */
18 #include <sys/ioctl.h>
20 #include "test_util.h"
23 #include "processor.h"
27 int main(int argc
, char *argv
[])
29 struct kvm_sregs sregs
;
33 /* Tell stdout not to buffer its content */
37 vm
= vm_create_default(VCPU_ID
, 0, NULL
);
39 vcpu_sregs_get(vm
, VCPU_ID
, &sregs
);
40 sregs
.apic_base
= 1 << 10;
41 rc
= _vcpu_sregs_set(vm
, VCPU_ID
, &sregs
);
42 TEST_ASSERT(rc
, "Set IA32_APIC_BASE to %llx (invalid)",
44 sregs
.apic_base
= 1 << 11;
45 rc
= _vcpu_sregs_set(vm
, VCPU_ID
, &sregs
);
46 TEST_ASSERT(!rc
, "Couldn't set IA32_APIC_BASE to %llx (valid)",