[PATCH] analyze-migration.py: Fix instance_id signedness

Fabiano Rosas posted 1 patch 2 years, 2 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20220221175357.2103775-1-farosas@linux.ibm.com
Maintainers: Cleber Rosa <crosa@redhat.com>, Eduardo Habkost <eduardo@habkost.net>
scripts/analyze-migration.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
[PATCH] analyze-migration.py: Fix instance_id signedness
Posted by Fabiano Rosas 2 years, 2 months ago
The instance_id field is uint32_t in the migration code, however the
script currently handles it as a signed integer:

$ ./scripts/analyze-migration.py -f mig
 Traceback (most recent call last):
   File "./scripts/analyze-migration.py", line 605, in <module>
     dump.read(dump_memory = args.memory)
   File "./scripts/analyze-migration.py", line 539, in read
     classdesc = self.section_classes[section_key]
 KeyError: ('spapr_iommu', -2147483648)

Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
---
 scripts/analyze-migration.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
index b82a1b0c58..713f645eea 100755
--- a/scripts/analyze-migration.py
+++ b/scripts/analyze-migration.py
@@ -40,8 +40,8 @@ def __init__(self, filename):
     def read64(self):
         return int.from_bytes(self.file.read(8), byteorder='big', signed=True)
 
-    def read32(self):
-        return int.from_bytes(self.file.read(4), byteorder='big', signed=True)
+    def read32(self, signed=True):
+        return int.from_bytes(self.file.read(4), byteorder='big', signed=signed)
 
     def read16(self):
         return int.from_bytes(self.file.read(2), byteorder='big', signed=True)
@@ -533,7 +533,7 @@ def read(self, desc_only = False, dump_memory = False, write_memory = False):
             elif section_type == self.QEMU_VM_SECTION_START or section_type == self.QEMU_VM_SECTION_FULL:
                 section_id = file.read32()
                 name = file.readstr()
-                instance_id = file.read32()
+                instance_id = file.read32(signed=False)
                 version_id = file.read32()
                 section_key = (name, instance_id)
                 classdesc = self.section_classes[section_key]
-- 
2.34.1


Re: [PATCH] analyze-migration.py: Fix instance_id signedness
Posted by Philippe Mathieu-Daudé 2 years, 2 months ago
On 21/2/22 18:53, Fabiano Rosas wrote:
> The instance_id field is uint32_t in the migration code, however the
> script currently handles it as a signed integer:
> 
> $ ./scripts/analyze-migration.py -f mig
>   Traceback (most recent call last):
>     File "./scripts/analyze-migration.py", line 605, in <module>
>       dump.read(dump_memory = args.memory)
>     File "./scripts/analyze-migration.py", line 539, in read
>       classdesc = self.section_classes[section_key]
>   KeyError: ('spapr_iommu', -2147483648)
> 
> Signed-off-by: Fabiano Rosas <farosas@linux.ibm.com>
> ---
>   scripts/analyze-migration.py | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>