Skip to content

Commit 71fc580

Browse files
committed
fix(vm): adapt to v0.2 API changes for multi-architecture compatibility
1 parent 8e29c31 commit 71fc580

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/config.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ impl PhysCpuList {
228228
/// - The physical id of the vCpu, equal to vCpu id if not provided.
229229
pub fn get_vcpu_affinities_pcpu_ids(&self) -> Vec<(usize, Option<usize>, usize)> {
230230
let mut vcpu_pcpu_tuples = Vec::new();
231+
#[cfg(target_arch = "riscv64")]
231232
let mut pcpu_mask_flag = false;
232233

233234
if let Some(phys_cpu_ids) = &self.phys_cpu_ids
@@ -243,19 +244,27 @@ impl PhysCpuList {
243244
vcpu_pcpu_tuples.push((vcpu_id, None, vcpu_id));
244245
}
245246

247+
#[cfg(target_arch = "riscv64")]
246248
if let Some(phys_cpu_sets) = &self.phys_cpu_sets {
247249
pcpu_mask_flag = true;
248250
for (vcpu_id, pcpu_mask_bitmap) in phys_cpu_sets.iter().enumerate() {
249251
vcpu_pcpu_tuples[vcpu_id].1 = Some(*pcpu_mask_bitmap);
250252
}
251253
}
252254

255+
#[cfg(not(target_arch = "riscv64"))]
256+
if let Some(phys_cpu_sets) = &self.phys_cpu_sets {
257+
for (vcpu_id, pcpu_mask_bitmap) in phys_cpu_sets.iter().enumerate() {
258+
vcpu_pcpu_tuples[vcpu_id].1 = Some(*pcpu_mask_bitmap);
259+
}
260+
}
261+
253262
if let Some(phys_cpu_ids) = &self.phys_cpu_ids {
254263
for (vcpu_id, phys_id) in phys_cpu_ids.iter().enumerate() {
255264
vcpu_pcpu_tuples[vcpu_id].2 = *phys_id;
256265
#[cfg(target_arch = "riscv64")]
257266
{
258-
if pcpu_mask_flag == false {
267+
if !pcpu_mask_flag {
259268
// if don't assign pcpu mask yet, assign it manually
260269
vcpu_pcpu_tuples[vcpu_id].1 = Some(1 << (*phys_id));
261270
}

src/vm.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,13 @@ use axvcpu::{AxVCpu, AxVCpuExitReason, AxVCpuHal};
2929
use cpumask::CpuMask;
3030

3131
use crate::config::{AxVMConfig, PhysCpuList};
32-
use crate::vcpu::{AxArchVCpuImpl, AxVCpuCreateConfig};
32+
use crate::vcpu::AxArchVCpuImpl;
3333
use crate::{AxVMHal, has_hardware_support};
3434

35+
#[cfg(target_arch = "riscv64")]
36+
use crate::vcpu::AxVCpuCreateConfig;
3537
#[cfg(target_arch = "aarch64")]
36-
use crate::vcpu::get_sysreg_device;
38+
use crate::vcpu::{AxVCpuCreateConfig, get_sysreg_device};
3739

3840
const VM_ASPACE_BASE: usize = 0x0;
3941
const VM_ASPACE_SIZE: usize = 0x7fff_ffff_f000;
@@ -202,15 +204,18 @@ impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U> {
202204
hart_id: vcpu_id as _,
203205
dtb_addr: dtb_addr.unwrap_or_default().as_usize(),
204206
};
205-
#[cfg(target_arch = "x86_64")]
206-
let arch_config = AxVCpuCreateConfig::default();
207207

208208
vcpu_list.push(Arc::new(VCpu::new(
209209
self.id(),
210210
vcpu_id,
211211
0, // Currently not used.
212212
phys_cpu_set,
213+
#[cfg(target_arch = "aarch64")]
213214
arch_config,
215+
#[cfg(target_arch = "riscv64")]
216+
arch_config,
217+
#[cfg(target_arch = "x86_64")]
218+
(),
214219
)?));
215220
}
216221

@@ -273,9 +278,14 @@ impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U> {
273278
)?;
274279
}
275280

281+
#[cfg(target_arch = "aarch64")]
276282
let mut devices = axdevice::AxVmDevices::new(AxVmDeviceConfig {
277283
emu_configs: inner_mut.config.emu_devices().to_vec(),
278284
});
285+
#[cfg(not(target_arch = "aarch64"))]
286+
let devices = axdevice::AxVmDevices::new(AxVmDeviceConfig {
287+
emu_configs: inner_mut.config.emu_devices().to_vec(),
288+
});
279289

280290
#[cfg(target_arch = "aarch64")]
281291
{
@@ -336,8 +346,6 @@ impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U> {
336346
passthrough_timer: passthrough,
337347
}
338348
};
339-
#[cfg(not(target_arch = "aarch64"))]
340-
let setup_config = <AxArchVCpuImpl<U> as axvcpu::AxArchVCpu>::SetupConfig::default();
341349

342350
let entry = if vcpu.id() == 0 {
343351
inner_mut.config.bsp_entry()
@@ -350,7 +358,10 @@ impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U> {
350358
vcpu.setup(
351359
entry,
352360
inner_mut.address_space.page_table_root(),
361+
#[cfg(target_arch = "aarch64")]
353362
setup_config,
363+
#[cfg(not(target_arch = "aarch64"))]
364+
(),
354365
)?;
355366
}
356367
info!("VM setup: id={}", self.id());
@@ -639,7 +650,10 @@ impl<H: AxVMHal, U: AxVCpuHal> AxVM<H, U> {
639650
let size = core::mem::size_of::<T>();
640651

641652
// Ensure the address is properly aligned for the type.
642-
if gpa_ptr.as_usize() % core::mem::align_of::<T>() != 0 {
653+
if !gpa_ptr
654+
.as_usize()
655+
.is_multiple_of(core::mem::align_of::<T>())
656+
{
643657
return ax_err!(InvalidInput, "Unaligned guest physical address");
644658
}
645659

0 commit comments

Comments
 (0)