[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v8 02/17] pci: Allow to omit errp for pci_add_capability
From: |
Akihiko Odaki |
Subject: |
[PATCH v8 02/17] pci: Allow to omit errp for pci_add_capability |
Date: |
Tue, 1 Nov 2022 22:57:34 +0900 |
pci_add_capability appears most PCI devices. Its error handling required
lots of code, and led to inconsistent behaviors such as:
- passing error_abort
- passing error_fatal
- asserting the returned value
- propagating the error to the caller
- skipping the rest of the function
- just ignoring
The code generating errors in pci_add_capability had a comment which
says:
> Verify that capabilities don't overlap. Note: device assignment
> depends on this check to verify that the device is not broken.
> Should never trigger for emulated devices, but it's helpful for
> debugging these.
Indeed vfio has some code that passes capability offsets and sizes from
a physical device, but it explicitly pays attention so that the
capabilities never overlap. Therefore, we can always assert that
capabilities never overlap when pci_add_capability is called, resolving
these inconsistencies.
Such an implementation of pci_add_capability will not have errp
parameter. However, there are so many callers of pci_add_capability
that it does not make sense to amend all of them at once to match
with the new signature. Instead, this change will allow callers of
pci_add_capability to omit errp as the first step.
Signed-off-by: Akihiko Odaki <akihiko.odaki@daynix.com>
---
hw/pci/pci.c | 8 ++++----
include/hw/pci/pci.h | 13 ++++++++++---
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index b53649d1fd..cce57f572c 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2532,14 +2532,14 @@ bool pci_check_capability_overlap(PCIDevice *pdev,
uint8_t cap_id,
}
/*
- * On success, pci_add_capability() returns a positive value
+ * On success, pci_add_capability_legacy() returns a positive value
* that the offset of the pci capability.
* On failure, it sets an error and returns a negative error
* code.
*/
-int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
- uint8_t offset, uint8_t size,
- Error **errp)
+int pci_add_capability_legacy(PCIDevice *pdev, uint8_t cap_id,
+ uint8_t offset, uint8_t size,
+ Error **errp)
{
uint8_t *config;
diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 77b264c17e..50c00ece3e 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -2,6 +2,7 @@
#define QEMU_PCI_H
#include "exec/memory.h"
+#include "qapi/error.h"
#include "sysemu/dma.h"
/* PCI includes legacy ISA access. */
@@ -393,9 +394,15 @@ pcibus_t pci_get_bar_addr(PCIDevice *pci_dev, int
region_num);
bool pci_check_capability_overlap(PCIDevice *pdev, uint8_t cap_id,
uint8_t offset, uint8_t size, Error **errp);
-int pci_add_capability(PCIDevice *pdev, uint8_t cap_id,
- uint8_t offset, uint8_t size,
- Error **errp);
+int pci_add_capability_legacy(PCIDevice *pdev, uint8_t cap_id,
+ uint8_t offset, uint8_t size,
+ Error **errp);
+
+#define PCI_ADD_CAPABILITY_VA(pdev, cap_id, offset, size, errp, ...) \
+ pci_add_capability_legacy(pdev, cap_id, offset, size, errp)
+
+#define pci_add_capability(...) \
+ PCI_ADD_CAPABILITY_VA(__VA_ARGS__, &error_abort)
void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size);
--
2.38.1
- [PATCH v8 00/17] pci: Abort if pci_add_capability fails, Akihiko Odaki, 2022/11/01
- [PATCH v8 02/17] pci: Allow to omit errp for pci_add_capability,
Akihiko Odaki <=
- [PATCH v8 01/17] hw/vfio/pci: Ensure MSI and MSI-X do not overlap, Akihiko Odaki, 2022/11/01
- [PATCH v8 03/17] hw/i386/amd_iommu: Omit errp for pci_add_capability, Akihiko Odaki, 2022/11/01
- [PATCH v8 04/17] ahci: Omit errp for pci_add_capability, Akihiko Odaki, 2022/11/01
- [PATCH v8 05/17] e1000e: Omit errp for pci_add_capability, Akihiko Odaki, 2022/11/01
- [PATCH v8 06/17] eepro100: Omit errp for pci_add_capability, Akihiko Odaki, 2022/11/01
- [PATCH v8 07/17] hw/nvme: Omit errp for pci_add_capability, Akihiko Odaki, 2022/11/01
- [PATCH v8 08/17] msi: Omit errp for pci_add_capability, Akihiko Odaki, 2022/11/01
- [PATCH v8 09/17] hw/pci/pci_bridge: Omit errp for pci_add_capability, Akihiko Odaki, 2022/11/01