pvmfw: Improve memory sharing with the host

Instead of issuing memory sharing/unsharing HVCs every time alloc_shared
and dealloc_shared are called, introduce a MemorySharer object to share
pages from the global allocator on demand and keep them in a pool until
its destructor is called, at which point, it unshares all the regions
and returns them to the heap.

This allows the backends for memory sharing to be unified behind a
unique SHARED_POOL heap that is either populated by the MemorySharer on
pKVM or covers the statically shared region on Gunyah. On pKVM,
alloc_shared calls will only result in MEM_SHARE HVCs if SHARED_POOL
isn't already large enough to fulfill the request.

This also guarantees that all pages that have been been shared during
pvmfw execution have been unshared by the time the guest OS is entered,
even if an alloc_shared hasn't been matched with a dealloc_shared call.

By caching the granule size in the MemorySharer ctor, this removes the
need to issue a granule-discovery HVC every time memory is being shared
or unshared with the host.

Bug: 280644106
Test: atest MicrodroidHostTests
Change-Id: I3992e7c59ea79897e93bccc043d4438acbc0586c
4 files changed
tree: af2ef16b2ba132ed1a81bc4f2c09e6740acd2b1f
  1. apex/
  2. apkdmverity/
  3. authfs/
  4. compos/
  5. demo/
  6. docs/
  7. encryptedstore/
  8. javalib/
  9. launcher/
  10. libs/
  11. microdroid/
  12. microdroid_manager/
  13. pvmfw/
  14. rialto/
  15. service_vm/
  16. tests/
  17. virtualizationmanager/
  18. virtualizationservice/
  19. vm/
  20. vm_payload/
  21. vmbase/
  22. vmclient/
  23. zipfuse/
  24. .clang-format
  25. .gitignore
  26. Android.bp
  27. OWNERS
  28. PREUPLOAD.cfg
  29. README.md
  30. TEST_MAPPING
README.md

Virtualization

This repository contains userspace services related to running virtual machines on Android, especially protected virtual machines. See the getting started documentation and Microdroid README for more information.