[dpdk-dev,v2] bus/pci: fix wrong intr_handle.type with uio_pci_generic

Message ID 20171229075511.33180-1-zhiyong.yang@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers

Checks

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

Commit Message

Yang, Zhiyong Dec. 29, 2017, 7:55 a.m. UTC
  For virtio legacy device, testpmd startup fails when using
uio_pci_generic. The issue is caused by invoking the function
pci_ioport_map. The right intr_handle.type is already set before
calling it, we should avoid overwriting the default value "RTE_
INTR_HANDLE_UNKNOWN" in it. Besides, the removal has no harm to
other cases since it already is set to this value (0) at init.

Fixes: 756ce64b1ecd ("eal: introduce PCI ioport API")
Cc: stable@dpdk.org
Signed-off-by: Zhiyong Yang <zhiyong.yang@intel.com>
---

Changes in V2:
1. reword the commit log.
2. remove the assignment operation which causes the issue.

 drivers/bus/pci/linux/pci.c | 1 -
 1 file changed, 1 deletion(-)
  

Comments

Thomas Monjalon Dec. 29, 2017, 11:07 a.m. UTC | #1
29/12/2017 08:55, Zhiyong Yang:
> For virtio legacy device, testpmd startup fails when using
> uio_pci_generic. The issue is caused by invoking the function
> pci_ioport_map. The right intr_handle.type is already set before
> calling it, we should avoid overwriting the default value "RTE_
> INTR_HANDLE_UNKNOWN" in it. Besides, the removal has no harm to
> other cases since it already is set to this value (0) at init.

To be more precise, it is set to 0 by a memset on the whole struct
during allocation in the scan function (pci_scan_one).

