git: 82a6a8c2941a - stable/13 - LinuxKPI: 802.11 fix locking in lkpi_stop_hw_scan()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Sun, 16 Jan 2022 23:21:01 UTC
The branch stable/13 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=82a6a8c2941ac7819b90c841484ed6a155e2a459

commit 82a6a8c2941ac7819b90c841484ed6a155e2a459
Author:     Bjoern A. Zeeb <bz@FreeBSD.org>
AuthorDate: 2022-01-10 22:12:53 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2022-01-16 22:39:28 +0000

    LinuxKPI: 802.11 fix locking in lkpi_stop_hw_scan()
    
    In lkpi_stop_hw_scan() we have to unlock around cancelling the
    hardware scan and an msleep to wait for the confirmation that the
    scan ended.  Otherwise we are sleeping with the non-sleepable
    net80211 com lock held.  At the same time we need to hold the lhw
    lock for the msleep().
    This lock change got lost in the refactoring of lkpi_iv_newstate().
    
    Reported by:    ambrisko, delphij
    PR:             261075
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit bec766282f242aab3a4bfba402ea74cb0ccf96fb)
---
 sys/compat/linuxkpi/common/src/linux_80211.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c
index 8515152d66a6..ff58d715ac65 100644
--- a/sys/compat/linuxkpi/common/src/linux_80211.c
+++ b/sys/compat/linuxkpi/common/src/linux_80211.c
@@ -573,11 +573,15 @@ lkpi_stop_hw_scan(struct lkpi_hw *lhw, struct ieee80211_vif *vif)
 
 	hw = LHW_TO_HW(lhw);
 
+	IEEE80211_UNLOCK(lhw->ic);
+	LKPI_80211_LHW_LOCK(lhw);
 	/* Need to cancel the scan. */
 	lkpi_80211_mo_cancel_hw_scan(hw, vif);
 
 	/* Need to make sure we see ieee80211_scan_completed. */
 	error = msleep(lhw, &lhw->mtx, 0, "lhwscanstop", hz/2);
+	LKPI_80211_LHW_UNLOCK(lhw);
+	IEEE80211_LOCK(lhw->ic);
 
 	if ((lhw->scan_flags & LKPI_SCAN_RUNNING) != 0)
 		ic_printf(lhw->ic, "%s: failed to cancel scan: %d (%p, %p)\n",