diff mbox

[1/5] vfio-pci: Allow PCI IDs to be specified as module options

Message ID 20150304200243.26766.556.stgit@gimli.home (mailing list archive)
State New, archived
Headers show

Commit Message

Alex Williamson March 4, 2015, 8:02 p.m. UTC
This copies the same support from pci-stub for exactly the same
purpose, enabling a set of PCI IDs to be automatically added to the
driver's dynamic ID table at module load time.  The code here is
pretty simple and both vfio-pci and pci-stub are fairly unique in
being meta drivers, capable of attaching to any device, so there's no
attempt made to generalize the code into pci-core.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 drivers/vfio/pci/vfio_pci.c |   46 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Bandan Das March 4, 2015, 8:49 p.m. UTC | #1
Hi Alex,

Alex Williamson <alex.williamson@redhat.com> writes:
...
> +		if (fields < 2) {
> +			pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
> +			continue;
> +		}
> +
> +		pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
> +			vendor, device, subvendor, subdevice,
> +			class, class_mask);
> +
> +		rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
> +				   subvendor, subdevice, class, class_mask, 0);
> +		if (rc)
> +			pr_warn("vfio-pci: failed to add dynamic id (%d)\n",
> +				rc);
Just a minor observation - maybe we should print out the
vendor/device/subvendor/subdevice as part of the failure message too. The info
message could potentially get lost in a system with high syslog traffic.

Bandan

> +	}
> +}
> +
>  static int __init vfio_pci_init(void)
>  {
>  	int ret;
> @@ -1053,6 +1097,8 @@ static int __init vfio_pci_init(void)
>  	if (ret)
>  		goto out_driver;
>  
> +	vfio_pci_fill_ids();
> +
>  	return 0;
>  
>  out_driver:
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alex Williamson March 4, 2015, 10:18 p.m. UTC | #2
On Wed, 2015-03-04 at 15:49 -0500, Bandan Das wrote:
> Hi Alex,
> 
> Alex Williamson <alex.williamson@redhat.com> writes:
> ...
> > +		if (fields < 2) {
> > +			pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
> > +			continue;
> > +		}
> > +
> > +		pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
> > +			vendor, device, subvendor, subdevice,
> > +			class, class_mask);
> > +
> > +		rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
> > +				   subvendor, subdevice, class, class_mask, 0);
> > +		if (rc)
> > +			pr_warn("vfio-pci: failed to add dynamic id (%d)\n",
> > +				rc);
> Just a minor observation - maybe we should print out the
> vendor/device/subvendor/subdevice as part of the failure message too. The info
> message could potentially get lost in a system with high syslog traffic.

Thanks for the comment.  I don't think we want to duplicate the pr_info
above it, so are you thinking something like this?

                if (fields < 2) {
                        pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
                        continue;
                }

                rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
                                   subvendor, subdevice, class, class_mask, 0);
                if (rc)
                        pr_warn("vfio-pci: failed to add dynamic id: %04X:%04X sub=%04X:%04X cls=%08X/%08X (%d)\n",
                                vendor, device, subvendor, subdevice,
                                class, class_mask, rc);
                else
                        pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
                                vendor, device, subvendor, subdevice,
                                class, class_mask);
        }


