Re: [PATCH 2/2] wifi: mac80211_hwsim: serialize radio removal with frame commands

From: enderaoelyther

Date: Wed Nov 11 2026 - 14:52:41 EST


> That, with significant work done under the mutex, seems like too big a
> hammer, can't it really not be done in any other way?

Yes, you are right. The global mutex is way too broad, and I am dropping
that approach entirely.

The underlying problem is per-radio object lifetime, not command
serialization. get_hwsim_data_ref_from_addr() returns a radio pointer
after rhashtable_lookup_fast() has already ended its RCU read-side
protection. A concurrent deletion can then unpublish and free that radio
while a frame, TX-status, or PMSR command is still using the pointer.

I reworked the fix around a per-radio reference count. Address lookups
acquire a reference while holding hwsim_radio_lock, which is already used
when removing a radio from the hash table. Deletion first unpublishes the
radio under hwsim_radio_lock, releases that lock, drops the initial
reference, and waits only for in-flight lookups on that specific radio to
finish before calling ieee80211_unregister_hw().

This keeps the expensive ieee80211_unregister_hw() path outside
hwsim_radio_lock. It introduces no new lock and does not serialize command
handlers or the teardown of unrelated radios.

Since patch 1/2 is already applied, I will send the replacement as a
standalone v2.

Thanks,
Zhao

On Tue, 10 Nov 2026 11:54:21 +0100, Johannes Berg
<johannes@xxxxxxxxxxxxxxxx> wrote:
> On Wed, 2026-10-28 at 22:17 +0800, Zhao Li wrote:
> > Destroying a radio while a frame, TX status, or PMSR command is in
> > progress can make the command access the radio after it has been freed.
> >
> > DEFINE_SPINLOCK(hwsim_radio_lock);
> > +static DEFINE_MUTEX(hwsim_radio_mutex);
>
> That, with significant work done under the mutex, seems like too big a
> hammer, can't it really not be done in any other way?
>
> johannes