[dpdk-dev] BugFix: VFIO never works

Message ID 20150710113826.GA10608@bricha3-MOBL3 (mailing list archive)
State Changes Requested, archived
Headers

Commit Message

Bruce Richardson July 10, 2015, 11:38 a.m. UTC
  On Fri, Jul 10, 2015 at 01:25:49PM +0200, David Marchand wrote:
> 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 ?
>
Just tried it. BSD build fails with this patch applied.

Rather than using ifdefs, we could also look at providing dummy functions for
vfio in BSD. They would never be called by this code as drivers in BSD should
never have dev->kdrv == RTE_KDRV_VFIO.

/Bruce
  

Comments

Tetsuya Mukawa July 10, 2015, 12:12 p.m. UTC | #1
2015-07-10 20:38 GMT+09:00 Bruce Richardson <bruce.richardson@intel.com>:
> On Fri, Jul 10, 2015 at 01:25:49PM +0200, David Marchand wrote:
>> 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 ?
>>
> Just tried it. BSD build fails with this patch applied.
>
> Rather than using ifdefs, we could also look at providing dummy functions for
> vfio in BSD. They would never be called by this code as drivers in BSD should
> never have dev->kdrv == RTE_KDRV_VFIO.
>
> /Bruce

I've got it. Right, we need to fix the patch.

I don't have BSD machine within reach now.
So I will write and test a new patch tomorrow.

Tetsuya

>
> diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
> index 12f39d9..8c1422c 100644
> --- a/lib/librte_eal/bsdapp/eal/eal_pci.c
> +++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
> @@ -358,6 +358,16 @@ error:
>         return -1;
>  }
>
> +/*
> + * no vfio on BSD, but provide empty functions to avoid compile errors in
> + * common code.
> + */
> +int
> +pci_vfio_is_enabled(void) { return 0; }
> +
> +int
> +pci_vfio_map_resource(struct rte_pci_device *dev __rte_unused) { return -1; }
> +
>  /* Init the PCI EAL subsystem */
>  int
>  rte_eal_pci_init(void)
>
  
Thomas Monjalon July 10, 2015, 12:16 p.m. UTC | #2
2015-07-10 12:38, Bruce Richardson:
> On Fri, Jul 10, 2015 at 01:25:49PM +0200, David Marchand wrote:
> > 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>
[...]
> > > > --- 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 ?
> >
> Just tried it. BSD build fails with this patch applied.
> 
> Rather than using ifdefs, we could also look at providing dummy functions for
> vfio in BSD. They would never be called by this code as drivers in BSD should
> never have dev->kdrv == RTE_KDRV_VFIO.

Why not implementing different versions of pci_map_device() and pci_unmap_device()
in linuxapp and bsdapp EAL? They are only wrappers so no code would be duplicated.
  
Tetsuya Mukawa July 11, 2015, 6:32 a.m. UTC | #3
On 2015/07/10 21:16, Thomas Monjalon wrote:
> 2015-07-10 12:38, Bruce Richardson:
>> On Fri, Jul 10, 2015 at 01:25:49PM +0200, David Marchand wrote:
>>> 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>
> [...]
>>>>> --- 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 ?
>>>
>> Just tried it. BSD build fails with this patch applied.
>>
>> Rather than using ifdefs, we could also look at providing dummy functions for
>> vfio in BSD. They would never be called by this code as drivers in BSD should
>> never have dev->kdrv == RTE_KDRV_VFIO.
> Why not implementing different versions of pci_map_device() and pci_unmap_device()
> in linuxapp and bsdapp EAL? They are only wrappers so no code would be duplicated.

Thanks for comment.
Right, it should be. I fixed like above.

Tetsuya
  

Patch

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 12f39d9..8c1422c 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -358,6 +358,16 @@  error:
        return -1;
 }

+/*
+ * no vfio on BSD, but provide empty functions to avoid compile errors in
+ * common code.
+ */
+int
+pci_vfio_is_enabled(void) { return 0; }
+
+int
+pci_vfio_map_resource(struct rte_pci_device *dev __rte_unused) { return -1; }
+
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)