qemu-devel
[Top][All Lists]
Advanced

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

Re: [PATCH] hw/pci/pci_bridge: ensure PCIe slots have only one slot


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [PATCH] hw/pci/pci_bridge: ensure PCIe slots have only one slot
Date: Wed, 6 Jul 2022 21:38:39 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1

On 7/4/22 13:25, Roman Kagan wrote:
It's possible to create non-working configurations by attaching a device
to a derivative of PCIe slot (pcie-root-port, ioh3420, etc) and
specifying a slot number other that zero, e.g.:

     -device pcie-root-port,id=s0,... \
     -device virtio-blk-pci,bus=s0,addr=4,...

Make QEMU reject such configurations and only allow addr=0 on the
secondary bus of a PCIe slot.

Signed-off-by: Roman Kagan <rvkagan@yandex-team.ru>
---
  hw/pci/pci_bridge.c | 5 +++++
  1 file changed, 5 insertions(+)

diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
index da34c8ebcd..8b38d5ad3d 100644
--- a/hw/pci/pci_bridge.c
+++ b/hw/pci/pci_bridge.c
@@ -33,6 +33,7 @@
  #include "qemu/units.h"
  #include "hw/pci/pci_bridge.h"
  #include "hw/pci/pci_bus.h"
+#include "hw/pci/pcie_port.h"
  #include "qemu/module.h"
  #include "qemu/range.h"
  #include "qapi/error.h"
@@ -386,6 +387,10 @@ void pci_bridge_initfn(PCIDevice *dev, const char 
*typename)
      br->windows = pci_bridge_region_init(br);
      QLIST_INIT(&sec_bus->child);
      QLIST_INSERT_HEAD(&parent->child, sec_bus, sibling);
+
+    if (PCIE_SLOT(dev)) {

Hmm, wouldn't PCIE_SLOT just crash if dev is not pcie slot? As I understand, 
PCIE_SLOT is finally an OBJECT_CHECK(), which say:

 * If an invalid object is passed to this function, a run time assert will be
 * generated.


+        sec_bus->slot_reserved_mask = ~1u;
+    }
  }
/* default qdev clean up function for PCI-to-PCI bridge */


--
Best regards,
Vladimir



reply via email to

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