kvm-uuid.c 1.7 KB

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