|
| 1 | +.. _GVT-G-porting: |
| 2 | + |
| 3 | +GVT-G Enabling and Porting Guide |
| 4 | +################################ |
| 5 | + |
| 6 | +Introduction |
| 7 | +************ |
| 8 | + |
| 9 | +GVT-g is Intel's Open Source GPU virtualization solution, up-streamed to |
| 10 | +the Linux kernel. Its implementation over KVM is named KVMGT, over Xen |
| 11 | +is named XenGT, and over ACRN is named ACRN-GT. GVT-g can export |
| 12 | +multiple virtual-GPU (vGPU) instances for virtual machine (VM) system. A |
| 13 | +VM can be assigned one instance of a vGPU. The guest OS graphic driver |
| 14 | +needs only minor modifications to drive the vGPU adapter in a VM. Every |
| 15 | +vGPU instance adopts the full HW GPU's acceleration capability for |
| 16 | +media, 3D renderingi, and display. |
| 17 | + |
| 18 | +ACRN-GT refers to the glue layer between the ACRN hypervisor and GVT-g |
| 19 | +core device model. It works as the agent of hypervisor-related services. |
| 20 | +It is the only layer that needs to be rewritten when porting GVT-g to |
| 21 | +other specific hypervisors. |
| 22 | + |
| 23 | +For simplicity, in the rest of this document, the term GVT is used to |
| 24 | +refer to the core device model component of GVT-g, specifically |
| 25 | +corresponding to ``gvt.ko`` when build as a module. |
| 26 | + |
| 27 | +Purpose of this document |
| 28 | +************************ |
| 29 | + |
| 30 | +This document explains the relationship between components of GVT-g in |
| 31 | +the ACRN hypervisor, shows how to enable GVT-g on ACRN, and guides |
| 32 | +developers porting GVT-g to work on other hypervisors. |
| 33 | + |
| 34 | +This document describes: |
| 35 | + |
| 36 | +- the overall components of GVT-g |
| 37 | +- interaction interface of each components |
| 38 | +- core interaction scenarios |
| 39 | + |
| 40 | +APIs of each component interface can be found in the :ref:`GVT-g_api` |
| 41 | +documentation. |
| 42 | + |
| 43 | + |
| 44 | +Overall Components |
| 45 | +****************** |
| 46 | + |
| 47 | +For the GVT-g solution for the ACRN hypervisor, there are two |
| 48 | +key modules: ACRN-GT and GVT: |
| 49 | + |
| 50 | +ACRN-GT module |
| 51 | + Compiled from ``drivers/gpu/drm/i915/gvt/acrn_gvt.c``, the ACRN-GT |
| 52 | + module acts as a glue layer between the ACRN hypervisor and the |
| 53 | + interface to the ACRN-DM in user space. |
| 54 | + |
| 55 | + ACRN-GT is the agent of hypervisor related services, including I/O trap |
| 56 | + request, IRQ injection, address translation, VM controls, etc. It also |
| 57 | + listens to ACRN hypervisor in ``acrngt_emulation_thread``, and informs GVT |
| 58 | + module of I/O traps. |
| 59 | + |
| 60 | + It calls into the GVT module's :ref:`intel_gvt_ops_interface` to invoke |
| 61 | + Device Model's routines, and receives request from GVT module through |
| 62 | + the :ref:`MPT_interface`. |
| 63 | + |
| 64 | + User space programs, such as ACRN-DM, communicate with ACRN-GT through |
| 65 | + the :ref:`sysfs_interface` by writing to sysfs node |
| 66 | + ``/sys/kernel/gvt/control/create_gvt_instance``. |
| 67 | + |
| 68 | + This is the only module that needs to be rewritten when porting to |
| 69 | + another embedded device hypervisor. |
| 70 | + |
| 71 | +GVT module |
| 72 | + This Device Model service is the central part of all |
| 73 | + GVT-g components. It receives workloads from each vGPU, shadows the |
| 74 | + workloads, and dispatches the workloads to Dom0's i915 module to deliver |
| 75 | + workloads to real hardware. It also emulates the virtual display to each |
| 76 | + VM. |
| 77 | + |
| 78 | +VHM module |
| 79 | + This is a kernel module that requires an interrupt (vIRQ) number, |
| 80 | + and exposes APIs to external kernel modules such as GVT-g, and the |
| 81 | + virtIO BE service running in kernel space. It exposes a char device node |
| 82 | + in user space, and only interacts with the DM. The DM routes I/O |
| 83 | + requests and responses between other modules to and from the VHM module |
| 84 | + via the char device. DM may use the VHM for hypervisor service |
| 85 | + (including remote memory map), and VHM may directly service the request |
| 86 | + such as for the remote memory map, or invoking hypercall. It also sends |
| 87 | + I/O responses to user space modules, notified by vIRQ injections. |
| 88 | + |
| 89 | + |
| 90 | +.. figure:: images/GVT-G-porting-image1.png |
| 91 | + :width: 700px |
| 92 | + :align: center |
| 93 | + :name: GVT-g_components |
| 94 | + |
| 95 | + GVT-g components and interfaces |
| 96 | + |
| 97 | +Core scenario interaction sequences |
| 98 | +*********************************** |
| 99 | + |
| 100 | + |
| 101 | +vGPU creation scenario |
| 102 | +====================== |
| 103 | + |
| 104 | +In this scenario, ACRN-GT receives a create request from ACRN-DM. It |
| 105 | +calls GVT's :ref:`intel_gvt_ops_interface` to inform GVT of vGPU |
| 106 | +creation. This interface sets up all vGPU resources such as MMIO, GMA, |
| 107 | +PVINFO, GTT, DISPLAY, and Execlists, and calls back to the ACRN-GT |
| 108 | +module through the :ref:`MPT_interface` ``attach_vgpu``. Then, the |
| 109 | +ACRN-GT module sets up an I/O request server and asks to trap the PCI |
| 110 | +configure space of the vGPU (virtual device 0:2:0) via VHM's APIs. |
| 111 | +Finally, the ACRN-GT module launches a ACRN-GT emulation thread to |
| 112 | +listen to I/O trap notifications from HVM and ACRN hypervisor. |
| 113 | + |
| 114 | +vGPU destroy scenario |
| 115 | +===================== |
| 116 | + |
| 117 | +In this scenario, ACRN-GT receives a destroy request from ACRN-DM. It |
| 118 | +calls GVT's :ref:`intel_gvt_ops_interface` to inform GVT of the vGPU destroy |
| 119 | +request, and cleans up all vGPU resources. |
| 120 | + |
| 121 | +vGPU pci configure space write scenario |
| 122 | +======================================= |
| 123 | + |
| 124 | +ACRN traps the vGPU's PCI config space write, notifies ACRN-GT's |
| 125 | +``acrngt_emulation_thread``, which calls ``acrngt_hvm_pio_emulation`` to |
| 126 | +handle all I/O trap notifications. This routine calls the GVT's |
| 127 | +:ref:`intel_gvt_ops_interface` ``emulate_cfg_write`` to emulate the vGPU PCI |
| 128 | +config space write: |
| 129 | + |
| 130 | +#. If it's BAR0 (GTTMMIO) write, turn on/off GTTMMIO trap, according to |
| 131 | + the write value. |
| 132 | +#. If it's BAR1 (Aperture) write, maps/unmaps vGPU's aperture to its |
| 133 | + corresponding part in the host's aperture. |
| 134 | +#. Otherwise, write to the virtual PCI configuration space of the vGPU. |
| 135 | + |
| 136 | +pci configure space read scenario |
| 137 | +================================= |
| 138 | + |
| 139 | +Call sequence is almost the same as the write scenario above, |
| 140 | +but instead it calls the GVT's :ref:`intel_gvt_ops_interface` |
| 141 | +``emulate_cfg_read`` to emulate the vGPU PCI config space read. |
| 142 | + |
| 143 | +GGTT read/write scenario |
| 144 | +======================== |
| 145 | + |
| 146 | +GGTT's trap is set up in the pci configure space write |
| 147 | +scenario above. |
| 148 | + |
| 149 | +MMIO read/write scenario |
| 150 | +======================== |
| 151 | + |
| 152 | +MMIO's trap is set up in the pci configure space write |
| 153 | +scenario above. |
| 154 | + |
| 155 | +PPGTT write protection page set/unset scenario |
| 156 | +============================================== |
| 157 | + |
| 158 | +PPGTT write protection page is set by calling ``acrn_ioreq_add_iorange`` |
| 159 | +with range type as ``REQ_WP``, and trap its write to device model while |
| 160 | +allowing read without trap. |
| 161 | + |
| 162 | +PPGTT write protection page is unset by calling ``acrn_ioreq_del_range``. |
| 163 | + |
| 164 | +PPGTT write protection page write |
| 165 | +================================= |
| 166 | + |
| 167 | +In the VHM module, ioreq for PPGTT WP and MMIO trap is the same. It will |
| 168 | +also be trapped into the routine ``intel_vgpu_emulate_mmio_write()``. |
| 169 | + |
| 170 | +API details |
| 171 | +*********** |
| 172 | + |
| 173 | +APIs of each component interface can be found in the :ref:`GVT-g_api` |
| 174 | +documentation. |
0 commit comments