PCI capabilities can't appear magically at runtime. Guests aren't expecting that. Assert all capabilities are added _before_ a device instance is realized.
Signed-off-by: Philippe Mathieu-Daudé <phi...@linaro.org> --- hw/pci/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index ac41fcbf6a..ed60b352e4 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -2397,7 +2397,7 @@ static void pci_del_option_rom(PCIDevice *pdev) * On success, pci_add_capability() returns a positive value * that the offset of the pci capability. * On failure, it sets an error and returns a negative error - * code. + * code. @pdev must be unrealized. */ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t offset, uint8_t size, @@ -2406,6 +2406,8 @@ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t *config; int i, overlapping_cap; + assert(!DEVICE(pdev)->realized); + if (!offset) { offset = pci_find_space(pdev, size); /* out of PCI config space is programming error */ -- 2.38.1