Skip to content

Commit 8eb5186

Browse files
committed
refactor: vmm: remove redundant allocate_system_memory wrapper
Following same logic from previous commit, remove this wrapper as well. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent e48d74e commit 8eb5186

6 files changed

Lines changed: 20 additions & 48 deletions

File tree

src/vmm/src/acpi/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ impl AcpiTableWriter<'_> {
6060
where
6161
S: Sdt,
6262
{
63-
let addr = resource_allocator.allocate_system_memory(
64-
table.len().try_into().unwrap(),
65-
1,
66-
AllocPolicy::FirstMatch,
67-
)?;
63+
let addr = resource_allocator
64+
.system_memory
65+
.allocate(table.len().try_into().unwrap(), 1, AllocPolicy::FirstMatch)?
66+
.start();
6867

6968
table
7069
.write_to_guest(self.mem, GuestAddress(addr))

src/vmm/src/arch/x86_64/mptable.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,10 @@ pub fn setup_mptable(
124124
}
125125

126126
let mp_size = compute_mp_size(num_cpus);
127-
let mptable_addr =
128-
resource_allocator.allocate_system_memory(mp_size as u64, 1, AllocPolicy::FirstMatch)?;
127+
let mptable_addr = resource_allocator
128+
.system_memory
129+
.allocate(mp_size as u64, 1, AllocPolicy::FirstMatch)?
130+
.start();
129131
debug!(
130132
"mptable: Allocated {mp_size} bytes for MPTable {num_cpus} vCPUs at address {:#010x}",
131133
mptable_addr

src/vmm/src/builder.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,10 @@ fn allocate_pvtime_region(
568568
) -> Result<GuestAddress, StartMicrovmError> {
569569
let size = STEALTIME_STRUCT_MEM_SIZE * vcpu_count as u64;
570570
let addr = resource_allocator
571-
.allocate_system_memory(size, STEALTIME_STRUCT_MEM_SIZE, policy)
572-
.map_err(StartMicrovmError::AllocateResources)?;
571+
.system_memory
572+
.allocate(size, STEALTIME_STRUCT_MEM_SIZE, policy)
573+
.map_err(StartMicrovmError::AllocateResources)?
574+
.start();
573575
Ok(GuestAddress(addr))
574576
}
575577

src/vmm/src/devices/acpi/vmclock.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,14 @@ impl VmClock {
7777
/// Create a new [`VmClock`] device for a newly booted VM
7878
pub fn new(resource_allocator: &mut ResourceAllocator) -> Result<VmClock, VmClockError> {
7979
let addr = resource_allocator
80-
.allocate_system_memory(
80+
.system_memory
81+
.allocate(
8182
VMCLOCK_SIZE as u64,
8283
VMCLOCK_SIZE as u64,
8384
AllocPolicy::LastMatch,
8485
)
85-
.map_err(VmClockError::AllocateMemory)?;
86+
.map_err(VmClockError::AllocateMemory)?
87+
.start();
8688

8789
let gsi = resource_allocator
8890
.allocate_gsi_legacy(1)

src/vmm/src/devices/acpi/vmgenid.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ impl VmGenId {
8484
.map_err(VmGenIdError::AllocateGsi)?[0];
8585
// The generation ID needs to live in an 8-byte aligned buffer
8686
let addr = resource_allocator
87-
.allocate_system_memory(VMGENID_MEM_SIZE, 8, vm_allocator::AllocPolicy::LastMatch)
88-
.map_err(VmGenIdError::AllocateMemory)?;
87+
.system_memory
88+
.allocate(VMGENID_MEM_SIZE, 8, vm_allocator::AllocPolicy::LastMatch)
89+
.map_err(VmGenIdError::AllocateMemory)?
90+
.start();
8991

9092
Self::from_parts(GuestAddress(addr), gsi)
9193
}

src/vmm/src/vstate/resources.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,6 @@ impl ResourceAllocator {
108108
pub fn allocate_gsi_msi(&mut self, gsi_count: u32) -> Result<Vec<u32>, vm_allocator::Error> {
109109
allocate_many_ids(&mut self.gsi_msi_allocator, gsi_count)
110110
}
111-
112-
/// Allocate a memory range for system data
113-
///
114-
/// If it succeeds, it returns the first address of the allocated range
115-
///
116-
/// # Arguments
117-
///
118-
/// * `size` - The size in bytes of the memory to allocate
119-
/// * `alignment` - The alignment of the address of the first byte
120-
/// * `policy` - A [`vm_allocator::AllocPolicy`] variant for determining the allocation policy
121-
pub fn allocate_system_memory(
122-
&mut self,
123-
size: u64,
124-
alignment: u64,
125-
policy: AllocPolicy,
126-
) -> Result<u64, vm_allocator::Error> {
127-
Ok(self
128-
.system_memory
129-
.allocate(size, alignment, policy)?
130-
.start())
131-
}
132111
}
133112

134113
impl<'a> Persist<'a> for ResourceAllocator {
@@ -150,8 +129,6 @@ impl<'a> Persist<'a> for ResourceAllocator {
150129

151130
#[cfg(test)]
152131
mod tests {
153-
use vm_allocator::AllocPolicy;
154-
155132
use super::ResourceAllocator;
156133
use crate::arch::{self, GSI_LEGACY_NUM, GSI_LEGACY_START, GSI_MSI_NUM, GSI_MSI_START};
157134
use crate::snapshot::Persist;
@@ -263,23 +240,11 @@ mod tests {
263240
assert_eq!(irq_1, GSI_LEGACY_START + 1);
264241
let gsi_1 = allocator1.allocate_gsi_msi(1).unwrap()[0];
265242
assert_eq!(gsi_1, GSI_MSI_START + 1);
266-
let system_mem = allocator1
267-
.allocate_system_memory(0x42, 1, AllocPolicy::FirstMatch)
268-
.unwrap();
269-
assert_eq!(system_mem, arch::SYSTEM_MEM_START);
270243

271244
let mut allocator2 = clone_allocator(&allocator1);
272-
allocator2
273-
.allocate_system_memory(0x42, 1, AllocPolicy::ExactMatch(system_mem))
274-
.unwrap_err();
275-
276245
let irq_2 = allocator2.allocate_gsi_legacy(1).unwrap()[0];
277246
assert_eq!(irq_2, GSI_LEGACY_START + 2);
278247
let gsi_2 = allocator2.allocate_gsi_msi(1).unwrap()[0];
279248
assert_eq!(gsi_2, GSI_MSI_START + 2);
280-
let system_mem = allocator1
281-
.allocate_system_memory(0x42, 1, AllocPolicy::FirstMatch)
282-
.unwrap();
283-
assert_eq!(system_mem, arch::SYSTEM_MEM_START + 0x42);
284249
}
285250
}

0 commit comments

Comments
 (0)