Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E57C3C433EF for ; Sun, 17 Oct 2021 07:45:31 +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 E655761027 for ; Sun, 17 Oct 2021 07:45:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E655761027 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=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 4873A17DA; Sun, 17 Oct 2021 09:44:39 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 4873A17DA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1634456729; bh=JHn2jaYsg3socWKkQmQ1jqPvrNsSNcDC8HyixfVhLPI=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=AH6UmueZxSKKjNVuMsvxXwz6lKomXJAGZsDIF/f5nd4xAZTFAFX6o7OhQkMIdJFW5 YfiChvOEg1tdBBp+JzVlAJNOwQQ1JfMqCtiUG2msAf0mK/K43Nml9UURQjT4Htsdrt lfMIx8Q8P/kq+6qoVWWHdD+SfRQNzCeVXtfR8Apk= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id AD9E9F80254; Sun, 17 Oct 2021 09:44:38 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7BB64F80254; Sun, 17 Oct 2021 09:44:37 +0200 (CEST) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 87023F80254 for ; Sun, 17 Oct 2021 09:44:26 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 87023F80254 Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="fDQd5tve"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="nLy32iuv" Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 1073F1FD63; Sun, 17 Oct 2021 07:44:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634456665; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=I/1DNWjGoA4HrkjgNF7lmzDx68+QYYqUQAl7906aeSA=; b=fDQd5tve4H3buVBedoTsZ5/lNlXLXvB3zv32cHHvl/yZBbspvBEY5Nm45PZwWtTdwMEwqo L4otQYsbs50QIGHHJ69DigLTkkSrqHiXh+lxNbddZIO0UFlYpzzaXxhZU7jkBFO1u9ECw7 q5JoBeePCvFVVWGTFmGmh43vJDElNDI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634456665; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=I/1DNWjGoA4HrkjgNF7lmzDx68+QYYqUQAl7906aeSA=; b=nLy32iuvsoNJfP54kurPOhxAnn9kv2KPMAjWnKjezjSCv4n8X/dMI8kXlNLgyE0eXITW5P LbGy9OSM+vCdFqAQ== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 092D6A3B81; Sun, 17 Oct 2021 07:44:25 +0000 (UTC) Date: Sun, 17 Oct 2021 09:44:25 +0200 Message-ID: From: Takashi Iwai To: Pierre-Louis Bossart Subject: Re: [PATCH v3 2/4] ALSA: pcm: introduce INFO_NO_REWINDS flag In-Reply-To: <20211015195932.224925-3-pierre-louis.bossart@linux.intel.com> References: <20211015195932.224925-1-pierre-louis.bossart@linux.intel.com> <20211015195932.224925-3-pierre-louis.bossart@linux.intel.com> 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") Content-Type: text/plain; charset=US-ASCII Cc: Kai Vehmanen , alsa-devel@alsa-project.org, broonie@kernel.org, Ranjani Sridharan 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Fri, 15 Oct 2021 21:59:30 +0200, Pierre-Louis Bossart wrote: > > When the hardware can only deal with a monotonically increasing > appl_ptr, this flag can be set. > > In case the application requests a rewind, be it with a > snd_pcm_rewind() or with a direct change of a mmap'ed pointer followed > by a SNDRV_PCM_IOCTL_SYNC_PTR, this patch checks if a rewind > occurred and returns an error. > > Credits to Takashi Iwai for identifying the path with SYNC_PTR and > suggesting the pointer checks. > > Suggested-by: Takashi Iwai > Signed-off-by: Pierre-Louis Bossart > Reviewed-by: Ranjani Sridharan > Reviewed-by: Kai Vehmanen Reviewed-by: Takashi Iwai thanks, Takashi > --- > include/uapi/sound/asound.h | 2 +- > sound/core/pcm_lib.c | 14 ++++++++++++++ > 2 files changed, 15 insertions(+), 1 deletion(-) > > diff --git a/include/uapi/sound/asound.h b/include/uapi/sound/asound.h > index 5859ca0a1439..59fcf39f022e 100644 > --- a/include/uapi/sound/asound.h > +++ b/include/uapi/sound/asound.h > @@ -300,7 +300,7 @@ typedef int __bitwise snd_pcm_subformat_t; > #define SNDRV_PCM_INFO_HAS_LINK_ESTIMATED_ATIME 0x04000000 /* report estimated link audio time */ > #define SNDRV_PCM_INFO_HAS_LINK_SYNCHRONIZED_ATIME 0x08000000 /* report synchronized audio/system time */ > #define SNDRV_PCM_INFO_EXPLICIT_SYNC 0x10000000 /* needs explicit sync of pointers and data */ > - > +#define SNDRV_PCM_INFO_NO_REWINDS 0x20000000 /* hardware can only support monotonic changes of appl_ptr */ > #define SNDRV_PCM_INFO_DRAIN_TRIGGER 0x40000000 /* internal kernel flag - trigger in drain */ > #define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */ > > diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c > index ec53a3e7cf35..1d3927aa3dd8 100644 > --- a/sound/core/pcm_lib.c > +++ b/sound/core/pcm_lib.c > @@ -2127,6 +2127,7 @@ int pcm_lib_apply_appl_ptr(struct snd_pcm_substream *substream, > { > struct snd_pcm_runtime *runtime = substream->runtime; > snd_pcm_uframes_t old_appl_ptr = runtime->control->appl_ptr; > + snd_pcm_sframes_t diff; > int ret; > > if (old_appl_ptr == appl_ptr) > @@ -2134,6 +2135,19 @@ int pcm_lib_apply_appl_ptr(struct snd_pcm_substream *substream, > > if (appl_ptr >= runtime->boundary) > return -EINVAL; > + /* > + * check if a rewind is requested by the application > + */ > + if (substream->runtime->info & SNDRV_PCM_INFO_NO_REWINDS) { > + diff = appl_ptr - old_appl_ptr; > + if (diff >= 0) { > + if (diff > runtime->buffer_size) > + return -EINVAL; > + } else { > + if (runtime->boundary + diff > runtime->buffer_size) > + return -EINVAL; > + } > + } > > runtime->control->appl_ptr = appl_ptr; > if (substream->ops->ack) { > -- > 2.25.1 >