Skip to contentSkip to conversation

sound: pci: trident: a possible data race

BUG Jia-Ju Bai 2 participants 5 messages Oct 3, 2018 – Oct 4, 2018

lore
Share & tools
lore

Jia-Ju Bai

author
#0 lore raw

CPU0:
snd_trident_hw_free

    snd_trident_free_voice
            line 3870: spin_lock_irqsave()
            line 3881: voice->substream = NULL; [WRITE]
CPU1:
snd_trident_interrupt
    line 3798: snd_pcm_period_elapsed(voice->substream);  [READ]

As for voice->substream, the WRITE operation in CPU0 is performed with holding a spinlock, but the READ operation in CPU1 is performed without holding this spinlock, so there may exist a data race.

Best wishes,
Jia-Ju Bai

#1 lore raw
Quoted 10 lines · Jia-Ju Bai

CPU0:
snd_trident_hw_free

    snd_trident_free_voice
            line 3870: spin_lock_irqsave()
            line 3881: voice->substream = NULL; [WRITE]
CPU1:
snd_trident_interrupt
    line 3798: snd_pcm_period_elapsed(voice->substream);  [READ]
Quoted 3 lines

As for voice->substream, the WRITE operation in CPU0 is performed with holding a spinlock, but the READ operation in CPU1 is performed without holding this spinlock, so there may exist a data race.

Thanks for the report.

The actual crash must be very unlikely, almost 0%, though. snd_trident_hw_free() is called always after the PCM stream gets stopped via trigger callback, i.e. at the moment, there is no corresponding interrupt is generated for that voice entry.

And the hardware is very old, I bet only a handful people still using in the whole world :)

If we really want to be 100% sure, we may call synchronize_irq() before the NULL-clearing. But there is no way to test the bug nor the fix, so it's fairly moot, IMO.

thanks,

Takashi

author
#2 lore raw

Thanks for the reply :)

Quoted 14 lines · Takashi Iwai
Quoted 9 lines · Jia-Ju Bai

CPU0:
snd_trident_hw_free

     snd_trident_free_voice
             line 3870: spin_lock_irqsave()
             line 3881: voice->substream = NULL; [WRITE]
CPU1:
snd_trident_interrupt
     line 3798: snd_pcm_period_elapsed(voice->substream);  [READ]
Quoted 3 lines

As for voice->substream, the WRITE operation in CPU0 is performed with holding a spinlock, but the READ operation in CPU1 is performed without holding this spinlock, so there may exist a data race.

Quoted 6 lines

Thanks for the report.

The actual crash must be very unlikely, almost 0%, though. snd_trident_hw_free() is called always after the PCM stream gets stopped via trigger callback, i.e. at the moment, there is no corresponding interrupt is generated for that voice entry.

How about the case that playback and capture are performed concurrently?
Namely, snd_trident_hw_free() is called for playback, and the interrupt is generated for capture.

Quoted 2 lines

And the hardware is very old, I bet only a handful people still using in the whole world :)

I have this hardware, so I am the one of these handful people ;)

Best wishes,
Jia-Ju Bai

#3 lore raw
Quoted 21 lines · Jia-Ju Bai

Thanks for the reply :)

Quoted 16 lines · Takashi Iwai
Quoted 9 lines · Jia-Ju Bai

CPU0:
snd_trident_hw_free

     snd_trident_free_voice
             line 3870: spin_lock_irqsave()
             line 3881: voice->substream = NULL; [WRITE]
CPU1:
snd_trident_interrupt
     line 3798: snd_pcm_period_elapsed(voice->substream);  [READ]
Quoted 3 lines

As for voice->substream, the WRITE operation in CPU0 is performed with holding a spinlock, but the READ operation in CPU1 is performed without holding this spinlock, so there may exist a data race.

Thanks for the report.

Quoted 8 lines
Quoted 4 lines

The actual crash must be very unlikely, almost 0%, though. snd_trident_hw_free() is called always after the PCM stream gets stopped via trigger callback, i.e. at the moment, there is no corresponding interrupt is generated for that voice entry.

How about the case that playback and capture are performed concurrently? Namely, snd_trident_hw_free() is called for playback, and the interrupt is generated for capture.

They are different substreams, hence it won't pick up the substream object.

Quoted 4 lines
Quoted 2 lines

And the hardware is very old, I bet only a handful people still using in the whole world :)

I have this hardware, so I am the one of these handful people ;)

Wow, that's fun. Then we can really fix the issue, if any. Did you actually hit any relevant bug?

thanks,

Takashi

author
#4 lore raw
Quoted 26 lines · Takashi Iwai
Quoted 24 lines · Jia-Ju Bai

Thanks for the reply :)

Quoted 20 lines · Takashi Iwai
Quoted 9 lines · Jia-Ju Bai

CPU0:
snd_trident_hw_free

      snd_trident_free_voice
              line 3870: spin_lock_irqsave()
              line 3881: voice->substream = NULL; [WRITE]
CPU1:
snd_trident_interrupt
      line 3798: snd_pcm_period_elapsed(voice->substream);  [READ]
Quoted 3 lines

As for voice->substream, the WRITE operation in CPU0 is performed with holding a spinlock, but the READ operation in CPU1 is performed without holding this spinlock, so there may exist a data race.

Thanks for the report.

The actual crash must be very unlikely, almost 0%, though. snd_trident_hw_free() is called always after the PCM stream gets stopped via trigger callback, i.e. at the moment, there is no corresponding interrupt is generated for that voice entry.

Quoted 5 lines
Quoted 3 lines

How about the case that playback and capture are performed concurrently? Namely, snd_trident_hw_free() is called for playback, and the interrupt is generated for capture.

They are different substreams, hence it won't pick up the substream object.

Actually, I performed a runtime testing, and found that snd_trident_hw_free() and snd_trident_interrupt() are executed concurrently. However, I did not check the substream object, so I guess this report was produced in the case that I mentioned. Anyway, my report should be false, sorry...

Best wishes,
Jia-Ju Bai