Skip to contentSkip to conversation

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

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

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

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

If coalece_count is greater than 255 it will not fit in the register and will overflow. This can be reproduced by running

    # ethtool -C ethX rx-frames 256

which will result in a timeout of 0us instead. Fix this by clamping the counts to the maximum value.

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

---

Changes in v2:
- Use FIELD_MAX to extract the max value from the mask
- Expand the commit message with an example on how to reproduce this issue

 drivers/net/ethernet/xilinx/xilinx_axienet.h      | 5 ++---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -3
index 1223fcc1a8da..54db69893565 100644
@@ -109,11 +109,10 @@
 #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet */
 #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits */
 
-#define XAXIDMA_DELAY_MASK		0xFF000000 /* Delay timeout counter */
-#define XAXIDMA_COALESCE_MASK		0x00FF0000 /* Coalesce counter */
+#define XAXIDMA_DELAY_MASK		((u32)0xFF000000) /* Delay timeout counter */
+#define XAXIDMA_COALESCE_MASK		((u32)0x00FF0000) /* Coalesce counter */
 
 #define XAXIDMA_DELAY_SHIFT		24
-#define XAXIDMA_COALESCE_SHIFT		16
 
 #define XAXIDMA_IRQ_IOC_MASK		0x00001000 /* Completion intr */
 #define XAXIDMA_IRQ_DELAY_MASK		0x00002000 /* Delay interrupt */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6 -2
index 9eb300fc3590..89b63695293d 100644
@@ -252,7 +252,9 @@ 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 = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_rx,
+				       FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
 			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 +266,9 @@ 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 = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_tx,
+				       FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
 			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
Reviewed-by on v2 1/1
#1 lore raw
Quoted 2 lines · Sean Anderson

If coalece_count is greater than 255 it will not fit in the register and

s/coalece_count/coalesce_count/

Otherwise

Quoted 68 lines

will overflow. This can be reproduced by running

     # ethtool -C ethX rx-frames 256

which will result in a timeout of 0us instead. Fix this by clamping the counts to the maximum value.

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

---

Changes in v2:
- Use FIELD_MAX to extract the max value from the mask
- Expand the commit message with an example on how to reproduce this issue

  drivers/net/ethernet/xilinx/xilinx_axienet.h      | 5 ++---
  drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++--
  2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +2 -3
index 1223fcc1a8da..54db69893565 100644
@@ -109,11 +109,10 @@
  #define XAXIDMA_BD_CTRL_TXEOF_MASK     0x04000000 /* Last tx packet */
  #define XAXIDMA_BD_CTRL_ALL_MASK       0x0C000000 /* All control bits */
 
-#define XAXIDMA_DELAY_MASK             0xFF000000 /* Delay timeout counter */
-#define XAXIDMA_COALESCE_MASK          0x00FF0000 /* Coalesce counter */
+#define XAXIDMA_DELAY_MASK             ((u32)0xFF000000) /* Delay timeout counter */
+#define XAXIDMA_COALESCE_MASK          ((u32)0x00FF0000) /* Coalesce counter */
 
  #define XAXIDMA_DELAY_SHIFT            24
