Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
    reserved-memory {
        #address-cells = <0x2>;
        #size-cells = <0x2>;
        ranges;


        xen-shmem@70000000 {
            compatible = "xen,shared-memory-v1";
            reg = <0x0 0x70000000 0x0 0x1000>;
        };
    };

...

This feature allows sharing one or more pages in memory across VMs, simply by adding one config option to the VM config file. Memory can be shared as cacheable memory. Here is an example:

Code Block
# Add following to the config file of VM1:

...

 
static_shm = ["id=ID1, begin=0x40000000, size=0x1000, role=owner"]

...



# Add following to the config file of VM2:

...

 
static_shm = ["id=ID1, begin=0x48000000, size=0x1000, role=borrower"]

In this example we are sharing one page owned by VM1 with VM2. The owner of the page is the "owner" VM (VM1), while the other VM is called "borrower" (VM2). The memory of Xen VMs always starts at 0x40000000 (guest physical address), so in this example we are sharing the first page of VM1 with VM2. Make sure to choose a valid allocated address of the owner VM.

...

The shared page is advertised as "reserved-memory" in the guest device tree. This is a sample device tree node of a guest with a static_shm configuration:

...

Code Block
reserved-memory {

...


                #address-cells = <0x2>;

...


                #size-cells = <0x2>;

...


                ranges;

...



                xen-shmem@40000000 {

...


                        compatible = "xen,shared-memory-v1";

...


                        id = "ID1";

...


                        reg = <0x0 0x40000000 0x0 0x1000>;

...


                };

The guest is free to use the reserved-memory region as it wishes. For instance, in the case of the Linux kernel, it is possible to export the memory as cacheable memory to userspace with a dmabuf driver. See this proof of concept of Linux driver and userspace user-space program:

https://git.kernel.org/pub/scm/linux/kernel/git/sstabellini/xen.git xen-dmabuf

https://github.com/sstabellini/dmabuf-user xen-dmabufXen-dmabuf Linux driver

xen-dmabuf user space program