Skip to contentSkip to conversation

VFIO update 2021-07-14 (for v6.1)

GIT PULL Applied Alex Williamson 2 participants 5 messages Jul 14, 2021 – Jul 16, 2021

lore
Share & tools
lore
#0 lore raw

The following changes since commit a9649a719a44894b81f38dc1c5c1888ee684acef:

Merge remote-tracking branch 'remotes/cleber-gitlab/tags/python-next-pull-request' into staging (2021-07-14 18:09:09 +0100)

are available in the Git repository at:

git://github.com/awilliam/qemu-vfio.git tags/vfio-update-20210714.0

for you to fetch changes up to 1bd9f1b14d1e9c1498bb03faf4e2bb945cf6542d:

vfio/pci: Add pba_offset PCI quirk for BAIDU KUNLUN AI processor (2021-07-14 13:47:17 -0600)

----------------------------------------------------------------
VFIO update 2021-07-14

* Coverity fix to discard listener (David Hildenbrand)

* MSI-X PBA quirk for BAIDU VFs, additional helper use cases (Cai Huoqing)

----------------------------------------------------------------
Cai Huoqing (2):
vfio/pci: Change to use vfio_pci_is()
vfio/pci: Add pba_offset PCI quirk for BAIDU KUNLUN AI processor

David Hildenbrand (1):
vfio: Fix CID 1458134 in vfio_register_ram_discard_listener()

 hw/vfio/common.c         |  3 ++-
 hw/vfio/pci.c            | 12 ++++++++++--
 include/hw/pci/pci_ids.h |  3 +++
 3 files changed, 15 insertions(+), 3 deletions(-)
#1 lore raw

[PULL v2 1/3] vfio: Fix CID 1458134 in vfio_register_ram_discard_listener()

From: David Hildenbrand <[email protected]>

CID 1458134: Integer handling issues (BAD_SHIFT)

    In expression "1 << ctz64(container->pgsizes)", left shifting by more
    than 31 bits has undefined behavior.  The shift amount,
    "ctz64(container->pgsizes)", is 64.

Commit 5e3b981c330c ("vfio: Support for RamDiscardManager in the !vIOMMU case") added an assertion that our granularity is at least as big as the page size.

Although unlikely, we could have a page size that does not fit into 32 bit. In that case, we'd try shifting by more than 31 bit.

Let's use 1ULL instead and make sure we're not shifting by more than 63 bit by asserting that any bit in container->pgsizes is set.

Fixes CID 1458134
Cc Alex Williamson <[email protected]>
Cc Eduardo Habkost <[email protected]>
Cc "Michael S. Tsirkin" <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Dr. David Alan Gilbert <[email protected]>
Cc Igor Mammedov <[email protected]>
Cc Pankaj Gupta <[email protected]>
Cc Peter Xu <[email protected]>
Cc Auger Eric <[email protected]>
Cc Wei Yang <[email protected]>
Cc teawater <[email protected]>
Cc Marek Kedzierski <[email protected]>
---
 hw/vfio/common.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/vfio/common.c +2 -1
index 3f0d11136081..8728d4d5c2e2 100644
@@ -783,7 +783,8 @@ static void vfio_register_ram_discard_listener(VFIOContainer *container,
                                                                 section->mr);
 
     g_assert(vrdl->granularity && is_power_of_2(vrdl->granularity));
-    g_assert(vrdl->granularity >= 1 << ctz64(container->pgsizes));
+    g_assert(container->pgsizes &&
+             vrdl->granularity >= 1ULL << ctz64(container->pgsizes));
 
     ram_discard_listener_init(&vrdl->listener,
                               vfio_ram_discard_notify_populate,
#2 lore raw

[PULL v2 2/3] vfio/pci: Change to use vfio_pci_is()

In reply to Alex Williamson

From: Cai Huoqing <[email protected]>

Make use of vfio_pci_is() helper function.

---
 hw/vfio/pci.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/vfio/pci.c +2 -2
index ab4077aad23e..971273fd458b 100644
@@ -3058,14 +3058,14 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
         }
     }
 
