ionic: minor code fixes
Subsystems (3)
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
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.
--- 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
@@ -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
@@ -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
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 callingionic_lif_unregister()onregister_netdev()failure. This will also callionic_lif_unregister_phc()if it has already been registered.
Quoted 7 lines
While at it, remove the empty and unused
nb_workand associatedionic_lif_notify_work()function.Fixes 30b87ab4c0b3 ("ionic: remove lif list concept")Signed-off-by Brett Creeley <[email protected]>Signed-off-by Shannon Nelson <[email protected]>---
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@@ -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@@ -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 ; }
Jakub Kicinski
maintainerRe: [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
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_workremoval to a net-next commit --
pw-bot: cr
Will do - thanks.
sln
PATCH 2/3 ionic: no double destroy workqueue
In reply to Shannon NelsonThere 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.
--- 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
@@ -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
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 thusionic_dev_teardown()got called twice in a row. The second time through the workqueue was already destroyed, anddestroy_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")Signed-off-by Shannon Nelson <[email protected]>--- 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
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
-0mutex_destroy (&idev->cmb_inuse_lock); }
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 thusionic_dev_teardown()got called twice in a row. The second time through the workqueue was already destroyed, anddestroy_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")Signed-off-by Shannon Nelson <[email protected]>--- 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@@ -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_teardowntwice. 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,
JakeQuoted 3 lines
drivers/net/ethernet/pensando/ionic/ionic_dev.c +0
-0mutex_destroy (&idev->cmb_inuse_lock); }
Jacob Keller
Reviewed-byRe: [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 thusionic_dev_teardown()got called twice in a row. The second time through the workqueue was already destroyed, anddestroy_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")Signed-off-by Shannon Nelson <[email protected]>--- 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@@ -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_teardowntwice. 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_preparethreads, 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 ifreset_prepareand 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,
JakeQuoted 3 lines
drivers/net/ethernet/pensando/ionic/ionic_dev.c +0
-0mutex_destroy (&idev->cmb_inuse_lock); }
PATCH 3/3 ionic: use ee->offset when returning sprom data
In reply to Shannon NelsonSome 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.
--- 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
@@ -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
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")Signed-off-by Shannon Nelson <[email protected]>--- 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
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))