From nobody Sat Apr 12 16:45:43 2025 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4ZZfYz3Z0Tz5sHyC; Sat, 12 Apr 2025 16:45:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZZfYz2rWsz3Kb0; Sat, 12 Apr 2025 16:45:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744476343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PKqJjW5QY/sGkmurREBcANgm7fYrQARBcV716sUt88w=; b=IR+LRzxYB6a7bkl8tC07Xffb9yizwzOWC0akJP96RI0R1fHrGer6BWJMsiLfJklCKeSdLq 1iZB1/KfLXXxSY1gmwSHKypzSNHSSAYcRqmNFjAtFH2SDv7e6Ro15tVMlbBSEneG57WgXx LcmJkhzUuZRxsY2Lc9xLJeQVo3mMh5hYuJJrq3WwQG35YrJkWOcEZxlHDRKY6VpP0ScC2B OTHA1GO4HvuonRdiLD8sBny0N2Lp24cSpAkZ04RjQZlPLxaN2q7VnGFwLA2U0b9VI0xNy5 YfDpHEgKVd6r9bhp/PZndfDiaH3okU7Vj7Jnm3aNZM1O1H94AFdHqnCSLSMfUg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744476343; a=rsa-sha256; cv=none; b=s2ZhfTkoF4Shx43CLlV1H27QscgZQKH/19uuDDYvKoScuGjjtKkYm9RWC05wVbWq/b6YMk Ppi0DdRLe8pyC7LUkzgAQ7rTjTqHCaMlK9dlgXt26P6Cfje2ueO8nJXjrbRxbrRCyX1Iaj RiJomvBXnveUtOqnxIuu490lrXCkTQC77lWHppVx6kTnBeGf+wONNM5W8gwFg3RqMtC1IT /XuPCb8TpmgomtymFolWoTiFcfq8DhTIzQHH34aQvcUkthbO0n6c+L8kgDt4fXhF7FrJA+ dUGxnw9huppytFec2Ns1C4uSO821RiXoM+IjQifyP25LMgdQgTXE1nNzcXt0Og== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744476343; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PKqJjW5QY/sGkmurREBcANgm7fYrQARBcV716sUt88w=; b=D2w0tWCBXil9QojJHsyQDjU8r+NnsvA04cuvGZ0SYi2T0hjSXJJ57B47BCA4WYEVjZShiA uRExpM0dkGudVNRKlI/SlKtJUO7Y2CuYBSdKvs4wSFbPtABMcoOZRBB+iPDYa4KaXcDAan 8BG5g6WupjIUNIrShQ9BYLvK4wyXEIXn3r7lLZK694ul9Y0kO5x8HKrJUgS8e1sxlNxAgL 9WnKEGwwAOtjHgD/4p/uWFjRdf+FIqkRlt4Y5AxvP118fbPUlwdEGRXGqDRYsg7mkcIWnO YCj7yowWkR5eMY2Gx29uxPkcDE0POv0Oyxsyiaef+rM+OPkl7QUvNQLMdelbGA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4ZZfYz2Rfkz9Vx; Sat, 12 Apr 2025 16:45:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 53CGjhh7043421; Sat, 12 Apr 2025 16:45:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 53CGjhMl043418; Sat, 12 Apr 2025 16:45:43 GMT (envelope-from git) Date: Sat, 12 Apr 2025 16:45:43 GMT Message-Id: <202504121645.53CGjhMl043418@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Bjoern A. Zeeb" Subject: git: a6165709e3c8 - main - LinuxKPI: 802.11: further locking workarounds fro crypto updates List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a6165709e3c8ba4a0bee18aead6ca8ea2b033933 Auto-Submitted: auto-generated The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=a6165709e3c8ba4a0bee18aead6ca8ea2b033933 commit a6165709e3c8ba4a0bee18aead6ca8ea2b033933 Author: Bjoern A. Zeeb AuthorDate: 2025-04-11 23:01:55 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-04-12 16:44:26 +0000 LinuxKPI: 802.11: further locking workarounds fro crypto updates There are cases when net80211 calls into crypto updates with the ic lock held (not (just) the nt lock). We have to unlock that as well and track the unlock like we do for the nt to avoid panics when we later can sleep (on the wiphy [sx] lock). Sponsored by: The FreeBSD Foundation MFC after: 3 days Reported by: rm Tested by: rm PR: 285729 Fixes: b8dfc3ecf703 Differential Revision: https://reviews.freebsd.org/D49791 --- sys/compat/linuxkpi/common/src/linux_80211.c | 51 ++++++++++++++++++---------- sys/compat/linuxkpi/common/src/linux_80211.h | 1 + 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c index 8368ed0d563d..3548ad04b795 100644 --- a/sys/compat/linuxkpi/common/src/linux_80211.c +++ b/sys/compat/linuxkpi/common/src/linux_80211.c @@ -1427,7 +1427,7 @@ lkpi_iv_key_update_begin(struct ieee80211vap *vap) struct lkpi_hw *lhw; struct ieee80211_hw *hw; struct lkpi_vif *lvif; - bool islocked; + bool icislocked, ntislocked; ic = vap->iv_ic; lhw = ic->ic_softc; @@ -1435,28 +1435,35 @@ lkpi_iv_key_update_begin(struct ieee80211vap *vap) lvif = VAP_TO_LVIF(vap); nt = &ic->ic_sta; - islocked = IEEE80211_NODE_IS_LOCKED(nt); + icislocked = IEEE80211_IS_LOCKED(ic); + ntislocked = IEEE80211_NODE_IS_LOCKED(nt); #ifdef LINUXKPI_DEBUG_80211 if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO) - ic_printf(vap->iv_ic, "%s: tid %d vap %p nt %p %slocked " - "lvif nt_unlocked %d\n", __func__, curthread->td_tid, - vap, nt, islocked ? "" : "un", lvif->nt_unlocked); + ic_printf(ic, "%s: tid %d vap %p ic %p %slocked nt %p %slocked " + "lvif ic_unlocked %d nt_unlocked %d\n", __func__, + curthread->td_tid, vap, + ic, icislocked ? "" : "un", nt, ntislocked ? "" : "un", + lvif->ic_unlocked, lvif->nt_unlocked); #endif /* This is inconsistent net80211 locking to be fixed one day. */ - if (islocked) + if (icislocked) + IEEE80211_UNLOCK(ic); + if (ntislocked) IEEE80211_NODE_UNLOCK(nt); wiphy_lock(hw->wiphy); /* - * nt_unlocked could be a bool given we are under the lock and there + * ic/nt_unlocked could be a bool given we are under the lock and there * must only be a single thread. * In case anything in the future disturbs the order the refcnt will * help us catching problems a lot easier. */ - if (islocked) + if (icislocked) + refcount_acquire(&lvif->ic_unlocked); + if (ntislocked) refcount_acquire(&lvif->nt_unlocked); } @@ -1468,7 +1475,7 @@ lkpi_iv_key_update_end(struct ieee80211vap *vap) struct lkpi_hw *lhw; struct ieee80211_hw *hw; struct lkpi_vif *lvif; - bool islocked; + bool icislocked, ntislocked; ic = vap->iv_ic; lhw = ic->ic_softc; @@ -1476,14 +1483,18 @@ lkpi_iv_key_update_end(struct ieee80211vap *vap) lvif = VAP_TO_LVIF(vap); nt = &ic->ic_sta; - islocked = IEEE80211_NODE_IS_LOCKED(nt); - MPASS(!islocked); + icislocked = IEEE80211_IS_LOCKED(ic); + MPASS(!icislocked); + ntislocked = IEEE80211_NODE_IS_LOCKED(nt); + MPASS(!ntislocked); #ifdef LINUXKPI_DEBUG_80211 if (linuxkpi_debug_80211 & D80211_TRACE_HW_CRYPTO) - ic_printf(vap->iv_ic, "%s: tid %d vap %p nt %p %slocked " - "lvif nt_unlocked %d\n", __func__, curthread->td_tid, - vap, nt, islocked ? "" : "un", lvif->nt_unlocked); + ic_printf(ic, "%s: tid %d vap %p ic %p %slocked nt %p %slocked " + "lvif ic_unlocked %d nt_unlocked %d\n", __func__, + curthread->td_tid, vap, + ic, icislocked ? "" : "un", nt, ntislocked ? "" : "un", + lvif->ic_unlocked, lvif->nt_unlocked); #endif /* @@ -1491,11 +1502,17 @@ lkpi_iv_key_update_end(struct ieee80211vap *vap) * In case the refcnt gets out of sync locking in net80211 will * quickly barf as well (trying to unlock a lock not held). */ - islocked = refcount_release_if_last(&lvif->nt_unlocked); + icislocked = refcount_release_if_last(&lvif->ic_unlocked); + ntislocked = refcount_release_if_last(&lvif->nt_unlocked); wiphy_unlock(hw->wiphy); - /* This is inconsistent net80211 locking to be fixed one day. */ - if (islocked) + /* + * This is inconsistent net80211 locking to be fixed one day. + * ic before nt to avoid a LOR. + */ + if (icislocked) + IEEE80211_LOCK(ic); + if (ntislocked) IEEE80211_NODE_LOCK(nt); } #endif diff --git a/sys/compat/linuxkpi/common/src/linux_80211.h b/sys/compat/linuxkpi/common/src/linux_80211.h index da377280b1c0..ebf02994af47 100644 --- a/sys/compat/linuxkpi/common/src/linux_80211.h +++ b/sys/compat/linuxkpi/common/src/linux_80211.h @@ -187,6 +187,7 @@ struct lkpi_vif { struct lkpi_sta *lvif_bss; + int ic_unlocked; /* Count of ic unlocks pending (*mo_set_key) */ int nt_unlocked; /* Count of nt unlocks pending (*mo_set_key) */ bool lvif_bss_synched; bool added_to_drv; /* Driver knows; i.e. we called add_interface(). */