> > +	}
> > +}
> > +
> >  static int __init vfio_pci_init(void)
> >  {
> >  	int ret;
> > @@ -1053,6 +1097,8 @@ static int __init vfio_pci_init(void)
> >  	if (ret)
> >  		goto out_driver;
> >  
> > +	vfio_pci_fill_ids();
> > +
> >  	return 0;
> >  
> >  out_driver:
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bandan Das March 4, 2015, 10:32 p.m. UTC | #3
Alex Williamson <alex.williamson@redhat.com> writes:

> On Wed, 2015-03-04 at 15:49 -0500, Bandan Das wrote:
>> Hi Alex,
>> 
>> Alex Williamson <alex.williamson@redhat.com> writes:
>> ...
>> > +		if (fields < 2) {
>> > +			pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
>> > +			continue;
>> > +		}
>> > +
>> > +		pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
>> > +			vendor, device, subvendor, subdevice,
>> > +			class, class_mask);
>> > +
>> > +		rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
>> > +				   subvendor, subdevice, class, class_mask, 0);
>> > +		if (rc)
>> > +			pr_warn("vfio-pci: failed to add dynamic id (%d)\n",
>> > +				rc);
>> Just a minor observation - maybe we should print out the
>> vendor/device/subvendor/subdevice as part of the failure message too. The info
>> message could potentially get lost in a system with high syslog traffic.
>
> Thanks for the comment.  I don't think we want to duplicate the pr_info
> above it, so are you thinking something like this?
>
>                 if (fields < 2) {
>                         pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
>                         continue;
>                 }
>
>                 rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
>                                    subvendor, subdevice, class, class_mask, 0);
>                 if (rc)
>                         pr_warn("vfio-pci: failed to add dynamic id: %04X:%04X sub=%04X:%04X cls=%08X/%08X (%d)\n",
>                                 vendor, device, subvendor, subdevice,
>                                 class, class_mask, rc);
>                 else
>                         pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
>                                 vendor, device, subvendor, subdevice,
>                                 class, class_mask);
>         }

Yep, this is good. (BTW, we can define pr_fmt at the top of the file and avoid
the "vfio-pci" prefix)

>
>> > +	}
>> > +}
>> > +
>> >  static int __init vfio_pci_init(void)
>> >  {
>> >  	int ret;
>> > @@ -1053,6 +1097,8 @@ static int __init vfio_pci_init(void)
>> >  	if (ret)
>> >  		goto out_driver;
>> >  
>> > +	vfio_pci_fill_ids();
>> > +
>> >  	return 0;
>> >  
>> >  out_driver:
>> >
>> > --
>> > To unsubscribe from this list: send the line "unsubscribe kvm" in
>> > the body of a message to majordomo@vger.kernel.org
>> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alex Williamson March 4, 2015, 11:01 p.m. UTC | #4
On Wed, 2015-03-04 at 17:32 -0500, Bandan Das wrote:
> Alex Williamson <alex.williamson@redhat.com> writes:
> 
> > On Wed, 2015-03-04 at 15:49 -0500, Bandan Das wrote:
> >> Hi Alex,
> >> 
> >> Alex Williamson <alex.williamson@redhat.com> writes:
> >> ...
> >> > +		if (fields < 2) {
> >> > +			pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
> >> > +			continue;
> >> > +		}
> >> > +
> >> > +		pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
> >> > +			vendor, device, subvendor, subdevice,
> >> > +			class, class_mask);
> >> > +
> >> > +		rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
> >> > +				   subvendor, subdevice, class, class_mask, 0);
> >> > +		if (rc)
> >> > +			pr_warn("vfio-pci: failed to add dynamic id (%d)\n",
> >> > +				rc);
> >> Just a minor observation - maybe we should print out the
> >> vendor/device/subvendor/subdevice as part of the failure message too. The info
> >> message could potentially get lost in a system with high syslog traffic.
> >
> > Thanks for the comment.  I don't think we want to duplicate the pr_info
> > above it, so are you thinking something like this?
> >
> >                 if (fields < 2) {
> >                         pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
> >                         continue;
> >                 }
> >
> >                 rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
> >                                    subvendor, subdevice, class, class_mask, 0);
> >                 if (rc)
> >                         pr_warn("vfio-pci: failed to add dynamic id: %04X:%04X sub=%04X:%04X cls=%08X/%08X (%d)\n",
> >                                 vendor, device, subvendor, subdevice,
> >                                 class, class_mask, rc);
> >                 else
> >                         pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
> >                                 vendor, device, subvendor, subdevice,
> >                                 class, class_mask);
> >         }
> 
> Yep, this is good. (BTW, we can define pr_fmt at the top of the file and avoid
> the "vfio-pci" prefix)

