target-arm: handle address translations that start at level 3

The ARMv8 address translation system defines that a page table walk
starts at a level which depends on the translation granule size
and the number of bits of virtual address that need to be resolved.
Where the translation granule is 64KB and the guest sets the
TCR.TxSZ field to between 35 and 39, it's actually possible to
start at level 3 (the final level). QEMU's implementation failed
to handle this case, and so we would set level to 2 and behave
incorrectly (including invoking the C undefined behaviour of
shifting left by a negative number). Correct the code that
determines the starting level to deal with the start-at-3 case,
by replacing the if-else ladder with an expression derived from
the ARM ARM pseudocode version.

This error was detected by the Coverity scan, which spotted
the potential shift by a negative number.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Message-id: 1415890569-7454-1-git-send-email-peter.maydell@linaro.org
1 file changed
tree: f5658b03ccd9c31765b3020f4ac1b35a599d860d
  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