Message ID | 1413813882-27047-1-git-send-email-marcel.a@redhat.com (mailing list archive) |
---|---|
State | New, archived |
Delegated to: | Bjorn Helgaas |
Headers | show |
[cc+ stuart] On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > Scanning a lot of devices during boot requires a lot of time. > On other scenarios there is a need to bind a driver to a specific slot. > > Binding devices to pci-stub driver does not work, > as it will not differentiate between devices of the > same type. Using some start scripts is error prone. > > The solution leverages driver_override functionality introduced by > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > Author: Alex Williamson <alex.williamson@redhat.com> > Date: Tue May 20 08:53:21 2014 -0600 > > PCI: Introduce new device binding path using pci_dev.driver_override > > In order to bind PCI slots to specific drivers use: > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > --- > v3 -> v4: > - Addressed Alex Williamson's comments: > - Modified the type of driver_override_entry's fields > - Used PCI_DEVFN when appropriated > - Removed redundant checks > - Replaced BUG_ON with pr_err messages > - Simpler command line parsing > - Addressed Michael S. Tsirkin comments > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > v2 -> v3: > - Corrected subject line > v1 -> v2: > - Addressed Michael S. Tsirkin comments > - Removed 32 slots limitation > - Better handling of memory allocation failures > (preferred BUG_ON over error messages) > - Addressed Alex Williamson's comments: > - Modified commit message to show parameter usage more clear. > - I preferred to re-use parse_args instead of manually using > strstr in order to better comply with command line parsing > rules. > - I didn't use any locking when parsing the command line args > (see parse_done usage) assuming that first call will be > early in system boot and no race can occur. Please correct > me if I am wrong. > > Notes: > - I have further ideas on top of this patch based on your reviews. > I thought of: > - Use wildcards to specify entire buses/devices, something like: > driver[0001:02:*.*]=pci-stub > - Use comma to separate several devices: > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > - Make domain optional: > driver[00:03.0]=pci-stub > > Comments will be appreciated, > Thanks, > Marcel > Documentation/kernel-parameters.txt | 4 ++ > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > drivers/pci/pci.c | 2 + > 3 files changed, 117 insertions(+) The driver_override feature that we're making use of here is also going to be supported by platform devices and potentially more bustypes in the future, so I'm concerned that making a pci specific kernel parameter is too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for bustypes that support driver_override so we can have a common interface. Perhaps: driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform Finding delimiters that don't conflict may be challenging. Also, can we assume that bus-name:dev-name is unique for every bustype? It is for pci, platform? It also seems like there's a question of how long should this override last and how does the user disable it? I think with pci-stub.ids= $VENDOR:$DEVICE a user can echo the IDs to the pci-stub/remove_id sysfs entry to cancel the effect. The only option here seems to be a reboot. Do we need a /sys/bus/pci/driver_overrides/{add_name,remove_name} for this interface? Thanks, Alex > diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt > index 5ae8608..c1cbb4c 100644 > --- a/Documentation/kernel-parameters.txt > +++ b/Documentation/kernel-parameters.txt > @@ -2631,6 +2631,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted. > pcie_scan_all Scan all possible PCIe devices. Otherwise we > only look for one device below a PCIe downstream > port. > + driver Provide an override to the devid<->driver mapping > + for a specific slot. > + Bind PCI slot 0001:02:03.4 to pci-stub by: > + driver[0001:02:03.4]=pci-stub > > pcie_aspm= [PCIE] Forcibly enable or disable PCIe Active State Power > Management. > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > index 73aef51..b49f5cc 100644 > --- a/drivers/pci/bus.c > +++ b/drivers/pci/bus.c > @@ -15,6 +15,8 @@ > #include <linux/proc_fs.h> > #include <linux/slab.h> > > +#include <asm/setup.h> > + > #include "pci.h" > > void pci_add_resource_offset(struct list_head *resources, struct resource *res, > @@ -230,6 +232,114 @@ EXPORT_SYMBOL(pci_bus_alloc_resource); > > void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } > > +struct driver_override_entry { > + u16 domain; > + u8 bus; > + u8 devfn; > + char *driver_name; > + struct list_head list; > +}; > + > +static LIST_HEAD(driver_override_entries); > + > +static int pci_device_parse_driver_override(char *param, char *val, > + const char *unused) > +{ > + unsigned int domain, bus, dev, fn; > + char *buf; > + struct driver_override_entry *entry; > + int ret; > + > + buf = kmalloc(COMMAND_LINE_SIZE, GFP_KERNEL); > + if (!buf) > + goto err_buf; > + > + while (val) { > + char *k = strchr(val, ','); > + > + if (k) > + *k++ = 0; > + > + if (strncmp(val, "driver", 6)) { > + val = k; > + continue; > + } > + > + memset(buf, 0, COMMAND_LINE_SIZE); > + ret = sscanf(val + 6, "[%4x:%2x:%2x.%2x]=%s", > + &domain, &bus, &dev, &fn, buf); > + if (ret != 5) { > + pr_warn("PCI: Invalid command line: %s\n", val); > + val = k; > + continue; > + } > + > + entry = kzalloc(sizeof(*entry), GFP_KERNEL); > + if (!entry) > + goto err_entry; > + > + INIT_LIST_HEAD(&entry->list); > + entry->domain = domain; > + entry->bus = bus; > + entry->devfn = PCI_DEVFN(dev, fn); > + entry->driver_name = kstrdup(buf, GFP_KERNEL); > + if (!entry->driver_name) > + goto err_driver_name; > + > + list_add_tail(&entry->list, &driver_override_entries); > + val = k; > + } > + > + kfree(buf); > + return 0; > + > +err_driver_name: > + kfree(entry); > + > +err_entry: > + kfree(buf); > + > +err_buf: > + pr_err("PCI: Out of memory while parsing command line: %s\n", val); > + return -ENOMEM; > +} > + > +static void pci_device_setup_driver_override(struct pci_dev *dev) > +{ > + static int parse_done; > + struct driver_override_entry *entry; > + > + if (!parse_done) { > + char *cmdline = kstrdup(saved_command_line, GFP_KERNEL); > + > + if (!cmdline) > + goto err_out_of_mem; > + > + parse_args("pci", cmdline, NULL, > + 0, 0, 0, &pci_device_parse_driver_override); > + kfree(cmdline); > + parse_done = 1; > + } > + > + list_for_each_entry(entry, &driver_override_entries, list) { > + if (pci_domain_nr(dev->bus) != entry->domain || > + dev->bus->number != entry->bus || > + dev->devfn != entry->devfn) > + continue; > + > + dev->driver_override = kstrdup(entry->driver_name, GFP_KERNEL); > + if (!dev->driver_override) > + goto err_out_of_mem; > + > + break; > + } > + > + return; > + > +err_out_of_mem: > + pr_err("PCI: Out of memory while setting up driver override\n"); > +} > + > /** > * pci_bus_add_device - start driver for a single device > * @dev: device to add > @@ -245,6 +355,7 @@ void pci_bus_add_device(struct pci_dev *dev) > * are not assigned yet for some devices. > */ > pci_fixup_device(pci_fixup_final, dev); > + pci_device_setup_driver_override(dev); > pci_create_sysfs_dev_files(dev); > pci_proc_attach_device(dev); > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 625a4ac..37809d4 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -4508,6 +4508,8 @@ static int __init pci_setup(char *str) > pcie_bus_config = PCIE_BUS_PEER2PEER; > } else if (!strncmp(str, "pcie_scan_all", 13)) { > pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS); > + } else if (!strncmp(str, "driver", 6)) { > + /* lazy evaluation by the pci subsystem */ > } else { > printk(KERN_ERR "PCI: Unknown option `%s'\n", > str); -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Marcel, I'm not quite clear on what the objective is here, so I apologize for some questions that probably seem silly. On Mon, Oct 20, 2014 at 8:04 AM, Marcel Apfelbaum <marcel.a@redhat.com> wrote: > Scanning a lot of devices during boot requires a lot of time. I think what takes a lot of time is the .probe() method for some drivers, right? I first thought you meant that it took a long time for the PCI core to enumerate a lot of devices, but you're not changing anything there. If the intent is to reduce boot time, I don't think this is a general solution. Drivers should be able to schedule asynchronous things in their .probe() methods if necessary. > On other scenarios there is a need to bind a driver to a specific slot. A short example here would be good. Are you talking about something like binding a NIC driver to one device while leaving others unbound for use by guests? > Binding devices to pci-stub driver does not work, > as it will not differentiate between devices of the > same type. I assume you mean booting with "pci-stub.ids=$VENDOR:$DEVICE" will make pci-stub bind to *all* matching devices, and you only want it to bind to some. Maybe pci-stub could be extended to pay attention to PCI bus addresses in addition to vendor/device IDs. > Using some start scripts is error prone. > > The solution leverages driver_override functionality introduced by > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > Author: Alex Williamson <alex.williamson@redhat.com> > Date: Tue May 20 08:53:21 2014 -0600 > > PCI: Introduce new device binding path using pci_dev.driver_override > > In order to bind PCI slots to specific drivers use: > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... If/when you address Alex's comments about other bus types, can you also update the changelog to use the canonical commit reference format, i.e., 782a985d7af2 ("PCI: Introduce new device binding path using pci_dev.driver_override") in this case? PCI bus numbers are mutable, e.g., they can change with hotplug or other configuration changes. But I don't have any better suggestion, so I guess all we can do is be aware of this. Speaking of hotplug, this is only a boot-time kernel parameter, with no opportunity to use this, e.g., to add slot/driver pairs, after boot. Do you not need that because of Alex's driver_override thing? How can we integrate this all together into a coherent whole? I'm a little confused as to how this would all be documented in a form usable by end-users. Bjorn -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, 2014-10-22 at 12:32 -0600, Alex Williamson wrote: > [cc+ stuart] > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > Scanning a lot of devices during boot requires a lot of time. > > On other scenarios there is a need to bind a driver to a specific slot. > > > > Binding devices to pci-stub driver does not work, > > as it will not differentiate between devices of the > > same type. Using some start scripts is error prone. > > > > The solution leverages driver_override functionality introduced by > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > Author: Alex Williamson <alex.williamson@redhat.com> > > Date: Tue May 20 08:53:21 2014 -0600 > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > In order to bind PCI slots to specific drivers use: > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > --- > > v3 -> v4: > > - Addressed Alex Williamson's comments: > > - Modified the type of driver_override_entry's fields > > - Used PCI_DEVFN when appropriated > > - Removed redundant checks > > - Replaced BUG_ON with pr_err messages > > - Simpler command line parsing > > - Addressed Michael S. Tsirkin comments > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > v2 -> v3: > > - Corrected subject line > > v1 -> v2: > > - Addressed Michael S. Tsirkin comments > > - Removed 32 slots limitation > > - Better handling of memory allocation failures > > (preferred BUG_ON over error messages) > > - Addressed Alex Williamson's comments: > > - Modified commit message to show parameter usage more clear. > > - I preferred to re-use parse_args instead of manually using > > strstr in order to better comply with command line parsing > > rules. > > - I didn't use any locking when parsing the command line args > > (see parse_done usage) assuming that first call will be > > early in system boot and no race can occur. Please correct > > me if I am wrong. > > > > Notes: > > - I have further ideas on top of this patch based on your reviews. > > I thought of: > > - Use wildcards to specify entire buses/devices, something like: > > driver[0001:02:*.*]=pci-stub > > - Use comma to separate several devices: > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > - Make domain optional: > > driver[00:03.0]=pci-stub > > > > Comments will be appreciated, > > Thanks, > > Marcel > > Documentation/kernel-parameters.txt | 4 ++ > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > drivers/pci/pci.c | 2 + > > 3 files changed, 117 insertions(+) > > The driver_override feature that we're making use of here is also going > to be supported by platform devices and potentially more bustypes in the > future, so I'm concerned that making a pci specific kernel parameter is > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > bustypes that support driver_override so we can have a common interface. The real question here if those bus types/devices would benefit from this feature, and I also must confess that I have no knowledge of the other buses. Can anyone confirm that it does make sense for them? > Perhaps: > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > Finding delimiters that don't conflict may be challenging. Also, can we > assume that bus-name:dev-name is unique for every bustype? It is for > pci, platform? For PCI, sure the domain:bus:dev.func is unique, for platform I have no idea, can anyone that knows "platform" confirm or deny? > > It also seems like there's a question of how long should this override > last and how does the user disable it? > I think with pci-stub.ids= > $VENDOR:$DEVICE a user can echo the IDs to the pci-stub/remove_id sysfs > entry to cancel the effect. The way I see it is simple, the override specified in kernel command line last as long as the user does not specifically remove it using echo "" > /sys/.../driver_override and then unbind and bind the device again. > The only option here seems to be a reboot. Please see above > Do we need a /sys/bus/pci/driver_overrides/{add_name,remove_name} for > this interface? Thanks, While it does not hurt, I see it as optional since a simple removal of driver_override and rebind does the same Thanks, Marcel > > Alex > > > diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt > > index 5ae8608..c1cbb4c 100644 > > --- a/Documentation/kernel-parameters.txt > > +++ b/Documentation/kernel-parameters.txt > > @@ -2631,6 +2631,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted. > > pcie_scan_all Scan all possible PCIe devices. Otherwise we > > only look for one device below a PCIe downstream > > port. > > + driver Provide an override to the devid<->driver mapping > > + for a specific slot. > > + Bind PCI slot 0001:02:03.4 to pci-stub by: > > + driver[0001:02:03.4]=pci-stub > > > > pcie_aspm= [PCIE] Forcibly enable or disable PCIe Active State Power > > Management. > > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > > index 73aef51..b49f5cc 100644 > > --- a/drivers/pci/bus.c > > +++ b/drivers/pci/bus.c > > @@ -15,6 +15,8 @@ > > #include <linux/proc_fs.h> > > #include <linux/slab.h> > > > > +#include <asm/setup.h> > > + > > #include "pci.h" > > > > void pci_add_resource_offset(struct list_head *resources, struct resource *res, > > @@ -230,6 +232,114 @@ EXPORT_SYMBOL(pci_bus_alloc_resource); > > > > void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } > > > > +struct driver_override_entry { > > + u16 domain; > > + u8 bus; > > + u8 devfn; > > + char *driver_name; > > + struct list_head list; > > +}; > > + > > +static LIST_HEAD(driver_override_entries); > > + > > +static int pci_device_parse_driver_override(char *param, char *val, > > + const char *unused) > > +{ > > + unsigned int domain, bus, dev, fn; > > + char *buf; > > + struct driver_override_entry *entry; > > + int ret; > > + > > + buf = kmalloc(COMMAND_LINE_SIZE, GFP_KERNEL); > > + if (!buf) > > + goto err_buf; > > + > > + while (val) { > > + char *k = strchr(val, ','); > > + > > + if (k) > > + *k++ = 0; > > + > > + if (strncmp(val, "driver", 6)) { > > + val = k; > > + continue; > > + } > > + > > + memset(buf, 0, COMMAND_LINE_SIZE); > > + ret = sscanf(val + 6, "[%4x:%2x:%2x.%2x]=%s", > > + &domain, &bus, &dev, &fn, buf); > > + if (ret != 5) { > > + pr_warn("PCI: Invalid command line: %s\n", val); > > + val = k; > > + continue; > > + } > > + > > + entry = kzalloc(sizeof(*entry), GFP_KERNEL); > > + if (!entry) > > + goto err_entry; > > + > > + INIT_LIST_HEAD(&entry->list); > > + entry->domain = domain; > > + entry->bus = bus; > > + entry->devfn = PCI_DEVFN(dev, fn); > > + entry->driver_name = kstrdup(buf, GFP_KERNEL); > > + if (!entry->driver_name) > > + goto err_driver_name; > > + > > + list_add_tail(&entry->list, &driver_override_entries); > > + val = k; > > + } > > + > > + kfree(buf); > > + return 0; > > + > > +err_driver_name: > > + kfree(entry); > > + > > +err_entry: > > + kfree(buf); > > + > > +err_buf: > > + pr_err("PCI: Out of memory while parsing command line: %s\n", val); > > + return -ENOMEM; > > +} > > + > > +static void pci_device_setup_driver_override(struct pci_dev *dev) > > +{ > > + static int parse_done; > > + struct driver_override_entry *entry; > > + > > + if (!parse_done) { > > + char *cmdline = kstrdup(saved_command_line, GFP_KERNEL); > > + > > + if (!cmdline) > > + goto err_out_of_mem; > > + > > + parse_args("pci", cmdline, NULL, > > + 0, 0, 0, &pci_device_parse_driver_override); > > + kfree(cmdline); > > + parse_done = 1; > > + } > > + > > + list_for_each_entry(entry, &driver_override_entries, list) { > > + if (pci_domain_nr(dev->bus) != entry->domain || > > + dev->bus->number != entry->bus || > > + dev->devfn != entry->devfn) > > + continue; > > + > > + dev->driver_override = kstrdup(entry->driver_name, GFP_KERNEL); > > + if (!dev->driver_override) > > + goto err_out_of_mem; > > + > > + break; > > + } > > + > > + return; > > + > > +err_out_of_mem: > > + pr_err("PCI: Out of memory while setting up driver override\n"); > > +} > > + > > /** > > * pci_bus_add_device - start driver for a single device > > * @dev: device to add > > @@ -245,6 +355,7 @@ void pci_bus_add_device(struct pci_dev *dev) > > * are not assigned yet for some devices. > > */ > > pci_fixup_device(pci_fixup_final, dev); > > + pci_device_setup_driver_override(dev); > > pci_create_sysfs_dev_files(dev); > > pci_proc_attach_device(dev); > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > index 625a4ac..37809d4 100644 > > --- a/drivers/pci/pci.c > > +++ b/drivers/pci/pci.c > > @@ -4508,6 +4508,8 @@ static int __init pci_setup(char *str) > > pcie_bus_config = PCIE_BUS_PEER2PEER; > > } else if (!strncmp(str, "pcie_scan_all", 13)) { > > pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS); > > + } else if (!strncmp(str, "driver", 6)) { > > + /* lazy evaluation by the pci subsystem */ > > } else { > > printk(KERN_ERR "PCI: Unknown option `%s'\n", > > str); > > > -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, 2014-10-22 at 15:28 -0600, Bjorn Helgaas wrote: > Hi Marcel, Hi Bjorn, Thank you for the review! > > I'm not quite clear on what the objective is here, so I apologize for > some questions that probably seem silly. I appreciate you took your time to go over it. > > On Mon, Oct 20, 2014 at 8:04 AM, Marcel Apfelbaum <marcel.a@redhat.com> wrote: > > Scanning a lot of devices during boot requires a lot of time. > > I think what takes a lot of time is the .probe() method for some > drivers, right? I first thought you meant that it took a long time > for the PCI core to enumerate a lot of devices, but you're not > changing anything there. Yes indeed. > > If the intent is to reduce boot time, I don't think this is a general > solution. Drivers should be able to schedule asynchronous things in > their .probe() methods if necessary. I agree, but sadly we cannot go over *all* existing drivers and fix, we can of course do the best effort :) By the way this was not the only reason as you also thought, see bellow > > > On other scenarios there is a need to bind a driver to a specific slot. > > A short example here would be good. Are you talking about something > like binding a NIC driver to one device while leaving others unbound > for use by guests? Exactly! This is the "perfect" example, thanks! > > > Binding devices to pci-stub driver does not work, > > as it will not differentiate between devices of the > > same type. > > I assume you mean booting with "pci-stub.ids=$VENDOR:$DEVICE" will > make pci-stub bind to *all* matching devices, and you only want it to > bind to some. You are right again. > Maybe pci-stub could be extended to pay attention to > PCI bus addresses in addition to vendor/device IDs. A few thoughts here: - We will have a race here between the "native" driver and pci-stub, right? - Why not leverage the existing driver_override feature that is already there and gives us exactly what we want: slot<->driver mapping? - Maybe there are other scenarios that can benefit from slot<->driver mapping, not only pci-stub. > > > Using some start scripts is error prone. > > > > The solution leverages driver_override functionality introduced by > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > Author: Alex Williamson <alex.williamson@redhat.com> > > Date: Tue May 20 08:53:21 2014 -0600 > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > In order to bind PCI slots to specific drivers use: > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > If/when you address Alex's comments about other bus types, can you > also update the changelog to use the canonical commit reference > format, i.e., 782a985d7af2 ("PCI: Introduce new device binding path > using pci_dev.driver_override") in this case? Sure, thanks for the tip. > > PCI bus numbers are mutable, e.g., they can change with hotplug or > other configuration changes. But I don't have any better suggestion, > so I guess all we can do is be aware of this. Well, indeed, there is so much that can be done. (We can listen to an event and remap...) > > Speaking of hotplug, this is only a boot-time kernel parameter, with > no opportunity to use this, e.g., to add slot/driver pairs, after > boot. Do you not need that because of Alex's driver_override thing? Well actually Alex's "driver_override" feature does that for runtime (adds slot/driver pair), the only thing missing is the boot time mapping. > How can we integrate this all together into a coherent whole? I'm a > little confused as to how this would all be documented in a form > usable by end-users. For end-users it will be like this: They want to create a slot/driver mapping. In order to do that they will use the "driver_override" feature: 1. Run-time use: - Use sysfs to edit driver_override file associated with the slot. 2. Boot-time use: - Use the pci's driver_override parameter. Thanks, Marcel > > Bjorn -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, Oct 22, 2014 at 03:28:29PM -0600, Bjorn Helgaas wrote: > Hi Marcel, > > I'm not quite clear on what the objective is here, so I apologize for > some questions that probably seem silly. > > On Mon, Oct 20, 2014 at 8:04 AM, Marcel Apfelbaum <marcel.a@redhat.com> wrote: > > Scanning a lot of devices during boot requires a lot of time. > > I think what takes a lot of time is the .probe() method for some > drivers, right? I first thought you meant that it took a long time > for the PCI core to enumerate a lot of devices, but you're not > changing anything there. > > If the intent is to reduce boot time, I don't think this is a general > solution. Drivers should be able to schedule asynchronous things in > their .probe() methods if necessary. If this worked for all devices, we could just make probe asynchronous in PCI core. Unfortunately this doesn't work esp for storage devices since people expect disks to be available for mount immediately. If the point of the patch is to speed up boot, we could try to probe everything in parallel? Probe is serialized now, right? > > On other scenarios there is a need to bind a driver to a specific slot. > > A short example here would be good. Are you talking about something > like binding a NIC driver to one device while leaving others unbound > for use by guests? > > > Binding devices to pci-stub driver does not work, > > as it will not differentiate between devices of the > > same type. > > I assume you mean booting with "pci-stub.ids=$VENDOR:$DEVICE" will > make pci-stub bind to *all* matching devices, and you only want it to > bind to some. Maybe pci-stub could be extended to pay attention to > PCI bus addresses in addition to vendor/device IDs. > > > Using some start scripts is error prone. > > > > The solution leverages driver_override functionality introduced by > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > Author: Alex Williamson <alex.williamson@redhat.com> > > Date: Tue May 20 08:53:21 2014 -0600 > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > In order to bind PCI slots to specific drivers use: > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > If/when you address Alex's comments about other bus types, can you > also update the changelog to use the canonical commit reference > format, i.e., 782a985d7af2 ("PCI: Introduce new device binding path > using pci_dev.driver_override") in this case? > > PCI bus numbers are mutable, e.g., they can change with hotplug or > other configuration changes. But I don't have any better suggestion, > so I guess all we can do is be aware of this. We could use slot capability for addressing if that's available. > Speaking of hotplug, this is only a boot-time kernel parameter, with > no opportunity to use this, e.g., to add slot/driver pairs, after > boot. Do you not need that because of Alex's driver_override thing? > How can we integrate this all together into a coherent whole? I'm a > little confused as to how this would all be documented in a form > usable by end-users. > > Bjorn -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2014-10-23 at 15:32 +0300, Marcel Apfelbaum wrote: > On Wed, 2014-10-22 at 12:32 -0600, Alex Williamson wrote: > > [cc+ stuart] > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > Scanning a lot of devices during boot requires a lot of time. > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > Binding devices to pci-stub driver does not work, > > > as it will not differentiate between devices of the > > > same type. Using some start scripts is error prone. > > > > > > The solution leverages driver_override functionality introduced by > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > In order to bind PCI slots to specific drivers use: > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > --- > > > v3 -> v4: > > > - Addressed Alex Williamson's comments: > > > - Modified the type of driver_override_entry's fields > > > - Used PCI_DEVFN when appropriated > > > - Removed redundant checks > > > - Replaced BUG_ON with pr_err messages > > > - Simpler command line parsing > > > - Addressed Michael S. Tsirkin comments > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > v2 -> v3: > > > - Corrected subject line > > > v1 -> v2: > > > - Addressed Michael S. Tsirkin comments > > > - Removed 32 slots limitation > > > - Better handling of memory allocation failures > > > (preferred BUG_ON over error messages) > > > - Addressed Alex Williamson's comments: > > > - Modified commit message to show parameter usage more clear. > > > - I preferred to re-use parse_args instead of manually using > > > strstr in order to better comply with command line parsing > > > rules. > > > - I didn't use any locking when parsing the command line args > > > (see parse_done usage) assuming that first call will be > > > early in system boot and no race can occur. Please correct > > > me if I am wrong. > > > > > > Notes: > > > - I have further ideas on top of this patch based on your reviews. > > > I thought of: > > > - Use wildcards to specify entire buses/devices, something like: > > > driver[0001:02:*.*]=pci-stub > > > - Use comma to separate several devices: > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > - Make domain optional: > > > driver[00:03.0]=pci-stub > > > > > > Comments will be appreciated, > > > Thanks, > > > Marcel > > > Documentation/kernel-parameters.txt | 4 ++ > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > drivers/pci/pci.c | 2 + > > > 3 files changed, 117 insertions(+) > > > > The driver_override feature that we're making use of here is also going > > to be supported by platform devices and potentially more bustypes in the > > future, so I'm concerned that making a pci specific kernel parameter is > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > bustypes that support driver_override so we can have a common interface. > The real question here if those bus types/devices would benefit from this > feature, and I also must confess that I have no knowledge of the other buses. > Can anyone confirm that it does make sense for them? Platform devices are adding vfio support, so I expect the next logical question will be how to reserve devices for use by vfio at boot. > > Perhaps: > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > Finding delimiters that don't conflict may be challenging. Also, can we > > assume that bus-name:dev-name is unique for every bustype? It is for > > pci, platform? > For PCI, sure the domain:bus:dev.func is unique, for platform I have no idea, > can anyone that knows "platform" confirm or deny? > > > > > It also seems like there's a question of how long should this override > > last and how does the user disable it? > > I think with pci-stub.ids= > > $VENDOR:$DEVICE a user can echo the IDs to the pci-stub/remove_id sysfs > > entry to cancel the effect. > The way I see it is simple, the override specified in kernel command line > last as long as the user does not specifically remove it using > echo "" > /sys/.../driver_override > and then unbind and bind the device again. > > > The only option here seems to be a reboot. > Please see above That's only a temporary removal though, if the device is removed and re-added, either via physical hotplug or sysfs, the override is re-applied. Thanks, Alex > > Do we need a /sys/bus/pci/driver_overrides/{add_name,remove_name} for > > this interface? Thanks, > While it does not hurt, I see it as optional since a simple removal of > driver_override and rebind does the same > > Thanks, > Marcel > > > > > Alex > > > > > diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt > > > index 5ae8608..c1cbb4c 100644 > > > --- a/Documentation/kernel-parameters.txt > > > +++ b/Documentation/kernel-parameters.txt > > > @@ -2631,6 +2631,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted. > > > pcie_scan_all Scan all possible PCIe devices. Otherwise we > > > only look for one device below a PCIe downstream > > > port. > > > + driver Provide an override to the devid<->driver mapping > > > + for a specific slot. > > > + Bind PCI slot 0001:02:03.4 to pci-stub by: > > > + driver[0001:02:03.4]=pci-stub > > > > > > pcie_aspm= [PCIE] Forcibly enable or disable PCIe Active State Power > > > Management. > > > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > > > index 73aef51..b49f5cc 100644 > > > --- a/drivers/pci/bus.c > > > +++ b/drivers/pci/bus.c > > > @@ -15,6 +15,8 @@ > > > #include <linux/proc_fs.h> > > > #include <linux/slab.h> > > > > > > +#include <asm/setup.h> > > > + > > > #include "pci.h" > > > > > > void pci_add_resource_offset(struct list_head *resources, struct resource *res, > > > @@ -230,6 +232,114 @@ EXPORT_SYMBOL(pci_bus_alloc_resource); > > > > > > void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } > > > > > > +struct driver_override_entry { > > > + u16 domain; > > > + u8 bus; > > > + u8 devfn; > > > + char *driver_name; > > > + struct list_head list; > > > +}; > > > + > > > +static LIST_HEAD(driver_override_entries); > > > + > > > +static int pci_device_parse_driver_override(char *param, char *val, > > > + const char *unused) > > > +{ > > > + unsigned int domain, bus, dev, fn; > > > + char *buf; > > > + struct driver_override_entry *entry; > > > + int ret; > > > + > > > + buf = kmalloc(COMMAND_LINE_SIZE, GFP_KERNEL); > > > + if (!buf) > > > + goto err_buf; > > > + > > > + while (val) { > > > + char *k = strchr(val, ','); > > > + > > > + if (k) > > > + *k++ = 0; > > > + > > > + if (strncmp(val, "driver", 6)) { > > > + val = k; > > > + continue; > > > + } > > > + > > > + memset(buf, 0, COMMAND_LINE_SIZE); > > > + ret = sscanf(val + 6, "[%4x:%2x:%2x.%2x]=%s", > > > + &domain, &bus, &dev, &fn, buf); > > > + if (ret != 5) { > > > + pr_warn("PCI: Invalid command line: %s\n", val); > > > + val = k; > > > + continue; > > > + } > > > + > > > + entry = kzalloc(sizeof(*entry), GFP_KERNEL); > > > + if (!entry) > > > + goto err_entry; > > > + > > > + INIT_LIST_HEAD(&entry->list); > > > + entry->domain = domain; > > > + entry->bus = bus; > > > + entry->devfn = PCI_DEVFN(dev, fn); > > > + entry->driver_name = kstrdup(buf, GFP_KERNEL); > > > + if (!entry->driver_name) > > > + goto err_driver_name; > > > + > > > + list_add_tail(&entry->list, &driver_override_entries); > > > + val = k; > > > + } > > > + > > > + kfree(buf); > > > + return 0; > > > + > > > +err_driver_name: > > > + kfree(entry); > > > + > > > +err_entry: > > > + kfree(buf); > > > + > > > +err_buf: > > > + pr_err("PCI: Out of memory while parsing command line: %s\n", val); > > > + return -ENOMEM; > > > +} > > > + > > > +static void pci_device_setup_driver_override(struct pci_dev *dev) > > > +{ > > > + static int parse_done; > > > + struct driver_override_entry *entry; > > > + > > > + if (!parse_done) { > > > + char *cmdline = kstrdup(saved_command_line, GFP_KERNEL); > > > + > > > + if (!cmdline) > > > + goto err_out_of_mem; > > > + > > > + parse_args("pci", cmdline, NULL, > > > + 0, 0, 0, &pci_device_parse_driver_override); > > > + kfree(cmdline); > > > + parse_done = 1; > > > + } > > > + > > > + list_for_each_entry(entry, &driver_override_entries, list) { > > > + if (pci_domain_nr(dev->bus) != entry->domain || > > > + dev->bus->number != entry->bus || > > > + dev->devfn != entry->devfn) > > > + continue; > > > + > > > + dev->driver_override = kstrdup(entry->driver_name, GFP_KERNEL); > > > + if (!dev->driver_override) > > > + goto err_out_of_mem; > > > + > > > + break; > > > + } > > > + > > > + return; > > > + > > > +err_out_of_mem: > > > + pr_err("PCI: Out of memory while setting up driver override\n"); > > > +} > > > + > > > /** > > > * pci_bus_add_device - start driver for a single device > > > * @dev: device to add > > > @@ -245,6 +355,7 @@ void pci_bus_add_device(struct pci_dev *dev) > > > * are not assigned yet for some devices. > > > */ > > > pci_fixup_device(pci_fixup_final, dev); > > > + pci_device_setup_driver_override(dev); > > > pci_create_sysfs_dev_files(dev); > > > pci_proc_attach_device(dev); > > > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > > index 625a4ac..37809d4 100644 > > > --- a/drivers/pci/pci.c > > > +++ b/drivers/pci/pci.c > > > @@ -4508,6 +4508,8 @@ static int __init pci_setup(char *str) > > > pcie_bus_config = PCIE_BUS_PEER2PEER; > > > } else if (!strncmp(str, "pcie_scan_all", 13)) { > > > pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS); > > > + } else if (!strncmp(str, "driver", 6)) { > > > + /* lazy evaluation by the pci subsystem */ > > > } else { > > > printk(KERN_ERR "PCI: Unknown option `%s'\n", > > > str); > > > > > > > > > -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2014-10-23 at 07:11 -0600, Alex Williamson wrote: > On Thu, 2014-10-23 at 15:32 +0300, Marcel Apfelbaum wrote: > > On Wed, 2014-10-22 at 12:32 -0600, Alex Williamson wrote: > > > [cc+ stuart] > > > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > > Scanning a lot of devices during boot requires a lot of time. > > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > > > Binding devices to pci-stub driver does not work, > > > > as it will not differentiate between devices of the > > > > same type. Using some start scripts is error prone. > > > > > > > > The solution leverages driver_override functionality introduced by > > > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > > > In order to bind PCI slots to specific drivers use: > > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > > --- > > > > v3 -> v4: > > > > - Addressed Alex Williamson's comments: > > > > - Modified the type of driver_override_entry's fields > > > > - Used PCI_DEVFN when appropriated > > > > - Removed redundant checks > > > > - Replaced BUG_ON with pr_err messages > > > > - Simpler command line parsing > > > > - Addressed Michael S. Tsirkin comments > > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > > v2 -> v3: > > > > - Corrected subject line > > > > v1 -> v2: > > > > - Addressed Michael S. Tsirkin comments > > > > - Removed 32 slots limitation > > > > - Better handling of memory allocation failures > > > > (preferred BUG_ON over error messages) > > > > - Addressed Alex Williamson's comments: > > > > - Modified commit message to show parameter usage more clear. > > > > - I preferred to re-use parse_args instead of manually using > > > > strstr in order to better comply with command line parsing > > > > rules. > > > > - I didn't use any locking when parsing the command line args > > > > (see parse_done usage) assuming that first call will be > > > > early in system boot and no race can occur. Please correct > > > > me if I am wrong. > > > > > > > > Notes: > > > > - I have further ideas on top of this patch based on your reviews. > > > > I thought of: > > > > - Use wildcards to specify entire buses/devices, something like: > > > > driver[0001:02:*.*]=pci-stub > > > > - Use comma to separate several devices: > > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > > - Make domain optional: > > > > driver[00:03.0]=pci-stub > > > > > > > > Comments will be appreciated, > > > > Thanks, > > > > Marcel > > > > Documentation/kernel-parameters.txt | 4 ++ > > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > > drivers/pci/pci.c | 2 + > > > > 3 files changed, 117 insertions(+) > > > > > > The driver_override feature that we're making use of here is also going > > > to be supported by platform devices and potentially more bustypes in the > > > future, so I'm concerned that making a pci specific kernel parameter is > > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > > bustypes that support driver_override so we can have a common interface. > > The real question here if those bus types/devices would benefit from this > > feature, and I also must confess that I have no knowledge of the other buses. > > Can anyone confirm that it does make sense for them? > > Platform devices are adding vfio support, so I expect the next logical > question will be how to reserve devices for use by vfio at boot. Well, I'll have to learn more about vfio before saying anything, but my question is if it can be deferred or it has to be part of this patch. If the platform devices do not have a slot like hw address, maybe it can be configured separately. I saw this patch as a PCI patch, and not "driver_override" expansion; meaning that I only leveraged an existing feature, not trying to extend it. If I am wrong, please point me to a more robust solution. > > > > Perhaps: > > > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > > > Finding delimiters that don't conflict may be challenging. Also, can we > > > assume that bus-name:dev-name is unique for every bustype? It is for > > > pci, platform? > > For PCI, sure the domain:bus:dev.func is unique, for platform I have no idea, > > can anyone that knows "platform" confirm or deny? > > > > > > > > It also seems like there's a question of how long should this override > > > last and how does the user disable it? > > > I think with pci-stub.ids= > > > $VENDOR:$DEVICE a user can echo the IDs to the pci-stub/remove_id sysfs > > > entry to cancel the effect. > > The way I see it is simple, the override specified in kernel command line > > last as long as the user does not specifically remove it using > > echo "" > /sys/.../driver_override > > and then unbind and bind the device again. > > > > > The only option here seems to be a reboot. > > Please see above > > That's only a temporary removal though, if the device is removed and > re-added, either via physical hotplug or sysfs, the override is > re-applied. Thanks, Bear with me please, If we empty the driver_override file (cat "" /sys/bus/.../slot/driver_override) as suggested above, the override will not be reapplied. So, it is a consistent model: 1. The end-user specified the driver in command-line, so he wants it there even after unbinding/binding or hotplug operations. 2. If the end-user "changes his mind", he doesn't need to reboot the system, only to clear the driver_override sysfs file and from this moment on the system behaves like usual. (at next unbind/bind or hotplug) I hope I got it right, Thanks, Marcel > > Alex > > > > Do we need a /sys/bus/pci/driver_overrides/{add_name,remove_name} for > > > this interface? Thanks, > > While it does not hurt, I see it as optional since a simple removal of > > driver_override and rebind does the same > > > > Thanks, > > Marcel > > > > > > > > Alex > > > > > > > diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt > > > > index 5ae8608..c1cbb4c 100644 > > > > --- a/Documentation/kernel-parameters.txt > > > > +++ b/Documentation/kernel-parameters.txt > > > > @@ -2631,6 +2631,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted. > > > > pcie_scan_all Scan all possible PCIe devices. Otherwise we > > > > only look for one device below a PCIe downstream > > > > port. > > > > + driver Provide an override to the devid<->driver mapping > > > > + for a specific slot. > > > > + Bind PCI slot 0001:02:03.4 to pci-stub by: > > > > + driver[0001:02:03.4]=pci-stub > > > > > > > > pcie_aspm= [PCIE] Forcibly enable or disable PCIe Active State Power > > > > Management. > > > > diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c > > > > index 73aef51..b49f5cc 100644 > > > > --- a/drivers/pci/bus.c > > > > +++ b/drivers/pci/bus.c > > > > @@ -15,6 +15,8 @@ > > > > #include <linux/proc_fs.h> > > > > #include <linux/slab.h> > > > > > > > > +#include <asm/setup.h> > > > > + > > > > #include "pci.h" > > > > > > > > void pci_add_resource_offset(struct list_head *resources, struct resource *res, > > > > @@ -230,6 +232,114 @@ EXPORT_SYMBOL(pci_bus_alloc_resource); > > > > > > > > void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } > > > > > > > > +struct driver_override_entry { > > > > + u16 domain; > > > > + u8 bus; > > > > + u8 devfn; > > > > + char *driver_name; > > > > + struct list_head list; > > > > +}; > > > > + > > > > +static LIST_HEAD(driver_override_entries); > > > > + > > > > +static int pci_device_parse_driver_override(char *param, char *val, > > > > + const char *unused) > > > > +{ > > > > + unsigned int domain, bus, dev, fn; > > > > + char *buf; > > > > + struct driver_override_entry *entry; > > > > + int ret; > > > > + > > > > + buf = kmalloc(COMMAND_LINE_SIZE, GFP_KERNEL); > > > > + if (!buf) > > > > + goto err_buf; > > > > + > > > > + while (val) { > > > > + char *k = strchr(val, ','); > > > > + > > > > + if (k) > > > > + *k++ = 0; > > > > + > > > > + if (strncmp(val, "driver", 6)) { > > > > + val = k; > > > > + continue; > > > > + } > > > > + > > > > + memset(buf, 0, COMMAND_LINE_SIZE); > > > > + ret = sscanf(val + 6, "[%4x:%2x:%2x.%2x]=%s", > > > > + &domain, &bus, &dev, &fn, buf); > > > > + if (ret != 5) { > > > > + pr_warn("PCI: Invalid command line: %s\n", val); > > > > + val = k; > > > > + continue; > > > > + } > > > > + > > > > + entry = kzalloc(sizeof(*entry), GFP_KERNEL); > > > > + if (!entry) > > > > + goto err_entry; > > > > + > > > > + INIT_LIST_HEAD(&entry->list); > > > > + entry->domain = domain; > > > > + entry->bus = bus; > > > > + entry->devfn = PCI_DEVFN(dev, fn); > > > > + entry->driver_name = kstrdup(buf, GFP_KERNEL); > > > > + if (!entry->driver_name) > > > > + goto err_driver_name; > > > > + > > > > + list_add_tail(&entry->list, &driver_override_entries); > > > > + val = k; > > > > + } > > > > + > > > > + kfree(buf); > > > > + return 0; > > > > + > > > > +err_driver_name: > > > > + kfree(entry); > > > > + > > > > +err_entry: > > > > + kfree(buf); > > > > + > > > > +err_buf: > > > > + pr_err("PCI: Out of memory while parsing command line: %s\n", val); > > > > + return -ENOMEM; > > > > +} > > > > + > > > > +static void pci_device_setup_driver_override(struct pci_dev *dev) > > > > +{ > > > > + static int parse_done; > > > > + struct driver_override_entry *entry; > > > > + > > > > + if (!parse_done) { > > > > + char *cmdline = kstrdup(saved_command_line, GFP_KERNEL); > > > > + > > > > + if (!cmdline) > > > > + goto err_out_of_mem; > > > > + > > > > + parse_args("pci", cmdline, NULL, > > > > + 0, 0, 0, &pci_device_parse_driver_override); > > > > + kfree(cmdline); > > > > + parse_done = 1; > > > > + } > > > > + > > > > + list_for_each_entry(entry, &driver_override_entries, list) { > > > > + if (pci_domain_nr(dev->bus) != entry->domain || > > > > + dev->bus->number != entry->bus || > > > > + dev->devfn != entry->devfn) > > > > + continue; > > > > + > > > > + dev->driver_override = kstrdup(entry->driver_name, GFP_KERNEL); > > > > + if (!dev->driver_override) > > > > + goto err_out_of_mem; > > > > + > > > > + break; > > > > + } > > > > + > > > > + return; > > > > + > > > > +err_out_of_mem: > > > > + pr_err("PCI: Out of memory while setting up driver override\n"); > > > > +} > > > > + > > > > /** > > > > * pci_bus_add_device - start driver for a single device > > > > * @dev: device to add > > > > @@ -245,6 +355,7 @@ void pci_bus_add_device(struct pci_dev *dev) > > > > * are not assigned yet for some devices. > > > > */ > > > > pci_fixup_device(pci_fixup_final, dev); > > > > + pci_device_setup_driver_override(dev); > > > > pci_create_sysfs_dev_files(dev); > > > > pci_proc_attach_device(dev); > > > > > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > > > index 625a4ac..37809d4 100644 > > > > --- a/drivers/pci/pci.c > > > > +++ b/drivers/pci/pci.c > > > > @@ -4508,6 +4508,8 @@ static int __init pci_setup(char *str) > > > > pcie_bus_config = PCIE_BUS_PEER2PEER; > > > > } else if (!strncmp(str, "pcie_scan_all", 13)) { > > > > pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS); > > > > + } else if (!strncmp(str, "driver", 6)) { > > > > + /* lazy evaluation by the pci subsystem */ > > > > } else { > > > > printk(KERN_ERR "PCI: Unknown option `%s'\n", > > > > str); > > > > > > > > > > > > > > > > > > > -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
> -----Original Message----- > From: Alex Williamson [mailto:alex.williamson@redhat.com] > Sent: Wednesday, October 22, 2014 1:33 PM > To: Marcel Apfelbaum > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > mst@redhat.com; Yoder Stuart-B08248 > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > [cc+ stuart] > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > Scanning a lot of devices during boot requires a lot of time. > > On other scenarios there is a need to bind a driver to a specific slot. > > > > Binding devices to pci-stub driver does not work, > > as it will not differentiate between devices of the > > same type. Using some start scripts is error prone. > > > > The solution leverages driver_override functionality introduced by > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > Author: Alex Williamson <alex.williamson@redhat.com> > > Date: Tue May 20 08:53:21 2014 -0600 > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > In order to bind PCI slots to specific drivers use: > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > --- > > v3 -> v4: > > - Addressed Alex Williamson's comments: > > - Modified the type of driver_override_entry's fields > > - Used PCI_DEVFN when appropriated > > - Removed redundant checks > > - Replaced BUG_ON with pr_err messages > > - Simpler command line parsing > > - Addressed Michael S. Tsirkin comments > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > v2 -> v3: > > - Corrected subject line > > v1 -> v2: > > - Addressed Michael S. Tsirkin comments > > - Removed 32 slots limitation > > - Better handling of memory allocation failures > > (preferred BUG_ON over error messages) > > - Addressed Alex Williamson's comments: > > - Modified commit message to show parameter usage more clear. > > - I preferred to re-use parse_args instead of manually using > > strstr in order to better comply with command line parsing > > rules. > > - I didn't use any locking when parsing the command line args > > (see parse_done usage) assuming that first call will be > > early in system boot and no race can occur. Please correct > > me if I am wrong. > > > > Notes: > > - I have further ideas on top of this patch based on your reviews. > > I thought of: > > - Use wildcards to specify entire buses/devices, something like: > > driver[0001:02:*.*]=pci-stub > > - Use comma to separate several devices: > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > - Make domain optional: > > driver[00:03.0]=pci-stub > > > > Comments will be appreciated, > > Thanks, > > Marcel > > Documentation/kernel-parameters.txt | 4 ++ > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > drivers/pci/pci.c | 2 + > > 3 files changed, 117 insertions(+) > > The driver_override feature that we're making use of here is also going > to be supported by platform devices and potentially more bustypes in the > future, so I'm concerned that making a pci specific kernel parameter is > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > bustypes that support driver_override so we can have a common interface. > Perhaps: > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > Finding delimiters that don't conflict may be challenging. I think what you proposed works-- <bus-name>,<bus-dev>=<driver>; Think that will work for PCI, platform, and the new fsl-mc bus we are working on. > Also, can we > assume that bus-name:dev-name is unique for every bustype? It is for > pci, platform? I think that has to be the case. > It also seems like there's a question of how long should this override > last and how does the user disable it? Isn't that a general question for the "driver_overrride" mechanism? I'm forgetting if the mechanism in the kernel now has a way to disable it-- e.g. echo /dev/null > /sys/pci/devices/.../driver_override ?? So, it would last until explicitly disabled through sysfs. > I think with pci-stub.ids= > $VENDOR:$DEVICE a user can echo the IDs to the pci-stub/remove_id sysfs > entry to cancel the effect. The only option here seems to be a reboot. > Do we need a /sys/bus/pci/driver_overrides/{add_name,remove_name} for > this interface? Thanks, Thanks, Stuart
> -----Original Message----- > From: Marcel Apfelbaum [mailto:marcel.a@redhat.com] > Sent: Thursday, October 23, 2014 7:32 AM > To: Alex Williamson > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > mst@redhat.com; Yoder Stuart-B08248 > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > On Wed, 2014-10-22 at 12:32 -0600, Alex Williamson wrote: > > [cc+ stuart] > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > Scanning a lot of devices during boot requires a lot of time. > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > Binding devices to pci-stub driver does not work, > > > as it will not differentiate between devices of the > > > same type. Using some start scripts is error prone. > > > > > > The solution leverages driver_override functionality introduced by > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > In order to bind PCI slots to specific drivers use: > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > --- > > > v3 -> v4: > > > - Addressed Alex Williamson's comments: > > > - Modified the type of driver_override_entry's fields > > > - Used PCI_DEVFN when appropriated > > > - Removed redundant checks > > > - Replaced BUG_ON with pr_err messages > > > - Simpler command line parsing > > > - Addressed Michael S. Tsirkin comments > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > v2 -> v3: > > > - Corrected subject line > > > v1 -> v2: > > > - Addressed Michael S. Tsirkin comments > > > - Removed 32 slots limitation > > > - Better handling of memory allocation failures > > > (preferred BUG_ON over error messages) > > > - Addressed Alex Williamson's comments: > > > - Modified commit message to show parameter usage more clear. > > > - I preferred to re-use parse_args instead of manually using > > > strstr in order to better comply with command line parsing > > > rules. > > > - I didn't use any locking when parsing the command line args > > > (see parse_done usage) assuming that first call will be > > > early in system boot and no race can occur. Please correct > > > me if I am wrong. > > > > > > Notes: > > > - I have further ideas on top of this patch based on your reviews. > > > I thought of: > > > - Use wildcards to specify entire buses/devices, something like: > > > driver[0001:02:*.*]=pci-stub > > > - Use comma to separate several devices: > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > - Make domain optional: > > > driver[00:03.0]=pci-stub > > > > > > Comments will be appreciated, > > > Thanks, > > > Marcel > > > Documentation/kernel-parameters.txt | 4 ++ > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > drivers/pci/pci.c | 2 + > > > 3 files changed, 117 insertions(+) > > > > The driver_override feature that we're making use of here is also going > > to be supported by platform devices and potentially more bustypes in the > > future, so I'm concerned that making a pci specific kernel parameter is > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > bustypes that support driver_override so we can have a common interface. > The real question here if those bus types/devices would benefit from this > feature, and I also must confess that I have no knowledge of the other buses. > Can anyone confirm that it does make sense for them? We don't have vfio-platform in use yet, so not much actual real world user experience yet. But, I think it makes sense. Especially, given that we are inventing a kernel parameter I think we should design the syntax so that it can work buses can implement support for this. The driver_override mechanism is not bus specific, so let's not make the kernel parameter bus specific. > > Perhaps: > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > Finding delimiters that don't conflict may be challenging. Also, can we > > assume that bus-name:dev-name is unique for every bustype? It is for > > pci, platform? > For PCI, sure the domain:bus:dev.func is unique, for platform I have no idea, > can anyone that knows "platform" confirm or deny? Yes, dev-name will be unique. All platform devices are under a single platform bus. Stuart
On Thu, 2014-10-23 at 13:51 +0000, Stuart Yoder wrote: > > > -----Original Message----- > > From: Marcel Apfelbaum [mailto:marcel.a@redhat.com] > > Sent: Thursday, October 23, 2014 7:32 AM > > To: Alex Williamson > > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > > mst@redhat.com; Yoder Stuart-B08248 > > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > > > On Wed, 2014-10-22 at 12:32 -0600, Alex Williamson wrote: > > > [cc+ stuart] > > > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > > Scanning a lot of devices during boot requires a lot of time. > > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > > > Binding devices to pci-stub driver does not work, > > > > as it will not differentiate between devices of the > > > > same type. Using some start scripts is error prone. > > > > > > > > The solution leverages driver_override functionality introduced by > > > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > > > In order to bind PCI slots to specific drivers use: > > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > > --- > > > > v3 -> v4: > > > > - Addressed Alex Williamson's comments: > > > > - Modified the type of driver_override_entry's fields > > > > - Used PCI_DEVFN when appropriated > > > > - Removed redundant checks > > > > - Replaced BUG_ON with pr_err messages > > > > - Simpler command line parsing > > > > - Addressed Michael S. Tsirkin comments > > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > > v2 -> v3: > > > > - Corrected subject line > > > > v1 -> v2: > > > > - Addressed Michael S. Tsirkin comments > > > > - Removed 32 slots limitation > > > > - Better handling of memory allocation failures > > > > (preferred BUG_ON over error messages) > > > > - Addressed Alex Williamson's comments: > > > > - Modified commit message to show parameter usage more clear. > > > > - I preferred to re-use parse_args instead of manually using > > > > strstr in order to better comply with command line parsing > > > > rules. > > > > - I didn't use any locking when parsing the command line args > > > > (see parse_done usage) assuming that first call will be > > > > early in system boot and no race can occur. Please correct > > > > me if I am wrong. > > > > > > > > Notes: > > > > - I have further ideas on top of this patch based on your reviews. > > > > I thought of: > > > > - Use wildcards to specify entire buses/devices, something like: > > > > driver[0001:02:*.*]=pci-stub > > > > - Use comma to separate several devices: > > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > > - Make domain optional: > > > > driver[00:03.0]=pci-stub > > > > > > > > Comments will be appreciated, > > > > Thanks, > > > > Marcel > > > > Documentation/kernel-parameters.txt | 4 ++ > > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > > drivers/pci/pci.c | 2 + > > > > 3 files changed, 117 insertions(+) > > > > > > The driver_override feature that we're making use of here is also going > > > to be supported by platform devices and potentially more bustypes in the > > > future, so I'm concerned that making a pci specific kernel parameter is > > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > > bustypes that support driver_override so we can have a common interface. > > The real question here if those bus types/devices would benefit from this > > feature, and I also must confess that I have no knowledge of the other buses. > > Can anyone confirm that it does make sense for them? > > We don't have vfio-platform in use yet, so not much actual real world user > experience yet. But, I think it makes sense. Especially, given that we are > inventing a kernel parameter I think we should design the syntax so that it > can work buses can implement support for this. The driver_override mechanism > is not bus specific, so let's not make the kernel parameter bus specific. Make sense, point taken. I'll come up with something. Thank you Stuart, Marcel > > > > Perhaps: > > > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > > > Finding delimiters that don't conflict may be challenging. Also, can we > > > assume that bus-name:dev-name is unique for every bustype? It is for > > > pci, platform? > > For PCI, sure the domain:bus:dev.func is unique, for platform I have no idea, > > can anyone that knows "platform" confirm or deny? > > Yes, dev-name will be unique. All platform devices are under a single > platform bus. > > Stuart -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2014-10-23 at 13:44 +0000, Stuart Yoder wrote: > > > -----Original Message----- > > From: Alex Williamson [mailto:alex.williamson@redhat.com] > > Sent: Wednesday, October 22, 2014 1:33 PM > > To: Marcel Apfelbaum > > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > > mst@redhat.com; Yoder Stuart-B08248 > > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > > > [cc+ stuart] > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > Scanning a lot of devices during boot requires a lot of time. > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > Binding devices to pci-stub driver does not work, > > > as it will not differentiate between devices of the > > > same type. Using some start scripts is error prone. > > > > > > The solution leverages driver_override functionality introduced by > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > In order to bind PCI slots to specific drivers use: > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > --- > > > v3 -> v4: > > > - Addressed Alex Williamson's comments: > > > - Modified the type of driver_override_entry's fields > > > - Used PCI_DEVFN when appropriated > > > - Removed redundant checks > > > - Replaced BUG_ON with pr_err messages > > > - Simpler command line parsing > > > - Addressed Michael S. Tsirkin comments > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > v2 -> v3: > > > - Corrected subject line > > > v1 -> v2: > > > - Addressed Michael S. Tsirkin comments > > > - Removed 32 slots limitation > > > - Better handling of memory allocation failures > > > (preferred BUG_ON over error messages) > > > - Addressed Alex Williamson's comments: > > > - Modified commit message to show parameter usage more clear. > > > - I preferred to re-use parse_args instead of manually using > > > strstr in order to better comply with command line parsing > > > rules. > > > - I didn't use any locking when parsing the command line args > > > (see parse_done usage) assuming that first call will be > > > early in system boot and no race can occur. Please correct > > > me if I am wrong. > > > > > > Notes: > > > - I have further ideas on top of this patch based on your reviews. > > > I thought of: > > > - Use wildcards to specify entire buses/devices, something like: > > > driver[0001:02:*.*]=pci-stub > > > - Use comma to separate several devices: > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > - Make domain optional: > > > driver[00:03.0]=pci-stub > > > > > > Comments will be appreciated, > > > Thanks, > > > Marcel > > > Documentation/kernel-parameters.txt | 4 ++ > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > drivers/pci/pci.c | 2 + > > > 3 files changed, 117 insertions(+) > > > > The driver_override feature that we're making use of here is also going > > to be supported by platform devices and potentially more bustypes in the > > future, so I'm concerned that making a pci specific kernel parameter is > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > bustypes that support driver_override so we can have a common interface. > > Perhaps: > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > Finding delimiters that don't conflict may be challenging. > > I think what you proposed works-- <bus-name>,<bus-dev>=<driver>; > > Think that will work for PCI, platform, and the new fsl-mc bus we are working > on. > > > Also, can we > > assume that bus-name:dev-name is unique for every bustype? It is for > > pci, platform? > > I think that has to be the case. > > > It also seems like there's a question of how long should this override > > last and how does the user disable it? > > Isn't that a general question for the "driver_overrride" mechanism? > I'm forgetting if the mechanism in the kernel now has a way to disable > it-- e.g. echo /dev/null > /sys/pci/devices/.../driver_override ?? > > So, it would last until explicitly disabled through sysfs. Yes, when you set a driver_override on a device you cancel it by writing a NULL string to the same interface. The problem is that here we have a new entity in the driver scan that keeps re-applying the driver_override as devices are scanned with no way to stop it. So you can certainly undo the immediate effect and bind the device to another driver, but if the device is removed and re-scanned there's no way to stop if from re-applying the override. Thanks, Alex > > I think with pci-stub.ids= > > $VENDOR:$DEVICE a user can echo the IDs to the pci-stub/remove_id sysfs > > entry to cancel the effect. The only option here seems to be a reboot. > > Do we need a /sys/bus/pci/driver_overrides/{add_name,remove_name} for > > this interface? Thanks, > > Thanks, > Stuart -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2014-10-23 at 07:57 -0600, Alex Williamson wrote: > On Thu, 2014-10-23 at 13:44 +0000, Stuart Yoder wrote: > > > > > -----Original Message----- > > > From: Alex Williamson [mailto:alex.williamson@redhat.com] > > > Sent: Wednesday, October 22, 2014 1:33 PM > > > To: Marcel Apfelbaum > > > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > > > mst@redhat.com; Yoder Stuart-B08248 > > > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > > > > > [cc+ stuart] > > > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > > Scanning a lot of devices during boot requires a lot of time. > > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > > > Binding devices to pci-stub driver does not work, > > > > as it will not differentiate between devices of the > > > > same type. Using some start scripts is error prone. > > > > > > > > The solution leverages driver_override functionality introduced by > > > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > > > In order to bind PCI slots to specific drivers use: > > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > > --- > > > > v3 -> v4: > > > > - Addressed Alex Williamson's comments: > > > > - Modified the type of driver_override_entry's fields > > > > - Used PCI_DEVFN when appropriated > > > > - Removed redundant checks > > > > - Replaced BUG_ON with pr_err messages > > > > - Simpler command line parsing > > > > - Addressed Michael S. Tsirkin comments > > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > > v2 -> v3: > > > > - Corrected subject line > > > > v1 -> v2: > > > > - Addressed Michael S. Tsirkin comments > > > > - Removed 32 slots limitation > > > > - Better handling of memory allocation failures > > > > (preferred BUG_ON over error messages) > > > > - Addressed Alex Williamson's comments: > > > > - Modified commit message to show parameter usage more clear. > > > > - I preferred to re-use parse_args instead of manually using > > > > strstr in order to better comply with command line parsing > > > > rules. > > > > - I didn't use any locking when parsing the command line args > > > > (see parse_done usage) assuming that first call will be > > > > early in system boot and no race can occur. Please correct > > > > me if I am wrong. > > > > > > > > Notes: > > > > - I have further ideas on top of this patch based on your reviews. > > > > I thought of: > > > > - Use wildcards to specify entire buses/devices, something like: > > > > driver[0001:02:*.*]=pci-stub > > > > - Use comma to separate several devices: > > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > > - Make domain optional: > > > > driver[00:03.0]=pci-stub > > > > > > > > Comments will be appreciated, > > > > Thanks, > > > > Marcel > > > > Documentation/kernel-parameters.txt | 4 ++ > > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > > drivers/pci/pci.c | 2 + > > > > 3 files changed, 117 insertions(+) > > > > > > The driver_override feature that we're making use of here is also going > > > to be supported by platform devices and potentially more bustypes in the > > > future, so I'm concerned that making a pci specific kernel parameter is > > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > > bustypes that support driver_override so we can have a common interface. > > > Perhaps: > > > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > > > Finding delimiters that don't conflict may be challenging. > > > > I think what you proposed works-- <bus-name>,<bus-dev>=<driver>; > > > > Think that will work for PCI, platform, and the new fsl-mc bus we are working > > on. > > > > > Also, can we > > > assume that bus-name:dev-name is unique for every bustype? It is for > > > pci, platform? > > > > I think that has to be the case. > > > > > It also seems like there's a question of how long should this override > > > last and how does the user disable it? > > > > Isn't that a general question for the "driver_overrride" mechanism? > > I'm forgetting if the mechanism in the kernel now has a way to disable > > it-- e.g. echo /dev/null > /sys/pci/devices/.../driver_override ?? > > > > So, it would last until explicitly disabled through sysfs. > > Yes, when you set a driver_override on a device you cancel it by writing > a NULL string to the same interface. The problem is that here we have a > new entity in the driver scan that keeps re-applying the driver_override > as devices are scanned with no way to stop it. So you can certainly > undo the immediate effect and bind the device to another driver, but if > the device is removed and re-scanned there's no way to stop if from > re-applying the override. Thanks, Hi Alex, I checked the above scenario and after driver_override is cleared an we do bind/unbind, the mapping defined in the command line does not apply anymore. My steps were: 1. define the override in command-line -> the mapped driver is used instead of the native one 2. unbind the device from the slot -> no driver for device 3. remove the driver_override mapping form the slot -> no mapping defined 3, bind the device again -> native driver in use. Thanks, Marcel > > Alex > > > > I think with pci-stub.ids= > > > $VENDOR:$DEVICE a user can echo the IDs to the pci-stub/remove_id sysfs > > > entry to cancel the effect. The only option here seems to be a reboot. > > > Do we need a /sys/bus/pci/driver_overrides/{add_name,remove_name} for > > > this interface? Thanks, > > > > Thanks, > > Stuart > > > -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2014-10-23 at 17:33 +0300, Marcel Apfelbaum wrote: > On Thu, 2014-10-23 at 07:57 -0600, Alex Williamson wrote: > > On Thu, 2014-10-23 at 13:44 +0000, Stuart Yoder wrote: > > > > > > > -----Original Message----- > > > > From: Alex Williamson [mailto:alex.williamson@redhat.com] > > > > Sent: Wednesday, October 22, 2014 1:33 PM > > > > To: Marcel Apfelbaum > > > > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > > > > mst@redhat.com; Yoder Stuart-B08248 > > > > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > > > > > > > [cc+ stuart] > > > > > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > > > Scanning a lot of devices during boot requires a lot of time. > > > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > > > > > Binding devices to pci-stub driver does not work, > > > > > as it will not differentiate between devices of the > > > > > same type. Using some start scripts is error prone. > > > > > > > > > > The solution leverages driver_override functionality introduced by > > > > > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > > > > > In order to bind PCI slots to specific drivers use: > > > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > > > --- > > > > > v3 -> v4: > > > > > - Addressed Alex Williamson's comments: > > > > > - Modified the type of driver_override_entry's fields > > > > > - Used PCI_DEVFN when appropriated > > > > > - Removed redundant checks > > > > > - Replaced BUG_ON with pr_err messages > > > > > - Simpler command line parsing > > > > > - Addressed Michael S. Tsirkin comments > > > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > > > v2 -> v3: > > > > > - Corrected subject line > > > > > v1 -> v2: > > > > > - Addressed Michael S. Tsirkin comments > > > > > - Removed 32 slots limitation > > > > > - Better handling of memory allocation failures > > > > > (preferred BUG_ON over error messages) > > > > > - Addressed Alex Williamson's comments: > > > > > - Modified commit message to show parameter usage more clear. > > > > > - I preferred to re-use parse_args instead of manually using > > > > > strstr in order to better comply with command line parsing > > > > > rules. > > > > > - I didn't use any locking when parsing the command line args > > > > > (see parse_done usage) assuming that first call will be > > > > > early in system boot and no race can occur. Please correct > > > > > me if I am wrong. > > > > > > > > > > Notes: > > > > > - I have further ideas on top of this patch based on your reviews. > > > > > I thought of: > > > > > - Use wildcards to specify entire buses/devices, something like: > > > > > driver[0001:02:*.*]=pci-stub > > > > > - Use comma to separate several devices: > > > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > > > - Make domain optional: > > > > > driver[00:03.0]=pci-stub > > > > > > > > > > Comments will be appreciated, > > > > > Thanks, > > > > > Marcel > > > > > Documentation/kernel-parameters.txt | 4 ++ > > > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > > > drivers/pci/pci.c | 2 + > > > > > 3 files changed, 117 insertions(+) > > > > > > > > The driver_override feature that we're making use of here is also going > > > > to be supported by platform devices and potentially more bustypes in the > > > > future, so I'm concerned that making a pci specific kernel parameter is > > > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > > > bustypes that support driver_override so we can have a common interface. > > > > Perhaps: > > > > > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > > > > > Finding delimiters that don't conflict may be challenging. > > > > > > I think what you proposed works-- <bus-name>,<bus-dev>=<driver>; > > > > > > Think that will work for PCI, platform, and the new fsl-mc bus we are working > > > on. > > > > > > > Also, can we > > > > assume that bus-name:dev-name is unique for every bustype? It is for > > > > pci, platform? > > > > > > I think that has to be the case. > > > > > > > It also seems like there's a question of how long should this override > > > > last and how does the user disable it? > > > > > > Isn't that a general question for the "driver_overrride" mechanism? > > > I'm forgetting if the mechanism in the kernel now has a way to disable > > > it-- e.g. echo /dev/null > /sys/pci/devices/.../driver_override ?? > > > > > > So, it would last until explicitly disabled through sysfs. > > > > Yes, when you set a driver_override on a device you cancel it by writing > > a NULL string to the same interface. The problem is that here we have a > > new entity in the driver scan that keeps re-applying the driver_override > > as devices are scanned with no way to stop it. So you can certainly > > undo the immediate effect and bind the device to another driver, but if > > the device is removed and re-scanned there's no way to stop if from > > re-applying the override. Thanks, > Hi Alex, > > I checked the above scenario and after driver_override is cleared > an we do bind/unbind, the mapping defined in the command line > does not apply anymore. > > My steps were: > 1. define the override in command-line -> the mapped driver is used instead of the native one > 2. unbind the device from the slot -> no driver for device > 3. remove the driver_override mapping form the slot -> no mapping defined > 3, bind the device again -> native driver in use. That's not the scenario I'm describing. Use the remove and rescan sysfs attributes to do a software hotplug and you'll see that the driver_override will always be re-applied to the device. For example: # echo "" > /sys/bus/pci/devices/0000:02:00.0/driver_override # echo 1 > /sys/bus/pci/devices/0000:02:00.0/remove # echo 1 > /sys/bus/pci/rescan # cat /sys/bus/pci/devices/0000:02:00.0/driver_override I expect the last step will show the original override re-applied. Thanks, Alex -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2014-10-23 at 08:49 -0600, Alex Williamson wrote: > On Thu, 2014-10-23 at 17:33 +0300, Marcel Apfelbaum wrote: > > On Thu, 2014-10-23 at 07:57 -0600, Alex Williamson wrote: > > > On Thu, 2014-10-23 at 13:44 +0000, Stuart Yoder wrote: > > > > > > > > > -----Original Message----- > > > > > From: Alex Williamson [mailto:alex.williamson@redhat.com] > > > > > Sent: Wednesday, October 22, 2014 1:33 PM > > > > > To: Marcel Apfelbaum > > > > > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > > > > > mst@redhat.com; Yoder Stuart-B08248 > > > > > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > > > > > > > > > [cc+ stuart] > > > > > > > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > > > > Scanning a lot of devices during boot requires a lot of time. > > > > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > > > > > > > Binding devices to pci-stub driver does not work, > > > > > > as it will not differentiate between devices of the > > > > > > same type. Using some start scripts is error prone. > > > > > > > > > > > > The solution leverages driver_override functionality introduced by > > > > > > > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > > > > > > > In order to bind PCI slots to specific drivers use: > > > > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > > > > --- > > > > > > v3 -> v4: > > > > > > - Addressed Alex Williamson's comments: > > > > > > - Modified the type of driver_override_entry's fields > > > > > > - Used PCI_DEVFN when appropriated > > > > > > - Removed redundant checks > > > > > > - Replaced BUG_ON with pr_err messages > > > > > > - Simpler command line parsing > > > > > > - Addressed Michael S. Tsirkin comments > > > > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > > > > v2 -> v3: > > > > > > - Corrected subject line > > > > > > v1 -> v2: > > > > > > - Addressed Michael S. Tsirkin comments > > > > > > - Removed 32 slots limitation > > > > > > - Better handling of memory allocation failures > > > > > > (preferred BUG_ON over error messages) > > > > > > - Addressed Alex Williamson's comments: > > > > > > - Modified commit message to show parameter usage more clear. > > > > > > - I preferred to re-use parse_args instead of manually using > > > > > > strstr in order to better comply with command line parsing > > > > > > rules. > > > > > > - I didn't use any locking when parsing the command line args > > > > > > (see parse_done usage) assuming that first call will be > > > > > > early in system boot and no race can occur. Please correct > > > > > > me if I am wrong. > > > > > > > > > > > > Notes: > > > > > > - I have further ideas on top of this patch based on your reviews. > > > > > > I thought of: > > > > > > - Use wildcards to specify entire buses/devices, something like: > > > > > > driver[0001:02:*.*]=pci-stub > > > > > > - Use comma to separate several devices: > > > > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > > > > - Make domain optional: > > > > > > driver[00:03.0]=pci-stub > > > > > > > > > > > > Comments will be appreciated, > > > > > > Thanks, > > > > > > Marcel > > > > > > Documentation/kernel-parameters.txt | 4 ++ > > > > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > > > > drivers/pci/pci.c | 2 + > > > > > > 3 files changed, 117 insertions(+) > > > > > > > > > > The driver_override feature that we're making use of here is also going > > > > > to be supported by platform devices and potentially more bustypes in the > > > > > future, so I'm concerned that making a pci specific kernel parameter is > > > > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > > > > bustypes that support driver_override so we can have a common interface. > > > > > Perhaps: > > > > > > > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > > > > > > > Finding delimiters that don't conflict may be challenging. > > > > > > > > I think what you proposed works-- <bus-name>,<bus-dev>=<driver>; > > > > > > > > Think that will work for PCI, platform, and the new fsl-mc bus we are working > > > > on. > > > > > > > > > Also, can we > > > > > assume that bus-name:dev-name is unique for every bustype? It is for > > > > > pci, platform? > > > > > > > > I think that has to be the case. > > > > > > > > > It also seems like there's a question of how long should this override > > > > > last and how does the user disable it? > > > > > > > > Isn't that a general question for the "driver_overrride" mechanism? > > > > I'm forgetting if the mechanism in the kernel now has a way to disable > > > > it-- e.g. echo /dev/null > /sys/pci/devices/.../driver_override ?? > > > > > > > > So, it would last until explicitly disabled through sysfs. > > > > > > Yes, when you set a driver_override on a device you cancel it by writing > > > a NULL string to the same interface. The problem is that here we have a > > > new entity in the driver scan that keeps re-applying the driver_override > > > as devices are scanned with no way to stop it. So you can certainly > > > undo the immediate effect and bind the device to another driver, but if > > > the device is removed and re-scanned there's no way to stop if from > > > re-applying the override. Thanks, > > Hi Alex, > > > > I checked the above scenario and after driver_override is cleared > > an we do bind/unbind, the mapping defined in the command line > > does not apply anymore. > > > > My steps were: > > 1. define the override in command-line -> the mapped driver is used instead of the native one > > 2. unbind the device from the slot -> no driver for device > > 3. remove the driver_override mapping form the slot -> no mapping defined > > 3, bind the device again -> native driver in use. > > That's not the scenario I'm describing. Use the remove and rescan sysfs > attributes to do a software hotplug and you'll see that the > driver_override will always be re-applied to the device. For example: > > # echo "" > /sys/bus/pci/devices/0000:02:00.0/driver_override > # echo 1 > /sys/bus/pci/devices/0000:02:00.0/remove > # echo 1 > /sys/bus/pci/rescan > # cat /sys/bus/pci/devices/0000:02:00.0/driver_override > > I expect the last step will show the original override re-applied. I can check this, but I am sure you are right. We need to think about this, if is acceptable or not. Thanks, Marcel > Thanks, > > Alex > -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
DQoNCj4gLS0tLS1PcmlnaW5hbCBNZXNzYWdlLS0tLS0NCj4gRnJvbTogTWFyY2VsIEFwZmVsYmF1 bSBbbWFpbHRvOm1hcmNlbC5hQHJlZGhhdC5jb21dDQo+IFNlbnQ6IFRodXJzZGF5LCBPY3RvYmVy IDIzLCAyMDE0IDg6MzcgQU0NCj4gVG86IEFsZXggV2lsbGlhbXNvbg0KPiBDYzogbGludXgtcGNp QHZnZXIua2VybmVsLm9yZzsgYmhlbGdhYXNAZ29vZ2xlLmNvbTsgbGludXgta2VybmVsQHZnZXIu a2VybmVsLm9yZzsgbWFyY2VsQHJlZGhhdC5jb207DQo+IG1zdEByZWRoYXQuY29tOyBZb2RlciBT dHVhcnQtQjA4MjQ4DQo+IFN1YmplY3Q6IFJlOiBbUEFUQ0ggdjRdIFBDSTogYWRkIGtlcm5lbCBw YXJhbWV0ZXIgdG8gb3ZlcnJpZGUgZGV2aWQ8LT5kcml2ZXIgbWFwcGluZy4NCj4gDQo+IE9uIFRo dSwgMjAxNC0xMC0yMyBhdCAwNzoxMSAtMDYwMCwgQWxleCBXaWxsaWFtc29uIHdyb3RlOg0KPiA+ IE9uIFRodSwgMjAxNC0xMC0yMyBhdCAxNTozMiArMDMwMCwgTWFyY2VsIEFwZ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ZXJbeHh4eF09Zm9vLGRyaXZl clt4eHh4XT12ZmlvLXBsYXRmb3JtDQogICBwY2k9ZHJpdmVyW3h4eHg6eHg6eHgueF09Zm9vLGRy aXZlclt4eHh4Onh4Onh4LnhdPWJhcg0KDQpTbyBubyBzdHJvbmcgb3BpbmlvbiBvbiB0aGF0IHZz IEFsZXgncyBwcm9wb3NhbDoNCg0KICAgZHJpdmVyX292ZXJyaWRlPXBjaSwwMDAwOjAyOjAwLjA9 cGNpLXN0dWI7cGxhdGZvcm0seHh4eD12ZmlvLXBsYXRmb3JtDQoNCkl0IHNlZW1zIHRvIG1lIHRo YXQgZWl0aGVyIGNvdWxkIHdvcmsuDQoNClRoYW5rcywNClN0dWFydA0K -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2014-10-23 at 18:00 +0300, Marcel Apfelbaum wrote: > On Thu, 2014-10-23 at 08:49 -0600, Alex Williamson wrote: > > On Thu, 2014-10-23 at 17:33 +0300, Marcel Apfelbaum wrote: > > > On Thu, 2014-10-23 at 07:57 -0600, Alex Williamson wrote: > > > > On Thu, 2014-10-23 at 13:44 +0000, Stuart Yoder wrote: > > > > > > > > > > > -----Original Message----- > > > > > > From: Alex Williamson [mailto:alex.williamson@redhat.com] > > > > > > Sent: Wednesday, October 22, 2014 1:33 PM > > > > > > To: Marcel Apfelbaum > > > > > > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > > > > > > mst@redhat.com; Yoder Stuart-B08248 > > > > > > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > > > > > > > > > > > [cc+ stuart] > > > > > > > > > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > > > > > Scanning a lot of devices during boot requires a lot of time. > > > > > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > > > > > > > > > Binding devices to pci-stub driver does not work, > > > > > > > as it will not differentiate between devices of the > > > > > > > same type. Using some start scripts is error prone. > > > > > > > > > > > > > > The solution leverages driver_override functionality introduced by > > > > > > > > > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > > > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > > > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > > > > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > > > > > > > > > In order to bind PCI slots to specific drivers use: > > > > > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > > > > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > > > > > --- > > > > > > > v3 -> v4: > > > > > > > - Addressed Alex Williamson's comments: > > > > > > > - Modified the type of driver_override_entry's fields > > > > > > > - Used PCI_DEVFN when appropriated > > > > > > > - Removed redundant checks > > > > > > > - Replaced BUG_ON with pr_err messages > > > > > > > - Simpler command line parsing > > > > > > > - Addressed Michael S. Tsirkin comments > > > > > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > > > > > v2 -> v3: > > > > > > > - Corrected subject line > > > > > > > v1 -> v2: > > > > > > > - Addressed Michael S. Tsirkin comments > > > > > > > - Removed 32 slots limitation > > > > > > > - Better handling of memory allocation failures > > > > > > > (preferred BUG_ON over error messages) > > > > > > > - Addressed Alex Williamson's comments: > > > > > > > - Modified commit message to show parameter usage more clear. > > > > > > > - I preferred to re-use parse_args instead of manually using > > > > > > > strstr in order to better comply with command line parsing > > > > > > > rules. > > > > > > > - I didn't use any locking when parsing the command line args > > > > > > > (see parse_done usage) assuming that first call will be > > > > > > > early in system boot and no race can occur. Please correct > > > > > > > me if I am wrong. > > > > > > > > > > > > > > Notes: > > > > > > > - I have further ideas on top of this patch based on your reviews. > > > > > > > I thought of: > > > > > > > - Use wildcards to specify entire buses/devices, something like: > > > > > > > driver[0001:02:*.*]=pci-stub > > > > > > > - Use comma to separate several devices: > > > > > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > > > > > - Make domain optional: > > > > > > > driver[00:03.0]=pci-stub > > > > > > > > > > > > > > Comments will be appreciated, > > > > > > > Thanks, > > > > > > > Marcel > > > > > > > Documentation/kernel-parameters.txt | 4 ++ > > > > > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > > > > > drivers/pci/pci.c | 2 + > > > > > > > 3 files changed, 117 insertions(+) > > > > > > > > > > > > The driver_override feature that we're making use of here is also going > > > > > > to be supported by platform devices and potentially more bustypes in the > > > > > > future, so I'm concerned that making a pci specific kernel parameter is > > > > > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > > > > > bustypes that support driver_override so we can have a common interface. > > > > > > Perhaps: > > > > > > > > > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > > > > > > > > > Finding delimiters that don't conflict may be challenging. > > > > > > > > > > I think what you proposed works-- <bus-name>,<bus-dev>=<driver>; > > > > > > > > > > Think that will work for PCI, platform, and the new fsl-mc bus we are working > > > > > on. > > > > > > > > > > > Also, can we > > > > > > assume that bus-name:dev-name is unique for every bustype? It is for > > > > > > pci, platform? > > > > > > > > > > I think that has to be the case. > > > > > > > > > > > It also seems like there's a question of how long should this override > > > > > > last and how does the user disable it? > > > > > > > > > > Isn't that a general question for the "driver_overrride" mechanism? > > > > > I'm forgetting if the mechanism in the kernel now has a way to disable > > > > > it-- e.g. echo /dev/null > /sys/pci/devices/.../driver_override ?? > > > > > > > > > > So, it would last until explicitly disabled through sysfs. > > > > > > > > Yes, when you set a driver_override on a device you cancel it by writing > > > > a NULL string to the same interface. The problem is that here we have a > > > > new entity in the driver scan that keeps re-applying the driver_override > > > > as devices are scanned with no way to stop it. So you can certainly > > > > undo the immediate effect and bind the device to another driver, but if > > > > the device is removed and re-scanned there's no way to stop if from > > > > re-applying the override. Thanks, > > > Hi Alex, > > > > > > I checked the above scenario and after driver_override is cleared > > > an we do bind/unbind, the mapping defined in the command line > > > does not apply anymore. > > > > > > My steps were: > > > 1. define the override in command-line -> the mapped driver is used instead of the native one > > > 2. unbind the device from the slot -> no driver for device > > > 3. remove the driver_override mapping form the slot -> no mapping defined > > > 3, bind the device again -> native driver in use. > > > > That's not the scenario I'm describing. Use the remove and rescan sysfs > > attributes to do a software hotplug and you'll see that the > > driver_override will always be re-applied to the device. For example: > > > > # echo "" > /sys/bus/pci/devices/0000:02:00.0/driver_override > > # echo 1 > /sys/bus/pci/devices/0000:02:00.0/remove > > # echo 1 > /sys/bus/pci/rescan > > # cat /sys/bus/pci/devices/0000:02:00.0/driver_override > > > > I expect the last step will show the original override re-applied. > I can check this, but I am sure you are right. > We need to think about this, if is acceptable or not. I think we're going to need a sysfs way to manipulate the set of active overrides. I was thinking about whether a one-shot implementation might be acceptable, ie. discard the override after use, but I think that would look just as unpredictable to users as the current approach. Thanks, Alex -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thu, 2014-10-23 at 09:54 -0600, Alex Williamson wrote: > On Thu, 2014-10-23 at 18:00 +0300, Marcel Apfelbaum wrote: > > On Thu, 2014-10-23 at 08:49 -0600, Alex Williamson wrote: > > > On Thu, 2014-10-23 at 17:33 +0300, Marcel Apfelbaum wrote: > > > > On Thu, 2014-10-23 at 07:57 -0600, Alex Williamson wrote: > > > > > On Thu, 2014-10-23 at 13:44 +0000, Stuart Yoder wrote: > > > > > > > > > > > > > -----Original Message----- > > > > > > > From: Alex Williamson [mailto:alex.williamson@redhat.com] > > > > > > > Sent: Wednesday, October 22, 2014 1:33 PM > > > > > > > To: Marcel Apfelbaum > > > > > > > Cc: linux-pci@vger.kernel.org; bhelgaas@google.com; linux-kernel@vger.kernel.org; marcel@redhat.com; > > > > > > > mst@redhat.com; Yoder Stuart-B08248 > > > > > > > Subject: Re: [PATCH v4] PCI: add kernel parameter to override devid<->driver mapping. > > > > > > > > > > > > > > [cc+ stuart] > > > > > > > > > > > > > > On Mon, 2014-10-20 at 17:04 +0300, Marcel Apfelbaum wrote: > > > > > > > > Scanning a lot of devices during boot requires a lot of time. > > > > > > > > On other scenarios there is a need to bind a driver to a specific slot. > > > > > > > > > > > > > > > > Binding devices to pci-stub driver does not work, > > > > > > > > as it will not differentiate between devices of the > > > > > > > > same type. Using some start scripts is error prone. > > > > > > > > > > > > > > > > The solution leverages driver_override functionality introduced by > > > > > > > > > > > > > > > > commit: 782a985d7af26db39e86070d28f987cad21313c0 > > > > > > > > Author: Alex Williamson <alex.williamson@redhat.com> > > > > > > > > Date: Tue May 20 08:53:21 2014 -0600 > > > > > > > > > > > > > > > > PCI: Introduce new device binding path using pci_dev.driver_override > > > > > > > > > > > > > > > > In order to bind PCI slots to specific drivers use: > > > > > > > > pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... > > > > > > > > > > > > > > > > Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> > > > > > > > > --- > > > > > > > > v3 -> v4: > > > > > > > > - Addressed Alex Williamson's comments: > > > > > > > > - Modified the type of driver_override_entry's fields > > > > > > > > - Used PCI_DEVFN when appropriated > > > > > > > > - Removed redundant checks > > > > > > > > - Replaced BUG_ON with pr_err messages > > > > > > > > - Simpler command line parsing > > > > > > > > - Addressed Michael S. Tsirkin comments > > > > > > > > - removed DRIVER_OVERRIDE_NAME_LENGTH limitation > > > > > > > > v2 -> v3: > > > > > > > > - Corrected subject line > > > > > > > > v1 -> v2: > > > > > > > > - Addressed Michael S. Tsirkin comments > > > > > > > > - Removed 32 slots limitation > > > > > > > > - Better handling of memory allocation failures > > > > > > > > (preferred BUG_ON over error messages) > > > > > > > > - Addressed Alex Williamson's comments: > > > > > > > > - Modified commit message to show parameter usage more clear. > > > > > > > > - I preferred to re-use parse_args instead of manually using > > > > > > > > strstr in order to better comply with command line parsing > > > > > > > > rules. > > > > > > > > - I didn't use any locking when parsing the command line args > > > > > > > > (see parse_done usage) assuming that first call will be > > > > > > > > early in system boot and no race can occur. Please correct > > > > > > > > me if I am wrong. > > > > > > > > > > > > > > > > Notes: > > > > > > > > - I have further ideas on top of this patch based on your reviews. > > > > > > > > I thought of: > > > > > > > > - Use wildcards to specify entire buses/devices, something like: > > > > > > > > driver[0001:02:*.*]=pci-stub > > > > > > > > - Use comma to separate several devices: > > > > > > > > driver[0001:02:03.4,0001:02:04.0,...]=pci-stub > > > > > > > > - Make domain optional: > > > > > > > > driver[00:03.0]=pci-stub > > > > > > > > > > > > > > > > Comments will be appreciated, > > > > > > > > Thanks, > > > > > > > > Marcel > > > > > > > > Documentation/kernel-parameters.txt | 4 ++ > > > > > > > > drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ > > > > > > > > drivers/pci/pci.c | 2 + > > > > > > > > 3 files changed, 117 insertions(+) > > > > > > > > > > > > > > The driver_override feature that we're making use of here is also going > > > > > > > to be supported by platform devices and potentially more bustypes in the > > > > > > > future, so I'm concerned that making a pci specific kernel parameter is > > > > > > > too shortsighted. Instead we could hook on to BUS_NOTIFY_ADD_DEVICE for > > > > > > > bustypes that support driver_override so we can have a common interface. > > > > > > > Perhaps: > > > > > > > > > > > > > > driver_override=pci,0000:02:00.0=pci-stub;platform,fakename=vfio-platform > > > > > > > > > > > > > > Finding delimiters that don't conflict may be challenging. > > > > > > > > > > > > I think what you proposed works-- <bus-name>,<bus-dev>=<driver>; > > > > > > > > > > > > Think that will work for PCI, platform, and the new fsl-mc bus we are working > > > > > > on. > > > > > > > > > > > > > Also, can we > > > > > > > assume that bus-name:dev-name is unique for every bustype? It is for > > > > > > > pci, platform? > > > > > > > > > > > > I think that has to be the case. > > > > > > > > > > > > > It also seems like there's a question of how long should this override > > > > > > > last and how does the user disable it? > > > > > > > > > > > > Isn't that a general question for the "driver_overrride" mechanism? > > > > > > I'm forgetting if the mechanism in the kernel now has a way to disable > > > > > > it-- e.g. echo /dev/null > /sys/pci/devices/.../driver_override ?? > > > > > > > > > > > > So, it would last until explicitly disabled through sysfs. > > > > > > > > > > Yes, when you set a driver_override on a device you cancel it by writing > > > > > a NULL string to the same interface. The problem is that here we have a > > > > > new entity in the driver scan that keeps re-applying the driver_override > > > > > as devices are scanned with no way to stop it. So you can certainly > > > > > undo the immediate effect and bind the device to another driver, but if > > > > > the device is removed and re-scanned there's no way to stop if from > > > > > re-applying the override. Thanks, > > > > Hi Alex, > > > > > > > > I checked the above scenario and after driver_override is cleared > > > > an we do bind/unbind, the mapping defined in the command line > > > > does not apply anymore. > > > > > > > > My steps were: > > > > 1. define the override in command-line -> the mapped driver is used instead of the native one > > > > 2. unbind the device from the slot -> no driver for device > > > > 3. remove the driver_override mapping form the slot -> no mapping defined > > > > 3, bind the device again -> native driver in use. > > > > > > That's not the scenario I'm describing. Use the remove and rescan sysfs > > > attributes to do a software hotplug and you'll see that the > > > driver_override will always be re-applied to the device. For example: > > > > > > # echo "" > /sys/bus/pci/devices/0000:02:00.0/driver_override > > > # echo 1 > /sys/bus/pci/devices/0000:02:00.0/remove > > > # echo 1 > /sys/bus/pci/rescan > > > # cat /sys/bus/pci/devices/0000:02:00.0/driver_override > > > > > > I expect the last step will show the original override re-applied. > > I can check this, but I am sure you are right. > > We need to think about this, if is acceptable or not. > > I think we're going to need a sysfs way to manipulate the set of active > overrides. I was thinking about whether a one-shot implementation might > be acceptable, ie. discard the override after use, but I think that > would look just as unpredictable to users as the current approach. > Thanks, Sure, maybe a /sys/bus/<bus type>/driver_overrides file that has the same format as the kernel parameter (and can be edited by the end user) or something based on operations like you suggested: /sys/bus/pci/driver_overrides/{add_name,remove_name} Thanks for the ideas, Marcel > > Alex > -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt index 5ae8608..c1cbb4c 100644 --- a/Documentation/kernel-parameters.txt +++ b/Documentation/kernel-parameters.txt @@ -2631,6 +2631,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted. pcie_scan_all Scan all possible PCIe devices. Otherwise we only look for one device below a PCIe downstream port. + driver Provide an override to the devid<->driver mapping + for a specific slot. + Bind PCI slot 0001:02:03.4 to pci-stub by: + driver[0001:02:03.4]=pci-stub pcie_aspm= [PCIE] Forcibly enable or disable PCIe Active State Power Management. diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 73aef51..b49f5cc 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -15,6 +15,8 @@ #include <linux/proc_fs.h> #include <linux/slab.h> +#include <asm/setup.h> + #include "pci.h" void pci_add_resource_offset(struct list_head *resources, struct resource *res, @@ -230,6 +232,114 @@ EXPORT_SYMBOL(pci_bus_alloc_resource); void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } +struct driver_override_entry { + u16 domain; + u8 bus; + u8 devfn; + char *driver_name; + struct list_head list; +}; + +static LIST_HEAD(driver_override_entries); + +static int pci_device_parse_driver_override(char *param, char *val, + const char *unused) +{ + unsigned int domain, bus, dev, fn; + char *buf; + struct driver_override_entry *entry; + int ret; + + buf = kmalloc(COMMAND_LINE_SIZE, GFP_KERNEL); + if (!buf) + goto err_buf; + + while (val) { + char *k = strchr(val, ','); + + if (k) + *k++ = 0; + + if (strncmp(val, "driver", 6)) { + val = k; + continue; + } + + memset(buf, 0, COMMAND_LINE_SIZE); + ret = sscanf(val + 6, "[%4x:%2x:%2x.%2x]=%s", + &domain, &bus, &dev, &fn, buf); + if (ret != 5) { + pr_warn("PCI: Invalid command line: %s\n", val); + val = k; + continue; + } + + entry = kzalloc(sizeof(*entry), GFP_KERNEL); + if (!entry) + goto err_entry; + + INIT_LIST_HEAD(&entry->list); + entry->domain = domain; + entry->bus = bus; + entry->devfn = PCI_DEVFN(dev, fn); + entry->driver_name = kstrdup(buf, GFP_KERNEL); + if (!entry->driver_name) + goto err_driver_name; + + list_add_tail(&entry->list, &driver_override_entries); + val = k; + } + + kfree(buf); + return 0; + +err_driver_name: + kfree(entry); + +err_entry: + kfree(buf); + +err_buf: + pr_err("PCI: Out of memory while parsing command line: %s\n", val); + return -ENOMEM; +} + +static void pci_device_setup_driver_override(struct pci_dev *dev) +{ + static int parse_done; + struct driver_override_entry *entry; + + if (!parse_done) { + char *cmdline = kstrdup(saved_command_line, GFP_KERNEL); + + if (!cmdline) + goto err_out_of_mem; + + parse_args("pci", cmdline, NULL, + 0, 0, 0, &pci_device_parse_driver_override); + kfree(cmdline); + parse_done = 1; + } + + list_for_each_entry(entry, &driver_override_entries, list) { + if (pci_domain_nr(dev->bus) != entry->domain || + dev->bus->number != entry->bus || + dev->devfn != entry->devfn) + continue; + + dev->driver_override = kstrdup(entry->driver_name, GFP_KERNEL); + if (!dev->driver_override) + goto err_out_of_mem; + + break; + } + + return; + +err_out_of_mem: + pr_err("PCI: Out of memory while setting up driver override\n"); +} + /** * pci_bus_add_device - start driver for a single device * @dev: device to add @@ -245,6 +355,7 @@ void pci_bus_add_device(struct pci_dev *dev) * are not assigned yet for some devices. */ pci_fixup_device(pci_fixup_final, dev); + pci_device_setup_driver_override(dev); pci_create_sysfs_dev_files(dev); pci_proc_attach_device(dev); diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 625a4ac..37809d4 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -4508,6 +4508,8 @@ static int __init pci_setup(char *str) pcie_bus_config = PCIE_BUS_PEER2PEER; } else if (!strncmp(str, "pcie_scan_all", 13)) { pci_add_flags(PCI_SCAN_ALL_PCIE_DEVS); + } else if (!strncmp(str, "driver", 6)) { + /* lazy evaluation by the pci subsystem */ } else { printk(KERN_ERR "PCI: Unknown option `%s'\n", str);
Scanning a lot of devices during boot requires a lot of time. On other scenarios there is a need to bind a driver to a specific slot. Binding devices to pci-stub driver does not work, as it will not differentiate between devices of the same type. Using some start scripts is error prone. The solution leverages driver_override functionality introduced by commit: 782a985d7af26db39e86070d28f987cad21313c0 Author: Alex Williamson <alex.williamson@redhat.com> Date: Tue May 20 08:53:21 2014 -0600 PCI: Introduce new device binding path using pci_dev.driver_override In order to bind PCI slots to specific drivers use: pci=driver[xxxx:xx:xx.x]=foo,driver[xxxx:xx:xx.x]=bar,... Signed-off-by: Marcel Apfelbaum <marcel.a@redhat.com> --- v3 -> v4: - Addressed Alex Williamson's comments: - Modified the type of driver_override_entry's fields - Used PCI_DEVFN when appropriated - Removed redundant checks - Replaced BUG_ON with pr_err messages - Simpler command line parsing - Addressed Michael S. Tsirkin comments - removed DRIVER_OVERRIDE_NAME_LENGTH limitation v2 -> v3: - Corrected subject line v1 -> v2: - Addressed Michael S. Tsirkin comments - Removed 32 slots limitation - Better handling of memory allocation failures (preferred BUG_ON over error messages) - Addressed Alex Williamson's comments: - Modified commit message to show parameter usage more clear. - I preferred to re-use parse_args instead of manually using strstr in order to better comply with command line parsing rules. - I didn't use any locking when parsing the command line args (see parse_done usage) assuming that first call will be early in system boot and no race can occur. Please correct me if I am wrong. Notes: - I have further ideas on top of this patch based on your reviews. I thought of: - Use wildcards to specify entire buses/devices, something like: driver[0001:02:*.*]=pci-stub - Use comma to separate several devices: driver[0001:02:03.4,0001:02:04.0,...]=pci-stub - Make domain optional: driver[00:03.0]=pci-stub Comments will be appreciated, Thanks, Marcel Documentation/kernel-parameters.txt | 4 ++ drivers/pci/bus.c | 111 ++++++++++++++++++++++++++++++++++++ drivers/pci/pci.c | 2 + 3 files changed, 117 insertions(+)