Tom Weininger | 1516997 | 2022-09-14 17:16:00 +0200 | [diff] [blame] | 1 | .. _kvm_nested_virt: |
| 2 | |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 3 | ======================================================= |
| 4 | Configure DevStack with KVM-based Nested Virtualization |
| 5 | ======================================================= |
| 6 | |
| 7 | When using virtualization technologies like KVM, one can take advantage |
| 8 | of "Nested VMX" (i.e. the ability to run KVM on KVM) so that the VMs in |
| 9 | cloud (Nova guests) can run relatively faster than with plain QEMU |
| 10 | emulation. |
| 11 | |
| 12 | Kernels shipped with Linux distributions doesn't have this enabled by |
| 13 | default. This guide outlines the configuration details to enable nested |
| 14 | virtualization in KVM-based environments. And how to setup DevStack |
| 15 | (that'll run in a VM) to take advantage of this. |
| 16 | |
| 17 | |
| 18 | Nested Virtualization Configuration |
| 19 | =================================== |
| 20 | |
| 21 | Configure Nested KVM for Intel-based Machines |
| 22 | --------------------------------------------- |
| 23 | |
Kashyap Chamarthy | a7c6558 | 2015-02-11 17:58:15 +0100 | [diff] [blame] | 24 | Procedure to enable nested KVM virtualization on Intel-based machines. |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 25 | |
| 26 | Check if the nested KVM Kernel parameter is enabled: |
| 27 | |
| 28 | :: |
| 29 | |
| 30 | cat /sys/module/kvm_intel/parameters/nested |
| 31 | N |
| 32 | |
| 33 | Temporarily remove the KVM intel Kernel module, enable nested |
| 34 | virtualization to be persistent across reboots and add the Kernel |
| 35 | module back: |
| 36 | |
| 37 | :: |
| 38 | |
| 39 | sudo rmmod kvm-intel |
| 40 | sudo sh -c "echo 'options kvm-intel nested=y' >> /etc/modprobe.d/dist.conf" |
| 41 | sudo modprobe kvm-intel |
| 42 | |
| 43 | Ensure the Nested KVM Kernel module parameter for Intel is enabled on |
| 44 | the host: |
| 45 | |
| 46 | :: |
| 47 | |
| 48 | cat /sys/module/kvm_intel/parameters/nested |
| 49 | Y |
| 50 | |
| 51 | modinfo kvm_intel | grep nested |
| 52 | parm: nested:bool |
| 53 | |
| 54 | Start your VM, now it should have KVM capabilities -- you can verify |
Markus Zoeller | c30657d | 2015-11-02 11:27:46 +0100 | [diff] [blame] | 55 | that by ensuring ``/dev/kvm`` character device is present. |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 56 | |
| 57 | |
| 58 | Configure Nested KVM for AMD-based Machines |
Shilla Saebi | 2ed09d8 | 2015-04-21 15:02:13 -0400 | [diff] [blame] | 59 | ------------------------------------------- |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 60 | |
| 61 | Procedure to enable nested KVM virtualization on AMD-based machines. |
| 62 | |
| 63 | Check if the nested KVM Kernel parameter is enabled: |
| 64 | |
| 65 | :: |
| 66 | |
| 67 | cat /sys/module/kvm_amd/parameters/nested |
| 68 | 0 |
| 69 | |
| 70 | |
| 71 | Temporarily remove the KVM AMD Kernel module, enable nested |
| 72 | virtualization to be persistent across reboots and add the Kernel module |
| 73 | back: |
| 74 | |
| 75 | :: |
| 76 | |
| 77 | sudo rmmod kvm-amd |
Vincent Untz | 09698d0 | 2017-01-06 11:25:46 +0100 | [diff] [blame] | 78 | sudo sh -c "echo 'options kvm-amd nested=1' >> /etc/modprobe.d/dist.conf" |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 79 | sudo modprobe kvm-amd |
| 80 | |
| 81 | Ensure the Nested KVM Kernel module parameter for AMD is enabled on the |
| 82 | host: |
| 83 | |
| 84 | :: |
| 85 | |
| 86 | cat /sys/module/kvm_amd/parameters/nested |
| 87 | 1 |
| 88 | |
| 89 | modinfo kvm_amd | grep -i nested |
| 90 | parm: nested:int |
| 91 | |
| 92 | To make the above value persistent across reboots, add an entry in |
Hiroshi Miura | c1dded9 | 2015-07-22 12:18:35 +0900 | [diff] [blame] | 93 | /etc/modprobe.d/dist.conf so it looks as below:: |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 94 | |
| 95 | cat /etc/modprobe.d/dist.conf |
| 96 | options kvm-amd nested=y |
| 97 | |
| 98 | |
| 99 | Expose Virtualization Extensions to DevStack VM |
| 100 | ----------------------------------------------- |
| 101 | |
Markus Zoeller | c30657d | 2015-11-02 11:27:46 +0100 | [diff] [blame] | 102 | Edit the VM's libvirt XML configuration via ``virsh`` utility: |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 103 | |
| 104 | :: |
| 105 | |
| 106 | sudo virsh edit devstack-vm |
| 107 | |
| 108 | Add the below snippet to expose the host CPU features to the VM: |
| 109 | |
| 110 | :: |
| 111 | |
| 112 | <cpu mode='host-passthrough'> |
| 113 | </cpu> |
| 114 | |
| 115 | |
| 116 | Ensure DevStack VM is Using KVM |
| 117 | ------------------------------- |
| 118 | |
| 119 | Before invoking ``stack.sh`` in the VM, ensure that KVM is enabled. This |
Markus Zoeller | c30657d | 2015-11-02 11:27:46 +0100 | [diff] [blame] | 120 | can be verified by checking for the presence of the file ``/dev/kvm`` in |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 121 | your VM. If it is present, DevStack will default to using the config |
Markus Zoeller | c30657d | 2015-11-02 11:27:46 +0100 | [diff] [blame] | 122 | attribute ``virt_type = kvm`` in ``/etc/nova.conf``; otherwise, it'll fall |
| 123 | back to ``virt_type=qemu``, i.e. plain QEMU emulation. |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 124 | |
| 125 | Optionally, to explicitly set the type of virtualization, to KVM, by the |
Shilla Saebi | 2ed09d8 | 2015-04-21 15:02:13 -0400 | [diff] [blame] | 126 | libvirt driver in nova, the below config attribute can be used in |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 127 | DevStack's ``local.conf``: |
| 128 | |
| 129 | :: |
| 130 | |
| 131 | LIBVIRT_TYPE=kvm |
| 132 | |
| 133 | |
Takashi NATSUME | 4de0f1c | 2015-03-10 14:51:39 +0900 | [diff] [blame] | 134 | Once DevStack is configured successfully, verify if the Nova instances |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 135 | are using KVM by noticing the QEMU CLI invoked by Nova is using the |
Markus Zoeller | c30657d | 2015-11-02 11:27:46 +0100 | [diff] [blame] | 136 | parameter ``accel=kvm``, e.g.: |
Kashyap Chamarthy | 75afd6d | 2015-01-20 17:39:25 +0100 | [diff] [blame] | 137 | |
| 138 | :: |
| 139 | |
| 140 | ps -ef | grep -i qemu |
| 141 | root 29773 1 0 11:24 ? 00:00:00 /usr/bin/qemu-system-x86_64 -machine accel=kvm [. . .] |