> --- a/drivers/bus/pci/linux/pci.c
> +++ b/drivers/bus/pci/linux/pci.c
> @@ -723,7 +723,6 @@ pci_ioport_map(struct rte_pci_device *dev, int bar __rte_unused,
>  	if (!found)
>  		return -1;
>  
> -	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;

There is the same assignment in pci_vfio_map_resource_primary(),
pci_vfio_map_resource_secondary() and pci_uio_map_resource().

Please could you check why there is such assignments?
  
Yang, Zhiyong Dec. 30, 2017, 2:19 p.m. UTC | #2
> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Friday, December 29, 2017 7:07 PM
> To: Yang, Zhiyong <zhiyong.yang@intel.com>
> Cc: dev@dpdk.org; Yigit, Ferruh <ferruh.yigit@intel.com>; stable@dpdk.org
> Subject: Re: [PATCH v2] bus/pci: fix wrong intr_handle.type with uio_pci_generic
> 
> 29/12/2017 08:55, Zhiyong Yang:
> > For virtio legacy device, testpmd startup fails when using
> > uio_pci_generic. The issue is caused by invoking the function
> > pci_ioport_map. The right intr_handle.type is already set before
> > calling it, we should avoid overwriting the default value "RTE_
> > INTR_HANDLE_UNKNOWN" in it. Besides, the removal has no harm to other
> > cases since it already is set to this value (0) at init.
> 
> To be more precise, it is set to 0 by a memset on the whole struct during
> allocation in the scan function (pci_scan_one).

Ok

> 
> > --- a/drivers/bus/pci/linux/pci.c
> > +++ b/drivers/bus/pci/linux/pci.c
> > @@ -723,7 +723,6 @@ pci_ioport_map(struct rte_pci_device *dev, int bar
> __rte_unused,
> >  	if (!found)
> >  		return -1;
> >
> > -	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> 
> There is the same assignment in pci_vfio_map_resource_primary(),
> pci_vfio_map_resource_secondary() and pci_uio_map_resource().
> 
> Please could you check why there is such assignments?

Well, Let me check them later.

Thanks
Zhiyong
  
Yang, Zhiyong Jan. 3, 2018, 3:29 a.m. UTC | #3
> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Friday, December 29, 2017 7:07 PM
> To: Yang, Zhiyong <zhiyong.yang@intel.com>
> Cc: dev@dpdk.org; Yigit, Ferruh <ferruh.yigit@intel.com>; stable@dpdk.org
> Subject: Re: [PATCH v2] bus/pci: fix wrong intr_handle.type with uio_pci_generic
> 
> 29/12/2017 08:55, Zhiyong Yang:
> > For virtio legacy device, testpmd startup fails when using
> > uio_pci_generic. The issue is caused by invoking the function
> > pci_ioport_map. The right intr_handle.type is already set before
> > calling it, we should avoid overwriting the default value "RTE_
> > INTR_HANDLE_UNKNOWN" in it. Besides, the removal has no harm to other
> > cases since it already is set to this value (0) at init.
> 
> To be more precise, it is set to 0 by a memset on the whole struct during
> allocation in the scan function (pci_scan_one).
> 
> > --- a/drivers/bus/pci/linux/pci.c
> > +++ b/drivers/bus/pci/linux/pci.c
> > @@ -723,7 +723,6 @@ pci_ioport_map(struct rte_pci_device *dev, int bar
> __rte_unused,
> >  	if (!found)
> >  		return -1;
> >
> > -	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> 
> There is the same assignment in pci_vfio_map_resource_primary(),
> pci_vfio_map_resource_secondary() and pci_uio_map_resource().
> 
> Please could you check why there is such assignments?

In general, the operation in the three functions intends to initialize the "intr_handle.type",
For example,
For pci_uio_map_resource(),  it wants to get "unknown" status once the code returns abnormally after initializing.
If the code goes smoothly,  dev->intr_handle.type must be assigned to "RTE_INTR_HANDLE_UIO"  for bsd environment,
Or must be assigned to "RTE_INTR_HANDLE_UIO" or " RTE_INTR_HANDLE_UIO_INTX" for linux environment
In consideration of the "memset" in pci_scan_one, it can be removed to has no harm to the existing logic. 
Of course, keeping it is ok.

pci_vfio_map_resource_primary() and pci_vfio_map_resource_secondary() are similar.

The author was emphasizing that  intr_handle.type should be initialized (0) and can be assigned to a right value after it.
Once fails, we can read a status "unknown". I guess.

Turn back  to the patch, it is crude to assign "unknown" directly since  pci_ioport_map is not only used by real "unknown"
But also is used to handle uio_pci_generic driver on X86 platform. It is a special case to cause error for uio_pci_generic. 

Thanks
Zhiyong
  
Thomas Monjalon Jan. 9, 2018, 3:34 p.m. UTC | #4
03/01/2018 04:29, Yang, Zhiyong:
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > 29/12/2017 08:55, Zhiyong Yang:
> > > --- a/drivers/bus/pci/linux/pci.c
> > > +++ b/drivers/bus/pci/linux/pci.c
> > > @@ -723,7 +723,6 @@ pci_ioport_map(struct rte_pci_device *dev, int bar
> > __rte_unused,
> > >  	if (!found)
> > >  		return -1;
> > >
> > > -	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> > 
> > There is the same assignment in pci_vfio_map_resource_primary(),
> > pci_vfio_map_resource_secondary() and pci_uio_map_resource().
> > 
> > Please could you check why there is such assignments?
> 
> In general, the operation in the three functions intends to initialize the "intr_handle.type",
> For example,
> For pci_uio_map_resource(),  it wants to get "unknown" status once the code returns abnormally after initializing.
> If the code goes smoothly,  dev->intr_handle.type must be assigned to "RTE_INTR_HANDLE_UIO"  for bsd environment,
> Or must be assigned to "RTE_INTR_HANDLE_UIO" or " RTE_INTR_HANDLE_UIO_INTX" for linux environment
> In consideration of the "memset" in pci_scan_one, it can be removed to has no harm to the existing logic.

So what do you think of doing a v3 which removes it everywhere?
It would remove inconsistencies and avoid future questions.

> Of course, keeping it is ok.
> 
> pci_vfio_map_resource_primary() and pci_vfio_map_resource_secondary() are similar.
> 
> The author was emphasizing that  intr_handle.type should be initialized (0) and can be assigned to a right value after it.
> Once fails, we can read a status "unknown". I guess.
> 
> Turn back  to the patch, it is crude to assign "unknown" directly since  pci_ioport_map is not only used by real "unknown"
> But also is used to handle uio_pci_generic driver on X86 platform. It is a special case to cause error for uio_pci_generic.
  
Yang, Zhiyong Jan. 10, 2018, 1:28 a.m. UTC | #5
> -----Original Message-----
> From: Thomas Monjalon [mailto:thomas@monjalon.net]
> Sent: Tuesday, January 9, 2018 11:34 PM
> To: Yang, Zhiyong <zhiyong.yang@intel.com>
> Cc: dev@dpdk.org; Yigit, Ferruh <ferruh.yigit@intel.com>
> Subject: Re: [dpdk-dev] [PATCH v2] bus/pci: fix wrong intr_handle.type with
> uio_pci_generic
> 
> 03/01/2018 04:29, Yang, Zhiyong:
> > From: Thomas Monjalon [mailto:thomas@monjalon.net]
> > > 29/12/2017 08:55, Zhiyong Yang:
> > > > --- a/drivers/bus/pci/linux/pci.c
> > > > +++ b/drivers/bus/pci/linux/pci.c
> > > > @@ -723,7 +723,6 @@ pci_ioport_map(struct rte_pci_device *dev, int
> > > > bar
> > > __rte_unused,
> > > >  	if (!found)
> > > >  		return -1;
> > > >
> > > > -	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
> > >
> > > There is the same assignment in pci_vfio_map_resource_primary(),
> > > pci_vfio_map_resource_secondary() and pci_uio_map_resource().
> > >
> > > Please could you check why there is such assignments?
> >
> > In general, the operation in the three functions intends to initialize
> > the "intr_handle.type", For example, For pci_uio_map_resource(),  it
> > wants to get "unknown" status once the code returns abnormally after
> initializing.
> > If the code goes smoothly,  dev->intr_handle.type must be assigned to
> > "RTE_INTR_HANDLE_UIO"  for bsd environment, Or must be assigned to
> > "RTE_INTR_HANDLE_UIO" or " RTE_INTR_HANDLE_UIO_INTX" for linux
> environment In consideration of the "memset" in pci_scan_one, it can be
> removed to has no harm to the existing logic.
> 
> So what do you think of doing a v3 which removes it everywhere?
> It would remove inconsistencies and avoid future questions.
> 

It's reasonable  and I will do that in V3.

Thanks
Zhiyong
  

Patch

diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c
index 5da6728fb..ec31216bc 100644
--- a/drivers/bus/pci/linux/pci.c
+++ b/drivers/bus/pci/linux/pci.c
@@ -723,7 +723,6 @@  pci_ioport_map(struct rte_pci_device *dev, int bar __rte_unused,
 	if (!found)
 		return -1;
 
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
 	p->base = start;
 	RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%x\n", start);