bus/pci: use device driver name instead of handler type

Message ID 1539967418-17824-1-git-send-email-alejandro.lucero@netronome.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series bus/pci: use device driver name instead of handler type |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Alejandro Lucero Oct. 19, 2018, 4:43 p.m. UTC
  Invoking the right pci read/write functions is based on interrupt
handler type. However, this is not configured for secondary processes
precluding to use those functions.

This patch fixes the issue using the driver name the device is bound
to instead.

Fixes: 632b2d1deeed ("eal: provide functions to access PCI config")

Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
---
 drivers/bus/pci/linux/pci.c | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)
  

Comments

Anatoly Burakov Oct. 22, 2018, 8:58 a.m. UTC | #1
On 19-Oct-18 5:43 PM, Alejandro Lucero wrote:
> Invoking the right pci read/write functions is based on interrupt
> handler type. However, this is not configured for secondary processes
> precluding to use those functions.
> 
> This patch fixes the issue using the driver name the device is bound
> to instead.
> 
> Fixes: 632b2d1deeed ("eal: provide functions to access PCI config")
> 
> Signed-off-by: Alejandro Lucero <alejandro.lucero@netronome.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>
  
Thomas Monjalon Oct. 24, 2018, 11:11 p.m. UTC | #2
Hi,

19/10/2018 18:43, Alejandro Lucero:
> --- a/drivers/bus/pci/linux/pci.c
> +++ b/drivers/bus/pci/linux/pci.c
> +	char devname[RTE_DEV_NAME_MAX_LEN] = {0};

I think "" would be more appropriate than {0}.

>  	const struct rte_intr_handle *intr_handle = &device->intr_handle;
>  
> -	switch (intr_handle->type) {
> -	case RTE_INTR_HANDLE_UIO:
> -	case RTE_INTR_HANDLE_UIO_INTX:
> +	switch (device->kdrv) {
> +	case RTE_KDRV_IGB_UIO:
>  		return pci_uio_read_config(intr_handle, buf, len, offset);
> -
> -#ifdef VFIO_PRESENT

Why this #ifdef is removed?

> -	case RTE_INTR_HANDLE_VFIO_MSIX:
> -	case RTE_INTR_HANDLE_VFIO_MSI:
> -	case RTE_INTR_HANDLE_VFIO_LEGACY:
> +	case RTE_KDRV_VFIO:
>  		return pci_vfio_read_config(intr_handle, buf, len, offset);
> -#endif
>  	default:
> +		rte_pci_device_name(&device->addr, devname,
> +				    RTE_DEV_NAME_MAX_LEN);
>  		RTE_LOG(ERR, EAL,
> -			"Unknown handle type of fd %d\n",
> -					intr_handle->fd);
> +			"Unknown driver type for %s\n", devname);
>  		return -1;
>  	}
  
Alejandro Lucero Oct. 25, 2018, 5:30 a.m. UTC | #3
On Thu, Oct 25, 2018 at 12:11 AM Thomas Monjalon <thomas@monjalon.net>
wrote:

> Hi,
>
> 19/10/2018 18:43, Alejandro Lucero:
> > --- a/drivers/bus/pci/linux/pci.c
> > +++ b/drivers/bus/pci/linux/pci.c
> > +     char devname[RTE_DEV_NAME_MAX_LEN] = {0};
>
> I think "" would be more appropriate than {0}.
>
> >       const struct rte_intr_handle *intr_handle = &device->intr_handle;
> >
> > -     switch (intr_handle->type) {
> > -     case RTE_INTR_HANDLE_UIO:
> > -     case RTE_INTR_HANDLE_UIO_INTX:
> > +     switch (device->kdrv) {
> > +     case RTE_KDRV_IGB_UIO:
> >               return pci_uio_read_config(intr_handle, buf, len, offset);
> > -
> > -#ifdef VFIO_PRESENT
>
> Why this #ifdef is removed?
>
>
Because it is not needed. VFIO is present if the kdrv field tells us so.


> > -     case RTE_INTR_HANDLE_VFIO_MSIX:
> > -     case RTE_INTR_HANDLE_VFIO_MSI:
> > -     case RTE_INTR_HANDLE_VFIO_LEGACY:
> > +     case RTE_KDRV_VFIO:
> >               return pci_vfio_read_config(intr_handle, buf, len, offset);
> > -#endif
> >       default:
> > +             rte_pci_device_name(&device->addr, devname,
> > +                                 RTE_DEV_NAME_MAX_LEN);
> >               RTE_LOG(ERR, EAL,
> > -                     "Unknown handle type of fd %d\n",
> > -                                     intr_handle->fd);
> > +                     "Unknown driver type for %s\n", devname);
> >               return -1;
> >       }
>
>
>
>
  
