mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-01 11:05:46 +00:00
vmm: cpu: Increase robustness of CpuManager control device
See: #1289 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
33a55bac0f
commit
bdc44cd8bc
@ -406,14 +406,14 @@ const CPU_SELECTION_OFFSET: u64 = 0;
|
|||||||
impl BusDevice for CpuManager {
|
impl BusDevice for CpuManager {
|
||||||
fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) {
|
fn read(&mut self, _base: u64, offset: u64, data: &mut [u8]) {
|
||||||
// The Linux kernel, quite reasonably, doesn't zero the memory it gives us.
|
// 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);
|
||||||
|
|
||||||
match offset {
|
match offset {
|
||||||
CPU_SELECTION_OFFSET => {
|
CPU_SELECTION_OFFSET => {
|
||||||
data[0] = self.selected_cpu;
|
data[0] = self.selected_cpu;
|
||||||
}
|
}
|
||||||
CPU_STATUS_OFFSET => {
|
CPU_STATUS_OFFSET => {
|
||||||
if self.selected_cpu < self.present_vcpus() {
|
if self.selected_cpu < self.max_vcpus() {
|
||||||
let state = &self.vcpu_states[usize::from(self.selected_cpu)];
|
let state = &self.vcpu_states[usize::from(self.selected_cpu)];
|
||||||
if state.active() {
|
if state.active() {
|
||||||
data[0] |= 1 << CPU_ENABLE_FLAG;
|
data[0] |= 1 << CPU_ENABLE_FLAG;
|
||||||
@ -424,6 +424,8 @@ impl BusDevice for CpuManager {
|
|||||||
if state.removing {
|
if state.removing {
|
||||||
data[0] |= 1 << CPU_REMOVING_FLAG;
|
data[0] |= 1 << CPU_REMOVING_FLAG;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
warn!("Out of range vCPU id: {}", self.selected_cpu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
@ -441,23 +443,28 @@ impl BusDevice for CpuManager {
|
|||||||
self.selected_cpu = data[0];
|
self.selected_cpu = data[0];
|
||||||
}
|
}
|
||||||
CPU_STATUS_OFFSET => {
|
CPU_STATUS_OFFSET => {
|
||||||
let state = &mut self.vcpu_states[usize::from(self.selected_cpu)];
|
if self.selected_cpu < self.max_vcpus() {
|
||||||
// The ACPI code writes back a 1 to acknowledge the insertion
|
let state = &mut self.vcpu_states[usize::from(self.selected_cpu)];
|
||||||
if (data[0] & (1 << CPU_INSERTING_FLAG) == 1 << CPU_INSERTING_FLAG)
|
// The ACPI code writes back a 1 to acknowledge the insertion
|
||||||
&& state.inserting
|
if (data[0] & (1 << CPU_INSERTING_FLAG) == 1 << CPU_INSERTING_FLAG)
|
||||||
{
|
&& state.inserting
|
||||||
state.inserting = false;
|
{
|
||||||
}
|
state.inserting = false;
|
||||||
// Ditto for removal
|
|
||||||
if (data[0] & (1 << CPU_REMOVING_FLAG) == 1 << CPU_REMOVING_FLAG) && state.removing
|
|
||||||
{
|
|
||||||
state.removing = false;
|
|
||||||
}
|
|
||||||
// Trigger removal of vCPU
|
|
||||||
if data[0] & (1 << CPU_EJECT_FLAG) == 1 << CPU_EJECT_FLAG {
|
|
||||||
if let Err(e) = self.remove_vcpu(self.selected_cpu) {
|
|
||||||
error!("Error removing vCPU: {:?}", e);
|
|
||||||
}
|
}
|
||||||
|
// Ditto for removal
|
||||||
|
if (data[0] & (1 << CPU_REMOVING_FLAG) == 1 << CPU_REMOVING_FLAG)
|
||||||
|
&& state.removing
|
||||||
|
{
|
||||||
|
state.removing = false;
|
||||||
|
}
|
||||||
|
// Trigger removal of vCPU
|
||||||
|
if data[0] & (1 << CPU_EJECT_FLAG) == 1 << CPU_EJECT_FLAG {
|
||||||
|
if let Err(e) = self.remove_vcpu(self.selected_cpu) {
|
||||||
|
error!("Error removing vCPU: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
warn!("Out of range vCPU id: {}", self.selected_cpu);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
Loading…
Reference in New Issue
Block a user