vmm: memory_manager: Increase robustness of MemoryManager control device

See: #1289

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-09-10 10:41:38 +01:00 committed by Bo Chen
parent bdc44cd8bc
commit 171d12943d

View File

@ -315,7 +315,7 @@ impl BusDevice for MemoryManager {
}
STATUS_OFFSET => {
// The Linux kernel, quite reasonably, doesn't zero the memory it gives us.
data.copy_from_slice(&[0; 8][0..data.len()]);
data.fill(0);
if state.active {
data[0] |= 1 << ENABLE_FLAG;
}
@ -333,6 +333,8 @@ impl BusDevice for MemoryManager {
);
}
}
} else {
warn!("Out of range memory slot: {}", self.selected_slot);
}
}
@ -342,6 +344,7 @@ impl BusDevice for MemoryManager {
self.selected_slot = usize::from(data[0]);
}
STATUS_OFFSET => {
if self.selected_slot < self.hotplug_slots.len() {
let state = &mut self.hotplug_slots[self.selected_slot];
// The ACPI code writes back a 1 to acknowledge the insertion
if (data[0] & (1 << INSERTING_FLAG) == 1 << INSERTING_FLAG) && state.inserting {
@ -355,6 +358,9 @@ impl BusDevice for MemoryManager {
if data[0] & (1 << EJECT_FLAG) == 1 << EJECT_FLAG {
warn!("Ejection of memory not currently supported");
}
} else {
warn!("Out of range memory slot: {}", self.selected_slot);
}
}
_ => {
warn!(