Alan Stokes | c3f2ac2 | 2022-06-23 12:19:46 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2022 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //! Detection for nested virtualization. |
| 18 | |
| 19 | use anyhow::Result; |
| 20 | use rustutils::system_properties; |
| 21 | |
| 22 | /// Return whether we will be running our VM in a VM, which causes the nested VM to run very slowly. |
| 23 | pub fn is_nested_virtualization() -> Result<bool> { |
| 24 | // Currently nested virtualization only occurs when we run KVM inside the cuttlefish VM. |
| 25 | // So we just need to check for vsoc. |
| 26 | if let Some(value) = system_properties::read("ro.build.product")? { |
| 27 | // Fuzzy matching to allow for vsoc_x86, vsoc_x86_64, vsoc_x86_64_only, ... |
| 28 | Ok(value.starts_with("vsoc_x86")) |
| 29 | } else { |
| 30 | Ok(false) |
| 31 | } |
| 32 | } |