exec: Handle multipage ranges in invalidate_and_set_dirty()

The code in invalidate_and_set_dirty() needs to handle addr/length
combinations which cross guest physical page boundaries. This can happen,
for example, when disk I/O reads large blocks into guest RAM which previously
held code that we have cached translations for. Unfortunately we were only
checking the clean/dirty status of the first page in the range, and then
were calling a tb_invalidate function which only handles ranges that don't
cross page boundaries. Fix the function to deal with multipage ranges.

The symptoms of this bug were that guest code would misbehave (eg segfault),
in particular after a guest reboot but potentially any time the guest
reused a page of its physical RAM for new code.

[This is a cherry pick of upstream commit f874bf90]

Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 1416167061-13203-1-git-send-email-peter.maydell@linaro.org
2 files changed
tree: caeb0d61de8d685e804ba96bd95e95e0ff09bc61
  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. aio-posix.c
  57. aio-win32.c
  58. android-commands.h
  59. android-console.c
  60. android-console.h
  61. arch_init.c
  62. async.c
  63. balloon.c
  64. block-migration.c
  65. block.c
  66. blockdev-nbd.c
  67. blockdev.c
  68. blockjob.c
  69. bt-host.c
  70. bt-vhci.c
  71. Changelog
  72. CODING_STYLE
  73. configure
  74. COPYING
  75. COPYING.LIB
  76. coroutine-gthread.c
  77. coroutine-sigaltstack.c
  78. coroutine-ucontext.c
  79. coroutine-win32.c
  80. cpu-exec.c
  81. cpus.c
  82. cputlb.c
  83. device-hotplug.c
  84. device_tree.c
  85. disas.c
  86. dma-helpers.c
  87. dump.c
  88. exec.c
  89. gdbstub.c
  90. HACKING
  91. hmp-commands.hx
  92. hmp.c
  93. hmp.h
  94. iohandler.c
  95. ioport.c
  96. iothread.c
  97. kvm-all.c
  98. kvm-stub.c
  99. LICENSE
  100. main-loop.c
  101. MAINTAINERS
  102. Makefile
  103. Makefile.objs
  104. Makefile.target
  105. memory.c
  106. memory_mapping.c
  107. migration-exec.c
  108. migration-fd.c
  109. migration-rdma.c
  110. migration-tcp.c
  111. migration-unix.c
  112. migration.c
  113. module-common.c
  114. monitor.c
  115. nbd.c
  116. numa.c
  117. os-posix.c
  118. os-win32.c
  119. page_cache.c
  120. qapi-schema.json
  121. qdev-monitor.c
  122. qdict-test-data.txt
  123. qemu-bridge-helper.c
  124. qemu-char.c
  125. qemu-coroutine-io.c
  126. qemu-coroutine-lock.c
  127. qemu-coroutine-sleep.c
  128. qemu-coroutine.c
  129. qemu-doc.texi
  130. qemu-file.c
  131. qemu-img-cmds.hx
  132. qemu-img.c
  133. qemu-img.texi
  134. qemu-io-cmds.c
  135. qemu-io.c
  136. qemu-log.c
  137. qemu-nbd.c
  138. qemu-nbd.texi
  139. qemu-options-wrapper.h
  140. qemu-options.h
  141. qemu-options.hx
  142. qemu-seccomp.c
  143. qemu-tech.texi
  144. qemu-timer.c
  145. qemu.nsi
  146. qemu.sasl
  147. qmp-commands.hx
  148. qmp.c
  149. qtest.c
  150. README
  151. rules.mak
  152. savevm.c
  153. softmmu_template.h
  154. spice-qemu-char.c
  155. tcg-runtime.c
  156. tci.c
  157. thread-pool.c
  158. thunk.c
  159. tpm.c
  160. trace-events
  161. translate-all.c
  162. translate-all.h
  163. user-exec.c
  164. VERSION
  165. version.rc
  166. vl.c
  167. vmstate.c
  168. xbzrle.c
  169. xen-common-stub.c
  170. xen-common.c
  171. xen-hvm-stub.c
  172. xen-hvm.c
  173. xen-mapcache.c