[RFC kvmtool 03/31] hw: cfi flash: Handle errors in memory transitions

Suzuki K Poulose
2023-01-27T11:40:57Z

Handle failures in creating the memory maps and back in
transitioning the CFI flash. e.g., with MTE enabled, CFI
flash emulation breaks with the map operation, silently.
And we later hit unhandled aborts in the guest.

To avoid such issues, let us make sure we catch the error
and handle it right at source.

Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
---
hw/cfi_flash.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/hw/cfi_flash.c b/hw/cfi_flash.c
index 7faecdfb..bce546bc 100644
--- a/hw/cfi_flash.c
+++ b/hw/cfi_flash.c
@@ -455,6 +455,8 @@ static int map_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev)
KVM_MEM_TYPE_RAM | KVM_MEM_TYPE_READONLY);
if (!ret)
sfdev->is_mapped = true;
+ else
+ die("CFI Flash: ERROR: Unable to map memory: %d\n", ret);

return ret;
}
@@ -472,6 +474,8 @@ static int unmap_flash_memory(struct kvm *kvm, struct cfi_flash_device *sfdev)

if (!ret)
sfdev->is_mapped = false;
+ else
+ die("CFI Flash: Failed to unmap Flash %d", ret);

return ret;
}
--
2.34.1