diff mbox series

[net] net: stmmac: fix invalid usage of irq_set_affinity_hint

Message ID 20220914015120.3023123-1-dqfext@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net] net: stmmac: fix invalid usage of irq_set_affinity_hint | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 28 this patch: 28
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 2
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
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: 28 this patch: 28
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 47 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Qingfang Deng Sept. 14, 2022, 1:51 a.m. UTC
The cpumask should not be a local variable, since its pointer is saved
to irq_desc and may be accessed from procfs.
To fix it, store cpumask to the heap.

Fixes: 8deec94c6040 ("net: stmmac: set IRQ affinity hint for multi MSI vectors")
Signed-off-by: Qingfang DENG <dqfext@gmail.com>
---
 drivers/net/ethernet/stmicro/stmmac/stmmac.h      |  2 ++
 drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 15 ++++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

Comments

Robin Murphy Sept. 14, 2022, 10:47 a.m. UTC | #1
On 2022-09-14 02:51, Qingfang DENG wrote:
> The cpumask should not be a local variable, since its pointer is saved
> to irq_desc and may be accessed from procfs.
> To fix it, store cpumask to the heap.

FWIW, by the look of it you might be able to use cpumask_of() and not 
store anything at all.

Robin.

> Fixes: 8deec94c6040 ("net: stmmac: set IRQ affinity hint for multi MSI vectors")
> Signed-off-by: Qingfang DENG <dqfext@gmail.com>
> ---
>   drivers/net/ethernet/stmicro/stmmac/stmmac.h      |  2 ++
>   drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 15 ++++++++-------
>   2 files changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
> index bdbf86cb102a..720e9f2a40d8 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
> @@ -77,6 +77,7 @@ struct stmmac_tx_queue {
>   	dma_addr_t dma_tx_phy;
>   	dma_addr_t tx_tail_addr;
>   	u32 mss;
> +	cpumask_t cpu_mask;
>   };
>   
>   struct stmmac_rx_buffer {
> @@ -114,6 +115,7 @@ struct stmmac_rx_queue {
>   		unsigned int len;
>   		unsigned int error;
>   	} state;
> +	cpumask_t cpu_mask;
>   };
>   
>   struct stmmac_channel {
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> index 8418e795cc21..7b1c1be998e3 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
> @@ -3469,7 +3469,6 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev)
>   {
>   	struct stmmac_priv *priv = netdev_priv(dev);
>   	enum request_irq_err irq_err;
> -	cpumask_t cpu_mask;
>   	int irq_idx = 0;
>   	char *int_name;
>   	int ret;
> @@ -3580,9 +3579,10 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev)
>   			irq_idx = i;
>   			goto irq_error;
>   		}
> -		cpumask_clear(&cpu_mask);
> -		cpumask_set_cpu(i % num_online_cpus(), &cpu_mask);
> -		irq_set_affinity_hint(priv->rx_irq[i], &cpu_mask);
> +		cpumask_set_cpu(i % num_online_cpus(),
> +				&priv->dma_conf.rx_queue[i].cpu_mask);
> +		irq_set_affinity_hint(priv->rx_irq[i],
> +				      &priv->dma_conf.rx_queue[i].cpu_mask);
>   	}
>   
>   	/* Request Tx MSI irq */
> @@ -3605,9 +3605,10 @@ static int stmmac_request_irq_multi_msi(struct net_device *dev)
>   			irq_idx = i;
>   			goto irq_error;
>   		}
> -		cpumask_clear(&cpu_mask);
> -		cpumask_set_cpu(i % num_online_cpus(), &cpu_mask);
> -		irq_set_affinity_hint(priv->tx_irq[i], &cpu_mask);
> +		cpumask_set_cpu(i % num_online_cpus(),
> +				&priv->dma_conf.tx_queue[i].cpu_mask);
> +		irq_set_affinity_hint(priv->tx_irq[i],
> +				      &priv->dma_conf.tx_queue[i].cpu_mask);
>   	}
>   
>   	return 0;
diff mbox series

Patch

diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index bdbf86cb102a..720e9f2a40d8 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -77,6 +77,7 @@  struct stmmac_tx_queue {
 	dma_addr_t dma_tx_phy;
 	dma_addr_t tx_tail_addr;
 	u32 mss;
+	cpumask_t cpu_mask;
 };
 
 struct stmmac_rx_buffer {
@@ -114,6 +115,7 @@  struct stmmac_rx_queue {
 		unsigned int len;
 		unsigned int error;
 	} state;
+	cpumask_t cpu_mask;
 };
 
 struct stmmac_channel {
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index 8418e795cc21..7b1c1be998e3 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -3469,7 +3469,6 @@  static int stmmac_request_irq_multi_msi(struct net_device *dev)
 {
 	struct stmmac_priv *priv = netdev_priv(dev);
 	enum request_irq_err irq_err;
-	cpumask_t cpu_mask;
 	int irq_idx = 0;
 	char *int_name;
 	int ret;
@@ -3580,9 +3579,10 @@  static int stmmac_request_irq_multi_msi(struct net_device *dev)
 			irq_idx = i;
 			goto irq_error;
 		}
-		cpumask_clear(&cpu_mask);
-		cpumask_set_cpu(i % num_online_cpus(), &cpu_mask);
-		irq_set_affinity_hint(priv->rx_irq[i], &cpu_mask);
+		cpumask_set_cpu(i % num_online_cpus(),
+				&priv->dma_conf.rx_queue[i].cpu_mask);
+		irq_set_affinity_hint(priv->rx_irq[i],
+				      &priv->dma_conf.rx_queue[i].cpu_mask);
 	}
 
 	/* Request Tx MSI irq */
@@ -3605,9 +3605,10 @@  static int stmmac_request_irq_multi_msi(struct net_device *dev)
 			irq_idx = i;
 			goto irq_error;
 		}
-		cpumask_clear(&cpu_mask);
-		cpumask_set_cpu(i % num_online_cpus(), &cpu_mask);
-		irq_set_affinity_hint(priv->tx_irq[i], &cpu_mask);
+		cpumask_set_cpu(i % num_online_cpus(),
+				&priv->dma_conf.tx_queue[i].cpu_mask);
+		irq_set_affinity_hint(priv->tx_irq[i],
+				      &priv->dma_conf.tx_queue[i].cpu_mask);
 	}
 
 	return 0;