-#define XAXIDMA_COALESCE_SHIFT         16
 
  #define XAXIDMA_IRQ_IOC_MASK           0x00001000 /* Completion intr */
  #define XAXIDMA_IRQ_DELAY_MASK         0x00002000 /* Delay interrupt */
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +6 -3
index 9eb300fc3590..89b63695293d 100644
@@ -252,7 +252,9 @@ 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 = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+                                  min(lp->coalesce_count_rx,
+                                      FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
                         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 +266,9 @@ 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 = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+                                  min(lp->coalesce_count_tx,
+                                      FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
                         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.
--

2.35.1.1320.gc452695387.dirty

#2 lore raw
In reply to Sean Anderson
Quoted 15 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 10, 2024 4:39 AM
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: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; linux-arm- [email protected]; Simek, Michal <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 7 lines

If coalece_count is greater than 255 it will not fit in the register and will overflow. This can be reproduced by running

    # ethtool -C ethX rx-frames 256

which will result in a timeout of 0us instead. Fix this by clamping the counts to the maximum value.

After this fix - what is o/p we get on rx-frames read? I think silent clamping is not a great idea and user won't know about it. One alternative is to add check in set_coalesc count for valid range? (Similar to axienet_ethtools_set_ringparam so that user is notified for incorrect range)

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

driver")
---

Changes in v2:
- Use FIELD_MAX to extract the max value from the mask
- Expand the commit message with an example on how to reproduce this issue

 drivers/net/ethernet/xilinx/xilinx_axienet.h      | 5 ++---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -1
index 1223fcc1a8da..54db69893565 100644
@@ -109,11 +109,10 @@
 #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet
 */
 #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits
 */
 
-#define XAXIDMA_DELAY_MASK		0xFF000000 /* Delay timeout
Quoted 5 lines

counter */
-#define XAXIDMA_COALESCE_MASK 0x00FF0000 /* Coalesce
counter */
+#define XAXIDMA_DELAY_MASK ((u32)0xFF000000) /* Delay
timeout counter */

Adding typecast here looks odd. Any reason for it? If needed we do it in specific case where it is required.

Quoted 47 lines

+#define XAXIDMA_COALESCE_MASK ((u32)0x00FF0000) /*
Coalesce counter */

#define XAXIDMA_DELAY_SHIFT 24
-#define XAXIDMA_COALESCE_SHIFT 16

#define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion
intr */
#define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay
interrupt */

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
index 9eb300fc3590..89b63695293d 100644
@@ -252,7 +252,9 @@ 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 +3 -0
+	lp->rx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_rx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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 RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +266,9 @@ 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 +3 -0
+	lp->tx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_tx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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

#3 lore raw
Quoted 18 lines · Radhey Shyam
Quoted 18 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 10, 2024 4:39 AM
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: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; linux-arm- [email protected]; Simek, Michal <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

If coalece_count is greater than 255 it will not fit in the register and will overflow. This can be reproduced by running

Quoted 8 lines
Quoted 4 lines
    # ethtool -C ethX rx-frames 256

which will result in a timeout of 0us instead. Fix this by clamping the counts to the maximum value.

After this fix - what is o/p we get on rx-frames read? I think silent clamping is not a great idea and user won't know about it. One alternative is to add check in set_coalesc count for valid range? (Similar to axienet_ethtools_set_ringparam so that user is notified for incorrect range)

The value reported will be unclamped. In [1] I improve the driver to return the actual (clamped) value.

Remember that without this commit, we have silent wraparound instead. I think clamping is much friendlier, since you at least get something close to the rx-frames value, instead of zero!

This commit is just a fix for the overflow issue. To ensure it is appropriate for backporting I have omitted any other changes/improvements.

--Sean

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

Quoted 84 lines
Quoted 27 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet

driver")
---

Changes in v2:
- Use FIELD_MAX to extract the max value from the mask
- Expand the commit message with an example on how to reproduce this issue

 drivers/net/ethernet/xilinx/xilinx_axienet.h      | 5 ++---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -1
index 1223fcc1a8da..54db69893565 100644
@@ -109,11 +109,10 @@
 #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet
 */
 #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits
 */
 
-#define XAXIDMA_DELAY_MASK		0xFF000000 /* Delay timeout
Quoted 5 lines

counter */
-#define XAXIDMA_COALESCE_MASK 0x00FF0000 /* Coalesce
counter */
+#define XAXIDMA_DELAY_MASK ((u32)0xFF000000) /* Delay
timeout counter */

Adding typecast here looks odd. Any reason for it? If needed we do it in specific case where it is required.

Quoted 47 lines

+#define XAXIDMA_COALESCE_MASK ((u32)0x00FF0000) /*
Coalesce counter */

#define XAXIDMA_DELAY_SHIFT 24
-#define XAXIDMA_COALESCE_SHIFT 16

#define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion
intr */
#define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay
interrupt */

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
index 9eb300fc3590..89b63695293d 100644
@@ -252,7 +252,9 @@ 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 +3 -0
+	lp->rx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_rx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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 RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +266,9 @@ 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 +3 -0
+	lp->tx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_tx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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

#4 lore raw
Quoted 48 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Thursday, September 12, 2024 8:01 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]; Gupta, Suraj <[email protected]>; Katakam, Harini <[email protected]>
Cc: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Subject: Re: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 15 lines · Radhey Shyam
Quoted 15 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 10, 2024 4:39 AM
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: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; linux-arm- [email protected]; Simek, Michal <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 8 lines
Quoted 7 lines

If coalece_count is greater than 255 it will not fit in the register and will overflow. This can be reproduced by running

    # ethtool -C ethX rx-frames 256

which will result in a timeout of 0us instead. Fix this by clamping the counts to the maximum value.

After this fix - what is o/p we get on rx-frames read? I think silent clamping is not a

great

Quoted 2 lines

idea and user won't know about it. One alternative is to add check in set_coalesc count for valid range? (Similar to axienet_ethtools_set_ringparam so that user is

notified

Quoted 1 line

for incorrect range)

