git: bec766282f24 - main - LinuxKPI: 802.11 fix locking in lkpi_stop_hw_scan()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Mon, 10 Jan 2022 22:30:23 UTC
The branch main has been updated by bz:

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

commit bec766282f242aab3a4bfba402ea74cb0ccf96fb
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-10 22:29:23 +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
    MFC after:      3 days
    Sponsored by:   The FreeBSD Foundation
---
 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 973f49e8676b..d2e095040696 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",