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