Memory can be shared between guests and between Dom0 and guests. This page describes the details needed for sharing memory.
Table of Contents
|Table of Contents|
IntroductionThe following description is one way to accomplish the shared memory and there may be others. The following technique was last tested with the 2017.1 Xilinx release of Petalinux. The following paragraphs describe the process by which some memory is taken from Linux in the device tree and then added as a UIO device in the device tree. It is assumed the user has basic device tree skills understanding how to make changes to existing nodes and adding new nodes together with a basic understand of Xen guest configuration files.
The memory is accessed in Dom0 and the guest as I/O memory rather than normal memory such that performance is not a primary concern. This is the only easy configuration that is supported by default with Xen.
Dom0 Device Tree Changes
Adding Shared Memory
The UIO driver in Linux is used to access the shared memory from Dom0. Note that the iomem statement in the Xen guest configuration file allocates memory in 4K pages so that a 4K minimum is used. The following device tree snippet illustrates how to add the shared memory node.
#stream-id-cells = <0x1>;
compatible = "uio-dev";
reg = <0x0 0x7FFFF000 0x0 0x1000>;
Alter Linux Memory
Alter the amount of memory for Linux removing a 4K region which will be used by the UIO driver in Dom0. The following device tree snippet illustrates the memory with 4K less.
device_type = "memory";
reg = <0x0 0x0 0x0 0x7FFFF000>;
Linux Kernel Command Line
The command line of Linux is altered to allow the UIO driver to work with the shared memory node that was added. The following command line illustrates the addition of the UIO kernel module parameter initialization to allow the UIO driver to be compatible with the shared memory node in the device tree.
xen,dom0-bootargs = "console=hvc0 earlycon=xen earlyprintk=xen maxcpus=1 clk_ignore_unused uio_pdrv_genirq.of_id=uio-dev";
Note that the string "uio-dev" only has to match the compatible property of the shared memory node and could be any string.
The Xen guest configuration file is altered to use the shared memory as Device I/O memory. The following line illustrates the I/O mem line that allows the guest access to the shared memory together with the 2nd UART.
iomem = [ "0x7FFFF,1", "0xFF010,1" ]
More details can be found here:
The general syntax is:
iomem=[ "IOMEM_START,NUM_PAGES[@GFN]", "IOMEM_START,NUM_PAGES[@GFN]", ...]
For example, to map a page starting at physical address 0xFFFF0000 into a guest at address 0:
iomem = [ "0xFFFF0@0x0,1" ]