From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH 2/2] pci-assign: Use pci_device_set_intx_routing_notifier Date: Fri, 03 Aug 2012 19:04:12 +0200 Message-ID: <501C048C.5000600@web.de> References: <501BAD29.6080102@web.de> <501BAD72.4020105@web.de> <1344008134.8003.34.camel@ul30vt> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig093390E54FF1301DD5597300" Cc: Avi Kivity , Marcelo Tosatti , kvm To: Alex Williamson Return-path: Received: from mout.web.de ([212.227.17.11]:56844 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751432Ab2HCREU (ORCPT ); Fri, 3 Aug 2012 13:04:20 -0400 In-Reply-To: <1344008134.8003.34.camel@ul30vt> Sender: kvm-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig093390E54FF1301DD5597300 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 2012-08-03 17:35, Alex Williamson wrote: > On Fri, 2012-08-03 at 12:52 +0200, Jan Kiszka wrote: >> From: Jan Kiszka >> >> Replace the hack in pci_default_write_config with upstream's generic >> callback mechanism to get informed about changes on the PCI INTx >> routing. >> >> Signed-off-by: Jan Kiszka >> --- >> hw/Makefile.objs | 3 +-- >> hw/device-assignment.c | 48 ++++++++++++++++-----------------------= --------- >> hw/device-assignment.h | 33 --------------------------------- >> hw/pc.h | 3 --- >> hw/pci.c | 11 ----------- >> hw/piix_pci.c | 3 --- >> 6 files changed, 17 insertions(+), 84 deletions(-) >> delete mode 100644 hw/device-assignment.h >> >> diff --git a/hw/Makefile.objs b/hw/Makefile.objs >> index 30f9ba6..fa8bb08 100644 >> --- a/hw/Makefile.objs >> +++ b/hw/Makefile.objs >> @@ -3,7 +3,7 @@ hw-obj-y +=3D loader.o >> hw-obj-$(CONFIG_VIRTIO) +=3D virtio-console.o >> hw-obj-$(CONFIG_VIRTIO_PCI) +=3D virtio-pci.o >> hw-obj-y +=3D fw_cfg.o >> -hw-obj-$(CONFIG_PCI) +=3D pci_bridge.o pci_bridge_dev.o >> +hw-obj-$(CONFIG_PCI) +=3D pci.o pci_bridge.o pci_bridge_dev.o >> hw-obj-$(CONFIG_PCI) +=3D msix.o msi.o >> hw-obj-$(CONFIG_PCI) +=3D shpc.o >> hw-obj-$(CONFIG_PCI) +=3D slotid_cap.o >> @@ -164,7 +164,6 @@ obj-$(CONFIG_SOFTMMU) +=3D vhost_net.o >> obj-$(CONFIG_VHOST_NET) +=3D vhost.o >> obj-$(CONFIG_REALLY_VIRTFS) +=3D 9pfs/ >> obj-$(CONFIG_NO_PCI) +=3D pci-stub.o >> -obj-$(CONFIG_PCI) +=3D pci.o >> obj-$(CONFIG_VGA) +=3D vga.o >> obj-$(CONFIG_SOFTMMU) +=3D device-hotplug.o >> obj-$(CONFIG_XEN) +=3D xen_domainbuild.o xen_machine_pv.o >> diff --git a/hw/device-assignment.c b/hw/device-assignment.c >> index d14c327..7a90027 100644 >> --- a/hw/device-assignment.c >> +++ b/hw/device-assignment.c >> @@ -36,7 +36,6 @@ >> #include "pc.h" >> #include "qemu-error.h" >> #include "console.h" >> -#include "device-assignment.h" >> #include "loader.h" >> #include "monitor.h" >> #include "range.h" >> @@ -143,6 +142,8 @@ typedef struct AssignedDevice { >> QLIST_ENTRY(AssignedDevice) next; >> } AssignedDevice; >> =20 >> +static void assigned_dev_update_irq_routing(PCIDevice *dev); >> + >> static void assigned_dev_load_option_rom(AssignedDevice *dev); >> =20 >> static void assigned_dev_unregister_msix_mmio(AssignedDevice *dev); >> @@ -869,8 +870,13 @@ static int assign_irq(AssignedDevice *dev) >> int r =3D 0; >> =20 >> /* Interrupt PIN 0 means don't use INTx */ >> - if (assigned_dev_pci_read_byte(&dev->dev, PCI_INTERRUPT_PIN) =3D=3D= 0) >> + if (assigned_dev_pci_read_byte(&dev->dev, PCI_INTERRUPT_PIN) =3D=3D= 0) { >> + pci_device_set_intx_routing_notifier(&dev->dev, NULL); >> return 0; >> + } >> + >> + pci_device_set_intx_routing_notifier(&dev->dev, >> + assigned_dev_update_irq_rout= ing); >> =20 >> intx_route =3D pci_device_route_intx_to_irq(&dev->dev, 0); >> assert(intx_route.mode !=3D PCI_INTX_INVERTED); >> @@ -944,43 +950,19 @@ static void deassign_device(AssignedDevice *dev)= >> dev->dev.qdev.id, strerror(-r)); >> } >> =20 >> -#if 0 >> -AssignedDevInfo *get_assigned_device(int pcibus, int slot) >> -{ >> - AssignedDevice *assigned_dev =3D NULL; >> - AssignedDevInfo *adev =3D NULL; >> - >> - QLIST_FOREACH(adev, &adev_head, next) { >> - assigned_dev =3D adev->assigned_dev; >> - if (pci_bus_num(assigned_dev->dev.bus) =3D=3D pcibus && >> - PCI_SLOT(assigned_dev->dev.devfn) =3D=3D slot) >> - return adev; >> - } >> - >> - return NULL; >> -} >> -#endif >> - >> /* The pci config space got updated. Check if irq numbers have change= d >> * for our devices >> */ >> -void assigned_dev_update_irqs(void) >> +static void assigned_dev_update_irq_routing(PCIDevice *dev) >> { >> - AssignedDevice *dev, *next; >> + AssignedDevice *assigned_dev =3D DO_UPCAST(AssignedDevice, dev, d= ev); >> Error *err =3D NULL; >> int r; >> =20 >> - dev =3D QLIST_FIRST(&devs); >> - while (dev) { >> - next =3D QLIST_NEXT(dev, next); >> - if (dev->irq_requested_type & KVM_DEV_IRQ_HOST_INTX) { >> - r =3D assign_irq(dev); >> - if (r < 0) { >> - qdev_unplug(&dev->dev.qdev, &err); >> - assert(!err); >> - } >> - } >> - dev =3D next; >> + r =3D assign_irq(assigned_dev); >> + if (r < 0) { >> + qdev_unplug(&dev->qdev, &err); >> + assert(!err); >> } >> } >> =20 >> @@ -1009,6 +991,7 @@ static void assigned_dev_update_msi(PCIDevice *pc= i_dev) >> perror("assigned_dev_update_msi: deassign irq"); >> =20 >> assigned_dev->irq_requested_type =3D 0; >> + pci_device_set_intx_routing_notifier(pci_dev, NULL); >> } >> =20 >> if (ctrl_byte & PCI_MSI_FLAGS_ENABLE) { >> @@ -1151,6 +1134,7 @@ static void assigned_dev_update_msix(PCIDevice *= pci_dev) >> perror("assigned_dev_update_msix: deassign irq"); >> =20 >> assigned_dev->irq_requested_type =3D 0; >> + pci_device_set_intx_routing_notifier(pci_dev, NULL); >> } >> =20 >> if (ctrl_word & PCI_MSIX_FLAGS_ENABLE) { >> diff --git a/hw/device-assignment.h b/hw/device-assignment.h >> deleted file mode 100644 >> index 3fcb804..0000000 >> --- a/hw/device-assignment.h >> +++ /dev/null >> @@ -1,33 +0,0 @@ >> -/* >> - * Copyright (c) 2007, Neocleus Corporation. >> - * Copyright (c) 2007, Intel Corporation. >> - * >> - * This program is free software; you can redistribute it and/or modi= fy it >> - * under the terms and conditions of the GNU General Public License, >> - * version 2, as published by the Free Software Foundation. >> - * >> - * This program is distributed in the hope it will be useful, but WIT= HOUT >> - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY= or >> - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Lice= nse for >> - * more details. >> - * >> - * You should have received a copy of the GNU General Public License = along with >> - * this program; if not, write to the Free Software Foundation, Inc.,= 59 Temple >> - * Place - Suite 330, Boston, MA 02111-1307 USA. >> - * >> - * Data structures for storing PCI state >> - * >> - * Adapted to kvm by Qumranet >> - * >> - * Copyright (c) 2007, Neocleus, Alex Novik (alex@neocleus.com) >> - * Copyright (c) 2007, Neocleus, Guy Zana (guy@neocleus.com) >> - * Copyright (C) 2008, Qumranet, Amit Shah (amit.shah@qumranet.com) >> - * Copyright (C) 2008, Red Hat, Amit Shah (amit.shah@redhat.com) >> - */ >> - >> -#ifndef __DEVICE_ASSIGNMENT_H__ >> -#define __DEVICE_ASSIGNMENT_H__ >> - >> -void assigned_dev_update_irqs(void); >> - >> -#endif /* __DEVICE_ASSIGNMENT_H__ */ >> diff --git a/hw/pc.h b/hw/pc.h >> index 5b36eb5..31ccb6f 100644 >> --- a/hw/pc.h >> +++ b/hw/pc.h >> @@ -149,9 +149,6 @@ void piix4_smbus_register_device(SMBusDevice *dev,= uint8_t addr); >> extern int no_hpet; >> =20 >> /* piix_pci.c */ >> -/* config space register for IRQ routing */ >> -#define PIIX_CONFIG_IRQ_ROUTE 0x60 >> - >> struct PCII440FXState; >> typedef struct PCII440FXState PCII440FXState; >> =20 >> diff --git a/hw/pci.c b/hw/pci.c >> index 0b22913..4d95984 100644 >> --- a/hw/pci.c >> +++ b/hw/pci.c >> @@ -29,9 +29,6 @@ >> #include "net.h" >> #include "sysemu.h" >> #include "loader.h" >> -#include "hw/pc.h" >> -#include "kvm.h" >> -#include "device-assignment.h" >> #include "range.h" >> #include "qmp-commands.h" >> #include "msi.h" >> @@ -1048,14 +1045,6 @@ void pci_default_write_config(PCIDevice *d, uin= t32_t addr, uint32_t val, int l) >> d->config[addr + i] =3D (d->config[addr + i] & ~wmask) | (val= & wmask); >> d->config[addr + i] &=3D ~(val & w1cmask); /* W1C: Write 1 to= Clear */ >> } >> - >> -#ifdef CONFIG_KVM_DEVICE_ASSIGNMENT >> - if (kvm_enabled() && kvm_irqchip_in_kernel() && >> - addr >=3D PIIX_CONFIG_IRQ_ROUTE && >> - addr < PIIX_CONFIG_IRQ_ROUTE + 4) >> - assigned_dev_update_irqs(); >> -#endif /* CONFIG_KVM_DEVICE_ASSIGNMENT */ >> - >> if (ranges_overlap(addr, l, PCI_BASE_ADDRESS_0, 24) || >> ranges_overlap(addr, l, PCI_ROM_ADDRESS, 4) || >> ranges_overlap(addr, l, PCI_ROM_ADDRESS1, 4) || >> diff --git a/hw/piix_pci.c b/hw/piix_pci.c >> index 355814f..c497a01 100644 >> --- a/hw/piix_pci.c >> +++ b/hw/piix_pci.c >> @@ -250,8 +250,6 @@ static int i440fx_initfn(PCIDevice *dev) >> return 0; >> } >> =20 >> -static PIIX3State *piix3_dev; >> - >> static PCIBus *i440fx_common_init(const char *device_name, >> PCII440FXState **pi440fx_state, >> int *piix3_devfn, >> @@ -331,7 +329,6 @@ static PCIBus *i440fx_common_init(const char *devi= ce_name, >> ram_size =3D 255; >> (*pi440fx_state)->dev.config[0x57]=3Dram_size; >> =20 >> - piix3_dev =3D piix3; >> i440fx_update_memory_mappings(f); >> =20 >> return b; >=20 > For vfio I chose to leave the intx routing notifier in place for msi & > msix as we can easily ignore it when not using intx. I don't see much > advantage to one over the other though. Probably. When you don't disable, then you have to check in the callback if the IRQ is actually registered, but that's a nit as well. >=20 > Acked-by: Alex Williamson >=20 Thanks, Jan --------------enig093390E54FF1301DD5597300 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.16 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAlAcBJEACgkQitSsb3rl5xTaogCcDqlXw3UuJ0ZLdJRVJ0YBE3XG cbcAn2CEH/rUab3tNhlntyCnksUt6r4P =b4jd -----END PGP SIGNATURE----- --------------enig093390E54FF1301DD5597300--