Skip to content
Snippets Groups Projects
  1. May 12, 2022
    • Eric Blake's avatar
      nbd/server: Allow MULTI_CONN for shared writable exports · 58a6fdcc
      Eric Blake authored
      
      According to the NBD spec, a server that advertises
      NBD_FLAG_CAN_MULTI_CONN promises that multiple client connections will
      not see any cache inconsistencies: when properly separated by a single
      flush, actions performed by one client will be visible to another
      client, regardless of which client did the flush.
      
      We always satisfy these conditions in qemu - even when we support
      multiple clients, ALL clients go through a single point of reference
      into the block layer, with no local caching.  The effect of one client
      is instantly visible to the next client.  Even if our backend were a
      network device, we argue that any multi-path caching effects that
      would cause inconsistencies in back-to-back actions not seeing the
      effect of previous actions would be a bug in that backend, and not the
      fault of caching in qemu.  As such, it is safe to unconditionally
      advertise CAN_MULTI_CONN for any qemu NBD server situation that
      supports parallel clients.
      
      Note, however, that we don't want to advertise CAN_MULTI_CONN when we
      know that a second client cannot connect (for historical reasons,
      qemu-nbd defaults to a single connection while nbd-server-add and QMP
      commands default to unlimited connections; but we already have
      existing means to let either style of NBD server creation alter those
      defaults).  This is visible by no longer advertising MULTI_CONN for
      'qemu-nbd -r' without -e, as in the iotest nbd-qemu-allocation.
      
      The harder part of this patch is setting up an iotest to demonstrate
      behavior of multiple NBD clients to a single server.  It might be
      possible with parallel qemu-io processes, but I found it easier to do
      in python with the help of libnbd, and help from Nir and Vladimir in
      writing the test.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Suggested-by: default avatarNir Soffer <nsoffer@redhat.com>
      Suggested-by: default avatarVladimir Sementsov-Ogievskiy <v.sementsov-og@mail.ru>
      Message-Id: <20220512004924.417153-3-eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      58a6fdcc
    • Eric Blake's avatar
      qemu-nbd: Pass max connections to blockdev layer · a5fced40
      Eric Blake authored
      
      The next patch wants to adjust whether the NBD server code advertises
      MULTI_CONN based on whether it is known if the server limits to
      exactly one client.  For a server started by QMP, this information is
      obtained through nbd_server_start (which can support more than one
      export); but for qemu-nbd (which supports exactly one export), it is
      controlled only by the command-line option -e/--shared.  Since we
      already have a hook function used by qemu-nbd, it's easiest to just
      alter its signature to fit our needs.
      
      Signed-off-by: default avatarEric Blake <eblake@redhat.com>
      Message-Id: <20220512004924.417153-2-eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      a5fced40
    • Philippe Mathieu-Daudé's avatar
      tests/qtest/fdc-test: Add a regression test for CVE-2021-3507 · 46609b90
      Philippe Mathieu-Daudé authored
      Add the reproducer from https://gitlab.com/qemu-project/qemu/-/issues/339
      
      
      
      Without the previous commit, when running 'make check-qtest-i386'
      with QEMU configured with '--enable-sanitizers' we get:
      
        ==4028352==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x619000062a00 at pc 0x5626d03c491a bp 0x7ffdb4199410 sp 0x7ffdb4198bc0
        READ of size 786432 at 0x619000062a00 thread T0
            #0 0x5626d03c4919 in __asan_memcpy (qemu-system-i386+0x1e65919)
            #1 0x5626d1c023cc in flatview_write_continue softmmu/physmem.c:2787:13
            #2 0x5626d1bf0c0f in flatview_write softmmu/physmem.c:2822:14
            #3 0x5626d1bf0798 in address_space_write softmmu/physmem.c:2914:18
            #4 0x5626d1bf0f37 in address_space_rw softmmu/physmem.c:2924:16
            #5 0x5626d1bf14c8 in cpu_physical_memory_rw softmmu/physmem.c:2933:5
            #6 0x5626d0bd5649 in cpu_physical_memory_write include/exec/cpu-common.h:82:5
            #7 0x5626d0bd0a07 in i8257_dma_write_memory hw/dma/i8257.c:452:9
            #8 0x5626d09f825d in fdctrl_transfer_handler hw/block/fdc.c:1616:13
            #9 0x5626d0a048b4 in fdctrl_start_transfer hw/block/fdc.c:1539:13
            #10 0x5626d09f4c3e in fdctrl_write_data hw/block/fdc.c:2266:13
            #11 0x5626d09f22f7 in fdctrl_write hw/block/fdc.c:829:9
            #12 0x5626d1c20bc5 in portio_write softmmu/ioport.c:207:17
      
        0x619000062a00 is located 0 bytes to the right of 512-byte region [0x619000062800,0x619000062a00)
        allocated by thread T0 here:
            #0 0x5626d03c66ec in posix_memalign (qemu-system-i386+0x1e676ec)
            #1 0x5626d2b988d4 in qemu_try_memalign util/oslib-posix.c:210:11
            #2 0x5626d2b98b0c in qemu_memalign util/oslib-posix.c:226:27
            #3 0x5626d09fbaf0 in fdctrl_realize_common hw/block/fdc.c:2341:20
            #4 0x5626d0a150ed in isabus_fdc_realize hw/block/fdc-isa.c:113:5
            #5 0x5626d2367935 in device_set_realized hw/core/qdev.c:531:13
      
        SUMMARY: AddressSanitizer: heap-buffer-overflow (qemu-system-i386+0x1e65919) in __asan_memcpy
        Shadow bytes around the buggy address:
          0x0c32800044f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
          0x0c3280004500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
          0x0c3280004510: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
          0x0c3280004520: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
          0x0c3280004530: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
        =>0x0c3280004540:[fa]fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
          0x0c3280004550: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
          0x0c3280004560: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
          0x0c3280004570: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
          0x0c3280004580: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
          0x0c3280004590: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
        Shadow byte legend (one shadow byte represents 8 application bytes):
          Addressable:           00
          Heap left redzone:       fa
          Freed heap region:       fd
        ==4028352==ABORTING
      
      [ kwolf: Added snapshot=on to prevent write file lock failure ]
      
      Reported-by: default avatarAlexander Bulekov <alxndr@bu.edu>
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: default avatarAlexander Bulekov <alxndr@bu.edu>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      46609b90
    • Philippe Mathieu-Daudé's avatar
      hw/block/fdc: Prevent end-of-track overrun (CVE-2021-3507) · defac5e2
      Philippe Mathieu-Daudé authored
      
      Per the 82078 datasheet, if the end-of-track (EOT byte in
      the FIFO) is more than the number of sectors per side, the
      command is terminated unsuccessfully:
      
      * 5.2.5 DATA TRANSFER TERMINATION
      
        The 82078 supports terminal count explicitly through
        the TC pin and implicitly through the underrun/over-
        run and end-of-track (EOT) functions. For full sector
        transfers, the EOT parameter can define the last
        sector to be transferred in a single or multisector
        transfer. If the last sector to be transferred is a par-
        tial sector, the host can stop transferring the data in
        mid-sector, and the 82078 will continue to complete
        the sector as if a hardware TC was received. The
        only difference between these implicit functions and
        TC is that they return "abnormal termination" result
        status. Such status indications can be ignored if they
        were expected.
      
      * 6.1.3 READ TRACK
      
        This command terminates when the EOT specified
        number of sectors have been read. If the 82078
        does not find an I D Address Mark on the diskette
        after the second· occurrence of a pulse on the
        INDX# pin, then it sets the IC code in Status Regis-
        ter 0 to "01" (Abnormal termination), sets the MA bit
        in Status Register 1 to "1", and terminates the com-
        mand.
      
      * 6.1.6 VERIFY
      
        Refer to Table 6-6 and Table 6-7 for information
        concerning the values of MT and EC versus SC and
        EOT value.
      
      * Table 6·6. Result Phase Table
      
      * Table 6-7. Verify Command Result Phase Table
      
      Fix by aborting the transfer when EOT > # Sectors Per Side.
      
      Cc: qemu-stable@nongnu.org
      Cc: Hervé Poussineau <hpoussin@reactos.org>
      Fixes: baca51fa ("floppy driver: disk geometry auto detect")
      Reported-by: default avatarAlexander Bulekov <alxndr@bu.edu>
      Resolves: https://gitlab.com/qemu-project/qemu/-/issues/339
      
      
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Message-Id: <20211118115733.4038610-2-philmd@redhat.com>
      Reviewed-by: default avatarHanna Reitz <hreitz@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      defac5e2
    • Daniel P. Berrangé's avatar
      .gitlab-ci.d: export meson testlog.txt as an artifact · 29a49376
      Daniel P. Berrangé authored
      
      When running 'make check' we only get a summary of progress on the
      console. Fortunately meson/ninja have saved the raw test output to a
      logfile. Exposing this log will make it easier to debug failures that
      happen in CI.
      
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Message-Id: <20220509124134.867431-3-berrange@redhat.com>
      Reviewed-by: default avatarThomas Huth <thuth@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      29a49376
    • Daniel P. Berrangé's avatar
      tests/qemu-iotests: print intent to run a test in TAP mode · 5e781c70
      Daniel P. Berrangé authored
      
      When running I/O tests using TAP output mode, we get a single TAP test
      with a sub-test reported for each I/O test that is run. The output looks
      something like this:
      
       1..123
       ok qcow2 011
       ok qcow2 012
       ok qcow2 013
       ok qcow2 217
       ...
      
      If everything runs or fails normally this is fine, but periodically we
      have been seeing the test harness abort early before all 123 tests have
      been run, just leaving a fairly useless message like
      
        TAP parsing error: Too few tests run (expected 123, got 107)
      
      we have no idea which tests were running at the time the test harness
      abruptly exited. This change causes us to print a message about our
      intent to run each test, so we have a record of what is active at the
      time the harness exits abnormally.
      
       1..123
       # running qcow2 011
       ok qcow2 011
       # running qcow2 012
       ok qcow2 012
       # running qcow2 013
       ok qcow2 013
       # running qcow2 217
       ok qcow2 217
       ...
      
      Signed-off-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Message-Id: <20220509124134.867431-2-berrange@redhat.com>
      Reviewed-by: default avatarThomas Huth <thuth@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      5e781c70
    • Hanna Reitz's avatar
      iotests/testrunner: Flush after run_test() · 22d92e71
      Hanna Reitz authored
      
      When stdout is not a terminal, the buffer may not be flushed at each end
      of line, so we should flush after each test is done.  This is especially
      apparent when run by check-block, in two ways:
      
      First, when running make check-block -jX with X > 1, progress indication
      was missing, even though testrunner.py does theoretically print each
      test's status once it has been run, even in multi-processing mode.
      Flushing after each test restores this progress indication.
      
      Second, sometimes make check-block failed altogether, with an error
      message that "too few tests [were] run".  I presume that's because one
      worker process in the job pool did not get to flush its stdout before
      the main process exited, and so meson did not get to see that worker's
      test results.  In any case, by flushing at the end of run_test(), the
      problem has disappeared for me.
      
      Signed-off-by: default avatarHanna Reitz <hreitz@redhat.com>
      Message-Id: <20220506134215.10086-1-hreitz@redhat.com>
      Reviewed-by: default avatarEric Blake <eblake@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      22d92e71
    • Kevin Wolf's avatar
      coroutine: Revert to constant batch size · 9ec7a59b
      Kevin Wolf authored
      Commit 4c41c69e changed the way the coroutine pool is sized because for
      virtio-blk devices with a large queue size and heavy I/O, it was just
      too small and caused coroutines to be deleted and reallocated soon
      afterwards. The change made the size dynamic based on the number of
      queues and the queue size of virtio-blk devices.
      
      There are two important numbers here: Slightly simplified, when a
      coroutine terminates, it is generally stored in the global release pool
      up to a certain pool size, and if the pool is full, it is freed.
      Conversely, when allocating a new coroutine, the coroutines in the
      release pool are reused if the pool already has reached a certain
      minimum size (the batch size), otherwise we allocate new coroutines.
      
      The problem after commit 4c41c69e is that it not only increases the
      maximum pool size (which is the intended effect), but also the batch
      size for reusing coroutines (which is a bug). It means that in cases
      with many devices and/or a large queue size (which defaults to the
      number of vcpus for virtio-blk-pci), many thousand coroutines could be
      sitting in the release pool without being reused.
      
      This is not only a waste of memory and allocations, but it actually
      makes the QEMU process likely to hit the vm.max_map_count limit on Linux
      because each coroutine requires two mappings (its stack and the guard
      page for the stack), causing it to abort() in qemu_alloc_stack() because
      when the limit is hit, mprotect() starts to fail with ENOMEM.
      
      In order to fix the problem, change the batch size back to 64 to avoid
      uselessly accumulating coroutines in the release pool, but keep the
      dynamic maximum pool size so that coroutines aren't freed too early
      in heavy I/O scenarios.
      
      Note that this fix doesn't strictly make it impossible to hit the limit,
      but this would only happen if most of the coroutines are actually in use
      at the same time, not just sitting in a pool. This is the same behaviour
      as we already had before commit 4c41c69e. Fully preventing this would
      require allowing qemu_coroutine_create() to return an error, but it
      doesn't seem to be a scenario that people hit in practice.
      
      Cc: qemu-stable@nongnu.org
      Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2079938
      
      
      Fixes: 4c41c69e
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Message-Id: <20220510151020.105528-3-kwolf@redhat.com>
      Tested-by: default avatarHiroki Narukawa <hnarukaw@yahoo-corp.jp>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      9ec7a59b
    • Kevin Wolf's avatar
      coroutine: Rename qemu_coroutine_inc/dec_pool_size() · 98e3ab35
      Kevin Wolf authored
      
      It's true that these functions currently affect the batch size in which
      coroutines are reused (i.e. moved from the global release pool to the
      allocation pool of a specific thread), but this is a bug and will be
      fixed in a separate patch.
      
      In fact, the comment in the header file already just promises that it
      influences the pool size, so reflect this in the name of the functions.
      As a nice side effect, the shorter function name makes some line
      wrapping unnecessary.
      
      Cc: qemu-stable@nongnu.org
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      Message-Id: <20220510151020.105528-2-kwolf@redhat.com>
      Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
      98e3ab35
  2. May 11, 2022
    • Richard Henderson's avatar
      Merge tag 'pull-misc-2022-05-11' of git://repo.or.cz/qemu/armbru into staging · ec11dc41
      Richard Henderson authored
      Miscellaneous patches patches for 2022-05-11
      
      # -----BEGIN PGP SIGNATURE-----
      #
      # iQJGBAABCAAwFiEENUvIs9frKmtoZ05fOHC0AOuRhlMFAmJ7zwISHGFybWJydUBy
      # ZWRoYXQuY29tAAoJEDhwtADrkYZThuAQAJdSuj5fpY8EXxhuS3Rc8uHPrz6lP+nZ
      # kwxKPOldwFdmkXRJ8qrjcc/BXxiJU3pxmSRvFZ8miCFMrb4Vd16sUzD6PeKb1jr8
      # JsrvXcsaWn4f/p0v0WraamwSQeZUMjqsZPgZut93qfJoKmgTaxoZnR+ZDHFKoQJS
      # qBrHL/5+RPxSugLa6IEpSQwy80jd0tMBaG/e8V+JxzgFM5jzOExwXtfUujzS92Lr
      # NgapnbEZrpqErBC1xhpetQ8Q5I4r0kkLj4Exm/ClNtIM2GByJxI8x2DE+NJZNDnm
      # g/tvVKUhEl6cOywQRajAJ/LrhUpVSkz6wsczv35rhRS+1FoCb+PRKr42SxZGI2rB
      # tZLYt4ouoSGk2pYiudoIBKsIR1Svu7Cmg4YzOL9yvqF0BS3cRDvPgm3QFvoeErjL
      # EML7b41zLdIkbvujsJ7HJqVL44QmMSu13PcLUtDvLh+ivpL9wIUQn3ji+rfsgqh+
      # RYw4niJ9JO3N3/VwEhlymc9kRSTgZ6rdIWPrtQ5ACwTADAv30++opxAlksE6mo0m
      # TYrqyTG2FHGOKm+5Q4Lyx1heHJDUAE3dlRIhGt8KqD6UKlpSfIVIUU2ztjZK4JQ5
      # n85LOLZkE9ejbvbpnLX8hgKfouVKKYwFagc/ZA649cIXvC8YDxdOwvhjEVCxa+V5
      # dQbpQsekXf9G
      # =jOTx
      # -----END PGP SIGNATURE-----
      # gpg: Signature made Wed 11 May 2022 07:58:10 AM PDT
      # gpg:                using RSA key 354BC8B3D7EB2A6B68674E5F3870B400EB918653
      # gpg:                issuer "armbru@redhat.com"
      # gpg: Good signature from "Markus Armbruster <armbru@redhat.com>" [undefined]
      # gpg:                 aka "Markus Armbruster <armbru@pond.sub.org>" [undefined]
      # gpg: WARNING: This key is not certified with a trusted signature!
      # gpg:          There is no indication that the signature belongs to the owner.
      # Primary key fingerprint: 354B C8B3 D7EB 2A6B 6867  4E5F 3870 B400 EB91 8653
      
      * tag 'pull-misc-2022-05-11' of git://repo.or.cz/qemu/armbru
      
      :
        Clean up decorations and whitespace around header guards
        Normalize header guard symbol definition
        Clean up ill-advised or unusual header guards
        Clean up header guards that don't match their file name
      
      Signed-off-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      ec11dc41
    • Markus Armbruster's avatar
      Clean up decorations and whitespace around header guards · ea9cea93
      Markus Armbruster authored
      
      Cleaned up with scripts/clean-header-guards.pl.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20220506134911.2856099-5-armbru@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      ea9cea93
    • Markus Armbruster's avatar
      Normalize header guard symbol definition · 4f31b54b
      Markus Armbruster authored
      
      We commonly define the header guard symbol without an explicit value.
      Normalize the exceptions.
      
      Done with scripts/clean-header-guards.pl.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20220506134911.2856099-4-armbru@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      4f31b54b
    • Markus Armbruster's avatar
      Clean up ill-advised or unusual header guards · 9c092804
      Markus Armbruster authored
      
      Leading underscores are ill-advised because such identifiers are
      reserved.  Trailing underscores are merely ugly.  Strip both.
      
      Our header guards commonly end in _H.  Normalize the exceptions.
      
      Macros should be ALL_CAPS.  Normalize the exception.
      
      Done with scripts/clean-header-guards.pl.
      
      include/hw/xen/interface/ and tools/virtiofsd/ left alone, because
      these were imported from Xen and libfuse respectively.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20220506134911.2856099-3-armbru@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      9c092804
    • Markus Armbruster's avatar
      Clean up header guards that don't match their file name · 52581c71
      Markus Armbruster authored
      
      Header guard symbols should match their file name to make guard
      collisions less likely.
      
      Cleaned up with scripts/clean-header-guards.pl, followed by some
      renaming of new guard symbols picked by the script to better ones.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20220506134911.2856099-2-armbru@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      [Change to generated file ebpf/rss.bpf.skeleton.h backed out]
      52581c71
  3. May 09, 2022
Loading