Memory sharing

Guests in a hypervisor system can share memory regions through which they can pass data to each other or to the hypervisor host.

In a QNX hypervisor system, client applications running in guests can create and manage shared memory, and use shared memory regions to exchange data. Note, however, that shared memory regions are ultimately created and controlled by the hypervisor; not by the guest. Host applications may also create shared memory regions or attach to them if permission allows.

The hypervisor-shmem-examples-*.tgz archive available with QNX hypervisors includes source code for sample memory-sharing programs: ghstest.c for a QNX guest and hhstest.c for the hypervisor host.

To write hypervisor host modules that can share data with guests, you need to use the Virtualization API (libhyp.a). This is described in the Virtualization API Reference that's not included with the QNX hypervisor documentation. To obtain this additional documentation and support for writing host modules, contact your QNX representative.

How shared memory works

To use shared memory, a client application in a guest or in the hypervisor host needs:

The hypervisor provides the shmem vdev, which implements setting up the shared memory mapping and the interrupts you need to use shared memory. This vdev provides additional functionality to simplify using shared memory, including:

Figure 1. A 128 MB memory allocation (“moo”) shared by Guest 0 and Guest 1

The figure above illustrates memory sharing between two guests. Guest 0 attempts to attach to a 128 MB shared memory area (“moo”) first. Since no such area exists at the specified location, the attempt to attach creates the area and allows the guest to attach to it. Guest 1 can simply attach to the same name to share data with Guest 0.

Note:

All connections to a shared memory region are peers. That is, there is no distinction between the guest that creates a shared memory region and the guest that attaches to it. Simply, the first attempt to attach to a shared memory region creates the region. As far as the guest is concerned, it simply attaches to the region.

This design avoids ordering problems where the system designer would have to make sure that one guest always comes up and creates the shared memory region before another guest tries to attach to it.