Skip to contentSkip to conversation

ibmveth: Use WARN_ON with error handling rather than BUG_ON

PATCH In review Dave Marquardt 2 participants 3 messages Apr 10, 2025 – Apr 14, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ibmveth: Use WARN_ON with error handling rather than BUG_ON

- Replaced BUG_ON calls with WARN_ON calls with error handling, with calls to a new ibmveth_reset routine, which resets the device.
- Added KUnit tests for ibmveth_remove_buffer_from_pool and ibmveth_rxq_get_buffer under new IBMVETH_KUNIT_TEST config option.
- Removed unneeded forward declaration of ibmveth_rxq_harvest_buffer.

---
 drivers/net/ethernet/ibm/Kconfig   |  13 ++
 drivers/net/ethernet/ibm/ibmveth.c | 242 ++++++++++++++++++++++++++---
 drivers/net/ethernet/ibm/ibmveth.h |  65 ++++----
 3 files changed, 269 insertions(+), 51 deletions(-)
drivers/net/ethernet/ibm/Kconfig +13 -0
index c0c112d95b89..4f4b23465c47 100644
@@ -27,6 +27,19 @@ config IBMVETH
 	  To compile this driver as a module, choose M here. The module will
 	  be called ibmveth.
 
+config IBMVETH_KUNIT_TEST
+	bool "KUnit test for IBM LAN Virtual Ethernet support" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	depends on KUNIT=y && IBMVETH=y
+	default KUNIT_ALL_TESTS
+	help
+	  This builds unit tests for the IBM LAN Virtual Ethernet driver.
+
+	  For more information on KUnit and unit tests in general, please refer
+	  to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  If unsure, say N.
+
 source "drivers/net/ethernet/ibm/emac/Kconfig"
 
 config EHEA
drivers/net/ethernet/ibm/ibmveth.c +223 -19

352 lines not on this page · raw message

drivers/net/ethernet/ibm/ibmveth.h +33 -32

71 lines not on this page · raw message

Signature · 1 line
2.49.0
#1 lore raw
Quoted 5 lines · Dave Marquardt

- Replaced BUG_ON calls with WARN_ON calls with error handling, with calls to a new ibmveth_reset routine, which resets the device.
- Added KUnit tests for ibmveth_remove_buffer_from_pool and ibmveth_rxq_get_buffer under new IBMVETH_KUNIT_TEST config option.
- Removed unneeded forward declaration of ibmveth_rxq_harvest_buffer.

It will be great if you split this patch into 3 patches according to your description.

Quoted 54 lines
---
 drivers/net/ethernet/ibm/Kconfig   |  13 ++
 drivers/net/ethernet/ibm/ibmveth.c | 242 ++++++++++++++++++++++++++---
 drivers/net/ethernet/ibm/ibmveth.h |  65 ++++----
 3 files changed, 269 insertions(+), 51 deletions(-)
drivers/net/ethernet/ibm/Kconfig +13 -0
index c0c112d95b89..4f4b23465c47 100644
@@ -27,6 +27,19 @@ config IBMVETH
 	  To compile this driver as a module, choose M here. The module will
 	  be called ibmveth.
 
+config IBMVETH_KUNIT_TEST
+	bool "KUnit test for IBM LAN Virtual Ethernet support" if !KUNIT_ALL_TESTS
+	depends on KUNIT
+	depends on KUNIT=y && IBMVETH=y
+	default KUNIT_ALL_TESTS
+	help
+	  This builds unit tests for the IBM LAN Virtual Ethernet driver.
+
+	  For more information on KUnit and unit tests in general, please refer
+	  to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  If unsure, say N.
+
 source "drivers/net/ethernet/ibm/emac/Kconfig"
 
 config EHEA
drivers/net/ethernet/ibm/ibmveth.c +1 -2
index 04192190beba..ea201e5cc8bc 100644
@@ -28,6 +28,7 @@
 #include <linux/ip.h>
 #include <linux/ipv6.h>
 #include <linux/slab.h>
+#include <linux/workqueue.h>
 #include <asm/hvcall.h>
 #include <linux/atomic.h>
 #include <asm/vio.h>
@@ -39,8 +40,6 @@
 #include "ibmveth.h"
 
 static irqreturn_t ibmveth_interrupt(int irq, void *dev_instance);
