Re: [virtio-dev] Re: [RFC PATCH 1/3] qemu: virtio-bypass should explicitly bind to a passthrough device
(click the wrong reply button again, sorry) On Thu, Apr 5, 2018 at 8:31 AM, Paolo Bonzini wrote: > On 04/04/2018 10:02, Siwei Liu wrote: >>> pci_bus_num is almost always a bug if not done within >>> a context of a PCI host, bridge, etc. >>> >>> In particular this will not DTRT if run before guest assigns bus >>> numbers. >>> >> I was seeking means to reserve a specific pci bus slot from drivers, >> and update the driver when guest assigns the bus number but it seems >> there's no low-hanging fruits. Because of that reason the bus_num is >> only obtained until it's really needed (during get_config) and I >> assume at that point the pci bus assignment is already done. I know >> the current one is not perfect, but we need that information (PCI >> bus:slot.func number) to name the guest device correctly. > > Can you use the -device "id", and look it up as > > devices = container_get(qdev_get_machine(), "/peripheral"); > return object_resolve_path_component(devices, id); No. The problem of using device id is that the vfio device may come and go at any time, this is particularly true when live migration is happening. There's no gurantee we can get the bus:device.func info if that device is gone. Currently the binding between vfio and virtio-net is weakly coupled through the backup property, there's no better way than specifying the bus id and addr property directly. Regards, -Siwei > > ? > > Thanks, > > Paolo ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [virtio-dev] Re: [RFC PATCH 1/3] qemu: virtio-bypass should explicitly bind to a passthrough device
On 04/04/2018 10:02, Siwei Liu wrote: >> pci_bus_num is almost always a bug if not done within >> a context of a PCI host, bridge, etc. >> >> In particular this will not DTRT if run before guest assigns bus >> numbers. >> > I was seeking means to reserve a specific pci bus slot from drivers, > and update the driver when guest assigns the bus number but it seems > there's no low-hanging fruits. Because of that reason the bus_num is > only obtained until it's really needed (during get_config) and I > assume at that point the pci bus assignment is already done. I know > the current one is not perfect, but we need that information (PCI > bus:slot.func number) to name the guest device correctly. Can you use the -device "id", and look it up as devices = container_get(qdev_get_machine(), "/peripheral"); return object_resolve_path_component(devices, id); ? Thanks, Paolo ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Re: [virtio-dev] Re: [RFC PATCH 1/3] qemu: virtio-bypass should explicitly bind to a passthrough device
On Tue, Apr 3, 2018 at 5:25 AM, Michael S. Tsirkin wrote: > On Sun, Apr 01, 2018 at 05:13:08AM -0400, Si-Wei Liu wrote: >> @@ -896,6 +898,68 @@ void qmp_device_del(const char *id, Error **errp) >> } >> } >> >> +int pci_get_busdevfn_by_id(const char *id, uint16_t *busnr, >> + uint16_t *devfn, Error **errp) >> +{ >> +uint16_t busnum = 0, slot = 0, func = 0; >> +const char *pc, *pd, *pe; >> +Error *local_err = NULL; >> +ObjectClass *class; >> +char value[1024]; >> +BusState *bus; >> +uint64_t u64; >> + >> +if (!(pc = strchr(id, ':'))) { >> +error_setg(errp, "Invalid id: backup=%s, " >> + "correct format should be backup=" >> + "':[.]'", id); >> +return -1; >> +} >> +get_opt_name(value, sizeof(value), id, ':'); >> +if (pc != id + 1) { >> +bus = qbus_find(value, errp); >> +if (!bus) >> +return -1; >> + >> +class = object_get_class(OBJECT(bus)); >> +if (class != object_class_by_name(TYPE_PCI_BUS) && >> +class != object_class_by_name(TYPE_PCIE_BUS)) { >> +error_setg(errp, "%s is not a device on pci bus", id); >> +return -1; >> +} >> +busnum = (uint16_t)pci_bus_num(PCI_BUS(bus)); >> +} > > pci_bus_num is almost always a bug if not done within > a context of a PCI host, bridge, etc. > > In particular this will not DTRT if run before guest assigns bus > numbers. > I was seeking means to reserve a specific pci bus slot from drivers, and update the driver when guest assigns the bus number but it seems there's no low-hanging fruits. Because of that reason the bus_num is only obtained until it's really needed (during get_config) and I assume at that point the pci bus assignment is already done. I know the current one is not perfect, but we need that information (PCI bus:slot.func number) to name the guest device correctly. Regards, -Siwei > >> + >> +if (!devfn) >> +goto out; >> + >> +pd = strchr(pc, '.'); >> +pe = get_opt_name(value, sizeof(value), pc + 1, '.'); >> +if (pe != pc + 1) { >> +parse_option_number("slot", value, &u64, &local_err); >> +if (local_err) { >> +error_propagate(errp, local_err); >> +return -1; >> +} >> +slot = (uint16_t)u64; >> +} >> +if (pd && *(pd + 1) != '\0') { >> +parse_option_number("function", pd, &u64, &local_err); >> +if (local_err) { >> +error_propagate(errp, local_err); >> +return -1; >> +} >> +func = (uint16_t)u64; >> +} >> + >> +out: >> +if (busnr) >> +*busnr = busnum; >> +if (devfn) >> +*devfn = ((slot & 0x1F) << 3) | (func & 0x7); >> +return 0; >> +} >> + >> BlockBackend *blk_by_qdev_id(const char *id, Error **errp) >> { >> DeviceState *dev; >> -- >> 1.8.3.1 > > - > To unsubscribe, e-mail: virtio-dev-unsubscr...@lists.oasis-open.org > For additional commands, e-mail: virtio-dev-h...@lists.oasis-open.org > ___ Virtualization mailing list Virtualization@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/virtualization