On Sun, Jul 12, 2015 at 05:57:14PM +0200, Martin Pieuchot wrote:
> > > run_newstate_cb SCAN -> INIT
> > > run_newstate_cb SCAN -> SCAN
>
> How is this possible? Why it isn't INIT -> SCAN?
I'm not entirely sure.
I think one possible scenario is as follows:
We're scanning. scan_to runs (every 200ms) and appends a state
transition (i.e. run_newstate_cb()) for SCAN->SCAN on the cmdq
to scan the next channel.
Some process causes a call to run_stop() followed by run_init().
(Note that 'ifconfig run0 mediaopt monitor up' starts a scan and
then does IFF_UP. Somehow run_media_change runs, which does run_stop()
followed by run_init(), but I haven't yet tracked down why -- perhaps
to switch bands from 2GHz to 5GHz. But this seems to be an important
ingrediant since the crash can't be trigged with 2GHz-only devices.)
run_stop() calls timeout_del() to cancel scan_to.
run_stop() calls ieee80211_new_state(), i.e. run_newstate(), which appends
a state transition to INIT on the cmdq.
run_stop() waits for run_usb_task to complete.
usb_task_thread gets scheduled.
run_task() runs, and executes the pending SCAN->SCAN transition first.
This transition calls timeout_add on scan_to, effectively cancelling
run_stop's call to timeout_del().
After that, the SCAN->INIT transition is executed as well.
usb_task_thread goes back to sleep.
Now scan_to runs and puts run_newstate_cb() with for state transition
SCAN->SCAN on the cmdq.
run_stop() finishes up and returns.
run_init() is called. It resets cmdq.{next,cur,queued} to zero,
corrupting the cmdq.
run_task() runs to execute the pending SCAN->SCAN transition.
But cmdq is now corrupt and we crash.
If this is indeed what's happening, my diff ensures that no pending
SCAN->SCAN transition is on the cmdq before appending the transition
to INIT. However, the last SCAN->SCAN transition would still call
timeout_add for scan_to after run_stop called timeout_del. So the diff
may not be a bullet proof fix. Perhaps we should add a timeout_del
to run_newstate_cb if going back to INIT?
What do you think? Does this make any sense?
Are there other possiblities?
Perhaps we should try to find a whiteboard in calgary and draw
some diagrams ;-)