From nobody Mon Dec 15 18:10:00 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 4dVSlD6Yfsz6L6Yk for ; Mon, 15 Dec 2025 18:10:00 +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 4dVSlD4MyMz4G3b for ; Mon, 15 Dec 2025 18:10:00 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765822200; 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=/UdWmyGLm69/b+dzIIw69tBlSkA2VcHEho3vxw8BeV8=; b=iKBruOtfnlT3daq4vEODf8c0ovVHe02nx8AuGl96xA5oOe3DEbxBK10gMhfcZ0PMfHyhtq 1jFi594UJJMlzKTPWL++nZ3lixZdt5VM0G1KOPafW+Bwzz9CvLeDXFxpN3ut8iRYM9N9Rk 8MokwZhDy2HhswEoiJj4cwItaZl74rKvPiuZCoBMPL6AInd73zLmCEAtSQdU4cW/NeLl8X 8PcH+ZIhLVCWCq0lZUx7ltETQXpBEn+9HA0z0Wke4cxCdXX+zCTCfzPEazVqUmFKHmhaZ8 YrSraidhcwmKEzX/BkND3h6l6zA9q89PsHCTYWMUoQBfs0HeEqn7Ac5axktAZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1765822200; 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=/UdWmyGLm69/b+dzIIw69tBlSkA2VcHEho3vxw8BeV8=; b=d4lc3q7J3PHImQMY21myAYrYR5Y9IwNHjAD71YdZ9xVRBcmwb68YBtdExQs5xnubDugqjJ YWjUOWtG2xJpD+SrERtbYU3t5AU6OHceblOx5euKhgd77fLJwnujL0zCGYLMdKSGXPJqgx joENnIrk08mn2tZyoGHC7ClIZHNfoWa6hJPW0tIPZjwpAI6ADmMUd10DBOwOFntdWXihST 7ad3qzV3TMcfg29PkuwG8n4tgxxEkjOn8sWre3YmtV6i5cxDvidn06zkidVbiWT1fNamRP lQQOxVtiujp3L0HukBHLgaBTJ/kIHl4AJ8rywAlB6wKZh7goVntCNQIqiWjveg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1765822200; a=rsa-sha256; cv=none; b=mTdSi6fPrusA5eiGv0DrokmJ3ISNvh9psGT7j0Gq4pdRVdhI0t4VhMVoSeyWb2zGMC5gqg pnMGjfJZyvZPm2LaspOR1eseNSULQL5X9QD+9oqyiNhlxXlMpTm9gsr+ZXPJRZEZdMAK0z x5oaMjGcs3Sak9nZfb8LyZmbTnkzrwTfLdK7jQNjYaNujoWh6omPTphfLAqzP+7KKAT8oe EGu/OikBVssPjON3YfUrJmCcqTbpBFRVAECeeAsPIt37rWXWZTh+zEkH3YzM/iO4HCYKQh Rb+gBQ441KwdbifSXoHZ/+YTsPMDKbIygtS0wUQyAjvT6BrVS5J/TOUpLxPaHw== 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 4dVSlD3lQBzVfv for ; Mon, 15 Dec 2025 18:10:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 25512 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 15 Dec 2025 18:10:00 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Bjoern A. Zeeb Subject: git: 2e1156f75836 - stable/15 - LinuxKPI: 802.11: lock down the "txq_scheduled" tailq 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/stable/15 X-Git-Reftype: branch X-Git-Commit: 2e1156f75836a0e5a4026e13d72b54f272e705cb Auto-Submitted: auto-generated Date: Mon, 15 Dec 2025 18:10:00 +0000 Message-Id: <69404ef8.25512.23b9141@gitrepo.freebsd.org> The branch stable/15 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=2e1156f75836a0e5a4026e13d72b54f272e705cb commit 2e1156f75836a0e5a4026e13d72b54f272e705cb Author: Bjoern A. Zeeb AuthorDate: 2025-12-10 20:29:23 +0000 Commit: Bjoern A. Zeeb CommitDate: 2025-12-15 18:09:22 +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 (cherry picked from commit 567a097c8ab60d9fcd68a87c3c5ad605fe8715cc) --- 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. */