From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BEB5EC43603 for ; Tue, 10 Dec 2019 17:26:39 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C62120836 for ; Tue, 10 Dec 2019 17:26:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="A9hhG/LF" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C62120836 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 8AD2941; Tue, 10 Dec 2019 18:25:47 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8AD2941 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1575998797; bh=YmYJffGf+3cY32ywA3ugPcc/3me0N2JNVKmBpPLqnnA=; h=Date:From:To:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=A9hhG/LFTj61XyG/Hi+x4nt/+cBVADQLDgiepMLqQPlBfLeALhCGtCFK+II5fH+00 tKuDZeHO7lnhTy4TFuOqgBj6YBMzz0X1jZkT/SV66eoCQj80Tn2HCG1fmx6mSv2YRN Kb0jLmSGrBgIQhq80rLM5L7V6v+2hj5wJOGux+tg= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 098BAF8011E; Tue, 10 Dec 2019 18:25:46 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id DD3E4F8020C; Tue, 10 Dec 2019 18:25:44 +0100 (CET) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 02088F8011E for ; Tue, 10 Dec 2019 18:25:41 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 02088F8011E X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id DDDCEACF2; Tue, 10 Dec 2019 17:25:39 +0000 (UTC) Date: Tue, 10 Dec 2019 18:25:39 +0100 Message-ID: From: Takashi Iwai To: alsa-devel@alsa-project.org In-Reply-To: <20191210130219.27919-1-tiwai@suse.de> References: <20191210130219.27919-1-tiwai@suse.de> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Cc: Lionel Koenig Subject: Re: [alsa-devel] [PATCH] ALSA: pcm: Fill silence on buffers at hw_params X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Tue, 10 Dec 2019 14:02:19 +0100, Takashi Iwai wrote: > > The current PCM code doesn't initialize explicitly the buffers > allocated for PCM streams, hence it might leak some uninitialized > kernel data by mmapping or reading the buffer before actually reading > or writing. > > Since this is a common problem, let's initialize the data on the > buffers each hw_params properly. For that, an existing helper > function is exposed as snd_pcm_fill_silence_frames() and call it from > snd_pcm_hw_params(). > > Reported-and-tested-by: Lionel Koenig > Cc: > Signed-off-by: Takashi Iwai On the second thought, this use of fill_silence ops might have some side-effect on the drivers that do actually transfer stream data by that ops. So I dropped this patch again. Will submit the revised patch later. Sorry for the trouble. Takashi > --- > sound/core/pcm_lib.c | 13 ++++--------- > sound/core/pcm_local.h | 2 ++ > sound/core/pcm_native.c | 3 +++ > 3 files changed, 9 insertions(+), 9 deletions(-) > > diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c > index 2236b5e0c1f2..3c63324b8bb7 100644 > --- a/sound/core/pcm_lib.c > +++ b/sound/core/pcm_lib.c > @@ -30,9 +30,6 @@ > #define trace_applptr(substream, prev, curr) > #endif > > -static int fill_silence_frames(struct snd_pcm_substream *substream, > - snd_pcm_uframes_t off, snd_pcm_uframes_t frames); > - > /* > * fill ring buffer with silence > * runtime->silence_start: starting pointer to silence area > @@ -100,7 +97,7 @@ void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_ufram > ofs = runtime->silence_start % runtime->buffer_size; > while (frames > 0) { > transfer = ofs + frames > runtime->buffer_size ? runtime->buffer_size - ofs : frames; > - err = fill_silence_frames(substream, ofs, transfer); > + err = snd_pcm_fill_silence_frames(substream, ofs, transfer); > snd_BUG_ON(err < 0); > runtime->silence_filled += transfer; > frames -= transfer; > @@ -1945,8 +1942,6 @@ static int fill_silence(struct snd_pcm_substream *substream, int channel, > { > struct snd_pcm_runtime *runtime = substream->runtime; > > - if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) > - return 0; > if (substream->ops->fill_silence) > return substream->ops->fill_silence(substream, channel, > hwoff, bytes); > @@ -2030,10 +2025,10 @@ static int noninterleaved_copy(struct snd_pcm_substream *substream, > } > > /* fill silence on the given buffer position; > - * called from snd_pcm_playback_silence() > + * called from snd_pcm_playback_silence() and snd_pcm_hw_params() > */ > -static int fill_silence_frames(struct snd_pcm_substream *substream, > - snd_pcm_uframes_t off, snd_pcm_uframes_t frames) > +int snd_pcm_fill_silence_frames(struct snd_pcm_substream *substream, > + snd_pcm_uframes_t off, snd_pcm_uframes_t frames) > { > if (substream->runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED || > substream->runtime->access == SNDRV_PCM_ACCESS_MMAP_INTERLEAVED) > diff --git a/sound/core/pcm_local.h b/sound/core/pcm_local.h > index 384efd002984..ac4f455b1fff 100644 > --- a/sound/core/pcm_local.h > +++ b/sound/core/pcm_local.h > @@ -34,6 +34,8 @@ int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream); > > void snd_pcm_playback_silence(struct snd_pcm_substream *substream, > snd_pcm_uframes_t new_hw_ptr); > +int snd_pcm_fill_silence_frames(struct snd_pcm_substream *substream, > + snd_pcm_uframes_t off, snd_pcm_uframes_t frames); > > static inline snd_pcm_uframes_t > snd_pcm_avail(struct snd_pcm_substream *substream) > diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c > index 1fe581167b7b..d6f270c639b4 100644 > --- a/sound/core/pcm_native.c > +++ b/sound/core/pcm_native.c > @@ -739,6 +739,9 @@ static int snd_pcm_hw_params(struct snd_pcm_substream *substream, > while (runtime->boundary * 2 <= LONG_MAX - runtime->buffer_size) > runtime->boundary *= 2; > > + /* clear the buffer once for avoiding information leaks */ > + snd_pcm_fill_silence_frames(substream, 0, runtime->period_size); > + > snd_pcm_timer_resolution_change(substream); > snd_pcm_set_state(substream, SNDRV_PCM_STATE_SETUP); > > -- > 2.16.4 > _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org https://mailman.alsa-project.org/mailman/listinfo/alsa-devel