From nobody Tue Nov 18 09:21:14 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608680419; cv=none; d=zohomail.com; s=zohoarc; b=IYpGeBryNRNVKkj5T07jRbOe+Pc6T5sRw81NOYIemvBjRgpPmPUKiMAX6+KxdOoPjVm7N/ojtkuHOvzpx3VdmrAq3iKvn+KiNk5AF3Q539M43RrncpCzVLAmHSbyiKL2ZBrhIFVsVdpxTXZzGvHt6KSxIv5oJRZ607z3MR/4M9c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608680419; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=jRqJIElpNRLwzQi92GzEhWLqvO2sH/KNhssq3GcOdPw=; b=EDyLsnS6aXf6gkA6ZsGCEKyYWGgLRAC6W6l+IX6W1IObeGOqVFgVrKJJJNkMif61o9HCv2TGvkBg7HD2KcN3eRCRjY7Si/6B+JN2b9mLZCUFV5vreQTHFdsb63iQY/vMD4Kpm9ObQnhQIzmqK4uBxhMH0w72z7GvR9nw5TQDXHA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1608680419885277.444400677012; Tue, 22 Dec 2020 15:40:19 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-495-cdp7O_Y3OMmC7ueqfitzVQ-1; Tue, 22 Dec 2020 18:40:16 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 55B90107ACE4; Tue, 22 Dec 2020 23:40:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EB8660C5B; Tue, 22 Dec 2020 23:40:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 291704A7C6; Tue, 22 Dec 2020 23:39:59 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0BMNdvq6016669 for ; Tue, 22 Dec 2020 18:39:57 -0500 Received: by smtp.corp.redhat.com (Postfix) id 154415D9D3; Tue, 22 Dec 2020 23:39:57 +0000 (UTC) Received: from dell-r430-03.lab.eng.brq.redhat.com (dell-r430-03.lab.eng.brq.redhat.com [10.37.153.18]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1528B5D9CC; Tue, 22 Dec 2020 23:39:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608680418; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jRqJIElpNRLwzQi92GzEhWLqvO2sH/KNhssq3GcOdPw=; b=WaZMAiXX0VUggBcEK4vXb+UPhdlqYbHOsseJVytDbSf1yk8T2B2MSauysQtjx4S8/oQWk4 PVq38cbBOr59s1pjg9KMonTEul4sYV+WeMP/k6Mk865HiIBw08YhX5so9g42j395Den/Ss W2ebUzq8a2WuPXw8SDAdg2V1hgyfjG8= X-MC-Unique: cdp7O_Y3OMmC7ueqfitzVQ-1 From: Igor Mammedov To: qemu-devel@nongnu.org Subject: [RFC 3/5] pci: introduce apci-index property for PCI device Date: Tue, 22 Dec 2020 18:39:32 -0500 Message-Id: <20201222233934.451578-4-imammedo@redhat.com> In-Reply-To: <20201222233934.451578-1-imammedo@redhat.com> References: <20201222233934.451578-1-imammedo@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: libvir-list@redhat.com, jusual@redhat.com, laine@redhat.com, marcel.apfelbaum@gmail.com, mst@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" In x86/ACPI world, since systemd v197, linux distros are using predictable network interface naming since systemd v197. Which on QEMU based VMs results into path based naming scheme, that names network interfaces based on PCI topology. With this one has to plug NIC in exacly the same bus/slot, which was used when disk image was first provisioned/configured or one risks to loose network configuration due to NIC being renamed to actually used topology. That also restricts freedom reshape PCI configuration of VM without need to reconfigure used guest image. systemd also offers "onboard" naming scheme which is preffered over PCI slot/topology one, provided that firmware implements: " PCI Firmware Specification 3.1 4.6.7. DSM for Naming a PCI or PCI Express Device Under Operating Systems " that allows to assign user defined index to PCI device, which systemd will use to name NIC. For example, using -device e1000,acpi-index=3D100 guest will rename NIC to 'eno100', where 'eno' is default prefix for "onboard" naming scheme. This doesn't reqiure any advance configuration on guest side. Hope is that 'acpi-index' will be easier to consume by mangment layer, compared to forcing specic PCI topology and/or having several disk image templates for different topologies and will help to simplify process of spawning VM from the same template without need to reconfigure guest network configuration. this patch adds, 'acpi-index'* property and wires up (abuses) unused pci hotplug registers to pass index value to AML code at runtime. Following patch will add corresponding _DSM code and wire it up to PCI devices described in ACPI. *) name comes from linux kernel terminology Signed-off-by: Igor Mammedov --- CC: libvir-list@redhat.com include/hw/acpi/pcihp.h | 7 ++++++- include/hw/pci/pci.h | 1 + hw/acpi/pci.c | 6 ++++++ hw/acpi/pcihp.c | 25 ++++++++++++++++++++++++- hw/i386/acpi-build.c | 10 ++++++++++ hw/pci/pci.c | 1 + 6 files changed, 48 insertions(+), 2 deletions(-) diff --git a/include/hw/acpi/pcihp.h b/include/hw/acpi/pcihp.h index dfd375820f..72d1773ca1 100644 --- a/include/hw/acpi/pcihp.h +++ b/include/hw/acpi/pcihp.h @@ -46,6 +46,7 @@ typedef struct AcpiPciHpPciStatus { typedef struct AcpiPciHpState { AcpiPciHpPciStatus acpi_pcihp_pci_status[ACPI_PCIHP_MAX_HOTPLUG_BUS]; uint32_t hotplug_select; + uint32_t acpi_index; PCIBus *root; MemoryRegion io; bool legacy_piix; @@ -71,6 +72,8 @@ void acpi_pcihp_reset(AcpiPciHpState *s, bool acpihp_root= _off); =20 extern const VMStateDescription vmstate_acpi_pcihp_pci_status; =20 +bool vmstate_acpi_pcihp_use_acpi_index(void *opaque, int version_id); + #define VMSTATE_PCI_HOTPLUG(pcihp, state, test_pcihp) \ VMSTATE_UINT32_TEST(pcihp.hotplug_select, state, \ test_pcihp), \ @@ -78,6 +81,8 @@ extern const VMStateDescription vmstate_acpi_pcihp_pci_st= atus; ACPI_PCIHP_MAX_HOTPLUG_BUS, \ test_pcihp, 1, \ vmstate_acpi_pcihp_pci_status, \ - AcpiPciHpPciStatus) + AcpiPciHpPciStatus), \ + VMSTATE_UINT32_TEST(pcihp.acpi_index, state, \ + vmstate_acpi_pcihp_use_acpi_index) =20 #endif diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h index 259f9c992d..e592532558 100644 --- a/include/hw/pci/pci.h +++ b/include/hw/pci/pci.h @@ -357,6 +357,7 @@ struct PCIDevice { =20 /* ID of standby device in net_failover pair */ char *failover_pair_id; + uint32_t acpi_index; }; =20 void pci_register_bar(PCIDevice *pci_dev, int region_num, diff --git a/hw/acpi/pci.c b/hw/acpi/pci.c index 9510597a19..07d5101d83 100644 --- a/hw/acpi/pci.c +++ b/hw/acpi/pci.c @@ -27,6 +27,7 @@ #include "hw/acpi/aml-build.h" #include "hw/acpi/pci.h" #include "hw/pci/pcie_host.h" +#include "hw/acpi/pcihp.h" =20 void build_mcfg(GArray *table_data, BIOSLinker *linker, AcpiMcfgInfo *info) { @@ -59,3 +60,8 @@ void build_mcfg(GArray *table_data, BIOSLinker *linker, A= cpiMcfgInfo *info) "MCFG", table_data->len - mcfg_start, 1, NULL, NULL); } =20 +bool vmstate_acpi_pcihp_use_acpi_index(void *opaque, int version_id) +{ + AcpiPciHpState *s =3D opaque; + return s->acpi_index; +} diff --git a/hw/acpi/pcihp.c b/hw/acpi/pcihp.c index 9dc4d3e2db..9634567e3a 100644 --- a/hw/acpi/pcihp.c +++ b/hw/acpi/pcihp.c @@ -347,7 +347,8 @@ static uint64_t pci_read(void *opaque, hwaddr addr, uns= igned int size) trace_acpi_pci_down_read(val); break; case PCI_EJ_BASE: - /* No feature defined yet */ + val =3D s->acpi_index; + s->acpi_index =3D 0; trace_acpi_pci_features_read(val); break; case PCI_RMV_BASE: @@ -367,8 +368,30 @@ static uint64_t pci_read(void *opaque, hwaddr addr, un= signed int size) static void pci_write(void *opaque, hwaddr addr, uint64_t data, unsigned int size) { + int slot; + PCIBus *bus; + BusChild *kid, *next; AcpiPciHpState *s =3D opaque; + + s->acpi_index =3D 0; switch (addr) { + case PCI_UP_BASE: + slot =3D ctz32(data); + + if (s->hotplug_select >=3D ACPI_PCIHP_MAX_HOTPLUG_BUS) { + break; + } + + bus =3D acpi_pcihp_find_hotplug_bus(s, s->hotplug_select); + QTAILQ_FOREACH_SAFE(kid, &bus->qbus.children, sibling, next) { + Object *o =3D OBJECT(kid->child); + PCIDevice *dev =3D PCI_DEVICE(o); + if (PCI_SLOT(dev->devfn) =3D=3D slot) { + s->acpi_index =3D object_property_get_uint(o, "acpi-index"= , NULL); + break; + } + } + break; case PCI_EJ_BASE: if (s->hotplug_select >=3D ACPI_PCIHP_MAX_HOTPLUG_BUS) { break; diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c index f18b71dea9..27d2958e25 100644 --- a/hw/i386/acpi-build.c +++ b/hw/i386/acpi-build.c @@ -1132,6 +1132,16 @@ static void build_piix4_pci_hotplug(Aml *table) aml_append(method, aml_return(aml_int(0))); aml_append(scope, method); =20 + method =3D aml_method("AIDX", 2, AML_NOTSERIALIZED); + aml_append(method, aml_acquire(aml_name("BLCK"), 0xFFFF)); + aml_append(method, aml_store(aml_arg(0), aml_name("BNUM"))); + aml_append(method, + aml_store(aml_shiftleft(aml_int(1), aml_arg(1)), aml_name("PCIU"))= ); + aml_append(method, aml_store(aml_name("B0EJ"), aml_local(0))); + aml_append(method, aml_release(aml_name("BLCK"))); + aml_append(method, aml_return(aml_local(0))); + aml_append(scope, method); + aml_append(table, scope); } =20 diff --git a/hw/pci/pci.c b/hw/pci/pci.c index d4349ea577..617f48ff3b 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -76,6 +76,7 @@ static Property pci_props[] =3D { QEMU_PCIE_EXTCAP_INIT_BITNR, true), DEFINE_PROP_STRING("failover_pair_id", PCIDevice, failover_pair_id), + DEFINE_PROP_UINT32("acpi-index", PCIDevice, acpi_index, -1), DEFINE_PROP_END_OF_LIST() }; =20 --=20 2.27.0