Merge "Update is_nested_virtualization() to check for qemu" into main am: e803461baa am: d64178f629
Original change: https://android-review.googlesource.com/c/platform/packages/modules/Virtualization/+/3363947
Change-Id: I3e992bdef2f2f271eef6ee1a3410dd833a0fd41b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/libs/nested_virt/src/lib.rs b/libs/nested_virt/src/lib.rs
index b43fcb7..b2aea88 100644
--- a/libs/nested_virt/src/lib.rs
+++ b/libs/nested_virt/src/lib.rs
@@ -21,12 +21,21 @@
/// Return whether we will be running our VM in a VM, which causes the nested VM to run very slowly.
pub fn is_nested_virtualization() -> Result<bool> {
- // Currently nested virtualization only occurs when we run KVM inside the cuttlefish VM.
- // So we just need to check for vsoc.
- if let Some(value) = system_properties::read("ro.product.vendor.device")? {
- // Fuzzy matching to allow for vsoc_x86, vsoc_x86_64, vsoc_x86_64_only, ...
- Ok(value.starts_with("vsoc_"))
- } else {
- Ok(false)
+ // Nested virtualization occurs when we run KVM inside the cuttlefish VM or when
+ // we run trusty within qemu.
+ let checks = [
+ ("ro.product.vendor.device", "vsoc_"), // vsoc_x86, vsoc_x86_64, vsoc_x86_64_only, ...
+ ("ro.hardware", "qemu_"), // qemu_trusty, ...
+ ];
+
+ for (property, prefix) in checks {
+ if let Some(value) = system_properties::read(property)? {
+ if value.starts_with(prefix) {
+ return Ok(true);
+ }
+ }
}
+
+ // No match -> not nested
+ Ok(false)
}