r8169: replace custom flag with disable_work() et al
Heiner Kallweit
maintainercover r8169: replace custom flag with disable_work() et al
This series removes RTNL lock from rtl_task(), what is a requirement for patch 2, where instead of a custom flag we use disable_work() et al to define when work is allowed to be scheduled.
Heiner Kallweit (2):
r8169: don't take RTNL lock in rtl_task()
r8169: replace custom flag with disable_work() et al
drivers/net/ethernet/realtek/r8169_main.c | 24 +++++++---------------- 1 file changed, 7 insertions(+), 17 deletions(-)
Signature · 1 line
2.47.0
Heiner Kallweit
maintainerPATCH 1/2 r8169: don't take RTNL lock in rtl_task()
There's not really a benefit here in taking the RTNL lock. The task handler does exception handling only, so we're in trouble anyway when we come here, and there's no need to protect against e.g. a parallel ethtool call.
A benefit of removing the RTNL lock here is that we now can synchronously cancel the workqueue from a context holding the RTNL mutex.
--- drivers/net/ethernet/realtek/r8169_main.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +2 -6
@@ -4799,10 +4799,8 @@ static void rtl_task(struct work_struct *work) container_of(work, struct rtl8169_private, wk.work);int ret; -rtnl_lock (); -if (!test_bit (RTL_FLAG_TASK_ENABLED , tp->wk.flags)) - goto out_unlock; +return ;if (test_and_clear_bit (RTL_FLAG_TASK_TX_TIMEOUT , tp->wk.flags)) {/* if chip isn't accessible, reset bus to revive it */
@@ -4811,7 +4809,7 @@ static void rtl_task(struct work_struct *work)if (ret <0 ) {netdev_err (tp->dev,"Can't reset secondary PCI bus, detach NIC\n" );netif_device_detach (tp->dev); - goto out_unlock; +return ; } }
@@ -4830,8 +4828,6 @@ static void rtl_task(struct work_struct *work) }else if (test_and_clear_bit (RTL_FLAG_TASK_RESET_NO_QUEUE_WAKE , tp->wk.flags)) {rtl_reset_work (tp); } -out_unlock: -rtnl_unlock (); }static int rtl8169_poll (struct napi_struct *napi,int budget)
Signature · 1 line
2.47.0
Heiner Kallweit
maintainerPATCH 2/2 r8169: replace custom flag with disable_work() et al
In reply to Heiner KallweitSo far we use a custom flag to define when a task can be scheduled and when not. Let's use the standard mechanism with disable_work() et al instead.
Note that in rtl8169_close() we can remove the call to cancel_work() because we now call disable_work_sync() in rtl8169_down() already.
--- drivers/net/ethernet/realtek/r8169_main.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-)
drivers/net/ethernet/realtek/r8169_main.c +6 -12
@@ -618,7 +618,6 @@ struct rtl8169_tc_offsets { };enum rtl_flag { -RTL_FLAG_TASK_ENABLED =0 ,RTL_FLAG_TASK_RESET_PENDING ,RTL_FLAG_TASK_RESET_NO_QUEUE_WAKE ,RTL_FLAG_TASK_TX_TIMEOUT ,
@@ -2503,11 +2502,9 @@ u16 rtl8168h_2_get_adc_bias_ioffset(struct rtl8169_private *tp)static void rtl_schedule_task (struct rtl8169_private *tp,enum rtl_flag flag) { -if (!test_bit (RTL_FLAG_TASK_ENABLED , tp->wk.flags)) -return ; -set_bit (flag, tp->wk.flags); -schedule_work (&tp->wk.work); +if (!schedule_work (&tp->wk.work)) +clear_bit (flag, tp->wk.flags); }static void rtl8169_init_phy (struct rtl8169_private *tp)
@@ -4799,9 +4796,6 @@ static void rtl_task(struct work_struct *work) container_of(work, struct rtl8169_private, wk.work);int ret; -if (!test_bit (RTL_FLAG_TASK_ENABLED , tp->wk.flags)) -return ; -if (test_and_clear_bit (RTL_FLAG_TASK_TX_TIMEOUT , tp->wk.flags)) {/* if chip isn't accessible, reset bus to revive it */ if (RTL_R32 (tp, TxConfig) == ~0 ) {
@@ -4885,6 +4879,7 @@ static int r8169_phy_connect(struct rtl8169_private *tp)static void rtl8169_down (struct rtl8169_private *tp) { +disable_work_sync (&tp->wk.work);/* Clear all task flags */ bitmap_zero (tp->wk.flags,RTL_FLAG_MAX );
@@ -4913,7 +4908,7 @@ static void rtl8169_up(struct rtl8169_private *tp)phy_resume (tp->phydev);rtl8169_init_phy (tp);napi_enable (&tp->napi); -set_bit (RTL_FLAG_TASK_ENABLED , tp->wk.flags); +enable_work (&tp->wk.work);rtl_reset_work (tp);phy_start (tp->phydev);
@@ -4930,8 +4925,6 @@ static int rtl8169_close(struct net_device *dev)rtl8169_down (tp);rtl8169_rx_clear (tp); -cancel_work (&tp->wk.work); -free_irq (tp->irq, tp);phy_disconnect (tp->phydev);
@@ -5164,7 +5157,7 @@ static void rtl_remove_one(struct pci_dev *pdev)if (pci_dev_run_wake (pdev))pm_runtime_get_noresume (&pdev->dev); -cancel_work_sync (&tp->wk.work); +disable_work_sync (&tp->wk.work);if (IS_ENABLED (CONFIG_R8169_LEDS ))r8169_remove_leds (tp->leds);
@@ -5578,6 +5571,7 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) tp->irq =pci_irq_vector (pdev,0 );INIT_WORK (&tp->wk.work, rtl_task); +disable_work (&tp->wk.work);rtl_init_mac_address (tp);
Signature · 1 line
2.47.0
This series was applied to netdev/net-next.git (main) by Andrew Lunn <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Andrew Lunn <[email protected]>:
Quoted 9 lines · On Wed, 16 Oct 2024 22:04:44 +0200 you wrote:
This series removes RTNL lock from
rtl_task(), what is a requirement for patch 2, where instead of a custom flag we usedisable_work()et al to define when work is allowed to be scheduled.Heiner Kallweit (2):
r8169: don't take RTNL lock inrtl_task()
r8169: replace custom flag withdisable_work()et al[...]
Here is the summary with links:
- [net-next,1/2] r8169: don't take RTNL lock in rtl_task()
https://git.kernel.org/netdev/net-next/c/ac48430368c1 - [net-next,2/2] r8169: replace custom flag with disable_work() et al https://git.kernel.org/netdev/net-next/c/e2015942e90a
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html