vmm: Do the downcast of GicDevice in a safer way for AArch64
Downcasting of GicDevice trait might fail. Therefore we try to downcast the trait first and only if the downcasting succeeded we can then use the object to call methods. Otherwise, do nothing and log the failure. Signed-off-by: Henry Wang <Henry.Wang@arm.com>
This commit is contained in:
parent
46c60183cd
commit
0d01eac1d4
2 changed files with 25 additions and 10 deletions
|
|
@ -4147,14 +4147,19 @@ impl Pausable for DeviceManager {
|
|||
.get_gic_device()
|
||||
.unwrap(),
|
||||
);
|
||||
gic_device
|
||||
if let Some(gicv3_its) = gic_device
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_any_concrete_mut()
|
||||
.downcast_mut::<KvmGicV3Its>()
|
||||
.unwrap()
|
||||
.pause()?;
|
||||
}
|
||||
{
|
||||
gicv3_its.pause()?;
|
||||
} else {
|
||||
return Err(MigratableError::Pause(anyhow!(
|
||||
"GicDevice downcast to KvmGicV3Its failed when pausing device manager!"
|
||||
)));
|
||||
};
|
||||
};
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2027,13 +2027,18 @@ impl Vm {
|
|||
.set_gicr_typers(&saved_vcpu_states);
|
||||
|
||||
vm_snapshot.add_snapshot(
|
||||
gic_device
|
||||
if let Some(gicv3_its) = gic_device
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_any_concrete_mut()
|
||||
.downcast_mut::<KvmGicV3Its>()
|
||||
.unwrap()
|
||||
.snapshot()?,
|
||||
{
|
||||
gicv3_its.snapshot()?
|
||||
} else {
|
||||
return Err(MigratableError::Snapshot(anyhow!(
|
||||
"GicDevice downcast to KvmGicV3Its failed when snapshotting VM!"
|
||||
)));
|
||||
},
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
|
@ -2071,13 +2076,18 @@ impl Vm {
|
|||
|
||||
// Restore GIC states.
|
||||
if let Some(gicv3_its_snapshot) = vm_snapshot.snapshots.get(GIC_V3_ITS_SNAPSHOT_ID) {
|
||||
gic_device
|
||||
if let Some(gicv3_its) = gic_device
|
||||
.lock()
|
||||
.unwrap()
|
||||
.as_any_concrete_mut()
|
||||
.downcast_mut::<KvmGicV3Its>()
|
||||
.unwrap()
|
||||
.restore(*gicv3_its_snapshot.clone())?;
|
||||
{
|
||||
gicv3_its.restore(*gicv3_its_snapshot.clone())?;
|
||||
} else {
|
||||
return Err(MigratableError::Restore(anyhow!(
|
||||
"GicDevice downcast to KvmGicV3Its failed when restoring VM!"
|
||||
)));
|
||||
};
|
||||
} else {
|
||||
return Err(MigratableError::Restore(anyhow!(
|
||||
"Missing GicV3Its snapshot"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue