From nobody Mon Nov 25 17:48:01 2024 Received: from e2i340.smtp2go.com (e2i340.smtp2go.com [103.2.141.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45B621DF754 for ; Fri, 22 Nov 2024 16:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.2.141.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732294191; cv=none; b=n/cnCCLdorSv9YcQc+eMSkp4tPg3+ZBjoUEneMp9WzshqM4zEx183u3PIl2w2QtVG6vIwYTb1HdtOw/6+li3/xkj2hexagM6URFGbzH2QtMa5q0NYVoJNzOsf+htjqAk2BcykBUr8ZDohMvHGYVMmQ9ZcMTvA9uwo+283lZ+vfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732294191; c=relaxed/simple; bh=xBp48a7NJAmuRhfuvTg1UfVngg6KTk5DZh5riLJL8NU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZbfXqnoPYcV2Hd9+SJHj6hT0Kx/k90/tWqBuFZjxakT4Ingh1EGW3yraynT5ccRbpymAZ7tMT3+70++/kypSbMs+nSNQza/y1nLJ9JIb4duMX4X7Td5smfVwaYjPMTiquJOxyzJ79HBJi8YcZ1TvM/ydYbGmfsrSuuAftKBRKx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=triplefau.lt; spf=pass smtp.mailfrom=em510616.triplefau.lt; dkim=fail (0-bit key) header.d=smtpservice.net header.i=@smtpservice.net header.b=to896Mtm reason="unknown key version"; dkim=pass (2048-bit key) header.d=triplefau.lt header.i=@triplefau.lt header.b=LVuCUyod; arc=none smtp.client-ip=103.2.141.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=triplefau.lt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=em510616.triplefau.lt Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="unknown key version" (0-bit key) header.d=smtpservice.net header.i=@smtpservice.net header.b="to896Mtm"; dkim=pass (2048-bit key) header.d=triplefau.lt header.i=@triplefau.lt header.b="LVuCUyod" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1732295089; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=H6t+0VQi/hPriWRBUTFUcC2YjAKrLFxImgas1F5cAQM=; b=to896MtmQ+pJ9nm+S3QVMuKru3 R1EmpOFmSnzUR/PsQdLx68DPsb/fbf/nombIbT1Nsy2VH+t8q61FcmL/BSDTB/jD+/sZGieDsxdZ9 iNbf0PCxVqFiIvCwmdRQWGFw0L/sJyxrgePckIurYuDLRVmCbFMJK3MyT1y29vFRwsWS33dHqWavu JevruV0TW0qp4UNGGc4EoWQJmqv7OwqBrmkpWu5PP2J2xsGP/Z80NIQbiv+DpmqgQISkZsHQigc+S +AXfGFskZFigMUkCXwOgsI80BQ9SAzz8bVR/sACV4V6lmjw6FEFSCYPPH7ZhZ9mZjok4jhiIK54rD aJW2+x8w==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1732294189; h=from : subject : to : message-id : date; bh=H6t+0VQi/hPriWRBUTFUcC2YjAKrLFxImgas1F5cAQM=; b=LVuCUyodJzqZwfe2S2KW8+ebcaUktGNraNZTDcrLwrF8RmTuni7nJivKqJqm1DjXY9w8y zFGydabQ4E6A2nRQNjqdQ9O1iNn0sGpVzdglFIBhoCHAagPPUDvhSxwmwY/qR2edBhgoHm1 BQbb9xoHQVXCgafNHuX1ph0uPZ607SxSl5SksZe4uhUhsXxQPDgcbKne4QMegv9b6m19MBn x/6NC9bCsa3cNQXRh5/+A1wQMe0Iyh8mF9AESXGmWnH2FfWwDhwymEpb6GHCgZhr+TdzyGw +MQtAohQOvVXuOxMoqidak1toST2NCEWANlQB8uzN3xv4T7sWYizZ67W8oOA== Received: from [10.176.58.103] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1tEWqT-TRjyMk-Jd; Fri, 22 Nov 2024 16:49:25 +0000 Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1tEWqT-4o5NDgrusvn-pkjQ; Fri, 22 Nov 2024 16:49:25 +0000 From: Remi Pommarel To: ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kalle Valo , Jeff Johnson , Cedric Veilleux , Vasanthakumar Thiagarajan , Remi Pommarel Subject: [RESEND PATCH v3 1/2] wifi: ath10k: Implement ieee80211 flush_sta callback Date: Fri, 22 Nov 2024 17:48:01 +0100 Message-Id: <17d26d6a3e80ff03939ee7935fdc07f979b61a4f.1732293922.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Smtpcorp-Track: JPbUiC19hIl3.XY1kM4dnZ8N3.IVKCiAXI7uT Feedback-ID: 510616m:510616apGKSTK:510616sqVrJeNwUF X-Report-Abuse: Please forward a copy of this message, including all headers, to Content-Type: text/plain; charset="utf-8" When a STA reassociates, mac80211's _sta_info_move_state() waits for all pending frame to be flushed before removing the key (so that no frame get sent unencrypted after key removable [0]). When a driver does not implement the flush_sta callback, ieee80211_flush_queues() is called instead which effectively stops the whole queue until it is completely drained. The ath10k driver configure all STAs of one vdev to share the same queue. So when flushing one STA this is the whole vdev queue that is blocked until completely drained causing Tx to other STA to also stall this whole time. One easy way to reproduce the issue is to connect two STAs (STA0 and STA1) to an ath10k AP. While Generating a bunch of traffic from AP to STA0 (e.g. fping -l -p 20 ) disconnect STA0 from AP without clean disassociation (e.g. remove power, reboot -f). Then as soon as STA0 is effectively disconnected from AP (either after inactivity timeout or forced with iw dev AP station del STA0), its queues get flushed using ieee80211_flush_queues(). This causes STA1 to suffer a connectivity stall for about 5 seconds (see ATH10K_FLUSH_TIMEOUT_HZ). Implement a flush_sta callback in ath10k to wait only for a specific STA pending frames to be drained (without stopping the whole HW queue) to fix that. [0]: commit 0b75a1b1e42e ("wifi: mac80211: flush queues on STA removal") Reported-by: Cedric Veilleux Closes: https://lore.kernel.org/all/CA+Xfe4FjUmzM5mvPxGbpJsF3SvSdE5_wgxvgFJ= 0bsdrKODVXCQ@mail.gmail.com/ Signed-off-by: Remi Pommarel --- drivers/net/wireless/ath/ath10k/core.h | 2 ++ drivers/net/wireless/ath/ath10k/htt.h | 4 +++ drivers/net/wireless/ath/ath10k/htt_tx.c | 31 ++++++++++++++++++ drivers/net/wireless/ath/ath10k/mac.c | 40 +++++++++++++++++++++++- drivers/net/wireless/ath/ath10k/txrx.c | 9 ++++-- 5 files changed, 82 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/core.h b/drivers/net/wireless/= ath/ath10k/core.h index 446dca74f06a..4ec2faa055c0 100644 --- a/drivers/net/wireless/ath/ath10k/core.h +++ b/drivers/net/wireless/ath/ath10k/core.h @@ -558,6 +558,8 @@ struct ath10k_sta { u8 rate_ctrl[ATH10K_TID_MAX]; u32 rate_code[ATH10K_TID_MAX]; int rtscts[ATH10K_TID_MAX]; + wait_queue_head_t empty_tx_wq; + atomic_t num_fw_queued; }; =20 #define ATH10K_VDEV_SETUP_TIMEOUT_HZ (5 * HZ) diff --git a/drivers/net/wireless/ath/ath10k/htt.h b/drivers/net/wireless/a= th/ath10k/htt.h index 603f6de62b0a..d150f9330941 100644 --- a/drivers/net/wireless/ath/ath10k/htt.h +++ b/drivers/net/wireless/ath/ath10k/htt.h @@ -2452,6 +2452,10 @@ int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt= ); void ath10k_htt_tx_mgmt_dec_pending(struct ath10k_htt *htt); int ath10k_htt_tx_mgmt_inc_pending(struct ath10k_htt *htt, bool is_mgmt, bool is_presp); +void ath10k_htt_tx_sta_inc_pending(struct ath10k_htt *htt, + struct ieee80211_sta *sta); +void ath10k_htt_tx_sta_dec_pending(struct ath10k_htt *htt, + struct ieee80211_sta *sta); =20 int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt, struct sk_buff *sk= b); void ath10k_htt_tx_free_msdu_id(struct ath10k_htt *htt, u16 msdu_id); diff --git a/drivers/net/wireless/ath/ath10k/htt_tx.c b/drivers/net/wireles= s/ath/ath10k/htt_tx.c index 9725feecefd6..211752bd0f65 100644 --- a/drivers/net/wireless/ath/ath10k/htt_tx.c +++ b/drivers/net/wireless/ath/ath10k/htt_tx.c @@ -195,6 +195,37 @@ void ath10k_htt_tx_mgmt_dec_pending(struct ath10k_htt = *htt) htt->num_pending_mgmt_tx--; } =20 +void ath10k_htt_tx_sta_inc_pending(struct ath10k_htt *htt, + struct ieee80211_sta *sta) +{ + struct ath10k_sta *arsta; + + if (!sta) + return; + + arsta =3D (struct ath10k_sta *)sta->drv_priv; + + atomic_inc(&arsta->num_fw_queued); +} + +void ath10k_htt_tx_sta_dec_pending(struct ath10k_htt *htt, + struct ieee80211_sta *sta) +{ + struct ath10k_sta *arsta; + int v; + + if (!sta) + return; + + arsta =3D (struct ath10k_sta *)sta->drv_priv; + + v =3D atomic_dec_if_positive(&arsta->num_fw_queued); + if (v < 0) + WARN_ON_ONCE(1); + if (v =3D=3D 0) + wake_up(&arsta->empty_tx_wq); +} + int ath10k_htt_tx_alloc_msdu_id(struct ath10k_htt *htt, struct sk_buff *sk= b) { struct ath10k *ar =3D htt->ar; diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/a= th/ath10k/mac.c index c61b95a928da..8b8d4f24e5fb 100644 --- a/drivers/net/wireless/ath/ath10k/mac.c +++ b/drivers/net/wireless/ath/ath10k/mac.c @@ -4423,6 +4423,8 @@ int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw, spin_unlock_bh(&ar->htt.tx_lock); } =20 + ath10k_htt_tx_sta_inc_pending(&ar->htt, sta); + ret =3D ath10k_mac_tx(ar, vif, txmode, txpath, skb, false); if (unlikely(ret)) { ath10k_warn(ar, "failed to push frame: %d\n", ret); @@ -4432,6 +4434,7 @@ int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw, if (is_mgmt) ath10k_htt_tx_mgmt_dec_pending(htt); spin_unlock_bh(&ar->htt.tx_lock); + ath10k_htt_tx_sta_dec_pending(&ar->htt, sta); =20 return ret; } @@ -7481,7 +7484,7 @@ static int ath10k_sta_state(struct ieee80211_hw *hw, arsta->peer_ps_state =3D WMI_PEER_PS_STATE_DISABLED; INIT_WORK(&arsta->update_wk, ath10k_sta_rc_update_wk); INIT_WORK(&arsta->tid_config_wk, ath10k_sta_tid_cfg_wk); - + init_waitqueue_head(&arsta->empty_tx_wq); for (i =3D 0; i < ARRAY_SIZE(sta->txq); i++) ath10k_mac_txq_init(sta->txq[i]); } @@ -8112,6 +8115,40 @@ static void ath10k_flush(struct ieee80211_hw *hw, st= ruct ieee80211_vif *vif, mutex_unlock(&ar->conf_mutex); } =20 +static void ath10k_flush_sta(struct ieee80211_hw *hw, struct ieee80211_vif= *vif, + struct ieee80211_sta *sta) +{ + struct ath10k_sta *arsta =3D (struct ath10k_sta *)sta->drv_priv; + struct ath10k *ar =3D hw->priv; + bool skip; + long time_left; + + /* TODO do we need drop implemented here ? */ + + mutex_lock(&ar->conf_mutex); + + if (ar->state =3D=3D ATH10K_STATE_WEDGED) + goto out; + + time_left =3D wait_event_timeout(arsta->empty_tx_wq, ({ + bool empty; + + empty =3D atomic_read(&arsta->num_fw_queued) =3D=3D 0; + + skip =3D (ar->state =3D=3D ATH10K_STATE_WEDGED) || + test_bit(ATH10K_FLAG_CRASH_FLUSH, + &ar->dev_flags); + + (empty || skip); + }), ATH10K_FLUSH_TIMEOUT_HZ); + + if (time_left =3D=3D 0 || skip) + ath10k_warn(ar, "failed to flush sta txq (sta %pM skip %i ar-state %i): = %ld\n", + sta->addr, skip, ar->state, time_left); +out: + mutex_unlock(&ar->conf_mutex); +} + /* TODO: Implement this function properly * For now it is needed to reply to Probe Requests in IBSS mode. * Probably we need this information from FW. @@ -9459,6 +9496,7 @@ static const struct ieee80211_ops ath10k_ops =3D { .set_rts_threshold =3D ath10k_set_rts_threshold, .set_frag_threshold =3D ath10k_mac_op_set_frag_threshold, .flush =3D ath10k_flush, + .flush_sta =3D ath10k_flush_sta, .tx_last_beacon =3D ath10k_tx_last_beacon, .set_antenna =3D ath10k_set_antenna, .get_antenna =3D ath10k_get_antenna, diff --git a/drivers/net/wireless/ath/ath10k/txrx.c b/drivers/net/wireless/= ath/ath10k/txrx.c index da3bc35e41aa..5b6750ef7d19 100644 --- a/drivers/net/wireless/ath/ath10k/txrx.c +++ b/drivers/net/wireless/ath/ath10k/txrx.c @@ -86,9 +86,12 @@ int ath10k_txrx_tx_unref(struct ath10k_htt *htt, spin_unlock_bh(&htt->tx_lock); =20 rcu_read_lock(); - if (txq && txq->sta && skb_cb->airtime_est) - ieee80211_sta_register_airtime(txq->sta, txq->tid, - skb_cb->airtime_est, 0); + if (txq && txq->sta) { + if (skb_cb->airtime_est) + ieee80211_sta_register_airtime(txq->sta, txq->tid, + skb_cb->airtime_est, 0); + ath10k_htt_tx_sta_dec_pending(htt, txq->sta); + } rcu_read_unlock(); =20 if (ar->bus_param.dev_type !=3D ATH10K_DEV_TYPE_HL) --=20 2.40.0 From nobody Mon Nov 25 17:48:01 2024 Received: from e2i340.smtp2go.com (e2i340.smtp2go.com [103.2.141.84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31B995D477 for ; Fri, 22 Nov 2024 16:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.2.141.84 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732294192; cv=none; b=VqIeHmubm4UslZ3ALdV3K45znL26gaun3gjYX9VzDv3Tj+xVp3dRfw4t6AH8UJJx/PzJtx4OKLchLsB6YP1eSET3/G2G4VACZIFyJN7tH7wtMpD5gumxpBfTn/HhDenTeJCcdS9Ehxt8iZDRFQwkdWu6Rfv+Qxe3ao/+7nei1tk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732294192; c=relaxed/simple; bh=Zvcu5IVZTFMSBYHrm2FKiwsj+A2VsshdC2zeg1vCgzw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=s3WT6GwBEBT+FD4clJhcj94f/SYJz9jYbQ+oV8Ee/atEIf7Bk36Ol/6LxA4CDkvRUXFCl6fSPwgaMb+oQPBZxhva2ULrj/5H40qj9ZU08J2WvhQprn3LPWhXQzyMdLn0pCfMFKmLwwz2HIfX60Q8h+VGR/6z5WW5/GNwB7Y2mf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=triplefau.lt; spf=pass smtp.mailfrom=em510616.triplefau.lt; dkim=fail (0-bit key) header.d=smtpservice.net header.i=@smtpservice.net header.b=1zNRKMxP reason="unknown key version"; dkim=pass (2048-bit key) header.d=triplefau.lt header.i=@triplefau.lt header.b=lCIJQeyS; arc=none smtp.client-ip=103.2.141.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=triplefau.lt Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=em510616.triplefau.lt Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="unknown key version" (0-bit key) header.d=smtpservice.net header.i=@smtpservice.net header.b="1zNRKMxP"; dkim=pass (2048-bit key) header.d=triplefau.lt header.i=@triplefau.lt header.b="lCIJQeyS" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=smtpservice.net; s=maxzs0.a1-4.dyn; x=1732295090; h=Feedback-ID: X-Smtpcorp-Track:Message-Id:Date:Subject:To:From:Reply-To:Sender: List-Unsubscribe:List-Unsubscribe-Post; bh=VU7yyzm4vBwdip1dBLsGRd5MJn1hCw2dZHCEfwLlKhE=; b=1zNRKMxPL/yp3m2QjB3uwtBbdn yfvZrWCMTflhAB6p/8cD6KjutEruoFVtlHx8VhDPcWtoNjbmxPBSsWaWuz+z7cCPLVu/YkL50hXA7 hwVXDOg/LX5A5o7okl95KWC1Gnu6a8Up7o+80Av05pGh/qEsz3l8DDC7Max1PUEIkvG8nrqI6QesA xhd7662wWe/e8jPy6EVxjmxHFZmvUGA2EZexfKoe9BpUM7JO1efDkFlMz8k1M/zf2WFEgAeRMi7iE 9Azn/+qLPg3vKC4djKb9DFWfNT/BTPZIFivxKXg+H+DPZtIMQlstG0FqpylKl3anjYPfiWNpazIce tKekwKAw==; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=triplefau.lt; i=@triplefau.lt; q=dns/txt; s=s510616; t=1732294190; h=from : subject : to : message-id : date; bh=VU7yyzm4vBwdip1dBLsGRd5MJn1hCw2dZHCEfwLlKhE=; b=lCIJQeySGkNQoz+Scn8WDi58T0APTwZwJiSM6oSIMDNcH+sHeq+tu9eTNZx8gUt+QWst1 8lnU4ovAqL17vEoH3qEtx8hdYZ2bL0rx0kHF6vNXSzDoEYynlbOmqVm+cznxSMN8JcfTyVT dUjdxQEoOVelSQ/RsMAb9lGOv9EHODojZNP/FO7A7z9bB6QvS/pHliRV7P5BDZIy04eC6H4 tAKV0oqT1FEmOsm2ULwoxTJ96D+cHuRM+nqL8WUIkfFL/e8e/I/CnqImVabZH7i3azLHKUc /Ad8hWHfXdYxwD6l6zc9L6VIuz5AWbsySgDPEOEjAU9BZovBUEF7xSF4WmMA== Received: from [10.139.162.187] (helo=SmtpCorp) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.94.2-S2G) (envelope-from ) id 1tEWqU-TRjyNW-1X; Fri, 22 Nov 2024 16:49:26 +0000 Received: from [10.12.239.196] (helo=localhost) by smtpcorp.com with esmtpsa (TLS1.3:ECDHE_SECP256R1__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.97.1-S2G) (envelope-from ) id 1tEWqT-4o5NDgrgcgU-nS39; Fri, 22 Nov 2024 16:49:25 +0000 From: Remi Pommarel To: ath10k@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kalle Valo , Jeff Johnson , Cedric Veilleux , Vasanthakumar Thiagarajan , Remi Pommarel Subject: [RESEND PATCH v3 2/2] wifi: ath10k: Flush only requested txq in ath10k_flush() Date: Fri, 22 Nov 2024 17:48:02 +0100 Message-Id: <01d859e8e574a1f5d0b916333fe0b5cda859af9b.1732293922.git.repk@triplefau.lt> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Smtpcorp-Track: fSZwjiXovEku.p9B27uDpdu1F.ifVexARPOJW Feedback-ID: 510616m:510616apGKSTK:510616sEnxp3C9dm X-Report-Abuse: Please forward a copy of this message, including all headers, to Content-Type: text/plain; charset="utf-8" The ieee80211 flush callback can be called to flush only part of all hw queues. The ath10k's flush callback implementation (i.e. ath10k_flush()) was waiting for all pending frames of all queues to be flushed ignoring the queue parameter. Because only the queues to be flushed are stopped by mac80211, skb can still be queued to other queues meanwhile. Thus ath10k_flush() could fail (and wait 5sec holding ar->conf lock) even if the requested queues are flushed correctly. A way to reproduce the issue is to use two different APs because each vdev has its own hw queue in ath10k. Connect STA0 to AP0 and STA1 to AP1. Then generate traffic from AP0 to STA0 and kill STA0 without clean disassociation frame (e.g. unplug power cable, reboot -f, ...). Now if we were to flush AP1's queue, ath10k_flush() would fail (and effectively block 5 seconds with ar->conf or even wiphy's lock held) with the following warning: ath10k_pci 0000:01:00.0: failed to flush transmit queue (skip 0 ar-state 2= ): 0 Wait only for pending frames of the requested queues to be flushed in ath10k_flush() to avoid that long blocking. Reported-by: Cedric Veilleux Closes: https://lore.kernel.org/all/CA+Xfe4FjUmzM5mvPxGbpJsF3SvSdE5_wgxvgFJ= 0bsdrKODVXCQ@mail.gmail.com/ Signed-off-by: Remi Pommarel --- drivers/net/wireless/ath/ath10k/htt.h | 7 +++-- drivers/net/wireless/ath/ath10k/htt_tx.c | 18 ++++++++++-- drivers/net/wireless/ath/ath10k/mac.c | 35 ++++++++++++++++-------- drivers/net/wireless/ath/ath10k/txrx.c | 2 +- 4 files changed, 45 insertions(+), 17 deletions(-) diff --git a/drivers/net/wireless/ath/ath10k/htt.h b/drivers/net/wireless/a= th/ath10k/htt.h index d150f9330941..ca8bf3b6766d 100644 --- a/drivers/net/wireless/ath/ath10k/htt.h +++ b/drivers/net/wireless/ath/ath10k/htt.h @@ -1870,6 +1870,7 @@ struct ath10k_htt { spinlock_t tx_lock; int max_num_pending_tx; int num_pending_tx; + int num_pending_per_queue[IEEE80211_MAX_QUEUES]; int num_pending_mgmt_tx; struct idr pending_tx; wait_queue_head_t empty_tx_wq; @@ -2447,8 +2448,10 @@ void ath10k_htt_tx_txq_update(struct ieee80211_hw *h= w, void ath10k_htt_tx_txq_recalc(struct ieee80211_hw *hw, struct ieee80211_txq *txq); void ath10k_htt_tx_txq_sync(struct ath10k *ar); -void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt); -int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt); +void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt, + struct ieee80211_txq *txq); +int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt, + struct ieee80211_txq *txq); void ath10k_htt_tx_mgmt_dec_pending(struct ath10k_htt *htt); int ath10k_htt_tx_mgmt_inc_pending(struct ath10k_htt *htt, bool is_mgmt, bool is_presp); diff --git a/drivers/net/wireless/ath/ath10k/htt_tx.c b/drivers/net/wireles= s/ath/ath10k/htt_tx.c index 211752bd0f65..ef5a992e8cce 100644 --- a/drivers/net/wireless/ath/ath10k/htt_tx.c +++ b/drivers/net/wireless/ath/ath10k/htt_tx.c @@ -140,19 +140,26 @@ void ath10k_htt_tx_txq_update(struct ieee80211_hw *hw, spin_unlock_bh(&ar->htt.tx_lock); } =20 -void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt) +void ath10k_htt_tx_dec_pending(struct ath10k_htt *htt, + struct ieee80211_txq *txq) { + int qnr =3D -1; + lockdep_assert_held(&htt->tx_lock); =20 htt->num_pending_tx--; if (htt->num_pending_tx =3D=3D htt->max_num_pending_tx - 1) ath10k_mac_tx_unlock(htt->ar, ATH10K_TX_PAUSE_Q_FULL); =20 - if (htt->num_pending_tx =3D=3D 0) + if (txq) + qnr =3D --htt->num_pending_per_queue[txq->vif->hw_queue[txq->ac]]; + + if (htt->num_pending_tx =3D=3D 0 || qnr =3D=3D 0) wake_up(&htt->empty_tx_wq); } =20 -int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt) +int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt, + struct ieee80211_txq *txq) { lockdep_assert_held(&htt->tx_lock); =20 @@ -163,6 +170,11 @@ int ath10k_htt_tx_inc_pending(struct ath10k_htt *htt) if (htt->num_pending_tx =3D=3D htt->max_num_pending_tx) ath10k_mac_tx_lock(htt->ar, ATH10K_TX_PAUSE_Q_FULL); =20 + if (!txq) + return 0; + + htt->num_pending_per_queue[txq->vif->hw_queue[txq->ac]]++; + return 0; } =20 diff --git a/drivers/net/wireless/ath/ath10k/mac.c b/drivers/net/wireless/a= th/ath10k/mac.c index 8b8d4f24e5fb..7c5f95f2858f 100644 --- a/drivers/net/wireless/ath/ath10k/mac.c +++ b/drivers/net/wireless/ath/ath10k/mac.c @@ -4385,7 +4385,7 @@ int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw, u16 airtime; =20 spin_lock_bh(&ar->htt.tx_lock); - ret =3D ath10k_htt_tx_inc_pending(htt); + ret =3D ath10k_htt_tx_inc_pending(htt, txq); spin_unlock_bh(&ar->htt.tx_lock); =20 if (ret) @@ -4394,7 +4394,7 @@ int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw, skb =3D ieee80211_tx_dequeue_ni(hw, txq); if (!skb) { spin_lock_bh(&ar->htt.tx_lock); - ath10k_htt_tx_dec_pending(htt); + ath10k_htt_tx_dec_pending(htt, txq); spin_unlock_bh(&ar->htt.tx_lock); =20 return -ENOENT; @@ -4416,7 +4416,7 @@ int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw, ret =3D ath10k_htt_tx_mgmt_inc_pending(htt, is_mgmt, is_presp); =20 if (ret) { - ath10k_htt_tx_dec_pending(htt); + ath10k_htt_tx_dec_pending(htt, txq); spin_unlock_bh(&ar->htt.tx_lock); return ret; } @@ -4430,7 +4430,7 @@ int ath10k_mac_tx_push_txq(struct ieee80211_hw *hw, ath10k_warn(ar, "failed to push frame: %d\n", ret); =20 spin_lock_bh(&ar->htt.tx_lock); - ath10k_htt_tx_dec_pending(htt); + ath10k_htt_tx_dec_pending(htt, txq); if (is_mgmt) ath10k_htt_tx_mgmt_dec_pending(htt); spin_unlock_bh(&ar->htt.tx_lock); @@ -4693,7 +4693,7 @@ static void ath10k_mac_op_tx(struct ieee80211_hw *hw, is_presp =3D ieee80211_is_probe_resp(hdr->frame_control); } =20 - ret =3D ath10k_htt_tx_inc_pending(htt); + ret =3D ath10k_htt_tx_inc_pending(htt, txq); if (ret) { ath10k_warn(ar, "failed to increase tx pending count: %d, dropping\n", ret); @@ -4706,7 +4706,7 @@ static void ath10k_mac_op_tx(struct ieee80211_hw *hw, if (ret) { ath10k_dbg(ar, ATH10K_DBG_MAC, "failed to increase tx mgmt pending coun= t: %d, dropping\n", ret); - ath10k_htt_tx_dec_pending(htt); + ath10k_htt_tx_dec_pending(htt, txq); spin_unlock_bh(&ar->htt.tx_lock); ieee80211_free_txskb(ar->hw, skb); return; @@ -4719,7 +4719,7 @@ static void ath10k_mac_op_tx(struct ieee80211_hw *hw, ath10k_warn(ar, "failed to transmit frame: %d\n", ret); if (is_htt) { spin_lock_bh(&ar->htt.tx_lock); - ath10k_htt_tx_dec_pending(htt); + ath10k_htt_tx_dec_pending(htt, txq); if (is_mgmt) ath10k_htt_tx_mgmt_dec_pending(htt); spin_unlock_bh(&ar->htt.tx_lock); @@ -8059,10 +8059,12 @@ static int ath10k_mac_op_set_frag_threshold(struct = ieee80211_hw *hw, u32 value) return -EOPNOTSUPP; } =20 -void ath10k_mac_wait_tx_complete(struct ath10k *ar) +static void _ath10k_mac_wait_tx_complete(struct ath10k *ar, + unsigned long queues) { bool skip; long time_left; + unsigned int q; =20 /* mac80211 doesn't care if we really xmit queued frames or not * we'll collect those frames either way if we stop/delete vdevs @@ -8072,10 +8074,14 @@ void ath10k_mac_wait_tx_complete(struct ath10k *ar) return; =20 time_left =3D wait_event_timeout(ar->htt.empty_tx_wq, ({ - bool empty; + bool empty =3D true; =20 spin_lock_bh(&ar->htt.tx_lock); - empty =3D (ar->htt.num_pending_tx =3D=3D 0); + for_each_set_bit(q, &queues, ar->hw->queues) { + empty =3D (ar->htt.num_pending_per_queue[q] =3D=3D 0); + if (!empty) + break; + } spin_unlock_bh(&ar->htt.tx_lock); =20 skip =3D (ar->state =3D=3D ATH10K_STATE_WEDGED) || @@ -8090,6 +8096,13 @@ void ath10k_mac_wait_tx_complete(struct ath10k *ar) skip, ar->state, time_left); } =20 +void ath10k_mac_wait_tx_complete(struct ath10k *ar) +{ + unsigned int queues =3D GENMASK(ar->hw->queues - 1, 0); + + _ath10k_mac_wait_tx_complete(ar, queues); +} + static void ath10k_flush(struct ieee80211_hw *hw, struct ieee80211_vif *vi= f, u32 queues, bool drop) { @@ -8111,7 +8124,7 @@ static void ath10k_flush(struct ieee80211_hw *hw, str= uct ieee80211_vif *vif, } =20 mutex_lock(&ar->conf_mutex); - ath10k_mac_wait_tx_complete(ar); + _ath10k_mac_wait_tx_complete(ar, queues); mutex_unlock(&ar->conf_mutex); } =20 diff --git a/drivers/net/wireless/ath/ath10k/txrx.c b/drivers/net/wireless/= ath/ath10k/txrx.c index 5b6750ef7d19..b848962fc8fb 100644 --- a/drivers/net/wireless/ath/ath10k/txrx.c +++ b/drivers/net/wireless/ath/ath10k/txrx.c @@ -82,7 +82,7 @@ int ath10k_txrx_tx_unref(struct ath10k_htt *htt, =20 flags =3D skb_cb->flags; ath10k_htt_tx_free_msdu_id(htt, tx_done->msdu_id); - ath10k_htt_tx_dec_pending(htt); + ath10k_htt_tx_dec_pending(htt, txq); spin_unlock_bh(&htt->tx_lock); =20 rcu_read_lock(); --=20 2.40.0