Linux wireless drivers development
 help / color / mirror / Atom feed
From: "Nicolas Escande" <nico.escande@gmail.com>
To: "Baochen Qiang" <baochen.qiang@oss.qualcomm.com>,
	"Nicolas Escande" <nico.escande@gmail.com>,
	<ath11k@lists.infradead.org>
Cc: <linux-wireless@vger.kernel.org>, "Maxime Bizon" <mbizon@freebox.fr>
Subject: Re: [PATCH ath-current] wifi: ath11k: fix locking problem in ath11k_dp_rx_tid_del_func()
Date: Fri, 31 Jul 2026 16:36:17 +0200	[thread overview]
Message-ID: <DKCTYSL53MB6.16YGGTQW1BGDC@gmail.com> (raw)
In-Reply-To: <387b4bb6-b0e4-471a-9276-211ecdedb58e@oss.qualcomm.com>

On Fri Jul 31, 2026 at 8:49 AM CEST, Baochen Qiang wrote:
>
>
> On 7/29/2026 4:57 PM, Nicolas Escande wrote:
>> From: Maxime Bizon <mbizon@freebox.fr>
>> 
>> In this function, we iterate over dp->reo_cmd_cache_flush_list using
>> list_for_each_entry_safe(), and for each expired entries we call
>> ath11k_dp_reo_cache_flush() then free the entry. As this can be called
>> from multiple CPU we protect for concurrent access using dp->reo_cmd_lock.
>> 
>> The lock is dropped to call ath11k_dp_reo_cache_flush() and taken again
>> before keeping iterating over the loop. That is broken.
>> 
>> The list_for_each_entry_safe() protects over deleting the entry being 
>> iterated over but does not protect for concurrent access. So another
>> thread might have taken the lock in between and modified the list, leading
>> to a crash (see bellow). 
>
> nit: s/bellow/below/
>
will do
[...]
>> 
>> Tested-on: QCN9074 PCI WLAN.HK.2.9.0.1-01977-QCAHKSWPL_SILICONZ-1
>
> hardware version missing betweeen target and bus type
>
will change
> QCN9074 hw1.0 PCI
>
>> 
>> Fixes: d5c65159f289 ("ath11k: driver for Qualcomm IEEE 802.11ax devices")
>> Signed-off-by: Maxime Bizon <mbizon@freebox.fr>
>> Signed-off-by: Nicolas Escande <nico.escande@gmail.com>
[...]
>
> while this seems the minimal fix which stable team might prefer, how about refactoring as
> firstly detaching all the expired entries onto a local list under the lock and flushing
> that list afterwards:
>
>   LIST_HEAD(flush_list);
>
>   spin_lock_bh(&dp->reo_cmd_lock);
>   list_for_each_entry_safe(elem, tmp, &dp->reo_cmd_cache_flush_list, list) {
>         if () {
>                 list_move_tail(&elem->list, &flush_list);
>         }
>   }
>   spin_unlock_bh(&dp->reo_cmd_lock);
>
>   list_for_each_entry_safe(elem, tmp, &flush_list, list) {
>         list_del(&elem->list);
>         ath11k_dp_reo_cache_flush(ab, &elem->data);
>         kfree(elem);
>   }
>
> This fully decouples the concurrency from the flushing: the detach phase runs entirely
> under the lock, and the flush phase walks a thread-private list where no concurrency
> exists. It's a single O(N) pass instead of the O(N^2) worst case of re-scanning from the
> head, and it avoids bouncing reo_cmd_lock once per freed entry.
>
> Also this seems simpler and more direct — its correctness is obvious by construction;
> while the fix of this patch is less self-evident: a reader may not easily grasp why the
> code has to rescan from the head after re-taking the lock.
>
> Non-blocking though — either form fixes the crash. If you'd rather keep the minimal goto
> retry for the stable backport and do the detach-list version as a follow-up cleanup, that
> works for me too.

Yes I remember that we fixed it this way with Maxime to minimize code change.
But doing it your way seems to be the better thing to do. So I agree I'll
rework this wit the single iteration under lock + cleanup pass.
But it will take me some time to do so, I do not have much time right now. 
So if Jeff prefers taking this one as is just to have a quick fix no objection
either, I'll rework it later for next. You guys tell me what you prefer.

  reply	other threads:[~2026-07-31 14:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-29  8:57 [PATCH ath-current] wifi: ath11k: fix locking problem in ath11k_dp_rx_tid_del_func() Nicolas Escande
2026-07-31  6:49 ` Baochen Qiang
2026-07-31 14:36   ` Nicolas Escande [this message]
2026-07-31 16:31     ` Jeff Johnson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DKCTYSL53MB6.16YGGTQW1BGDC@gmail.com \
    --to=nico.escande@gmail.com \
    --cc=ath11k@lists.infradead.org \
    --cc=baochen.qiang@oss.qualcomm.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=mbizon@freebox.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox