Skip to contentSkip to conversation

ionic: minor code fixes

PATCH In review Shannon Nelson 3 participants 11 messages Dec 10, 2024 – Dec 12, 2024

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

cover ionic: minor code fixes

These are a couple of code fixes for the ionic driver.

Brett Creeley (1):
ionic: Fix netdev notifier unregister on failure

Shannon Nelson (2):
ionic: no double destroy workqueue
ionic: use ee->offset when returning sprom data

 drivers/net/ethernet/pensando/ionic/ionic.h         |  1 -
 drivers/net/ethernet/pensando/ionic/ionic_dev.c     |  5 ++++-
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c |  4 ++--
 drivers/net/ethernet/pensando/ionic/ionic_lif.c     | 11 ++---------
 4 files changed, 8 insertions(+), 13 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/3 ionic: Fix netdev notifier unregister on failure

From: Brett Creeley <[email protected]>

If register_netdev() fails, then the driver leaks the netdev notifier. Fix this by calling ionic_lif_unregister() on register_netdev() failure. This will also call ionic_lif_unregister_phc() if it has already been registered.

While at it, remove the empty and unused nb_work and associated ionic_lif_notify_work() function.

Fixes 30b87ab4c0b3 ("ionic: remove lif list concept")
---
 drivers/net/ethernet/pensando/ionic/ionic.h     |  1 -
 drivers/net/ethernet/pensando/ionic/ionic_lif.c | 11 ++---------
 2 files changed, 2 insertions(+), 10 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic.h +0 -1
index 1c61390677f7..faaf96af506d 100644
@@ -59,7 +59,6 @@ struct ionic {
 	DECLARE_BITMAP(intrs, IONIC_INTR_CTRL_REGS_MAX);
 	cpumask_var_t *affinity_masks;
 	struct delayed_work doorbell_check_dwork;
-	struct work_struct nb_work;
 	struct notifier_block nb;
 	struct rw_semaphore vf_op_lock;	/* lock for VF operations */
 	struct ionic_vf *vfs;
drivers/net/ethernet/pensando/ionic/ionic_lif.c +2 -9
index 40496587b2b3..bfa24c659d84 100644
@@ -3804,10 +3804,6 @@ int ionic_lif_init(struct ionic_lif *lif)
 	return err;
 }
 
-static void ionic_lif_notify_work(struct work_struct *ws)
-{
-}
-
 static void ionic_lif_set_netdev_info(struct ionic_lif *lif)
 {
 	struct ionic_admin_ctx ctx = {
@@ -3858,8 +3854,6 @@ int ionic_lif_register(struct ionic_lif *lif)
 
 	ionic_lif_register_phc(lif);
 
-	INIT_WORK(&lif->ionic->nb_work, ionic_lif_notify_work);
-
 	lif->ionic->nb.notifier_call = ionic_lif_notify;
 
 	err = register_netdevice_notifier(&lif->ionic->nb);
@@ -3869,8 +3863,8 @@ int ionic_lif_register(struct ionic_lif *lif)
 	/* only register LIF0 for now */
 	err = register_netdev(lif->netdev);
 	if (err) {
-		dev_err(lif->ionic->dev, "Cannot register net device, aborting\n");
-		ionic_lif_unregister_phc(lif);
+		dev_err(lif->ionic->dev, "Cannot register net device: %d, aborting\n", err);
+		ionic_lif_unregister(lif);
 		return err;
 	}
 
@@ -3885,7 +3879,6 @@ void ionic_lif_unregister(struct ionic_lif *lif)
 {
 	if (lif->ionic->nb.notifier_call) {
 		unregister_netdevice_notifier(&lif->ionic->nb);
-		cancel_work_sync(&lif->ionic->nb_work);
 		lif->ionic->nb.notifier_call = NULL;
 	}
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH net 1/3] ionic: Fix netdev notifier unregister on failure

Quoted 7 lines · Shannon Nelson

From: Brett Creeley <[email protected]>

If register_netdev() fails, then the driver leaks the netdev notifier. Fix this by calling ionic_lif_unregister() on register_netdev() failure. This will also call ionic_lif_unregister_phc() if it has already been registered.

Quoted 7 lines

While at it, remove the empty and unused nb_work and associated ionic_lif_notify_work() function.

Fixes 30b87ab4c0b3 ("ionic: remove lif list concept")

---

I'm not certain about the inclusion of cleanup to drop unused code in the same commit as an obvious fix. However, the changes as a whole seem ok to me:

With or without splitting:

Quoted 59 lines
 drivers/net/ethernet/pensando/ionic/ionic.h     |  1 -
 drivers/net/ethernet/pensando/ionic/ionic_lif.c | 11 ++---------
 2 files changed, 2 insertions(+), 10 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic.h +0 -1
index 1c61390677f7..faaf96af506d 100644
@@ -59,7 +59,6 @@ struct ionic {
 	DECLARE_BITMAP(intrs, IONIC_INTR_CTRL_REGS_MAX);
 	cpumask_var_t *affinity_masks;
 	struct delayed_work doorbell_check_dwork;
-	struct work_struct nb_work;
 	struct notifier_block nb;
 	struct rw_semaphore vf_op_lock;	/* lock for VF operations */
 	struct ionic_vf *vfs;
drivers/net/ethernet/pensando/ionic/ionic_lif.c +2 -9
index 40496587b2b3..bfa24c659d84 100644
@@ -3804,10 +3804,6 @@ int ionic_lif_init(struct ionic_lif *lif)
 	return err;
 }
 
-static void ionic_lif_notify_work(struct work_struct *ws)
-{
-}
-
 static void ionic_lif_set_netdev_info(struct ionic_lif *lif)
 {
 	struct ionic_admin_ctx ctx = {
@@ -3858,8 +3854,6 @@ int ionic_lif_register(struct ionic_lif *lif)
 
 	ionic_lif_register_phc(lif);
 
-	INIT_WORK(&lif->ionic->nb_work, ionic_lif_notify_work);
-
 	lif->ionic->nb.notifier_call = ionic_lif_notify;
 
 	err = register_netdevice_notifier(&lif->ionic->nb);
@@ -3869,8 +3863,8 @@ int ionic_lif_register(struct ionic_lif *lif)
 	/* only register LIF0 for now */
 	err = register_netdev(lif->netdev);
 	if (err) {
-		dev_err(lif->ionic->dev, "Cannot register net device, aborting\n");
-		ionic_lif_unregister_phc(lif);
+		dev_err(lif->ionic->dev, "Cannot register net device: %d, aborting\n", err);
+		ionic_lif_unregister(lif);
 		return err;
 	}
 
@@ -3885,7 +3879,6 @@ void ionic_lif_unregister(struct ionic_lif *lif)
 {
 	if (lif->ionic->nb.notifier_call) {
 		unregister_netdevice_notifier(&lif->ionic->nb);
-		cancel_work_sync(&lif->ionic->nb_work);
 		lif->ionic->nb.notifier_call = NULL;
 	}
 
maintainer
#3 lore raw

Re: [PATCH net 1/3] ionic: Fix netdev notifier unregister on failure

Quoted 2 lines · On Tue, 10 Dec 2024 12:59:31 -0800 Jacob Keller wrote:

I'm not certain about the inclusion of cleanup to drop unused code in the same commit as an obvious fix.

+1, please separate the nb_work removal to a net-next commit

Signature · 1 line
pw-bot: cr
#4 lore raw

Re: [PATCH net 1/3] ionic: Fix netdev notifier unregister on failure

Quoted 7 lines · Jakub Kicinski
Quoted 2 lines · On Tue, 10 Dec 2024 12:59:31 -0800 Jacob Keller wrote:

I'm not certain about the inclusion of cleanup to drop unused code in the same commit as an obvious fix.

+1, please separate the nb_work removal to a net-next commit --
pw-bot: cr

Will do - thanks.
sln

#5 lore raw

PATCH 2/3 ionic: no double destroy workqueue

In reply to Shannon Nelson

There are some FW error handling paths that can cause us to try to destroy the workqueue more than once, so let's be sure we're checking for that.

The case where this popped up was in an AER event where the handlers got called in such a way that ionic_reset_prepare() and thus ionic_dev_teardown() got called twice in a row. The second time through the workqueue was already destroyed, and destroy_workqueue() choked on the bad wq pointer.

We didn't hit this in AER handler testing before because at that time we weren't using a private workqueue. Later we replaced the use of the system workqueue with our own private workqueue but hadn't rerun the AER handler testing since then.

Fixes 9e25450da700 ("ionic: add private workqueue per-device")
---
 drivers/net/ethernet/pensando/ionic/ionic_dev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_dev.c +4 -1
index 9e42d599840d..57edcde9e6f8 100644
@@ -277,7 +277,10 @@ void ionic_dev_teardown(struct ionic *ionic)
 	idev->phy_cmb_pages = 0;
 	idev->cmb_npages = 0;
 
-	destroy_workqueue(ionic->wq);
+	if (ionic->wq) {
+		destroy_workqueue(ionic->wq);
+		ionic->wq = NULL;
+	}
 	mutex_destroy(&idev->cmb_inuse_lock);
 }
 
Signature · 1 line
2.17.1
#6 lore raw

Re: [PATCH net 2/3] ionic: no double destroy workqueue

Quoted 26 lines · Shannon Nelson

There are some FW error handling paths that can cause us to try to destroy the workqueue more than once, so let's be sure we're checking for that.

The case where this popped up was in an AER event where the handlers got called in such a way that ionic_reset_prepare() and thus ionic_dev_teardown() got called twice in a row. The second time through the workqueue was already destroyed, and destroy_workqueue() choked on the bad wq pointer.

We didn't hit this in AER handler testing before because at that time we weren't using a private workqueue. Later we replaced the use of the system workqueue with our own private workqueue but hadn't rerun the AER handler testing since then.

Fixes 9e25450da700 ("ionic: add private workqueue per-device")
---
 drivers/net/ethernet/pensando/ionic/ionic_dev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_dev.c +0 -0
index 9e42d599840d..57edcde9e6f8 100644

drivers/net/ethernet/pensando/ionic/ionic_dev.c void ionic_dev_teardown(struct ionic *ionic) · line 283

Quoted 8 lines
drivers/net/ethernet/pensando/ionic/ionic_dev.c +4 -1
@@ -277,7 +277,10 @@ void ionic_dev_teardown(struct ionic *ionic)
 	idev->phy_cmb_pages = 0;
 	idev->cmb_npages = 0;
 
-	destroy_workqueue(ionic->wq);
+	if (ionic->wq) {
+		destroy_workqueue(ionic->wq);
+		ionic->wq = NULL;
+	}

This seems like you still could race if two threads call ionic_dev_teardown twice. Is that not possible due to some other synchronization mechanism?

Thanks,
Jake

Quoted 3 lines
drivers/net/ethernet/pensando/ionic/ionic_dev.c +0 -0
 	mutex_destroy(&idev->cmb_inuse_lock);
 }
 
#7 lore raw

Re: [PATCH net 2/3] ionic: no double destroy workqueue

Quoted 30 lines · Jacob Keller
Quoted 29 lines · Shannon Nelson

There are some FW error handling paths that can cause us to try to destroy the workqueue more than once, so let's be sure we're checking for that.

The case where this popped up was in an AER event where the handlers got called in such a way that ionic_reset_prepare() and thus ionic_dev_teardown() got called twice in a row. The second time through the workqueue was already destroyed, and destroy_workqueue() choked on the bad wq pointer.

We didn't hit this in AER handler testing before because at that time we weren't using a private workqueue. Later we replaced the use of the system workqueue with our own private workqueue but hadn't rerun the AER handler testing since then.

Fixes 9e25450da700 ("ionic: add private workqueue per-device")
---
  drivers/net/ethernet/pensando/ionic/ionic_dev.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_dev.c +0 -0
index 9e42d599840d..57edcde9e6f8 100644
@@ -277,7 +277,10 @@ void ionic_dev_teardown(struct ionic *ionic)
       idev->phy_cmb_pages = 0;
       idev->cmb_npages = 0;
 
Quoted 9 lines

drivers/net/ethernet/pensando/ionic/ionic_dev.c void ionic_dev_teardown(struct ionic *ionic) · line 283

Quoted 5 lines
drivers/net/ethernet/pensando/ionic/ionic_dev.c +4 -1
-     destroy_workqueue(ionic->wq);
+     if (ionic->wq) {
+             destroy_workqueue(ionic->wq);
+             ionic->wq = NULL;
+     }

This seems like you still could race if two threads call ionic_dev_teardown twice. Is that not possible due to some other synchronization mechanism?

Good question. Thanks for looking at this and the other patches.

This is not a race thing so much as an already-been-here thing. This function is only called by the probe, remove, and reset_prepare threads, all driven as PCI calls. I'm reasonably sure that they won't be called my simultaneous threads, so we just need to be sure that we don't break if reset_prepare and remove get called one after the other because some PCI bus element got removed by surprise.

sln

Quoted 8 lines

Thanks,
Jake

Quoted 3 lines
drivers/net/ethernet/pensando/ionic/ionic_dev.c +0 -0
       mutex_destroy(&idev->cmb_inuse_lock);
  }
 
Reviewed-by
#8 lore raw

Re: [PATCH net 2/3] ionic: no double destroy workqueue

Quoted 43 lines · Shannon
Quoted 30 lines · Jacob Keller
Quoted 29 lines · Shannon Nelson

There are some FW error handling paths that can cause us to try to destroy the workqueue more than once, so let's be sure we're checking for that.

The case where this popped up was in an AER event where the handlers got called in such a way that ionic_reset_prepare() and thus ionic_dev_teardown() got called twice in a row. The second time through the workqueue was already destroyed, and destroy_workqueue() choked on the bad wq pointer.

We didn't hit this in AER handler testing before because at that time we weren't using a private workqueue. Later we replaced the use of the system workqueue with our own private workqueue but hadn't rerun the AER handler testing since then.

Fixes 9e25450da700 ("ionic: add private workqueue per-device")
---
  drivers/net/ethernet/pensando/ionic/ionic_dev.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/net/ethernet/pensando/ionic/ionic_dev.c +0 -0
index 9e42d599840d..57edcde9e6f8 100644
@@ -277,7 +277,10 @@ void ionic_dev_teardown(struct ionic *ionic)
       idev->phy_cmb_pages = 0;
       idev->cmb_npages = 0;
 
Quoted 9 lines

drivers/net/ethernet/pensando/ionic/ionic_dev.c void ionic_dev_teardown(struct ionic *ionic) · line 283

Quoted 5 lines
drivers/net/ethernet/pensando/ionic/ionic_dev.c +4 -1
-     destroy_workqueue(ionic->wq);
+     if (ionic->wq) {
+             destroy_workqueue(ionic->wq);
+             ionic->wq = NULL;
+     }

This seems like you still could race if two threads call ionic_dev_teardown twice. Is that not possible due to some other synchronization mechanism?

Good question. Thanks for looking at this and the other patches.

Quoted 8 lines

This is not a race thing so much as an already-been-here thing. This function is only called by the probe, remove, and reset_prepare threads, all driven as PCI calls. I'm reasonably sure that they won't be called my simultaneous threads, so we just need to be sure that we don't break if reset_prepare and remove get called one after the other because some PCI bus element got removed by surprise.

sln

Ok. This is all serialized by the device/PCI layer then?

Makes sense.

Quoted 11 lines
Quoted 10 lines

Thanks,
Jake

Quoted 3 lines
drivers/net/ethernet/pensando/ionic/ionic_dev.c +0 -0
       mutex_destroy(&idev->cmb_inuse_lock);
  }
 
#9 lore raw

PATCH 3/3 ionic: use ee->offset when returning sprom data

In reply to Shannon Nelson

Some calls into ionic_get_module_eeprom() don't use a single full buffer size, but instead multiple calls with an offset. Teach our driver to use the offset correctly so we can respond appropriately to the caller.

Fixes 4d03e00a2140 ("ionic: Add initial ethtool support")
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +2 -2
index dda22fa4448c..9b7f78b6cdb1 100644
@@ -961,8 +961,8 @@ static int ionic_get_module_eeprom(struct net_device *netdev,
 	len = min_t(u32, sizeof(xcvr->sprom), ee->len);
 
 	do {
-		memcpy(data, xcvr->sprom, len);
-		memcpy(tbuf, xcvr->sprom, len);
+		memcpy(data, &xcvr->sprom[ee->offset], len);
+		memcpy(tbuf, &xcvr->sprom[ee->offset], len);
 
 		/* Let's make sure we got a consistent copy */
 		if (!memcmp(data, tbuf, len))
Signature · 1 line
2.17.1
Reviewed-by on v1 3/3
#10 lore raw

Re: [PATCH net 3/3] ionic: use ee->offset when returning sprom data

Quoted 16 lines · Shannon Nelson

Some calls into ionic_get_module_eeprom() don't use a single full buffer size, but instead multiple calls with an offset. Teach our driver to use the offset correctly so we can respond appropriately to the caller.

Fixes 4d03e00a2140 ("ionic: Add initial ethtool support")
---
 drivers/net/ethernet/pensando/ionic/ionic_ethtool.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +0 -0
index dda22fa4448c..9b7f78b6cdb1 100644

drivers/net/ethernet/pensando/ionic/ionic_ethtool.c static int ionic_get_module_eeprom(struct net_device *netdev, · line 966

Quoted 8 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +2 -2
@@ -961,8 +961,8 @@ static int ionic_get_module_eeprom(struct net_device *netdev,
 	len = min_t(u32, sizeof(xcvr->sprom), ee->len);
 
 	do {
-		memcpy(data, xcvr->sprom, len);
-		memcpy(tbuf, xcvr->sprom, len);
+		memcpy(data, &xcvr->sprom[ee->offset], len);
+		memcpy(tbuf, &xcvr->sprom[ee->offset], len);
 

Makes sense. The eeprom API doesn't require reading the entire EEPROM, and can use offsets. Previously, you copied always from the beginning which results in failure to copy the correct data out.

Quoted 2 lines
drivers/net/ethernet/pensando/ionic/ionic_ethtool.c +0 -0
 		/* Let's make sure we got a consistent copy */
 		if (!memcmp(data, tbuf, len))