This page includes information on how to build and deploy Xen on Xilinx boards, including both Xilinx Ultrascale+ and Versal boards.
Table of Contents
The guide below shows you how to build Xen, boot Xen and then run some example configurations. The steps below use PetaLinux and assume you have some knowledge of using PetaLinux. Before starting you need to create a PetaLinux project. It is assumed that a default PetaLinux reference design is used unchanged in these instructions. The default PetaLinux configuration has images ready to do boot Xen, these are the pre-built images. You can use those or you can manually edit recipes and build Xen yourself. The pre-built images can be found in this directory (inside a PetaLinux project) pre-built/linux/xen. You can either use the pre-builts or follow the next section to configure and build Xen yourself. If you are using the pre-builts you can skip to the booting Xen section for your release version.
Configuring and building XEN from source using PetaLinux
First let's enable Xen to be built by default.
Now let's enable Xen:
Now we need to change the rootFS to be an INITRD
You can still use the prebuilt Image file which does still include the rootFS to boot DomU.
We also want to edit the device tree to build in the extra Xen related configs.
Edit this file
and add this line: /include/ "xen.dtsi".
It should look like this for harware:
or like this for QEMU:
NOTE: There is a bug on QEMU where the CPUs running in SMP sometimes cause hangs. To avoid this we only tell Xen about a single CPU.
Also edit this file:
and add this line to it: file://xen.dtsi.
The file should look like this:
Then run petaliux-build:
TFTP Booting Xen and Dom0
Run Xen dom0 on QEMU
To use the prebuilt Xen run:
To use the Xen you built yourself run:
Run Xen dom0 on HW
To use the prebuilt Xen on hardware:
To use the Xen you built yourself run:
You should eventually see something similar to this, when you do press any key to stop the autoboot.
If u-boot wasn't able to get an IP address from the DHCP server you may need to manually set the serverip (it's typically 10.0.2.2 for QEMU):
Now to download and boot Xen, if running on QEMU, use xen-qemu.dtb otherwise use xen.dtb. Example:
TFTPing Xen using ImageBuilder
ImageBuilder is a set of Open Source community scripts to automatically configure a Xen system with Dom0 and multiple Dom0-less VMs for booting. ImageBuilder can generate a U-Boot script that loads all of the binaries automatically and boot the full system quickly. ImageBuilder is available here. The main script is scripts/uboot-script-gen and its usage is described in details on the Xen Project wikipage.
Petalinux prebuilt binaries can be used in a config file as follows for uboot-script-gen:
Now uboot-script-gen can be used to generate boot.scr:
Boot the system with the following uboot command (assuming the tftp serverip is 10.0.2.2, which is typically the value for QEMU):
The Xen and Dom0 command line are generated by uboot-script-gen. If you would like to change anything, for instance increase the dom0 memory allocation, it is always possible by editing boot.source. Simply do the following:
- edit boot.source, change dom0_mem to dom0_mem=2G
- regenerate boot.scr with the following command: mkimage -A arm64 -T script -C none -a 0xC00000 -e 0xC00000 -d boot.source boot.scr
SD Booting Xen and Dom0
To boot Xen from an SD card you need to copy the following files to the boot partition of the SD card:
- the compiled device tree file renamed to system.dtb (xen.dtb or xen-qemu.dtb for QEMU from the pre-built images, system.dtb from a Petalinux build)
When using the pre-built images from the BSP, copy these files from <project-dir>/pre-built/linux/xen.
Booting with ImageBuliderImageBuilder's script uboot-script-gen can be used to generate a uboot script that loads all the binaries automatically from MMC. Call uboot-script-gen with the following command, assuming that $sdbootdev is 0 and $partid is 1:
Copy the generated boot.scr onto the boot partition of the SD card. Boot the system with the following U-Boot command:
Graphical Desktop in Dom0
To get a graphic desktop, e.g. matchbox, working in dom0, it is necessary to add two SMIDs to device tree: the SMID 0xce3 for zynqmp-display@fd4a0000 and SMID 0xce4 for dma@fd4c0000. The attached DTB comes with the necessary modifications.
Starting simple additional guests
If running on QEMU, we'll need to setup a port mapping for port 22 (SSH) in our VM.
In this example, we forward the hosts port 2222 to the VM's port 22.
Once you hit the u-boot prompt, follow the steps in the earlier section on how to run Xen dom0.
When dom0 has finished booting, we'll need to copy a guest Image into dom0's filesystem.
We'll use the base prebuilt PetaLinux Image as our domU guest.
If running on QEMU, we use scp's -P option to connect to our hosts port 2222 where QEMU will forward the connection to the guests port 22:
To target QEMU run the following on the host:
If running on hardware run the following on the host:
If you would prefer to load DomU's kernel to the guest via SD card, you can follow the instructions in the "Starting Linux guests with Pass-through networking" section.
The xen-image-minimal rootFS includes some prepared configurations that you can use. These are located in '/etc/xen/'
To start a simple guest run the following from the dom0 prompt
You'll see another instance of Linux booting up.
At any time you can leave the console of the guest and get back to dom0 by pressing ctrl+]
Once at the dom0 prompt you can list the guests from dom0:
To get back to the guests console:
You can create further guests by for example running:
To destroy a guest:
The following will only work on QEMU with multi-core enabled or on real HW.
When running multiple guests with multiple Virtual CPUs, Xen will schedule the various vCPUs onto real physical CPUs.
The rules and considerations taken in scheduling decisions depend on the chosen scheduler and the configuration.
To avoid having multiple vCPUs share a single pCPU, it is possible to pin a vCPU onto a pCPU and to give it exclusive access.
To create a simple guest with one Virtual CPU pinned to Physical CPU #3, you can do the following:
Another way to pin virtual CPUs on to Physical CPUs is to create dedicated cpu-pools.
This has the advantage of isolating the scheduling instances.
By default a single cpu-pool named Pool-0 exists. It contains all the physical cpus.
We'll now create our pool named rt using the credit2 scheduler.
Now we are ready to create a guest with a single vcpu pinned to physical CPU #3.
Starting Linux guests with Para-Virtual networking (PV network)
IMPORTANT: due to a bug, it is necessary to rebuild Xen 2020.1 and 2020.2 with this patch applied to Xen to get PV drivers to work, including PV network.
This time we will run QEMU slightly different. We'll create two port mappings. One for dom0's SSH port and another for the Para-Virtual domU.
The default IP addresses assigned by QEMUs builtin DHCP server start from 10.0.2.15 and count upwards.
Dom0 will be assigned 10.0.2.15, the next guest 10.0.2.16 and so on.
So here's the command line that maps host port 2222 to dom0 port 22 and 2322 to domUs port 22.
Now, follow the instructions from section 1 on how to boot Xen dom0.
Once you are at the dom0 prompt and have copied a domU image (see earlier steps) we'll need to setup the networking.
In this example, we will configure the guests to directly join the external network by means of a bridge.
First of all, we need to de-configure the default setup.
Kill the dhcp client for eth0:
List and remove existing addresses from eth0:
In our example the address is 10.0.2.15/24:
Then, create the bridge and start DHCP on it for dom0:
You should see something like the following:
Similar to before we will use the pre-defined examples in '/etc/xen/'
The start DomU
You should see a new linux instance boot up.
Now we'll ssh into the domU from the host running Para-Virtual networking:
Starting Linux guests with Pass-through networking
It is possible to directly assign the network peripheral to a domU on both ZU+ and Versal. The following example is for ZU+.
Turn xen.dtb into xen.dts:
The, edit xen.dts by adding xen,passthrough; under the node of the device to assign, in this case ethernet@ff0e0000:
Convert xen.dts back into xen.dtb:
Starting a Guest with a Passthrough SD Card
It is possible to directly assign the MMC controller to a domU on both ZU+ and Versal. The following example is for ZU+ only. It allows a Xen DomU full unmediated access to a SD card plugged into the board.
Add the following lines to the xl config file for the VM:
Where passthrough-example-part.dtb is the following attached file:
Also, you need to add xen,passthrough; under the mmc node in the host device tree so that it doesn't get automatically assigned to dom0:
Finally, make sure to run the following commands at boot from xsdb to configure the system so that normal-world MMC DMA goes via the SMMU:
For MMC assignment to a dom0less guest, use the attached partial device tree binary:
To use it, just add it to your ImageBuilder config as follows:
Regenerate the boot.scr and boot.source scripts as usual with ImageBuilder’s uboot-script-gen.
As for the traditional Dom0 case, it is also necessary to add xen,passthrough; under the mmc node in the host device tree, and issue the three special writes at boot time to configure the system so that normal-world MMC DMA goes via the SMMU.
Starting a guest with a passthrough SATA disk
It is possible to directly assign the SATA controller to a domU on both ZU+ and Versal. The following example is for ZU+ only. It allows a Xen DomU full unmediated access to any SATA disks connected to it.
Add the following lines to the xl config file for the VM:
Where passthrough-example-sata.dtb is this attached file.
Then, you need to add xen,passthrough; under the ahci@fd0c0000 node in the host device tree so that it doesn't get automatically assigned to dom0:
It is also necessary to add the four SMIDs of the SATA controller to device tree: 0x4c0, 0x4c1, 0x4c2, 0x4c3:
The attached DTB comes with the necessary modifications.
Finally, make sure to run the following commands at boot from xsdb to configure the system so that normal-world SATA DMA goes via the SMMU: