diff mbox series

[net,v3,1/4] net: txgbe: initialize num_q_vectors for MSI/INTx interrupts

Message ID 20240701071416.8468-2-jiawenwu@trustnetic.com (mailing list archive)
State Accepted
Commit 7c36711a2cd8059c2d24f5e5c1d76e8ea2d5613c
Delegated to: Netdev Maintainers
Headers show
Series net: txgbe: fix MSI and INTx interrupts | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 856 this patch: 856
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 860 this patch: 860
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 860 this patch: 860
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 14 this patch: 14
netdev/source_inline success Was 0 now: 0

Commit Message

Jiawen Wu July 1, 2024, 7:14 a.m. UTC
When using MSI/INTx interrupts, wx->num_q_vectors is uninitialized.
Thus there will be kernel panic in wx_alloc_q_vectors() to allocate
queue vectors.

Fixes: 3f703186113f ("net: libwx: Add irq flow functions")
Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
---
 drivers/net/ethernet/wangxun/libwx/wx_lib.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Michal Kubiak July 2, 2024, 3:21 p.m. UTC | #1
On Mon, Jul 01, 2024 at 03:14:13PM +0800, Jiawen Wu wrote:
> When using MSI/INTx interrupts, wx->num_q_vectors is uninitialized.
> Thus there will be kernel panic in wx_alloc_q_vectors() to allocate
> queue vectors.
> 
> Fixes: 3f703186113f ("net: libwx: Add irq flow functions")
> Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> ---
>  drivers/net/ethernet/wangxun/libwx/wx_lib.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> index 68bde91b67a0..f53776877f71 100644
> --- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> +++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> @@ -1686,6 +1686,7 @@ static int wx_set_interrupt_capability(struct wx *wx)
>  	}
>  
>  	pdev->irq = pci_irq_vector(pdev, 0);
> +	wx->num_q_vectors = 1;

I would suggest improving readability of that logic. TBH, initially it wasn't
obvious to me why you assign 1 to num_q_vectors (instead of nvecs variable).
Maybe you just want to exit with an error when nvecs != 1 and avoid some nesting.
I think that should make that logic easier to read. For example:

        /* minmum one for queue, one for misc*/
        nvecs = 1;
        nvecs = pci_alloc_irq_vectors(pdev, nvecs,
                                      nvecs, PCI_IRQ_MSI | PCI_IRQ_INTX);
        if (nvecs != 1) {
                wx_err(wx, "Failed to allocate MSI/INTx interrupts. Error: %d\n", nvecs);
                return nvecs;
        }

        if (pdev->msi_enabled)
                wx_err(wx, "Fallback to MSI.\n");
        else
                wx_err(wx, "Fallback to INTx.\n");

        pdev->irq = pci_irq_vector(pdev, 0);
	wx->num_q_vectors = 1;

(Please consider it as a suggestion only).
>  
>  	return 0;
>  }
> -- 
> 2.27.0
> 
> 

Thanks,
Michal
Jiawen Wu July 3, 2024, 1:45 a.m. UTC | #2
On Tue, Jul 2, 2024 11:22 PM, Michal Kubiak wrote:
> On Mon, Jul 01, 2024 at 03:14:13PM +0800, Jiawen Wu wrote:
> > When using MSI/INTx interrupts, wx->num_q_vectors is uninitialized.
> > Thus there will be kernel panic in wx_alloc_q_vectors() to allocate
> > queue vectors.
> >
> > Fixes: 3f703186113f ("net: libwx: Add irq flow functions")
> > Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
> > ---
> >  drivers/net/ethernet/wangxun/libwx/wx_lib.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> > index 68bde91b67a0..f53776877f71 100644
> > --- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> > +++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
> > @@ -1686,6 +1686,7 @@ static int wx_set_interrupt_capability(struct wx *wx)
> >  	}
> >
> >  	pdev->irq = pci_irq_vector(pdev, 0);
> > +	wx->num_q_vectors = 1;
> 
> I would suggest improving readability of that logic. TBH, initially it wasn't
> obvious to me why you assign 1 to num_q_vectors (instead of nvecs variable).
> Maybe you just want to exit with an error when nvecs != 1 and avoid some nesting.
> I think that should make that logic easier to read. For example:
> 
>         /* minmum one for queue, one for misc*/
>         nvecs = 1;
>         nvecs = pci_alloc_irq_vectors(pdev, nvecs,
>                                       nvecs, PCI_IRQ_MSI | PCI_IRQ_INTX);
>         if (nvecs != 1) {
>                 wx_err(wx, "Failed to allocate MSI/INTx interrupts. Error: %d\n", nvecs);
>                 return nvecs;
>         }
> 
>         if (pdev->msi_enabled)
>                 wx_err(wx, "Fallback to MSI.\n");
>         else
>                 wx_err(wx, "Fallback to INTx.\n");
> 
>         pdev->irq = pci_irq_vector(pdev, 0);
> 	wx->num_q_vectors = 1;
> 
> (Please consider it as a suggestion only).

Thanks for the suggestion, it can be considered as a commit for code optimization.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/wangxun/libwx/wx_lib.c b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
index 68bde91b67a0..f53776877f71 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_lib.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_lib.c
@@ -1686,6 +1686,7 @@  static int wx_set_interrupt_capability(struct wx *wx)
 	}
 
 	pdev->irq = pci_irq_vector(pdev, 0);
+	wx->num_q_vectors = 1;
 
 	return 0;
 }