Skip to contentSkip to conversation

wifi: mt76: mt792x: Fix a potential deadlock in high-load situations

PATCH In review Leon Yen 2 participants 2 messages Dec 15, 2025 – Dec 18, 2025

Subsystems (2)
lore
Share & tools
lore

Leon Yen

author
#0 lore raw

PATCH v2 1/1 wifi: mt76: mt792x: Fix a potential deadlock in high-load situations

A deadlock may occur between two works, ps_work and mac_work, if their work functions run simultaneously as they attempt to cancel each other by calling cancel_delayed_work_sync().

mt792x_mac_work() -> ... -> cancel_delayed_work_sync(&pm->ps_work);
mt792x_pm_power_save_work() -> cancel_delayed_work_sync(&mphy->mac_work);

In high-load situations, they are queued but may not have chance to be executed until the CPUs are released. Once the CPUs are available, there is a high possibility that the ps_work function and mac_work function will be executed simultaneously, resulting in a possible deadlock.

This patch replaces cancel_delayed_work_sync() with cancel_delayed_work() in ps_work to eliminate the deadlock and make the code easier to maintain.

---
v2: Modify the solution to make it simpler and easier to maintain

---
 drivers/net/wireless/mediatek/mt76/mt792x_mac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt792x_mac.c +1 -1
index 71dec93094eb..888e5a505673 100644
@@ -375,7 +375,7 @@ void mt792x_pm_power_save_work(struct work_struct *work)
 	}
 
 	if (!mt792x_mcu_fw_pmctrl(dev)) {
-		cancel_delayed_work_sync(&mphy->mac_work);
+		cancel_delayed_work(&mphy->mac_work);
 		return;
 	}
 out:
Signature · 1 line
2.45.2
Tested-by on v2 1/1
#1 lore raw

Leon Yen <[email protected]> 於 2025年12月15日週一 下午8:24寫道:

Quoted 13 lines

A deadlock may occur between two works, ps_work and mac_work, if their work functions run simultaneously as they attempt to cancel each other by calling cancel_delayed_work_sync().

mt792x_mac_work() -> ... -> cancel_delayed_work_sync(&pm->ps_work);
mt792x_pm_power_save_work() -> cancel_delayed_work_sync(&mphy->mac_work);

In high-load situations, they are queued but may not have chance to be executed until the CPUs are released. Once the CPUs are available, there is a high possibility that the ps_work function and mac_work function will be executed simultaneously, resulting in a possible deadlock.

Quoted 4 lines

This patch replaces cancel_delayed_work_sync() with cancel_delayed_work() in ps_work to eliminate the deadlock and make the code easier to maintain.

Without the patch, the system may hang during stress tests. And now I can't reproduce the hang issue with this patch. Thanks.

Quoted 23 lines

---
v2: Modify the solution to make it simpler and easier to maintain

---
 drivers/net/wireless/mediatek/mt76/mt792x_mac.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/mediatek/mt76/mt792x_mac.c +1 -2
index 71dec93094eb..888e5a505673 100644
@@ -375,7 +375,7 @@ void mt792x_pm_power_save_work(struct work_struct *work)
        }
 
        if (!mt792x_mcu_fw_pmctrl(dev)) {
-               cancel_delayed_work_sync(&mphy->mac_work);
+               cancel_delayed_work(&mphy->mac_work);
                return;
        }
 out:
--

2.45.2