The value reported will be unclamped. In [1] I improve the driver to return the actual (clamped) value.

Quoted 7 lines

Remember that without this commit, we have silent wraparound instead. I think clamping is much friendlier, since you at least get something close to the rx-frames value, instead of zero!

This commit is just a fix for the overflow issue. To ensure it is appropriate for backporting I have omitted any other changes/improvements.

But the point is the fix also can be to avoid setting coalesce count to invalid (or not supported range) value - like done in existing axienet_ethtools_set_ringparam() implementation.

And we don't clamp on every dma_start().

Quoted 90 lines

--Sean

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

Quoted 84 lines
Quoted 27 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet

driver")
---

Changes in v2:
- Use FIELD_MAX to extract the max value from the mask
- Expand the commit message with an example on how to reproduce this issue

 drivers/net/ethernet/xilinx/xilinx_axienet.h      | 5 ++---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -1
index 1223fcc1a8da..54db69893565 100644
@@ -109,11 +109,10 @@
 #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet
 */
 #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits
 */
 
-#define XAXIDMA_DELAY_MASK		0xFF000000 /* Delay timeout
Quoted 5 lines

counter */
-#define XAXIDMA_COALESCE_MASK 0x00FF0000 /* Coalesce
counter */
+#define XAXIDMA_DELAY_MASK ((u32)0xFF000000) /* Delay
timeout counter */

Adding typecast here looks odd. Any reason for it? If needed we do it in specific case where it is required.

Quoted 47 lines

+#define XAXIDMA_COALESCE_MASK ((u32)0x00FF0000) /*
Coalesce counter */

#define XAXIDMA_DELAY_SHIFT 24
-#define XAXIDMA_COALESCE_SHIFT 16

#define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion
intr */
#define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay
interrupt */

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
index 9eb300fc3590..89b63695293d 100644
@@ -252,7 +252,9 @@ 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 +3 -0
+	lp->rx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_rx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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 RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +266,9 @@ 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 +3 -0
+	lp->tx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_tx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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

#5 lore raw
Quoted 72 lines

-----Original Message-----
From: Pandey, Radhey Shyam
Sent: Thursday, September 12, 2024 8:05 PM
To: Sean Anderson <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; Gupta, Suraj <[email protected]>; Katakam, Harini <[email protected]>
Cc: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Subject: RE: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 5 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Thursday, September 12, 2024 8:01 PM
To: Pandey, Radhey Shyam <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub

Kicinski

Quoted 1 line

<[email protected]>; Paolo Abeni <[email protected]>;

[email protected];

Quoted 4 lines

Gupta, Suraj <[email protected]>; Katakam, Harini <[email protected]>
Cc: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>;

Daniel

Quoted 5 lines

Borkmann <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Subject: Re: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 24 lines
Quoted 23 lines · Radhey Shyam
Quoted 15 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 10, 2024 4:39 AM
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: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; linux-arm- [email protected]; Simek, Michal <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 7 lines

If coalece_count is greater than 255 it will not fit in the register and will overflow. This can be reproduced by running

    # ethtool -C ethX rx-frames 256

which will result in a timeout of 0us instead. Fix this by clamping the counts to the maximum value.

After this fix - what is o/p we get on rx-frames read? I think silent clamping is not

a

Quoted 2 lines

great

Quoted 1 line

idea and user won't know about it. One alternative is to add check in

set_coalesc

Quoted 11 lines
Quoted 1 line

count for valid range? (Similar to axienet_ethtools_set_ringparam so that user is

notified

Quoted 1 line

for incorrect range)

The value reported will be unclamped. In [1] I improve the driver to return the actual (clamped) value.

Remember that without this commit, we have silent wraparound instead. I think clamping is much friendlier, since you at least get something close to the rx-frames value, instead of zero!

Quoted 7 lines
Quoted 3 lines

This commit is just a fix for the overflow issue. To ensure it is appropriate for backporting I have omitted any other changes/improvements.

But the point is the fix also can be to avoid setting coalesce count to invalid (or not supported range) value - like done in existing axienet_ethtools_set_ringparam() implementation.

Sean: I think above comment got missed out, so I am bringing it again to discuss and close on it.

Quoted 93 lines

And we don't clamp on every dma_start().

Quoted 90 lines

--Sean

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

Quoted 84 lines
Quoted 27 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet

driver")
---

Changes in v2:
- Use FIELD_MAX to extract the max value from the mask
- Expand the commit message with an example on how to reproduce this issue

 drivers/net/ethernet/xilinx/xilinx_axienet.h      | 5 ++---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -1
