gzvm_exception.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2023 MediaTek Inc.
  4. */
  5. #include <linux/device.h>
  6. #include <linux/gzvm_drv.h>
  7. /**
  8. * gzvm_handle_guest_exception() - Handle guest exception
  9. * @vcpu: Pointer to struct gzvm_vcpu_run in userspace
  10. * Return:
  11. * * true - This exception has been processed, no need to back to VMM.
  12. * * false - This exception has not been processed, require userspace.
  13. */
  14. bool gzvm_handle_guest_exception(struct gzvm_vcpu *vcpu)
  15. {
  16. int ret;
  17. for (int i = 0; i < ARRAY_SIZE(vcpu->run->exception.reserved); i++) {
  18. if (vcpu->run->exception.reserved[i])
  19. return -EINVAL;
  20. }
  21. switch (vcpu->run->exception.exception) {
  22. case GZVM_EXCEPTION_PAGE_FAULT:
  23. ret = gzvm_handle_page_fault(vcpu);
  24. break;
  25. case GZVM_EXCEPTION_UNKNOWN:
  26. fallthrough;
  27. default:
  28. ret = -EFAULT;
  29. }
  30. if (!ret)
  31. return true;
  32. else
  33. return false;
  34. }
  35. /**
  36. * gzvm_handle_guest_hvc() - Handle guest hvc
  37. * @vcpu: Pointer to struct gzvm_vcpu struct
  38. * Return:
  39. * * true - This hvc has been processed, no need to back to VMM.
  40. * * false - This hvc has not been processed, require userspace.
  41. */
  42. bool gzvm_handle_guest_hvc(struct gzvm_vcpu *vcpu)
  43. {
  44. unsigned long ipa;
  45. int ret;
  46. switch (vcpu->run->hypercall.args[0]) {
  47. case GZVM_HVC_MEM_RELINQUISH:
  48. ipa = vcpu->run->hypercall.args[1];
  49. ret = gzvm_handle_relinquish(vcpu, ipa);
  50. return (ret == 0) ? true : false;
  51. default:
  52. break;
  53. }
  54. return false;
  55. }