Xen Hypervisor Gets Ported to the Raspberry Pi, Shakes Out Bugs in the Linux Kernel

An "easy" porting task turned into a bug-hunt in the Linux kernel, but Xen is now officially available on the Raspberry Pi 4 family.

The Xen Project, maintainer of the popular hypervisor of the same name, has announced it has now ported its tool to the Raspberry Pi 4 single-board computer — complete with a tutorial for anyone looking to get started.

"We have always been eager to get the Xen hypervisor running on [the Raspberry Pi], but technical differences between RPi and other Arm platforms made it impractical for the longest time," Xen's Stefano Stabellini and Roman Shaposhnik explain in a joint announcement. "Specifically, a non-standard interrupt controller without virtualization support. Then the Raspberry Pi 4 came along, together with a regular GIC-400 interrupt controller that Xen supports out of the box."

"Soon Roman Shaposhnik of Project EVE and a few other community members started asking about it on the 'xen-devel' mailing list. 'It should be easy,' we answered. 'It might even work out of the box,' we wrote in our reply. We were utterly oblivious that we were about to embark on an adventure deep in the belly of the Xen memory allocator and Linux address translation layers."

That "easy" porting process proved anything but: The porting team had to work around devices' ability to access enough memory below 1GB, which was initially thought to be a one-line fix but turned into a bug-hunt in address translation within the Linux kernel itself.

Once that was sorted, another bug was found: "None of the x86, ARM, and ARM64 platforms where Xen could run had DMA addresses different from physical addresses," the pair states. "The Xen subsystem in Linux is exploiting the DMA/physical address duality for its own address translations. It uses it to convert physical addresses, as seen by the guest, to physical addresses, as seen by Xen."

"To our surprise and astonishment, the Raspberry Pi 4 was the very first platform to have physical addresses different from DMA addresses, causing the Xen subsystem in Linux to break. It wasn’t easy to narrow down the issue. Once we understood the problem, a dozen patches later, we had full support for handling DMA/physical address conversions in Linux. The Linux patches are in master and will be available in Linux 5.9."

For those willing to live at the cutting edge, the Xen Project has a tutorial on installing the Xen hypervisor on a Raspberry Pi 4 via TFTP; those looking for an off-the-shelf way to get started will find early support in LF Edge Project EVE, an Internet of Things (IoT) operating system built to be secure by design.

More information is available on the Xen blog.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles