|
| 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