blob: ba483e9ec9c0a4b7eb5af3605a72fc705f58035a [file] [log] [blame]
Tom Weininger15169972022-09-14 17:16:00 +02001.. _kvm_nested_virt:
2
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +01003=======================================================
4Configure DevStack with KVM-based Nested Virtualization
5=======================================================
6
7When using virtualization technologies like KVM, one can take advantage
8of "Nested VMX" (i.e. the ability to run KVM on KVM) so that the VMs in
9cloud (Nova guests) can run relatively faster than with plain QEMU
10emulation.
11
12Kernels shipped with Linux distributions doesn't have this enabled by
13default. This guide outlines the configuration details to enable nested
14virtualization in KVM-based environments. And how to setup DevStack
15(that'll run in a VM) to take advantage of this.
16
17
18Nested Virtualization Configuration
19===================================
20
21Configure Nested KVM for Intel-based Machines
22---------------------------------------------
23
Kashyap Chamarthya7c65582015-02-11 17:58:15 +010024Procedure to enable nested KVM virtualization on Intel-based machines.
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +010025
26Check if the nested KVM Kernel parameter is enabled:
27
28::
29
30 cat /sys/module/kvm_intel/parameters/nested
31 N
32
33Temporarily remove the KVM intel Kernel module, enable nested
34virtualization to be persistent across reboots and add the Kernel
35module 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
43Ensure the Nested KVM Kernel module parameter for Intel is enabled on
44the 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
54Start your VM, now it should have KVM capabilities -- you can verify
Markus Zoellerc30657d2015-11-02 11:27:46 +010055that by ensuring ``/dev/kvm`` character device is present.
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +010056
57
58Configure Nested KVM for AMD-based Machines
Shilla Saebi2ed09d82015-04-21 15:02:13 -040059-------------------------------------------
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +010060
61Procedure to enable nested KVM virtualization on AMD-based machines.
62
63Check if the nested KVM Kernel parameter is enabled:
64
65::
66
67 cat /sys/module/kvm_amd/parameters/nested
68 0
69
70
71Temporarily remove the KVM AMD Kernel module, enable nested
72virtualization to be persistent across reboots and add the Kernel module
73back:
74
75::
76
77 sudo rmmod kvm-amd
Vincent Untz09698d02017-01-06 11:25:46 +010078 sudo sh -c "echo 'options kvm-amd nested=1' >> /etc/modprobe.d/dist.conf"
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +010079 sudo modprobe kvm-amd
80
81Ensure the Nested KVM Kernel module parameter for AMD is enabled on the
82host:
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
92To make the above value persistent across reboots, add an entry in
Hiroshi Miurac1dded92015-07-22 12:18:35 +090093/etc/modprobe.d/dist.conf so it looks as below::
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +010094
95 cat /etc/modprobe.d/dist.conf
96 options kvm-amd nested=y
97
98
99Expose Virtualization Extensions to DevStack VM
100-----------------------------------------------
101
Markus Zoellerc30657d2015-11-02 11:27:46 +0100102Edit the VM's libvirt XML configuration via ``virsh`` utility:
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +0100103
104::
105
106 sudo virsh edit devstack-vm
107
108Add the below snippet to expose the host CPU features to the VM:
109
110::
111
112 <cpu mode='host-passthrough'>
113 </cpu>
114
115
116Ensure DevStack VM is Using KVM
117-------------------------------
118
119Before invoking ``stack.sh`` in the VM, ensure that KVM is enabled. This
Markus Zoellerc30657d2015-11-02 11:27:46 +0100120can be verified by checking for the presence of the file ``/dev/kvm`` in
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +0100121your VM. If it is present, DevStack will default to using the config
Markus Zoellerc30657d2015-11-02 11:27:46 +0100122attribute ``virt_type = kvm`` in ``/etc/nova.conf``; otherwise, it'll fall
123back to ``virt_type=qemu``, i.e. plain QEMU emulation.
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +0100124
125Optionally, to explicitly set the type of virtualization, to KVM, by the
Shilla Saebi2ed09d82015-04-21 15:02:13 -0400126libvirt driver in nova, the below config attribute can be used in
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +0100127DevStack's ``local.conf``:
128
129::
130
131 LIBVIRT_TYPE=kvm
132
133
Takashi NATSUME4de0f1c2015-03-10 14:51:39 +0900134Once DevStack is configured successfully, verify if the Nova instances
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +0100135are using KVM by noticing the QEMU CLI invoked by Nova is using the
Markus Zoellerc30657d2015-11-02 11:27:46 +0100136parameter ``accel=kvm``, e.g.:
Kashyap Chamarthy75afd6d2015-01-20 17:39:25 +0100137
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 [. . .]