AMD SME/SEV on Ubuntu 20
Objective
Enable AMD SME on your Ubuntu 20.04 server, and spawn a KVM/QEMU virtual machine secured with SEV
Requirements
- A dedicated server with an AMD Naples/Rome Epyc CPU
- Administrative (sudo) access to the server via SSH
- Ubuntu 20.04 installed
Instructions
Step 1 - Enable SME and SEV
Enabling SME just requires adding mem_encrypt=on on the kernel's boot cmdline. To be able to use SEV in KVM, we need to add kvm_amd.sev=1 as well.
To do this, we need to add it to GRUB_CMDLINE_LINUX_DEFAULT.
The usual way to do this is by editing /etc/default/grub, however, on Ubuntu cloud images, we need to edit this file instead: /etc/default/grub.d/50-cloudimg-settings.cfg
Here's what it looks like on a freshly installed Ubuntu 20.04, after editing the file:
Now, we need to update our grub configuration to make our change effective:
Step 2 - Reboot the server to have SME/SEV available
Let's reboot the server to apply our cmdline changes:
Once the server is back up, we should see mem_encrypt=on and kvm_amd.sev=1 in /proc/cmdline:
You should also see the following messages in dmesg:
You can also check /sys/module/kvm_amd/parameters/sev to verify that SEV is available:
Step 3 - Install/download requirements for spawning our guest VM
Install packages:
Let's download the image for our VM. We'll use an Ubuntu 20.04 cloud image:
Step 4 - Prepare the image
Let's ensure that the image is in the correct format for QEMU/KVM, and put it in the proper folder:
Since we're using a cloud image, we also need to prepare a small ISO that will configure the ubuntu user's password:
Step 5 - Launch our VM
Note: at the time of writing, there is an issue in apparmor/libvirt that wil make the above command fail with the following message:
To fix it, we'll edit /etc/apparmor.d/abstractions/libvirt-qemu to authorize rw access to /dev/sev. Here's what it should look like once edited:
Once we've succesfully spawned the VM, we can login using the credentials defined in cloud-config earlier, and check that SEV is indeed enabled:
References and additional resources
- AMD Secure Encrypted Virtualization (SEV)
- libvirt : Launch security with AMD SEV
- libvirt XML domain format - launchSecurity
- libvirt domain capabilities - SEV
- github.com/AMDESE/AMDSEV
- github.com/AMDESE/sev-tool
Go further
Join our community of users.