apic: Defer interrupt updates to VCPU thread

KVM performs TPR raising asynchronously to QEMU, specifically outside
QEMU's global lock. When an interrupt is injected into the APIC and TPR
is checked to decide if this can be delivered, a stale TPR value may be
used, causing spurious interrupts in the end.

Fix this by deferring apic_update_irq to the context of the target VCPU.
We introduce a new interrupt flag for this, CPU_INTERRUPT_POLL. When it
is set, the VCPU calls apic_poll_irq before checking for further pending
interrupts. To avoid special-casing KVM, we also implement this logic
for TCG mode.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
6 files changed
tree: 3a87b9355b9fce43838e803a38591bb0e4bb908e
  1. audio/
  2. block/
  3. bsd-user/
  4. default-configs/
  5. docs/
  6. fpu/
  7. fsdev/
  8. gdb-xml/
  9. hw/
  10. include/
  11. libcacard/
  12. linux-headers/
  13. linux-user/
  14. net/
  15. pc-bios/
  16. qapi/
  17. qga/
  18. QMP/
  19. qom/
  20. roms/
  21. scripts/
  22. slirp/
  23. sysconfigs/
  24. target-alpha/
  25. target-arm/
  26. target-cris/
  27. target-i386/
  28. target-lm32/
  29. target-m68k/
  30. target-microblaze/
  31. target-mips/
  32. target-ppc/
  33. target-s390x/
  34. target-sh4/
  35. target-sparc/
  36. target-unicore32/
  37. target-xtensa/
  38. tcg/
  39. tests/
  40. trace/
  41. ui/
  42. .gitignore
  43. .gitmodules
  44. .mailmap
  45. a.out.h
  46. acl.c
  47. acl.h
  48. aes.c
  49. aes.h
  50. aio.c
  51. alpha-dis.c
  52. alpha.ld
  53. arch_init.c
  54. arch_init.h
  55. arm-dis.c
  56. arm.ld
  57. async.c
  58. balloon.c
  59. balloon.h
  60. bitmap.c
  61. bitmap.h
  62. bitops.c
  63. bitops.h
  64. block-migration.c
  65. block-migration.h
  66. block.c
  67. block.h
  68. block_int.h
  69. blockdev.c
  70. blockdev.h
  71. bswap.h
  72. bt-host.c
  73. bt-host.h
  74. bt-vhci.c
  75. buffered_file.c
  76. buffered_file.h
  77. cache-utils.c
  78. cache-utils.h
  79. Changelog
  80. cmd.c
  81. cmd.h
  82. CODING_STYLE
  83. compatfd.c
  84. compatfd.h
  85. compiler.h
  86. config.h
  87. configure
  88. console.c
  89. console.h
  90. COPYING
  91. COPYING.LIB
  92. coroutine-gthread.c
  93. coroutine-sigaltstack.c
  94. coroutine-ucontext.c
  95. coroutine-win32.c
  96. cpu-all.h
  97. cpu-common.h
  98. cpu-defs.h
  99. cpu-exec.c
  100. cpus.c
  101. cpus.h
  102. cputlb.c
  103. cputlb.h
  104. cris-dis.c
  105. cursor.c
  106. cursor_hidden.xpm
  107. cursor_left_ptr.xpm
  108. cutils.c
  109. def-helper.h
  110. device_tree.c
  111. device_tree.h
  112. dis-asm.h
  113. disas.c
  114. disas.h
  115. dma-helpers.c
  116. dma.h
  117. dump-stub.c
  118. dump.c
  119. dump.h
  120. dyngen-exec.h
  121. elf.h
  122. envlist.c
  123. envlist.h
  124. error.c
  125. error.h
  126. error_int.h
  127. event_notifier.c
  128. event_notifier.h
  129. exec-all.h
  130. exec-memory.h
  131. exec-obsolete.h
  132. exec.c
  133. gdbstub.c
  134. gdbstub.h
  135. gen-icount.h
  136. HACKING
  137. hmp-commands.hx
  138. hmp.c
  139. hmp.h
  140. host-utils.c
  141. host-utils.h
  142. hppa-dis.c
  143. hppa.ld
  144. i386-dis.c
  145. i386.ld
  146. ia64-dis.c
  147. ia64.ld
  148. input.c
  149. int128.h
  150. iohandler.c
  151. ioport.c
  152. ioport.h
  153. iorange.h
  154. iov.c
  155. iov.h
  156. json-lexer.c
  157. json-lexer.h
  158. json-parser.c
  159. json-parser.h
  160. json-streamer.c
  161. json-streamer.h
  162. kvm-all.c
  163. kvm-stub.c
  164. kvm.h
  165. libfdt_env.h
  166. LICENSE
  167. linux-aio.c
  168. lm32-dis.c
  169. m68k-dis.c
  170. m68k.ld
  171. main-loop.c
  172. main-loop.h
  173. MAINTAINERS
  174. Makefile
  175. Makefile.dis
  176. Makefile.hw
  177. Makefile.objs
  178. Makefile.target
  179. Makefile.user
  180. memory.c
  181. memory.h
  182. memory_mapping-stub.c
  183. memory_mapping.c
  184. memory_mapping.h
  185. microblaze-dis.c
  186. migration-exec.c
  187. migration-fd.c
  188. migration-tcp.c
  189. migration-unix.c
  190. migration.c
  191. migration.h
  192. mips-dis.c
  193. mips.ld
  194. module.c
  195. module.h
  196. monitor.c
  197. monitor.h
  198. nbd.c
  199. nbd.h
  200. net.c
  201. net.h
  202. notify.c
  203. notify.h
  204. os-posix.c
  205. os-win32.c
  206. osdep.c
  207. osdep.h
  208. oslib-posix.c
  209. oslib-win32.c
  210. path.c
  211. pci-ids.txt
  212. pflib.c
  213. pflib.h
  214. poison.h
  215. posix-aio-compat.c
  216. ppc-dis.c
  217. ppc.ld
  218. ppc64.ld
  219. qapi-schema-guest.json
  220. qapi-schema-test.json
  221. qapi-schema.json
  222. qbool.c
  223. qbool.h
  224. qdict-test-data.txt
  225. qdict.c
  226. qdict.h
  227. qemu-aio.h
  228. qemu-barrier.h
  229. qemu-bridge-helper.c
  230. qemu-char.c
  231. qemu-char.h
  232. qemu-common.h
  233. qemu-config.c
  234. qemu-config.h
  235. qemu-coroutine-int.h
  236. qemu-coroutine-io.c
  237. qemu-coroutine-lock.c
  238. qemu-coroutine-sleep.c
  239. qemu-coroutine.c
  240. qemu-coroutine.h
  241. qemu-doc.texi
  242. qemu-error.c
  243. qemu-error.h
  244. qemu-file.h
  245. qemu-ga.c
  246. qemu-img-cmds.hx
  247. qemu-img.c
  248. qemu-img.texi
  249. qemu-io.c
  250. qemu-lock.h
  251. qemu-log.c
  252. qemu-log.h
  253. qemu-nbd.c
  254. qemu-nbd.texi
  255. qemu-objects.h
  256. qemu-option.c
  257. qemu-option.h
  258. qemu-options-wrapper.h
  259. qemu-options.h
  260. qemu-options.hx
  261. qemu-os-posix.h
  262. qemu-os-win32.h
  263. qemu-progress.c
  264. qemu-queue.h
  265. qemu-sockets.c
  266. qemu-tech.texi
  267. qemu-thread-posix.c
  268. qemu-thread-posix.h
  269. qemu-thread-win32.c
  270. qemu-thread-win32.h
  271. qemu-thread.h
  272. qemu-timer-common.c
  273. qemu-timer.c
  274. qemu-timer.h
  275. qemu-tls.h
  276. qemu-tool.c
  277. qemu-user.c
  278. qemu-x509.h
  279. qemu-xattr.h
  280. qemu.sasl
  281. qemu_socket.h
  282. qerror.c
  283. qerror.h
  284. qfloat.c
  285. qfloat.h
  286. qint.c
  287. qint.h
  288. qjson.c
  289. qjson.h
  290. qlist.c
  291. qlist.h
  292. qmp-commands.hx
  293. qmp.c
  294. qobject.h
  295. qstring.c
  296. qstring.h
  297. qtest.c
  298. qtest.h
  299. range.h
  300. readline.c
  301. readline.h
  302. README
  303. rules.mak
  304. s390-dis.c
  305. s390.ld
  306. savevm.c
  307. sh4-dis.c
  308. softmmu-semi.h
  309. softmmu_defs.h
  310. softmmu_exec.h
  311. softmmu_header.h
  312. softmmu_template.h
  313. sparc-dis.c
  314. sparc.ld
  315. sparc64.ld
  316. spice-qemu-char.c
  317. sysemu.h
  318. targphys.h
  319. tcg-runtime.c
  320. tci-dis.c
  321. tci.c
  322. thunk.c
  323. thunk.h
  324. TODO
  325. trace-events
  326. translate-all.c
  327. uboot_image.h
  328. user-exec.c
  329. VERSION
  330. version.rc
  331. vgafont.h
  332. vl.c
  333. vmstate.h
  334. x86_64.ld
  335. xen-all.c
  336. xen-mapcache.c
  337. xen-mapcache.h
  338. xen-stub.c