Re: [PATCH] wifi: mac80211: Serialize calls to drv_wake_tx_queue()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Tue, 2023-03-14 at 12:20 +0100, Alexander Wetzel wrote:
> On 13.03.23 21:33, Johannes Berg wrote:
> > On Mon, 2023-03-13 at 21:15 +0100, Alexander Wetzel wrote:
> > > 
> > > While drivers with native iTXQ support are able to handle that,
> > > 
> > 
> > questionable. Looking at iwlwifi:
> > 
> > void iwl_mvm_mac_wake_tx_queue(struct ieee80211_hw *hw,
> >                                 struct ieee80211_txq *txq)
> > {
> >          struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
> > ...
> >          list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
> > ...
> > }
> > 
> > which might explain some rare and hard to debug list corruptions in the
> > driver that we've seen reports of ...
> > 
> 
> Shall I change the scope of the fix from "only 6.2" to any stable kernel?
> 'Fixes: ba8c3d6f16a1 ("mac80211: add an intermediate software queue 
> implementation")'
> 
> Or is that a overreaction and we better stick to what we know for sure 
> and keep the 'Fixes: c850e31f79f0 ("wifi: mac80211: add internal handler 
> for wake_tx_queue")'?

I think we stick with the latter. I already have a fix for iwlwifi (see
https://lore.kernel.org/r/20230314103840.30771-1-jtornosm@xxxxxxxxxx)
and other drivers should be fine.

Also that means we should probably restrict the fix to actually be for
mac80211 only.

> > > To avoid what seems to be a not needed distinction between native and
> > > drivers using ieee80211_handle_wake_tx_queue(), the serialization is
> > > done for drv_wake_tx_queue() here.
> > 
> > So probably no objection to that, at least for now, though in the common
> > path (what I showed above was the 'first use' path), iwlwifi actually
> > hits different HW resources, so it _could_ benefit from concurrent TX
> > after fixing that bug.
> > 
> 
> I could also directly add a driver a driver flag, allowing drivers to 
> opt in to overlapping calls. And then set the flag for mt76, since Felix 
> prefers to not change the behavior and knows this driver works with it.

Too much complexity. I change my position - let's fix mac80211 and
iwlwifi separately.

> Exactly. With the benefit that when we run uncontested the overhead is 
> close to zero.
> But this should also be true for spinlocks. And when we spin on 
> contention it even better... So I'll change it to use a spinlock instead.

Yeah that was kind of my thought process here too.


> > Since drivers are supposed to handle concurrent TX per AC, you could
> I assume you mean multiple drv_wake_tx_queue() can run in parallel, as 
> long as they are serving different ACs?
> In a prior test patch I just blocked concurrent calls for the same ac.

No, I meant that drv_tx() was previously allowed concurrently for
different HW queues, which in practice means at least different ACs.

> While that may be enough for full iTXQ drivers I have doubts that this 
> is sufficient for the ones using ieee80211_handle_wake_tx_queue.

No no, that's what I mean, it should've been sufficient for old-style
drivers.

> I at least was unable to identify any code in the rt2800usb driver which 
> looked dangerous for concurrent execution. (Large parts are protected by 
> a driver spinlock)

Indeed, that's not so clear.

> I ended up with the assumption, that the DMA handover - or something 
> related to that - must cause the queue freezes. (Or my ability to detect 
> critical calls is not good enough, yet.)

That part is protected by a per-queue lock in
rt2x00queue_write_tx_frame() though, but I don't see any problem either.

> The patch still fixed the issue, of course. All races in the examined 
> regression are for IEEE80211_AC_BE, so it's sufficient fix when we 
> decide that's save.

It seems to me it should be safe, again, since we previously assumed you
could do TX per HW queue concurrently. However, that's not precisely per
AC, so we might need to be careful, and maybe that's not worth it.

> Holding active_txq_lock[ac] all that time - it's normally acquired and 
> released multiple times in between - seems to be a bit too daring for a 
> "stable" patch.

Fair enough :)

> I also still would place the spinlock in drv_wake_tx_queue(). After all 
> ieee80211_txq_schedule_start/end is kind of optional and e.g. iwlwifi is 
> not using it.

True.

> What about handling it that way:
> 
> Keep serializing drv_wake_tx_queue(). But use a new spinlock the drivers 
> can opt out from.
>   1) No flag set:
>      drv_wake_tx_queue() can be running only once at any time
> 
>   2) IEEE80211_HW_CONCURRENT_AC_TX
>      drv_wake_tx_queue() can be running once per AC at any time
> 
>   3) IEEE80211_HW_CONCURRENT
>      current behavior.
> 

I don't like the flags, to be honest.

Have you considered Felix's proposal of having a separate thread to
handle all the transmits? Or maybe that's too much for stable too?


I think my personal order of options would be:

1) for stable, just add a spinlock to ieee80211_handle_wake_tx_queue()

2) for later, maybe consider making ieee80211_handle_wake_tx_queue()
   just wake up a kthread or something, and handle the schedule loop
   there

However we may need to think more about 2), maybe we could even map to
hardware queues and do concurrency there, but better we just say screw
it and remove all that cruft instead ...

johannes




[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux