Page MenuHomeFreeBSD

sound: Remove CHN_F_SLEEPING
ClosedPublic

Authored by christos on Nov 13 2024, 10:33 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Dec 11, 8:38 PM
Unknown Object (File)
Tue, Dec 10, 7:11 PM
Unknown Object (File)
Tue, Dec 10, 5:13 PM
Unknown Object (File)
Tue, Dec 3, 6:59 PM
Unknown Object (File)
Tue, Dec 3, 6:57 PM
Unknown Object (File)
Tue, Nov 26, 6:05 PM
Unknown Object (File)
Nov 24 2024, 11:01 AM
Unknown Object (File)
Nov 21 2024, 12:50 AM
Subscribers

Details

Summary

The KASSERT in chn_sleep() can be triggered if more than one thread
wants to sleep on a given channel at the same time. While this is not
really a common scenario, tools such as stress2, which use fork() and
the child process(es) inherit the parent's FDs as a result, we can end
up triggering such scenarios.

Fix this by removing CHN_F_SLEEPING altogether, which is not very useful
in the first place:

  • CHN_BROADCAST() checks cv_waiters already, so there is no need to check CHN_F_SLEEPING as well.
  • We can check whether cv_waiters is 0 in pcm_killchans(), instead of whether CHN_F_SLEEPING is not set.

Reported by: dougm, pho (stress2)
Sponsored by: The FreeBSD Foundation
MFC after: 2 days

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 60539
Build 57423: arc lint + arc unit

Event Timeline

Minor fix in CHN_F_EXCLUSIVE.

@dougm @pho Could you please let me know if the panic persists with this patch?

I do net see any panics with D47559.146396.patch

sys/dev/sound/pcm/channel.h
357

In general we don't renumber flags into now-unused slots. You can instead just leave a comment here indicating that 0x00000020 was CHN_F_SLEEPING

christos marked an inline comment as done.

Address Ed's comment.

sys/dev/sound/pcm/sound.c
223–224

Checking the waiters field directly like this is a bit of a layering violation, though the sound driver framework already does this. In fact, cv_waiters == 0 implies there are no waiters, but the converse is not true: cv_waiters != 0 does not imply that there are waiters.

What happens if the code below is executed and there are no waiters? Is it harmless?

sys/dev/sound/pcm/sound.c
223–224

In order to get past this loop we'll have to eventually execute this check without waiters for all channels, so I'm pretty sure it's fine.

sys/dev/sound/pcm/sound.c
223–224

Ah sorry, you meant what happens if the lines below this check are executed. Still, nothing. chn_shutdown() calls CHN_BROADCAST() which also checks for cv_waiters, and the rest shouldn't concern the value of cv_waiters anyway.

This revision is now accepted and ready to land.Nov 16 2024, 5:04 PM
This revision was automatically updated to reflect the committed changes.