Skip to content

Commit 72e364a

Browse files
author
Lai Jiangshan
committed
Add PVM paper and slides
0 parents  commit 72e364a

3 files changed

Lines changed: 264 additions & 0 deletions

File tree

pvm-get-started-with-kata.md

Lines changed: 264 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,264 @@
1+
This document provides an overview on how to run Kata Containers with PVM hypervisor.
2+
## Introduction
3+
4+
---
5+
6+
`PVM`is a software virtualization technology that is purpose-built to support Kata Containers without the need for hardware virtualization assistance. It is designed as a vendor for KVM, similar to Intel and AMD, making it compatible with the software stack in Kata Containers.
7+
## Pre-requisites
8+
9+
---
10+
11+
This document requires the presence of Kata Containers and Containerd on your system. If you have the necessary environment set up, you can proceed directly to the [PVM configuration](#ILtus).
12+
13+
Since the PVM hypervisor is based on `Linux kernel 6.7-rc6`, if you only want to test it, we also provide a pre-configured VM image with Kata Containers and PVM. You can directly proceed to [verify using the VM image](#trbiG).
14+
## Configure Kata Containers and Containerd
15+
16+
---
17+
18+
You can follow the [offical guide](https://github.com/kata-containers/kata-containers/blob/main/docs/install/README.md) to install Kata Containers with Containerd. Here, we will the step-by-step [manual installation](https://github.com/kata-containers/kata-containers/blob/main/docs/install/container-manager/containerd/containerd-install.md) process of Kata Containers with Containerd.
19+
### Install Kata Containers.
20+
21+
---
22+
23+
- **Download a release**
24+
25+
You can get a release from the [offical release url](https://github.com/kata-containers/kata-containers/releases), choose a latest release version (eg: 3.2.0).
26+
```bash
27+
$ wget https://github.com/kata-containers/kata-containers/releases/download/3.2.0/kata-static-3.2.0-amd64.tar.xz
28+
```
29+
30+
- **Unpack the downloaded archive**
31+
```bash
32+
$ sudo tar -C / -xvf kata-static-3.2.0-amd64.tar.xz
33+
```
34+
After unpacking the downloaded archive, you will find the binaries in the /opt/kata/bin directory. It is recommended by Kata Containers to create symbolic links for these binaries, so that Containerd can locate them.
35+
```bash
36+
$ sudo ln -s /opt/kata/bin/kata-collect-data.sh /usr/local/bin/
37+
$ sudo ln -s /opt/kata/bin/kata-runtime /usr/local/bin/
38+
```
39+
40+
- **Check installation**
41+
42+
Check installation by showing version details:
43+
```bash
44+
$ kata-runtime --version
45+
```
46+
### Install Containerd
47+
48+
---
49+
50+
- **Download a release**
51+
52+
You can get a release from the [offical release url](https://github.com/containerd/containerd/releases), choose a latest release version (eg: 1.7.10).
53+
```bash
54+
$ wget https://github.com/containerd/containerd/releases/download/v1.7.10/containerd-1.7.10-linux-amd64.tar.gz
55+
```
56+
57+
- **Unpack the downloaded archive**
58+
```bash
59+
$ sudo tar -C /usr/local -xvf containerd-1.7.10-linux-amd64.tar.gz
60+
```
61+
62+
- **Configure Containerd**
63+
64+
Firstly, download the standard systemd(1) service file and install it in the`/etc/systemd/system/`directory.
65+
```bash
66+
$ wget https://raw.githubusercontent.com/containerd/containerd/master/containerd.service
67+
$ sudo mv containerd.service /etc/systemd/system/
68+
$ sudo systemctl daemon-reload
69+
```
70+
Secondly, add the necessary files for runtime and VMM configuration. In this step, we will add configurations for `QEMU` and `Cloud Hypervisor`.
71+
```bash
72+
$ cat <<-EOF | sudo tee -a "/usr/local/bin/containerd-shim-kata-v2"
73+
#!/bin/bash
74+
# QEMU (Default VMM)
75+
KATA_CONF_FILE=/opt/kata/share/defaults/kata-containers/configuration.toml /opt/kata/bin/containerd-shim-kata-v2 \$@
76+
EOF
77+
78+
$ sudo chmod +x /usr/local/bin/containerd-shim-kata-v2
79+
80+
$ cat <<-EOF | sudo tee -a "/usr/local/bin/containerd-shim-kata-clh-v2"
81+
#!/bin/bash
82+
# Cloud Hypervisor
83+
KATA_CONF_FILE=/opt/kata/share/defaults/kata-containers/configuration-clh.toml /opt/kata/bin/containerd-shim-kata-v2 \$@
84+
EOF
85+
86+
$ sudo chmod +x /usr/local/bin/containerd-shim-kata-clh-v2
87+
```
88+
Next, add the Kata Containers configuration to the Containerd configuration file (`/etc/containerd/config.toml`).
89+
> **Note:If you don't have the confiurtation file, you can generate it as follows:**
90+
91+
```bash
92+
$ sudo mkdir -p /etc/containerd
93+
$ sudo containerd config default >> /etc/containerd/config.toml
94+
```
95+
Add the following content into the configuration file under `[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]`** **section. This will configure Containerd to use the Kata runtime.
96+
> **[plugins."io.containerd.grpc.v1.cri".containerd.runtimes]**
97+
> ** [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata]**
98+
> runtime_type = "io.containerd.kata.v2"
99+
> ** [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.kata-clh]**
100+
> runtime_type = "io.containerd.kata-clh.v2"
101+
102+
Finally, start the Containerd service.
103+
```bash
104+
$ sudo systemctl start containerd
105+
$ sudo systemctl enable containerd
106+
```
107+
### Verify the installation with KVM
108+
109+
---
110+
111+
You are now ready to run Kata Containers with KVM.
112+
First, ensure the `KVM` and `VSOCK` modules are loaded.
113+
```bash
114+
$ sudo modprobe kvm-intel
115+
$ sudo modprobe vhost_vsock # For QEMU
116+
$ sudo modprobe vmw_vmci # For cloud hypervisor
117+
```
118+
Then you can perform a simple test by running the following commands:
119+
```bash
120+
$ image="docker.io/library/busybox:latest"
121+
$ sudo ctr image pull "$image"
122+
$ sudo ctr run --runtime "io.containerd.kata.v2" --rm -t "$image" test-kata date
123+
$ sudo ctr run --runtime "io.containerd.kata-clh.v2" --rm -t "$image" test-kata date
124+
```
125+
The last command above will show date information in container.
126+
## Configure PVM
127+
128+
---
129+
130+
The PVM hypervisor is a Linux kernel module based on KVM. Currently, it is maintained privately and is not part of the Linux tree. We are working on merging it upstream as soon as possible. In the meantime, it requires a customized guest kernel as well.
131+
### Install PVM hypervisor
132+
133+
---
134+
135+
- **Download source code**
136+
137+
You can obtain the source code from here, which is base on `Linux kernel 6.7-rc6`**.**
138+
139+
- **Build kernel and modules**
140+
141+
To build the kernel and module, please refer to the [official kernel build documentation](https://www.kernel.org/doc/html/latest/admin-guide/README.html#documentation). In the menuconfig, select `CONFIG_KVM_PVM`. Then, use the make command to build the kernel and module.
142+
> **Note**: PVM is not currently available with PTI (Page Table Isolation). You can either disable PTI during the building process or disable it during the booting later.
143+
144+
```bash
145+
$ make oldefconfig # use old config and set new symbols to theie default values
146+
$ make menuconfig # select kvm-pvm module, which is
147+
# under Virtualization menu
148+
$ make -j # build kernel and modules
149+
$ sudo make modules_install install # install kernel and modules
150+
```
151+
152+
- **Reboot with new kernel**
153+
154+
Add the additional kernel boot parameter `pti=off` to the kernel cmdline. Then you can reboot the host.
155+
156+
- **Load pvm module**
157+
> **Note:** Currently, kvm-intel.ko and kvm-amd.ko cannot coexist with kvm-pvm.ko. Therefore, you must unload them first before loading kvm-pvm.ko.
158+
159+
```bash
160+
$ sudo rmmod kvm-intel
161+
$ sudo rmmod kvm
162+
$ sudo modprobe kvm-pvm
163+
```
164+
### Install PVM guest kernel
165+
166+
---
167+
168+
- **Download source code**
169+
170+
You can obtain source code from here, which is base on `Linux kernel 6.7-rc6`**.**
171+
172+
- **Build kernel**
173+
174+
To build the guest kernel, please refer to the [official kernel build documentation](https://www.kernel.org/doc/html/latest/admin-guide/README.html#documentation). Additionally, we provide a configuration file based on the default configuration for the guest kernel from Kata Containers.
175+
```bash
176+
$ wget # copy the customized config
177+
$ make olddefconfig
178+
$ make -j vmlinux # build kernel
179+
```
180+
181+
- **Install kernel**
182+
183+
You can move the guest kernel to the default path for Kata Containers.
184+
```bash
185+
$ sudo cp vmlinux /opt/kata/share/kata-containers/vmlinux-pvm
186+
```
187+
### Verify Kata Containers with PVM
188+
189+
---
190+
191+
#### Configure QEMU for PVM
192+
QEMU would [override the guest cpuid](https://gitlab.com/qemu-project/qemu/-/blame/master/target/i386/kvm/kvm.c#L1861) (`KVM_CPUID_SIGNATURE`) provided by the hypervisor, so we currently need to skip the cpuid verification in the PVM guest for QEMU.
193+
```c
194+
diff --git a/arch/x86/kernel/head64_identity.c b/arch/x86/kernel/head64_identity.c
195+
index 41167f071528..a1d3fc30d267 100644
196+
--- a/arch/x86/kernel/head64_identity.c
197+
+++ b/arch/x86/kernel/head64_identity.c
198+
@@ -417,6 +417,7 @@ static bool __head detect_pvm(void)
199+
if ((cs & 3) != 3)
200+
return false;
201+
202+
+ return true;
203+
/* check KVM_SIGNATURE and KVM_CPUID_VENDOR_FEATURES */
204+
eax = KVM_CPUID_SIGNATURE;
205+
pvm_cpuid(&eax, &signature[0], &signature[1], &signature[2]);
206+
```
207+
And we only support using qboot as the BIOS for QEMU instead of SeaBIOS, so please change the configuration file (`/opt/kata/share/defaults/kata-containers/configuration.toml`) to use qboot. Additionally, please change the guest kernel path option too.
208+
> kernel = "/opt/kata/share/kata-containers/vmlinux-pvm"
209+
> firmware = "/opt/kata/share/kata-qemu/qemu/qboot.rom"
210+
211+
#### Configure Cloud Hypervisor for PVM
212+
Due to the [virtio-vsock issue](https://github.com/cloud-hypervisor/cloud-hypervisor/issues/5691), the rust vmm (including Dragonball, Cloud Hypervisor and Firecracker) installed in the Kata Container package cannot support PVM guest. We have only found that Cloud Hypervisor has fixed the issue, so we should use version 35.0 or higher of Cloud Hypervisor.
213+
```bash
214+
$ sudo wget https://github.com/cloud-hypervisor/cloud-hypervisor/releases/download/v37.0/cloud-hypervisor-static -O /opt/kata/bin/cloud-hypervisor
215+
```
216+
Then please change the guest kernel option in configuration file (`/opt/kata/share/defaults/kata-containers/configuration.toml`) .
217+
> kernel = "/opt/kata/share/kata-containers/vmlinux-pvm"
218+
219+
#### Verify Kata Containers with PVM
220+
You can perform a simple test by running the following commands:
221+
```bash
222+
$ image="docker.io/library/busybox:latest"
223+
$ sudo ctr image pull "$image"
224+
$ sudo ctr run --runtime "io.containerd.kata.v2" --rm -t "$image" test-kata date
225+
$ sudo ctr run --runtime "io.containerd.kata-clh.v2" --rm -t "$image" test-kata date
226+
```
227+
The last command above will show date information in container.
228+
## Verify Kata Containers with PVM using VM image
229+
230+
---
231+
232+
We provide a VM image based on the `Official Ubuntu Cloud Image`, which you can use to test Kata Containers with PVM directly.
233+
234+
- **Download VM image**
235+
236+
You can obtain the VM image from the following url.
237+
```bash
238+
$ wget xx -O ubuntu-22.04-pvm.img
239+
```
240+
241+
- **Start VM**
242+
243+
You can use QEMU to boot it, and run the previous test command. Then, login with the `root` account and the default password is "`root`".
244+
```bash
245+
qemu-system-x86_64 -machine accel=kvm \
246+
-cpu host \
247+
-m 4G \
248+
-smp cores=2,threads=1 \
249+
-nographic \
250+
-device virtio-net-pci,netdev=net0 \
251+
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
252+
-drive if=virtio,format=qcow2,file=ubuntu-22.04-pvm.img
253+
```
254+
255+
- **Test running**
256+
257+
You can perform a simple test by running the following commands:
258+
```bash
259+
$ image="docker.io/library/busybox:latest"
260+
$ sudo ctr run --runtime "io.containerd.kata.v2" --rm -t "$image" test-kata date
261+
$ sudo ctr run --runtime "io.containerd.kata-clh.v2" --rm -t "$image" test-kata date
262+
```
263+
The last command above will show date information in container.
264+

sosp2023-pvm-paper.pdf

2.06 MB
Binary file not shown.

sosp2023-pvm-slides.pptx

1.94 MB
Binary file not shown.

0 commit comments

Comments
 (0)