forked from mirrors/linux
		
	net: xilinx: axienet: Fix race in axienet_stop
axienet_dma_err_handler can race with axienet_stop in the following
manner:
CPU 1                       CPU 2
======================      ==================
axienet_stop()
    napi_disable()
    axienet_dma_stop()
                            axienet_dma_err_handler()
                                napi_disable()
                                axienet_dma_stop()
                                axienet_dma_start()
                                napi_enable()
    cancel_work_sync()
    free_irq()
Fix this by setting a flag in axienet_stop telling
axienet_dma_err_handler not to bother doing anything. I chose not to use
disable_work_sync to allow for easier backporting.
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Fixes: 8a3b7a252d ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")
Link: https://patch.msgid.link/20240903175141.4132898-1-sean.anderson@linux.dev
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
			
			
This commit is contained in:
		
							parent
							
								
									bee2ef946d
								
							
						
					
					
						commit
						858430db28
					
				
					 2 changed files with 11 additions and 0 deletions
				
			
		|  | @ -436,6 +436,8 @@ struct skbuf_dma_descriptor { | |||
|  * @tx_bytes:	TX byte count for statistics | ||||
|  * @tx_stat_sync: Synchronization object for TX stats | ||||
|  * @dma_err_task: Work structure to process Axi DMA errors | ||||
|  * @stopping:   Set when @dma_err_task shouldn't do anything because we are | ||||
|  *              about to stop the device. | ||||
|  * @tx_irq:	Axidma TX IRQ number | ||||
|  * @rx_irq:	Axidma RX IRQ number | ||||
|  * @eth_irq:	Ethernet core IRQ number | ||||
|  | @ -507,6 +509,7 @@ struct axienet_local { | |||
| 	struct u64_stats_sync tx_stat_sync; | ||||
| 
 | ||||
| 	struct work_struct dma_err_task; | ||||
| 	bool stopping; | ||||
| 
 | ||||
| 	int tx_irq; | ||||
| 	int rx_irq; | ||||
|  |  | |||
|  | @ -1460,6 +1460,7 @@ static int axienet_init_legacy_dma(struct net_device *ndev) | |||
| 	struct axienet_local *lp = netdev_priv(ndev); | ||||
| 
 | ||||
| 	/* Enable worker thread for Axi DMA error handling */ | ||||
| 	lp->stopping = false; | ||||
| 	INIT_WORK(&lp->dma_err_task, axienet_dma_err_handler); | ||||
| 
 | ||||
| 	napi_enable(&lp->napi_rx); | ||||
|  | @ -1580,6 +1581,9 @@ static int axienet_stop(struct net_device *ndev) | |||
| 	dev_dbg(&ndev->dev, "axienet_close()\n"); | ||||
| 
 | ||||
| 	if (!lp->use_dmaengine) { | ||||
| 		WRITE_ONCE(lp->stopping, true); | ||||
| 		flush_work(&lp->dma_err_task); | ||||
| 
 | ||||
| 		napi_disable(&lp->napi_tx); | ||||
| 		napi_disable(&lp->napi_rx); | ||||
| 	} | ||||
|  | @ -2154,6 +2158,10 @@ static void axienet_dma_err_handler(struct work_struct *work) | |||
| 						dma_err_task); | ||||
| 	struct net_device *ndev = lp->ndev; | ||||
| 
 | ||||
| 	/* Don't bother if we are going to stop anyway */ | ||||
| 	if (READ_ONCE(lp->stopping)) | ||||
| 		return; | ||||
| 
 | ||||
| 	napi_disable(&lp->napi_tx); | ||||
| 	napi_disable(&lp->napi_rx); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Sean Anderson
						Sean Anderson