1. 01 7月, 2019 3 次提交
    • M
      pcie: work around for racy guest init · 110c477c
      Michael S. Tsirkin 提交于
      During boot, linux guests tend to clear all bits in pcie slot status
      register which is used for hotplug.
      If they clear bits that weren't set this is racy and will lose events:
      not a big problem for manual hotplug on bare-metal, but a problem for us.
      
      For example, the following is broken ATM:
      
      /x86_64-softmmu/qemu-system-x86_64 -enable-kvm -S -machine q35  \
          -device pcie-root-port,id=pcie_root_port_0,slot=2,chassis=2,addr=0x2,bus=pcie.0 \
          -device virtio-balloon-pci,id=balloon,bus=pcie_root_port_0 \
          -monitor stdio disk.qcow2
      (qemu)device_del balloon
      (qemu)cont
      
      Balloon isn't deleted as it should.
      
      As a work-around, detect this attempt to clear slot status and revert
      status to what it was before the write.
      
      Note: in theory this can be detected as a duplicate button press
      which cancels the previous press. Does not seem to happen in
      practice as guests seem to only have this bug during init.
      
      Note2: the right thing to do is probably to fix Linux to
      read status before clearing it, and act on the bits that are set.
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: NMarcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Reviewed-by: NIgor Mammedov <imammedo@redhat.com>
      Tested-by: NIgor Mammedov <imammedo@redhat.com>
      110c477c
    • M
      pcie: check that slt ctrl changed before deleting · 2841ab43
      Michael S. Tsirkin 提交于
      During boot, linux would sometimes overwrites control of a powered off
      slot before powering it on. Unfortunately QEMU interprets that as a
      power off request and ejects the device.
      
      For example:
      
      /x86_64-softmmu/qemu-system-x86_64 -enable-kvm -S -machine q35  \
          -device pcie-root-port,id=pcie_root_port_0,slot=2,chassis=2,addr=0x2,bus=pcie.0 \
          -monitor stdio disk.qcow2
      (qemu)device_add virtio-balloon-pci,id=balloon,bus=pcie_root_port_0
      (qemu)cont
      
      Balloon is deleted during guest boot.
      
      To fix, save control beforehand and check that power
      or led state actually change before ejecting.
      
      Note: this is more a hack than a solution, ideally we'd
      find a better way to detect ejects, or move away
      from ejects completely and instead monitor whether
      it's safe to delete device due to e.g. its power state.
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: NMarcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Reviewed-by: NIgor Mammedov <imammedo@redhat.com>
      Tested-by: NIgor Mammedov <imammedo@redhat.com>
      2841ab43
    • M
      pcie: don't skip multi-mask events · 861dc735
      Michael S. Tsirkin 提交于
      If we are trying to set multiple bits at once, testing that just one of
      them is already set gives a false positive. As a result we won't
      interrupt guest if e.g. presence detection change and attention button
      press are both set. This happens with multi-function device removal.
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      Reviewed-by: NIgor Mammedov <imammedo@redhat.com>
      Reviewed-by: NMarcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Reviewed-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
      861dc735
  2. 12 6月, 2019 1 次提交
    • M
      Include qemu-common.h exactly where needed · a8d25326
      Markus Armbruster 提交于
      No header includes qemu-common.h after this commit, as prescribed by
      qemu-common.h's file comment.
      Signed-off-by: NMarkus 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
  3. 13 3月, 2019 1 次提交
  4. 06 3月, 2019 1 次提交
    • D
      qdev: Let the hotplug_handler_unplug() caller delete the device · 07578b0a
      David Hildenbrand 提交于
      When unplugging a device, at one point the device will be destroyed
      via object_unparent(). This will, one the one hand, unrealize the
      removed device hierarchy, and on the other hand, destroy/free the
      device hierarchy.
      
      When chaining hotplug handlers, we want to overwrite a bus hotplug
      handler by the machine hotplug handler, to be able to perform
      some part of the plug/unplug and to forward the calls to the bus hotplug
      handler.
      
      For now, the bus hotplug handler would trigger an object_unparent(), not
      allowing us to perform some unplug action on a device after we forwarded
      the call to the bus hotplug handler. The device would be gone at that
      point.
      
      machine_unplug_handler(dev)
          /* eventually do unplug stuff */
          bus_unplug_handler(dev)
          /* dev is gone, we can't do more unplug stuff */
      
      So move the object_unparent() to the original caller of the unplug. For
      now, keep the unrealize() at the original places of the
      object_unparent(). For implicitly chained hotplug handlers (e.g. pc
      code calling acpi hotplug handlers), the object_unparent() has to be
      done by the outermost caller. So when calling hotplug_handler_unplug()
      from inside an unplug handler, nothing is to be done.
      
      hotplug_handler_unplug(dev) -> calls machine_unplug_handler()
          machine_unplug_handler(dev) {
              /* eventually do unplug stuff */
              bus_unplug_handler(dev) -> calls unrealize(dev)
              /* we can do more unplug stuff but device already unrealized */
          }
      object_unparent(dev)
      
      In the long run, every unplug action should be factored out of the
      unrealize() function into the unplug handler (especially for PCI). Then
      we can get rid of the additonal unrealize() calls and object_unparent()
      will properly unrealize the device hierarchy after the device has been
      unplugged.
      
      hotplug_handler_unplug(dev) -> calls machine_unplug_handler()
          machine_unplug_handler(dev) {
              /* eventually do unplug stuff */
              bus_unplug_handler(dev) -> only unplugs, does not unrealize
              /* we can do more unplug stuff */
          }
      object_unparent(dev) -> will unrealize
      
      The original approach was suggested by Igor Mammedov for the PCI
      part, but I extended it to all hotplug handlers. I consider this one
      step into the right direction.
      
      To summarize:
      - object_unparent() on synchronous unplugs is done by common code
      -- "Caller of hotplug_handler_unplug"
      - object_unparent() on asynchronous unplugs ("unplug requests") has to
        be done manually
      -- "Caller of hotplug_handler_unplug"
      Reviewed-by: NIgor Mammedov <imammedo@redhat.com>
      Acked-by: NCornelia Huck <cohuck@redhat.com>
      Signed-off-by: NDavid Hildenbrand <david@redhat.com>
      Message-Id: <20190228122849.4296-2-david@redhat.com>
      Reviewed-by: NGreg Kurz <groug@kaod.org>
      Signed-off-by: NEduardo Habkost <ehabkost@redhat.com>
      07578b0a
  5. 22 2月, 2019 1 次提交
    • A
      pci: Sanity test minimum downstream LNKSTA · 88c86919
      Alex Williamson 提交于
      The entire link status register for SR-IOV VFs is defined as RsvdZ,
      reads simply return zero.  Usually this is nothing more than lspci
      reporting inconsequentially broken values:
      
          LnkSta: Speed unknown, Width x0, ...
      
      However, now that we're using the downstream endpoint link status to
      fill in the value at the parent downstream port, invalid values become
      a problem.  In particular, the PCIe hotplug driver in Linux looks for
      a valid negotiated link width and will fail to enumerate hot-added
      downstream endpoints without non-zero value here, ex:
      
          pciehp 0000:00:02.0:pcie004: Slot(0): Attention button pressed
          pciehp 0000:00:02.0:pcie004: Slot(0) Powering on due to button press
          pciehp 0000:00:02.0:pcie004: Slot(0): Card present
          pciehp 0000:00:02.0:pcie004: Slot(0): Link Up
          pciehp 0000:00:02.0:pcie004: link training error: status 0x2000
          pciehp 0000:00:02.0:pcie004: Failed to check link status
      
      Resolve by using minimum width and speed values for the downstream
      port link status when the endpoint fails to provide valid values.
      Long term, we may want to implement emulation in the vfio-pci host
      driver to suppliment this field with the PF value as the SR-IOV spec
      seems to allow, but the solution here is compatible should that be
      implemented later.
      
      Fixes: 727b4866 ("pci: Sync PCIe downstream port LNKSTA on read")
      Reported-by: NJens Freimann <jfreimann@redhat.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Message-Id: <155060310248.19547.14979269067689441201.stgit@gimli.home>
      Tested-by: NJens Freimann <jfreimann@redhat.com>
      Reviewed-by: NMarcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      88c86919
  6. 17 2月, 2019 1 次提交
  7. 15 1月, 2019 1 次提交
  8. 21 12月, 2018 2 次提交
  9. 20 12月, 2018 4 次提交
    • A
      pcie: Fill PCIESlot link fields to support higher speeds and widths · 3d67447f
      Alex Williamson 提交于
      Make use of the PCIESlot speed and width fields to update link
      information beyond those configured in pcie_cap_v1_fill().  This is
      only called for devices supporting a version 2 capability and
      automatically skips any non-PCIESlot devices.  Only devices with
      increased link values generate any visible config space differences.
      
      Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Tested-by: NGeoffrey McRae <geoff@hostfission.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      3d67447f
    • A
      pci: Sync PCIe downstream port LNKSTA on read · 727b4866
      Alex Williamson 提交于
      The PCIe link speed and width between a downstream device and its
      upstream port is negotiated on real hardware and susceptible to
      dynamic changes due to signal issues and power management.  In the
      emulated device case there is no real hardware link, but we still
      might wish to have some consistency between endpoint and downstream
      port via a virtual negotiation.  There is of course a real link for
      assigned devices and this same virtual negotiation allows the
      downstream port to match the endpoint, synchronizing on every read
      to support underlying physical hardware dynamically adjusting the
      link.
      
      This negotiation is intentionally unidirectional for compatibility.
      If the endpoint exceeds the capabilities of the downstream port or
      there is no endpoint device, the downstream port reports negotiation
      to its maximum speed and width, matching the previous case where
      negotiation was absent.  De-tuning the endpoint to match a virtual
      link doesn't seem to benefit anyone and is a condition we've thus
      far reported without functional issues.
      
      Note that PCI_EXP_LNKSTA is already ignored for migration
      compatibility via pcie_cap_v1_fill().
      
      Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Tested-by: NGeoffrey McRae <geoff@hostfission.com>
      Reviewed-by: NEric Auger <eric.auger@redhat.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      727b4866
    • A
      pcie: Create enums for link speed and width · d96a0ac7
      Alex Williamson 提交于
      In preparation for reporting higher virtual link speeds and widths,
      create enums and macros to help us manage them.
      
      Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Tested-by: NGeoffrey McRae <geoff@hostfission.com>
      Reviewed-by: NPhilippe Mathieu-Daudé <philmd@redhat.com>
      Reviewed-by: NEric Auger <eric.auger@redhat.com>
      Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      d96a0ac7
    • Z
      pcie: set link state inactive/active after hot unplug/plug · 2f2b18f6
      Zheng Xiang 提交于
      When VM boots from the latest version of linux kernel, after
      hot-unpluging virtio-blk disks which are hotplugged into
      pcie-root-port, the VM's dmesg log shows:
      
      [  151.046242] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0001 from Slot Status
      [  151.046365] pciehp 0000:00:05.0:pcie004: Slot(0-3): Attention button pressed
      [  151.046369] pciehp 0000:00:05.0:pcie004: Slot(0-3): Powering off due to button press
      [  151.046420] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  151.046425] pciehp 0000:00:05.0:pcie004: pciehp_green_led_blink: SLOTCTRL a8 write cmd 200
      [  151.046464] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  151.046468] pciehp 0000:00:05.0:pcie004: pciehp_set_attention_status: SLOTCTRL a8 write cmd c0
      [  156.163421] pciehp 0000:00:05.0:pcie004: pciehp_get_power_status: SLOTCTRL a8 value read 2f1
      [  156.163427] pciehp 0000:00:05.0:pcie004: pciehp_unconfigure_device: domain:bus:dev = 0000:06:00
      [  156.198736] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  156.198772] pciehp 0000:00:05.0:pcie004: pciehp_power_off_slot: SLOTCTRL a8 write cmd 400
      [  157.224124] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0018 from Slot Status
      [  157.224194] pciehp 0000:00:05.0:pcie004: pciehp_green_led_off: SLOTCTRL a8 write cmd 300
      [  157.224220] pciehp 0000:00:05.0:pcie004: pciehp_check_link_active: lnk_status = 2011
      [  157.224223] pciehp 0000:00:05.0:pcie004: Slot(0-3): Link Up
      [  157.224233] pciehp 0000:00:05.0:pcie004: pciehp_get_power_status: SLOTCTRL a8 value read 7f1
      [  157.224281] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  157.224285] pciehp 0000:00:05.0:pcie004: pciehp_power_on_slot: SLOTCTRL a8 write cmd 0
      [  157.224300] pciehp 0000:00:05.0:pcie004: __pciehp_link_set: lnk_ctrl = 0
      [  157.224336] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  157.224339] pciehp 0000:00:05.0:pcie004: pciehp_green_led_blink: SLOTCTRL a8 write cmd 200
      [  159.739294] pci 0000:06:00.0 id reading try 50 times with interval 20 ms to get ffffffff
      [  159.739315] pciehp 0000:00:05.0:pcie004: pciehp_check_link_status: lnk_status = 2011
      [  159.739318] pciehp 0000:00:05.0:pcie004: Failed to check link status
      [  159.739371] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  159.739394] pciehp 0000:00:05.0:pcie004: pciehp_power_off_slot: SLOTCTRL a8 write cmd 400
      [  160.771426] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  160.771452] pciehp 0000:00:05.0:pcie004: pciehp_green_led_off: SLOTCTRL a8 write cmd 300
      [  160.771495] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  160.771499] pciehp 0000:00:05.0:pcie004: pciehp_set_attention_status: SLOTCTRL a8 write cmd 40
      [  160.771535] pciehp 0000:00:05.0:pcie004: pending interrupts 0x0010 from Slot Status
      [  160.771539] pciehp 0000:00:05.0:pcie004: pciehp_green_led_off: SLOTCTRL a8 write cmd 300
      
      After analyzing the log information, it seems that qemu doesn't
      change the Link Status from active to inactive after hot-unplug.
      This results in the abnormal log after the linux kernel commit
      d331710ea78fea merged.
      
      Furthermore, If I hotplug the same virtio-blk disk after hot-unplug,
      the virtio-blk would turn on and then back off.
      
      So this patch set the Link Status inactive after hot-unplug and
      active after hot-plug.
      Signed-off-by: NZheng Xiang <zhengxiang9@huawei.com>
      Signed-off-by: NZheng Xiang <xiang.zheng@linaro.org>
      Cc: Wang Haibin <wanghaibin.wang@huawei.com>
      Cc: qemu-stable@nongnu.org
      Reviewed-by: NMarcel Apfelbaum <marcel.apfelbaum@gmail.com>
      Reviewed-by: NMichael S. Tsirkin <mst@redhat.com>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      2f2b18f6
  10. 06 12月, 2017 1 次提交
  11. 04 7月, 2017 2 次提交
  12. 16 3月, 2017 2 次提交
  13. 18 2月, 2017 2 次提交
  14. 25 1月, 2017 1 次提交
  15. 10 1月, 2017 1 次提交
  16. 29 7月, 2016 1 次提交
    • M
      pcie: fix link active status bit migration · 6b449540
      Michael S. Tsirkin 提交于
      We changed link status register in pci express endpoint capability
      over time. Specifically,
      
      commit b2101eae ("pcie: Set the "link
      active" in the link status register") set data link layer link active
      bit in this register without adding compatibility to old machine types.
      
      When migrating from qemu 2.3 and older this affects xhci devices which
      under machine type 2.0 and older have a pci express endpoint capability
      even if they are on a pci bus.
      
      Add compatibility flags to make this bit value match what it was under
      2.3.
      
      Additionally, to avoid breaking migration from qemu 2.3 and up,
      suppress checking link status during migration: this seems sane
      since hardware can change link status at any time.
      
      https://bugzilla.redhat.com/show_bug.cgi?id=1352860Reported-by: NGerd Hoffmann <kraxel@redhat.com>
      Fixes: b2101eae
          ("pcie: Set the "link active" in the link status register")
      Cc: qemu-stable@nongnu.org
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
      6b449540
  17. 02 6月, 2016 2 次提交
  18. 23 3月, 2016 1 次提交
    • M
      include/qemu/osdep.h: Don't include qapi/error.h · da34e65c
      Markus Armbruster 提交于
      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: NMarkus Armbruster <armbru@redhat.com>
      [Fix compilation without the spice devel packages. - Paolo]
      Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
      da34e65c
  19. 20 2月, 2016 1 次提交
  20. 29 1月, 2016 1 次提交
    • P
      pci: Clean up includes · 97d5408f
      Peter Maydell 提交于
      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: NPeter Maydell <peter.maydell@linaro.org>
      Message-id: 1453832250-766-23-git-send-email-peter.maydell@linaro.org
      97d5408f
  21. 06 11月, 2015 1 次提交
  22. 29 10月, 2015 2 次提交
  23. 08 7月, 2015 1 次提交
  24. 23 6月, 2015 1 次提交
  25. 18 3月, 2015 1 次提交
  26. 25 11月, 2014 2 次提交
  27. 02 11月, 2014 1 次提交
  28. 15 10月, 2014 1 次提交