Skip to content
Snippets Groups Projects
  1. Sep 01, 2020
  2. Aug 27, 2020
  3. Aug 21, 2020
  4. Jul 13, 2020
    • Philippe Mathieu-Daudé's avatar
      chardev: Extract system emulation specific code · 30827bad
      Philippe Mathieu-Daudé authored
      
      Split out code only used during system emulation,
      to reduce code pulled in user emulation and tools.
      
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-Id: <20200423202112.644-6-philmd@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      30827bad
    • Philippe Mathieu-Daudé's avatar
      chardev: Reduce "char-mux.h" scope, rename it "chardev-internal.h" · ffa0f7eb
      Philippe Mathieu-Daudé authored
      
      No file out of chardev/ requires access to this header,
      restrict its scope.
      
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-Id: <20200423202112.644-5-philmd@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      ffa0f7eb
    • Philippe Mathieu-Daudé's avatar
      chardev: Restrict msmouse / wctablet / testdev to system emulation · c383efd5
      Philippe Mathieu-Daudé authored
      
      The msmouse / wctablet / testdev character devices are only
      used by system emulation. Remove them from user mode and tools.
      
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-Id: <20200423202112.644-4-philmd@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      c383efd5
    • Marc-André Lureau's avatar
      char: fix use-after-free with dup chardev & reconnect · 68066019
      Marc-André Lureau authored
      
      With a reconnect socket, qemu_char_open() will start a background
      thread. It should keep a reference on the chardev.
      
      Fixes invalid read:
      READ of size 8 at 0x6040000ac858 thread T7
          #0 0x5555598d37b8 in unix_connect_saddr /home/elmarco/src/qq/util/qemu-sockets.c:954
          #1 0x5555598d4751 in socket_connect /home/elmarco/src/qq/util/qemu-sockets.c:1109
          #2 0x555559707c34 in qio_channel_socket_connect_sync /home/elmarco/src/qq/io/channel-socket.c:145
          #3 0x5555596adebb in tcp_chr_connect_client_task /home/elmarco/src/qq/chardev/char-socket.c:1104
          #4 0x555559723d55 in qio_task_thread_worker /home/elmarco/src/qq/io/task.c:123
          #5 0x5555598a6731 in qemu_thread_start /home/elmarco/src/qq/util/qemu-thread-posix.c:519
          #6 0x7ffff40d4431 in start_thread (/lib64/libpthread.so.0+0x9431)
          #7 0x7ffff40029d2 in __clone (/lib64/libc.so.6+0x1019d2)
      
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Message-Id: <20200420112012.567284-1-marcandre.lureau@redhat.com>
      68066019
    • Marc-André Lureau's avatar
      chardev: don't abort on attempt to add duplicated chardev · 14a7a203
      Marc-André Lureau authored
      
      This is a regression from commit d2623129 ("qom: Drop parameter @errp
      of object_property_add() & friends").
      
      (qemu) chardev-add id=null,backend=null
      (qemu) chardev-add id=null,backend=null
      Unexpected error in object_property_try_add() at /home/elmarco/src/qemu/qom/object.c:1166:
      attempt to add duplicate property 'null' to object (type 'container')
      
      That case is currently not covered in the test suite, but will be with
      the queued patch "char: fix use-after-free with dup chardev &
      reconnect".
      
      Fixes: d2623129
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      14a7a203
    • Li Feng's avatar
      char-socket: initialize reconnect timer only when the timer doesn't start · 2b61bb71
      Li Feng authored
      
      When the disconnect event is triggered in the connecting stage,
      the tcp_chr_disconnect_locked may be called twice.
      
      The first call:
          #0  qemu_chr_socket_restart_timer (chr=0x55555582ee90) at chardev/char-socket.c:120
          #1  0x000055555558e38c in tcp_chr_disconnect_locked (chr=<optimized out>) at chardev/char-socket.c:490
          #2  0x000055555558e3cd in tcp_chr_disconnect (chr=0x55555582ee90) at chardev/char-socket.c:497
          #3  0x000055555558ea32 in tcp_chr_new_client (chr=chr@entry=0x55555582ee90, sioc=sioc@entry=0x55555582f0b0) at chardev/char-socket.c:892
          #4  0x000055555558eeb8 in qemu_chr_socket_connected (task=0x55555582f300, opaque=<optimized out>) at chardev/char-socket.c:1090
          #5  0x0000555555574352 in qio_task_complete (task=task@entry=0x55555582f300) at io/task.c:196
          #6  0x00005555555745f4 in qio_task_thread_result (opaque=0x55555582f300) at io/task.c:111
          #7  qio_task_wait_thread (task=0x55555582f300) at io/task.c:190
          #8  0x000055555558f17e in tcp_chr_wait_connected (chr=0x55555582ee90, errp=0x555555802a08 <error_abort>) at chardev/char-socket.c:1013
          #9  0x0000555555567cbd in char_socket_client_reconnect_test (opaque=0x5555557fe020 <client8unix>) at tests/test-char.c:1152
      The second call:
          #0  0x00007ffff5ac3277 in raise () from /lib64/libc.so.6
          #1  0x00007ffff5ac4968 in abort () from /lib64/libc.so.6
          #2  0x00007ffff5abc096 in __assert_fail_base () from /lib64/libc.so.6
          #3  0x00007ffff5abc142 in __assert_fail () from /lib64/libc.so.6
          #4  0x000055555558d10a in qemu_chr_socket_restart_timer (chr=0x55555582ee90) at chardev/char-socket.c:125
          #5  0x000055555558df0c in tcp_chr_disconnect_locked (chr=<optimized out>) at chardev/char-socket.c:490
          #6  0x000055555558df4d in tcp_chr_disconnect (chr=0x55555582ee90) at chardev/char-socket.c:497
          #7  0x000055555558e5b2 in tcp_chr_new_client (chr=chr@entry=0x55555582ee90, sioc=sioc@entry=0x55555582f0b0) at chardev/char-socket.c:892
          #8  0x000055555558e93a in tcp_chr_connect_client_sync (chr=chr@entry=0x55555582ee90, errp=errp@entry=0x7fffffffd178) at chardev/char-socket.c:944
          #9  0x000055555558ec78 in tcp_chr_wait_connected (chr=0x55555582ee90, errp=0x555555802a08 <error_abort>) at chardev/char-socket.c:1035
          #10 0x000055555556804b in char_socket_client_test (opaque=0x5555557fe020 <client8unix>) at tests/test-char.c:1023
      
      Run test/test-char to reproduce this issue.
      
      test-char: chardev/char-socket.c:125: qemu_chr_socket_restart_timer: Assertion `!s->reconnect_timer' failed.
      
      Signed-off-by: default avatarLi Feng <fengli@smartx.com>
      Acked-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <20200522025554.41063-1-fengli@smartx.com>
      2b61bb71
  5. Jul 10, 2020
    • Markus Armbruster's avatar
      qemu-option: Use returned bool to check for failure · 235e59cf
      Markus Armbruster authored
      
      The previous commit enables conversion of
      
          foo(..., &err);
          if (err) {
              ...
          }
      
      to
      
          if (!foo(..., &err)) {
              ...
          }
      
      for QemuOpts functions that now return true / false on success /
      error.  Coccinelle script:
      
          @@
          identifier fun = {
              opts_do_parse, parse_option_bool, parse_option_number,
              parse_option_size, qemu_opt_parse, qemu_opt_rename, qemu_opt_set,
              qemu_opt_set_bool, qemu_opt_set_number, qemu_opts_absorb_qdict,
              qemu_opts_do_parse, qemu_opts_from_qdict_entry, qemu_opts_set,
              qemu_opts_validate
          };
          expression list args, args2;
          typedef Error;
          Error *err;
          @@
          -    fun(args, &err, args2);
          -    if (err)
          +    if (!fun(args, &err, args2))
               {
                   ...
               }
      
      A few line breaks tidied up manually.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarVladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
      Message-Id: <20200707160613.848843-15-armbru@redhat.com>
      [Conflict with commit 0b6786a9 "block/amend: refactor qcow2 amend
      options" resolved by rerunning Coccinelle on master's version]
      235e59cf
  6. Jul 07, 2020
  7. Jul 02, 2020
  8. Jun 18, 2020
  9. Jun 10, 2020
  10. Jun 09, 2020
    • Dima Stepanov's avatar
      char-socket: return -1 in case of disconnect during tcp_chr_write · 27109447
      Dima Stepanov authored
      
      During testing of the vhost-user-blk reconnect functionality the qemu
      SIGSEGV was triggered:
       start qemu as:
       x86_64-softmmu/qemu-system-x86_64 -m 1024M -M q35 \
         -object memory-backend-file,id=ram-node0,size=1024M,mem-path=/dev/shm/qemu,share=on \
         -numa node,cpus=0,memdev=ram-node0 \
         -chardev socket,id=chardev0,path=./vhost.sock,noserver,reconnect=1 \
         -device vhost-user-blk-pci,chardev=chardev0,num-queues=4 --enable-kvm
       start vhost-user-blk daemon:
       ./vhost-user-blk -s ./vhost.sock -b test-img.raw
      
      If vhost-user-blk will be killed during the vhost initialization
      process, for instance after getting VHOST_SET_VRING_CALL command, then
      QEMU will fail with the following backtrace:
      
      Thread 1 "qemu-system-x86" received signal SIGSEGV, Segmentation fault.
      0x00005555559272bb in vhost_user_read (dev=0x7fffef2d53e0, msg=0x7fffffffd5b0)
          at ./hw/virtio/vhost-user.c:260
      260         CharBackend *chr = u->user->chr;
      
       #0  0x00005555559272bb in vhost_user_read (dev=0x7fffef2d53e0, msg=0x7fffffffd5b0)
          at ./hw/virtio/vhost-user.c:260
       #1  0x000055555592acb8 in vhost_user_get_config (dev=0x7fffef2d53e0, config=0x7fffef2d5394 "", config_len=60)
          at ./hw/virtio/vhost-user.c:1645
       #2  0x0000555555925525 in vhost_dev_get_config (hdev=0x7fffef2d53e0, config=0x7fffef2d5394 "", config_len=60)
          at ./hw/virtio/vhost.c:1490
       #3  0x00005555558cc46b in vhost_user_blk_device_realize (dev=0x7fffef2d51a0, errp=0x7fffffffd8f0)
          at ./hw/block/vhost-user-blk.c:429
       #4  0x0000555555920090 in virtio_device_realize (dev=0x7fffef2d51a0, errp=0x7fffffffd948)
          at ./hw/virtio/virtio.c:3615
       #5  0x0000555555a9779c in device_set_realized (obj=0x7fffef2d51a0, value=true, errp=0x7fffffffdb88)
          at ./hw/core/qdev.c:891
       ...
      
      The problem is that vhost_user_write doesn't get an error after
      disconnect and try to call vhost_user_read(). The tcp_chr_write()
      routine should return -1 in case of disconnect. Indicate the EIO error
      if this routine is called in the disconnected state.
      
      Signed-off-by: default avatarDima Stepanov <dimastep@yandex-team.ru>
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <aeb7806bfc945faadf09f64dcfa30f59de3ac053.1590396396.git.dimastep@yandex-team.ru>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      27109447
  11. May 27, 2020
  12. May 20, 2020
  13. May 15, 2020
    • Markus Armbruster's avatar
      qom: Drop parameter @errp of object_property_add() & friends · d2623129
      Markus Armbruster authored
      
      The only way object_property_add() can fail is when a property with
      the same name already exists.  Since our property names are all
      hardcoded, failure is a programming error, and the appropriate way to
      handle it is passing &error_abort.
      
      Same for its variants, except for object_property_add_child(), which
      additionally fails when the child already has a parent.  Parentage is
      also under program control, so this is a programming error, too.
      
      We have a bit over 500 callers.  Almost half of them pass
      &error_abort, slightly fewer ignore errors, one test case handles
      errors, and the remaining few callers pass them to their own callers.
      
      The previous few commits demonstrated once again that ignoring
      programming errors is a bad idea.
      
      Of the few ones that pass on errors, several violate the Error API.
      The Error ** argument must be NULL, &error_abort, &error_fatal, or a
      pointer to a variable containing NULL.  Passing an argument of the
      latter kind twice without clearing it in between is wrong: if the
      first call sets an error, it no longer points to NULL for the second
      call.  ich9_pm_add_properties(), sparc32_ledma_realize(),
      sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
      are wrong that way.
      
      When the one appropriate choice of argument is &error_abort, letting
      users pick the argument is a bad idea.
      
      Drop parameter @errp and assert the preconditions instead.
      
      There's one exception to "duplicate property name is a programming
      error": the way object_property_add() implements the magic (and
      undocumented) "automatic arrayification".  Don't drop @errp there.
      Instead, rename object_property_add() to object_property_try_add(),
      and add the obvious wrapper object_property_add().
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20200505152926.18877-15-armbru@redhat.com>
      [Two semantic rebase conflicts resolved]
      d2623129
  14. May 04, 2020
  15. Mar 09, 2020
  16. Mar 06, 2020
    • Kevin Wolf's avatar
      hmp: Fail gracefully if chardev is already in use · 8e9119a8
      Kevin Wolf authored
      
      Trying to attach a HMP monitor to a chardev that is already in use
      results in a crash because monitor_init_hmp() passes &error_abort to
      qemu_chr_fe_init():
      
      $ ./x86_64-softmmu/qemu-system-x86_64 --chardev stdio,id=foo --mon foo --mon foo
      QEMU 4.2.50 monitor - type 'help' for more information
      (qemu) Unexpected error in qemu_chr_fe_init() at chardev/char-fe.c:220:
      qemu-system-x86_64: --mon foo: Device 'foo' is in use
      Abgebrochen (Speicherabzug geschrieben)
      
      Fix this by allowing monitor_init_hmp() to return an error and passing
      any error in qemu_chr_fe_init() to its caller instead of aborting.
      
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Message-Id: <20200224143008.13362-19-kwolf@redhat.com>
      Acked-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      8e9119a8
  17. Feb 22, 2020
  18. Jan 08, 2020
  19. Jan 07, 2020
  20. Sep 03, 2019
  21. Aug 21, 2019
    • Alberto Garcia's avatar
      char-socket: Lock tcp_chr_disconnect() and socket_reconnect_timeout() · 78d01598
      Alberto Garcia authored
      
      There's a race condition in which the tcp_chr_read() ioc handler can
      close a connection that is being written to from another thread.
      
      Running iotest 136 in a loop triggers this problem and crashes QEMU.
      
       (gdb) bt
       #0  0x00005558b842902d in object_get_class (obj=0x0) at qom/object.c:860
       #1  0x00005558b84f92db in qio_channel_writev_full (ioc=0x0, iov=0x7ffc355decf0, niov=1, fds=0x0, nfds=0, errp=0x0) at io/channel.c:76
       #2  0x00005558b84e0e9e in io_channel_send_full (ioc=0x0, buf=0x5558baf5beb0, len=138, fds=0x0, nfds=0) at chardev/char-io.c:123
       #3  0x00005558b84e4a69 in tcp_chr_write (chr=0x5558ba460380, buf=0x5558baf5beb0 "...", len=138) at chardev/char-socket.c:135
       #4  0x00005558b84dca55 in qemu_chr_write_buffer (s=0x5558ba460380, buf=0x5558baf5beb0 "...", len=138, offset=0x7ffc355dedd0, write_all=false) at chardev/char.c:112
       #5  0x00005558b84dcbc2 in qemu_chr_write (s=0x5558ba460380, buf=0x5558baf5beb0 "...", len=138, write_all=false) at chardev/char.c:147
       #6  0x00005558b84dfb26 in qemu_chr_fe_write (be=0x5558ba476610, buf=0x5558baf5beb0 "...", len=138) at chardev/char-fe.c:42
       #7  0x00005558b8088c86 in monitor_flush_locked (mon=0x5558ba476610) at monitor.c:406
       #8  0x00005558b8088e8c in monitor_puts (mon=0x5558ba476610, str=0x5558ba921e49 "") at monitor.c:449
       #9  0x00005558b8089178 in qmp_send_response (mon=0x5558ba476610, rsp=0x5558bb161600) at monitor.c:498
       #10 0x00005558b808920c in monitor_qapi_event_emit (event=QAPI_EVENT_SHUTDOWN, qdict=0x5558bb161600) at monitor.c:526
       #11 0x00005558b8089307 in monitor_qapi_event_queue_no_reenter (event=QAPI_EVENT_SHUTDOWN, qdict=0x5558bb161600) at monitor.c:551
       #12 0x00005558b80896c0 in qapi_event_emit (event=QAPI_EVENT_SHUTDOWN, qdict=0x5558bb161600) at monitor.c:626
       #13 0x00005558b855f23b in qapi_event_send_shutdown (guest=false, reason=SHUTDOWN_CAUSE_HOST_QMP_QUIT) at qapi/qapi-events-run-state.c:43
       #14 0x00005558b81911ef in qemu_system_shutdown (cause=SHUTDOWN_CAUSE_HOST_QMP_QUIT) at vl.c:1837
       #15 0x00005558b8191308 in main_loop_should_exit () at vl.c:1885
       #16 0x00005558b819140d in main_loop () at vl.c:1924
       #17 0x00005558b8198c84 in main (argc=18, argv=0x7ffc355df3f8, envp=0x7ffc355df490) at vl.c:4665
      
      This patch adds a lock to protect tcp_chr_disconnect() and
      socket_reconnect_timeout()
      
      Signed-off-by: default avatarAlberto Garcia <berto@igalia.com>
      Signed-off-by: default avatarAndrey Shinkevich <andrey.shinkevich@virtuozzo.com>
      Message-Id: <1565625509-404969-3-git-send-email-andrey.shinkevich@virtuozzo.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      78d01598
  22. Aug 16, 2019
  23. Jun 18, 2019
  24. Jun 12, 2019
    • Markus Armbruster's avatar
      Include qemu-common.h exactly where needed · a8d25326
      Markus Armbruster authored
      
      No header includes qemu-common.h after this commit, as prescribed by
      qemu-common.h's file comment.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190523143508.25387-5-armbru@redhat.com>
      [Rebased with conflicts resolved automatically, except for
      include/hw/arm/xlnx-zynqmp.h hw/arm/nrf51_soc.c hw/arm/msf2-soc.c
      block/qcow2-refcount.c block/qcow2-cluster.c block/qcow2-cache.c
      target/arm/cpu.h target/lm32/cpu.h target/m68k/cpu.h target/mips/cpu.h
      target/moxie/cpu.h target/nios2/cpu.h target/openrisc/cpu.h
      target/riscv/cpu.h target/tilegx/cpu.h target/tricore/cpu.h
      target/unicore32/cpu.h target/xtensa/cpu.h; bsd-user/main.c and
      net/tap-bsd.c fixed up]
      a8d25326
    • Markus Armbruster's avatar
      Include qemu/module.h where needed, drop it from qemu-common.h · 0b8fa32f
      Markus Armbruster authored
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190523143508.25387-4-armbru@redhat.com>
      [Rebased with conflicts resolved automatically, except for
      hw/usb/dev-hub.c hw/misc/exynos4210_rng.c hw/misc/bcm2835_rng.c
      hw/misc/aspeed_scu.c hw/display/virtio-vga.c hw/arm/stm32f205_soc.c;
      ui/cocoa.m fixed up]
      0b8fa32f
  25. Apr 18, 2019
  26. Apr 16, 2019
  27. Mar 22, 2019
Loading