io-request.rst 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. .. SPDX-License-Identifier: GPL-2.0
  2. I/O request handling
  3. ====================
  4. An I/O request of a User VM, which is constructed by the hypervisor, is
  5. distributed by the ACRN Hypervisor Service Module to an I/O client
  6. corresponding to the address range of the I/O request. Details of I/O request
  7. handling are described in the following sections.
  8. 1. I/O request
  9. --------------
  10. For each User VM, there is a shared 4-KByte memory region used for I/O requests
  11. communication between the hypervisor and Service VM. An I/O request is a
  12. 256-byte structure buffer, which is 'struct acrn_io_request', that is filled by
  13. an I/O handler of the hypervisor when a trapped I/O access happens in a User
  14. VM. ACRN userspace in the Service VM first allocates a 4-KByte page and passes
  15. the GPA (Guest Physical Address) of the buffer to the hypervisor. The buffer is
  16. used as an array of 16 I/O request slots with each I/O request slot being 256
  17. bytes. This array is indexed by vCPU ID.
  18. 2. I/O clients
  19. --------------
  20. An I/O client is responsible for handling User VM I/O requests whose accessed
  21. GPA falls in a certain range. Multiple I/O clients can be associated with each
  22. User VM. There is a special client associated with each User VM, called the
  23. default client, that handles all I/O requests that do not fit into the range of
  24. any other clients. The ACRN userspace acts as the default client for each User
  25. VM.
  26. Below illustration shows the relationship between I/O requests shared buffer,
  27. I/O requests and I/O clients.
  28. ::
  29. +------------------------------------------------------+
  30. | Service VM |
  31. |+--------------------------------------------------+ |
  32. || +----------------------------------------+ | |
  33. || | shared page ACRN userspace | | |
  34. || | +-----------------+ +------------+ | | |
  35. || +----+->| acrn_io_request |<-+ default | | | |
  36. || | | | +-----------------+ | I/O client | | | |
  37. || | | | | ... | +------------+ | | |
  38. || | | | +-----------------+ | | |
  39. || | +-|--------------------------------------+ | |
  40. ||---|----|-----------------------------------------| |
  41. || | | kernel | |
  42. || | | +----------------------+ | |
  43. || | | | +-------------+ HSM | | |
  44. || | +--------------+ | | | |
  45. || | | | I/O clients | | | |
  46. || | | | | | | |
  47. || | | +-------------+ | | |
  48. || | +----------------------+ | |
  49. |+---|----------------------------------------------+ |
  50. +----|-------------------------------------------------+
  51. |
  52. +----|-------------------------------------------------+
  53. | +-+-----------+ |
  54. | | I/O handler | ACRN Hypervisor |
  55. | +-------------+ |
  56. +------------------------------------------------------+
  57. 3. I/O request state transition
  58. -------------------------------
  59. The state transitions of an ACRN I/O request are as follows.
  60. ::
  61. FREE -> PENDING -> PROCESSING -> COMPLETE -> FREE -> ...
  62. - FREE: this I/O request slot is empty
  63. - PENDING: a valid I/O request is pending in this slot
  64. - PROCESSING: the I/O request is being processed
  65. - COMPLETE: the I/O request has been processed
  66. An I/O request in COMPLETE or FREE state is owned by the hypervisor. HSM and
  67. ACRN userspace are in charge of processing the others.
  68. 4. Processing flow of I/O requests
  69. ----------------------------------
  70. a. The I/O handler of the hypervisor will fill an I/O request with PENDING
  71. state when a trapped I/O access happens in a User VM.
  72. b. The hypervisor makes an upcall, which is a notification interrupt, to
  73. the Service VM.
  74. c. The upcall handler schedules a worker to dispatch I/O requests.
  75. d. The worker looks for the PENDING I/O requests, assigns them to different
  76. registered clients based on the address of the I/O accesses, updates
  77. their state to PROCESSING, and notifies the corresponding client to handle.
  78. e. The notified client handles the assigned I/O requests.
  79. f. The HSM updates I/O requests states to COMPLETE and notifies the hypervisor
  80. of the completion via hypercalls.