Fix for crash after migration in virtio-rng on bi-endian targets

VirtIO devices now remember which endianness they're operating in in order
to support targets which may have guests of either endianness, such as
powerpc.  This endianness state is transferred in a subsection of the
virtio device's information.

With virtio-rng this can lead to an abort after a loadvm hitting the
assert() in virtio_is_big_endian().  This can be reproduced by doing a
migrate and load from file on a bi-endian target with a virtio-rng device.
The actual guest state isn't particularly important to triggering this.

The cause is that virtio_rng_load_device() calls virtio_rng_process() which
accesses the ring and thus needs the endianness.  However,
virtio_rng_process() is called via virtio_load() before it loads the
subsections.  Essentially the ->load callback in VirtioDeviceClass should
only be used for actually reading the device state from the stream, not for
post-load re-initialization.

This patch fixes the bug by moving the virtio_rng_process() after the call
to virtio_load().  Better yet would be to convert virtio to use vmsd and
have the virtio_rng_process() as a post_load callback, but that's a bigger
project for another day.

This is bugfix, and should be considered for the 2.2 branch.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Greg Kurz <gkurz@linux.vnet.ibm.com>
Message-id: 1417067290-20715-1-git-send-email-david@gibson.dropbear.id.au
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
1 file changed
tree: e32476479f04b46d0f59af67bb4e1d5192ae7b14
  1. audio/
  2. backends/
  3. block/
  4. bsd-user/
  5. default-configs/
  6. disas/
  7. docs/
  8. fpu/
  9. fsdev/
  10. gdb-xml/
  11. hw/
  12. include/
  13. libcacard/
  14. libdecnumber/
  15. linux-headers/
  16. linux-user/
  17. net/
  18. pc-bios/
  19. po/
  20. qapi/
  21. qga/
  22. qobject/
  23. qom/
  24. roms/
  25. scripts/
  26. slirp/
  27. stubs/
  28. sysconfigs/
  29. target-alpha/
  30. target-arm/
  31. target-cris/
  32. target-i386/
  33. target-lm32/
  34. target-m68k/
  35. target-microblaze/
  36. target-mips/
  37. target-moxie/
  38. target-openrisc/
  39. target-ppc/
  40. target-s390x/
  41. target-sh4/
  42. target-sparc/
  43. target-tricore/
  44. target-unicore32/
  45. target-xtensa/
  46. tcg/
  47. tests/
  48. trace/
  49. ui/
  50. util/
  51. .exrc
  52. .gitignore
  53. .gitmodules
  54. .mailmap
  55. .travis.yml
  56. accel.c
  57. aio-posix.c
  58. aio-win32.c
  59. arch_init.c
  60. async.c
  61. balloon.c
  62. block-migration.c
  63. block.c
  64. blockdev-nbd.c
  65. blockdev.c
  66. blockjob.c
  67. bootdevice.c
  68. bt-host.c
  69. bt-vhci.c
  70. Changelog
  71. CODING_STYLE
  72. configure
  73. COPYING
  74. COPYING.LIB
  75. coroutine-gthread.c
  76. coroutine-sigaltstack.c
  77. coroutine-ucontext.c
  78. coroutine-win32.c
  79. cpu-exec.c
  80. cpus.c
  81. cputlb.c
  82. device-hotplug.c
  83. device_tree.c
  84. disas.c
  85. dma-helpers.c
  86. dump.c
  87. exec.c
  88. gdbstub.c
  89. HACKING
  90. hmp-commands.hx
  91. hmp.c
  92. hmp.h
  93. iohandler.c
  94. ioport.c
  95. iothread.c
  96. kvm-all.c
  97. kvm-stub.c
  98. LICENSE
  99. main-loop.c
  100. MAINTAINERS
  101. Makefile
  102. Makefile.objs
  103. Makefile.target
  104. memory.c
  105. memory_mapping.c
  106. migration-exec.c
  107. migration-fd.c
  108. migration-rdma.c
  109. migration-tcp.c
  110. migration-unix.c
  111. migration.c
  112. module-common.c
  113. monitor.c
  114. nbd.c
  115. numa.c
  116. os-posix.c
  117. os-win32.c
  118. page_cache.c
  119. qapi-schema.json
  120. qdev-monitor.c
  121. qdict-test-data.txt
  122. qemu-bridge-helper.c
  123. qemu-char.c
  124. qemu-coroutine-io.c
  125. qemu-coroutine-lock.c
  126. qemu-coroutine-sleep.c
  127. qemu-coroutine.c
  128. qemu-doc.texi
  129. qemu-file-stdio.c
  130. qemu-file-unix.c
  131. qemu-file.c
  132. qemu-img-cmds.hx
  133. qemu-img.c
  134. qemu-img.texi
  135. qemu-io-cmds.c
  136. qemu-io.c
  137. qemu-log.c
  138. qemu-nbd.c
  139. qemu-nbd.texi
  140. qemu-options-wrapper.h
  141. qemu-options.h
  142. qemu-options.hx
  143. qemu-seccomp.c
  144. qemu-tech.texi
  145. qemu-timer.c
  146. qemu.nsi
  147. qemu.sasl
  148. qmp-commands.hx
  149. qmp.c
  150. qtest.c
  151. README
  152. rules.mak
  153. savevm.c
  154. softmmu_template.h
  155. spice-qemu-char.c
  156. tcg-runtime.c
  157. tci.c
  158. thread-pool.c
  159. thunk.c
  160. tpm.c
  161. trace-events
  162. translate-all.c
  163. translate-all.h
  164. user-exec.c
  165. VERSION
  166. version.rc
  167. vl.c
  168. vmstate.c
  169. xbzrle.c
  170. xen-common-stub.c
  171. xen-common.c
  172. xen-hvm-stub.c
  173. xen-hvm.c
  174. xen-mapcache.c