Skip to contentSkip to conversation

net: xilinx: axienet: Fix IRQ coalescing packet count overflow

PATCH Superseded Sean Anderson 3 participants 7 messages Sep 3, 2024 – Sep 9, 2024

Subsystems (4)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: xilinx: axienet: Fix IRQ coalescing packet count overflow

If coalesce_count is greater than 255 it will not fit in the register and will overflow. Clamp it to 255 for more-predictable results.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

---

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +4 -2
index 9aeb7b9f3ae4..5f27fc1c4375 100644
@@ -252,7 +252,8 @@ static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec)
 static void axienet_dma_start(struct axienet_local *lp)
 {
 	/* Start updating the Rx channel control register */
-	lp->rx_dma_cr = (lp->coalesce_count_rx << XAXIDMA_COALESCE_SHIFT) |
+	lp->rx_dma_cr = (min(lp->coalesce_count_rx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_ERROR_MASK;
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +265,8 @@ static void axienet_dma_start(struct axienet_local *lp)
 	axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr);
 
 	/* Start updating the Tx channel control register */
-	lp->tx_dma_cr = (lp->coalesce_count_tx << XAXIDMA_COALESCE_SHIFT) |
+	lp->tx_dma_cr = (min(lp->coalesce_count_tx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_ERROR_MASK;
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first TX packet. Otherwise leave at 0 to disable delay interrupt.
Signature · 1 line
2.35.1.1320.gc452695387.dirty
reviewer
#1 lore raw
Quoted 2 lines · Sean Anderson

If coalesce_count is greater than 255 it will not fit in the register and will overflow. Clamp it to 255 for more-predictable results.

Hi Sean,

Can this occur in practice?

Quoted 3 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

nit: I think it is usual for the order of these tags to be reversed.

Quoted 10 lines

---

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -0
index 9aeb7b9f3ae4..5f27fc1c4375 100644

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec) · line 257

Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -1
@@ -252,7 +252,8 @@ static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec)
 static void axienet_dma_start(struct axienet_local *lp)
 {
 	/* Start updating the Rx channel control register */
-	lp->rx_dma_cr = (lp->coalesce_count_rx << XAXIDMA_COALESCE_SHIFT) |
+	lp->rx_dma_cr = (min(lp->coalesce_count_rx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_ERROR_MASK;

nit: it would be nice to avoid using a naked 255 here.

     Perhaps: #define XAXIDMA_COALESCE_MAX 0xff
Quoted 16 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -1
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +265,8 @@ static void axienet_dma_start(struct axienet_local *lp)
 	axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr);
 
 	/* Start updating the Tx channel control register */
-	lp->tx_dma_cr = (lp->coalesce_count_tx << XAXIDMA_COALESCE_SHIFT) |
+	lp->tx_dma_cr = (min(lp->coalesce_count_tx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_ERROR_MASK;
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first TX packet. Otherwise leave at 0 to disable delay interrupt.
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#4 lore raw
In reply to Sean Anderson
Quoted 38 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 3, 2024 11:31 PM
To: Pandey, Radhey Shyam <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]
Cc: Simek, Michal <[email protected]>; linux-arm- [email protected]; Ariane Keller <[email protected]>; [email protected]; Daniel Borkmann <[email protected]>; Andy Chiu <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

If coalesce_count is greater than 255 it will not fit in the register and will overflow. Clamp it to 255 for more-predictable results.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet

driver")
---

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
index 9aeb7b9f3ae4..5f27fc1c4375 100644
@@ -252,7 +252,8 @@ static u32 axienet_usec_to_timer(struct axienet_local
 *lp, u32 coalesce_usec)
 static void axienet_dma_start(struct axienet_local *lp)
 {
 	/* Start updating the Rx channel control register */
-	lp->rx_dma_cr = (lp->coalesce_count_rx <<

XAXIDMA_COALESCE_SHIFT) |

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec)

Quoted 3 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -0
+	lp->rx_dma_cr = (min(lp->coalesce_count_rx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK |

Instead of every time clamping coalesce_count_rx on read I think better to do it place where it set in axienet_ethtools_set_coalesce()? It would also represent the coalesce count state that is reported by get_coalesce() and same is being used in programming.

Quoted 18 lines

XAXIDMA_IRQ_ERROR_MASK;

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +265,8 @@ static void axienet_dma_start(struct axienet_local
 *lp)
 	axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr);
 
 	/* Start updating the Tx channel control register */
-	lp->tx_dma_cr = (lp->coalesce_count_tx <<

XAXIDMA_COALESCE_SHIFT) |

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -0
+	lp->tx_dma_cr = (min(lp->coalesce_count_tx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK |

XAXIDMA_IRQ_ERROR_MASK;

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first TX packet. Otherwise leave at 0 to disable delay interrupt.
--

2.35.1.1320.gc452695387.dirty

#2 lore raw
In reply to Simon Horman
Quoted 7 lines · Simon Horman
Quoted 2 lines · Sean Anderson

If coalesce_count is greater than 255 it will not fit in the register and will overflow. Clamp it to 255 for more-predictable results.

Hi Sean,

Can this occur in practice?

Yes. Simply do ethtool -C ethX rx-frames 300 or something similar and you will end up with a limit of 44 instead. I ran into this with DIM and was wondering why the highest-throughput setting (256) was behaving so poorly...

Quoted 5 lines
Quoted 3 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

nit: I think it is usual for the order of these tags to be reversed.

OK

Quoted 19 lines
Quoted 10 lines

---

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -0
index 9aeb7b9f3ae4..5f27fc1c4375 100644

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec) · line 257

Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -1
@@ -252,7 +252,8 @@ static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec)
 static void axienet_dma_start(struct axienet_local *lp)
 {
 	/* Start updating the Rx channel control register */
-	lp->rx_dma_cr = (lp->coalesce_count_rx << XAXIDMA_COALESCE_SHIFT) |
+	lp->rx_dma_cr = (min(lp->coalesce_count_rx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_ERROR_MASK;

nit: it would be nice to avoid using a naked 255 here.

Quoted 1 line
     Perhaps: #define XAXIDMA_COALESCE_MAX 0xff

OK, but this is the same as the limit used in axienet_usec_to_timer.

--Sean

Quoted 16 lines
Quoted 16 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -1
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +265,8 @@ static void axienet_dma_start(struct axienet_local *lp)
 	axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr);
 
 	/* Start updating the Tx channel control register */
-	lp->tx_dma_cr = (lp->coalesce_count_tx << XAXIDMA_COALESCE_SHIFT) |
+	lp->tx_dma_cr = (min(lp->coalesce_count_tx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_ERROR_MASK;
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first TX packet. Otherwise leave at 0 to disable delay interrupt.
Signature · 1 line
2.35.1.1320.gc452695387.dirty
#5 lore raw
In reply to Pandey, Radhey Shyam
Quoted 38 lines · Radhey Shyam
Quoted 38 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 3, 2024 11:31 PM
To: Pandey, Radhey Shyam <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]
Cc: Simek, Michal <[email protected]>; linux-arm- [email protected]; Ariane Keller <[email protected]>; [email protected]; Daniel Borkmann <[email protected]>; Andy Chiu <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

If coalesce_count is greater than 255 it will not fit in the register and will overflow. Clamp it to 255 for more-predictable results.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet

driver")
---

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
index 9aeb7b9f3ae4..5f27fc1c4375 100644
@@ -252,7 +252,8 @@ static u32 axienet_usec_to_timer(struct axienet_local
 *lp, u32 coalesce_usec)
 static void axienet_dma_start(struct axienet_local *lp)
 {
 	/* Start updating the Rx channel control register */
-	lp->rx_dma_cr = (lp->coalesce_count_rx <<

XAXIDMA_COALESCE_SHIFT) |

Quoted 8 lines

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec)

Quoted 3 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -0
+	lp->rx_dma_cr = (min(lp->coalesce_count_rx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK |

Instead of every time clamping coalesce_count_rx on read I think better to do it place where it set in axienet_ethtools_set_coalesce()? It would also represent the coalesce count state that is reported by get_coalesce() and same is being used in programming.

The parameter which will be trickier is the timer, which is also clamped but depends on the (DMA) clock speed. So theoretically it may be different if the clock gets changed at runtime between when we set coalesce and when we apply it. But do we even support dynamic rate changes for that clock?

In either case, I think this will be easier to do as part of [1], since I am already rearranging the calculation in that patch.

--Sean

[1] https://lore.kernel.org/netdev/[email protected]/

Quoted 19 lines
Quoted 18 lines

XAXIDMA_IRQ_ERROR_MASK;

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +265,8 @@ static void axienet_dma_start(struct axienet_local
 *lp)
 	axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr);
 
 	/* Start updating the Tx channel control register */
-	lp->tx_dma_cr = (lp->coalesce_count_tx <<

XAXIDMA_COALESCE_SHIFT) |

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -0
+	lp->tx_dma_cr = (min(lp->coalesce_count_tx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK |

XAXIDMA_IRQ_ERROR_MASK;

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first TX packet. Otherwise leave at 0 to disable delay interrupt.
--

2.35.1.1320.gc452695387.dirty

reviewer
#3 lore raw
In reply to Sean Anderson
Quoted 5 lines · Sean Anderson
Quoted 4 lines · Simon Horman
Quoted 2 lines · Sean Anderson

If coalesce_count is greater than 255 it will not fit in the register and will overflow. Clamp it to 255 for more-predictable results.

Quoted 8 lines
Quoted 3 lines

Hi Sean,

Can this occur in practice?

Yes. Simply do ethtool -C ethX rx-frames 300 or something similar and you will end up with a limit of 44 instead. I ran into this with DIM and was wondering why the highest-throughput setting (256) was behaving so poorly...

I think it would be nice to include an explanation along those lines in the patch description.

Quoted 30 lines
Quoted 6 lines
Quoted 4 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet driver")

nit: I think it is usual for the order of these tags to be reversed.

OK

Quoted 19 lines
Quoted 10 lines

---

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -0
index 9aeb7b9f3ae4..5f27fc1c4375 100644

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec) · line 257

Quoted 7 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -1
@@ -252,7 +252,8 @@ static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec)
 static void axienet_dma_start(struct axienet_local *lp)
 {
 	/* Start updating the Rx channel control register */
-	lp->rx_dma_cr = (lp->coalesce_count_rx << XAXIDMA_COALESCE_SHIFT) |
+	lp->rx_dma_cr = (min(lp->coalesce_count_rx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK | XAXIDMA_IRQ_ERROR_MASK;

nit: it would be nice to avoid using a naked 255 here.

Quoted 1 line
     Perhaps: #define XAXIDMA_COALESCE_MAX 0xff
Quoted 1 line

OK, but this is the same as the limit used in axienet_usec_to_timer.

Ok, that does muddy the waters a bit.

#6 lore raw
In reply to Sean Anderson
Quoted 48 lines · Sean Anderson
Quoted 38 lines · Radhey Shyam
Quoted 38 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 3, 2024 11:31 PM
To: Pandey, Radhey Shyam <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]
Cc: Simek, Michal <[email protected]>; linux-arm- [email protected]; Ariane Keller <[email protected]>; [email protected]; Daniel Borkmann <[email protected]>; Andy Chiu <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

If coalesce_count is greater than 255 it will not fit in the register and will overflow. Clamp it to 255 for more-predictable results.

Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet

driver")
---

 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
index 9aeb7b9f3ae4..5f27fc1c4375 100644
@@ -252,7 +252,8 @@ static u32 axienet_usec_to_timer(struct axienet_local
 *lp, u32 coalesce_usec)
 static void axienet_dma_start(struct axienet_local *lp)
 {
 	/* Start updating the Rx channel control register */
-	lp->rx_dma_cr = (lp->coalesce_count_rx <<

XAXIDMA_COALESCE_SHIFT) |

Quoted 8 lines

drivers/net/ethernet/xilinx/xilinx_axienet_main.c static u32 axienet_usec_to_timer(struct axienet_local *lp, u32 coalesce_usec)

Quoted 3 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -0
+	lp->rx_dma_cr = (min(lp->coalesce_count_rx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK |

Instead of every time clamping coalesce_count_rx on read I think better to do it place where it set in axienet_ethtools_set_coalesce()? It would also represent the coalesce count state that is reported by get_coalesce() and same is being used in programming.

Quoted 8 lines

The parameter which will be trickier is the timer, which is also clamped but depends on the (DMA) clock speed. So theoretically it may be different if the clock gets changed at runtime between when we set coalesce and when we apply it. But do we even support dynamic rate changes for that clock?

In either case, I think this will be easier to do as part of [1], since I am already rearranging the calculation in that patch.

Implemented as https://lore.kernel.org/netdev/[email protected]/

--Sean

Quoted 23 lines

--Sean

[1] https://lore.kernel.org/netdev/[email protected]/

Quoted 19 lines
Quoted 18 lines

XAXIDMA_IRQ_ERROR_MASK;

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +265,8 @@ static void axienet_dma_start(struct axienet_local
 *lp)
 	axienet_dma_out32(lp, XAXIDMA_RX_CR_OFFSET, lp->rx_dma_cr);
 
 	/* Start updating the Tx channel control register */
-	lp->tx_dma_cr = (lp->coalesce_count_tx <<

XAXIDMA_COALESCE_SHIFT) |

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +2 -0
+	lp->tx_dma_cr = (min(lp->coalesce_count_tx, 255) <<
+			 XAXIDMA_COALESCE_SHIFT) |
 			XAXIDMA_IRQ_IOC_MASK |

XAXIDMA_IRQ_ERROR_MASK;

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
 	/* Only set interrupt delay timer if not generating an interrupt on
 	 * the first TX packet. Otherwise leave at 0 to disable delay interrupt.
--

2.35.1.1320.gc452695387.dirty