-static void ibmveth_rxq_harvest_buffer(struct ibmveth_adapter *adapter,
-				       bool reuse);
 static unsigned long ibmveth_get_desired_dma(struct vio_dev *vdev);
 
 static struct kobj_type ktype_veth_pool;

drivers/net/ethernet/ibm/ibmveth.c static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, · line 234

Quoted 6 lines
drivers/net/ethernet/ibm/ibmveth.c +2 -1
@@ -231,7 +230,10 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter,
 		index = pool->free_map[free_index];
 		skb = NULL;
 
-		BUG_ON(index == IBM_VETH_INVALID_MAP);
+		if (WARN_ON(index == IBM_VETH_INVALID_MAP)) {
+			(void)schedule_work(&adapter->work);

What is the purpose of void casting here (and in other places in this patch)?

drivers/net/ethernet/ibm/ibmveth.c static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, · line 235

Quoted 1 line
drivers/net/ethernet/ibm/ibmveth.c +1 -0
+			goto failure2;

Maybe increment_buffer_failure, or sth that is telling what happen after goto.

Quoted 16 lines
drivers/net/ethernet/ibm/ibmveth.c +2 -0
+		}
 
 		/* are we allocating a new buffer or recycling an old one */
 		if (pool->skbuff[index])
@@ -300,6 +302,7 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter,
 		                 DMA_FROM_DEVICE);
 	dev_kfree_skb_any(pool->skbuff[index]);
 	pool->skbuff[index] = NULL;
+failure2:
 	adapter->replenish_add_buff_failure++;
 
 	mb();
@@ -370,20 +373,36 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter,
 	}
 }
 

[...]

#2 lore raw
Quoted 9 lines · Michal Swiatkowski
Quoted 5 lines · Dave Marquardt

- Replaced BUG_ON calls with WARN_ON calls with error handling, with calls to a new ibmveth_reset routine, which resets the device.
- Added KUnit tests for ibmveth_remove_buffer_from_pool and ibmveth_rxq_get_buffer under new IBMVETH_KUNIT_TEST config option.
- Removed unneeded forward declaration of ibmveth_rxq_harvest_buffer.

It will be great if you split this patch into 3 patches according to your description.

Thanks. I debated the right approach here. Thanks for the guidance.

Quoted 11 lines

drivers/net/ethernet/ibm/ibmveth.c static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, · line 234

Quoted 8 lines

static struct kobj_type ktype_veth_pool;

drivers/net/ethernet/ibm/ibmveth.c +2 -1
@@ -231,7 +230,10 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter,
 		index = pool->free_map[free_index];
 		skb = NULL;
 
-		BUG_ON(index == IBM_VETH_INVALID_MAP);
+		if (WARN_ON(index == IBM_VETH_INVALID_MAP)) {
+			(void)schedule_work(&adapter->work);

What is the purpose of void casting here (and in other places in this patch)?

I'm indicating that I'm ignoring the bool returned by schedule_work(). Since this seemed odd to you, I take it the convention in Linux code is not doing this.

Quoted 4 lines

drivers/net/ethernet/ibm/ibmveth.c static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter, · line 235

Quoted 1 line
drivers/net/ethernet/ibm/ibmveth.c +1 -0
+			goto failure2;

Maybe increment_buffer_failure, or sth that is telling what happen after goto.

Okay, I can change that.

Quoted 11 lines
Quoted 11 lines
drivers/net/ethernet/ibm/ibmveth.c +2 -0
+		}
 
 		/* are we allocating a new buffer or recycling an old one */
 		if (pool->skbuff[index])
@@ -300,6 +302,7 @@ static void ibmveth_replenish_buffer_pool(struct ibmveth_adapter *adapter,
 		                 DMA_FROM_DEVICE);
 	dev_kfree_skb_any(pool->skbuff[index]);
 	pool->skbuff[index] = NULL;
+failure2:
 	adapter->replenish_add_buff_failure++;
 
Quoted 7 lines
Quoted 5 lines
(quoted diff) +0 -0
 	mb();
@@ -370,20 +373,36 @@ static void ibmveth_free_buffer_pool(struct ibmveth_adapter *adapter,
 	}
 }
 

[...]

Thanks for your review!

-Dave