Alejandro Lucero Oct. 25, 2018, 6 a.m. UTC | #4
On Thu, Oct 25, 2018 at 6:30 AM Alejandro Lucero <
alejandro.lucero@netronome.com> wrote:

>
>
> On Thu, Oct 25, 2018 at 12:11 AM Thomas Monjalon <thomas@monjalon.net>
> wrote:
>
>> Hi,
>>
>> 19/10/2018 18:43, Alejandro Lucero:
>> > --- a/drivers/bus/pci/linux/pci.c
>> > +++ b/drivers/bus/pci/linux/pci.c
>> > +     char devname[RTE_DEV_NAME_MAX_LEN] = {0};
>>
>> I think "" would be more appropriate than {0}.
>>
>> >       const struct rte_intr_handle *intr_handle = &device->intr_handle;
>> >
>> > -     switch (intr_handle->type) {
>> > -     case RTE_INTR_HANDLE_UIO:
>> > -     case RTE_INTR_HANDLE_UIO_INTX:
>> > +     switch (device->kdrv) {
>> > +     case RTE_KDRV_IGB_UIO:
>> >               return pci_uio_read_config(intr_handle, buf, len, offset);
>> > -
>> > -#ifdef VFIO_PRESENT
>>
>> Why this #ifdef is removed?
>>
>>
> Because it is not needed. VFIO is present if the kdrv field tells us so.
>

And at this point it is clear VFIO is present if that is the case.
Otherwise this code is not executed.


>
>
>> > -     case RTE_INTR_HANDLE_VFIO_MSIX:
>> > -     case RTE_INTR_HANDLE_VFIO_MSI:
>> > -     case RTE_INTR_HANDLE_VFIO_LEGACY:
>> > +     case RTE_KDRV_VFIO:
>> >               return pci_vfio_read_config(intr_handle, buf, len,
>> offset);
>> > -#endif
>> >       default:
>> > +             rte_pci_device_name(&device->addr, devname,
>> > +                                 RTE_DEV_NAME_MAX_LEN);
>> >               RTE_LOG(ERR, EAL,
>> > -                     "Unknown handle type of fd %d\n",
>> > -                                     intr_handle->fd);
>> > +                     "Unknown driver type for %s\n", devname);
>> >               return -1;
>> >       }
>>
>>
>>
>>
  
