Skip to content
Snippets Groups Projects
  1. Aug 16, 2019
    • Markus Armbruster's avatar
      memory: Fix type of IOMMUMemoryRegionClass member @parent_class · 1b53ecd9
      Markus Armbruster authored
      
      TYPE_IOMMU_MEMORY_REGION is a direct subtype of TYPE_MEMORY_REGION.
      Its instance struct is IOMMUMemoryRegion, and its first member is a
      MemoryRegion.  Correct.  Its class struct is IOMMUMemoryRegionClass,
      and its first member is a DeviceClass.  Wrong.  Messed up when commit
      1221a474 introduced the QOM type.  It even included hw/qdev-core.h
      just for that.
      
      TYPE_MEMORY_REGION doesn't bother to define a class struct.  This is
      fine, it simply defaults to its super-type TYPE_OBJECT's class struct
      ObjectClass.  Changing IOMMUMemoryRegionClass's first member's type to
      ObjectClass would be a minimal fix, if a bit brittle: if
      TYPE_MEMORY_REGION ever acquired own class struct, we'd have to update
      IOMMUMemoryRegionClass to use it.
      
      Fix it the clean and robust way instead: give TYPE_MEMORY_REGION its
      own class struct MemoryRegionClass now, and use it for
      IOMMUMemoryRegionClass's first member.
      
      Revert the include of hw/qdev-core.h, and fix the few files that have
      come to rely on it.
      
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Tested-by: default avatarPhilippe Mathieu-Daudé <philmd@redhat.com>
      Acked-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Message-Id: <20190812052359.30071-5-armbru@redhat.com>
      1b53ecd9
  2. Jul 19, 2019
    • Alexey Kardashevskiy's avatar
      hmp: Print if memory section is registered with an accelerator · 8072aae3
      Alexey Kardashevskiy authored
      
      This adds an accelerator name to the "into mtree -f" to tell the user if
      a particular memory section is registered with the accelerator;
      the primary user for this is KVM and such information is useful
      for debugging purposes.
      
      This adds a has_memory() callback to the accelerator class allowing any
      accelerator to have a label in that memory tree dump.
      
      Since memory sections are passed to memory listeners and get registered
      in accelerators (rather than memory regions), this only prints new labels
      for flatviews attached to the system address space.
      
      An example:
       Root memory region: system
        0000000000000000-0000002fffffffff (prio 0, ram): /objects/mem0 kvm
        0000003000000000-0000005fffffffff (prio 0, ram): /objects/mem1 kvm
        0000200000000020-000020000000003f (prio 1, i/o): virtio-pci
        0000200080000000-000020008000003f (prio 0, i/o): capabilities
      
      Signed-off-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
      Message-Id: <20190614015237.82463-1-aik@ozlabs.ru>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      8072aae3
  3. Jul 15, 2019
    • Peter Xu's avatar
      memory: Introduce memory listener hook log_clear() · 077874e0
      Peter Xu authored
      
      Introduce a new memory region listener hook log_clear() to allow the
      listeners to hook onto the points where the dirty bitmap is cleared by
      the bitmap users.
      
      Previously log_sync() contains two operations:
      
        - dirty bitmap collection, and,
        - dirty bitmap clear on remote site.
      
      Let's take KVM as example - log_sync() for KVM will first copy the
      kernel dirty bitmap to userspace, and at the same time we'll clear the
      dirty bitmap there along with re-protecting all the guest pages again.
      
      We add this new log_clear() interface only to split the old log_sync()
      into two separated procedures:
      
        - use log_sync() to collect the collection only, and,
        - use log_clear() to clear the remote dirty bitmap.
      
      With the new interface, the memory listener users will still be able
      to decide how to implement the log synchronization procedure, e.g.,
      they can still only provide log_sync() method only and put all the two
      procedures within log_sync() (that's how the old KVM works before
      KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2 is introduced).  However with this
      new interface the memory listener users will start to have a chance to
      postpone the log clear operation explicitly if the module supports.
      That can really benefit users like KVM at least for host kernels that
      support KVM_CAP_MANUAL_DIRTY_LOG_PROTECT2.
      
      There are three places that can clear dirty bits in any one of the
      dirty bitmap in the ram_list.dirty_memory[3] array:
      
              cpu_physical_memory_snapshot_and_clear_dirty
              cpu_physical_memory_test_and_clear_dirty
              cpu_physical_memory_sync_dirty_bitmap
      
      Currently we hook directly into each of the functions to notify about
      the log_clear().
      
      Reviewed-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
      Reviewed-by: default avatarJuan Quintela <quintela@redhat.com>
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Message-Id: <20190603065056.25211-7-peterx@redhat.com>
      Signed-off-by: default avatarJuan Quintela <quintela@redhat.com>
      077874e0
    • Peter Xu's avatar
      memory: Pass mr into snapshot_and_clear_dirty · 5dea4079
      Peter Xu authored
      
      Also we change the 2nd parameter of it to be the relative offset
      within the memory region. This is to be used in follow up patches.
      
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reviewed-by: default avatarJuan Quintela <quintela@redhat.com>
      Message-Id: <20190603065056.25211-6-peterx@redhat.com>
      Signed-off-by: default avatarJuan Quintela <quintela@redhat.com>
      5dea4079
    • Peter Xu's avatar
      memory: Don't set migration bitmap when without migration · ae7a2bca
      Peter Xu authored
      
      Similar to 9460dee4 ("memory: do not touch code dirty bitmap unless
      TCG is enabled", 2015-06-05) but for the migration bitmap - we can
      skip the MIGRATION bitmap update if migration not enabled.
      
      Reviewed-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      Reviewed-by: default avatarJuan Quintela <quintela@redhat.com>
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Message-Id: <20190603065056.25211-4-peterx@redhat.com>
      Signed-off-by: default avatarJuan Quintela <quintela@redhat.com>
      ae7a2bca
    • King Wang's avatar
      memory: unref the memory region in simplify flatview · 838ec117
      King Wang authored
      
      The memory region reference is increased when insert a range
      into flatview range array, then decreased by destroy flatview.
      If some flat range merged by flatview_simplify, the memory region
      reference can not be decreased by destroy flatview any more.
      
      In this case, start virtual machine by the command line:
      qemu-system-x86_64
      -name guest=ubuntu,debug-threads=on
      -machine pc,accel=kvm,usb=off,dump-guest-core=off
      -cpu host
      -m 16384
      -realtime mlock=off
      -smp 8,sockets=2,cores=4,threads=1
      -object memory-backend-file,id=ram-node0,prealloc=yes,mem-path=/dev/hugepages,share=yes,size=8589934592
      -numa node,nodeid=0,cpus=0-3,memdev=ram-node0
      -object memory-backend-file,id=ram-node1,prealloc=yes,mem-path=/dev/hugepages,share=yes,size=8589934592
      -numa node,nodeid=1,cpus=4-7,memdev=ram-node1
      -no-user-config
      -nodefaults
      -rtc base=utc
      -no-shutdown
      -boot strict=on
      -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2
      -device virtio-scsi-pci,id=scsi0,bus=pci.0,addr=0x2
      -device virtio-serial-pci,id=virtio-serial0,bus=pci.0,addr=0x3
      -drive file=ubuntu.qcow2,format=qcow2,if=none,id=drive-virtio-disk0,cache=none,aio=native
      -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=drive-virtio-disk0,id=virtio-disk0,bootindex=1
      -chardev pty,id=charserial0
      -device isa-serial,chardev=charserial0,id=serial0
      -device usb-tablet,id=input0,bus=usb.0,port=1
      -vnc 0.0.0.0:0
      -device VGA,id=video0,vgamem_mb=16,bus=pci.0,addr=0x5
      -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x6
      -msg timestamp=on
      
      And run the script in guest OS:
      while true
      do
          setpci -s 00:06.0 04.b=03
      	setpci -s 00:06.0 04.b=07
      done
      
      I found the reference of node0 HostMemoryBackendFile is a big one.
      (gdb) p numa_info[0]->node_memdev->parent.ref
      $6 = 1636278
      (gdb)
      
      Signed-off-by: default avatarKing <Wang&lt;king.wang@huawei.com>
      Message-Id: <20190712065241.11784-1-king.wang@huawei.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      838ec117
  4. Jul 01, 2019
    • Greg Kurz's avatar
      spapr_pci: Unregister listeners before destroying the IOMMU address space · a2166410
      Greg Kurz authored
      
      Hot-unplugging a PHB with a VFIO device connected to it crashes QEMU:
      
      -device spapr-pci-host-bridge,index=1,id=phb1 \
      -device vfio-pci,host=0034:01:00.3,id=vfio0
      
      (qemu) device_del phb1
      [  357.207183] iommu: Removing device 0001:00:00.0 from group 1
      [  360.375523] rpadlpar_io: slot PHB 1 removed
      qemu-system-ppc64: memory.c:2742:
       do_address_space_destroy: Assertion `QTAILQ_EMPTY(&as->listeners)' failed.
      
      'as' is the IOMMU address space, which indeed has a listener registered
      to by vfio_connect_container() when the VFIO device is realized. This
      listener is supposed to be unregistered by vfio_disconnect_container()
      when the VFIO device is finalized. Unfortunately, the VFIO device hasn't
      reached finalize yet at the time the PHB unrealize function is called,
      and address_space_destroy() gets called with the VFIO listener still
      being registered.
      
      All regions have just been unmapped from the address space. Listeners
      aren't needed anymore at this point. Remove them before destroying the
      address space.
      
      The VFIO code will try to remove them _again_ at device finalize,
      but it is okay since memory_listener_unregister() is idempotent.
      
      Signed-off-by: default avatarGreg Kurz <groug@kaod.org>
      Message-Id: <156110925375.92514.11649846071216864570.stgit@bahia.lan>
      Reviewed-by: default avatarAlexey Kardashevskiy <aik@ozlabs.ru>
      [dwg: Correct spelling error pointed out by aik]
      Signed-off-by: default avatarDavid Gibson <david@gibson.dropbear.id.au>
      a2166410
  5. Jun 11, 2019
    • Markus Armbruster's avatar
      qemu-common: Move tcg_enabled() etc. to sysemu/tcg.h · 14a48c1d
      Markus Armbruster authored
      
      Other accelerators have their own headers: sysemu/hax.h, sysemu/hvf.h,
      sysemu/kvm.h, sysemu/whpx.h.  Only tcg_enabled() & friends sit in
      qemu-common.h.  This necessitates inclusion of qemu-common.h into
      headers, which is against the rules spelled out in qemu-common.h's
      file comment.
      
      Move tcg_enabled() & friends into their own header sysemu/tcg.h, and
      adjust #include directives.
      
      Cc: Richard Henderson <rth@twiddle.net>
      Cc: Paolo Bonzini <pbonzini@redhat.com>
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Message-Id: <20190523143508.25387-2-armbru@redhat.com>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      [Rebased with conflicts resolved automatically, except for
      accel/tcg/tcg-all.c]
      14a48c1d
  6. Jun 03, 2019
  7. May 17, 2019
  8. Apr 18, 2019
    • Markus Armbruster's avatar
      memory: Clean up how mtree_info() prints · b6b71cb5
      Markus Armbruster authored
      
      mtree_info() takes an fprintf()-like callback and a FILE * to pass to
      it, and so do its helper functions.  Passing around callback and
      argument is rather tiresome.
      
      Its only caller hmp_info_mtree() passes monitor_printf() cast to
      fprintf_function and the current monitor cast to FILE *.
      
      The type-punning is technically undefined behaviour, but works in
      practice.  Clean up: drop the callback, and call qemu_printf()
      instead.
      
      Signed-off-by: default avatarMarkus Armbruster <armbru@redhat.com>
      Reviewed-by: default avatarDr. David Alan Gilbert <dgilbert@redhat.com>
      Message-Id: <20190417191805.28198-9-armbru@redhat.com>
      b6b71cb5
  9. Mar 18, 2019
  10. Mar 11, 2019
  11. Jan 11, 2019
  12. Nov 06, 2018
    • Marc-André Lureau's avatar
      memory: learn about non-volatile memory region · c26763f8
      Marc-André Lureau authored
      
      Add a new flag to mark memory region that are used as non-volatile, by
      NVDIMM for example. That bit is propagated down to the flat view, and
      reflected in HMP info mtree with a "nv-" prefix on the memory type.
      
      This way, guest_phys_blocks_region_add() can skip the NV memory
      regions for dumps and TCG memory clear in a following patch.
      
      Cc: dgilbert@redhat.com
      Cc: imammedo@redhat.com
      Cc: pbonzini@redhat.com
      Cc: guangrong.xiao@linux.intel.com
      Cc: mst@redhat.com
      Cc: xiaoguangrong.eric@gmail.com
      Signed-off-by: default avatarMarc-André Lureau <marcandre.lureau@redhat.com>
      Message-Id: <20181003114454.5662-2-marcandre.lureau@redhat.com>
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      c26763f8
  13. Oct 19, 2018
  14. Oct 02, 2018
  15. Aug 20, 2018
  16. Aug 14, 2018
    • Peter Maydell's avatar
      accel/tcg: Pass read access type through to io_readx() · dbea78a4
      Peter Maydell authored
      
      The io_readx() function needs to know whether the load it is
      doing is an MMU_DATA_LOAD or an MMU_INST_FETCH, so that it
      can pass the right value to the cpu_transaction_failed()
      function. Plumb this information through from the softmmu
      code.
      
      This is currently not often going to give the wrong answer,
      because usually instruction fetches go via get_page_addr_code().
      However once we switch over to handling execution from non-RAM by
      creating single-insn TBs, the path for an insn fetch to generate
      a bus error will be through cpu_ld*_code() and io_readx(),
      so without this change we will generate a d-side fault when we
      should generate an i-side fault.
      
      We also have to pass the access type via a CPU struct global
      down to unassigned_mem_read(), for the benefit of the targets
      which still use the cpu_unassigned_access() hook (m68k, mips,
      sparc, xtensa).
      
      Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
      Reviewed-by: default avatarRichard Henderson <richard.henderson@linaro.org>
      Reviewed-by: default avatarPhilippe Mathieu-Daudé <f4bug@amsat.org>
      Tested-by: default avatarCédric Le Goater <clg@kaod.org>
      Message-id: 20180710160013.26559-2-peter.maydell@linaro.org
      dbea78a4
  17. Aug 10, 2018
  18. Jun 28, 2018
  19. Jun 15, 2018
  20. Jun 01, 2018
  21. May 31, 2018
  22. May 08, 2018
    • Paolo Bonzini's avatar
      exec: reintroduce MemoryRegion caching · 48564041
      Paolo Bonzini authored
      
      MemoryRegionCache was reverted to "normal" address_space_* operations
      for 2.9, due to lack of support for IOMMUs.  Reinstate the
      optimizations, caching only the IOMMU translation at address_cache_init
      but not the IOMMU lookup and target AddressSpace translation are not
      cached; now that MemoryRegionCache supports IOMMUs, it becomes more widely
      applicable too.
      
      The inlined fast path is defined in memory_ldst_cached.inc.h, while the
      slow path uses memory_ldst.inc.c as before.  The smaller fast path causes
      a little code size reduction in MemoryRegionCache users:
      
          hw/virtio/virtio.o text size before: 32373
          hw/virtio/virtio.o text size after: 31941
      
      Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
      48564041
  23. Mar 06, 2018
Loading