Skip to content

Commit

Permalink
vmm:qemu support aarch64
Browse files Browse the repository at this point in the history
Signed-off-by: liuxu <[email protected]>
  • Loading branch information
root authored and liuxu committed Oct 22, 2024
1 parent f7cca8a commit 18dd86f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions vmm/sandbox/src/qemu/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::{
};

use containerd_sandbox::error::{Error, Result};
#[cfg(target_arch = "x86_64")]
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
use lazy_static::lazy_static;
use sandbox_derive::{CmdLineParamSet, CmdLineParams};
use serde::{Deserialize, Serialize};
Expand All @@ -40,24 +40,34 @@ const DEFAULT_QEMU_PATH: &str = "/usr/bin/qemu-system-x86_64";
#[cfg(target_arch = "aarch64")]
const DEFAULT_QEMU_PATH: &str = "/usr/bin/qemu-system-aarch64";

#[cfg(target_arch = "x86_64")]
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
lazy_static! {
static ref SUPPORTED_MACHINES: HashMap<String, Machine> = {
let mut sms = HashMap::new();
#[cfg(target_arch = "x86_64")]
sms.insert(
"microvm-pci".to_string(),
Machine {
r#type: "microvm-pci".to_string(),
options: None,
},
);
#[cfg(target_arch = "x86_64")]
sms.insert(
"pc".to_string(),
Machine {
r#type: "pc".to_string(),
options: Some("accel=kvm,kernel_irqchip=on".to_string()),
},
);
#[cfg(target_arch = "aarch64")]
sms.insert(
"virt".to_string(),
Machine {
r#type: "virt".to_string(),
options: Some("usb=off,accel=kvm,gic-version=3".to_string()),
},
);
sms
};
}
Expand Down Expand Up @@ -155,17 +165,17 @@ impl QemuVMConfig {
} else {
return Err(Error::InvalidArgument("cpu model".to_string()));
}
#[cfg(target_arch = "x86_64")]
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
if let Some(machine) = SUPPORTED_MACHINES.get(&self.machine_type) {
result.machine = machine.clone();
} else {
return Err(Error::InvalidArgument(
"machine_type not supported!".to_string(),
));
}
#[cfg(not(target_arch = "x86_64"))]
#[cfg(not(any(target_arch = "x86_64", target_arch = "aarch64")))]
return Err(Error::Unimplemented(
"cpu other than x86 not supported".to_string(),
"cpu other than x86 or aarch64 not supported".to_string(),
));
if !self.firmware_path.is_empty() {
result.bios = Some(self.firmware_path.to_string());
Expand Down

0 comments on commit 18dd86f

Please sign in to comment.