From nobody Wed Sep 10 05:59:23 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1757350598; cv=none; d=zohomail.com; s=zohoarc; b=Jnz2X9EIOx8Q1h/ZF9bQUMex6nca6/BK18PsKhg+TEMhDzfR1iD4/oAQdOFTXR7TZExV/mF7ui/xrAEh9MEas79mFo7xfgjnaRik6GjmMSwQHhktOXdh63U2LG/B58WN7nVdOqrwTlqE7vMEj8Ukzm9DrlHCEqb57++pGCw57K4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1757350598; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Unov/+9wCa1CgQRxZUAu5LOV2dzyHa5fZ7go7/hv/VU=; b=UccqcQG1d7a+GNyqUwik72ApG8ewDkkNSMBMFC4WvWKWHJjqq+F2Y3iaVd6AVdBmpMYtMqZDluYX0arIlwccS806H5wFRvtcv8f6YRu4E7k1YGxyk7NMAko4O1eb8lVVXVy4L/+ztn4aVe2Nv4yZOlftJes2EfPvFe9WZki6bhw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1757350598819456.8941902811936; Mon, 8 Sep 2025 09:56:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uvf9J-0007lI-Px; Mon, 08 Sep 2025 12:55:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uvf9H-0007hZ-8q for qemu-devel@nongnu.org; Mon, 08 Sep 2025 12:55:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uvf96-0001r3-NJ for qemu-devel@nongnu.org; Mon, 08 Sep 2025 12:55:22 -0400 Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-627-1Ds6UxzrN-CxxnD8aBDBuw-1; Mon, 08 Sep 2025 12:55:06 -0400 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CFC4018002C3; Mon, 8 Sep 2025 16:55:04 +0000 (UTC) Received: from corto.redhat.com (unknown [10.44.32.50]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3B6DB3000198; Mon, 8 Sep 2025 16:55:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1757350508; h=from:from: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; bh=Unov/+9wCa1CgQRxZUAu5LOV2dzyHa5fZ7go7/hv/VU=; b=WR01faMEVBY+izLoQnXFJwCuzhacQ2WtVmCQYVBm52ApiMBX5BFvygmv1/LwXcVh5YQvJZ kq5AKqRcGcw4oTaD+HJK4KtM0PslnpOz1+fmWmdzgH+v89VO/vZpS1RBLilrffROGd3U9w QMC76c3n5nysyU58/xqnb7FoXK+GCm4= X-MC-Unique: 1Ds6UxzrN-CxxnD8aBDBuw-1 X-Mimecast-MFC-AGG-ID: 1Ds6UxzrN-CxxnD8aBDBuw_1757350504 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: qemu-devel@nongnu.org Cc: Alex Williamson , Mark Cave-Ayland , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Subject: [PULL 25/31] vfio/pci.c: use QOM casts where appropriate Date: Mon, 8 Sep 2025 18:53:48 +0200 Message-ID: <20250908165354.1731444-26-clg@redhat.com> In-Reply-To: <20250908165354.1731444-1-clg@redhat.com> References: <20250908165354.1731444-1-clg@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=clg@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1757350599529116600 From: Mark Cave-Ayland Use QOM casts to convert between VFIOPCIDevice and PCIDevice instead of accessing pdev directly. Signed-off-by: Mark Cave-Ayland Reviewed-by: C=C3=A9dric Le Goater Link: https://lore.kernel.org/qemu-devel/20250715093110.107317-17-mark.cave= ayland@nutanix.com [ clg: Updated vfio_sub_page_bar_update_mappings() ] Signed-off-by: C=C3=A9dric Le Goater --- hw/vfio/pci.c | 204 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 121 insertions(+), 83 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 3fe5b03eb1160bb66fc4ae3942d14a2d71b4431a..052591d2c970a1668db390f31ea= 06cd90e6a420f 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -117,6 +117,7 @@ static void vfio_intx_mmap_enable(void *opaque) static void vfio_intx_interrupt(void *opaque) { VFIOPCIDevice *vdev =3D opaque; + PCIDevice *pdev =3D PCI_DEVICE(vdev); =20 if (!event_notifier_test_and_clear(&vdev->intx.interrupt)) { return; @@ -125,7 +126,7 @@ static void vfio_intx_interrupt(void *opaque) trace_vfio_intx_interrupt(vdev->vbasedev.name, 'A' + vdev->intx.pin); =20 vdev->intx.pending =3D true; - pci_irq_assert(&vdev->pdev); + pci_irq_assert(pdev); vfio_mmap_set_enabled(vdev, false); if (vdev->intx.mmap_timeout) { timer_mod(vdev->intx.mmap_timer, @@ -136,6 +137,7 @@ static void vfio_intx_interrupt(void *opaque) void vfio_pci_intx_eoi(VFIODevice *vbasedev) { VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + PCIDevice *pdev =3D PCI_DEVICE(vdev); =20 if (!vdev->intx.pending) { return; @@ -144,13 +146,14 @@ void vfio_pci_intx_eoi(VFIODevice *vbasedev) trace_vfio_pci_intx_eoi(vbasedev->name); =20 vdev->intx.pending =3D false; - pci_irq_deassert(&vdev->pdev); + pci_irq_deassert(pdev); vfio_device_irq_unmask(vbasedev, VFIO_PCI_INTX_IRQ_INDEX); } =20 static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, Error **errp) { #ifdef CONFIG_KVM + PCIDevice *pdev =3D PCI_DEVICE(vdev); int irq_fd =3D event_notifier_get_fd(&vdev->intx.interrupt); =20 if (vdev->no_kvm_intx || !kvm_irqfds_enabled() || @@ -163,7 +166,7 @@ static bool vfio_intx_enable_kvm(VFIOPCIDevice *vdev, E= rror **errp) qemu_set_fd_handler(irq_fd, NULL, NULL, vdev); vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); vdev->intx.pending =3D false; - pci_irq_deassert(&vdev->pdev); + pci_irq_deassert(pdev); =20 /* Get an eventfd for resample/unmask */ if (!vfio_notifier_init(vdev, &vdev->intx.unmask, "intx-unmask", 0, er= rp)) { @@ -241,6 +244,8 @@ static bool vfio_cpr_intx_enable_kvm(VFIOPCIDevice *vde= v, Error **errp) static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) { #ifdef CONFIG_KVM + PCIDevice *pdev =3D PCI_DEVICE(vdev); + if (!vdev->intx.kvm_accel) { return; } @@ -251,7 +256,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) */ vfio_device_irq_mask(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); vdev->intx.pending =3D false; - pci_irq_deassert(&vdev->pdev); + pci_irq_deassert(pdev); =20 /* Tell KVM to stop listening for an INTx irqfd */ if (kvm_irqchip_remove_irqfd_notifier_gsi(kvm_state, &vdev->intx.inter= rupt, @@ -307,7 +312,7 @@ static void vfio_intx_routing_notifier(PCIDevice *pdev) return; } =20 - route =3D pci_device_route_intx_to_irq(&vdev->pdev, vdev->intx.pin); + route =3D pci_device_route_intx_to_irq(pdev, vdev->intx.pin); =20 if (pci_intx_route_changed(&vdev->intx.route, &route)) { vfio_intx_update(vdev, &route); @@ -324,7 +329,8 @@ static void vfio_irqchip_change(Notifier *notify, void = *data) =20 static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error **errp) { - uint8_t pin =3D vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1= ); + PCIDevice *pdev =3D PCI_DEVICE(vdev); + uint8_t pin =3D vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1); Error *err =3D NULL; int32_t fd; =20 @@ -342,7 +348,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) } =20 vdev->intx.pin =3D pin - 1; /* Pin A (1) -> irq[0] */ - pci_config_set_interrupt_pin(vdev->pdev.config, pin); + pci_config_set_interrupt_pin(pdev->config, pin); =20 #ifdef CONFIG_KVM /* @@ -350,7 +356,7 @@ static bool vfio_intx_enable(VFIOPCIDevice *vdev, Error= **errp) * where we won't actually use the result anyway. */ if (kvm_irqfds_enabled() && kvm_resamplefds_enabled()) { - vdev->intx.route =3D pci_device_route_intx_to_irq(&vdev->pdev, + vdev->intx.route =3D pci_device_route_intx_to_irq(pdev, vdev->intx.pin); } #endif @@ -390,13 +396,14 @@ skip_signaling: =20 static void vfio_intx_disable(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); int fd; =20 timer_del(vdev->intx.mmap_timer); vfio_intx_disable_kvm(vdev); vfio_device_irq_disable(&vdev->vbasedev, VFIO_PCI_INTX_IRQ_INDEX); vdev->intx.pending =3D false; - pci_irq_deassert(&vdev->pdev); + pci_irq_deassert(pdev); vfio_mmap_set_enabled(vdev, true); =20 fd =3D event_notifier_get_fd(&vdev->intx.interrupt); @@ -428,6 +435,7 @@ static void vfio_msi_interrupt(void *opaque) { VFIOMSIVector *vector =3D opaque; VFIOPCIDevice *vdev =3D vector->vdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); MSIMessage (*get_msg)(PCIDevice *dev, unsigned vector); void (*notify)(PCIDevice *dev, unsigned vector); MSIMessage msg; @@ -442,9 +450,9 @@ static void vfio_msi_interrupt(void *opaque) notify =3D msix_notify; =20 /* A masked vector firing needs to use the PBA, enable it */ - if (msix_is_masked(&vdev->pdev, nr)) { + if (msix_is_masked(pdev, nr)) { set_bit(nr, vdev->msix->pending); - memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, true); + memory_region_set_enabled(&pdev->msix_pba_mmio, true); trace_vfio_msix_pba_enable(vdev->vbasedev.name); } } else if (vdev->interrupt =3D=3D VFIO_INT_MSI) { @@ -454,9 +462,9 @@ static void vfio_msi_interrupt(void *opaque) abort(); } =20 - msg =3D get_msg(&vdev->pdev, nr); + msg =3D get_msg(pdev, nr); trace_vfio_msi_interrupt(vdev->vbasedev.name, nr, msg.address, msg.dat= a); - notify(&vdev->pdev, nr); + notify(pdev, nr); } =20 void vfio_pci_msi_set_handler(VFIOPCIDevice *vdev, int nr, bool enable) @@ -495,6 +503,7 @@ static int vfio_enable_msix_no_vec(VFIOPCIDevice *vdev) =20 static int vfio_enable_vectors(VFIOPCIDevice *vdev, bool msix) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); struct vfio_irq_set *irq_set; int ret =3D 0, i, argsz; int32_t *fds; @@ -537,7 +546,7 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, boo= l msix) */ if (vdev->msi_vectors[i].use) { if (vdev->msi_vectors[i].virq < 0 || - (msix && msix_is_masked(&vdev->pdev, i))) { + (msix && msix_is_masked(pdev, i))) { fd =3D event_notifier_get_fd(&vdev->msi_vectors[i].interru= pt); } else { fd =3D event_notifier_get_fd(&vdev->msi_vectors[i].kvm_int= errupt); @@ -557,12 +566,14 @@ static int vfio_enable_vectors(VFIOPCIDevice *vdev, b= ool msix) void vfio_pci_add_kvm_msi_virq(VFIOPCIDevice *vdev, VFIOMSIVector *vector, int vector_n, bool msix) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); + if ((msix && vdev->no_kvm_msix) || (!msix && vdev->no_kvm_msi)) { return; } =20 vector->virq =3D kvm_irqchip_add_msi_route(&vfio_route_change, - vector_n, &vdev->pdev); + vector_n, pdev); } =20 static void vfio_connect_kvm_msi_virq(VFIOMSIVector *vector, int nr) @@ -631,7 +642,7 @@ static void set_irq_signalling(VFIODevice *vbasedev, VF= IOMSIVector *vector, void vfio_pci_vector_init(VFIOPCIDevice *vdev, int nr) { VFIOMSIVector *vector =3D &vdev->msi_vectors[nr]; - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); Error *local_err =3D NULL; =20 vector->vdev =3D vdev; @@ -720,7 +731,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, uns= igned int nr, clear_bit(nr, vdev->msix->pending); if (find_first_bit(vdev->msix->pending, vdev->nr_vectors) =3D=3D vdev->nr_vectors) { - memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false); + memory_region_set_enabled(&pdev->msix_pba_mmio, false); trace_vfio_msix_pba_disable(vdev->vbasedev.name); } =20 @@ -771,7 +782,9 @@ static void vfio_msix_vector_release(PCIDevice *pdev, u= nsigned int nr) =20 void vfio_pci_msix_set_notifiers(VFIOPCIDevice *vdev) { - msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use, + PCIDevice *pdev =3D PCI_DEVICE(vdev); + + msix_set_vector_notifiers(pdev, vfio_msix_vector_use, vfio_msix_vector_release, NULL); } =20 @@ -798,6 +811,7 @@ void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *= vdev) =20 static void vfio_msix_enable(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); int ret; =20 vfio_disable_interrupts(vdev); @@ -814,7 +828,7 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev) */ vfio_pci_prepare_kvm_msi_virq_batch(vdev); =20 - if (msix_set_vector_notifiers(&vdev->pdev, vfio_msix_vector_use, + if (msix_set_vector_notifiers(pdev, vfio_msix_vector_use, vfio_msix_vector_release, NULL)) { error_report("vfio: msix_set_vector_notifiers failed"); } @@ -852,11 +866,12 @@ static void vfio_msix_enable(VFIOPCIDevice *vdev) =20 static void vfio_msi_enable(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); int ret, i; =20 vfio_disable_interrupts(vdev); =20 - vdev->nr_vectors =3D msi_nr_vectors_allocated(&vdev->pdev); + vdev->nr_vectors =3D msi_nr_vectors_allocated(pdev); retry: /* * Setting vector notifiers needs to enable route for each vector. @@ -949,10 +964,11 @@ static void vfio_msi_disable_common(VFIOPCIDevice *vd= ev) =20 static void vfio_msix_disable(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); Error *err =3D NULL; int i; =20 - msix_unset_vector_notifiers(&vdev->pdev); + msix_unset_vector_notifiers(pdev); =20 /* * MSI-X will only release vectors if MSI-X is still enabled on the @@ -960,8 +976,8 @@ static void vfio_msix_disable(VFIOPCIDevice *vdev) */ for (i =3D 0; i < vdev->nr_vectors; i++) { if (vdev->msi_vectors[i].use) { - vfio_msix_vector_release(&vdev->pdev, i); - msix_vector_unuse(&vdev->pdev, i); + vfio_msix_vector_release(pdev, i); + msix_vector_unuse(pdev, i); } } =20 @@ -998,6 +1014,7 @@ static void vfio_msi_disable(VFIOPCIDevice *vdev) =20 static void vfio_update_msi(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); int i; =20 for (i =3D 0; i < vdev->nr_vectors; i++) { @@ -1008,8 +1025,8 @@ static void vfio_update_msi(VFIOPCIDevice *vdev) continue; } =20 - msg =3D msi_get_message(&vdev->pdev, i); - vfio_update_kvm_msi_virq(vector, msg, &vdev->pdev); + msg =3D msi_get_message(pdev, i); + vfio_update_kvm_msi_virq(vector, msg, pdev); } } =20 @@ -1171,13 +1188,14 @@ static const MemoryRegionOps vfio_rom_ops =3D { =20 static void vfio_pci_size_rom(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); VFIODevice *vbasedev =3D &vdev->vbasedev; uint32_t orig, size =3D cpu_to_le32((uint32_t)PCI_ROM_ADDRESS_MASK); char *name; =20 - if (vdev->pdev.romfile || !vdev->pdev.rom_bar) { + if (pdev->romfile || !pdev->rom_bar) { /* Since pci handles romfile, just print a message and return */ - if (vfio_opt_rom_in_denylist(vdev) && vdev->pdev.romfile) { + if (vfio_opt_rom_in_denylist(vdev) && pdev->romfile) { warn_report("Device at %s is known to cause system instability" " issues during option rom execution", vdev->vbasedev.name); @@ -1206,7 +1224,7 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) } =20 if (vfio_opt_rom_in_denylist(vdev)) { - if (vdev->pdev.rom_bar > 0) { + if (pdev->rom_bar > 0) { warn_report("Device at %s is known to cause system instability" " issues during option rom execution", vdev->vbasedev.name); @@ -1225,12 +1243,12 @@ static void vfio_pci_size_rom(VFIOPCIDevice *vdev) =20 name =3D g_strdup_printf("vfio[%s].rom", vdev->vbasedev.name); =20 - memory_region_init_io(&vdev->pdev.rom, OBJECT(vdev), + memory_region_init_io(&pdev->rom, OBJECT(vdev), &vfio_rom_ops, vdev, name, size); g_free(name); =20 - pci_register_bar(&vdev->pdev, PCI_ROM_SLOT, - PCI_BASE_ADDRESS_SPACE_MEMORY, &vdev->pdev.rom); + pci_register_bar(pdev, PCI_ROM_SLOT, + PCI_BASE_ADDRESS_SPACE_MEMORY, &pdev->rom); =20 vdev->rom_read_failed =3D false; } @@ -1503,6 +1521,7 @@ static void vfio_disable_interrupts(VFIOPCIDevice *vd= ev) =20 static bool vfio_msi_setup(VFIOPCIDevice *vdev, int pos, Error **errp) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); uint16_t ctrl; bool msi_64bit, msi_maskbit; int ret, entries; @@ -1523,7 +1542,7 @@ static bool vfio_msi_setup(VFIOPCIDevice *vdev, int p= os, Error **errp) =20 trace_vfio_msi_setup(vdev->vbasedev.name, pos); =20 - ret =3D msi_init(&vdev->pdev, pos, entries, msi_64bit, msi_maskbit, &e= rr); + ret =3D msi_init(pdev, pos, entries, msi_64bit, msi_maskbit, &err); if (ret < 0) { if (ret =3D=3D -ENOTSUP) { return true; @@ -1716,6 +1735,7 @@ static bool vfio_pci_relocate_msix(VFIOPCIDevice *vde= v, Error **errp) */ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev, Error **errp) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); uint8_t pos; uint16_t ctrl; uint32_t table, pba; @@ -1723,7 +1743,7 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vdev= , Error **errp) VFIOMSIXInfo *msix; int ret; =20 - pos =3D pci_find_capability(&vdev->pdev, PCI_CAP_ID_MSIX); + pos =3D pci_find_capability(pdev, PCI_CAP_ID_MSIX); if (!pos) { return true; } @@ -1815,12 +1835,13 @@ static bool vfio_msix_early_setup(VFIOPCIDevice *vd= ev, Error **errp) =20 static bool vfio_msix_setup(VFIOPCIDevice *vdev, int pos, Error **errp) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); int ret; Error *err =3D NULL; =20 vdev->msix->pending =3D g_new0(unsigned long, BITS_TO_LONGS(vdev->msix->entries)); - ret =3D msix_init(&vdev->pdev, vdev->msix->entries, + ret =3D msix_init(pdev, vdev->msix->entries, vdev->bars[vdev->msix->table_bar].mr, vdev->msix->table_bar, vdev->msix->table_offset, vdev->bars[vdev->msix->pba_bar].mr, @@ -1852,7 +1873,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int = pos, Error **errp) * vector-use notifier is called, which occurs on unmask, we test whet= her * PBA emulation is needed and again disable if not. */ - memory_region_set_enabled(&vdev->pdev.msix_pba_mmio, false); + memory_region_set_enabled(&pdev->msix_pba_mmio, false); =20 /* * The emulated machine may provide a paravirt interface for MSIX setup @@ -1864,7 +1885,7 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, int = pos, Error **errp) */ if (object_property_get_bool(OBJECT(qdev_get_machine()), "vfio-no-msix-emulation", NULL)) { - memory_region_set_enabled(&vdev->pdev.msix_table_mmio, false); + memory_region_set_enabled(&pdev->msix_table_mmio, false); } =20 return true; @@ -1872,10 +1893,12 @@ static bool vfio_msix_setup(VFIOPCIDevice *vdev, in= t pos, Error **errp) =20 void vfio_pci_teardown_msi(VFIOPCIDevice *vdev) { - msi_uninit(&vdev->pdev); + PCIDevice *pdev =3D PCI_DEVICE(vdev); + + msi_uninit(pdev); =20 if (vdev->msix) { - msix_uninit(&vdev->pdev, + msix_uninit(pdev, vdev->bars[vdev->msix->table_bar].mr, vdev->bars[vdev->msix->pba_bar].mr); g_free(vdev->msix->pending); @@ -1936,6 +1959,7 @@ static void vfio_bars_prepare(VFIOPCIDevice *vdev) =20 static void vfio_bar_register(VFIOPCIDevice *vdev, int nr) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); VFIOBAR *bar =3D &vdev->bars[nr]; char *name; =20 @@ -1957,7 +1981,7 @@ static void vfio_bar_register(VFIOPCIDevice *vdev, in= t nr) } } =20 - pci_register_bar(&vdev->pdev, nr, bar->type, bar->mr); + pci_register_bar(pdev, nr, bar->type, bar->mr); } =20 static void vfio_bars_register(VFIOPCIDevice *vdev) @@ -1971,6 +1995,7 @@ static void vfio_bars_register(VFIOPCIDevice *vdev) =20 void vfio_pci_bars_exit(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); int i; =20 for (i =3D 0; i < PCI_ROM_SLOT; i++) { @@ -1984,7 +2009,7 @@ void vfio_pci_bars_exit(VFIOPCIDevice *vdev) } =20 if (vdev->vga) { - pci_unregister_vga(&vdev->pdev); + pci_unregister_vga(pdev); vfio_vga_quirk_exit(vdev); } } @@ -2056,8 +2081,10 @@ static void vfio_set_word_bits(uint8_t *buf, uint16_= t val, uint16_t mask) static void vfio_add_emulated_word(VFIOPCIDevice *vdev, int pos, uint16_t val, uint16_t mask) { - vfio_set_word_bits(vdev->pdev.config + pos, val, mask); - vfio_set_word_bits(vdev->pdev.wmask + pos, ~mask, mask); + PCIDevice *pdev =3D PCI_DEVICE(vdev); + + vfio_set_word_bits(pdev->config + pos, val, mask); + vfio_set_word_bits(pdev->wmask + pos, ~mask, mask); vfio_set_word_bits(vdev->emulated_config_bits + pos, mask, mask); } =20 @@ -2069,8 +2096,10 @@ static void vfio_set_long_bits(uint8_t *buf, uint32_= t val, uint32_t mask) static void vfio_add_emulated_long(VFIOPCIDevice *vdev, int pos, uint32_t val, uint32_t mask) { - vfio_set_long_bits(vdev->pdev.config + pos, val, mask); - vfio_set_long_bits(vdev->pdev.wmask + pos, ~mask, mask); + PCIDevice *pdev =3D PCI_DEVICE(vdev); + + vfio_set_long_bits(pdev->config + pos, val, mask); + vfio_set_long_bits(pdev->wmask + pos, ~mask, mask); vfio_set_long_bits(vdev->emulated_config_bits + pos, mask, mask); } =20 @@ -2078,7 +2107,8 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice = *vdev) { struct vfio_device_info_cap_pci_atomic_comp *cap; g_autofree struct vfio_device_info *info =3D NULL; - PCIBus *bus =3D pci_get_bus(&vdev->pdev); + PCIDevice *pdev =3D PCI_DEVICE(vdev); + PCIBus *bus =3D pci_get_bus(pdev); PCIDevice *parent =3D bus->parent_dev; struct vfio_info_cap_header *hdr; uint32_t mask =3D 0; @@ -2094,8 +2124,8 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice = *vdev) if (pci_bus_is_root(bus) || !parent || !parent->exp.exp_cap || pcie_cap_get_type(parent) !=3D PCI_EXP_TYPE_ROOT_PORT || pcie_cap_get_version(parent) !=3D PCI_EXP_FLAGS_VER2 || - vdev->pdev.devfn || - vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) { + pdev->devfn || + pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) { return; } =20 @@ -2139,8 +2169,10 @@ static void vfio_pci_enable_rp_atomics(VFIOPCIDevice= *vdev) =20 static void vfio_pci_disable_rp_atomics(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); + if (vdev->clear_parent_atomics_on_exit) { - PCIDevice *parent =3D pci_get_bus(&vdev->pdev)->parent_dev; + PCIDevice *parent =3D pci_get_bus(pdev)->parent_dev; uint8_t *pos =3D parent->config + parent->exp.exp_cap + PCI_EXP_DE= VCAP2; =20 pci_long_test_and_clear_mask(pos, PCI_EXP_DEVCAP2_ATOMIC_COMP32 | @@ -2152,10 +2184,11 @@ static void vfio_pci_disable_rp_atomics(VFIOPCIDevi= ce *vdev) static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, int pos, uint8_t size, Error **errp) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); uint16_t flags; uint8_t type; =20 - flags =3D pci_get_word(vdev->pdev.config + pos + PCI_CAP_FLAGS); + flags =3D pci_get_word(pdev->config + pos + PCI_CAP_FLAGS); type =3D (flags & PCI_EXP_FLAGS_TYPE) >> 4; =20 if (type !=3D PCI_EXP_TYPE_ENDPOINT && @@ -2167,8 +2200,8 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, = int pos, uint8_t size, return false; } =20 - if (!pci_bus_is_express(pci_get_bus(&vdev->pdev))) { - PCIBus *bus =3D pci_get_bus(&vdev->pdev); + if (!pci_bus_is_express(pci_get_bus(pdev))) { + PCIBus *bus =3D pci_get_bus(pdev); PCIDevice *bridge; =20 /* @@ -2200,7 +2233,7 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev, = int pos, uint8_t size, return true; } =20 - } else if (pci_bus_is_root(pci_get_bus(&vdev->pdev))) { + } else if (pci_bus_is_root(pci_get_bus(pdev))) { /* * On a Root Complex bus Endpoints become Root Complex Integrated * Endpoints, which changes the type and clears the LNK & LNK2 fie= lds. @@ -2268,20 +2301,20 @@ static bool vfio_setup_pcie_cap(VFIOPCIDevice *vdev= , int pos, uint8_t size, 1, PCI_EXP_FLAGS_VERS); } =20 - pos =3D pci_add_capability(&vdev->pdev, PCI_CAP_ID_EXP, pos, size, - errp); + pos =3D pci_add_capability(pdev, PCI_CAP_ID_EXP, pos, size, errp); if (pos < 0) { return false; } =20 - vdev->pdev.exp.exp_cap =3D pos; + pdev->exp.exp_cap =3D pos; =20 return true; } =20 static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, uint8_t pos) { - uint32_t cap =3D pci_get_long(vdev->pdev.config + pos + PCI_EXP_DEVCAP= ); + PCIDevice *pdev =3D PCI_DEVICE(vdev); + uint32_t cap =3D pci_get_long(pdev->config + pos + PCI_EXP_DEVCAP); =20 if (cap & PCI_EXP_DEVCAP_FLR) { trace_vfio_check_pcie_flr(vdev->vbasedev.name); @@ -2291,7 +2324,8 @@ static void vfio_check_pcie_flr(VFIOPCIDevice *vdev, = uint8_t pos) =20 static void vfio_check_pm_reset(VFIOPCIDevice *vdev, uint8_t pos) { - uint16_t csr =3D pci_get_word(vdev->pdev.config + pos + PCI_PM_CTRL); + PCIDevice *pdev =3D PCI_DEVICE(vdev); + uint16_t csr =3D pci_get_word(pdev->config + pos + PCI_PM_CTRL); =20 if (!(csr & PCI_PM_CTRL_NO_SOFT_RESET)) { trace_vfio_check_pm_reset(vdev->vbasedev.name); @@ -2301,7 +2335,8 @@ static void vfio_check_pm_reset(VFIOPCIDevice *vdev, = uint8_t pos) =20 static void vfio_check_af_flr(VFIOPCIDevice *vdev, uint8_t pos) { - uint8_t cap =3D pci_get_byte(vdev->pdev.config + pos + PCI_AF_CAP); + PCIDevice *pdev =3D PCI_DEVICE(vdev); + uint8_t cap =3D pci_get_byte(pdev->config + pos + PCI_AF_CAP); =20 if ((cap & PCI_AF_CAP_TP) && (cap & PCI_AF_CAP_FLR)) { trace_vfio_check_af_flr(vdev->vbasedev.name); @@ -2312,7 +2347,7 @@ static void vfio_check_af_flr(VFIOPCIDevice *vdev, ui= nt8_t pos) static bool vfio_add_vendor_specific_cap(VFIOPCIDevice *vdev, int pos, uint8_t size, Error **errp) { - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); =20 pos =3D pci_add_capability(pdev, PCI_CAP_ID_VNDR, pos, size, errp); if (pos < 0) { @@ -2334,7 +2369,7 @@ static bool vfio_add_vendor_specific_cap(VFIOPCIDevic= e *vdev, int pos, static bool vfio_add_std_cap(VFIOPCIDevice *vdev, uint8_t pos, Error **err= p) { ERRP_GUARD(); - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); uint8_t cap_id, next, size; bool ret; =20 @@ -2420,17 +2455,18 @@ static bool vfio_add_std_cap(VFIOPCIDevice *vdev, u= int8_t pos, Error **errp) =20 static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev, uint16_t pos) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); uint32_t ctrl; int i, nbar; =20 - ctrl =3D pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL); + ctrl =3D pci_get_long(pdev->config + pos + PCI_REBAR_CTRL); nbar =3D (ctrl & PCI_REBAR_CTRL_NBAR_MASK) >> PCI_REBAR_CTRL_NBAR_SHIF= T; =20 for (i =3D 0; i < nbar; i++) { uint32_t cap; int size; =20 - ctrl =3D pci_get_long(vdev->pdev.config + pos + PCI_REBAR_CTRL + (= i * 8)); + ctrl =3D pci_get_long(pdev->config + pos + PCI_REBAR_CTRL + (i * 8= )); size =3D (ctrl & PCI_REBAR_CTRL_BAR_SIZE) >> PCI_REBAR_CTRL_BAR_SH= IFT; =20 /* The cap register reports sizes 1MB to 128TB, with 4 reserved bi= ts */ @@ -2468,7 +2504,7 @@ static int vfio_setup_rebar_ecap(VFIOPCIDevice *vdev,= uint16_t pos) =20 static void vfio_add_ext_cap(VFIOPCIDevice *vdev) { - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); uint32_t header; uint16_t cap_id, next, size; uint8_t cap_ver; @@ -2562,7 +2598,7 @@ static void vfio_add_ext_cap(VFIOPCIDevice *vdev) =20 bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp) { - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); =20 if (!(pdev->config[PCI_STATUS] & PCI_STATUS_CAP_LIST) || !pdev->config[PCI_CAPABILITY_LIST]) { @@ -2579,7 +2615,7 @@ bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, E= rror **errp) =20 void vfio_pci_pre_reset(VFIOPCIDevice *vdev) { - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); uint16_t cmd; =20 vfio_disable_interrupts(vdev); @@ -2796,7 +2832,7 @@ static int vfio_pci_save_config(VFIODevice *vbasedev,= QEMUFile *f, Error **errp) static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) { VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); pcibus_t old_addr[PCI_NUM_REGIONS - 1]; int bar, ret; =20 @@ -2844,7 +2880,7 @@ VFIOPCIDevice *vfio_pci_from_vfio_device(VFIODevice *= vbasedev) =20 void vfio_sub_page_bar_update_mappings(VFIOPCIDevice *vdev) { - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); int page_size =3D qemu_real_host_page_size(); int bar; =20 @@ -2928,6 +2964,7 @@ bool vfio_populate_vga(VFIOPCIDevice *vdev, Error **e= rrp) =20 bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); VFIODevice *vbasedev =3D &vdev->vbasedev; struct vfio_region_info *reg_info =3D NULL; struct vfio_irq_info irq_info; @@ -2979,7 +3016,7 @@ bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Er= ror **errp) =20 vdev->config_size =3D reg_info->size; if (vdev->config_size =3D=3D PCI_CONFIG_SPACE_SIZE) { - vdev->pdev.cap_present &=3D ~QEMU_PCI_CAP_EXPRESS; + pdev->cap_present &=3D ~QEMU_PCI_CAP_EXPRESS; } vdev->config_offset =3D reg_info->offset; =20 @@ -3183,25 +3220,26 @@ static void vfio_unregister_req_notifier(VFIOPCIDev= ice *vdev) =20 void vfio_pci_config_register_vga(VFIOPCIDevice *vdev) { + PCIDevice *pdev =3D PCI_DEVICE(vdev); assert(vdev->vga !=3D NULL); =20 - pci_register_vga(&vdev->pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem, + pci_register_vga(pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem, &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem, &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem); } =20 bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp) { - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); VFIODevice *vbasedev =3D &vdev->vbasedev; uint32_t config_space_size; int ret; =20 - config_space_size =3D MIN(pci_config_size(&vdev->pdev), vdev->config_s= ize); + config_space_size =3D MIN(pci_config_size(pdev), vdev->config_size); =20 /* Get a copy of config space */ ret =3D vfio_pci_config_space_read(vdev, 0, config_space_size, - vdev->pdev.config); + pdev->config); if (ret < (int)config_space_size) { ret =3D ret < 0 ? -ret : EFAULT; error_setg_errno(errp, ret, "failed to read device config space"); @@ -3286,10 +3324,10 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Err= or **errp) PCI_HEADER_TYPE_MULTI_FUNCTI= ON; =20 /* Restore or clear multifunction, this is always controlled by QEMU */ - if (vdev->pdev.cap_present & QEMU_PCI_CAP_MULTIFUNCTION) { - vdev->pdev.config[PCI_HEADER_TYPE] |=3D PCI_HEADER_TYPE_MULTI_FUNC= TION; + if (pdev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) { + pdev->config[PCI_HEADER_TYPE] |=3D PCI_HEADER_TYPE_MULTI_FUNCTION; } else { - vdev->pdev.config[PCI_HEADER_TYPE] &=3D ~PCI_HEADER_TYPE_MULTI_FUN= CTION; + pdev->config[PCI_HEADER_TYPE] &=3D ~PCI_HEADER_TYPE_MULTI_FUNCTION; } =20 /* @@ -3297,8 +3335,8 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error= **errp) * BAR, such as might be the case with the option ROM, we can get * confusing, unwritable, residual addresses from the host here. */ - memset(&vdev->pdev.config[PCI_BASE_ADDRESS_0], 0, 24); - memset(&vdev->pdev.config[PCI_ROM_ADDRESS], 0, 4); + memset(&pdev->config[PCI_BASE_ADDRESS_0], 0, 24); + memset(&pdev->config[PCI_ROM_ADDRESS], 0, 4); =20 vfio_pci_size_rom(vdev); =20 @@ -3319,7 +3357,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error= **errp) =20 bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp) { - PCIDevice *pdev =3D &vdev->pdev; + PCIDevice *pdev =3D PCI_DEVICE(vdev); =20 /* QEMU emulates all of MSI & MSIX */ if (pdev->cap_present & QEMU_PCI_CAP_MSIX) { @@ -3332,10 +3370,10 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, = Error **errp) vdev->msi_cap_size); } =20 - if (vfio_pci_read_config(&vdev->pdev, PCI_INTERRUPT_PIN, 1)) { + if (vfio_pci_read_config(pdev, PCI_INTERRUPT_PIN, 1)) { vdev->intx.mmap_timer =3D timer_new_ms(QEMU_CLOCK_VIRTUAL, vfio_intx_mmap_enable, vdev); - pci_device_set_intx_routing_notifier(&vdev->pdev, + pci_device_set_intx_routing_notifier(pdev, vfio_intx_routing_notifier); vdev->irqchip_change_notifier.notify =3D vfio_irqchip_change; kvm_irqchip_add_change_notifier(&vdev->irqchip_change_notifier); @@ -3347,7 +3385,7 @@ bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Er= ror **errp) */ if (!cpr_is_incoming() && !vfio_intx_enable(vdev, errp)) { timer_free(vdev->intx.mmap_timer); - pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); + pci_device_set_intx_routing_notifier(pdev, NULL); kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notif= ier); return false; } @@ -3498,7 +3536,7 @@ out_deregister: if (vdev->interrupt =3D=3D VFIO_INT_INTx) { vfio_intx_disable(vdev); } - pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); + pci_device_set_intx_routing_notifier(pdev, NULL); if (vdev->irqchip_change_notifier.notify) { kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier); } @@ -3530,7 +3568,7 @@ static void vfio_exitfn(PCIDevice *pdev) =20 vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); - pci_device_set_intx_routing_notifier(&vdev->pdev, NULL); + pci_device_set_intx_routing_notifier(pdev, NULL); if (vdev->irqchip_change_notifier.notify) { kvm_irqchip_remove_change_notifier(&vdev->irqchip_change_notifier); } --=20 2.51.0