virtualizationservice: Fix race in monitor_vm_exit

monitor_vm_exit() runs in a detached thread, waiting for an instance of
crosvm to exit. When it does, it cleans up after it and submits
telemetry to statsd.

However, there is currently no guarantee that the thread will get to
complete its task. If exit() is called, eg. because there are no
remaining clients of the service, the thread is interrupted and
terminated together with the rest of the process. Whether it completes
its job or not therefore can depend on the delay between the last
VirtualMachine reference is dropped and LazyServiceGuard terminating
the process.

Fix this race by joining the monitor_vm_exit as the VirtualMachine
object is dropped. This prevents the process from exiting until the
thread has completed.

Bug: 245727626
Test: atest -p packages/modules/Virtualization:avf-presubmit
Change-Id: Iefbd4181a8ca95bbb3a4fed0f85d9929d081ff73
1 file changed
tree: c7df0e74582724fdac39f0b62c875f64adba9df4
  1. apex/
  2. apkdmverity/
  3. authfs/
  4. avmd/
  5. compos/
  6. demo/
  7. docs/
  8. encryptedstore/
  9. javalib/
  10. launcher/
  11. libs/
  12. microdroid/
  13. microdroid_manager/
  14. pvmfw/
  15. rialto/
  16. tests/
  17. virtualizationservice/
  18. vm/
  19. vm_payload/
  20. vmbase/
  21. vmclient/
  22. zipfuse/
  23. .clang-format
  24. .gitignore
  25. Android.bp
  26. OWNERS
  27. PREUPLOAD.cfg
  28. README.md
  29. 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.