Skip to content

Commit f01905f

Browse files
committed
fix: compilation in aarch64
Changes we did for supporting older snapshot formats, did not really compile on ARM systems. Fix the compilation issues. The issues were mainly bad re-exports. Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
1 parent aa14c57 commit f01905f

8 files changed

Lines changed: 54 additions & 117 deletions

File tree

src/vmm/src/arch/aarch64/gic/gicv3/regs/its_regs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub fn its_restore_tables(its_fd: &DeviceFd) -> Result<(), GicError> {
8080
}
8181

8282
/// ITS registers that we save/restore during snapshot
83-
#[derive(Debug, Default, Serialize, Deserialize)]
83+
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
8484
pub struct ItsRegisterState {
8585
iidr: u64,
8686
cbaser: u64,

src/vmm/src/arch/aarch64/gic/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ mod regs;
88
use gicv2::GICv2;
99
use gicv3::GICv3;
1010
use kvm_ioctls::{DeviceFd, VmFd};
11-
pub use regs::GicState;
11+
pub use regs::{GicRegState, GicState, GicVcpuState, VgicSysRegsState};
12+
pub use gicv3::regs::its_regs::ItsRegisterState;
1213

1314
use super::layout;
1415

src/vmm/src/arch/aarch64/gic/regs.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,23 @@ use serde::{Deserialize, Serialize};
1212
use crate::arch::aarch64::gic::GicError;
1313
use crate::arch::aarch64::gic::gicv3::regs::its_regs::ItsRegisterState;
1414

15-
#[derive(Debug, Serialize, Deserialize)]
15+
/// Serializable state for a block of GIC registers.
16+
#[derive(Debug, Clone, Serialize, Deserialize)]
1617
pub struct GicRegState<T> {
1718
pub(crate) chunks: Vec<T>,
1819
}
1920

2021
/// Structure for serializing the state of the Vgic ICC regs
21-
#[derive(Debug, Default, Serialize, Deserialize)]
22+
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
2223
pub struct VgicSysRegsState {
24+
/// Main ICC system registers.
2325
pub main_icc_regs: Vec<GicRegState<u64>>,
26+
/// AP ICC system registers (one entry per priority group).
2427
pub ap_icc_regs: Vec<Option<GicRegState<u64>>>,
2528
}
2629

2730
/// Structure used for serializing the state of the GIC registers.
28-
#[derive(Debug, Default, Serialize, Deserialize)]
31+
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
2932
pub struct GicState {
3033
/// The state of the distributor registers.
3134
pub dist: Vec<GicRegState<u32>>,
@@ -36,9 +39,11 @@ pub struct GicState {
3639
}
3740

3841
/// Structure used for serializing the state of the GIC registers for a specific vCPU.
39-
#[derive(Debug, Default, Serialize, Deserialize)]
42+
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
4043
pub struct GicVcpuState {
44+
/// Redistributor registers for this vCPU.
4145
pub rdist: Vec<GicRegState<u32>>,
46+
/// ICC (CPU interface) system registers for this vCPU.
4247
pub icc: VgicSysRegsState,
4348
}
4449

src/vmm/src/persist/v1_10/aarch64.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@
33

44
use serde::{Deserialize, Serialize};
55

6-
use super::{KvmCapability, MMIODeviceInfo};
6+
use crate::cpu_config::templates::KvmCapability;
7+
use super::MMIODeviceInfo;
78

89
// Types that are identical across all versions — canonical definitions in v1_14.
9-
pub use crate::v1_14::{
10-
StaticCpuTemplate,
11-
DeviceType,
12-
GicRegState,
13-
VgicSysRegsState,
14-
GicVcpuState,
15-
Aarch64RegisterVec,
16-
};
10+
pub use crate::persist::v1_14::DeviceType;
1711

1812
// Types that are identical in v1.10 and v1.12 — canonical definitions in v1_12.
19-
pub use crate::v1_12::{
13+
pub use crate::persist::v1_12::{
2014
// aarch64 GicState is identical in v1.10 and v1.12 (gains its_state in v1.14)
2115
GicState,
2216
// aarch64 VcpuState is identical in v1.10 and v1.12 (gains pvtime_ipa in v1.14)

src/vmm/src/persist/v1_12/aarch64.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ use serde::{Deserialize, Serialize};
77
use super::{GuestMemoryState, MMIODeviceInfo};
88

99
// Types that are canonical in v1_14 and unchanged through all versions
10-
pub use crate::v1_14::{
10+
pub use crate::persist::v1_14::{
1111
// Legacy device type enum
1212
DeviceType,
1313
// GIC helper types (GicState itself changed — its_state added — so redefined in v1_14)
1414
GicRegState,
15-
VgicSysRegsState,
1615
GicVcpuState,
1716
// Register vector with custom serde
1817
Aarch64RegisterVec,

src/vmm/src/persist/v1_12/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use serde::{Deserialize, Serialize};
2020

2121
use super::v1_10;
22+
#[cfg(target_arch = "x86_64")]
2223
use crate::arch::VcpuState;
2324
use crate::devices::acpi::vmgenid::VMGenIDState;
2425
use crate::devices::virtio::balloon::persist::BalloonConfigSpaceState;

src/vmm/src/persist/v1_14/aarch64.rs

Lines changed: 31 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use kvm_bindings::{kvm_mp_state, kvm_vcpu_init};
54
use serde::{Deserialize, Serialize};
65

7-
use crate::convert::{ConvertError, irq_to_gsi};
8-
use crate::v1_12;
6+
use super::{ACPIDeviceManagerState, ConvertError, GuestMemoryState, MMIODeviceInfo,
7+
ResourceAllocator, irq_to_gsi};
8+
use crate::devices::acpi::vmgenid::VMGenIDState;
9+
use crate::persist::v1_12;
910

10-
use super::{
11-
ACPIDeviceManagerState, GuestMemoryState, MMIODeviceInfo, ResourceAllocator, VMGenIDState,
12-
};
11+
// ───────────────────────────────────────────────────────────────────
12+
// Re-export runtime types — v1.14 snapshot format matches the runtime format.
13+
// These are used by v1.12 (and v1.10 via v1.12) as canonical type definitions.
14+
// ───────────────────────────────────────────────────────────────────
15+
16+
pub use crate::arch::aarch64::gic::{GicRegState, GicState, GicVcpuState};
17+
pub use crate::arch::aarch64::regs::Aarch64RegisterVec;
18+
pub use crate::arch::aarch64::vcpu::VcpuState;
19+
pub use crate::arch::aarch64::vm::VmState;
1320

1421
// ───────────────────────────────────────────────────────────────────
15-
// StaticCpuTemplate — canonical definition (identical in v1.10, v1.12, v1.14)
22+
// StaticCpuTemplate — aarch64-specific snapshot enum (same in v1.10, v1.12, v1.14)
1623
// ───────────────────────────────────────────────────────────────────
1724

1825
#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
@@ -23,7 +30,7 @@ pub enum StaticCpuTemplate {
2330
}
2431

2532
// ───────────────────────────────────────────────────────────────────
26-
// aarch64 legacy device types — canonical definitions
33+
// DeviceType — aarch64 legacy device type enum (snapshot format)
2734
// ───────────────────────────────────────────────────────────────────
2835

2936
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -33,94 +40,34 @@ pub enum DeviceType {
3340
Rtc,
3441
}
3542

36-
// ───────────────────────────────────────────────────────────────────
37-
// GIC helper types — canonical definitions (unchanged since v1.10)
38-
// ───────────────────────────────────────────────────────────────────
39-
40-
#[derive(Debug, Clone, Serialize, Deserialize)]
41-
#[serde(bound(serialize = "T: Serialize", deserialize = "T: for<'a> Deserialize<'a>"))]
42-
pub struct GicRegState<T: Serialize + for<'a> Deserialize<'a>> {
43-
pub chunks: Vec<T>,
44-
}
45-
46-
#[derive(Debug, Clone, Serialize, Deserialize)]
47-
pub struct VgicSysRegsState {
48-
pub main_icc_regs: Vec<GicRegState<u64>>,
49-
pub ap_icc_regs: Vec<Option<GicRegState<u64>>>,
50-
}
51-
52-
#[derive(Debug, Clone, Serialize, Deserialize)]
53-
pub struct GicVcpuState {
54-
pub rdist: Vec<GicRegState<u32>>,
55-
pub icc: VgicSysRegsState,
56-
}
57-
58-
// ───────────────────────────────────────────────────────────────────
59-
// aarch64 register vector — canonical definition (unchanged since v1.10)
60-
// ───────────────────────────────────────────────────────────────────
61-
62-
/// aarch64 register vector with custom serde: serialized as (Vec<u64>, Vec<u8>)
63-
#[derive(Debug, Clone)]
64-
pub struct Aarch64RegisterVec {
65-
pub ids: Vec<u64>,
66-
pub data: Vec<u8>,
67-
}
68-
69-
impl Serialize for Aarch64RegisterVec {
70-
fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
71-
(&self.ids, &self.data).serialize(serializer)
72-
}
73-
}
74-
75-
impl<'de> Deserialize<'de> for Aarch64RegisterVec {
76-
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
77-
let (ids, data) = <(Vec<u64>, Vec<u8>)>::deserialize(deserializer)?;
78-
Ok(Aarch64RegisterVec { ids, data })
43+
impl From<DeviceType> for crate::arch::DeviceType {
44+
fn from(dt: DeviceType) -> Self {
45+
match dt {
46+
DeviceType::Virtio(n) => crate::arch::DeviceType::Virtio(n),
47+
DeviceType::Serial => crate::arch::DeviceType::Serial,
48+
DeviceType::Rtc => crate::arch::DeviceType::Rtc,
49+
}
7950
}
8051
}
8152

8253
// ───────────────────────────────────────────────────────────────────
83-
// aarch64 ConnectedLegacyState (uses updated MMIODeviceInfo with gsi)
54+
// ConnectedLegacyState — convert v1.12 snapshot type to runtime type
8455
// ───────────────────────────────────────────────────────────────────
8556

86-
#[derive(Debug, Clone, Serialize, Deserialize)]
87-
pub struct ConnectedLegacyState {
88-
pub type_: DeviceType,
89-
pub device_info: MMIODeviceInfo,
90-
}
91-
92-
impl From<v1_12::ConnectedLegacyState> for ConnectedLegacyState {
57+
impl From<v1_12::ConnectedLegacyState> for crate::device_manager::persist::ConnectedLegacyState {
9358
fn from(s: v1_12::ConnectedLegacyState) -> Self {
94-
ConnectedLegacyState {
95-
type_: s.type_,
59+
crate::device_manager::persist::ConnectedLegacyState {
60+
type_: crate::arch::DeviceType::from(s.type_),
9661
device_info: MMIODeviceInfo::from(s.device_info),
9762
}
9863
}
9964
}
10065

10166
// ───────────────────────────────────────────────────────────────────
102-
// aarch64 GIC state (v1.14: adds its_state)
103-
// GicRegState, VgicSysRegsState, GicVcpuState are defined above
67+
// GIC state (aarch64, v1.14: adds its_state)
68+
// GicState is the runtime type (re-exported above); conversion from v1.12 is here.
10469
// ───────────────────────────────────────────────────────────────────
10570

106-
#[derive(Debug, Clone, Serialize, Deserialize)]
107-
pub struct ItsRegisterState {
108-
pub iidr: u64,
109-
pub cbaser: u64,
110-
pub creadr: u64,
111-
pub cwriter: u64,
112-
pub baser: [u64; 8],
113-
pub ctlr: u64,
114-
}
115-
116-
#[derive(Debug, Clone, Serialize, Deserialize)]
117-
pub struct GicState {
118-
pub dist: Vec<GicRegState<u32>>,
119-
pub gic_vcpu_states: Vec<GicVcpuState>,
120-
/// ITS state (GICv3 only). None for GICv2 or when converted from v1.12.
121-
pub its_state: Option<ItsRegisterState>,
122-
}
123-
12471
impl GicState {
12572
pub(crate) fn from(old_state: v1_12::GicState) -> GicState {
12673
GicState {
@@ -133,17 +80,9 @@ impl GicState {
13380

13481
// ───────────────────────────────────────────────────────────────────
13582
// vCPU state (aarch64, v1.14: gains pvtime_ipa)
83+
// VcpuState is the runtime type (re-exported above); conversion from v1.12 is here.
13684
// ───────────────────────────────────────────────────────────────────
13785

138-
#[derive(Debug, Clone, Serialize, Deserialize)]
139-
pub struct VcpuState {
140-
pub mp_state: kvm_mp_state,
141-
pub regs: Aarch64RegisterVec,
142-
pub mpidr: u64,
143-
pub kvi: kvm_vcpu_init,
144-
pub pvtime_ipa: Option<u64>,
145-
}
146-
14786
impl VcpuState {
14887
pub(crate) fn from(old_state: v1_12::VcpuState) -> VcpuState {
14988
VcpuState {
@@ -157,7 +96,7 @@ impl VcpuState {
15796
}
15897

15998
// ───────────────────────────────────────────────────────────────────
160-
// ACPI device state impl (aarch64: no vmclock)
99+
// ACPI device state (aarch64: no vmclock)
161100
// ───────────────────────────────────────────────────────────────────
162101

163102
impl ACPIDeviceManagerState {
@@ -178,15 +117,9 @@ impl ACPIDeviceManagerState {
178117

179118
// ───────────────────────────────────────────────────────────────────
180119
// VM state (aarch64, v1.14: adds resource_allocator)
120+
// VmState is the runtime type (re-exported above); conversion from v1.12 is here.
181121
// ───────────────────────────────────────────────────────────────────
182122

183-
#[derive(Debug, Clone, Serialize, Deserialize)]
184-
pub struct VmState {
185-
pub memory: GuestMemoryState,
186-
pub gic: GicState,
187-
pub resource_allocator: ResourceAllocator,
188-
}
189-
190123
impl VmState {
191124
pub(crate) fn from(
192125
old_state: v1_12::VmState,

src/vmm/src/persist/v1_14/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,18 @@ pub use aarch64::*;
3434
use crate::arch::{
3535
FIRST_ADDR_PAST_64BITS_MMIO, GSI_LEGACY_END, GSI_LEGACY_START, GSI_MSI_END, GSI_MSI_START,
3636
MEM_32BIT_DEVICES_SIZE, MEM_32BIT_DEVICES_START, MEM_64BIT_DEVICES_SIZE,
37-
MEM_64BIT_DEVICES_START, PAST_64BITS_MMIO_SIZE, SYSTEM_MEM_SIZE, SYSTEM_MEM_START, VmState,
37+
MEM_64BIT_DEVICES_START, PAST_64BITS_MMIO_SIZE, SYSTEM_MEM_SIZE, SYSTEM_MEM_START,
3838
};
39+
#[cfg(target_arch = "x86_64")]
40+
use crate::arch::VmState;
3941
use crate::device_manager::DevicesState;
4042
use crate::device_manager::mmio::MMIODeviceInfo;
4143
use crate::device_manager::pci_mngr::PciDevicesState;
4244
use crate::device_manager::persist::{
4345
ACPIDeviceManagerState, DeviceStates, MmdsState, VirtioDeviceState as ConnectedDeviceState,
4446
};
47+
#[cfg(target_arch = "aarch64")]
48+
use crate::device_manager::persist::ConnectedLegacyState;
4549
use crate::devices::acpi::vmgenid::VMGENID_MEM_SIZE;
4650
use crate::devices::virtio::balloon::device::HintingState;
4751
use crate::devices::virtio::balloon::persist::{BalloonState, BalloonStatsState};

0 commit comments

Comments
 (0)