qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: robin@streamhpc.com, mst@redhat.com, marcel.apfelbaum@gmail.com
Cc: Alex Williamson <alex.williamson@redhat.com>, qemu-devel@nongnu.org
Subject: [RFC PATCH 4/4] vfio/pci: Enable AtomicOps completers on root ports
Date: Fri, 19 May 2023 15:57:39 -0600	[thread overview]
Message-ID: <20230519215739.402729-5-alex.williamson@redhat.com> (raw)
In-Reply-To: <20230519215739.402729-1-alex.williamson@redhat.com>

For cold-plug configurations where the vfio-pci device reports enabled
support for PCIe AtomicOps completers and we have a compatible VM
configuration, mirror the host AtomicOps completer support in the virtual
root port.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/pci.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index bf27a3990564..61d045785bf8 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -1826,6 +1826,70 @@ static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos,
     vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask);
 }
 
+/*
+ * For a cold-plugged device connected directly to a root port where
+ * vfio-pci reports AtomicOp completer support on the host, twiddle
+ * bits in the emulated root port to reflect this capability.
+ */
+static void vfio_pci_enable_rp_atomics(VFIOPCIDevice *vdev)
+{
+    struct vfio_device_info_cap_pci_atomic_comp *cap;
+    g_autofree struct vfio_device_info *info = NULL;
+    struct vfio_info_cap_header *hdr;
+    PCIDevice *parent;
+    uint32_t mask = 0;
+    PCIBus *bus;
+
+    /*
+     * XXX
+     *  - Should this also be restricted to TYPE_VFIO_PCI_NOHOTPLUG devices?
+     *  - Should we clear the capability on exit?
+     */
+    if (vdev->pdev.qdev.hotplugged) {
+        return;
+    }
+
+    info = vfio_get_device_info(vdev->vbasedev.fd);
+    if (!info) {
+        return;
+    }
+
+    hdr = vfio_get_device_info_cap(info, VFIO_DEVICE_INFO_CAP_PCI_ATOMIC_COMP);
+    if (!hdr) {
+        return;
+    }
+
+    cap = (void *)hdr;
+    if (cap->flags & VFIO_PCI_ATOMIC_COMP32) {
+        mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP32;
+    }
+    if (cap->flags & VFIO_PCI_ATOMIC_COMP64) {
+        mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP64;
+    }
+    if (cap->flags & VFIO_PCI_ATOMIC_COMP128) {
+        mask |= PCI_EXP_DEVCAP2_ATOMIC_COMP128;
+    }
+
+    if (!mask) {
+        return;
+    }
+
+    bus = pci_get_bus(&vdev->pdev);
+    parent = bus->parent_dev;
+
+    if (!parent || !pci_is_express(parent) || !parent->exp.exp_cap) {
+        return;
+    }
+
+    if (pcie_cap_get_type(parent) != PCI_EXP_TYPE_ROOT_PORT ||
+        pcie_cap_get_version(parent) != PCI_EXP_FLAGS_VER2) {
+        return;
+    }
+
+    pci_long_test_and_set_mask(parent->config + parent->exp.exp_cap +
+                               PCI_EXP_DEVCAP2, mask);
+}
+
 static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
                                Error **errp)
 {
@@ -1929,6 +1993,8 @@ static int vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size,
                            QEMU_PCI_EXP_LNKCAP_MLS(QEMU_PCI_EXP_LNK_2_5GT), ~0);
             vfio_add_emulated_word(vdev, pos + PCI_EXP_LNKCTL, 0, ~0);
         }
+
+        vfio_pci_enable_rp_atomics(vdev);
     }
 
     /*
-- 
2.39.2



      parent reply	other threads:[~2023-05-19 21:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 21:57 [RFC PATCH 0/4] vfio/pci: Atomic Ops completer support Alex Williamson
2023-05-19 21:57 ` [RFC PATCH 1/4] linux-headers: Update for vfio capability reporting AtomicOps Alex Williamson
2023-07-03 16:23   ` Cédric Le Goater
2023-05-19 21:57 ` [RFC PATCH 2/4] vfio: Implement a common device info helper Alex Williamson
2023-05-20  4:33   ` Philippe Mathieu-Daudé
2023-05-22  7:19   ` Cédric Le Goater
2023-05-19 21:57 ` [RFC PATCH 3/4] pcie: Add a PCIe capability version helper Alex Williamson
2023-05-19 21:57 ` Alex Williamson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230519215739.402729-5-alex.williamson@redhat.com \
    --to=alex.williamson@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=robin@streamhpc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).