Skip to contentSkip to conversation

qapi-types.py: Fix enum struct sizes on i686

PATCH Applied Cole Robinson 5 participants 5 messages Aug 31, 2013 – Sep 9, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qapi-types.py: Fix enum struct sizes on i686

Unlike other list types, enum wasn't adding any padding, which caused a mismatch between the generated struct size and GenericList struct size. More details in a678e26cbe89f7a27cbce794c2c2784571ee9d21

This crashed qemu if calling qmp query-tpm-types for example, which upsets libvirt capabilities probing. Reproducer on i686:

(sleep 5; printf '{"execute":"qmp_capabilities"}\n{"execute":"query-tpm-types"}\n') | ./i386-softmmu/qemu-system-i386 -S -nodefaults -nographic -M none -qmp stdio

https://bugs.launchpad.net/qemu/+bug/1219207

---
 scripts/qapi-types.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/qapi-types.py +4 -1
index 5ee46ea..5d31b06 100644
@@ -51,7 +51,10 @@ def generate_fwd_enum_struct(name, members):
     return mcgen('''
 typedef struct %(name)sList
 {
-    %(name)s value;
+    union {
+        %(name)s value;
+        uint64_t padding;
+    };
     struct %(name)sList *next;
 } %(name)sList;
 ''',
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Cole Robinson

Unlike other list types, enum wasn't adding any padding, which caused a mismatch between the generated struct size and GenericList struct size. More details in a678e26cbe89f7a27cbce794c2c2784571ee9d21

This crashed qemu if calling qmp query-tpm-types for example, which upsets libvirt capabilities probing. Reproducer on i686:

(sleep 5; printf '{"execute":"qmp_capabilities"}\n{"execute":"query-tpm-types"}\n') | ./i386-softmmu/qemu-system-i386 -S -nodefaults -nographic -M none -qmp stdio

Quoted 8 lines

https://bugs.launchpad.net/qemu/+bug/1219207

---
 scripts/qapi-types.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

scripts/qapi-types.py def generate_fwd_enum_struct(name, members): · line 57

Quoted 5 lines
scripts/qapi-types.py +4 -1
-    %(name)s value;
+    union {
+        %(name)s value;
+        uint64_t padding;
+    };

Am I right that anonymous unions are only a C11 feature (not C99)? But you are just copying and pasting from the other uses in this file, so it's not a problem.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 29 lines · Eric Blake
Quoted 8 lines · Cole Robinson

Unlike other list types, enum wasn't adding any padding, which caused a mismatch between the generated struct size and GenericList struct size. More details in a678e26cbe89f7a27cbce794c2c2784571ee9d21

This crashed qemu if calling qmp query-tpm-types for example, which upsets libvirt capabilities probing. Reproducer on i686:

(sleep 5; printf

'{"execute":"qmp_capabilities"}\n{"execute":"query-tpm-types"}\n') | ./i386-softmmu/qemu-system-i386 -S -nodefaults -nographic -M none -qmp stdio

Quoted 9 lines

https://bugs.launchpad.net/qemu/+bug/1219207

---
 scripts/qapi-types.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

scripts/qapi-types.py def generate_fwd_enum_struct(name, members): · line 57

Quoted 5 lines
scripts/qapi-types.py +4 -1
-    %(name)s value;
+    union {
+        %(name)s value;
+        uint64_t padding;
+    };
Quoted 5 lines

Am I right that anonymous unions are only a C11 feature (not C99)? But you are just copying and pasting from the other uses in this file, so it's not a problem.

Yes, they're a C11-ism. But they appear in gnu99, not sure as to what GCC added them but I know GCC 3.2 didn't have them.

Signature · 1 line
Doug Goldstein
Tested-by on v1 1/1
#3 lore raw
In reply to Cole Robinson
Quoted 7 lines · Cole Robinson

Unlike other list types, enum wasn't adding any padding, which caused a mismatch between the generated struct size and GenericList struct size. More details in a678e26cbe89f7a27cbce794c2c2784571ee9d21

This crashed qemu if calling qmp query-tpm-types for example, which upsets libvirt capabilities probing. Reproducer on i686:

Quoted 6 lines

(sleep 5; printf '{"execute":"qmp_capabilities"}\n{"execute":"query-tpm-types"}\n') | ./i386-softmmu/qemu-system-i386 -S -nodefaults -nographic -M none -qmp stdio

https://bugs.launchpad.net/qemu/+bug/1219207

Works for me, so you can add:

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
#4 lore raw
In reply to Cole Robinson
Quoted 7 lines · On Sat, 31 Aug 2013 18:36:17 -0400 Cole Robinson <[email protected]> wrote:

Unlike other list types, enum wasn't adding any padding, which caused a mismatch between the generated struct size and GenericList struct size. More details in a678e26cbe89f7a27cbce794c2c2784571ee9d21

This crashed qemu if calling qmp query-tpm-types for example, which upsets libvirt capabilities probing. Reproducer on i686:

Quoted 6 lines

(sleep 5; printf '{"execute":"qmp_capabilities"}\n{"execute":"query-tpm-types"}\n') | ./i386-softmmu/qemu-system-i386 -S -nodefaults -nographic -M none -qmp stdio

https://bugs.launchpad.net/qemu/+bug/1219207

Applied to the qmp branch, thanks.

Quoted 20 lines
---
 scripts/qapi-types.py | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
scripts/qapi-types.py +4 -1
index 5ee46ea..5d31b06 100644
@@ -51,7 +51,10 @@ def generate_fwd_enum_struct(name, members):
     return mcgen('''
 typedef struct %(name)sList
 {
-    %(name)s value;
+    union {
+        %(name)s value;
+        uint64_t padding;
+    };
     struct %(name)sList *next;
 } %(name)sList;
 ''',