Skip to content
Snippets Groups Projects
  1. May 03, 2022
  2. Apr 06, 2022
  3. Jun 04, 2021
  4. May 27, 2021
  5. Jul 15, 2020
    • Daniel P. Berrangé's avatar
      net: detect errors from probing vnet hdr flag for TAP devices · e7b347d0
      Daniel P. Berrangé authored
      
      When QEMU sets up a tap based network device backend, it mostly ignores errors
      reported from various ioctl() calls it makes, assuming the TAP file descriptor
      is valid. This assumption can easily be violated when the user is passing in a
      pre-opened file descriptor. At best, the ioctls may fail with a -EBADF, but if
      the user passes in a bogus FD number that happens to clash with a FD number that
      QEMU has opened internally for another reason, a wide variety of errnos may
      result, as the TUNGETIFF ioctl number may map to a completely different command
      on a different type of file.
      
      By ignoring all these errors, QEMU sets up a zombie network backend that will
      never pass any data. Even worse, when QEMU shuts down, or that network backend
      is hot-removed, it will close this bogus file descriptor, which could belong to
      another QEMU device backend.
      
      There's no obvious guaranteed reliable way to detect that a FD genuinely is a
      TAP device, as opposed to a UNIX socket, or pipe, or something else. Checking
      the errno from probing vnet hdr flag though, does catch the big common cases.
      ie calling TUNGETIFF will return EBADF for an invalid FD, and ENOTTY when FD is
      a UNIX socket, or pipe which catches accidental collisions with FDs used for
      stdio, or monitor socket.
      
      Previously the example below where bogus fd 9 collides with the FD used for the
      chardev saw:
      
      $ ./x86_64-softmmu/qemu-system-x86_64 -netdev tap,id=hostnet0,fd=9 \
        -chardev socket,id=charchannel0,path=/tmp/qga,server,nowait \
        -monitor stdio -vnc :0
      qemu-system-x86_64: -netdev tap,id=hostnet0,fd=9: TUNGETIFF ioctl() failed: Inappropriate ioctl for device
      TUNSETOFFLOAD ioctl() failed: Bad address
      QEMU 2.9.1 monitor - type 'help' for more information
      (qemu) Warning: netdev hostnet0 has no peer
      
      which gives a running QEMU with a zombie network backend.
      
      With this change applied we get an error message and QEMU immediately exits
      before carrying on and making a bigger disaster:
      
      $ ./x86_64-softmmu/qemu-system-x86_64 -netdev tap,id=hostnet0,fd=9 \
        -chardev socket,id=charchannel0,path=/tmp/qga,server,nowait \
        -monitor stdio -vnc :0
      qemu-system-x86_64: -netdev tap,id=hostnet0,vhost=on,fd=9: Unable to query TUNGETIFF on FD 9: Inappropriate ioctl for device
      
      Reported-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
      Signed-off-by: default avatarDaniel P. Berrange <berrange@redhat.com>
      Tested-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
      Message-id: 20171027085548.3472-1-berrange@redhat.com
      [lv: to simplify, don't check on EINVAL with TUNGETIFF as it exists since v2.6.27]
      Signed-off-by: default avatarLaurent Vivier <lvivier@redhat.com>
      Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
      e7b347d0
  6. Aug 16, 2019
    • Markus Armbruster's avatar
      Clean up inclusion of sysemu/sysemu.h · d5938f29
      Markus Armbruster authored
      
      In my "build everything" tree, changing sysemu/sysemu.h triggers a
      recompile of some 5400 out of 6600 objects (not counting tests and
      objects that don't depend on qemu/osdep.h).
      
      Almost a third of its inclusions are actually superfluous.  Delete
      them.  Downgrade two more to qapi/qapi-types-run-state.h, and move one
      from char/serial.h to char/serial.c.
      
      hw/semihosting/config.c, monitor/monitor.c, qdev-monitor.c, and
      stubs/semihost.c define variables declared in sysemu/sysemu.h without
      including it.  The compiler is cool with that, but include it anyway.
      
      This doesn't reduce actual use much, as it's still included into
      widely included headers.  The next commit will tackle that.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Message-Id: <20190812052359.30071-27-armbru@redhat.com>
      Reviewed-by: default avatarAlex Bennée <alex.bennee@linaro.org>
      d5938f29
  7. 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
  8. Oct 26, 2016
  9. Mar 22, 2016
    • Veronia Bahaa's avatar
      util: move declarations out of qemu-common.h · f348b6d1
      Veronia Bahaa authored
      
      Move declarations out of qemu-common.h for functions declared in
      utils/ files: e.g. include/qemu/path.h for utils/path.c.
      Move inline functions out of qemu-common.h and into new files (e.g.
      include/qemu/bcd.h)
      
      Signed-off-by: default avatarVeronia Bahaa <veroniabahaa@gmail.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      f348b6d1
    • Markus Armbruster's avatar
      include/qemu/osdep.h: Don't include qapi/error.h · da34e65c
      Markus Armbruster authored
      
      Commit 57cb38b3 included qapi/error.h into qemu/osdep.h to get the
      Error typedef.  Since then, we've moved to include qemu/osdep.h
      everywhere.  Its file comment explains: "To avoid getting into
      possible circular include dependencies, this file should not include
      any other QEMU headers, with the exceptions of config-host.h,
      compiler.h, os-posix.h and os-win32.h, all of which are doing a
      similar job to this file and are under similar constraints."
      qapi/error.h doesn't do a similar job, and it doesn't adhere to
      similar constraints: it includes qapi-types.h.  That's in excess of
      100KiB of crap most .c files don't actually need.
      
      Add the typedef to qemu/typedefs.h, and include that instead of
      qapi/error.h.  Include qapi/error.h in .c files that need it and don't
      get it now.  Include qapi-types.h in qom/object.h for uint16List.
      
      Update scripts/clean-includes accordingly.  Update it further to match
      reality: replace config.h by config-target.h, add sysemu/os-posix.h,
      sysemu/os-win32.h.  Update the list of includes in the qemu/osdep.h
      comment quoted above similarly.
      
      This reduces the number of objects depending on qapi/error.h from "all
      of them" to less than a third.  Unfortunately, the number depending on
      qapi-types.h shrinks only a little.  More work is needed for that one.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      [Fix compilation without the spice devel packages. - Paolo]
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      da34e65c
  10. Feb 04, 2016
    • Peter Maydell's avatar
      net: Clean up includes · 2744d920
      Peter Maydell authored
      
      Clean up includes so that osdep.h is included first and headers
      which it implies are not included manually.
      
      This commit was created with scripts/clean-includes.
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1454089805-5470-11-git-send-email-peter.maydell@linaro.org
      2744d920
  11. Nov 06, 2015
  12. Jun 19, 2015
  13. May 27, 2015
  14. Aug 01, 2014
  15. Sep 06, 2013
  16. May 24, 2013
  17. Feb 01, 2013
    • Jason Wang's avatar
      tap: multiqueue support · 264986e2
      Jason Wang authored
      
      Recently, linux support multiqueue tap which could let userspace call TUNSETIFF
      for a signle device many times to create multiple file descriptors as
      independent queues. User could also enable/disabe a specific queue through
      TUNSETQUEUE.
      
      The patch adds the generic infrastructure to create multiqueue taps. To achieve
      this a new parameter "queues" were introduced to specify how many queues were
      expected to be created for tap by qemu itself. Alternatively, management could
      also pass multiple pre-created tap file descriptors separated with ':' through a
      new parameter fds like -netdev tap,id=hn0,fds="X:Y:..:Z". Multiple vhost file
      descriptors could also be passed in this way.
      
      Each TAPState were still associated to a tap fd, which mean multiple TAPStates
      were created when user needs multiqueue taps. Since each TAPState contains one
      NetClientState, with the multiqueue nic support, an N peers of NetClientState
      were built up.
      
      A new parameter, mq_required were introduce in tap_open() to create multiqueue
      tap fds.
      
      Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
      Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
      264986e2
    • Jason Wang's avatar
      tap: introduce a helper to get the name of an interface · e5dc0b40
      Jason Wang authored
      
      This patch introduces a helper tap_get_ifname() to get the device name of tap
      device. This is needed when ifname is unspecified in the command line and qemu
      were asked to create tap device by itself. In this situation, the name were
      allocated by kernel, so if multiqueue is asked, we need to fetch its name after
      creating the first queue.
      
      Only linux has this support since it's the only platform that supports
      multiqueue tap.
      
      Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
      Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
      e5dc0b40
    • Jason Wang's avatar
      tap: add Linux multiqueue support · 94fdc6d0
      Jason Wang authored
      
      This patch add basic multiqueue support for Linux. When multiqueue is needed, we
      will first check whether kernel support multiqueue tap before creating more
      queues. Two new functions tap_fd_enable() and tap_fd_disable() were introduced
      to enable and disable a specific queue. Since the multiqueue is only supported
      in Linux, return error on other platforms.
      
      Signed-off-by: default avatarJason Wang <jasowang@redhat.com>
      Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
      94fdc6d0
  18. Dec 19, 2012
  19. Jul 23, 2012
  20. Jun 09, 2012
    • Michael Tokarev's avatar
      do not include <libutil.h> needlessly or if it doesn't exist · 3294ce18
      Michael Tokarev authored
      
      <libutil.h> and <util.h> on *BSD (some have one, some another)
      were #included just for openpty() declaration.  The only file
      where this function is actually used is qemu-char.c.
      
      In vl.c and net/tap-bsd.c, none of functions declared in libutil.h
      (login logout logwtmp timdomain openpty forkpty uu_lock realhostname
      fparseln and a few others depending on version) are used.
      
      Initially the code which is currently in qemu-char.c was in vl.c,
      it has been removed into separate file in commit 0e82f34d
      Fri Oct 31 18:44:40 2008, but the #includes were left in vl.c.
      So with vl.c, we just remove includes - libutil.h, util.h and
      pty.h (which declares only openpty() and forkpty()) from there.
      
      The code in net/tap-bsd.c, which come from net/tap.c, had this
      
      commit 5281d757
      Author: Mark McLoughlin <markmc@redhat.com>
      Date:   Thu Oct 22 17:49:07 2009 +0100
      
          net: split all the tap code out into net/tap.c
      
      Note this commit not only moved stuff out of net.c to net/tap.c,
      but also rewrote large portions of the tap code, and added these
      completely unnecessary #includes -- as usual, I question why such
      a misleading commit messages are allowed.
      
      Again, no functions defined in libutil.h or util.h on *BSD are
      used by neither net/tap.c nor net/tap-bsd.c.  Removing them.
      
      And finally, the only real user for these #includes, qemu-char.c,
      which actually uses openpty().  There, the #ifdef logic is wrong.
      A GLIBC-based system has <pty.h>, even if it is a variant of *BSD.
      So __GLIBC__ should be checked first, and instead of trying to
      include <libutil.h> or <util.h>, we include <pty.h>.  If it is not
      GLIBC-based, we check for variations between <*util.h> as before.
      
      This patch fixes build of qemu 1.1 on Debian/kFreebsd (well, one
      of the two problems): it is a distribution with a FreeBSD kernel,
      so it #defines at least __FreeBSD_kernel__, but since it is based
      on GLIBC, it has <pty.h>, but current version does not have neither
      <util.h> nor <libutil.h>, which the code tries to include 3 times
      but uses only once.
      
      Signed-off-By: default avatarMichael Tokarev <mjt@tls.msk.ru>
      Cc: Aurelien Jarno <aurelien@aurel32.net>
      
      Signed-off-by: default avatarBlue Swirl <blauwirbel@gmail.com>
      3294ce18
  21. Aug 07, 2011
  22. Dec 21, 2010
  23. Sep 29, 2010
  24. Sep 07, 2010
  25. Mar 27, 2010
    • Blue Swirl's avatar
      Fix BSD and win32 builds · 73d96e29
      Blue Swirl authored
      
        CC    net/tap-bsd.o
      /src/qemu/net/tap-bsd.c: In function `tap_open':
      /src/qemu/net/tap-bsd.c:93: warning: implicit declaration of function `error_report'
      
        CC    sparc-softmmu/../net/tap-win32.o
      cc1: warnings being treated as errors
      /src/qemu/target-sparc/../net/tap-win32.c: In function 'net_init_tap':
      /src/qemu/target-sparc/../net/tap-win32.c:709: warning: implicit declaration of function 'error_report'
      
      Signed-off-by: default avatarBlue Swirl <blauwirbel@gmail.com>
      73d96e29
  26. Mar 16, 2010
    • Markus Armbruster's avatar
      error: Replace qemu_error() by error_report() · 1ecda02b
      Markus Armbruster authored
      error_report() terminates the message with a newline.  Strip it it
      from its arguments.
      
      This fixes a few error messages lacking a newline:
      net_handle_fd_param()'s "No file descriptor named %s found", and
      tap_open()'s "vnet_hdr=1 requested, but no kernel support for
      IFF_VNET_HDR available" (all three versions).
      
      There's one place that passes arguments without newlines
      intentionally: load_vmstate().  Fix it up.
      1ecda02b
  27. Nov 29, 2009
  28. Nov 21, 2009
  29. Oct 30, 2009
Loading