Skip to content

Commit 01d0365

Browse files
committed
update
1 parent 23bdc0a commit 01d0365

File tree

7 files changed

+54
-74
lines changed

7 files changed

+54
-74
lines changed

Cargo.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[workspace]
2+
exclude = [
3+
"modules/axvisor_api",
4+
"arceos",
5+
]
26
members = [
37
"crates/*",
48
"modules/*",
59
"platform/*",
610
"xtask",
711
"kernel",
812
]
9-
exclude = [
10-
"modules/axvisor_api",
11-
"arceos",
12-
]
1313
resolver = "3"
1414

1515
[profile.release]
@@ -23,6 +23,7 @@ license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPubL-2.0 OR MulanPSL2"
2323
version = "0.1.0"
2424

2525
[workspace.dependencies]
26+
axvm-types = "0.1"
2627
bitflags = "2.2"
2728
cfg-if = "1.0"
2829
cpumask = "0.1.0"
@@ -34,7 +35,7 @@ log = "0.4"
3435
spin = "0.9"
3536
timer_list = "0.1"
3637
toml = "0.9"
37-
axvm-types = "0.1"
38+
vm-allocator = {git = "https://github.com/rust-vmm/vm-allocator.git", ref = "c66cfac", default-features = false }
3839

3940
# System dependent modules provided by ArceOS.
4041
axstd = {git = "https://github.com/arceos-hypervisor/arceos.git", tag = "hv-0.4.1", features = [
@@ -57,8 +58,6 @@ axmm = {git = "https://github.com/arceos-hypervisor/arceos.git", tag = "hv-0.4.1
5758
axnet = {git = "https://github.com/arceos-hypervisor/arceos.git", tag = "hv-0.4.1"}
5859
axtask = {git = "https://github.com/arceos-hypervisor/arceos.git", tag = "hv-0.4.1"}
5960

60-
61-
6261
axplat = {git = "https://github.com/arceos-hypervisor/axplat_crates.git", tag = "vmm-v0.3.0"}
6362

6463
# System dependent modules provided by ArceOS-Hypervisor.
@@ -92,21 +91,21 @@ axplat-x86-qemu-q35 = {path = "platform/x86-qemu-q35"}
9291
axvmconfig = "0.1"
9392

9493
[patch.crates-io]
95-
axvmconfig = { path = "modules/axvmconfig" }
96-
axvisor_api = { path = "modules/axvisor_api" }
97-
axdevice_base = { path = "modules/axdevice_base" }
98-
axaddrspace = { path = "modules/axaddrspace" }
9994
arm_vcpu = {path = "modules/arm_vcpu"}
10095
arm_vgic = {path = "modules/arm_vgic"}
96+
axaddrspace = {path = "modules/axaddrspace"}
97+
axdevice_base = {path = "modules/axdevice_base"}
10198
axvcpu = {path = "modules/axvcpu"}
102-
x86_vlapic = {path = "modules/x86_vlapic"}
103-
x86_vcpu = {path = "modules/x86_vcpu"}
99+
axvisor_api = {path = "modules/axvisor_api"}
104100
axvm-types = {path = "modules/axvm-types"}
101+
axvmconfig = {path = "modules/axvmconfig"}
102+
x86_vcpu = {path = "modules/x86_vcpu"}
103+
x86_vlapic = {path = "modules/x86_vlapic"}
105104

106105
[patch."https://github.com/arceos-hypervisor/axdevice".axdevice]
107106
path = "modules/axdevice"
108107

109108
[patch."https://github.com/arceos-hypervisor/arceos"]
109+
axalloc = {path = "modules/axalloc"}
110110
axconfig = {path = "modules/axconfig"}
111111
axruntime = {path = "modules/axruntime"}
112-
axalloc = {path = "modules/axalloc"}

kernel/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn main() {
2525
// info!("Hardware support: {:?}", axvm::has_hardware_support());
2626

2727
vmm::init();
28-
vmm::start();
28+
vmm::start_preconfigured_vms().unwrap();
2929

3030
info!("[OK] Default guest initialized");
3131

kernel/src/vmm/config.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,11 @@ use std::string::ToString;
22

33
use alloc::vec::Vec;
44
use anyhow::bail;
5-
use axvm::config::AxVMCrateConfig;
5+
use axvm::{AxVMConfig, Vm, config::AxVMCrateConfig};
66

7-
pub fn init_guest_vms() -> anyhow::Result<()> {
8-
let vm_configs = get_guest_prelude_vmconfig()?;
7+
use crate::vmm::vm_list::VMRef;
98

10-
for config in vm_configs.iter() {
11-
init_guest_vm(config)?;
12-
}
13-
14-
Ok(())
15-
}
16-
17-
fn get_guest_prelude_vmconfig() -> anyhow::Result<Vec<AxVMCrateConfig>> {
9+
pub fn get_guest_prelude_vmconfig() -> anyhow::Result<Vec<AxVMCrateConfig>> {
1810
let mut vm_configs = Vec::new();
1911
// First try to get configs from filesystem if fs feature is enabled
2012
let mut gvm_raw_configs = config::filesystem_vm_configs();
@@ -39,12 +31,6 @@ fn get_guest_prelude_vmconfig() -> anyhow::Result<Vec<AxVMCrateConfig>> {
3931
Ok(vm_configs)
4032
}
4133

42-
fn init_guest_vm(config: &AxVMCrateConfig) -> anyhow::Result<()> {
43-
debug!("Initializing guest VM `{}`", config.base.name);
44-
45-
Ok(())
46-
}
47-
4834
#[allow(clippy::module_inception, dead_code)]
4935
pub mod config {
5036
use alloc::string::String;

kernel/src/vmm/mod.rs

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44
pub mod config;
55
// pub mod images;
66
// pub mod timer;
7-
// pub mod vm_list;
7+
pub mod vm_list;
88

99
// #[cfg(target_arch = "aarch64")]
1010
// pub mod fdt;
1111

1212
use core::sync::atomic::{AtomicUsize, Ordering};
1313
use std::os::arceos::api::task::AxWaitQueueHandle;
1414

15+
use axvm::AxVMConfig;
16+
1517
// pub use timer::init_percpu as init_timer_percpu;
1618

1719
static VMM: AxWaitQueueHandle = AxWaitQueueHandle::new();
@@ -26,41 +28,6 @@ pub fn init() {
2628
info!("Initializing VMM...");
2729

2830
axvm::enable_viretualization().unwrap();
29-
30-
// Initialize guest VM according to config file.
31-
config::init_guest_vms().unwrap();
32-
33-
// Setup vcpus, spawn axtask for primary VCpu.
34-
info!("Setting up vcpus...");
35-
// for vm in vm_list::get_vm_list() {
36-
// vcpus::setup_vm_primary_vcpu(vm);
37-
// }
38-
}
39-
40-
/// Start the VMM.
41-
pub fn start() {
42-
info!("VMM starting, booting VMs...");
43-
// for vm in vm_list::get_vm_list() {
44-
// match vm.boot() {
45-
// Ok(_) => {
46-
// // vcpus::notify_primary_vcpu(vm.id());
47-
// RUNNING_VM_COUNT.fetch_add(1, Ordering::Release);
48-
// info!("VM[{}] boot success", vm.id())
49-
// }
50-
// Err(err) => warn!("VM[{}] boot failed, error {:?}", vm.id(), err),
51-
// }
52-
// }
53-
54-
// // Do not exit until all VMs are stopped.
55-
// task::ax_wait_queue_wait_until(
56-
// &VMM,
57-
// || {
58-
// let vm_count = RUNNING_VM_COUNT.load(Ordering::Acquire);
59-
// info!("a VM exited, current running VM count: {vm_count}");
60-
// vm_count == 0
61-
// },
62-
// None,
63-
// );
6431
}
6532

6633
pub fn get_running_vm_count() -> usize {
@@ -74,3 +41,20 @@ pub fn add_running_vm_count(count: usize) {
7441
pub fn sub_running_vm_count(count: usize) {
7542
RUNNING_VM_COUNT.fetch_sub(count, Ordering::Release);
7643
}
44+
45+
pub fn start_preconfigured_vms() -> anyhow::Result<()> {
46+
// Initialize guest VM according to config file.
47+
for config in config::get_guest_prelude_vmconfig()? {
48+
let vm_config = AxVMConfig::from(config);
49+
start_vm(vm_config)?;
50+
}
51+
Ok(())
52+
}
53+
54+
pub fn start_vm(config: AxVMConfig) -> anyhow::Result<()> {
55+
debug!("Starting guest VM `{}`", config.name());
56+
let vm = axvm::Vm::new(config)?;
57+
let vm = vm_list::push_vm(vm);
58+
vm.boot()?;
59+
Ok(())
60+
}

kernel/src/vmm/vm_list.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use alloc::collections::BTreeMap;
2-
use alloc::vec::Vec;
1+
use alloc::{collections::BTreeMap, sync::Arc, vec::Vec};
32

43
use spin::Mutex;
54

6-
use crate::vmm::VMRef;
5+
pub type VMRef = Arc<axvm::Vm>;
76

87
/// Represents a list of VMs,
98
/// stored in a BTreeMap where the key is the VM ID and the value is a reference to the VM.
@@ -71,8 +70,10 @@ static GLOBAL_VM_LIST: Mutex<VMList> = Mutex::new(VMList::new());
7170
/// # Arguments
7271
///
7372
/// * `vm` - A reference to the VM instance.
74-
pub fn push_vm(vm: VMRef) {
75-
GLOBAL_VM_LIST.lock().push_vm(vm.id(), vm)
73+
pub fn push_vm(vm: axvm::Vm) -> VMRef {
74+
let vm = Arc::new(vm);
75+
GLOBAL_VM_LIST.lock().push_vm(vm.id().into(), vm.clone());
76+
vm
7677
}
7778

7879
/// Removes a VM from the global VM list by its ID.

0 commit comments

Comments
 (0)