index 1223fcc1a8da..54db69893565 100644
@@ -109,11 +109,10 @@
 #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet
 */
 #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits
 */
 
-#define XAXIDMA_DELAY_MASK		0xFF000000 /* Delay timeout
Quoted 5 lines

counter */
-#define XAXIDMA_COALESCE_MASK 0x00FF0000 /* Coalesce
counter */
+#define XAXIDMA_DELAY_MASK ((u32)0xFF000000) /* Delay
timeout counter */

Adding typecast here looks odd. Any reason for it? If needed we do it in specific case where it is required.

Quoted 47 lines

+#define XAXIDMA_COALESCE_MASK ((u32)0x00FF0000) /*
Coalesce counter */

#define XAXIDMA_DELAY_SHIFT 24
-#define XAXIDMA_COALESCE_SHIFT 16

#define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion
intr */
#define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay
interrupt */

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
index 9eb300fc3590..89b63695293d 100644
@@ -252,7 +252,9 @@ 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 +3 -0
+	lp->rx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_rx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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 RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +266,9 @@ 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 +3 -0
+	lp->tx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_tx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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

#6 lore raw
Quoted 76 lines · Radhey Shyam
Quoted 76 lines

-----Original Message-----
From: Pandey, Radhey Shyam
Sent: Thursday, September 12, 2024 8:05 PM
To: Sean Anderson <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; [email protected]; Gupta, Suraj <[email protected]>; Katakam, Harini <[email protected]>
Cc: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Subject: RE: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 5 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Thursday, September 12, 2024 8:01 PM
To: Pandey, Radhey Shyam <[email protected]>; David S . Miller <[email protected]>; Eric Dumazet <[email protected]>; Jakub

Kicinski

Quoted 1 line

<[email protected]>; Paolo Abeni <[email protected]>;

[email protected];

Quoted 4 lines

Gupta, Suraj <[email protected]>; Katakam, Harini <[email protected]>
Cc: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>;

Daniel

Quoted 5 lines

Borkmann <[email protected]>; [email protected]; Simek, Michal <[email protected]>
Subject: Re: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 24 lines
Quoted 23 lines · Radhey Shyam
Quoted 15 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 10, 2024 4:39 AM
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: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; linux-arm- [email protected]; Simek, Michal <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 7 lines

If coalece_count is greater than 255 it will not fit in the register and will overflow. This can be reproduced by running

    # ethtool -C ethX rx-frames 256

which will result in a timeout of 0us instead. Fix this by clamping the counts to the maximum value.

After this fix - what is o/p we get on rx-frames read? I think silent clamping is not

a

Quoted 2 lines

great

Quoted 1 line

idea and user won't know about it. One alternative is to add check in

set_coalesc

Quoted 14 lines
Quoted 1 line

count for valid range? (Similar to axienet_ethtools_set_ringparam so that user is

notified

Quoted 1 line

for incorrect range)

The value reported will be unclamped. In [1] I improve the driver to return the actual (clamped) value.

Remember that without this commit, we have silent wraparound instead. I think clamping is much friendlier, since you at least get something close to the rx-frames value, instead of zero!

This commit is just a fix for the overflow issue. To ensure it is appropriate for backporting I have omitted any other changes/improvements.

Quoted 6 lines
Quoted 3 lines

But the point is the fix also can be to avoid setting coalesce count to invalid (or not supported range) value - like done in existing axienet_ethtools_set_ringparam() implementation.

Sean: I think above comment got missed out, so I am bringing it again to discuss and close on it.

I am investigating whether this will work within the broader context of the changes I want to make. I will reply when I have had a chance to work on it.

--Sean

Quoted 93 lines
Quoted 93 lines

And we don't clamp on every dma_start().

Quoted 90 lines

--Sean

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