Anatoly Burakov Oct. 25, 2018, 9:29 a.m. UTC | #5
On 25-Oct-18 7:00 AM, Alejandro Lucero wrote:
> On Thu, Oct 25, 2018 at 6:30 AM Alejandro Lucero <
> alejandro.lucero@netronome.com> wrote:
> 
>>
>>
>> On Thu, Oct 25, 2018 at 12:11 AM Thomas Monjalon <thomas@monjalon.net>
>> wrote:
>>
>>> Hi,
>>>
>>> 19/10/2018 18:43, Alejandro Lucero:
>>>> --- a/drivers/bus/pci/linux/pci.c
>>>> +++ b/drivers/bus/pci/linux/pci.c
>>>> +     char devname[RTE_DEV_NAME_MAX_LEN] = {0};
>>>
>>> I think "" would be more appropriate than {0}.
>>>
>>>>        const struct rte_intr_handle *intr_handle = &device->intr_handle;
>>>>
>>>> -     switch (intr_handle->type) {
>>>> -     case RTE_INTR_HANDLE_UIO:
>>>> -     case RTE_INTR_HANDLE_UIO_INTX:
>>>> +     switch (device->kdrv) {
>>>> +     case RTE_KDRV_IGB_UIO:
>>>>                return pci_uio_read_config(intr_handle, buf, len, offset);
>>>> -
>>>> -#ifdef VFIO_PRESENT
>>>
>>> Why this #ifdef is removed?
>>>
>>>
>> Because it is not needed. VFIO is present if the kdrv field tells us so.
>>
> 
> And at this point it is clear VFIO is present if that is the case.
> Otherwise this code is not executed.

Actually, i think Thomas is right here. The #ifdef shouldn't be removed, 
because if this is not defined, the function is simply not present - see 
pci_init.h, VFIO-related functions are only declared if VFIO_PRESENT is 
defined.

> 
> 
>>
>>
>>>> -     case RTE_INTR_HANDLE_VFIO_MSIX:
>>>> -     case RTE_INTR_HANDLE_VFIO_MSI:
>>>> -     case RTE_INTR_HANDLE_VFIO_LEGACY:
>>>> +     case RTE_KDRV_VFIO:
>>>>                return pci_vfio_read_config(intr_handle, buf, len,
>>> offset);
>>>> -#endif
>>>>        default:
>>>> +             rte_pci_device_name(&device->addr, devname,
>>>> +                                 RTE_DEV_NAME_MAX_LEN);
>>>>                RTE_LOG(ERR, EAL,
>>>> -                     "Unknown handle type of fd %d\n",
>>>> -                                     intr_handle->fd);
>>>> +                     "Unknown driver type for %s\n", devname);
>>>>                return -1;
>>>>        }
>>>
>>>
>>>
>>>
>
  
Alejandro Lucero Oct. 25, 2018, 9:45 a.m. UTC | #6
On Thu, Oct 25, 2018 at 10:29 AM Burakov, Anatoly <anatoly.burakov@intel.com>
wrote:

> On 25-Oct-18 7:00 AM, Alejandro Lucero wrote:
> > On Thu, Oct 25, 2018 at 6:30 AM Alejandro Lucero <
> > alejandro.lucero@netronome.com> wrote:
> >
> >>
> >>
> >> On Thu, Oct 25, 2018 at 12:11 AM Thomas Monjalon <thomas@monjalon.net>
> >> wrote:
> >>
> >>> Hi,
> >>>
> >>> 19/10/2018 18:43, Alejandro Lucero:
> >>>> --- a/drivers/bus/pci/linux/pci.c
> >>>> +++ b/drivers/bus/pci/linux/pci.c
> >>>> +     char devname[RTE_DEV_NAME_MAX_LEN] = {0};
> >>>
> >>> I think "" would be more appropriate than {0}.
> >>>
> >>>>        const struct rte_intr_handle *intr_handle =
> &device->intr_handle;
> >>>>
> >>>> -     switch (intr_handle->type) {
> >>>> -     case RTE_INTR_HANDLE_UIO:
> >>>> -     case RTE_INTR_HANDLE_UIO_INTX:
> >>>> +     switch (device->kdrv) {
> >>>> +     case RTE_KDRV_IGB_UIO:
> >>>>                return pci_uio_read_config(intr_handle, buf, len,
> offset);
> >>>> -
> >>>> -#ifdef VFIO_PRESENT
> >>>
> >>> Why this #ifdef is removed?
> >>>
> >>>
> >> Because it is not needed. VFIO is present if the kdrv field tells us so.
> >>
> >
> > And at this point it is clear VFIO is present if that is the case.
> > Otherwise this code is not executed.
>
> Actually, i think Thomas is right here. The #ifdef shouldn't be removed,
> because if this is not defined, the function is simply not present - see
> pci_init.h, VFIO-related functions are only declared if VFIO_PRESENT is
> defined.
>
>
Right. I did not try to compile without VFIO, but I have just done this and
it fails.
I will send another version using the #ifdef for VFIO.

Thanks


> >
> >
> >>
> >>
> >>>> -     case RTE_INTR_HANDLE_VFIO_MSIX:
> >>>> -     case RTE_INTR_HANDLE_VFIO_MSI:
> >>>> -     case RTE_INTR_HANDLE_VFIO_LEGACY:
> >>>> +     case RTE_KDRV_VFIO:
> >>>>                return pci_vfio_read_config(intr_handle, buf, len,
> >>> offset);
> >>>> -#endif
> >>>>        default:
> >>>> +             rte_pci_device_name(&device->addr, devname,
> >>>> +                                 RTE_DEV_NAME_MAX_LEN);
> >>>>                RTE_LOG(ERR, EAL,
> >>>> -                     "Unknown handle type of fd %d\n",
> >>>> -                                     intr_handle->fd);
> >>>> +                     "Unknown driver type for %s\n", devname);
> >>>>                return -1;
> >>>>        }
> >>>
> >>>
> >>>
> >>>
> >
>
>
> --
> Thanks,
> Anatoly
>
  

