[dpdk-dev] BugFix: VFIO never works

Message ID 1436514439-4893-1-git-send-email-michael.qiu@intel.com (mailing list archive)
State Changes Requested, archived
Headers

Commit Message

Michael Qiu July 10, 2015, 7:47 a.m. UTC
  Commit 35b3313e322b ("pci: merge mapping functions for linux and bsd")

introduced a bug that all vfio will be
blocked.

Root cause is that VFIO_PRESENT is unaccessable in eal
common level.

This patch is to fix this.

Signed-off-by: Michael Qiu <michael.qiu@intel.com>
---
 lib/librte_eal/common/eal_common_pci.c     |  2 --
 lib/librte_eal/common/eal_private.h        |  3 +++
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 10 ++++++++++
 3 files changed, 13 insertions(+), 2 deletions(-)
  

Comments

Tetsuya Mukawa July 10, 2015, 8:34 a.m. UTC | #1
On 2015/07/10 16:47, Michael Qiu wrote:
> Commit 35b3313e322b ("pci: merge mapping functions for linux and bsd")
>
> introduced a bug that all vfio will be
> blocked.
>
> Root cause is that VFIO_PRESENT is unaccessable in eal
> common level.
>
> This patch is to fix this.
>
> Signed-off-by: Michael Qiu <michael.qiu@intel.com>
> ---
>  lib/librte_eal/common/eal_common_pci.c     |  2 --
>  lib/librte_eal/common/eal_private.h        |  3 +++
>  lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 10 ++++++++++
>  3 files changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
> index 3805aed..f3dc697 100644
> --- a/lib/librte_eal/common/eal_common_pci.c
> +++ b/lib/librte_eal/common/eal_common_pci.c
> @@ -146,10 +146,8 @@ pci_map_device(struct rte_pci_device *dev)
>  	/* try mapping the NIC resources using VFIO if it exists */
>  	switch (dev->kdrv) {
>  	case RTE_KDRV_VFIO:
> -#ifdef VFIO_PRESENT
>  		if (pci_vfio_is_enabled())
>  			ret = pci_vfio_map_resource(dev);
> -#endif
>  		break;
>  	case RTE_KDRV_IGB_UIO:
>  	case RTE_KDRV_UIO_GENERIC:
> diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
> index e16bb68..10995c3 100644
> --- a/lib/librte_eal/common/eal_private.h
> +++ b/lib/librte_eal/common/eal_private.h
> @@ -174,6 +174,9 @@ int pci_unbind_kernel_driver(struct rte_pci_device *dev);
>   */
>  int pci_uio_map_resource(struct rte_pci_device *dev);
>  
> +int pci_vfio_is_enabled(void);
> +
> +int pci_vfio_map_resource(struct rte_pci_device *dev);
>  /**
>   * Unmap the PCI resource of a PCI device
>   *
> diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
> index 426953a..3b5da34 100644
> --- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
> +++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
> @@ -909,4 +909,14 @@ pci_vfio_is_enabled(void)
>  {
>  	return vfio_cfg.vfio_enabled;
>  }
> +#else
> +int pci_vfio_is_enabled(void)
> +{
> +	return 0;
> +}
> +
> +int pci_vfio_map_resource(__rte_unused struct rte_pci_device *dev)
> +{
> +	return -1;
> +}
>  #endif

Tested-by: Tetsuya Mukawa <mukawa@igel.co.jp>
Acked-by: Tetsuya Mukawa <mukawa@igel.co.jp>


Hi Michael,


Thanks, I haven't checked it with vfio.
I've make sure the patch works fine with vfio and pci_uio_generic.

Regards,
Tetsuya
  
David Marchand July 10, 2015, 11:25 a.m. UTC | #2
On Fri, Jul 10, 2015 at 10:34 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:

> On 2015/07/10 16:47, Michael Qiu wrote:
> > Commit 35b3313e322b ("pci: merge mapping functions for linux and bsd")
> >
> > introduced a bug that all vfio will be
> > blocked.
> >
> > Root cause is that VFIO_PRESENT is unaccessable in eal
> > common level.
> >
> > This patch is to fix this.
> >
> > Signed-off-by: Michael Qiu <michael.qiu@intel.com>
> > ---
> >  lib/librte_eal/common/eal_common_pci.c     |  2 --
> >  lib/librte_eal/common/eal_private.h        |  3 +++
> >  lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 10 ++++++++++
> >  3 files changed, 13 insertions(+), 2 deletions(-)
> >
> > diff --git a/lib/librte_eal/common/eal_common_pci.c
> b/lib/librte_eal/common/eal_common_pci.c
> > index 3805aed..f3dc697 100644
> > --- a/lib/librte_eal/common/eal_common_pci.c
> > +++ b/lib/librte_eal/common/eal_common_pci.c
> > @@ -146,10 +146,8 @@ pci_map_device(struct rte_pci_device *dev)
> >       /* try mapping the NIC resources using VFIO if it exists */
> >       switch (dev->kdrv) {
> >       case RTE_KDRV_VFIO:
> > -#ifdef VFIO_PRESENT
> >               if (pci_vfio_is_enabled())
> >                       ret = pci_vfio_map_resource(dev);
> > -#endif
>

This is a common file, vfio is not available on BSD.
I missed that during review.

Did you test build on BSD ?
  
Tetsuya Mukawa July 10, 2015, 11:35 a.m. UTC | #3
2015-07-10 20:25 GMT+09:00 David Marchand <david.marchand@6wind.com>:
> On Fri, Jul 10, 2015 at 10:34 AM, Tetsuya Mukawa <mukawa@igel.co.jp> wrote:
>>
>> On 2015/07/10 16:47, Michael Qiu wrote:
>> > Commit 35b3313e322b ("pci: merge mapping functions for linux and bsd")
>> >
>> > introduced a bug that all vfio will be
>> > blocked.
>> >
>> > Root cause is that VFIO_PRESENT is unaccessable in eal
>> > common level.
>> >
>> > This patch is to fix this.
>> >
>> > Signed-off-by: Michael Qiu <michael.qiu@intel.com>
>> > ---
>> >  lib/librte_eal/common/eal_common_pci.c     |  2 --
>> >  lib/librte_eal/common/eal_private.h        |  3 +++
>> >  lib/librte_eal/linuxapp/eal/eal_pci_vfio.c | 10 ++++++++++
>> >  3 files changed, 13 insertions(+), 2 deletions(-)
>> >
>> > diff --git a/lib/librte_eal/common/eal_common_pci.c
>> > b/lib/librte_eal/common/eal_common_pci.c
>> > index 3805aed..f3dc697 100644
>> > --- a/lib/librte_eal/common/eal_common_pci.c
>> > +++ b/lib/librte_eal/common/eal_common_pci.c
>> > @@ -146,10 +146,8 @@ pci_map_device(struct rte_pci_device *dev)
>> >       /* try mapping the NIC resources using VFIO if it exists */
>> >       switch (dev->kdrv) {
>> >       case RTE_KDRV_VFIO:
>> > -#ifdef VFIO_PRESENT
>> >               if (pci_vfio_is_enabled())
>> >                       ret = pci_vfio_map_resource(dev);
>> > -#endif
>
>
> This is a common file, vfio is not available on BSD.
> I missed that during review.
>
> Did you test build on BSD ?
>
>
> --
> David Marchand

Hi David,

Yes I did.
Before submitting the patch series, I've tested it with igb_uio on
Linux and with nic_uio on BSD.
Both were OK. But I didn't test it with vfio and pci_uio generic on Linux.
After receiving the patch, I tested both. So now all cases should be ok.

Tetsuya
  

Patch

diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 3805aed..f3dc697 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -146,10 +146,8 @@  pci_map_device(struct rte_pci_device *dev)
 	/* try mapping the NIC resources using VFIO if it exists */
 	switch (dev->kdrv) {
 	case RTE_KDRV_VFIO:
-#ifdef VFIO_PRESENT
 		if (pci_vfio_is_enabled())
 			ret = pci_vfio_map_resource(dev);
-#endif
 		break;
 	case RTE_KDRV_IGB_UIO:
 	case RTE_KDRV_UIO_GENERIC:
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index e16bb68..10995c3 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -174,6 +174,9 @@  int pci_unbind_kernel_driver(struct rte_pci_device *dev);
  */
 int pci_uio_map_resource(struct rte_pci_device *dev);
 
+int pci_vfio_is_enabled(void);
+
+int pci_vfio_map_resource(struct rte_pci_device *dev);
 /**
  * Unmap the PCI resource of a PCI device
  *
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 426953a..3b5da34 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -909,4 +909,14 @@  pci_vfio_is_enabled(void)
 {
 	return vfio_cfg.vfio_enabled;
 }
+#else
+int pci_vfio_is_enabled(void)
+{
+	return 0;
+}
+
+int pci_vfio_map_resource(__rte_unused struct rte_pci_device *dev)
+{
+	return -1;
+}
 #endif