ALSA: emu10k1: fix return value of snd_emu1010_adc_pads_put()
PATCH 1/3 ALSA: emu10k1: fix return value of snd_emu1010_adc_pads_put()
It returned zero even if the value had changed.
---
this should have been in cc766807a2 (fix return value of snd_emu1010_dac_pads_put()), but, well.
--- sound/pci/emu10k1/emumixer.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
sound/pci/emu10k1/emumixer.c +5 -2
@@ -770,18 +770,21 @@ static int snd_emu1010_adc_pads_put(struct snd_kcontrol *kcontrol, struct snd_ctstruct snd_emu10k1 *emu =snd_kcontrol_chip (kcontrol);unsigned int mask = snd_emu1010_adc_pad_regs[kcontrol->private_value];unsigned int val, cache; +int change; + val = ucontrol->value.integer.value[0 ]; cache = emu->emu1010.adc_pads;if (val ==1 ) cache = cache | mask;else cache = cache & ~mask; -if (cache != emu->emu1010.adc_pads) { + change = (cache != emu->emu1010.adc_pads); +if (change) {snd_emu1010_fpga_write (emu,EMU_HANA_ADC_PADS , cache ); emu->emu1010.adc_pads = cache; } -return 0 ; +return change; }static const struct snd_kcontrol_new emu1010_adc_pads_ctl = {
Signature · 1 line
2.40.0.152.g15d061e6df
PATCH 2/3 ALSA: emu10k1: remove superfluous IRQ enable state saving
The mixer, PCM prepare, MIDI, synth driver, and procfs callbacks are all always invoked with IRQs enabled, so there is no point in saving the state.
snd_emu1010_load_firmware_entry() is called from emu1010_firmware_work() and snd_emu10k1_emu1010_init(); the latter from snd_emu10k1_create() and snd_emu10k1_resume(), all of which have IRQs enabled.
The voice and memory functions are called from mixed contexts, so they keep the state saving.
The low-level functions all keep the state saving, because it's not feasible to keep track of what is called where.
--- sound/pci/emu10k1/emu10k1_main.c | 5 ++-- sound/pci/emu10k1/emu10k1_synth.c | 10 +++---- sound/pci/emu10k1/emumixer.c | 45 +++++++++++++------------------ sound/pci/emu10k1/emumpu401.c | 40 ++++++++++++--------------- sound/pci/emu10k1/emupcm.c | 6 ++--- sound/pci/emu10k1/emuproc.c | 10 +++---- 6 files changed, 47 insertions(+), 69 deletions(-)
sound/pci/emu10k1/emu10k1_main.c +2 -3
@@ -664,19 +664,18 @@ static int snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu,u16 reg;u8 value;__always_unused u16 write_post; -unsigned long flags;if (!fw_entry)return -EIO ;/* The FPGA is a Xilinx Spartan IIE XC2S50E */ /* On E-MU 0404b it is a Xilinx Spartan III XC3S50 */ /* GPIO7 -> FPGA PGMN * GPIO6 -> FPGA CCLK * GPIO5 -> FPGA DIN * FPGA CONFIG OFF -> FPGA PGMN */ -spin_lock_irqsave (&emu->emu_lock, flags); +spin_lock_irq (&emu->emu_lock);outw (0x00 , emu->port +A_GPIO );/* Set PGMN low for 100uS. */ write_post =inw (emu->port +A_GPIO );udelay (100 );
@@ -699,7 +698,7 @@ static int snd_emu1010_load_firmware_entry(struct snd_emu10k1 *emu,/* After programming, set GPIO bit 4 high again. */ outw (0x10 , emu->port +A_GPIO ); write_post =inw (emu->port +A_GPIO ); -spin_unlock_irqrestore (&emu->emu_lock, flags); +spin_unlock_irq (&emu->emu_lock);return 0 ; }
sound/pci/emu10k1/emu10k1_synth.c +4 -6
@@ -22,7 +22,6 @@ static int snd_emu10k1_synth_probe(struct device *_dev)struct snd_emux *emux;struct snd_emu10k1 *hw;struct snd_emu10k1_synth_arg *arg; -unsigned long flags; arg =SNDRV_SEQ_DEVICE_ARGPTR (dev);if (arg ==NULL )
@@ -56,33 +55,32 @@ static int snd_emu10k1_synth_probe(struct device *_dev)return -ENOMEM ; } -spin_lock_irqsave (&hw->voice_lock, flags); +spin_lock_irq (&hw->voice_lock); hw->synth = emux; hw->get_synth_voice = snd_emu10k1_synth_get_voice; -spin_unlock_irqrestore (&hw->voice_lock, flags); +spin_unlock_irq (&hw->voice_lock); dev->driver_data = emux;return 0 ; }static int snd_emu10k1_synth_remove (struct device *_dev) {struct snd_seq_device *dev =to_seq_dev (_dev);struct snd_emux *emux;struct snd_emu10k1 *hw; -unsigned long flags;if (dev->driver_data ==NULL )return 0 ;/* not registered actually */ emux = dev->driver_data; hw = emux->hw; -spin_lock_irqsave (&hw->voice_lock, flags); +spin_lock_irq (&hw->voice_lock); hw->synth =NULL ; hw->get_synth_voice =NULL ; -spin_unlock_irqrestore (&hw->voice_lock, flags); +spin_unlock_irq (&hw->voice_lock);snd_emux_free (emux);return 0 ;
sound/pci/emu10k1/emumixer.c +18 -27
213 lines not on this page · raw message
sound/pci/emu10k1/emumpu401.c +17 -23
@@ -104,10 +104,9 @@ static void snd_emu10k1_midi_interrupt2(struct snd_emu10k1 *emu, unsigned int ststatic int snd_emu10k1_midi_cmd (struct snd_emu10k1 * emu,struct snd_emu10k1_midi *midi,unsigned char cmd,int ack) { -unsigned long flags;int timeout, ok; -spin_lock_irqsave (&midi->input_lock, flags); +spin_lock_irq (&midi->input_lock);mpu401_write_data (emu, midi,0x00 );/* mpu401_clear_rx(emu, midi); */
@@ -126,7 +125,7 @@ static int snd_emu10k1_midi_cmd(struct snd_emu10k1 * emu, struct snd_emu10k1_mid }else { ok =1 ; } -spin_unlock_irqrestore (&midi->input_lock, flags); +spin_unlock_irq (&midi->input_lock);if (!ok) { dev_err(emu->card->dev, "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
@@ -142,98 +141,94 @@ static int snd_emu10k1_midi_input_open(struct snd_rawmidi_substream *substream) {struct snd_emu10k1 *emu;struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; -unsigned long flags; emu = midi->emu;if (snd_BUG_ON (!emu))return -ENXIO ; -spin_lock_irqsave (&midi->open_lock, flags); +spin_lock_irq (&midi->open_lock); midi->midi_mode |=EMU10K1_MIDI_MODE_INPUT ; midi->substream_input = substream;if (!(midi->midi_mode &EMU10K1_MIDI_MODE_OUTPUT )) { -spin_unlock_irqrestore (&midi->open_lock, flags); +spin_unlock_irq (&midi->open_lock);if (snd_emu10k1_midi_cmd (emu, midi,MPU401_RESET ,1 )) goto error_out;if (snd_emu10k1_midi_cmd (emu, midi,MPU401_ENTER_UART ,1 )) goto error_out; }else { -spin_unlock_irqrestore (&midi->open_lock, flags); +spin_unlock_irq (&midi->open_lock); }return 0 ; error_out:return -EIO ; }static int snd_emu10k1_midi_output_open (struct snd_rawmidi_substream *substream) {struct snd_emu10k1 *emu;struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; -unsigned long flags; emu = midi->emu;if (snd_BUG_ON (!emu))return -ENXIO ; -spin_lock_irqsave (&midi->open_lock, flags); +spin_lock_irq (&midi->open_lock); midi->midi_mode |=EMU10K1_MIDI_MODE_OUTPUT ; midi->substream_output = substream;if (!(midi->midi_mode &EMU10K1_MIDI_MODE_INPUT )) { -spin_unlock_irqrestore (&midi->open_lock, flags); +spin_unlock_irq (&midi->open_lock);if (snd_emu10k1_midi_cmd (emu, midi,MPU401_RESET ,1 )) goto error_out;if (snd_emu10k1_midi_cmd (emu, midi,MPU401_ENTER_UART ,1 )) goto error_out; }else { -spin_unlock_irqrestore (&midi->open_lock, flags); +spin_unlock_irq (&midi->open_lock); }return 0 ; error_out:return -EIO ; }static int snd_emu10k1_midi_input_close (struct snd_rawmidi_substream *substream) {struct snd_emu10k1 *emu;struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; -unsigned long flags;int err =0 ; emu = midi->emu;if (snd_BUG_ON (!emu))return -ENXIO ; -spin_lock_irqsave (&midi->open_lock, flags); +spin_lock_irq (&midi->open_lock);snd_emu10k1_intr_disable (emu, midi->rx_enable); midi->midi_mode &= ~EMU10K1_MIDI_MODE_INPUT ; midi->substream_input =NULL ;if (!(midi->midi_mode &EMU10K1_MIDI_MODE_OUTPUT )) { -spin_unlock_irqrestore (&midi->open_lock, flags); +spin_unlock_irq (&midi->open_lock); err =snd_emu10k1_midi_cmd (emu, midi,MPU401_RESET ,0 ); }else { -spin_unlock_irqrestore (&midi->open_lock, flags); +spin_unlock_irq (&midi->open_lock); }return err; }static int snd_emu10k1_midi_output_close (struct snd_rawmidi_substream *substream) {struct snd_emu10k1 *emu;struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; -unsigned long flags;int err =0 ; emu = midi->emu;if (snd_BUG_ON (!emu))return -ENXIO ; -spin_lock_irqsave (&midi->open_lock, flags); +spin_lock_irq (&midi->open_lock);snd_emu10k1_intr_disable (emu, midi->tx_enable); midi->midi_mode &= ~EMU10K1_MIDI_MODE_OUTPUT ; midi->substream_output =NULL ;if (!(midi->midi_mode &EMU10K1_MIDI_MODE_INPUT )) { -spin_unlock_irqrestore (&midi->open_lock, flags); +spin_unlock_irq (&midi->open_lock); err =snd_emu10k1_midi_cmd (emu, midi,MPU401_RESET ,0 ); }else { -spin_unlock_irqrestore (&midi->open_lock, flags); +spin_unlock_irq (&midi->open_lock); }return err; }
@@ -256,33 +251,32 @@ static void snd_emu10k1_midi_output_trigger(struct snd_rawmidi_substream *substr {struct snd_emu10k1 *emu;struct snd_emu10k1_midi *midi = (struct snd_emu10k1_midi *)substream->rmidi->private_data; -unsigned long flags; emu = midi->emu;if (snd_BUG_ON (!emu))return ;if (up) {int max =4 ;unsigned char byte;/* try to send some amount of bytes here before interrupts */ -spin_lock_irqsave (&midi->output_lock, flags); +spin_lock_irq (&midi->output_lock);while (max >0 ) {if (mpu401_output_ready (emu, midi)) {if (!(midi->midi_mode &EMU10K1_MIDI_MODE_OUTPUT ) ||snd_rawmidi_transmit (substream, &byte,1 ) !=1 ) {/* no more data */ -spin_unlock_irqrestore (&midi->output_lock, flags); +spin_unlock_irq (&midi->output_lock);return ; }mpu401_write_data (emu, midi, byte); max--; }else {break ; } } -spin_unlock_irqrestore (&midi->output_lock, flags); +spin_unlock_irq (&midi->output_lock);snd_emu10k1_intr_enable (emu, midi->tx_enable); }else {snd_emu10k1_intr_disable (emu, midi->tx_enable);
sound/pci/emu10k1/emupcm.c +2 -4
@@ -343,19 +343,17 @@ static void snd_emu10k1_pcm_init_voices(struct snd_emu10k1 *emu,unsigned int end_addr, struct snd_emu10k1_pcm_mixer *mix) { - unsigned long flags; - -spin_lock_irqsave (&emu->reg_lock, flags); + spin_lock_irq(&emu->reg_lock);snd_emu10k1_pcm_init_voice (emu, evoice, w_16, stereo, start_addr, end_addr, &mix->send_routing[stereo][0 ], &mix->send_volume[stereo][0 ]);if (stereo)snd_emu10k1_pcm_init_voice (emu, evoice +1 , w_16, true, start_addr, end_addr, &mix->send_routing[2 ][0 ], &mix->send_volume[2 ][0 ]); -spin_unlock_irqrestore (&emu->reg_lock, flags); +spin_unlock_irq (&emu->reg_lock); } static void snd_emu10k1_pcm_init_extra_voice(struct snd_emu10k1 *emu,
sound/pci/emu10k1/emuproc.c +4 -6
@@ -536,33 +536,31 @@ static unsigned int snd_ptr_read(struct snd_emu10k1 * emu, unsigned int reg, unsigned int chn) { -unsigned long flags;unsigned int regptr, val; regptr = (reg <<16 ) | chn; -spin_lock_irqsave (&emu->emu_lock, flags); +spin_lock_irq (&emu->emu_lock);outl (regptr, emu->port + iobase +PTR ); val =inl (emu->port + iobase +DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); +spin_unlock_irq (&emu->emu_lock);return val; }static void snd_ptr_write (struct snd_emu10k1 *emu,unsigned int iobase,unsigned int reg,unsigned int chn,unsigned int data) {unsigned int regptr; -unsigned long flags; regptr = (reg <<16 ) | chn; -spin_lock_irqsave (&emu->emu_lock, flags); +spin_lock_irq (&emu->emu_lock);outl (regptr, emu->port + iobase +PTR );outl (data, emu->port + iobase +DATA ); -spin_unlock_irqrestore (&emu->emu_lock, flags); +spin_unlock_irq (&emu->emu_lock); }
Signature · 1 line
2.40.0.152.g15d061e6df
Re: [PATCH 2/3] ALSA: emu10k1: remove superfluous IRQ enable state saving
Quoted 9 lines · Oswald Buddenhagen
The mixer, PCM prepare, MIDI, synth driver, and procfs callbacks are all always invoked with IRQs enabled, so there is no point in saving the state.
snd_emu1010_load_firmware_entry()is called fromemu1010_firmware_work()andsnd_emu10k1_emu1010_init(); the latter fromsnd_emu10k1_create()andsnd_emu10k1_resume(), all of which have IRQs enabled.
Quoted 7 lines
The voice and memory functions are called from mixed contexts, so they keep the state saving.
The low-level functions all keep the state saving, because it's not feasible to keep track of what is called where.
Signed-off-by Oswald Buddenhagen <[email protected]>
Wouldn't it make more sense if you replace it with a mutex? It'll become more obvious that it's only for non-IRQ context, too.
thanks,
Takashi
Re: [PATCH 2/3] ALSA: emu10k1: remove superfluous IRQ enable state saving
Quoted 11 lines · Takashi Iwai
Quoted 9 lines · Oswald Buddenhagen
The mixer, PCM prepare, MIDI, synth driver, and procfs callbacks are all always invoked with IRQs enabled, so there is no point in saving the state.
snd_emu1010_load_firmware_entry()is called fromemu1010_firmware_work()andsnd_emu10k1_emu1010_init(); the latter fromsnd_emu10k1_create()andsnd_emu10k1_resume(), all of which have IRQs enabled.
Quoted 9 lines
Quoted 6 lines
The voice and memory functions are called from mixed contexts, so they keep the state saving.
The low-level functions all keep the state saving, because it's not feasible to keep track of what is called where.
Wouldn't it make more sense if you replace it with a mutex? It'll become more obvious that it's only for non-IRQ context, too.
huh?
at least some of the ~six different locks touched by this patch absolutely _are_ used in irq context. this patch is concerned only about the specific call sites, where we know that local irqs are enabled, so we can unconditionally re-enable them rather than restoring the old state (the latter being a much more expensive operation). the code already contains precedents for this, and the complementary optimization of not disabling/restoring irqs where we know that they are already disabled.
the reg_lock would be convertible to a mixer_mutex in most mixer callbacks, but that is an orthogonal question, which is raised in the next commit.
regards
Re: [PATCH 2/3] ALSA: emu10k1: remove superfluous IRQ enable state saving
Quoted 32 lines · Oswald Buddenhagen
Quoted 11 lines · Takashi Iwai
Quoted 9 lines · Oswald Buddenhagen
The mixer, PCM prepare, MIDI, synth driver, and procfs callbacks are all always invoked with IRQs enabled, so there is no point in saving the state.
snd_emu1010_load_firmware_entry()is called fromemu1010_firmware_work()andsnd_emu10k1_emu1010_init(); the latter fromsnd_emu10k1_create()andsnd_emu10k1_resume(), all of which have IRQs enabled.Quoted 9 lines
Quoted 6 lines
The voice and memory functions are called from mixed contexts, so they keep the state saving.
The low-level functions all keep the state saving, because it's not feasible to keep track of what is called where.
Wouldn't it make more sense if you replace it with a mutex? It'll become more obvious that it's only for non-IRQ context, too.
huh?
at least some of the ~six different locks touched by this patch absolutely _are_ used in irq context. this patch is concerned only about the specific call sites, where we know that local irqs are enabled, so we can unconditionally re-enable them rather than restoring the old state (the latter being a much more expensive operation). the code already contains precedents for this, and the complementary optimization of not disabling/restoring irqs where we know that they are already disabled.
Quoted 3 lines
the
reg_lockwould be convertible to amixer_mutexin most mixer callbacks, but that is an orthogonal question, which is raised in the next commit.
Ah, sorry, I misread as if it were dropping the whole *_irq. Then the patch should be fine.
Takashi
Re: [PATCH 2/3] ALSA: emu10k1: remove superfluous IRQ enable state saving
In reply to Oswald BuddenhagenQuoted 9 lines · Oswald Buddenhagen
The mixer, PCM prepare, MIDI, synth driver, and procfs callbacks are all always invoked with IRQs enabled, so there is no point in saving the state.
snd_emu1010_load_firmware_entry()is called fromemu1010_firmware_work()andsnd_emu10k1_emu1010_init(); the latter fromsnd_emu10k1_create()andsnd_emu10k1_resume(), all of which have IRQs enabled.
Quoted 7 lines
The voice and memory functions are called from mixed contexts, so they keep the state saving.
The low-level functions all keep the state saving, because it's not feasible to keep track of what is called where.
Signed-off-by Oswald Buddenhagen <[email protected]>
Applied now. Thanks.
Takashi
PATCH 3/3 ALSA: emu10k1: (re-)add mixer locking
In reply to Oswald BuddenhagenTakashi now "prefers" that the drivers do not rely on the core's locking of card->controls_rwsem, so we undo 06405d8ee8 ("ALSA: emu10k1: remove now superfluous mixer locking") and add more locks that were already missing.
This adds some rather significant critical sections with IRQs disabled, as emu->reg_lock is also accessed by the PCM trigger callbacks, which are called with the hardirq-safe (self-)group lock held.
---
the long irq-disabled sections could be avoided by introducing a separate control mutex. i surveyed a few drivers, and the precedents are very mixed, so i'm not sure this would be considered worth it.
---
of the few drivers i checked, pcsp, ak4xxx-adda, pt2258, hal2, sgio2audio, au88x0_eq, and ca0106_mixer appear to be missing locking upon superficial inspection, a percentage well into the double digits.
given that there are ~3700 hits for snd_kcontrol_new (and many more _put() methods to check, due to initializer arrays), the whole endeavor seems just as utterly hopeless to me as i expected.
so i recommend that you reconsider, and consequently reject this patch.
--- sound/pci/emu10k1/emufx.c | 5 +++++ sound/pci/emu10k1/emumixer.c | 42 ++++++++++++++++++++++++++++++++++-- sound/pci/emu10k1/emupcm.c | 2 ++ sound/pci/emu10k1/p16v.c | 7 ++++++ 4 files changed, 54 insertions(+), 2 deletions(-)
sound/pci/emu10k1/emufx.c +5 -0
@@ -353,12 +353,15 @@ static int snd_emu10k1_gpr_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctstatic int snd_emu10k1_gpr_ctl_get (struct snd_kcontrol *kcontrol,struct snd_ctl_elem_value *ucontrol) { +struct snd_emu10k1 *emu =snd_kcontrol_chip (kcontrol);struct snd_emu10k1_fx8010_ctl *ctl = (struct snd_emu10k1_fx8010_ctl *) kcontrol->private_value;unsigned int i; +spin_lock_irq (&emu->reg_lock);for (i =0 ; i < ctl->vcount; i++) ucontrol->value.integer.value[i] = ctl->value[i]; +spin_unlock_irq (&emu->reg_lock);return 0 ; }
@@ -371,6 +374,7 @@ static int snd_emu10k1_gpr_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctlunsigned int i, j;int change =0 ; +spin_lock_irq (&emu->reg_lock);for (i =0 ; i < ctl->vcount; i++) { nval = ucontrol->value.integer.value[i];if (nval < ctl->min)
@@ -416,6 +420,7 @@ static int snd_emu10k1_gpr_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl } } __error: +spin_unlock_irq (&emu->reg_lock);return change; }
sound/pci/emu10k1/emumixer.c +40 -2
255 lines not on this page · raw message
sound/pci/emu10k1/emupcm.c +2 -0
@@ -1541,8 +1541,10 @@ static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol *kcontrol, stint nefx = emu->audigy ?64 :32 ;int idx; +spin_lock_irq (&emu->reg_lock);for (idx =0 ; idx < nefx; idx++) ucontrol->value.integer.value[idx] = (emu->efx_voices_mask[idx /32 ] & (1 << (idx %32 ))) ?1 :0 ; +spin_unlock_irq (&emu->reg_lock);return 0 ; }
sound/pci/emu10k1/p16v.c +7 -0
@@ -635,6 +635,7 @@ static int snd_p16v_volume_put(struct snd_kcontrol *kcontrol,int reg = kcontrol->private_value &0xff ;u32 value, oval; +spin_lock_irq (&emu->reg_lock); oval = value =snd_emu10k1_ptr20_read (emu, reg,0 );if (high_low ==1 ) { value &=0xffff ;
@@ -647,8 +648,10 @@ static int snd_p16v_volume_put(struct snd_kcontrol *kcontrol, }if (value != oval) {snd_emu10k1_ptr20_write (emu, reg,0 , value); +spin_unlock_irq (&emu->reg_lock);return 1 ; } +spin_unlock_irq (&emu->reg_lock);return 0 ; }
@@ -684,13 +687,15 @@ static int snd_p16v_capture_source_put(struct snd_kcontrol *kcontrol, val = ucontrol->value.enumerated.item[0 ] ;if (val >7 )return -EINVAL ; +spin_lock_irq (&emu->reg_lock); change = (emu->p16v_capture_source != val);if (change) { emu->p16v_capture_source = val; source = (val <<28 ) | (val <<24 ) | (val <<20 ) | (val <<16 ); mask =snd_emu10k1_ptr20_read (emu,BASIC_INTERRUPT ,0 ) &0xffff ;snd_emu10k1_ptr20_write (emu,BASIC_INTERRUPT ,0 , source | mask); } +spin_unlock_irq (&emu->reg_lock);return change; }
@@ -722,12 +727,14 @@ static int snd_p16v_capture_channel_put(struct snd_kcontrol *kcontrol, val = ucontrol->value.enumerated.item[0 ] ;if (val >3 )return -EINVAL ; +spin_lock_irq (&emu->reg_lock); change = (emu->p16v_capture_channel != val);if (change) { emu->p16v_capture_channel = val; tmp =snd_emu10k1_ptr20_read (emu,CAPTURE_P16V_SOURCE ,0 ) &0xfffc ;snd_emu10k1_ptr20_write (emu,CAPTURE_P16V_SOURCE ,0 , tmp | val); } +spin_unlock_irq (&emu->reg_lock);return change; } static const DECLARE_TLV_DB_SCALE(snd_p16v_db_scale1, -5175, 25, 1);
Signature · 1 line
2.40.0.152.g15d061e6df
Re: [PATCH 3/3] ALSA: emu10k1: (re-)add mixer locking
Quoted 22 lines · Oswald Buddenhagen
Takashi now "prefers" that the drivers do not rely on the core's locking of
card->controls_rwsem, so we undo06405d8ee8("ALSA: emu10k1: remove now superfluous mixer locking") and add more locks that were already missing.This adds some rather significant critical sections with IRQs disabled, as
emu->reg_lockis also accessed by the PCM trigger callbacks, which are called with the hardirq-safe (self-)group lock held.Signed-off-by Oswald Buddenhagen <[email protected]>---
the long irq-disabled sections could be avoided by introducing a separate control mutex. i surveyed a few drivers, and the precedents are very mixed, so i'm not sure this would be considered worth it.---
of the few drivers i checked, pcsp, ak4xxx-adda, pt2258, hal2, sgio2audio,au88x0_eq, andca0106_mixerappear to be missing locking upon superficial inspection, a percentage well into the double digits.
Quoted 5 lines
given that there are ~3700 hits for
snd_kcontrol_new(and many more_put()methods to check, due to initializer arrays), the whole endeavor seems just as utterly hopeless to me as i expected.so i recommend that you reconsider, and consequently reject this patch.
I applied this patch now. We may optimize out the whole locking conditionally for the known-good drivers, instead of relying on a (hackish) big iron lock that wasn't considered to be used originally at all.
thanks,
Takashi
Re: [PATCH 3/3] ALSA: emu10k1: (re-)add mixer locking
Quoted 2 lines · Takashi Iwai
We may optimize out the whole locking conditionally for the known-good drivers,
well, that would work, though obviously someone would still have to check the drivers and set the flag. also, this kind of technically unnecessary fragmentation doesn't really help.
Quoted 2 lines
instead of relying on a (hackish) big iron lock that wasn't considered to be used originally at all.
i think you're focusing on the wrong thing here.
the fact that the lock was originally meant to do something else is meaningless. you could just as well create a dedicated lock specifically for that task - the important thing is that the core would provide a guarantee to the drivers that mixer callbacks are locked, just like it does for some pcm callbacks unless the driver opts out. given that mixer operations are rare in the big picture, fine-grained locking in the drivers is unnecessary (except where not mixer-only data is accessed). given the amount of code this saves, this seems like a rather worthwhile trade-off with the formal cleanness of drivers having self-contained locking.
regards
Re: [PATCH 3/3] ALSA: emu10k1: (re-)add mixer locking
Quoted 12 lines · Oswald Buddenhagen
Quoted 3 lines · Takashi Iwai
We may optimize out the whole locking conditionally for the known-good drivers,
well, that would work, though obviously someone would still have to check the drivers and set the flag. also, this kind of technically unnecessary fragmentation doesn't really help.
Quoted 3 lines
instead of relying on a (hackish) big iron lock that wasn't considered to be used originally at all.
Quoted 11 lines
i think you're focusing on the wrong thing here.
the fact that the lock was originally meant to do something else is meaningless. you could just as well create a dedicated lock specifically for that task - the important thing is that the core would provide a guarantee to the drivers that mixer callbacks are locked, just like it does for some pcm callbacks unless the driver opts out. given that mixer operations are rare in the big picture, fine-grained locking in the drivers is unnecessary (except where not mixer-only data is accessed). given the amount of code this saves, this seems like a rather worthwhile trade-off with the formal cleanness of drivers having self-contained locking.
My whole point is that no driver should touch card->controls_rwsem from outside (unless the driver needs to traverse the card's linked list by some special reasons). It's not for protecting the driver's own content. It's used casually now for get/put, but it should be seen only for protecting the list.
Unlike PCM, the control get/put has never been considered to be fully protected, and it was always driver's responsibility.
Takashi
Re: [PATCH 3/3] ALSA: emu10k1: (re-)add mixer locking
Quoted 19 lines · Takashi Iwai
Quoted 5 lines · Oswald Buddenhagen
Quoted 3 lines · Takashi Iwai
instead of relying on a (hackish) big iron lock that wasn't considered to be used originally at all.
Quoted 11 lines
i think you're focusing on the wrong thing here.
the fact that the lock was originally meant to do something else is meaningless. you could just as well create a dedicated lock specifically for that task - the important thing is that the core would provide a guarantee to the drivers that mixer callbacks are locked, just like it does for some pcm callbacks unless the driver opts out. given that mixer operations are rare in the big picture, fine-grained locking in the drivers is unnecessary (except where not mixer-only data is accessed). given the amount of code this saves, this seems like a rather worthwhile trade-off with the formal cleanness of drivers having self-contained locking.
Quoted 4 lines
My whole point is that no driver should touch
card->controls_rwsemfrom outside (unless the driver needs to traverse the card's linked list by some special reasons).
nothing in what i wrote even suggests that it _should_. how a driver would explicitly interact with _a_ mixer callback lock is entirely open so far.
Quoted 3 lines
Unlike PCM, the control get/put has never been considered to be fully protected,
the whole argument is that it _should_.
Quoted 2 lines
and it was always driver's responsibility.
clearly a responsibility that has been widely shirked, even before it was actually safe to do so. the pragmatic thing to do would be accepting this reality and ensuring locking by the core, in whichever way.
regards
Re: [PATCH 3/3] ALSA: emu10k1: (re-)add mixer locking
Quoted 31 lines · Oswald Buddenhagen
Quoted 18 lines · Takashi Iwai
Quoted 5 lines · Oswald Buddenhagen
Quoted 3 lines · Takashi Iwai
instead of relying on a (hackish) big iron lock that wasn't considered to be used originally at all.
i think you're focusing on the wrong thing here.Quoted 10 lines
the fact that the lock was originally meant to do something else is meaningless. you could just as well create a dedicated lock specifically for that task - the important thing is that the core would provide a guarantee to the drivers that mixer callbacks are locked, just like it does for some pcm callbacks unless the driver opts out. given that mixer operations are rare in the big picture, fine-grained locking in the drivers is unnecessary (except where not mixer-only data is accessed). given the amount of code this saves, this seems like a rather worthwhile trade-off with the formal cleanness of drivers having self-contained locking.
Quoted 4 lines
My whole point is that no driver should touch
card->controls_rwsemfrom outside (unless the driver needs to traverse the card's linked list by some special reasons).nothing in what i wrote even suggests that it _should_. how a driver would explicitly interact with _a_ mixer callback lock is entirely open so far.
Quoted 3 lines
Unlike PCM, the control get/put has never been considered to be fully protected,
Quoted 8 lines
the whole argument is that it _should_.
Quoted 2 lines
and it was always driver's responsibility.
clearly a responsibility that has been widely shirked, even before it was actually safe to do so. the pragmatic thing to do would be accepting this reality and ensuring locking by the core, in whichever way.
Well, I took your patch 3 just because you wanted to have a protection of your data from both get/put callback and from another code path in another patch. It was an (ab)use of controls->rwsem that couldn't be accepted, so the patch 3 was taken as an alternative.
If this isn't the scenario, let me know: I'd rather drop the patch again, as it's superfluous.
Again, my point is that you shouldn't use controls_rwsem for the driver's data protection purpose.
There's many rooms for improvements in ALSA core, and things may change. So, if the driver needs to protect its own data from both mixer code path and from another, use the own lock, instead of touching controls_rwsem (which is basically an internal stuff for ALSA control core).
Takashi
Re: [PATCH 3/3] ALSA: emu10k1: (re-)add mixer locking
Quoted 8 lines · Takashi Iwai
Well, I took your patch 3 just because you wanted to have a protection of your data from both get/put callback and from another code path in another patch. It was an (ab)use of
controls->rwsemthat couldn't be accepted, so the patch 3 was taken as an alternative.If this isn't the scenario, let me know: I'd rather drop the patch again, as it's superfluous.
ok, then please drop it.
you're quite right that this is the scenario, but i can do that selectively just as well, like it already is the case in some other callbacks. i just wanted to have this patch first if it was to be applied at all, because it seemed cleaner.
regards
Re: [PATCH 3/3] ALSA: emu10k1: (re-)add mixer locking
Quoted 10 lines · Oswald Buddenhagen
Quoted 8 lines · Takashi Iwai
Well, I took your patch 3 just because you wanted to have a protection of your data from both get/put callback and from another code path in another patch. It was an (ab)use of
controls->rwsemthat couldn't be accepted, so the patch 3 was taken as an alternative.If this isn't the scenario, let me know: I'd rather drop the patch again, as it's superfluous.
Quoted 6 lines
ok, then please drop it.
you're quite right that this is the scenario, but i can do that selectively just as well, like it already is the case in some other callbacks. i just wanted to have this patch first if it was to be applied at all, because it seemed cleaner.
OK, dropped now.
thanks,
Takashi
Takashi Iwai
AppliedQuoted 4 lines · Oswald Buddenhagen
It returned zero even if the value had changed.
Signed-off-by Oswald Buddenhagen <[email protected]>
Applied this one. Thanks.
Takashi