qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v7 01/17] hw/vfio/pci: Ensure MSI and MSI-X do not overlap


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH v7 01/17] hw/vfio/pci: Ensure MSI and MSI-X do not overlap
Date: Tue, 1 Nov 2022 14:35:33 +0100
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.4.0

On 1/11/22 01:58, Akihiko Odaki wrote:
pci_add_capability() checks whether capabilities overlap, and notifies
its caller so that it can properly handle the case. However, in the
most cases, the capabilities actually never overlap, and the interface
incurred extra error handling code, which is often incorrect or
suboptimal. For such cases, pci_add_capability() can simply abort the
execution if the capabilities actually overlap since it should be a
programming error.

This change handles the other cases: hw/vfio/pci depends on the check to
decide MSI and MSI-X capabilities overlap with another. As they are
quite an exceptional and hw/vfio/pci knows much about PCI capabilities,
adding code specific to the cases to hw/vfio/pci still results in less
code than having error handling code everywhere in total.

Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
  hw/pci/pci.c         | 32 ++++++++++++++++++++------------
  hw/vfio/pci.c        | 15 ++++++++++++++-
  include/hw/pci/pci.h |  3 +++
  3 files changed, 37 insertions(+), 13 deletions(-)

diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 2f450f6a72..33f5406706 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2512,6 +2512,23 @@ static void pci_del_option_rom(PCIDevice *pdev)
      pdev->has_rom = false;
  }
+void pci_check_capability_overlap(PCIDevice *pdev, uint8_t cap_id,
+                                  uint8_t offset, uint8_t size, Error **errp)
+{
+    int i;
+
+    for (i = offset; i < offset + size; i++) {
+        if (pdev->used[i]) {
+            error_setg(errp,
+                       "%s:%02x:%02x.%x PCI capability %x at offset %x overlaps 
existing capability %x at offset %x",
+                       pci_root_bus_path(pdev), pci_dev_bus_num(pdev),
+                       PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn),
+                       cap_id, offset, pci_find_capability_at_offset(pdev, i), 
i);
+            return;

Per the Error API ("qapi/error.h" or https://gitlab.com/qemu-project/qemu/-/commit/e3fe3988d7851cac) this function should return a boolean (true on success and false on error).

+        }
+    }
+}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]