Skip to content

Cannot remove vsnd module #1

Closed
Closed

Description

@Cuda-Chen

It seems that vsnd module cannot be removed if the system contains other sound devices.

Test result:

$ make check
make -C /lib/modules/5.15.0-92-generic/build M=/home/jio/c_code/vsnd modules
make[1]: Entering directory '/usr/src/linux-headers-5.15.0-92-generic'
  CC [M]  /home/jio/c_code/vsnd/vsnd.o
  MODPOST /home/jio/c_code/vsnd/Module.symvers
  CC [M]  /home/jio/c_code/vsnd/vsnd.mod.o
  LD [M]  /home/jio/c_code/vsnd/vsnd.ko
  BTF [M] /home/jio/c_code/vsnd/vsnd.ko
Skipping BTF generation for /home/jio/c_code/vsnd/vsnd.ko due to unavailability of vmlinux
make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-92-generic'
curl -o CantinaBand3.wav https://www2.cs.uic.edu/~i101/SoundFiles/CantinaBand3.wav
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  129k  100  129k    0     0  60312      0  0:00:02  0:00:02 --:--:-- 60293
scripts/verify.sh
+ sudo modprobe snd_pcm
[sudo] password for jio: 
+ sudo rmmod vsnd
rmmod: ERROR: Module vsnd is in use
+ rm -f /tmp/audio.pcm
+ mkfifo /tmp/audio.pcm
+ sudo insmod vsnd.ko out_fifo_name=/tmp/audio.pcm
insmod: ERROR: could not insert module vsnd.ko: File exists
+ sleep 1
+ tee out.pcm
+ aplay CantinaBand3.wav
Playing WAVE 'CantinaBand3.wav' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
underrun!!! (at least 4013.908 ms long)
underrun!!! (at least 3997.829 ms long)
underrun!!! (at least 4000.495 ms long)
underrun!!! (at least 3994.409 ms long)
underrun!!! (at least 3997.966 ms long)
+ sudo rmmod vsnd
rmmod: ERROR: Module vsnd is in use
+ ffmpeg -f s16le -ar 22.05k -ac 1 -loglevel 8 -i out.pcm out.wav
[1]+  Done                    tee out.pcm < /tmp/audio.pcm > /dev/null

System environment:

$ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC269VB Analog [ALC269VB Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: vsnd [vsnd], device 0: vsnd PCM [vsnd PCM]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

$ uname -a
Linux <my-compuer-user-name> 5.15.0-92-generic #102-Ubuntu SMP Wed Jan 10 09:33:48 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Activity

  1. jserv commented on Feb 15, 2024

    @jserv
    Contributor

    @Cuda-Chen, Can you confirm that vsnd_unregister_all() properly iterates the registered sound devices?

  2. Cuda-Chen commented on Feb 16, 2024

    @Cuda-Chen
    ContributorAuthor

    Hi @jserv ,

    After upgrading my system to 5.15.0-94-generic, it gets worse: the kernel cannot load vsnd module, and I think there are some issues of the recently Ubuntu distro. I will solve the cannot load module issue first.

    FYI, here are the outputs after loading the vsnd module:

    $ make check
    make check
    make -C /lib/modules/5.15.0-94-generic/build M=/home/jio/c_code/vsnd modules
    make[1]: Entering directory '/usr/src/linux-headers-5.15.0-94-generic'
    make[1]: Leaving directory '/usr/src/linux-headers-5.15.0-94-generic'
    scripts/verify.sh
    + sudo modprobe snd_pcm
    + sudo rmmod vsnd
    rmmod: ERROR: Module vsnd is not currently loaded
    + rm -f /tmp/audio.pcm
    + mkfifo /tmp/audio.pcm
    + sudo insmod vsnd.ko out_fifo_name=/tmp/audio.pcm
    insmod: ERROR: could not insert module vsnd.ko: Invalid module format
    + sleep 1
    + tee out.pcm
    + aplay CantinaBand3.wav
    Playing WAVE 'CantinaBand3.wav' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono
    + sudo rmmod vsnd
    rmmod: ERROR: Module vsnd is not currently loaded
    + ffmpeg -f s16le -ar 22.05k -ac 1 -loglevel 8 -i out.pcm out.wav
    File 'out.wav' already exists. Overwrite? [y/N] 
    Not overwriting - exiting
    make: *** [Makefile:12: check] Error 1

    What's more, here are the results in dmesg while loading vsnd module:

    [26902.839728] module: x86/modules: Skipping invalid relocation target, existing value is nonzero for type 1, loc 0000000062f68630, val ffffffffc13faa3a
    
  3. Cuda-Chen commented on Feb 17, 2024

    @Cuda-Chen
    ContributorAuthor

    Hi @jserv ,

    After purging and reinstalling the linux-headers, it compiles without any errors (as I have not clean the linux-headers on my computer for years).

    For Ubuntu, to let vsnd play sound, you have to select the vsnd from System Settings -> Sounds (the system describe vsnd as Analog Output - Built-in Audio) or the test sound will be played by other sound devices.
    What's more, there is some interesting finding when using lsmod | grep vsnd:

    $ lsmod | grep vsnd
    vsnd                   16384  1
    snd_pcm               143360  7 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec,vsnd,snd_hda_core
    snd                   106496  24 snd_hda_codec_generic,snd_seq,snd_seq_device,snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_hda_codec,snd_hda_codec_realtek,snd_timer,vsnd,snd_pcm,snd_rawmidi
    

    You can see that vsnd is occupied by some unknown kernel modules. I think I should realize how Ubuntu manage the sound device first (maybe the System Setting occupies vsnd so we can't rmmod vsnd?).

  4. Cuda-Chen commented on Mar 18, 2024

    @Cuda-Chen
    ContributorAuthor

    Hi @jserv ,

    I would like to make some updates about my findings.

    I found vsnd cannot be removed once it plays any sound.
    To remove vsnd, I have to type pactl set-card-profile alsa_card.platform-vsnd.0 off and the vsnd will be able to be removed.

    What's more, it seems that the dmesg produces lagged output as follows (use this fork to re-produce):

    [ 3458.302210] start to unregister vsnd driver
    [ 3467.285842] Succeeded to load vsnd
    [ 3471.103242] START: channels 1 rate 22050
    [ 3502.116129] STOP
    [ 3557.413503] start to unregister vsnd components
    [ 3557.414614] end to unregister vsnd components
    

    Also, I think to designate the sound-playing device when testing should be more convenient so that we don't need to switch the sound output device from system setting manually.

  5. Cuda-Chen commented on May 6, 2024

    @Cuda-Chen
    ContributorAuthor

    Close this as we mention that the contributors should temporarily disable downstream sound services such as PluseAudio and PipeWire in README.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions