Skip to contentSkip to conversation

netdev: replace simple napi_schedule_prep/__napi_schedule to napi_schedule

PATCH Superseded Christian Marangi 3 participants 15 messages Oct 3, 2023 – Oct 9, 2023

Subsystems (21)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 netdev: replace simple napi_schedule_prep/__napi_schedule to napi_schedule

Replace drivers that still use napi_schedule_prep/__napi_schedule with napi_schedule helper as it does the same exact check and call.

---
Changes v2:
- Add missing semicolon

---
 drivers/net/ethernet/ni/nixge.c     | 3 +--
 drivers/net/ethernet/wiznet/w5100.c | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)
drivers/net/ethernet/ni/nixge.c +1 -2
index 97f4798f4b42..f71a4f8bbb89 100644
@@ -755,8 +755,7 @@ static irqreturn_t nixge_rx_irq(int irq, void *_ndev)
 		cr &= ~(XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_DELAY_MASK);
 		nixge_dma_write_reg(priv, XAXIDMA_RX_CR_OFFSET, cr);
 
-		if (napi_schedule_prep(&priv->napi))
-			__napi_schedule(&priv->napi);
+		napi_schedule(&priv->napi);
 		goto out;
 	}
 	if (!(status & XAXIDMA_IRQ_ALL_MASK)) {
drivers/net/ethernet/wiznet/w5100.c +2 -2
index 341ee2f249fd..b26fd15c25ae 100644
@@ -930,8 +930,8 @@ static irqreturn_t w5100_interrupt(int irq, void *ndev_instance)
 
 		if (priv->ops->may_sleep)
 			queue_work(priv->xfer_wq, &priv->rx_work);
-		else if (napi_schedule_prep(&priv->napi))
-			__napi_schedule(&priv->napi);
+		else
+			napi_schedule(&priv->napi);
 	}
 
 	return IRQ_HANDLED;
Signature · 1 line
2.40.1
#1 lore raw

PATCH v2 2/4 netdev: make napi_schedule return bool on NAPI successful schedule

Change napi_schedule to return a bool on NAPI successful schedule. This might be useful for some driver to do additional steps after a NAPI has been scheduled.

---
Changes v2:
- Add Suggested-by tag
- Add Reviewed-by tag

---
 include/linux/netdevice.h | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
include/linux/netdevice.h +9 -2
index 7e520c14eb8c..2bead8e2a14d 100644
@@ -490,11 +490,18 @@ bool napi_schedule_prep(struct napi_struct *n);
  *
  * Schedule NAPI poll routine to be called if it is not already
  * running.
+ * Return true if we schedule a NAPI or false if not.
+ * Refer to napi_schedule_prep() for additional reason on why
+ * a NAPI might not be scheduled.
  */
-static inline void napi_schedule(struct napi_struct *n)
+static inline bool napi_schedule(struct napi_struct *n)
 {
-	if (napi_schedule_prep(n))
+	if (napi_schedule_prep(n)) {
 		__napi_schedule(n);
+		return true;
+	}
+
+	return false;
 }
 
 /**
Signature · 1 line
2.40.1
#2 lore raw

PATCH v2 3/4 netdev: replace napi_reschedule with napi_schedule

In reply to Christian Marangi

Now that napi_schedule return a bool, we can drop napi_reschedule that does the same exact function. The function comes from a very old commit bfe13f54f502 ("ibm_emac: Convert to use napi_struct independent of struct net_device") and the purpose is actually deprecated in favour of different logic.

Convert every user of napi_reschedule to napi_schedule.

---
Changes v2:
- Add ack tag

---
 drivers/infiniband/ulp/ipoib/ipoib_ib.c                |  4 ++--
 drivers/net/can/dev/rx-offload.c                       |  2 +-
 drivers/net/ethernet/chelsio/cxgb4/sge.c               |  2 +-
 drivers/net/ethernet/chelsio/cxgb4vf/sge.c             |  2 +-
 drivers/net/ethernet/ezchip/nps_enet.c                 |  2 +-
 drivers/net/ethernet/google/gve/gve_main.c             |  2 +-
 drivers/net/ethernet/ibm/ehea/ehea_main.c              |  2 +-
 drivers/net/ethernet/ibm/emac/mal.c                    |  2 +-
 drivers/net/ethernet/ibm/ibmveth.c                     |  2 +-
 drivers/net/ethernet/ibm/ibmvnic.c                     |  2 +-
 drivers/net/ethernet/mellanox/mlx4/en_rx.c             |  2 +-
 drivers/net/ethernet/ni/nixge.c                        |  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c |  2 +-
 drivers/net/ethernet/xscale/ixp4xx_eth.c               |  4 ++--
 drivers/net/fjes/fjes_main.c                           |  2 +-
 drivers/net/wan/ixp4xx_hss.c                           |  4 ++--
 drivers/net/wireless/ath/ath10k/pci.c                  |  2 +-
 drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c             |  2 +-
 include/linux/netdevice.h                              | 10 ----------
 19 files changed, 21 insertions(+), 31 deletions(-)
drivers/infiniband/ulp/ipoib/ipoib_ib.c +2 -2
index ed25061fac62..7f84d9866cef 100644
@@ -488,7 +488,7 @@ int ipoib_rx_poll(struct napi_struct *napi, int budget)
 		if (unlikely(ib_req_notify_cq(priv->recv_cq,
 					      IB_CQ_NEXT_COMP |
 					      IB_CQ_REPORT_MISSED_EVENTS)) &&
-		    napi_reschedule(napi))
+		    napi_schedule(napi))
 			goto poll_more;
 	}
 
@@ -518,7 +518,7 @@ int ipoib_tx_poll(struct napi_struct *napi, int budget)
 		napi_complete(napi);
 		if (unlikely(ib_req_notify_cq(priv->send_cq, IB_CQ_NEXT_COMP |
 					      IB_CQ_REPORT_MISSED_EVENTS)) &&
-		    napi_reschedule(napi))
+		    napi_schedule(napi))
 			goto poll_more;
 	}
 	return n < 0 ? 0 : n;
drivers/net/can/dev/rx-offload.c +1 -1
index 77091f7d1fa7..46e7b6db4a1e 100644
@@ -67,7 +67,7 @@ static int can_rx_offload_napi_poll(struct napi_struct *napi, int quota)
 
 		/* Check if there was another interrupt */
 		if (!skb_queue_empty(&offload->skb_queue))
-			napi_reschedule(&offload->napi);
+			napi_schedule(&offload->napi);
 	}
 
 	return work_done;
drivers/net/ethernet/chelsio/cxgb4/sge.c +1 -1
index 98dd78551d89..b5ff2e1a9975 100644
@@ -4261,7 +4261,7 @@ static void sge_rx_timer_cb(struct timer_list *t)
 
 			if (fl_starving(adap, fl)) {
 				rxq = container_of(fl, struct sge_eth_rxq, fl);
-				if (napi_reschedule(&rxq->rspq.napi))
+				if (napi_schedule(&rxq->rspq.napi))
 					fl->starving++;
 				else
 					set_bit(id, s->starving_fl);
drivers/net/ethernet/chelsio/cxgb4vf/sge.c +1 -1
index 2d0cf76fb3c5..5b1d746e6563 100644
@@ -2094,7 +2094,7 @@ static void sge_rx_timer_cb(struct timer_list *t)
 				struct sge_eth_rxq *rxq;
 
 				rxq = container_of(fl, struct sge_eth_rxq, fl);
-				if (napi_reschedule(&rxq->rspq.napi))
+				if (napi_schedule(&rxq->rspq.napi))
 					fl->starving++;
 				else
 					set_bit(id, s->starving_fl);
drivers/net/ethernet/ezchip/nps_enet.c +1 -1
index edf000e7bab4..4d7184d46824 100644
@@ -198,7 +198,7 @@ static int nps_enet_poll(struct napi_struct *napi, int budget)
 		 */
 		if (nps_enet_is_tx_pending(priv)) {
 			nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0);
-			napi_reschedule(napi);
+			napi_schedule(napi);
 		}
 	}
 
drivers/net/ethernet/google/gve/gve_main.c +1 -1
index 83b09dcfafc4..276f996f95dc 100644
@@ -281,7 +281,7 @@ static int gve_napi_poll(struct napi_struct *napi, int budget)
 		if (block->rx)
 			reschedule |= gve_rx_work_pending(block->rx);
 
-		if (reschedule && napi_reschedule(napi))
+		if (reschedule && napi_schedule(napi))
 			iowrite32be(GVE_IRQ_MASK, irq_doorbell);
 	}
 	return work_done;
drivers/net/ethernet/ibm/ehea/ehea_main.c +1 -1
index 251dedd55cfb..1e29e5c9a2df 100644
@@ -900,7 +900,7 @@ static int ehea_poll(struct napi_struct *napi, int budget)
 		if (!cqe && !cqe_skb)
 			return rx;
 
-		if (!napi_reschedule(napi))
+		if (!napi_schedule(napi))
 			return rx;
 
 		cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
drivers/net/ethernet/ibm/emac/mal.c +1 -1
index 462646d1b817..2439f7e96e05 100644
@@ -442,7 +442,7 @@ static int mal_poll(struct napi_struct *napi, int budget)
 		if (unlikely(mc->ops->peek_rx(mc->dev) ||
 			     test_bit(MAL_COMMAC_RX_STOPPED, &mc->flags))) {
 			MAL_DBG2(mal, "rotting packet" NL);
-			if (!napi_reschedule(napi))
+			if (!napi_schedule(napi))
 				goto more_work;
 
 			spin_lock_irqsave(&mal->lock, flags);
drivers/net/ethernet/ibm/ibmveth.c +1 -1
index 832a2ae01950..9490272c0421 100644
@@ -1433,7 +1433,7 @@ static int ibmveth_poll(struct napi_struct *napi, int budget)
 		BUG_ON(lpar_rc != H_SUCCESS);
 
 		if (ibmveth_rxq_pending_buffer(adapter) &&
-		    napi_reschedule(napi)) {
+		    napi_schedule(napi)) {
 			lpar_rc = h_vio_signal(adapter->vdev->unit_address,
 					       VIO_IRQ_DISABLE);
 		}
drivers/net/ethernet/ibm/ibmvnic.c +1 -1
index cdf5251e5679..2094f413cbe4 100644
@@ -3519,7 +3519,7 @@ static int ibmvnic_poll(struct napi_struct *napi, int budget)
 		if (napi_complete_done(napi, frames_processed)) {
 			enable_scrq_irq(adapter, rx_scrq);
 			if (pending_scrq(adapter, rx_scrq)) {
-				if (napi_reschedule(napi)) {
+				if (napi_schedule(napi)) {
 					disable_scrq_irq(adapter, rx_scrq);
 					goto restart_poll;
 				}
drivers/net/ethernet/mellanox/mlx4/en_rx.c +1 -1
index 332472fe4990..a09b6e05337d 100644
@@ -400,7 +400,7 @@ void mlx4_en_recover_from_oom(struct mlx4_en_priv *priv)
 	for (ring = 0; ring < priv->rx_ring_num; ring++) {
 		if (mlx4_en_is_ring_empty(priv->rx_ring[ring])) {
 			local_bh_disable();
-			napi_reschedule(&priv->rx_cq[ring]->napi);
+			napi_schedule(&priv->rx_cq[ring]->napi);
 			local_bh_enable();
 		}
 	}
drivers/net/ethernet/ni/nixge.c +1 -1
index f71a4f8bbb89..fa1f78b03cb2 100644
@@ -683,7 +683,7 @@ static int nixge_poll(struct napi_struct *napi, int budget)
 		if (status & (XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_DELAY_MASK)) {
 			/* If there's more, reschedule, but clear */
 			nixge_dma_write_reg(priv, XAXIDMA_RX_SR_OFFSET, status);
-			napi_reschedule(napi);
+			napi_schedule(napi);
 		} else {
 			/* if not, turn on RX IRQs again ... */
 			cr = nixge_dma_read_reg(priv, XAXIDMA_RX_CR_OFFSET);
drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c +1 -1
index f9e43fc32ee8..3ca1c2a816ff 100644
@@ -802,7 +802,7 @@ static int stmmac_test_flowctrl(struct stmmac_priv *priv)
 		stmmac_start_rx(priv, priv->ioaddr, i);
 
 		local_bh_disable();
-		napi_reschedule(&ch->rx_napi);
+		napi_schedule(&ch->rx_napi);
 		local_bh_enable();
 	}
 
drivers/net/ethernet/xscale/ixp4xx_eth.c +2 -2
index b242aa61d8ab..64dea4ad2ad3 100644
@@ -714,9 +714,9 @@ static int eth_poll(struct napi_struct *napi, int budget)
 			napi_complete(napi);
 			qmgr_enable_irq(rxq);
 			if (!qmgr_stat_below_low_watermark(rxq) &&
-			    napi_reschedule(napi)) { /* not empty again */
+			    napi_schedule(napi)) { /* not empty again */
 #if DEBUG_RX
-				netdev_debug(dev, "eth_poll napi_reschedule succeeded\n");
+				netdev_debug(dev, "eth_poll napi_schedule succeeded\n");
 #endif
 				qmgr_disable_irq(rxq);
 				continue;
drivers/net/fjes/fjes_main.c +1 -1
index 2513be6d4e11..cd8cf08477ec 100644
@@ -1030,7 +1030,7 @@ static int fjes_poll(struct napi_struct *napi, int budget)
 		}
 
 		if (((long)jiffies - (long)adapter->rx_last_jiffies) < 3) {
-			napi_reschedule(napi);
+			napi_schedule(napi);
 		} else {
 			spin_lock(&hw->rx_status_lock);
 			for (epidx = 0; epidx < hw->max_epid; epidx++) {
drivers/net/wan/ixp4xx_hss.c +2 -2
index e46b7f5ee49e..b09f4c235142 100644
@@ -687,10 +687,10 @@ static int hss_hdlc_poll(struct napi_struct *napi, int budget)
 			napi_complete(napi);
 			qmgr_enable_irq(rxq);
 			if (!qmgr_stat_empty(rxq) &&
-			    napi_reschedule(napi)) {
+			    napi_schedule(napi)) {
 #if DEBUG_RX
 				printk(KERN_DEBUG "%s: hss_hdlc_poll"
-				       " napi_reschedule succeeded\n",
+				       " napi_schedule succeeded\n",
 				       dev->name);
 #endif
 				qmgr_disable_irq(rxq);
drivers/net/wireless/ath/ath10k/pci.c +1 -1
index 23f366221939..2f8c785277af 100644
@@ -3148,7 +3148,7 @@ static int ath10k_pci_napi_poll(struct napi_struct *ctx, int budget)
 		 * immediate servicing.
 		 */
 		if (ath10k_ce_interrupt_summary(ar)) {
-			napi_reschedule(ctx);
+			napi_schedule(ctx);
 			goto out;
 		}
 		ath10k_pci_enable_legacy_irq(ar);
drivers/net/wwan/t7xx/t7xx_hif_dpmaif_rx.c +1 -1
index f4ff2198b5ef..210d84c67ef9 100644
@@ -852,7 +852,7 @@ int t7xx_dpmaif_napi_rx_poll(struct napi_struct *napi, const int budget)
 	if (!ret) {
 		napi_complete_done(napi, work_done);
 		rxq->sleep_lock_pending = true;
-		napi_reschedule(napi);
+		napi_schedule(napi);
 		return work_done;
 	}
 
include/linux/netdevice.h +0 -10
index 2bead8e2a14d..bbf9038f2afd 100644
@@ -516,16 +516,6 @@ static inline void napi_schedule_irqoff(struct napi_struct *n)
 		__napi_schedule_irqoff(n);
 }
 
-/* Try to reschedule poll. Called by dev->poll() after napi_complete().  */
-static inline bool napi_reschedule(struct napi_struct *napi)
-{
-	if (napi_schedule_prep(napi)) {
-		__napi_schedule(napi);
-		return true;
-	}
-	return false;
-}
-
 /**
  * napi_complete_done - NAPI processing complete
  * @n: NAPI context
Signature · 1 line
2.40.1
Reviewed-by on v2 3/4
#3 lore raw

Re: [net-next PATCH v2 3/4] netdev: replace napi_reschedule with napi_schedule

Quoted 7 lines · Christian Marangi

Now that napi_schedule return a bool, we can drop napi_reschedule that does the same exact function. The function comes from a very old commit bfe13f54f502 ("ibm_emac: Convert to use napi_struct independent of struct net_device") and the purpose is actually deprecated in favour of different logic.

Quoted 6 lines

Convert every user of napi_reschedule to napi_schedule.

OK, but I suspect some users of napi_reschedule() might not be race-free...

maintainer
#4 lore raw

Re: [net-next PATCH v2 3/4] netdev: replace napi_reschedule with napi_schedule

Quoted 1 line · On Thu, 5 Oct 2023 18:11:56 +0200 Eric Dumazet wrote:

OK, but I suspect some users of napi_reschedule() might not be race-free...

What's the race you're thinking of?

#5 lore raw

Re: [net-next PATCH v2 3/4] netdev: replace napi_reschedule with napi_schedule

Quoted 5 lines · Jakub Kicinski
Quoted 1 line · On Thu, 5 Oct 2023 18:11:56 +0200 Eric Dumazet wrote:

OK, but I suspect some users of napi_reschedule() might not be race-free...

What's the race you're thinking of?

This sort of thing... the race is in fl_starving() though...

(quoted diff) +0 -0

b/drivers/net/ethernet/chelsio/cxgb4/sge.c
index 98dd78551d89..b5ff2e1a9975 100644

drivers/net/ethernet/chelsio/cxgb4/sge.c +1 -1
@@ -4261,7 +4261,7 @@ static void sge_rx_timer_cb(struct timer_list *t)
 
                        if (fl_starving(adap, fl)) {
                                rxq = container_of(fl, struct sge_eth_rxq, fl);
-                               if (napi_reschedule(&rxq->rspq.napi))
+                               if (napi_schedule(&rxq->rspq.napi))
                                        fl->starving++;
                                else
                                        set_bit(id, s->starving_fl);
#6 lore raw

Re: [net-next PATCH v2 3/4] netdev: replace napi_reschedule with napi_schedule

Quoted 15 lines · Eric Dumazet
Quoted 5 lines · Jakub Kicinski
Quoted 1 line · On Thu, 5 Oct 2023 18:11:56 +0200 Eric Dumazet wrote:

OK, but I suspect some users of napi_reschedule() might not be race-free...

What's the race you're thinking of?

This sort of thing... the race is in fl_starving() though...

drivers/net/ethernet/chelsio/cxgb4/sge.c +0 -0
index 98dd78551d89..b5ff2e1a9975 100644

drivers/net/ethernet/chelsio/cxgb4/sge.c static void sge_rx_timer_cb(struct timer_list *t) · line 4267

Quoted 8 lines
drivers/net/ethernet/chelsio/cxgb4/sge.c +1 -1
@@ -4261,7 +4261,7 @@ static void sge_rx_timer_cb(struct timer_list *t)
 
                        if (fl_starving(adap, fl)) {
                                rxq = container_of(fl, struct sge_eth_rxq, fl);
-                               if (napi_reschedule(&rxq->rspq.napi))
+                               if (napi_schedule(&rxq->rspq.napi))
                                        fl->starving++;
                                else
                                        set_bit(id, s->starving_fl);

Ehhh problem is that this is a simple rename so if any race is present, it's already there and not caused by this rename :(

Don't know maybe this is out of scope and should be investigated with a bug report?

Maybe this should be changed to prep/__schedule to prevent any kind of race? But doing so doesn't prevent any kind of ""starving""?

Signature · 1 line
	Ansuel
#7 lore raw

Re: [net-next PATCH v2 3/4] netdev: replace napi_reschedule with napi_schedule

Quoted 29 lines · Christian Marangi
Quoted 15 lines · Eric Dumazet
Quoted 5 lines · Jakub Kicinski
Quoted 1 line · On Thu, 5 Oct 2023 18:11:56 +0200 Eric Dumazet wrote:

OK, but I suspect some users of napi_reschedule() might not be race-free...

What's the race you're thinking of?

This sort of thing... the race is in fl_starving() though...

drivers/net/ethernet/chelsio/cxgb4/sge.c +0 -0
index 98dd78551d89..b5ff2e1a9975 100644

drivers/net/ethernet/chelsio/cxgb4/sge.c static void sge_rx_timer_cb(struct timer_list *t) · line 4267

Quoted 8 lines
drivers/net/ethernet/chelsio/cxgb4/sge.c +1 -1
@@ -4261,7 +4261,7 @@ static void sge_rx_timer_cb(struct timer_list *t)
 
                        if (fl_starving(adap, fl)) {
                                rxq = container_of(fl, struct sge_eth_rxq, fl);
-                               if (napi_reschedule(&rxq->rspq.napi))
+                               if (napi_schedule(&rxq->rspq.napi))
                                        fl->starving++;
                                else
                                        set_bit(id, s->starving_fl);

Ehhh problem is that this is a simple rename so if any race is present, it's already there and not caused by this rename :(

Quoted 6 lines

Don't know maybe this is out of scope and should be investigated with a bug report?

Maybe this should be changed to prep/__schedule to prevent any kind of race? But doing so doesn't prevent any kind of ""starving""?

I gave a "Reviewed-by: Eric Dumazet <[email protected]>", meaning your patch was ok for me.

My remark was orthogonal, I am not asking you to act on it ;)

#8 lore raw

PATCH v2 4/4 netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule

In reply to Christian Marangi

Replace if condition of napi_schedule_prep/__napi_schedule and use bool from napi_schedule directly where possible.

---
 drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
 drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)
drivers/net/ethernet/atheros/atlx/atl1.c +1 -3
index 02aa6fd8ebc2..a9014d7932db 100644
@@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
 
 static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
 {
-	if (!napi_schedule_prep(&adapter->napi))
+	if (!napi_schedule(&adapter->napi))
 		/* It is possible in case even the RX/TX ints are disabled via IMR
 		 * register the ISR bits are set anyway (but do not produce IRQ).
 		 * To handle such situation the napi functions used to check is
@@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
 		 */
 		return 0;
 
-	__napi_schedule(&adapter->napi);
-
 	/*
 	 * Disable RX/TX ints via IMR register if it is
 	 * allowed. NAPI handler must reenable them in same
drivers/net/ethernet/toshiba/tc35815.c +1 -3
index 14cf6ecf6d0d..a8b8a0e13f9a 100644
@@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
 	if (!(dmactl & DMA_IntMask)) {
 		/* disable interrupts */
 		tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
-		if (napi_schedule_prep(&lp->napi))
-			__napi_schedule(&lp->napi);
-		else {
+		if (!napi_schedule(&lp->napi)) {
 			printk(KERN_ERR "%s: interrupt taken in poll\n",
 			       dev->name);
 			BUG();
drivers/net/wireless/intel/iwlwifi/pcie/rx.c +1 -3
index 23b5a0adcbd6..146bc7bd14fb 100644
@@ -1660,9 +1660,7 @@ irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id)
 	IWL_DEBUG_ISR(trans, "[%d] Got interrupt\n", entry->entry);
 
 	local_bh_disable();
-	if (napi_schedule_prep(&rxq->napi))
-		__napi_schedule(&rxq->napi);
-	else
+	if (!napi_schedule(&rxq->napi))
 		iwl_pcie_clear_irq(trans, entry->entry);
 	local_bh_enable();
 
Signature · 1 line
2.40.1
#9 lore raw

Re: [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule

Quoted 38 lines · Christian Marangi

Replace if condition of napi_schedule_prep/__napi_schedule and use bool from napi_schedule directly where possible.

---
 drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
 drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)
drivers/net/ethernet/atheros/atlx/atl1.c +1 -3
index 02aa6fd8ebc2..a9014d7932db 100644
@@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
 
 static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
 {
-       if (!napi_schedule_prep(&adapter->napi))
+       if (!napi_schedule(&adapter->napi))
                /* It is possible in case even the RX/TX ints are disabled via IMR
                 * register the ISR bits are set anyway (but do not produce IRQ).
                 * To handle such situation the napi functions used to check is
@@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
                 */
                return 0;
 
-       __napi_schedule(&adapter->napi);
-
        /*
         * Disable RX/TX ints via IMR register if it is
         * allowed. NAPI handler must reenable them in same
drivers/net/ethernet/toshiba/tc35815.c +0 -0
index 14cf6ecf6d0d..a8b8a0e13f9a 100644

drivers/net/ethernet/toshiba/tc35815.c static irqreturn_t tc35815_interrupt(int irq, void *dev_id) · line 1442

Quoted 10 lines
drivers/net/ethernet/toshiba/tc35815.c +1 -3
@@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
        if (!(dmactl & DMA_IntMask)) {
                /* disable interrupts */
                tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
-               if (napi_schedule_prep(&lp->napi))
-                       __napi_schedule(&lp->napi);
-               else {
+               if (!napi_schedule(&lp->napi)) {
                        printk(KERN_ERR "%s: interrupt taken in poll\n",
                               dev->name);
                        BUG();

Hmmm... could you also remove this BUG() ? I think this code path can be taken if some applications are using busy polling.

Or simply rewrite this with the traditional

if (napi_schedule_prep(&lp->napi)) {
/* disable interrupts */

   tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
    __napi_schedule(&lp->napi);
}

drivers/net/wireless/intel/iwlwifi/pcie/rx.c irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id) · line 1664

Quoted 13 lines
drivers/net/wireless/intel/iwlwifi/pcie/rx.c +1 -3
index 23b5a0adcbd6..146bc7bd14fb 100644
@@ -1660,9 +1660,7 @@ irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id)
        IWL_DEBUG_ISR(trans, "[%d] Got interrupt\n", entry->entry);
 
        local_bh_disable();
-       if (napi_schedule_prep(&rxq->napi))
-               __napi_schedule(&rxq->napi);
-       else
+       if (!napi_schedule(&rxq->napi))
                iwl_pcie_clear_irq(trans, entry->entry);

Same remark here about twisted logic.

Quoted 5 lines
drivers/net/wireless/intel/iwlwifi/pcie/rx.c +0 -1
        local_bh_enable();
 
--

2.40.1

#10 lore raw

Re: [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule

Quoted 53 lines · Eric Dumazet
Quoted 38 lines · Christian Marangi

Replace if condition of napi_schedule_prep/__napi_schedule and use bool from napi_schedule directly where possible.

---
 drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
 drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)
drivers/net/ethernet/atheros/atlx/atl1.c +1 -3
index 02aa6fd8ebc2..a9014d7932db 100644
@@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
 
 static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
 {
-       if (!napi_schedule_prep(&adapter->napi))
+       if (!napi_schedule(&adapter->napi))
                /* It is possible in case even the RX/TX ints are disabled via IMR
                 * register the ISR bits are set anyway (but do not produce IRQ).
                 * To handle such situation the napi functions used to check is
@@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
                 */
                return 0;
 
-       __napi_schedule(&adapter->napi);
-
        /*
         * Disable RX/TX ints via IMR register if it is
         * allowed. NAPI handler must reenable them in same
drivers/net/ethernet/toshiba/tc35815.c +0 -0
index 14cf6ecf6d0d..a8b8a0e13f9a 100644

drivers/net/ethernet/toshiba/tc35815.c static irqreturn_t tc35815_interrupt(int irq, void *dev_id) · line 1442

Quoted 10 lines
drivers/net/ethernet/toshiba/tc35815.c +1 -3
@@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
        if (!(dmactl & DMA_IntMask)) {
                /* disable interrupts */
                tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
-               if (napi_schedule_prep(&lp->napi))
-                       __napi_schedule(&lp->napi);
-               else {
+               if (!napi_schedule(&lp->napi)) {
                        printk(KERN_ERR "%s: interrupt taken in poll\n",
                               dev->name);
                        BUG();

Hmmm... could you also remove this BUG() ? I think this code path can be taken if some applications are using busy polling.

Quoted 9 lines

Or simply rewrite this with the traditional

if (napi_schedule_prep(&lp->napi)) {
   /* disable interrupts */
   tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
    __napi_schedule(&lp->napi);
}

Mhhh is it safe to do so? I mean it seems very wrong to print a warning and BUG() instead of disabling the interrupt only if napi can be scheduled... Maybe is very old code? The more I see this the more I see problem... (randomly disabling the interrupt and then make the kernel die)

Quoted 8 lines
Quoted 8 lines
drivers/net/wireless/intel/iwlwifi/pcie/rx.c +0 -0
index 23b5a0adcbd6..146bc7bd14fb 100644
@@ -1660,9 +1660,7 @@ irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id)
        IWL_DEBUG_ISR(trans, "[%d] Got interrupt\n", entry->entry);
 
Quoted 9 lines

drivers/net/wireless/intel/iwlwifi/pcie/rx.c irqreturn_t iwl_pcie_irq_rx_msix_handler(int irq, void *dev_id) · line 1664

Quoted 6 lines
drivers/net/wireless/intel/iwlwifi/pcie/rx.c +1 -3
        local_bh_disable();
-       if (napi_schedule_prep(&rxq->napi))
-               __napi_schedule(&rxq->napi);
-       else
+       if (!napi_schedule(&rxq->napi))
                iwl_pcie_clear_irq(trans, entry->entry);

Same remark here about twisted logic.

Ehhh here we need to be careful... We can do the usual prep/__schedule with the DMA disable in between...

From the comments of iwl_pcie_clear_irq.

/*
* Before sending the interrupt the HW disables it to prevent
* a nested interrupt. This is done by writing 1 to the corresponding
* bit in the mask register. After handling the interrupt, it should be
* re-enabled by clearing this bit. This register is defined as
* write 1 clear (W1C) register, meaning that it's being clear
* by writing 1 to the bit.
*/

So the device disable the interrupt after being fired and the bit needs to set again for the interrupt to be reenabled. So the function correctly reenable the irq if a napi can't be scheduled... Think there isn't another way to handle this.

Quoted 5 lines
Quoted 5 lines
drivers/net/wireless/intel/iwlwifi/pcie/rx.c +0 -1
        local_bh_enable();
 
--

2.40.1

Signature · 1 line
	Ansuel
#11 lore raw

Re: [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule

Quoted 65 lines · Christian Marangi
Quoted 53 lines · Eric Dumazet
Quoted 38 lines · Christian Marangi

Replace if condition of napi_schedule_prep/__napi_schedule and use bool from napi_schedule directly where possible.

---
 drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
 drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)
drivers/net/ethernet/atheros/atlx/atl1.c +1 -3
index 02aa6fd8ebc2..a9014d7932db 100644
@@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
 
 static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
 {
-       if (!napi_schedule_prep(&adapter->napi))
+       if (!napi_schedule(&adapter->napi))
                /* It is possible in case even the RX/TX ints are disabled via IMR
                 * register the ISR bits are set anyway (but do not produce IRQ).
                 * To handle such situation the napi functions used to check is
@@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
                 */
                return 0;
 
-       __napi_schedule(&adapter->napi);
-
        /*
         * Disable RX/TX ints via IMR register if it is
         * allowed. NAPI handler must reenable them in same
drivers/net/ethernet/toshiba/tc35815.c +0 -0
index 14cf6ecf6d0d..a8b8a0e13f9a 100644

drivers/net/ethernet/toshiba/tc35815.c static irqreturn_t tc35815_interrupt(int irq, void *dev_id) · line 1442

Quoted 10 lines
drivers/net/ethernet/toshiba/tc35815.c +1 -3
@@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
        if (!(dmactl & DMA_IntMask)) {
                /* disable interrupts */
                tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
-               if (napi_schedule_prep(&lp->napi))
-                       __napi_schedule(&lp->napi);
-               else {
+               if (!napi_schedule(&lp->napi)) {
                        printk(KERN_ERR "%s: interrupt taken in poll\n",
                               dev->name);
                        BUG();

Hmmm... could you also remove this BUG() ? I think this code path can be taken if some applications are using busy polling.

Quoted 9 lines

Or simply rewrite this with the traditional

if (napi_schedule_prep(&lp->napi)) {
   /* disable interrupts */
   tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
    __napi_schedule(&lp->napi);
}
Quoted 5 lines

Mhhh is it safe to do so? I mean it seems very wrong to print a warning and BUG() instead of disabling the interrupt only if napi can be scheduled... Maybe is very old code? The more I see this the more I see problem... (randomly disabling the interrupt and then make the kernel die)

I am pretty sure this BUG() can be hit these days with busy polling or setting gro_flush_timeout.

I wish we could remove these bugs before someone copy-paste them.

Again, this is orthogonal, I might simply stop doing reviews if this is not useful.

#12 lore raw

Re: [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule

Quoted 72 lines · Eric Dumazet
Quoted 65 lines · Christian Marangi
Quoted 53 lines · Eric Dumazet
Quoted 38 lines · Christian Marangi

Replace if condition of napi_schedule_prep/__napi_schedule and use bool from napi_schedule directly where possible.

---
 drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
 drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)
drivers/net/ethernet/atheros/atlx/atl1.c +1 -3
index 02aa6fd8ebc2..a9014d7932db 100644
@@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
 
 static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
 {
-       if (!napi_schedule_prep(&adapter->napi))
+       if (!napi_schedule(&adapter->napi))
                /* It is possible in case even the RX/TX ints are disabled via IMR
                 * register the ISR bits are set anyway (but do not produce IRQ).
                 * To handle such situation the napi functions used to check is
@@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
                 */
                return 0;
 
-       __napi_schedule(&adapter->napi);
-
        /*
         * Disable RX/TX ints via IMR register if it is
         * allowed. NAPI handler must reenable them in same
drivers/net/ethernet/toshiba/tc35815.c +0 -0
index 14cf6ecf6d0d..a8b8a0e13f9a 100644

drivers/net/ethernet/toshiba/tc35815.c static irqreturn_t tc35815_interrupt(int irq, void *dev_id) · line 1442

Quoted 10 lines
drivers/net/ethernet/toshiba/tc35815.c +1 -3
@@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
        if (!(dmactl & DMA_IntMask)) {
                /* disable interrupts */
                tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
-               if (napi_schedule_prep(&lp->napi))
-                       __napi_schedule(&lp->napi);
-               else {
+               if (!napi_schedule(&lp->napi)) {
                        printk(KERN_ERR "%s: interrupt taken in poll\n",
                               dev->name);
                        BUG();

Hmmm... could you also remove this BUG() ? I think this code path can be taken if some applications are using busy polling.

Quoted 9 lines

Or simply rewrite this with the traditional

if (napi_schedule_prep(&lp->napi)) {
   /* disable interrupts */
   tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
    __napi_schedule(&lp->napi);
}
Quoted 5 lines

Mhhh is it safe to do so? I mean it seems very wrong to print a warning and BUG() instead of disabling the interrupt only if napi can be scheduled... Maybe is very old code? The more I see this the more I see problem... (randomly disabling the interrupt and then make the kernel die)

Quoted 7 lines

I am pretty sure this BUG() can be hit these days with busy polling or setting gro_flush_timeout.

I wish we could remove these bugs before someone copy-paste them.

Again, this is orthogonal, I might simply stop doing reviews if this is not useful.

They are very useful and thanks a lot for them! I'm asking these as to understand how to proceed. I have in queue 2 other series that depends on this and I'm just asking info on how to speedup the progress on this!

Soo think I have to send v3 with the suggested change and BUG() dropped? Happy to do everything to fix and improve this series!

Signature · 1 line
	Ansuel
#13 lore raw

Re: [net-next PATCH v2 4/4] netdev: use napi_schedule bool instead of napi_schedule_prep/__napi_schedule

Quoted 82 lines · Christian Marangi
Quoted 72 lines · Eric Dumazet
Quoted 65 lines · Christian Marangi
Quoted 53 lines · Eric Dumazet
Quoted 38 lines · Christian Marangi

Replace if condition of napi_schedule_prep/__napi_schedule and use bool from napi_schedule directly where possible.

---
 drivers/net/ethernet/atheros/atlx/atl1.c     | 4 +---
 drivers/net/ethernet/toshiba/tc35815.c       | 4 +---
 drivers/net/wireless/intel/iwlwifi/pcie/rx.c | 4 +---
 3 files changed, 3 insertions(+), 9 deletions(-)
drivers/net/ethernet/atheros/atlx/atl1.c +1 -3
index 02aa6fd8ebc2..a9014d7932db 100644
@@ -2446,7 +2446,7 @@ static int atl1_rings_clean(struct napi_struct *napi, int budget)
 
 static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
 {
-       if (!napi_schedule_prep(&adapter->napi))
+       if (!napi_schedule(&adapter->napi))
                /* It is possible in case even the RX/TX ints are disabled via IMR
                 * register the ISR bits are set anyway (but do not produce IRQ).
                 * To handle such situation the napi functions used to check is
@@ -2454,8 +2454,6 @@ static inline int atl1_sched_rings_clean(struct atl1_adapter* adapter)
                 */
                return 0;
 
-       __napi_schedule(&adapter->napi);
-
        /*
         * Disable RX/TX ints via IMR register if it is
         * allowed. NAPI handler must reenable them in same
drivers/net/ethernet/toshiba/tc35815.c +0 -0
index 14cf6ecf6d0d..a8b8a0e13f9a 100644

drivers/net/ethernet/toshiba/tc35815.c static irqreturn_t tc35815_interrupt(int irq, void *dev_id) · line 1442

Quoted 10 lines
drivers/net/ethernet/toshiba/tc35815.c +1 -3
@@ -1436,9 +1436,7 @@ static irqreturn_t tc35815_interrupt(int irq, void *dev_id)
        if (!(dmactl & DMA_IntMask)) {
                /* disable interrupts */
                tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
-               if (napi_schedule_prep(&lp->napi))
-                       __napi_schedule(&lp->napi);
-               else {
+               if (!napi_schedule(&lp->napi)) {
                        printk(KERN_ERR "%s: interrupt taken in poll\n",
                               dev->name);
                        BUG();

Hmmm... could you also remove this BUG() ? I think this code path can be taken if some applications are using busy polling.

Quoted 9 lines

Or simply rewrite this with the traditional

if (napi_schedule_prep(&lp->napi)) {
   /* disable interrupts */
   tc_writel(dmactl | DMA_IntMask, &tr->DMA_Ctl);
    __napi_schedule(&lp->napi);
}
Quoted 5 lines

Mhhh is it safe to do so? I mean it seems very wrong to print a warning and BUG() instead of disabling the interrupt only if napi can be scheduled... Maybe is very old code? The more I see this the more I see problem... (randomly disabling the interrupt and then make the kernel die)

Quoted 7 lines

I am pretty sure this BUG() can be hit these days with busy polling or setting gro_flush_timeout.

I wish we could remove these bugs before someone copy-paste them.

Again, this is orthogonal, I might simply stop doing reviews if this is not useful.

Quoted 6 lines

They are very useful and thanks a lot for them! I'm asking these as to understand how to proceed. I have in queue 2 other series that depends on this and I'm just asking info on how to speedup the progress on this!

Soo think I have to send v3 with the suggested change and BUG() dropped? Happy to do everything to fix and improve this series!

I think that your patch series is all about doing cleanups, so I suggested adding another cleanup/fix,
and this can be done independently.

I doubt this matters, this code has probably not been used for quite a long time...