Cool, I'll remove the "vfio-pci: " prefixes and define the standard:

#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

Thanks!

> >> > +	}
> >> > +}
> >> > +
> >> >  static int __init vfio_pci_init(void)
> >> >  {
> >> >  	int ret;
> >> > @@ -1053,6 +1097,8 @@ static int __init vfio_pci_init(void)
> >> >  	if (ret)
> >> >  		goto out_driver;
> >> >  
> >> > +	vfio_pci_fill_ids();
> >> > +
> >> >  	return 0;
> >> >  
> >> >  out_driver:
> >> >
> >> > --
> >> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> >> > the body of a message to majordomo@vger.kernel.org
> >> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> >
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas March 6, 2015, 10:11 p.m. UTC | #5
On Wed, Mar 04, 2015 at 01:02:43PM -0700, Alex Williamson wrote:
> This copies the same support from pci-stub for exactly the same
> purpose, enabling a set of PCI IDs to be automatically added to the
> driver's dynamic ID table at module load time.  The code here is
> pretty simple and both vfio-pci and pci-stub are fairly unique in
> being meta drivers, capable of attaching to any device, so there's no
> attempt made to generalize the code into pci-core.
> 
> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> ---
>  drivers/vfio/pci/vfio_pci.c |   46 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> index f8a1863..b3bae4c 100644
> --- a/drivers/vfio/pci/vfio_pci.c
> +++ b/drivers/vfio/pci/vfio_pci.c
> @@ -32,6 +32,10 @@
>  #define DRIVER_AUTHOR   "Alex Williamson <alex.williamson@redhat.com>"
>  #define DRIVER_DESC     "VFIO PCI - User Level meta-driver"
>  
> +static char ids[1024] __initdata;
> +module_param_string(ids, ids, sizeof(ids), 0);
> +MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the vfio driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified");
> +
>  static bool nointxmask;
>  module_param_named(nointxmask, nointxmask, bool, S_IRUGO | S_IWUSR);
>  MODULE_PARM_DESC(nointxmask,
> @@ -1034,6 +1038,46 @@ static void __exit vfio_pci_cleanup(void)
>  	vfio_pci_uninit_perm_bits();
>  }
>  
> +static void __init vfio_pci_fill_ids(void)
> +{
> +	char *p, *id;
> +	int rc;
> +
> +	/* no ids passed actually */
> +	if (ids[0] == '\0')
> +		return;
> +
> +	/* add ids specified in the module parameter */
> +	p = ids;
> +	while ((id = strsep(&p, ","))) {
> +		unsigned int vendor, device, subvendor = PCI_ANY_ID,
> +			subdevice = PCI_ANY_ID, class = 0, class_mask = 0;
> +		int fields;
> +
> +		if (!strlen(id))
> +			continue;
> +
> +		fields = sscanf(id, "%x:%x:%x:%x:%x:%x",
> +				&vendor, &device, &subvendor, &subdevice,
> +				&class, &class_mask);
> +
> +		if (fields < 2) {
> +			pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
> +			continue;
> +		}
> +
> +		pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",

pci_setup_device() uses "[%04x:%04x] ... class %#08x".  Maybe they should
be the same, at least as far as using upper/lower case, spelling out
"class", and "0x" prefix.  Maybe there's other precedent that you're
following and pci_setup_device() is not?

> +			vendor, device, subvendor, subdevice,
> +			class, class_mask);
> +
> +		rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
> +				   subvendor, subdevice, class, class_mask, 0);
> +		if (rc)
> +			pr_warn("vfio-pci: failed to add dynamic id (%d)\n",
> +				rc);
> +	}
> +}
> +
>  static int __init vfio_pci_init(void)
>  {
>  	int ret;
> @@ -1053,6 +1097,8 @@ static int __init vfio_pci_init(void)
>  	if (ret)
>  		goto out_driver;
>  
> +	vfio_pci_fill_ids();
> +
>  	return 0;
>  
>  out_driver:
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Alex Williamson March 11, 2015, 8:14 p.m. UTC | #6
On Fri, 2015-03-06 at 16:11 -0600, Bjorn Helgaas wrote:
> On Wed, Mar 04, 2015 at 01:02:43PM -0700, Alex Williamson wrote:
> > This copies the same support from pci-stub for exactly the same
> > purpose, enabling a set of PCI IDs to be automatically added to the
> > driver's dynamic ID table at module load time.  The code here is
> > pretty simple and both vfio-pci and pci-stub are fairly unique in
> > being meta drivers, capable of attaching to any device, so there's no
> > attempt made to generalize the code into pci-core.
> > 
> > Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
> > ---
> >  drivers/vfio/pci/vfio_pci.c |   46 +++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 46 insertions(+)
> > 
> > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
> > index f8a1863..b3bae4c 100644
> > --- a/drivers/vfio/pci/vfio_pci.c
> > +++ b/drivers/vfio/pci/vfio_pci.c
> > @@ -32,6 +32,10 @@
> >  #define DRIVER_AUTHOR   "Alex Williamson <alex.williamson@redhat.com>"
> >  #define DRIVER_DESC     "VFIO PCI - User Level meta-driver"
> >  
> > +static char ids[1024] __initdata;
> > +module_param_string(ids, ids, sizeof(ids), 0);
> > +MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the vfio driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified");
> > +
> >  static bool nointxmask;
> >  module_param_named(nointxmask, nointxmask, bool, S_IRUGO | S_IWUSR);
> >  MODULE_PARM_DESC(nointxmask,
> > @@ -1034,6 +1038,46 @@ static void __exit vfio_pci_cleanup(void)
> >  	vfio_pci_uninit_perm_bits();
> >  }
> >  
> > +static void __init vfio_pci_fill_ids(void)
> > +{
> > +	char *p, *id;
> > +	int rc;
> > +
> > +	/* no ids passed actually */
> > +	if (ids[0] == '\0')
> > +		return;
> > +
> > +	/* add ids specified in the module parameter */
> > +	p = ids;
> > +	while ((id = strsep(&p, ","))) {
> > +		unsigned int vendor, device, subvendor = PCI_ANY_ID,
> > +			subdevice = PCI_ANY_ID, class = 0, class_mask = 0;
> > +		int fields;
> > +
> > +		if (!strlen(id))
> > +			continue;
> > +
> > +		fields = sscanf(id, "%x:%x:%x:%x:%x:%x",
> > +				&vendor, &device, &subvendor, &subdevice,
> > +				&class, &class_mask);
> > +
> > +		if (fields < 2) {
> > +			pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
> > +			continue;
> > +		}
> > +
> > +		pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
> 
> pci_setup_device() uses "[%04x:%04x] ... class %#08x".  Maybe they should
> be the same, at least as far as using upper/lower case, spelling out
> "class", and "0x" prefix.  Maybe there's other precedent that you're
> following and pci_setup_device() is not?

Sorry for not responding to this right away.  The precedent I was
following is pci_stub_init(), but I don't know that it's any sort of
canonical reference.  PCI output in dmesg seems pretty consistent in
using lower case hex, so I agree we should make that change.  I also
note that the default value for sub IDs is PCI_ANY_ID, which ends up
getting printed as 8 characters since we don't specify the length.  I'm
also not a fan of the lack of consistency in printing the ID vs the sub
ID nor how the line wraps in dmesg w/ timestamps enabled.  What do you
think about this:

[%04hx:%04hx[%04hx:%04hx]] class %#08x/%08x

Which gives us this and doesn't wrap:

[   92.731809] vfio_pci: add [10de:11fa[ffff:ffff]] class 0x000000/00000000
[   92.738530] vfio_pci: add [10de:0e0b[ffff:ffff]] class 0x000000/00000000

I'm open to adding 0x on the class mask as well if anyone wants it.
Thanks,
Alex

> > +			vendor, device, subvendor, subdevice,
> > +			class, class_mask);
> > +
> > +		rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
> > +				   subvendor, subdevice, class, class_mask, 0);
> > +		if (rc)
> > +			pr_warn("vfio-pci: failed to add dynamic id (%d)\n",
> > +				rc);
> > +	}
> > +}
> > +
> >  static int __init vfio_pci_init(void)
> >  {
> >  	int ret;
> > @@ -1053,6 +1097,8 @@ static int __init vfio_pci_init(void)
> >  	if (ret)
> >  		goto out_driver;
> >  
> > +	vfio_pci_fill_ids();
> > +
> >  	return 0;
> >  
> >  out_driver:
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at  http://www.tux.org/lkml/



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Bjorn Helgaas March 11, 2015, 8:20 p.m. UTC | #7
On Wed, Mar 11, 2015 at 3:14 PM, Alex Williamson
<alex.williamson@redhat.com> wrote:
> On Fri, 2015-03-06 at 16:11 -0600, Bjorn Helgaas wrote:
>> On Wed, Mar 04, 2015 at 01:02:43PM -0700, Alex Williamson wrote:
>> > This copies the same support from pci-stub for exactly the same
>> > purpose, enabling a set of PCI IDs to be automatically added to the
>> > driver's dynamic ID table at module load time.  The code here is
>> > pretty simple and both vfio-pci and pci-stub are fairly unique in
>> > being meta drivers, capable of attaching to any device, so there's no
>> > attempt made to generalize the code into pci-core.
>> >
>> > Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
>> > ---
>> >  drivers/vfio/pci/vfio_pci.c |   46 +++++++++++++++++++++++++++++++++++++++++++
>> >  1 file changed, 46 insertions(+)
>> >
>> > diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
>> > index f8a1863..b3bae4c 100644
>> > --- a/drivers/vfio/pci/vfio_pci.c
>> > +++ b/drivers/vfio/pci/vfio_pci.c
>> > @@ -32,6 +32,10 @@
>> >  #define DRIVER_AUTHOR   "Alex Williamson <alex.williamson@redhat.com>"
>> >  #define DRIVER_DESC     "VFIO PCI - User Level meta-driver"
>> >
>> > +static char ids[1024] __initdata;
>> > +module_param_string(ids, ids, sizeof(ids), 0);
>> > +MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the vfio driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified");
>> > +
>> >  static bool nointxmask;
>> >  module_param_named(nointxmask, nointxmask, bool, S_IRUGO | S_IWUSR);
>> >  MODULE_PARM_DESC(nointxmask,
>> > @@ -1034,6 +1038,46 @@ static void __exit vfio_pci_cleanup(void)
>> >     vfio_pci_uninit_perm_bits();
>> >  }
>> >
>> > +static void __init vfio_pci_fill_ids(void)
>> > +{
>> > +   char *p, *id;
>> > +   int rc;
>> > +
>> > +   /* no ids passed actually */
>> > +   if (ids[0] == '\0')
>> > +           return;
>> > +
>> > +   /* add ids specified in the module parameter */
>> > +   p = ids;
>> > +   while ((id = strsep(&p, ","))) {
>> > +           unsigned int vendor, device, subvendor = PCI_ANY_ID,
>> > +                   subdevice = PCI_ANY_ID, class = 0, class_mask = 0;
>> > +           int fields;
>> > +
>> > +           if (!strlen(id))
>> > +                   continue;
>> > +
>> > +           fields = sscanf(id, "%x:%x:%x:%x:%x:%x",
>> > +                           &vendor, &device, &subvendor, &subdevice,
>> > +                           &class, &class_mask);
>> > +
>> > +           if (fields < 2) {
>> > +                   pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
>> > +                   continue;
>> > +           }
>> > +
>> > +           pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
>>
>> pci_setup_device() uses "[%04x:%04x] ... class %#08x".  Maybe they should
>> be the same, at least as far as using upper/lower case, spelling out
>> "class", and "0x" prefix.  Maybe there's other precedent that you're
>> following and pci_setup_device() is not?
>
> Sorry for not responding to this right away.  The precedent I was
> following is pci_stub_init(), but I don't know that it's any sort of
> canonical reference.  PCI output in dmesg seems pretty consistent in
> using lower case hex, so I agree we should make that change.  I also
> note that the default value for sub IDs is PCI_ANY_ID, which ends up
> getting printed as 8 characters since we don't specify the length.  I'm
> also not a fan of the lack of consistency in printing the ID vs the sub
> ID nor how the line wraps in dmesg w/ timestamps enabled.  What do you
> think about this:
>
> [%04hx:%04hx[%04hx:%04hx]] class %#08x/%08x
>
> Which gives us this and doesn't wrap:
>
> [   92.731809] vfio_pci: add [10de:11fa[ffff:ffff]] class 0x000000/00000000
> [   92.738530] vfio_pci: add [10de:0e0b[ffff:ffff]] class 0x000000/00000000

Looks OK to me.
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/vfio/pci/vfio_pci.c b/drivers/vfio/pci/vfio_pci.c
index f8a1863..b3bae4c 100644
--- a/drivers/vfio/pci/vfio_pci.c
+++ b/drivers/vfio/pci/vfio_pci.c
@@ -32,6 +32,10 @@ 
 #define DRIVER_AUTHOR   "Alex Williamson <alex.williamson@redhat.com>"
 #define DRIVER_DESC     "VFIO PCI - User Level meta-driver"
 
+static char ids[1024] __initdata;
+module_param_string(ids, ids, sizeof(ids), 0);
+MODULE_PARM_DESC(ids, "Initial PCI IDs to add to the vfio driver, format is \"vendor:device[:subvendor[:subdevice[:class[:class_mask]]]]\" and multiple comma separated entries can be specified");
+
 static bool nointxmask;
 module_param_named(nointxmask, nointxmask, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(nointxmask,
@@ -1034,6 +1038,46 @@  static void __exit vfio_pci_cleanup(void)
 	vfio_pci_uninit_perm_bits();
 }
 
+static void __init vfio_pci_fill_ids(void)
+{
+	char *p, *id;
+	int rc;
+
+	/* no ids passed actually */
+	if (ids[0] == '\0')
+		return;
+
+	/* add ids specified in the module parameter */
+	p = ids;
+	while ((id = strsep(&p, ","))) {
+		unsigned int vendor, device, subvendor = PCI_ANY_ID,
+			subdevice = PCI_ANY_ID, class = 0, class_mask = 0;
+		int fields;
+
+		if (!strlen(id))
+			continue;
+
+		fields = sscanf(id, "%x:%x:%x:%x:%x:%x",
+				&vendor, &device, &subvendor, &subdevice,
+				&class, &class_mask);
+
+		if (fields < 2) {
+			pr_warn("vfio-pci: invalid id string \"%s\"\n", id);
+			continue;
+		}
+
+		pr_info("vfio-pci: add %04X:%04X sub=%04X:%04X cls=%08X/%08X\n",
+			vendor, device, subvendor, subdevice,
+			class, class_mask);
+
+		rc = pci_add_dynid(&vfio_pci_driver, vendor, device,
+				   subvendor, subdevice, class, class_mask, 0);
+		if (rc)
+			pr_warn("vfio-pci: failed to add dynamic id (%d)\n",
+				rc);
+	}
+}
+
 static int __init vfio_pci_init(void)
 {
 	int ret;
@@ -1053,6 +1097,8 @@  static int __init vfio_pci_init(void)
 	if (ret)
 		goto out_driver;
 
+	vfio_pci_fill_ids();
+
 	return 0;
 
 out_driver: