Skip to content
Snippets Groups Projects
  1. Feb 19, 2020
    • Igor Mammedov's avatar
      hostmem: fix strict bind policy · 4ebc74db
      Igor Mammedov authored
      
      When option -mem-prealloc is used with one or more memory-backend
      objects, created backends may not obey configured bind policy or
      creation may fail after kernel attempts to move pages according
      to bind policy.
      Reason is in file_ram_alloc(), which will pre-allocate
      any descriptor based RAM if global mem_prealloc != 0 and that
      happens way before bind policy is applied to memory range.
      
      One way to fix it would be to extend memory_region_foo() API
      and add more invariants that could broken later due implicit
      dependencies that's hard to track.
      
      Another approach is to drop adhoc main RAM allocation and
      consolidate it around memory-backend. That allows to have
      single place that allocates guest RAM (main and memdev)
      in the same way and then global mem_prealloc could be
      replaced by backend's property[s] that will affect created
      memory-backend objects but only in correct order this time.
      
      With main RAM now converted to hostmem backends, there is no
      point in keeping global mem_prealloc around, so alias
       -mem-prealloc to "memory-backend.prealloc=on"
      machine compat[*] property and make mem_prealloc a local
      variable to only stir registration of compat property.
      
      *) currently user accessible -global works only with DEVICE
         based objects and extra work is needed to make it work
         with hostmem backends. But that is convenience option
         and out of scope of this already huge refactoring.
         Hence machine compat properties were used.
      
      Signed-off-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Message-Id: <20200219160953.13771-78-imammedo@redhat.com>
      4ebc74db
    • Igor Mammedov's avatar
      hostmem: introduce "prealloc-threads" property · ffac16fa
      Igor Mammedov authored
      
      the property will allow user to specify number of threads to use
      in pre-allocation stage. It also will allow to reduce implicit
      hostmem dependency on current_machine.
      On object creation it will default to 1, but via machine
      compat property it will be updated to MachineState::smp::cpus
      to keep current behavior for hostmem and main RAM (which is
      now also hostmem based).
      
      Signed-off-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Message-Id: <20200219160953.13771-77-imammedo@redhat.com>
      ffac16fa
    • Igor Mammedov's avatar
      machine: alias -mem-path and -mem-prealloc into memory-foo backend · 900c0ba3
      Igor Mammedov authored
      
      Allow machine to opt in for hostmem backend based initial RAM
      even if user uses old -mem-path/prealloc options by providing
        MachineClass::default_ram_id
      Follow up patches will incrementally convert machines to new API,
      by dropping memory_region_allocate_system_memory() and setting
      default_ram_id that board used to use before conversion to keep
      migration stream the same.
      
      Signed-off-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Message-Id: <20200219160953.13771-4-imammedo@redhat.com>
      900c0ba3
  2. Jan 20, 2020
  3. Jan 08, 2020
  4. Jan 07, 2020
    • Philippe Mathieu-Daudé's avatar
      vhost-user-crypto: Explicit we ignore some QEMUChrEvent in IOEventHandler · 5b082922
      Philippe Mathieu-Daudé authored
      
      The Chardev events are listed in the QEMUChrEvent enum. To be
      able to use this enum in the IOEventHandler typedef, we need to
      explicit all the events ignored by this frontend, to silent the
      following GCC warning:
      
          CC      backends/cryptodev-vhost-user.o
        backends/cryptodev-vhost-user.c: In function ‘cryptodev_vhost_user_event’:
        backends/cryptodev-vhost-user.c:163:5: error: enumeration value ‘CHR_EVENT_BREAK’ not handled in switch [-Werror=switch]
          163 |     switch (event) {
              |     ^~~~~~
        backends/cryptodev-vhost-user.c:163:5: error: enumeration value ‘CHR_EVENT_MUX_IN’ not handled in switch [-Werror=switch]
        backends/cryptodev-vhost-user.c:163:5: error: enumeration value ‘CHR_EVENT_MUX_OUT’ not handled in switch [-Werror=switch]
        cc1: all warnings being treated as errors
      
      Signed-off-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <20191218172009.8868-8-philmd@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      5b082922
  5. Jan 06, 2020
  6. Dec 18, 2019
  7. Oct 26, 2019
    • Wei Yang's avatar
      core: replace getpagesize() with qemu_real_host_page_size · 038adc2f
      Wei Yang authored
      
      There are three page size in qemu:
      
        real host page size
        host page size
        target page size
      
      All of them have dedicate variable to represent. For the last two, we
      use the same form in the whole qemu project, while for the first one we
      use two forms: qemu_real_host_page_size and getpagesize().
      
      qemu_real_host_page_size is defined to be a replacement of
      getpagesize(), so let it serve the role.
      
      [Note] Not fully tested for some arch or device.
      
      Signed-off-by: default avatarWei Yang <richardw.yang@linux.intel.com>
      Message-Id: <20191013021145.16011-3-richardw.yang@linux.intel.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      038adc2f
  8. Sep 16, 2019
    • Stefan Hajnoczi's avatar
      memory: fetch pmem size in get_file_size() · 72d41eb4
      Stefan Hajnoczi authored
      
      Neither stat(2) nor lseek(2) report the size of Linux devdax pmem
      character device nodes.  Commit 314aec4a
      ("hostmem-file: reject invalid pmem file sizes") added code to
      hostmem-file.c to fetch the size from sysfs and compare against the
      user-provided size=NUM parameter:
      
        if (backend->size > size) {
            error_setg(errp, "size property %" PRIu64 " is larger than "
                       "pmem file \"%s\" size %" PRIu64, backend->size,
                       fb->mem_path, size);
            return;
        }
      
      It turns out that exec.c:qemu_ram_alloc_from_fd() already has an
      equivalent size check but it skips devdax pmem character devices because
      lseek(2) returns 0:
      
        if (file_size > 0 && file_size < size) {
            error_setg(errp, "backing store %s size 0x%" PRIx64
                       " does not match 'size' option 0x" RAM_ADDR_FMT,
                       mem_path, file_size, size);
            return NULL;
        }
      
      This patch moves the devdax pmem file size code into get_file_size() so
      that we check the memory size in a single place:
      qemu_ram_alloc_from_fd().  This simplifies the code and makes it more
      general.
      
      This also fixes the problem that hostmem-file only checks the devdax
      pmem file size when the pmem=on parameter is given.  An unchecked
      size=NUM parameter can lead to SIGBUS in QEMU so we must always fetch
      the file size for Linux devdax pmem character device nodes.
      
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-Id: <20190830093056.12572-1-stefanha@redhat.com>
      Reviewed-by: default avatarEduardo Habkost <ehabkost@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      72d41eb4
    • Raphael Norwitz's avatar
      backends/vhost-user.c: prevent using uninitialized vqs · b8487a35
      Raphael Norwitz authored
      
      Similar rational to: e6cc11d6
      
      For vhost scsi and vhost-user-scsi an issue was observed
      where, of the 3 virtqueues, seabios would only set cmd,
      leaving ctrl and event without a physical address.
      This can caused vhost_verify_ring_part_mapping to return
      ENOMEM, causing the following logs:
      
      qemu-system-x86_64: Unable to map available ring for ring 0
      qemu-system-x86_64: Verify ring failure on region 0
      
      The issue has already been fixed elsewhere, but it was noted
      that in backends/vhost-user.c, the vhost_user_backend_dev_init()
      function, which other vdevs use in their realize() to initialize
      their vqs, was not being properly zeroing out the queues. This
      commit ensures hardware modules using the
      vhost_user_backend_dev_init() API properly zero out their vqs on
      initialization.
      
      Suggested-by: default avatarPhilippe Mathieu-Daude <philmd@redhat.com>
      Signed-off-by: default avatarRaphael Norwitz <raphael.norwitz@nutanix.com>
      Message-Id: <1566498865-55506-2-git-send-email-raphael.norwitz@nutanix.com>
      Reviewed-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      b8487a35
  9. Sep 04, 2019
  10. Sep 03, 2019
    • Stefan Hajnoczi's avatar
      hostmem-file: fix pmem file size check · 7faae95e
      Stefan Hajnoczi authored
      
      Commit 314aec4a ("hostmem-file: reject
      invalid pmem file sizes") added a file size check that verifies the
      hostmem object's size parameter against the actual devdax pmem file.
      This is useful because getting the size wrong results in confusing
      errors inside the guest.
      
      However, the code doesn't work properly for files where struct
      stat::st_size is zero.  Hostmem-file's ->alloc() function returns early
      without setting an Error, causing the following assertion failure:
      
        qemu/memory.c:2215: memory_region_get_ram_ptr: Assertion `mr->ram_block' failed.
      
      This patch handles the case where qemu_get_pmem_size() returns 0 but
      there is no error.
      
      Fixes: 314aec4a
      Signed-off-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-Id: <20190823135632.25010-1-stefanha@redhat.com>
      Signed-off-by: default avatarEduardo Habkost <ehabkost@redhat.com>
      7faae95e
  11. Aug 16, 2019
    • Markus Armbruster's avatar
      Include sysemu/sysemu.h a lot less · 46517dd4
      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).
      
      hw/qdev-core.h includes sysemu/sysemu.h since recent commit e965ffa7
      "qdev: add qdev_add_vm_change_state_handler()".  This is a bad idea:
      hw/qdev-core.h is widely included.
      
      Move the declaration of qdev_add_vm_change_state_handler() to
      sysemu/sysemu.h, and drop the problematic include from hw/qdev-core.h.
      
      Touching sysemu/sysemu.h now recompiles some 1800 objects.
      qemu/uuid.h also drops from 5400 to 1800.  A few more headers show
      smaller improvement: qemu/notify.h drops from 5600 to 5200,
      qemu/timer.h from 5600 to 4500, and qapi/qapi-types-run-state.h from
      5500 to 5000.
      
      Cc: Stefan Hajnoczi <stefanha@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Message-Id: <20190812052359.30071-28-armbru@redhat.com>
      Reviewed-by: default avatarAlex Bennée <alex.bennee@linaro.org>
      46517dd4
    • Markus Armbruster's avatar
      Include hw/boards.h a bit less · 12e9493d
      Markus Armbruster authored
      
      hw/boards.h pulls in almost 60 headers.  The less we include it into
      headers, the better.  As a first step, drop superfluous inclusions,
      and downgrade some more to what's actually needed.  Gets rid of just
      one inclusion into a header.
      
      Cc: Eduardo Habkost <ehabkost@redhat.com>
      Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarAlistair Francis <alistair.francis@wdc.com>
      Message-Id: <20190812052359.30071-23-armbru@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Tested-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: default avatarEduardo Habkost <ehabkost@redhat.com>
      12e9493d
    • Markus Armbruster's avatar
      Include hw/qdev-properties.h less · a27bd6c7
      Markus Armbruster authored
      
      In my "build everything" tree, changing hw/qdev-properties.h triggers
      a recompile of some 2700 out of 6600 objects (not counting tests and
      objects that don't depend on qemu/osdep.h).
      
      Many places including hw/qdev-properties.h (directly or via hw/qdev.h)
      actually need only hw/qdev-core.h.  Include hw/qdev-core.h there
      instead.
      
      hw/qdev.h is actually pointless: all it does is include hw/qdev-core.h
      and hw/qdev-properties.h, which in turn includes hw/qdev-core.h.
      Replace the remaining uses of hw/qdev.h by hw/qdev-properties.h.
      
      While there, delete a few superfluous inclusions of hw/qdev-core.h.
      
      Touching hw/qdev-properties.h now recompiles some 1200 objects.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Cc: "Daniel P. Berrangé" <berrange@redhat.com>
      Cc: Eduardo Habkost <ehabkost@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarEduardo Habkost <ehabkost@redhat.com>
      Message-Id: <20190812052359.30071-22-armbru@redhat.com>
      a27bd6c7
  12. Jul 05, 2019
  13. Jul 03, 2019
    • Kashyap Chamarthy's avatar
      VirtIO-RNG: Update default entropy source to `/dev/urandom` · a2230bd7
      Kashyap Chamarthy authored
      When QEMU exposes a VirtIO-RNG device to the guest, that device needs a
      source of entropy, and that source needs to be "non-blocking", like
      `/dev/urandom`.  However, currently QEMU defaults to the problematic
      `/dev/random`, which on Linux is "blocking" (as in, it waits until
      sufficient entropy is available).
      
      Why prefer `/dev/urandom` over `/dev/random`?
      ---------------------------------------------
      
      The man pages of urandom(4) and random(4) state:
      
          "The /dev/random device is a legacy interface which dates back to a
          time where the cryptographic primitives used in the implementation
          of /dev/urandom were not widely trusted.  It will return random
          bytes only within the estimated number of bits of fresh noise in the
          entropy pool, blocking if necessary.  /dev/random is suitable for
          applications that need high quality randomness, and can afford
          indeterminate delays."
      
      Further, the "Usage" section of the said man pages state:
      
          "The /dev/random interface is considered a legacy interface, and
          /dev/urandom is preferred and sufficient in all use cases, with the
          exception of applications which require randomness during early boot
          time; for these applications, getrandom(2) must be used instead,
          because it will block until the entropy pool is initialized.
      
          "If a seed file is saved across reboots as recommended below (all
          major Linux distributions have done this since 2000 at least), the
          output is cryptographically secure against attackers without local
          root access as soon as it is reloaded in the boot sequence, and
          perfectly adequate for network encryption session keys.  Since reads
          from /dev/random may block, users will usually want to open it in
          nonblocking mode (or perform a read with timeout), and provide some
          sort of user notification if the desired entropy is not immediately
          available."
      
      And refer to random(7) for a comparison of `/dev/random` and
      `/dev/urandom`.
      
      What about other OSes?
      ----------------------
      
      `/dev/urandom` exists and works on OS-X, FreeBSD, DragonFlyBSD, NetBSD
      and OpenBSD, which cover all the non-Linux platforms we explicitly
      support, aside from Windows.
      
      On Windows `/dev/random` doesn't work either so we don't regress.
      This is actually another argument in favour of using the newly
      proposed 'rng-builtin' backend by default, as that will work on
      Windows.
      
          - - -
      
      Given the above, change the entropy source for VirtIO-RNG device to
      `/dev/urandom`.
      
      Related discussion in these[1][2] past threads.
      
      [1] https://lists.nongnu.org/archive/html/qemu-devel/2018-06/msg08335.html
          -- "RNG: Any reason QEMU doesn't default to `/dev/urandom`?"
      [2] https://lists.nongnu.org/archive/html/qemu-devel/2018-09/msg02724.html
      
      
          -- "[RFC] Virtio RNG: Consider changing the default entropy source to
             /dev/urandom"
      
      Signed-off-by: default avatarKashyap Chamarthy <kchamart@redhat.com>
      Reviewed-by: default avatarDaniel P. Berrangé <berrange@redhat.com>
      Reviewed-by: default avatarStefan Hajnoczi <stefanha@redhat.com>
      Reviewed-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Signed-off-by: default avatarLaurent Vivier <lvivier@redhat.com>
      Message-Id: <20190529143106.11789-2-lvivier@redhat.com>
      Signed-off-by: default avatarLaurent Vivier <laurent@vivier.eu>
      a2230bd7
  14. Jun 12, 2019
  15. May 10, 2019
    • Marc-André Lureau's avatar
      Add vhost-user-backend · f24bb728
      Marc-André Lureau authored
      
      Create a vhost-user-backend object that holds a connection to a
      vhost-user backend (or "slave" process) and can be referenced from
      virtio devices that support it. See later patches for input & gpu
      usage.
      
      Note: a previous iteration of this object made it user-creatable, and
      allowed managed sub-process spawning, but that has been dropped for
      now.
      
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-id: 20190503130034.24916-4-marcandre.lureau@redhat.com
      Signed-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
      f24bb728
  16. Mar 13, 2019
  17. Mar 11, 2019
  18. Mar 06, 2019
  19. Feb 21, 2019
  20. Jan 28, 2019
  21. Jan 07, 2019
    • Marc-André Lureau's avatar
      hostmem: use object id for memory region name with >= 4.0 · fa0cb34d
      Marc-André Lureau authored
      
      hostmem-file and hostmem-memfd use the whole object path for the
      memory region name, and hostname-ram uses only the path component (the
      object id, or canonical path basename):
      
      qemu -m 1024 -object memory-backend-file,id=mem,size=1G,mem-path=/tmp/foo -numa node,memdev=mem -monitor stdio
      (qemu) info ramblock
                    Block Name    PSize              Offset               Used              Total
                  /objects/mem    4 KiB  0x0000000000000000 0x0000000040000000 0x0000000040000000
      
      qemu -m 1024 -object memory-backend-memfd,id=mem,size=1G -numa node,memdev=mem -monitor stdio
      (qemu) info ramblock
                    Block Name    PSize              Offset               Used              Total
                  /objects/mem    4 KiB  0x0000000000000000 0x0000000040000000 0x0000000040000000
      
      qemu -m 1024 -object memory-backend-ram,id=mem,size=1G -numa node,memdev=mem -monitor stdio
      (qemu) info ramblock
                    Block Name    PSize              Offset               Used              Total
                           mem    4 KiB  0x0000000000000000 0x0000000040000000 0x0000000040000000
      
      For consistency, change to use object id for -file and -memfd as well
      with >= 4.0.
      
      Having a consistent naming allows to migrate to different hostmem
      backends.
      
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Reviewed-by: default avatarIgor Mammedov <imammedo@redhat.com>
      Acked-by: default avatarEduardo Habkost <ehabkost@redhat.com>
      fa0cb34d
  22. Dec 11, 2018
  23. Nov 28, 2018
  24. Nov 27, 2018
  25. Oct 24, 2018
  26. Oct 05, 2018
  27. Oct 02, 2018
  28. Aug 10, 2018
  29. Jul 30, 2018
Loading