vm-manager.rst 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =======================
  3. Virtual Machine Manager
  4. =======================
  5. The Gunyah Virtual Machine Manager is a Linux driver to support launching
  6. virtual machines using Gunyah.
  7. Configuration of a Gunyah virtual machine is done via a devicetree. When the VM
  8. is launched, memory is provided by the host VM which contains the devictree.
  9. Gunyah reads the devicetree to configure the memory map and create resources
  10. such as vCPUs for the VM. Memory can be shared with the VM with
  11. `GH_VM_SET_USER_MEM_REGION`_. Userspace can interact with the resources in Linux
  12. by adding "functions" to the VM.
  13. Gunyah Functions
  14. ================
  15. Components of a Gunyah VM's configuration that need kernel configuration are
  16. called "functions" and are built on top of a framework. Functions are identified
  17. by a string and have some argument(s) to configure them. They are typically
  18. created by the `GH_VM_ADD_FUNCTION`_ ioctl.
  19. Functions typically will always do at least one of these operations:
  20. 1. Create resource ticket(s). Resource tickets allow a function to register
  21. itself as the client for a Gunyah resource (e.g. doorbell or vCPU) and
  22. the function is given the pointer to the &struct gh_resource when the
  23. VM is starting.
  24. 2. Register IO handler(s). IO handlers allow a function to handle stage-2 faults
  25. from the virtual machine.
  26. Sample Userspace VMM
  27. ====================
  28. A sample userspace VMM is included in samples/gunyah/ along with a minimal
  29. devicetree that can be used to launch a VM. To build this sample, enable
  30. CONFIG_SAMPLE_GUNYAH.
  31. IOCTLs and userspace VMM flows
  32. ==============================
  33. The kernel exposes a char device interface at /dev/gunyah.
  34. To create a VM, use the `GH_CREATE_VM`_ ioctl. A successful call will return a
  35. "Gunyah VM" file descriptor.
  36. /dev/gunyah API Descriptions
  37. ----------------------------
  38. GH_CREATE_VM
  39. ~~~~~~~~~~~~
  40. Creates a Gunyah VM. The argument is reserved for future use and must be 0.
  41. A successful call will return a Gunyah VM file descriptor. See
  42. `Gunyah VM API Descriptions`_ for list of IOCTLs that can be made on this file
  43. file descriptor.
  44. Gunyah VM API Descriptions
  45. --------------------------
  46. GH_VM_SET_USER_MEM_REGION
  47. ~~~~~~~~~~~~~~~~~~~~~~~~~
  48. This ioctl allows the user to create or delete a memory parcel for a guest
  49. virtual machine. Each memory region is uniquely identified by a label;
  50. attempting to create two regions with the same label is not allowed. Labels are
  51. unique per virtual machine.
  52. While VMM is guest-agnostic and allows runtime addition of memory regions,
  53. Linux guest virtual machines do not support accepting memory regions at runtime.
  54. Thus, for Linux guests, memory regions should be provided before starting the VM
  55. and the VM must be configured via the devicetree to accept these at boot-up.
  56. The guest physical address is used by Linux kernel to check that the requested
  57. user regions do not overlap and to help find the corresponding memory region
  58. for calls like `GH_VM_SET_DTB_CONFIG`_. It must be page aligned.
  59. To add a memory region, call `GH_VM_SET_USER_MEM_REGION`_ with fields set as
  60. described above.
  61. .. kernel-doc:: include/uapi/linux/gunyah.h
  62. :identifiers: gh_userspace_memory_region gh_mem_flags
  63. GH_VM_SET_DTB_CONFIG
  64. ~~~~~~~~~~~~~~~~~~~~
  65. This ioctl sets the location of the VM's devicetree blob and is used by Gunyah
  66. Resource Manager to allocate resources. The guest physical memory must be part
  67. of the primary memory parcel provided to the VM prior to GH_VM_START.
  68. .. kernel-doc:: include/uapi/linux/gunyah.h
  69. :identifiers: gh_vm_dtb_config
  70. GH_VM_START
  71. ~~~~~~~~~~~
  72. This ioctl starts the VM.
  73. GH_VM_ADD_FUNCTION
  74. ~~~~~~~~~~~~~~~~~~
  75. This ioctl registers a Gunyah VM function with the VM manager. The VM function
  76. is described with a &struct gh_fn_desc.type and some arguments for that type.
  77. Typically, the function is added before the VM starts, but the function doesn't
  78. "operate" until the VM starts with `GH_VM_START`_. For example, vCPU ioctls will
  79. all return an error until the VM starts because the vCPUs don't exist until the
  80. VM is started. This allows the VMM to set up all the kernel functions needed for
  81. the VM *before* the VM starts.
  82. .. kernel-doc:: include/uapi/linux/gunyah.h
  83. :identifiers: gh_fn_desc gh_fn_type
  84. The argument types are documented below:
  85. .. kernel-doc:: include/uapi/linux/gunyah.h
  86. :identifiers: gh_fn_vcpu_arg gh_fn_irqfd_arg gh_irqfd_flags gh_fn_ioeventfd_arg gh_ioeventfd_flags
  87. Gunyah VCPU API Descriptions
  88. ----------------------------
  89. A vCPU file descriptor is created after calling `GH_VM_ADD_FUNCTION` with the type `GH_FN_VCPU`.
  90. GH_VCPU_RUN
  91. ~~~~~~~~~~~
  92. This ioctl is used to run a guest virtual cpu. While there are no
  93. explicit parameters, there is an implicit parameter block that can be
  94. obtained by mmap()ing the vcpu fd at offset 0, with the size given by
  95. `GH_VCPU_MMAP_SIZE`_. The parameter block is formatted as a 'struct
  96. gh_vcpu_run' (see below).
  97. GH_VCPU_MMAP_SIZE
  98. ~~~~~~~~~~~~~~~~~
  99. The `GH_VCPU_RUN`_ ioctl communicates with userspace via a shared
  100. memory region. This ioctl returns the size of that region. See the
  101. `GH_VCPU_RUN`_ documentation for details.
  102. .. kernel-doc:: include/uapi/linux/gunyah.h
  103. :identifiers: gh_vcpu_exit gh_vcpu_run gh_vm_status gh_vm_exit_info