Patch

diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 5cf78d7..135b82c 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -673,23 +673,19 @@  enum rte_iova_mode
 int rte_pci_read_config(const struct rte_pci_device *device,
 		void *buf, size_t len, off_t offset)
 {
+	char devname[RTE_DEV_NAME_MAX_LEN] = {0};
 	const struct rte_intr_handle *intr_handle = &device->intr_handle;
 
-	switch (intr_handle->type) {
-	case RTE_INTR_HANDLE_UIO:
-	case RTE_INTR_HANDLE_UIO_INTX:
+	switch (device->kdrv) {
+	case RTE_KDRV_IGB_UIO:
 		return pci_uio_read_config(intr_handle, buf, len, offset);
-
-#ifdef VFIO_PRESENT
-	case RTE_INTR_HANDLE_VFIO_MSIX:
-	case RTE_INTR_HANDLE_VFIO_MSI:
-	case RTE_INTR_HANDLE_VFIO_LEGACY:
+	case RTE_KDRV_VFIO:
 		return pci_vfio_read_config(intr_handle, buf, len, offset);
-#endif
 	default:
+		rte_pci_device_name(&device->addr, devname,
+				    RTE_DEV_NAME_MAX_LEN);
 		RTE_LOG(ERR, EAL,
-			"Unknown handle type of fd %d\n",
-					intr_handle->fd);
+			"Unknown driver type for %s\n", devname);
 		return -1;
 	}
 }
@@ -698,23 +694,19 @@  int rte_pci_read_config(const struct rte_pci_device *device,
 int rte_pci_write_config(const struct rte_pci_device *device,
 		const void *buf, size_t len, off_t offset)
 {
+	char devname[RTE_DEV_NAME_MAX_LEN] = {0};
 	const struct rte_intr_handle *intr_handle = &device->intr_handle;
 
-	switch (intr_handle->type) {
-	case RTE_INTR_HANDLE_UIO:
-	case RTE_INTR_HANDLE_UIO_INTX:
+	switch (device->kdrv) {
+	case RTE_KDRV_IGB_UIO:
 		return pci_uio_write_config(intr_handle, buf, len, offset);
-
-#ifdef VFIO_PRESENT
-	case RTE_INTR_HANDLE_VFIO_MSIX:
-	case RTE_INTR_HANDLE_VFIO_MSI:
-	case RTE_INTR_HANDLE_VFIO_LEGACY:
+	case RTE_KDRV_VFIO:
 		return pci_vfio_write_config(intr_handle, buf, len, offset);
-#endif
 	default:
+		rte_pci_device_name(&device->addr, devname,
+				    RTE_DEV_NAME_MAX_LEN);
 		RTE_LOG(ERR, EAL,
-			"Unknown handle type of fd %d\n",
-					intr_handle->fd);
+			"Unknown driver type for %s\n", devname);
 		return -1;
 	}
 }