Part 6 of 6 · 3 min read
Exercises
Easy
Easy 1: Host or guest (20 minutes)
A VirtualBox window shows Ubuntu running on a Windows laptop. Name the host, the guest and the type of hypervisor.
Done when: host Windows, guest Ubuntu, type 2.
Hint
the guest is the system inside the VM.
Easy 2: Promised resources (20 minutes)
A server has 128 GiB of memory. It runs 10 guests of 16 GiB each. How much memory is promised, and is it more than the server has?
Done when: 160 GiB promised against 128 GiB, so 32 GiB (25 per cent) more.
Hint
10 x 16.
Easy 3: Ratio (20 minutes)
A trapped instruction takes 6,000 ns and an untrapped one 15 ns. How many times slower is the trapped one?
Done when: 400.
Hint
divide 6,000 by 15.
Medium
Medium 1: Exits per second (45 minutes)
A guest does 50,000 operations per second and each causes 1 exit of 5 microseconds. What fraction of each second is spent in exits?
Done when: 50,000 x 5 us = 0.25 s, so 25 per cent.
Hint
multiply and compare with one second.
Medium 2: Run it (45 minutes)
Compile the program of section 4 and run it five times on your machine. Report the two timings and the ratio. If your machine is not a VM, say so.
Done when: five lines of output, a ratio, and a sentence on whether the machine is a guest.
Hint
gcc -O1 cpuid.c -o cpuid (the header is cpuid.h).
Medium 3: Detect (45 minutes)
Run lscpu, systemd-detect-virt and grep -c hypervisor /proc/cpuinfo on your machine and explain each output.
Done when: all three results are explained, with a statement on whether you run in a VM or a container.
Hint
look for "Hypervisor vendor" in lscpu.
Hard
Hard 1: Which instruction traps (90 minutes)
Explain why add need not trap and cli must, using the idea of sensitive and privileged instructions. Give one more example of each kind.
Done when: add changes only guest registers; cli changes shared interrupt state; examples such as mov and hlt or out.
Hint
ask which instructions change state that other guests can see.
Hard 2: Cost of a design (90 minutes)
A device driver of an emulated disk causes 4 exits per 4 KiB block read. A virtio driver causes 1 exit per batch of 32 blocks. For reading 1 GiB with 4 KiB blocks, count the exits for both designs, and the time at 5 microseconds per exit.
Done when: 262,144 blocks; 1,048,576 exits (5.24 s) against 8,192 exits (0.04 s).
Hint
1 GiB / 4 KiB = 262,144.
Hard 3: Choose a hypervisor type (90 minutes)
A cloud provider runs thousands of tenants, and a developer runs two test guests on a laptop. Recommend a type for each, and give two reasons.
Done when: type 1 for the provider (speed, isolation, no host OS to attack or share), type 2 for the laptop (easy install, shares the desktop).
Hint
think of who is trusted and how many guests run.