mapping foreign hypervisor page to userspace

Not sure if this is the path I want to follow yet, but I may need to take a page from a foreign VM (under xen), map it into the memory of the windows VM, then allow a userspace application to directly access the memory. This would allow a way to communicate with a foreign VM completely via userspace. I think I can do this like:

  1. App allocates memory (page aligned)
  2. App passes memory to Driver via async IOCTL DIRECT_IO
  3. Driver holds on to the IOCTL until it gets a cancel from the App
  4. Driver swaps the physical page of memory with the one from the foreign VM (there is a hypercall to do this)
  5. Driver signals App that the mapping is complete (not sure how yet… app probably has to ask via IOCTL)
  6. App can now access the memory
  7. When closing, the App sends a cancel to the Driver
  8. Driver swaps the physical pages back, and completes the IOCTL
  9. App frees the memory

If the foreign VM crashes or something then I would like a mechanism for the App to close in a graceful way. I don’t know exactly how Xen handles the case of a VM with pages mapped elsewhere yet though so I can’t speculate on how to approach this.

Does that sound like the right way to do it?

Thanks

James