Skip to content

tools/kmod: tolerate USB-audio-busy for shared ALSA core modules - #1367

Open
harajend wants to merge 1 commit into
mainfrom
usb-audio-busy-tolerance-shared-alsa-core
Open

harajend wants to merge 1 commit into
mainfrom
usb-audio-busy-tolerance-shared-alsa-core

Conversation

@harajend

Copy link
Copy Markdown
Contributor

Problem

sof_remove.sh runs under 'bash -e'. If a USB audio device (e.g. a loopback/offload device used by CI) is briefly busy when snd_usb_audio/snd_usbmidi_lib are removed, the script aborts right there.

Root cause

Because the script aborts mid-way under set -e, snd_sof can already be removed by the time the abort happens, but reload_drivers() never gets to reload it. That breaks the DSP for every subsequent test case in the run, not just the current one.

Fix

Track whether USB audio is still loaded after the removal attempt (usb_audio_still_loaded) and tolerate the same failure on the shared ALSA-core modules it can keep busy: snd_hwdep, snd_rawmidi, snd_seq_device, snd_timer, snd, soundcore. This mirrors the existing tolerance already in place for snd_sof_intel_hda_common's SDW-BRA busy case a few lines above. Unrelated failures on these modules still abort normally, since the tolerance is conditional on USB audio itself having failed to unload.

Verification

Internally we carried an equivalent fix on our downstream fork and confirmed it resolves a cascade of ~38 failed test cases caused by a USB audio loopback device (WCL_HDA_AIOC) keeping shared modules busy during driver reload on an RVP DUT. This PR ports the same fix onto the current upstream module ordering (which already differs from our fork, e.g. the snd_usb_offload/soc_usb reordering and the snd_ump handling).

sof_remove.sh runs under 'set -e'. If a USB audio device (e.g. a
loopback/offload device under test) is briefly busy when
snd_usb_audio/snd_usbmidi_lib are removed, the script aborts right
there. That leaves snd_sof removed but never reloaded, breaking the
DSP for the rest of the test run, since reload_drivers() never
completes.

Track whether USB audio is still loaded after the removal attempt and
tolerate the same failure on the shared ALSA-core modules it can keep
busy (snd_hwdep, snd_rawmidi, snd_seq_device, snd_timer, snd,
soundcore), the same way snd_sof_intel_hda_common's SDW-BRA busy case
is already tolerated above. Unrelated failures on these modules still
abort, since the tolerance only applies when USB audio itself failed
to unload.
@harajend
harajend requested review from a team, lgirdwood, marc-hb and plbossart as code owners November 23, 2026 01:57
@harajend harajend self-assigned this Nov 23, 2026
@marc-hb

marc-hb commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

If a USB audio device (e.g. a loopback/offload device used by CI) is briefly busy

Why is it "briefly busy"? Some audio daemon interfering maybe? Which could cause many other, unrelated failures? As has already happened so many other times in the past?

See https://github.com/thesofproject/sof-test/pulls?q=pulseaudio , #289, + many other Intel-private issues.

It seems wiser to find and deal with the root cause and make the test configuration more deterministic rather than trying to paper over it.

reload_drivers() never gets to reload it. That breaks the DSP for every subsequent test case in the run, not just the current one.

In an ideal world, rebooting would be really fast and performed after each failure. Not rebooting after a failure is always a risky optimization because there is a million of other, unexpected ways a failure can cascade and lose the entire run - not just this USB one. Trying to manage them all has always been a game of whack-a-mole. This has already been discussed a lot in the past.

This being said, an interesting question is: why is reload_drivers() not capable of recovering from this failure and unexpected state? Maybe cleanup and setup functions should try harder to produce a deterministic test setup (with or without rebooting)

Track whether USB audio is still loaded after the removal attempt (usb_audio_still_loaded) and tolerate the same failure on the shared ALSA-core modules it can keep busy:

This tries to deal with a non-deterministic setup by making it even less deterministic. Good luck with that...

@marc-hb

marc-hb commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Why is it "briefly busy"? Some audio daemon interfering maybe? Which could cause many other, unrelated failures? As has already happened so many other times in the past?

BTW pgrep -a pipewire and all other audio daemons are definitely missing from the exit_handler(). That could answer this question.

sof_remove.sh runs under 'bash -e'. If a USB audio device (e.g. a loopback/offload device used by CI) is briefly busy when snd_usb_audio/snd_usbmidi_lib are removed, the script aborts right there.

If you want to keep ignoring why the test setup is not deterministic, another option could be something like this:

main
{
  for i in $(seq 1 $max_tries); do
   if remove_all_modules; then
       break;
   fi
   if [ $i -lt $max_tries]; then
      WARN sof_remove.sh failed...
   else
      die ...
   fi
done
}
{
  main "$@"; exit $?
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants