ath9k: do not link receive buffers during flush
PATCH v2 2/5 ath9k: fix double-free bug on beacon generate failure
In reply to Felix FietkauWhen the next beacon is sent, the ath_buf from the previous run is reused. If getting a new beacon from mac80211 fails, bf->bf_mpdu is not reset, yet the skb is freed, leading to a double-free on the next beacon tx attempt, resulting in a system crash.
--- drivers/net/wireless/ath/ath9k/beacon.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/ath/ath9k/beacon.c +1 -0
@@ -147,6 +147,7 @@ static struct ath_buf *ath9k_beacon_generate(struct ieee80211_hw *hw, skb->len, DMA_TO_DEVICE);dev_kfree_skb_any (skb); bf->bf_buf_addr =0 ; + bf->bf_mpdu =NULL ; } skb =ieee80211_beacon_get (hw, vif);
Signature · 1 line
1.8.0.2
PATCH v2 5/5 ath9k: fix rx flush handling
In reply to Felix FietkauRight now the rx flush is not doing anything useful on AR9003+, as it only works if the buffers in the rx FIFO have not been purged yet, as is done by ath_stoprecv.
To fix this, always call ath_flushrecv from within ath_stoprecv before the FIFO is emptied, but still after the hw receive path has been stopped.
This ensures that frames received (and ACKed by the hardware) shortly before a reset will be seen by the software, which should improve A-MPDU session stability.
--- drivers/net/wireless/ath/ath9k/ath9k.h | 1 - drivers/net/wireless/ath/ath9k/main.c | 16 +++------------- drivers/net/wireless/ath/ath9k/recv.c | 16 +++++++++------- 3 files changed, 12 insertions(+), 21 deletions(-)
drivers/net/wireless/ath/ath9k/ath9k.h +0 -1
@@ -324,7 +324,6 @@ struct ath_rx {int ath_startrecv (struct ath_softc *sc);bool ath_stoprecv (struct ath_softc *sc); -void ath_flushrecv (struct ath_softc *sc);u32 ath_calcrxfilter (struct ath_softc *sc);int ath_rx_init (struct ath_softc *sc,int nbufs);void ath_rx_cleanup (struct ath_softc *sc);
drivers/net/wireless/ath/ath9k/main.c +3 -13
@@ -182,7 +182,7 @@ static void ath_restart_work(struct ath_softc *sc)ath_start_ani (sc); } -static bool ath_prepare_reset (struct ath_softc *sc,bool retry_tx,bool flush) +static bool ath_prepare_reset (struct ath_softc *sc,bool retry_tx) {struct ath_hw *ah = sc->sc_ah;bool ret = true;
@@ -204,14 +204,6 @@ static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)if (!ath_drain_all_txq (sc, retry_tx)) ret = false; -if (!flush) { -if (ah->caps.hw_caps &ATH9K_HW_CAP_EDMA ) -ath_rx_tasklet (sc,1 , true); -ath_rx_tasklet (sc,1 , false); - }else { -ath_flushrecv (sc); - } -tasklet_enable (&sc->intr_tq);return ret;
@@ -266,7 +258,6 @@ static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,struct ath_common *common =ath9k_hw_common (ah);struct ath9k_hw_cal_data *caldata =NULL ;bool fastcc = true; -bool flush = false;int r;__ath_cancel_work (sc);
@@ -280,11 +271,10 @@ static int ath_reset_internal(struct ath_softc *sc, struct ath9k_channel *hchan,if (!hchan) { fastcc = false; - flush = true; hchan = ah->curchan; } -if (!ath_prepare_reset (sc, retry_tx, flush)) +if (!ath_prepare_reset (sc, retry_tx)) fastcc = false; ath_dbg(common, CONFIG, "Reset to %u MHz, HT40: %d fastcc: %d\n",
@@ -808,7 +798,7 @@ static void ath9k_stop(struct ieee80211_hw *hw)ath9k_hw_cfg_gpio_input (ah, ah->led_pin); } -ath_prepare_reset (sc, false, true); +ath_prepare_reset (sc, false);if (sc->rx.frag) {dev_kfree_skb_any (sc->rx.frag);
drivers/net/wireless/ath/ath9k/recv.c +9 -7
@@ -463,6 +463,13 @@ start_recv:return 0 ; } +static void ath_flushrecv (struct ath_softc *sc) +{ +if (sc->sc_ah->caps.hw_caps &ATH9K_HW_CAP_EDMA ) +ath_rx_tasklet (sc,1 , true); +ath_rx_tasklet (sc,1 , false); +} +bool ath_stoprecv (struct ath_softc *sc) {struct ath_hw *ah = sc->sc_ah;
@@ -473,6 +480,8 @@ bool ath_stoprecv(struct ath_softc *sc)ath9k_hw_setrxfilter (ah,0 ); stopped =ath9k_hw_stopdmarecv (ah, &reset); +ath_flushrecv (sc); +if (sc->sc_ah->caps.hw_caps &ATH9K_HW_CAP_EDMA )ath_edma_stop_recv (sc);else
@@ -489,13 +498,6 @@ bool ath_stoprecv(struct ath_softc *sc)return stopped && !reset; } -void ath_flushrecv (struct ath_softc *sc) -{ -if (sc->sc_ah->caps.hw_caps &ATH9K_HW_CAP_EDMA ) -ath_rx_tasklet (sc,1 , true); -ath_rx_tasklet (sc,1 , false); -} -static bool ath_beacon_dtim_pending_cab (struct sk_buff *skb) {/* Check whether the Beacon frame has DTIM indicating buffered bc/mc */
Signature · 1 line
1.8.0.2
PATCH v2 1/5 ath9k: do not link receive buffers during flush
On AR9300 the rx FIFO needs to be empty during reset to ensure that no further DMA activity is generated, otherwise it might lead to memory corruption issues.
--- drivers/net/wireless/ath/ath9k/recv.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/net/wireless/ath/ath9k/recv.c +6 -4
@@ -735,6 +735,7 @@ static struct ath_buf *ath_get_next_rx_buf(struct ath_softc *sc,return NULL ; } +list_del (&bf->list);if (!bf->bf_mpdu)return bf;
@@ -1245,14 +1246,15 @@ requeue_drop_frag: sc->rx.frag =NULL ; } requeue: +list_add_tail (&bf->list, &sc->rx.rxbuf); +if (!flush) +continue ; +if (edma) { -list_add_tail (&bf->list, &sc->rx.rxbuf);ath_rx_edma_buf_link (sc, qtype); }else { -list_move_tail (&bf->list, &sc->rx.rxbuf);ath_rx_buf_link (sc, bf); -if (!flush) -ath9k_hw_rxena (ah); +ath9k_hw_rxena (ah); } }while (1 );
Signature · 1 line
1.8.0.2
PATCH v2 3/5 ath9k: remove the WARN_ON that triggers if generating a beacon fails
In reply to Felix FietkauDuring teardown, mac80211 will not return a new beacon. This is normal and handled properly in the driver, so there's no need to spam the user with a kernel warning here.
--- drivers/net/wireless/ath/ath9k/beacon.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/wireless/ath/ath9k/beacon.c +0 -1
@@ -360,7 +360,6 @@ void ath9k_beacon_tasklet(unsigned long data)return ; bf =ath9k_beacon_generate (sc->hw, vif); -WARN_ON (!bf);if (sc->beacon.bmisscnt !=0 ) { ath_dbg(common, BSTUCK, "resume beacon xmit after %u misses\n",
Signature · 1 line
1.8.0.2
PATCH v2 4/5 ath9k: add a better fix for the rx tasklet vs rx flush race
Ensure that the rx tasklet is no longer running when entering the reset path. Also remove the distinction between flush and no-flush frame processing. If a frame has been received and ACKed by the hardware, the stack needs to see it, so that the BA receive window does not go out of sync.
--- drivers/net/wireless/ath/ath9k/ath9k.h | 1 - drivers/net/wireless/ath/ath9k/debug.c | 1 - drivers/net/wireless/ath/ath9k/debug.h | 2 -- drivers/net/wireless/ath/ath9k/main.c | 4 ++++ drivers/net/wireless/ath/ath9k/recv.c | 15 --------------- 5 files changed, 4 insertions(+), 19 deletions(-)
drivers/net/wireless/ath/ath9k/ath9k.h +0 -1
@@ -641,7 +641,6 @@ void ath_ant_comb_update(struct ath_softc *sc);enum sc_op_flags {SC_OP_INVALID ,SC_OP_BEACONS , -SC_OP_RXFLUSH ,SC_OP_ANI_RUN ,SC_OP_PRIM_STA_VIF ,SC_OP_HW_RESET ,
drivers/net/wireless/ath/ath9k/debug.c +0 -1
@@ -861,7 +861,6 @@ static ssize_t read_file_recv(struct file *file, char __user *user_buf,RXS_ERR ("RX-LENGTH-ERR" , rx_len_err);RXS_ERR ("RX-OOM-ERR" , rx_oom_err);RXS_ERR ("RX-RATE-ERR" , rx_rate_err); -RXS_ERR ("RX-DROP-RXFLUSH" , rx_drop_rxflush);RXS_ERR ("RX-TOO-MANY-FRAGS" , rx_too_many_frags_err);PHY_ERR ("UNDERRUN ERR" ,ATH9K_PHYERR_UNDERRUN );
drivers/net/wireless/ath/ath9k/debug.h +0 -2
@@ -216,7 +216,6 @@ struct ath_tx_stats {* @rx_oom_err: No. of frames dropped due to OOM issues. * @rx_rate_err: No. of frames dropped due to rate errors. * @rx_too_many_frags_err: Frames dropped due to too-many-frags received. -* @rx_drop_rxflush: No. of frames dropped due to RX-FLUSH. * @rx_beacons: No. of beacons received. * @rx_frags: No. of rx-fragements received. */
@@ -235,7 +234,6 @@ struct ath_rx_stats {u32 rx_oom_err;u32 rx_rate_err;u32 rx_too_many_frags_err; -u32 rx_drop_rxflush;u32 rx_beacons;u32 rx_frags; };
drivers/net/wireless/ath/ath9k/main.c +4 -0
@@ -196,6 +196,8 @@ static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)ath9k_debug_samp_bb_mac (sc);ath9k_hw_disable_interrupts (ah); +tasklet_disable (&sc->intr_tq); +if (!ath_stoprecv (sc)) ret = false;
@@ -210,6 +212,8 @@ static bool ath_prepare_reset(struct ath_softc *sc, bool retry_tx, bool flush)ath_flushrecv (sc); } +tasklet_enable (&sc->intr_tq); +return ret; }
drivers/net/wireless/ath/ath9k/recv.c +0 -15
@@ -280,7 +280,6 @@ int ath_rx_init(struct ath_softc *sc, int nbufs)spin_lock_init (&sc->sc_pcu_lock);spin_lock_init (&sc->rx.rxbuflock); -clear_bit (SC_OP_RXFLUSH , &sc->sc_flags); common->rx_bufsize =IEEE80211_MAX_MPDU_LEN /2 + sc->sc_ah->caps.rx_status_len;
@@ -492,11 +491,9 @@ bool ath_stoprecv(struct ath_softc *sc)void ath_flushrecv (struct ath_softc *sc) { -set_bit (SC_OP_RXFLUSH , &sc->sc_flags);if (sc->sc_ah->caps.hw_caps &ATH9K_HW_CAP_EDMA )ath_rx_tasklet (sc,1 , true);ath_rx_tasklet (sc,1 , false); -clear_bit (SC_OP_RXFLUSH , &sc->sc_flags); }static bool ath_beacon_dtim_pending_cab (struct sk_buff *skb)
@@ -1058,9 +1055,6 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp) do { bool decrypt_error = false; - /* If handling rx interrupt and flush is in progress => exit */ - if (test_bit(SC_OP_RXFLUSH, &sc->sc_flags) && (flush == 0)) - break; memset(&rs, 0, sizeof(rs)); if (edma)
@@ -1103,15 +1097,6 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)ath_debug_stat_rx (sc, &rs); -/* -* If we're asked to flush receive queue, directly -* chain it back at the queue without processing it. -*/ -if (test_bit (SC_OP_RXFLUSH , &sc->sc_flags)) { -RX_STAT_INC (rx_drop_rxflush); - goto requeue_drop_frag; - } -memset (rxs,0 ,sizeof (struct ieee80211_rx_status )); rxs->mactime = (tsf & ~0xffffffffULL ) | rs.rs_tstamp;
Signature · 1 line
1.8.0.2