idreg-idst.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Access all FEAT_IDST-handled registers that depend on more than
  4. * just FEAT_AA64, and fail if we don't get an a trap with an 0x18 EC.
  5. */
  6. #include <test_util.h>
  7. #include <kvm_util.h>
  8. #include <processor.h>
  9. static volatile bool sys64, undef;
  10. #define __check_sr_read(r) \
  11. ({ \
  12. uint64_t val; \
  13. \
  14. sys64 = false; \
  15. undef = false; \
  16. dsb(sy); \
  17. val = read_sysreg_s(SYS_ ## r); \
  18. val; \
  19. })
  20. /* Fatal checks */
  21. #define check_sr_read(r) \
  22. do { \
  23. __check_sr_read(r); \
  24. __GUEST_ASSERT(!undef, #r " unexpected UNDEF"); \
  25. __GUEST_ASSERT(sys64, #r " didn't trap"); \
  26. } while(0)
  27. static void guest_code(void)
  28. {
  29. check_sr_read(CCSIDR2_EL1);
  30. check_sr_read(SMIDR_EL1);
  31. check_sr_read(GMID_EL1);
  32. GUEST_DONE();
  33. }
  34. static void guest_sys64_handler(struct ex_regs *regs)
  35. {
  36. sys64 = true;
  37. undef = false;
  38. regs->pc += 4;
  39. }
  40. static void guest_undef_handler(struct ex_regs *regs)
  41. {
  42. sys64 = false;
  43. undef = true;
  44. regs->pc += 4;
  45. }
  46. static void test_run_vcpu(struct kvm_vcpu *vcpu)
  47. {
  48. struct ucall uc;
  49. do {
  50. vcpu_run(vcpu);
  51. switch (get_ucall(vcpu, &uc)) {
  52. case UCALL_ABORT:
  53. REPORT_GUEST_ASSERT(uc);
  54. break;
  55. case UCALL_PRINTF:
  56. printf("%s", uc.buffer);
  57. break;
  58. case UCALL_DONE:
  59. break;
  60. default:
  61. TEST_FAIL("Unknown ucall %lu", uc.cmd);
  62. }
  63. } while (uc.cmd != UCALL_DONE);
  64. }
  65. static void test_guest_feat_idst(void)
  66. {
  67. struct kvm_vcpu *vcpu;
  68. struct kvm_vm *vm;
  69. /* This VM has no MTE, no SME, no CCIDX */
  70. vm = vm_create_with_one_vcpu(&vcpu, guest_code);
  71. vm_init_descriptor_tables(vm);
  72. vcpu_init_descriptor_tables(vcpu);
  73. vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
  74. ESR_ELx_EC_SYS64, guest_sys64_handler);
  75. vm_install_sync_handler(vm, VECTOR_SYNC_CURRENT,
  76. ESR_ELx_EC_UNKNOWN, guest_undef_handler);
  77. test_run_vcpu(vcpu);
  78. kvm_vm_free(vm);
  79. }
  80. int main(int argc, char *argv[])
  81. {
  82. struct kvm_vcpu *vcpu;
  83. struct kvm_vm *vm;
  84. uint64_t mmfr2;
  85. test_disable_default_vgic();
  86. vm = vm_create_with_one_vcpu(&vcpu, NULL);
  87. mmfr2 = vcpu_get_reg(vcpu, KVM_ARM64_SYS_REG(SYS_ID_AA64MMFR2_EL1));
  88. __TEST_REQUIRE(FIELD_GET(ID_AA64MMFR2_EL1_IDS, mmfr2) > 0,
  89. "FEAT_IDST not supported");
  90. kvm_vm_free(vm);
  91. test_guest_feat_idst();
  92. return 0;
  93. }