Quoted 84 lines
Quoted 27 lines
Fixes 8a3b7a252dca ("drivers/net/ethernet/xilinx: added Xilinx AXI Ethernet

driver")
---

Changes in v2:
- Use FIELD_MAX to extract the max value from the mask
- Expand the commit message with an example on how to reproduce this issue

 drivers/net/ethernet/xilinx/xilinx_axienet.h      | 5 ++---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -1
index 1223fcc1a8da..54db69893565 100644
@@ -109,11 +109,10 @@
 #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet
 */
 #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits
 */
 
-#define XAXIDMA_DELAY_MASK		0xFF000000 /* Delay timeout
Quoted 5 lines

counter */
-#define XAXIDMA_COALESCE_MASK 0x00FF0000 /* Coalesce
counter */
+#define XAXIDMA_DELAY_MASK ((u32)0xFF000000) /* Delay
timeout counter */

Adding typecast here looks odd. Any reason for it? If needed we do it in specific case where it is required.

Quoted 47 lines

+#define XAXIDMA_COALESCE_MASK ((u32)0x00FF0000) /*
Coalesce counter */

#define XAXIDMA_DELAY_SHIFT 24
-#define XAXIDMA_COALESCE_SHIFT 16

#define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion
intr */
#define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay
interrupt */

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
index 9eb300fc3590..89b63695293d 100644
@@ -252,7 +252,9 @@ 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 +3 -0
+	lp->rx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_rx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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 RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +266,9 @@ 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 +3 -0
+	lp->tx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_tx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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

#7 lore raw
In reply to Pandey, Radhey Shyam
Quoted 53 lines · Radhey Shyam
Quoted 15 lines

-----Original Message-----
From: Sean Anderson <[email protected]>
Sent: Tuesday, September 10, 2024 4:39 AM
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: Andy Chiu <[email protected]>; [email protected]; Simon Horman <[email protected]>; Ariane Keller <[email protected]>; Daniel Borkmann <[email protected]>; linux-arm- [email protected]; Simek, Michal <[email protected]>; Sean Anderson <[email protected]>
Subject: [PATCH net v2] net: xilinx: axienet: Fix IRQ coalescing packet count overflow

Quoted 7 lines

If coalece_count is greater than 255 it will not fit in the register and will overflow. This can be reproduced by running

    # ethtool -C ethX rx-frames 256

which will result in a timeout of 0us instead. Fix this by clamping the counts to the maximum value.

After this fix - what is o/p we get on rx-frames read? I think silent clamping is not a great idea and user won't know about it. One alternative is to add check in set_coalesc count for valid range? (Similar to axienet_ethtools_set_ringparam so that user is notified for incorrect range)

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

driver")
---

Changes in v2:
- Use FIELD_MAX to extract the max value from the mask
- Expand the commit message with an example on how to reproduce this issue

 drivers/net/ethernet/xilinx/xilinx_axienet.h      | 5 ++---
 drivers/net/ethernet/xilinx/xilinx_axienet_main.c | 8 ++++++--
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -0
index 1223fcc1a8da..54db69893565 100644
@@ -109,11 +109,10 @@
 #define XAXIDMA_BD_CTRL_TXEOF_MASK	0x04000000 /* Last tx packet
 */
 #define XAXIDMA_BD_CTRL_ALL_MASK	0x0C000000 /* All control bits
 */
 
Quoted 9 lines
Quoted 6 lines
drivers/net/ethernet/xilinx/xilinx_axienet.h +0 -1
-#define XAXIDMA_DELAY_MASK		0xFF000000 /* Delay timeout

counter */
-#define XAXIDMA_COALESCE_MASK 0x00FF0000 /* Coalesce
counter */
+#define XAXIDMA_DELAY_MASK ((u32)0xFF000000) /* Delay
timeout counter */

Adding typecast here looks odd. Any reason for it? If needed we do it in specific case where it is required.

Sorry, I missed this on my first read.

This is necessary for...

Quoted 18 lines
Quoted 18 lines

+#define XAXIDMA_COALESCE_MASK ((u32)0x00FF0000) /*
Coalesce counter */

#define XAXIDMA_DELAY_SHIFT 24
-#define XAXIDMA_COALESCE_SHIFT 16

#define XAXIDMA_IRQ_IOC_MASK 0x00001000 /* Completion
intr */
#define XAXIDMA_IRQ_DELAY_MASK 0x00002000 /* Delay
interrupt */

drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -0
index 9eb300fc3590..89b63695293d 100644
@@ -252,7 +252,9 @@ static u32 axienet_usec_to_timer(struct axienet_local
 *lp, u32 coalesce_usec)
 static void axienet_dma_start(struct axienet_local *lp)
Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/xilinx/xilinx_axienet_main.c +0 -1
 {
 	/* 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 +3 -0
+	lp->rx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_rx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |

this expression. Since min will complain if the types of its arguments differ. Since coalesce_count_rx is a u32, and integer constants default to int, I cast the mask to u32 above. Although a U suffix would have also worked.

--Sean

Quoted 22 lines
Quoted 21 lines

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 RX packet. Otherwise leave at 0 to disable delay interrupt.
@@ -264,7 +266,9 @@ 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 +3 -0
+	lp->tx_dma_cr = FIELD_PREP(XAXIDMA_COALESCE_MASK,
+				   min(lp->coalesce_count_tx,
+

FIELD_MAX(XAXIDMA_COALESCE_MASK))) |
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