Skip to content

Commit 825f91f

Browse files
committed
refactor: vmm: remove redundant allocate_32bit_mmio_memory wrapper
This wrapper was used only once in the code and it generally does not follow the patter of using underlying allocators directly like the rest of the code does. The alternative to removing this is to do a exact opposite and find all places where allocators are used directly and make them use wrappers. This will not provide any benefits since wrappers have no logic in them and will only increase the line count and indirection overhead. Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
1 parent 9b53e62 commit 825f91f

3 files changed

Lines changed: 14 additions & 42 deletions

File tree

src/vmm/src/device_manager/mmio.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,13 @@ impl MMIODeviceManager {
161161
_ => return Err(MmioError::InvalidIrqConfig),
162162
};
163163

164+
let range = resource_allocator.mmio32_memory.allocate(
165+
MMIO_LEN,
166+
MMIO_LEN,
167+
AllocPolicy::FirstMatch,
168+
)?;
164169
let device_info = MMIODeviceInfo {
165-
addr: resource_allocator.allocate_32bit_mmio_memory(
166-
MMIO_LEN,
167-
MMIO_LEN,
168-
AllocPolicy::FirstMatch,
169-
)?,
170+
addr: range.start(),
170171
len: MMIO_LEN,
171172
gsi,
172173
};

src/vmm/src/vstate/resources.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,6 @@ impl ResourceAllocator {
109109
allocate_many_ids(&mut self.gsi_msi_allocator, gsi_count)
110110
}
111111

112-
/// Allocate a memory range in 32-bit MMIO address space
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_32bit_mmio_memory(
122-
&mut self,
123-
size: u64,
124-
alignment: u64,
125-
policy: AllocPolicy,
126-
) -> Result<u64, vm_allocator::Error> {
127-
Ok(self
128-
.mmio32_memory
129-
.allocate(size, alignment, policy)?
130-
.start())
131-
}
132-
133112
/// Allocate a memory range in 64-bit MMIO address space
134113
///
135114
/// If it succeeds, it returns the first address of the allocated range
@@ -305,10 +284,6 @@ mod tests {
305284
assert_eq!(irq_1, GSI_LEGACY_START + 1);
306285
let gsi_1 = allocator1.allocate_gsi_msi(1).unwrap()[0];
307286
assert_eq!(gsi_1, GSI_MSI_START + 1);
308-
let mmio32_mem = allocator1
309-
.allocate_32bit_mmio_memory(0x42, 1, AllocPolicy::FirstMatch)
310-
.unwrap();
311-
assert_eq!(mmio32_mem, arch::MEM_32BIT_DEVICES_START);
312287
let mmio64_mem = allocator1
313288
.allocate_64bit_mmio_memory(0x42, 1, AllocPolicy::FirstMatch)
314289
.unwrap();
@@ -319,9 +294,6 @@ mod tests {
319294
assert_eq!(system_mem, arch::SYSTEM_MEM_START);
320295

321296
let mut allocator2 = clone_allocator(&allocator1);
322-
allocator2
323-
.allocate_32bit_mmio_memory(0x42, 1, AllocPolicy::ExactMatch(mmio32_mem))
324-
.unwrap_err();
325297
allocator2
326298
.allocate_64bit_mmio_memory(0x42, 1, AllocPolicy::ExactMatch(mmio64_mem))
327299
.unwrap_err();
@@ -333,10 +305,6 @@ mod tests {
333305
assert_eq!(irq_2, GSI_LEGACY_START + 2);
334306
let gsi_2 = allocator2.allocate_gsi_msi(1).unwrap()[0];
335307
assert_eq!(gsi_2, GSI_MSI_START + 2);
336-
let mmio32_mem = allocator1
337-
.allocate_32bit_mmio_memory(0x42, 1, AllocPolicy::FirstMatch)
338-
.unwrap();
339-
assert_eq!(mmio32_mem, arch::MEM_32BIT_DEVICES_START + 0x42);
340308
let mmio64_mem = allocator1
341309
.allocate_64bit_mmio_memory(0x42, 1, AllocPolicy::FirstMatch)
342310
.unwrap();

src/vmm/src/vstate/vm.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,9 +1084,10 @@ pub(crate) mod tests {
10841084

10851085
let gsi = resource_allocator.allocate_gsi_msi(1).unwrap()[0];
10861086
let range = resource_allocator
1087-
.allocate_32bit_mmio_memory(1024, 1024, AllocPolicy::FirstMatch)
1087+
.mmio32_memory
1088+
.allocate(1024, 1024, AllocPolicy::FirstMatch)
10881089
.unwrap();
1089-
(gsi, range)
1090+
(gsi, range.start())
10901091
};
10911092

10921093
let state = vm.save_state().unwrap();
@@ -1100,11 +1101,13 @@ pub(crate) mod tests {
11001101
assert_eq!(gsi + 1, gsi_new);
11011102

11021103
resource_allocator
1103-
.allocate_32bit_mmio_memory(1024, 1024, AllocPolicy::ExactMatch(range))
1104+
.mmio32_memory
1105+
.allocate(1024, 1024, AllocPolicy::ExactMatch(range))
11041106
.unwrap_err();
11051107
let range_new = resource_allocator
1106-
.allocate_32bit_mmio_memory(1024, 1024, AllocPolicy::FirstMatch)
1108+
.mmio32_memory
1109+
.allocate(1024, 1024, AllocPolicy::FirstMatch)
11071110
.unwrap();
1108-
assert_eq!(range + 1024, range_new);
1111+
assert_eq!(range + 1024, range_new.start());
11091112
}
11101113
}

0 commit comments

Comments
 (0)