Skip to content

Commit 85acc29

Browse files
Marc Zyngieroupton
authored andcommitted
KVM: arm64: selftest: Add standalone test checking for KVM's own UUID
Tinkering with UUIDs is a perilious task, and the KVM UUID gets broken at times. In order to spot this early enough, add a selftest that will shout if the expected value isn't found. Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Sebastian Ott <[email protected]> Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Oliver Upton <[email protected]>
1 parent f1edb15 commit 85acc29

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tools/testing/selftests/kvm/Makefile.kvm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ TEST_GEN_PROGS_arm64 += arm64/vgic_irq
167167
TEST_GEN_PROGS_arm64 += arm64/vgic_lpi_stress
168168
TEST_GEN_PROGS_arm64 += arm64/vpmu_counter_access
169169
TEST_GEN_PROGS_arm64 += arm64/no-vgic-v3
170+
TEST_GEN_PROGS_arm64 += arm64/kvm-uuid
170171
TEST_GEN_PROGS_arm64 += access_tracking_perf_test
171172
TEST_GEN_PROGS_arm64 += arch_timer
172173
TEST_GEN_PROGS_arm64 += coalesced_io_test
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
// Check that nobody has tampered with KVM's UID
4+
5+
#include <errno.h>
6+
#include <linux/arm-smccc.h>
7+
#include <asm/kvm.h>
8+
#include <kvm_util.h>
9+
10+
#include "processor.h"
11+
12+
/*
13+
* Do NOT redefine these constants, or try to replace them with some
14+
* "common" version. They are hardcoded here to detect any potential
15+
* breakage happening in the rest of the kernel.
16+
*
17+
* KVM UID value: 28b46fb6-2ec5-11e9-a9ca-4b564d003a74
18+
*/
19+
#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 0xb66fb428U
20+
#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 0xe911c52eU
21+
#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 0x564bcaa9U
22+
#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3 0x743a004dU
23+
24+
static void guest_code(void)
25+
{
26+
struct arm_smccc_res res = {};
27+
28+
smccc_hvc(ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID, 0, 0, 0, 0, 0, 0, 0, &res);
29+
30+
__GUEST_ASSERT(res.a0 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 &&
31+
res.a1 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 &&
32+
res.a2 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 &&
33+
res.a3 == ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3,
34+
"Unexpected KVM-specific UID %lx %lx %lx %lx\n", res.a0, res.a1, res.a2, res.a3);
35+
GUEST_DONE();
36+
}
37+
38+
int main (int argc, char *argv[])
39+
{
40+
struct kvm_vcpu *vcpu;
41+
struct kvm_vm *vm;
42+
struct ucall uc;
43+
bool guest_done = false;
44+
45+
vm = vm_create_with_one_vcpu(&vcpu, guest_code);
46+
47+
while (!guest_done) {
48+
vcpu_run(vcpu);
49+
50+
switch (get_ucall(vcpu, &uc)) {
51+
case UCALL_SYNC:
52+
break;
53+
case UCALL_DONE:
54+
guest_done = true;
55+
break;
56+
case UCALL_ABORT:
57+
REPORT_GUEST_ASSERT(uc);
58+
break;
59+
case UCALL_PRINTF:
60+
printf("%s", uc.buffer);
61+
break;
62+
default:
63+
TEST_FAIL("Unexpected guest exit");
64+
}
65+
}
66+
67+
kvm_vm_free(vm);
68+
69+
return 0;
70+
}

0 commit comments

Comments
 (0)