Skip to content

Commit 654f72a

Browse files
committed
vmgenid: allocate only 16 bytes for VMGenID
Following the QEMU implementation, we were allocating a full page for holding the memory of the VMGenID device, even though the device itself is only using 16 bytes for the generation ID. We actually don't have any reason to do that. The Linux kernel itself is just remapping 16 bytes from the address we pass over via ACPI/DeviceTree. Revert to allocating 16 bytes for the VMGenID device and expose the value via a public constant for other systems to consume. Signed-off-by: Babis Chalios <[email protected]>
1 parent 9b6f067 commit 654f72a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ use crate::device_manager::resources::ResourceAllocator;
1515
use crate::snapshot::Persist;
1616
use crate::vstate::memory::{Bytes, GuestMemoryMmap};
1717

18+
/// Bytes of memory we allocate for VMGenID device
19+
pub const VMGENID_MEM_SIZE: u64 = 16;
20+
1821
/// Virtual Machine Generation ID device
1922
///
2023
/// VMGenID is an emulated device which exposes to the guest a 128-bit cryptographically random
@@ -86,8 +89,9 @@ impl VmGenId {
8689
resource_allocator: &mut ResourceAllocator,
8790
) -> Result<Self, VmGenIdError> {
8891
let gsi = resource_allocator.allocate_gsi(1)?;
92+
// The generation ID needs to live in an 8-byte aligned buffer
8993
let addr = resource_allocator.allocate_system_memory(
90-
4096,
94+
VMGENID_MEM_SIZE,
9195
8,
9296
vm_allocator::AllocPolicy::LastMatch,
9397
)?;
@@ -149,7 +153,7 @@ impl<'a> Persist<'a> for VmGenId {
149153
state: &Self::State,
150154
) -> std::result::Result<Self, Self::Error> {
151155
constructor_args.resource_allocator.allocate_system_memory(
152-
4096,
156+
VMGENID_MEM_SIZE,
153157
8,
154158
vm_allocator::AllocPolicy::ExactMatch(state.addr),
155159
)?;

0 commit comments

Comments
 (0)