From nobody Thu Dec 11 00:46:52 2025 X-Original-To: dev-commits-src-main@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 4dRYnS69rgz6K0J3 for ; Thu, 11 Dec 2025 00:46:52 +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 "R12" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dRYnS5GQFz3d5X for ; Thu, 11 Dec 2025 00:46:52 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765414012; 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=f4WCl3aLzq8fFD73YCWT67z1bQHwliGx+u89FQQ90eA=; b=BffvMiA64qliKOCnQpJ1yO7WJ7tfm2DbYW5Lcq1Eo4BAlL5oevrwyEH4EFGN9vST3JEaYt /uGWK542ZxhLTGAytFEUH6L938kCguxne0KRkvXuCN+C/3uu2KMTBk3sv7PfHL6CGcUc+U Djxqb5nblHOH9/MR/GN96FFrbhZmal6dYPLtImaBOG1R0tyQMIrw1gcLHdKRRYNmc99jMN EvSEF2EQtPq3Rkwh153r8R8NgfbzyQqnXdqQ5pYAdV6N12Jb+Jz2NNIKFAdSpzeE5Sb1zG vnY2IOi2A6uDVBMNKJhiztyPZpuR8dOwH9r+Q7X4m2ZcvElCD+9HUUguu3i0Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765414012; 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=f4WCl3aLzq8fFD73YCWT67z1bQHwliGx+u89FQQ90eA=; b=IuVLeTdkYv4xBZe7Eg4ltTHpJBxdVKXyUETe+YLWiEdUieXObRQ+dnC1TkhBnlAmHKx81t EtmQCMe28iI4uRSNhBGvSUZS3NyXzf4j1Gx0ykOTvLlOksKdYLYamVoHBuGybwDa9+YEm/ zGVmoMrZNWiVusxN5kJtitNJaBbGV0W4DpwW8ThwNXAmfeQi/aoKUjW2PTmZ2w2xt+49pG RqCR0DfkAMrxwESYfHDGPhqXW85i7pAHflMZo+zpR1KP6WWNhHeZA3IJvbwyA8CxtZsT6f XvoV3RvDaD17GOLZZr4RwEEy1XBG739AUUpbKYcacIDWWMKkAmatfowXz2L9ZA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765414012; a=rsa-sha256; cv=none; b=QhimHSjawXQBD5xq9NsxDWyIsMmJgdtSO9o+5gZotfwP/jiawrQqjhNHPjaQVpz8HYIEb4 9BuodnidWmd4nAImEoMRPVl6bdS0p2sVTsSd9I0JEDmeWjWRQuoBKZtxPI6geXcSzjFynt GQcG2q0IuRlDq/YR/+AmqhhPoN+PdAeiE0vjCNfCCZp9f7tVYd5NLfU0wJxfvSML6mFEfT 4l7IH7SVE7lMM5nYblfxwUmma1vmphlqxgaDyQUo7m05N3k3hHc5u5QWLNeTyRjI8saKob FgcFZXHfFB8OxG3lrFKypMZqPbdScvXwBh+7Hb28aI41VRWk99P1fWuLE32txg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4dRYnS4pQlz177k for ; Thu, 11 Dec 2025 00:46:52 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 267f3 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 11 Dec 2025 00:46:52 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Bjoern A. Zeeb Subject: git: 567a097c8ab6 - main - LinuxKPI: 802.11: lock down the "txq_scheduled" tailq List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: 567a097c8ab60d9fcd68a87c3c5ad605fe8715cc Auto-Submitted: auto-generated Date: Thu, 11 Dec 2025 00:46:52 +0000 Message-Id: <693a147c.267f3.1f34bc6e@gitrepo.freebsd.org> The branch main has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=567a097c8ab60d9fcd68a87c3c5ad605fe8715cc commit 567a097c8ab60d9fcd68a87c3c5ad605fe8715cc Author: Bjoern A. Zeeb AuthorDate: 2025-12-10 20:29:23 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-12-11 00:46:15 +0000 LinuxKPI: 802.11: lock down the "txq_scheduled" tailq For consistency rename the "scheduled_txqs" tailq to "txq_scheduled" and add a lock per txq ("txq_scheduled_lock[]"). We use the "_bh" locking as this called from the device driver. This fixes panics due to concurrent access to the tailq, especially in between "first" and "remove" on the out-direction and between "insert" and "elem_init" on the in-direction. This was easily reproducible just running iperf3 at basic rates for a few seconds to minutes with multiple chipsets, not only rtw89. Sponsored by: The FreeBSD Foundation PR: 290636 Reported by: arved, and others before MFC after: 3 days --- sys/compat/linuxkpi/common/src/linux_80211.c | 51 ++++++++++++++++++++++------ sys/compat/linuxkpi/common/src/linux_80211.h | 3 +- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_80211.c b/sys/compat/linuxkpi/common/src/linux_80211.c index 8098d02da1a9..1d510577f00c 100644 --- a/sys/compat/linuxkpi/common/src/linux_80211.c +++ b/sys/compat/linuxkpi/common/src/linux_80211.c @@ -6472,8 +6472,9 @@ linuxkpi_ieee80211_alloc_hw(size_t priv_len, const struct ieee80211_ops *ops) TAILQ_INIT(&lhw->lvif_head); __hw_addr_init(&lhw->mc_list); for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { + spin_lock_init(&lhw->txq_scheduled_lock[ac]); lhw->txq_generation[ac] = 1; - TAILQ_INIT(&lhw->scheduled_txqs[ac]); + TAILQ_INIT(&lhw->txq_scheduled[ac]); } /* Chanctx_conf */ @@ -6507,6 +6508,7 @@ linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) { struct lkpi_hw *lhw; struct mbuf *m; + int ac; lhw = HW_TO_LHW(hw); free(lhw->ic, M_LKPI80211); @@ -6571,6 +6573,9 @@ linuxkpi_ieee80211_iffree(struct ieee80211_hw *hw) lkpi_cleanup_mcast_list_locked(lhw); LKPI_80211_LHW_MC_UNLOCK(lhw); + for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) + spin_lock_destroy(&lhw->txq_scheduled_lock[ac]); + /* Cleanup more of lhw here or in wiphy_free()? */ spin_lock_destroy(&lhw->txq_lock); LKPI_80211_LHW_TXQ_LOCK_DESTROY(lhw); @@ -8664,7 +8669,12 @@ linuxkpi_ieee80211_wake_queue(struct ieee80211_hw *hw, int qnum) spin_unlock_irqrestore(&lhw->txq_lock, flags); } +/* -------------------------------------------------------------------------- */ + /* This is just hardware queues. */ +/* + * Being called from the driver thus use _bh() locking. + */ void linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac) { @@ -8672,10 +8682,16 @@ linuxkpi_ieee80211_txq_schedule_start(struct ieee80211_hw *hw, uint8_t ac) lhw = HW_TO_LHW(hw); - IMPROVE_TXQ("Are there reasons why we wouldn't schedule?"); - IMPROVE_TXQ("LOCKING"); + if (ac >= IEEE80211_NUM_ACS) { + ic_printf(lhw->ic, "%s: ac %u out of bounds.\n", __func__, ac); + return; + } + + spin_lock_bh(&lhw->txq_scheduled_lock[ac]); + IMPROVE("check AIRTIME_FAIRNESS"); if (++lhw->txq_generation[ac] == 0) lhw->txq_generation[ac]++; + spin_unlock_bh(&lhw->txq_scheduled_lock[ac]); } struct ieee80211_txq * @@ -8688,24 +8704,33 @@ linuxkpi_ieee80211_next_txq(struct ieee80211_hw *hw, uint8_t ac) lhw = HW_TO_LHW(hw); txq = NULL; - IMPROVE_TXQ("LOCKING"); + if (ac >= IEEE80211_NUM_ACS) { + ic_printf(lhw->ic, "%s: ac %u out of bounds.\n", __func__, ac); + return (NULL); + } + + spin_lock_bh(&lhw->txq_scheduled_lock[ac]); /* Check that we are scheduled. */ if (lhw->txq_generation[ac] == 0) goto out; - ltxq = TAILQ_FIRST(&lhw->scheduled_txqs[ac]); + ltxq = TAILQ_FIRST(&lhw->txq_scheduled[ac]); if (ltxq == NULL) goto out; if (ltxq->txq_generation == lhw->txq_generation[ac]) goto out; + IMPROVE("check AIRTIME_FAIRNESS"); + + TAILQ_REMOVE(&lhw->txq_scheduled[ac], ltxq, txq_entry); ltxq->txq_generation = lhw->txq_generation[ac]; - TAILQ_REMOVE(&lhw->scheduled_txqs[ac], ltxq, txq_entry); txq = <xq->txq; TAILQ_ELEM_INIT(ltxq, txq_entry); out: + spin_unlock_bh(&lhw->txq_scheduled_lock[ac]); + return (txq); } @@ -8718,8 +8743,6 @@ void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw, ltxq = TXQ_TO_LTXQ(txq); - IMPROVE_TXQ("LOCKING"); - /* Only schedule if work to do or asked to anyway. */ LKPI_80211_LTXQ_LOCK(ltxq); ltxq_empty = skb_queue_empty(<xq->skbq); @@ -8727,20 +8750,26 @@ void linuxkpi_ieee80211_schedule_txq(struct ieee80211_hw *hw, if (!withoutpkts && ltxq_empty) goto out; + lhw = HW_TO_LHW(hw); + spin_lock_bh(&lhw->txq_scheduled_lock[txq->ac]); /* * Make sure we do not double-schedule. We do this by checking tqe_prev, * the previous entry in our tailq. tqe_prev is always valid if this entry * is queued, tqe_next may be NULL if this is the only element in the list. */ if (ltxq->txq_entry.tqe_prev != NULL) - goto out; + goto unlock; + + TAILQ_INSERT_TAIL(&lhw->txq_scheduled[txq->ac], ltxq, txq_entry); +unlock: + spin_unlock_bh(&lhw->txq_scheduled_lock[txq->ac]); - lhw = HW_TO_LHW(hw); - TAILQ_INSERT_TAIL(&lhw->scheduled_txqs[txq->ac], ltxq, txq_entry); out: return; } +/* -------------------------------------------------------------------------- */ + void linuxkpi_ieee80211_handle_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq) diff --git a/sys/compat/linuxkpi/common/src/linux_80211.h b/sys/compat/linuxkpi/common/src/linux_80211.h index 0dfcd7646c34..fcbef46fc6de 100644 --- a/sys/compat/linuxkpi/common/src/linux_80211.h +++ b/sys/compat/linuxkpi/common/src/linux_80211.h @@ -252,7 +252,8 @@ struct lkpi_hw { /* name it mac80211_sc? */ struct mtx txq_mtx; uint32_t txq_generation[IEEE80211_NUM_ACS]; - TAILQ_HEAD(, lkpi_txq) scheduled_txqs[IEEE80211_NUM_ACS]; + spinlock_t txq_scheduled_lock[IEEE80211_NUM_ACS]; + TAILQ_HEAD(, lkpi_txq) txq_scheduled[IEEE80211_NUM_ACS]; spinlock_t txq_lock; /* Deferred RX path. */