[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/20] pci: acpi: ensure that acpi-index is unique
From: |
Michael S. Tsirkin |
Subject: |
[PULL 12/20] pci: acpi: ensure that acpi-index is unique |
Date: |
Mon, 22 Mar 2021 11:45:01 -0400 |
From: Igor Mammedov <imammedo@redhat.com>
it helps to avoid device naming conflicts when guest OS is
configured to use acpi-index for naming.
Spec ialso says so:
PCI Firmware Specification Revision 3.2
4.6.7. _DSM for Naming a PCI or PCI Express Device Under Operating Systems
"
Instance number must be unique under \_SB scope. This instance number does not
have to
be sequential in a given system configuration.
"
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Message-Id: <20210315180102.3008391-4-imammedo@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/acpi/pcihp.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c
index ceab287bd3..f4cb3c979d 100644
--- a/hw/acpi/pcihp.c
+++ b/hw/acpi/pcihp.c
@@ -52,6 +52,21 @@ typedef struct AcpiPciHpFind {
PCIBus *bus;
} AcpiPciHpFind;
+static gint g_cmp_uint32(gconstpointer a, gconstpointer b, gpointer user_data)
+{
+ return a - b;
+}
+
+static GSequence *pci_acpi_index_list(void)
+{
+ static GSequence *used_acpi_index_list;
+
+ if (!used_acpi_index_list) {
+ used_acpi_index_list = g_sequence_new(NULL);
+ }
+ return used_acpi_index_list;
+}
+
static int acpi_pcihp_get_bsel(PCIBus *bus)
{
Error *local_err = NULL;
@@ -277,6 +292,23 @@ void acpi_pcihp_device_pre_plug_cb(HotplugHandler
*hotplug_dev,
ONBOARD_INDEX_MAX);
return;
}
+
+ /*
+ * make sure that acpi-index is unique across all present PCI devices
+ */
+ if (pdev->acpi_index) {
+ GSequence *used_indexes = pci_acpi_index_list();
+
+ if (g_sequence_lookup(used_indexes, GINT_TO_POINTER(pdev->acpi_index),
+ g_cmp_uint32, NULL)) {
+ error_setg(errp, "a PCI device with acpi-index = %" PRIu32
+ " already exist", pdev->acpi_index);
+ return;
+ }
+ g_sequence_insert_sorted(used_indexes,
+ GINT_TO_POINTER(pdev->acpi_index),
+ g_cmp_uint32, NULL);
+ }
}
void acpi_pcihp_device_plug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState *s,
@@ -315,8 +347,22 @@ void acpi_pcihp_device_plug_cb(HotplugHandler
*hotplug_dev, AcpiPciHpState *s,
void acpi_pcihp_device_unplug_cb(HotplugHandler *hotplug_dev, AcpiPciHpState
*s,
DeviceState *dev, Error **errp)
{
+ PCIDevice *pdev = PCI_DEVICE(dev);
+
trace_acpi_pci_unplug(PCI_SLOT(PCI_DEVICE(dev)->devfn),
acpi_pcihp_get_bsel(pci_get_bus(PCI_DEVICE(dev))));
+
+ /*
+ * clean up acpi-index so it could reused by another device
+ */
+ if (pdev->acpi_index) {
+ GSequence *used_indexes = pci_acpi_index_list();
+
+ g_sequence_remove(g_sequence_lookup(used_indexes,
+ GINT_TO_POINTER(pdev->acpi_index),
+ g_cmp_uint32, NULL));
+ }
+
qdev_unrealize(dev);
}
--
MST
- [PULL 01/20] virtio: Fix virtio_mmio_read()/virtio_mmio_write(), (continued)
- [PULL 01/20] virtio: Fix virtio_mmio_read()/virtio_mmio_write(), Michael S. Tsirkin, 2021/03/22
- [PULL 03/20] vhost-user: Fix double-close on slave_read() error path, Michael S. Tsirkin, 2021/03/22
- [PULL 02/20] vhost-user: Drop misleading EAGAIN checks in slave_read(), Michael S. Tsirkin, 2021/03/22
- [PULL 04/20] vhost-user: Factor out duplicated slave_fd teardown code, Michael S. Tsirkin, 2021/03/22
- [PULL 05/20] vhost-user: Convert slave channel to QIOChannelSocket, Michael S. Tsirkin, 2021/03/22
- [PULL 06/20] vhost-user: Introduce nested event loop in vhost_user_read(), Michael S. Tsirkin, 2021/03/22
- [PULL 07/20] vhost-user: Monitor slave channel in vhost_user_read(), Michael S. Tsirkin, 2021/03/22
- [PULL 08/20] virtio-pmem: fix virtio_pmem_resp assign problem, Michael S. Tsirkin, 2021/03/22
- [PULL 09/20] acpi:piix4, vt82c686: reinitialize acpi PM device on reset, Michael S. Tsirkin, 2021/03/22
- [PULL 11/20] pci: introduce acpi-index property for PCI device, Michael S. Tsirkin, 2021/03/22
- [PULL 12/20] pci: acpi: ensure that acpi-index is unique,
Michael S. Tsirkin <=
- [PULL 13/20] acpi: add aml_to_decimalstring() and aml_call6() helpers, Michael S. Tsirkin, 2021/03/22
- [PULL 16/20] acpi: Set proper maximum size for "etc/table-loader" blob, Michael S. Tsirkin, 2021/03/22
- [PULL 17/20] microvm: Don't open-code "etc/table-loader", Michael S. Tsirkin, 2021/03/22
- [PULL 18/20] acpi: Move maximum size logic into acpi_add_rom_blob(), Michael S. Tsirkin, 2021/03/22
- [PULL 19/20] acpi: Set proper maximum size for "etc/acpi/rsdp" blob, Michael S. Tsirkin, 2021/03/22
- [PULL 20/20] acpi: Move setters/getters of oem fields to X86MachineState, Michael S. Tsirkin, 2021/03/22
- [PULL 14/20] pci: acpi: add _DSM method to PCI devices, Michael S. Tsirkin, 2021/03/22
- [PULL 15/20] tests: acpi: update expected blobs, Michael S. Tsirkin, 2021/03/22
- Re: [PULL 00/20] pc,virtio,pci: fixes, features, Peter Maydell, 2021/03/22