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=-0.7 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=no 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 4890EC432C0 for ; Mon, 18 Nov 2019 18:48:56 +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 C4487222CD for ; Mon, 18 Nov 2019 18:48:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="p9jNKv6R" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4487222CD 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 D55DC168A; Mon, 18 Nov 2019 19:48:03 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz D55DC168A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1574102934; bh=cZRaNhT2VR0C23fXcKFPEpg14Wr0OOKCow+fkC3ZM40=; h=Date:From:To:In-Reply-To:References:Cc:Subject:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=p9jNKv6RFU4VufrPZRlOWpaE+QHSbQQ7/qd3U8SGMUGx2/7ZwYDZT3iM3Qg3U53Wh p4OtSDVDhF1CBVInSk1rHQGcGzLhPpskZshQ2UI7ziZ2VdBCFKLOwNY1z69kdDaFfB sBs229tfZ5Da2N3/Pds8tt8jugMzZ+Ih9U9n8wv8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 64A5EF80100; Mon, 18 Nov 2019 19:48:03 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 5B48CF8013D; Mon, 18 Nov 2019 19:48:02 +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 E5B4CF800F6 for ; Mon, 18 Nov 2019 19:47:59 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz E5B4CF800F6 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 1F3C9AD31; Mon, 18 Nov 2019 18:47:59 +0000 (UTC) Date: Mon, 18 Nov 2019 19:47:59 +0100 Message-ID: From: Takashi Iwai To: Pierre-Louis Bossart In-Reply-To: References: <20191117085308.23915-1-tiwai@suse.de> <20191117085308.23915-7-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: alsa-devel@alsa-project.org Subject: Re: [alsa-devel] [PATCH 6/8] ALSA: pcm: Add the support for sync-stop operation 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 Mon, 18 Nov 2019 17:33:51 +0100, Pierre-Louis Bossart wrote: > > > > On 11/17/19 2:53 AM, Takashi Iwai wrote: > > The standard programming model of a PCM sound driver is to process > > snd_pcm_period_elapsed() from an interrupt handler. When a running > > stream is stopped, PCM core calls the trigger-STOP PCM ops, sets the > > stream state to SETUP, and moves on to the next step. This is > > performed in an atomic manner -- this could be called from the interrupt > > context, after all. > > > > The problem is that, if the stream goes further and reaches to the > > CLOSE state immediately, the stream might be still being processed in > > snd_pcm_period_elapsed() in the interrupt context, and hits a NULL > > dereference. Such a crash happens because of the atomic operation, > > and we can't wait until the stream-stop finishes. > > > > For addressing such a problem, this commit adds a new PCM ops, > > sync_stop. This gets called at the appropriate places that need a > > sync with the stream-stop, i.e. at hw_params, prepare and hw_free. > > > > Some drivers already have a similar mechanism implemented locally, and > > we'll refactor the code later. > > This rings a bell, for the SOF driver Keyon added a workqueue to avoid > doing the call to snd_pcm_period_elapsed() while handling IPC > interrupts. I believe the reason what that the IPC needs to be > serialized, and the call to snd_pcm_period_elapsed could initiate a > trigger stop IPC while we were dealing with an IPC, which broke the > notion of serialization. > > See "ASoC: SOF: PCM: add period_elapsed work to fix race condition in > interrupt context" > and "ASoC: SOF: ipc: use snd_sof_pcm_period_elapsed" The new PCM ops is exactly for resolving such a thing. Basically snd_pcm_period_elapsed() is handled asynchronously, so we need the synchronization. For a simpler driver, it's merely synchronize_irq() call (no matter whether it's a hard-irq or a threaded-irq), but for drivers that deal with another async mechanism (e.g. USB-audio), another sync procedure is required. It's possible that the workaround you've done in SOF can be simplified by this mechanism, but I didn't take a deeper look at it yet. thanks, Takashi _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org https://mailman.alsa-project.org/mailman/listinfo/alsa-devel