-    if (vdev->vendor_id == PCI_VENDOR_ID_NVIDIA) {
+    if (vfio_pci_is(vdev, PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID)) {
         ret = vfio_pci_nvidia_v100_ram_init(vdev, errp);
         if (ret && ret != -ENODEV) {
             error_report("Failed to setup NVIDIA V100 GPU RAM");
         }
     }
 
-    if (vdev->vendor_id == PCI_VENDOR_ID_IBM) {
+    if (vfio_pci_is(vdev, PCI_VENDOR_ID_IBM, PCI_ANY_ID)) {
         ret = vfio_pci_nvlink2_init(vdev, errp);
         if (ret && ret != -ENODEV) {
             error_report("Failed to setup NVlink2 bridge");
#3 lore raw

[PULL v2 3/3] vfio/pci: Add pba_offset PCI quirk for BAIDU KUNLUN AI processor

In reply to Alex Williamson

From: Cai Huoqing <[email protected]>

Fix pba_offset initialization value for BAIDU KUNLUN Virtual Function device. The KUNLUN hardware returns an incorrect value for the VF PBA offset, and add a quirk to instead return a hardcoded value of 0xb400.

---
 hw/vfio/pci.c            |    8 ++++++++
 include/hw/pci/pci_ids.h |    3 +++
 2 files changed, 11 insertions(+)
hw/vfio/pci.c +8 -0
index 971273fd458b..e1ea1d8a23b5 100644
@@ -1499,6 +1499,14 @@ static void vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp)
         if (vdev->vendor_id == PCI_VENDOR_ID_CHELSIO &&
             (vdev->device_id & 0xff00) == 0x5800) {
             msix->pba_offset = 0x1000;
+        /*
+         * BAIDU KUNLUN Virtual Function devices for KUNLUN AI processor
+         * return an incorrect value of 0x460000 for the VF PBA offset while
+         * the BAR itself is only 0x10000.  The correct value is 0xb400.
+         */
+        } else if (vfio_pci_is(vdev, PCI_VENDOR_ID_BAIDU,
+                               PCI_DEVICE_ID_KUNLUN_VF)) {
+            msix->pba_offset = 0xb400;
         } else if (vdev->msix_relo == OFF_AUTOPCIBAR_OFF) {
             error_setg(errp, "hardware reports invalid configuration, "
                        "MSIX PBA outside of specified BAR");
include/hw/pci/pci_ids.h +3 -0
index 5c14681b82eb..11abe22d4604 100644
@@ -227,6 +227,9 @@
 #define PCI_VENDOR_ID_FREESCALE          0x1957
 #define PCI_DEVICE_ID_MPC8533E           0x0030
 
+#define PCI_VENDOR_ID_BAIDU              0x1d22
+#define PCI_DEVICE_ID_KUNLUN_VF          0x3685
+
 #define PCI_VENDOR_ID_INTEL              0x8086
 #define PCI_DEVICE_ID_INTEL_82378        0x0484
 #define PCI_DEVICE_ID_INTEL_82441        0x1237
#4 lore raw
In reply to Alex Williamson
Quoted 11 lines · Alex Williamson

The following changes since commit a9649a719a44894b81f38dc1c5c1888ee684acef:

Merge remote-tracking branch 'remotes/cleber-gitlab/tags/python-next-pull-request' into staging (2021-07-14 18:09:09 +0100)

are available in the Git repository at:

git://github.com/awilliam/qemu-vfio.git tags/vfio-update-20210714.0

for you to fetch changes up to 1bd9f1b14d1e9c1498bb03faf4e2bb945cf6542d:

Quoted 9 lines

vfio/pci: Add pba_offset PCI quirk for BAIDU KUNLUN AI processor (2021-07-14 13:47:17 -0600)

----------------------------------------------------------------
VFIO update 2021-07-14

* Coverity fix to discard listener (David Hildenbrand)

* MSI-X PBA quirk for BAIDU VFs, additional helper use cases (Cai Huoqing)

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/6.1
for any user-visible changes.

-- PMM