Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp518788yba; Mon, 1 Apr 2019 10:55:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqx10SU+JglviJORvWg07LWFjG63OeTBGiZZg6lO79ojDR5eUZGprpu95XyZy2p1CH6/6AA9 X-Received: by 2002:a63:6fc1:: with SMTP id k184mr49757698pgc.239.1554141355764; Mon, 01 Apr 2019 10:55:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554141355; cv=none; d=google.com; s=arc-20160816; b=rshJSJseqiKTSkV6Pb/s2icG1B8T6PhoogN6uvI5mgRV0vNkDKjPnjYbL13H/VJkHJ T20lDhIY6+sJUXK+YUsmZuCu1mJTv/AKF4Yz0gCGXj7dhix/DP8kvxEPZr9O5K6ZE4ce aqaybs7lvU/oeX4KhQL77NrosQwYxpjhp5s5PxVoXrmdKLASvXInn4ZLuU0ISMLtUoKL kErRd7zJnnCB5VpeSY8iH22MWRdLDOydbVSCOfjWvC0EeG4GsqoyZzEoi7bI3uLdF7Rv 9QnSyrZqp0pRTN8ESS/zQNwxVERg6Q3CshH7qK5LvQrHHcByZoWVQ6Ot9FLqH9KhVSfY 7B+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VhsSaRwD6HEi01jwwl+gykmtWQ7Ty7V2rYAW6xlAGoM=; b=Neu/05DdxbmO0h78F+mHLBDq+oxKKbgnBpMdRaVuIbXKDa808GMtizwkc+at7iNLeD MIdAmXMrcMUmFO+0xGmsKCl4UQ2BhtzLPXMkr24WzA+J1gr2cD8lrLHp+pPr56Ych1Cs 59tS4omTrR4CFiYCR+MvpzPi8ZBi2XjdFupMDSMw5jDZrwpIzruNBOpIJh+Nv5eIKBVW qDlEhCK/zyTATJnhBtFKB8Zunc1DDZuoBSfA8I8gLCLh8sRKfamZQJi6IzY6VR5l+JRl 8ZwwkgrbbiY/PpUQAAWKfGOFqlOGaX2tLVZLpkrlIPZfXPmn6s2XtBAS3h8dpcBzZGnH NbBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kquIrBsm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v131si9367478pgb.452.2019.04.01.10.55.40; Mon, 01 Apr 2019 10:55:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=kquIrBsm; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732115AbfDARX3 (ORCPT + 99 others); Mon, 1 Apr 2019 13:23:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:53278 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732106AbfDARX1 (ORCPT ); Mon, 1 Apr 2019 13:23:27 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8399A20856; Mon, 1 Apr 2019 17:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554139406; bh=9tWqKUXkufHJK4AaeVQ3us0nJMNHEPZahbkT+WZ4GKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kquIrBsm9eRJPmaRodKPGKPSvX/d+hZQh8JTujFaTVYcBtX20R/zmIb9YcjSTYdJF ws8rlg65EFN4xEYpjcnJfSedvsVx+EKjDPYrjBPwsVcKzRoqh50vU7MYkIg31GpCrT xLT7YDtUgLkbs/clpSRwkwmD3cL8+zllC96789TA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Jon Hunter Subject: [PATCH 4.14 066/107] ALSA: pcm: Dont suspend stream in unrecoverable PCM state Date: Mon, 1 Apr 2019 19:02:21 +0200 Message-Id: <20190401170051.669225727@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170045.246405031@linuxfoundation.org> References: <20190401170045.246405031@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit 113ce08109f8e3b091399e7cc32486df1cff48e7 upstream. Currently PCM core sets each opened stream forcibly to SUSPENDED state via snd_pcm_suspend_all() call, and the user-space is responsible for re-triggering the resume manually either via snd_pcm_resume() or prepare call. The scheme works fine usually, but there are corner cases where the stream can't be resumed by that call: the streams still in OPEN state before finishing hw_params. When they are suspended, user-space cannot perform resume or prepare because they haven't been set up yet. The only possible recovery is to re-open the device, which isn't nice at all. Similarly, when a stream is in DISCONNECTED state, it makes no sense to change it to SUSPENDED state. Ditto for in SETUP state; which you can re-prepare directly. So, this patch addresses these issues by filtering the PCM streams to be suspended by checking the PCM state. When a stream is in either OPEN, SETUP or DISCONNECTED as well as already SUSPENDED, the suspend action is skipped. To be noted, this problem was originally reported for the PCM runtime PM on HD-audio. And, the runtime PM problem itself was already addressed (although not intended) by the code refactoring commits 3d21ef0b49f8 ("ALSA: pcm: Suspend streams globally via device type PM ops") and 17bc4815de58 ("ALSA: pci: Remove superfluous snd_pcm_suspend*() calls"). These commits eliminated the snd_pcm_suspend*() calls from the runtime PM suspend callback code path, hence the racy OPEN state won't appear while runtime PM. (FWIW, the race window is between snd_pcm_open_substream() and the first power up in azx_pcm_open().) Although the runtime PM issue was already "fixed", the same problem is still present for the system PM, hence this patch is still needed. And for stable trees, this patch alone should suffice for fixing the runtime PM problem, too. Reported-and-tested-by: Jon Hunter Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/pcm_native.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -1395,8 +1395,15 @@ static int snd_pcm_pause(struct snd_pcm_ static int snd_pcm_pre_suspend(struct snd_pcm_substream *substream, int state) { struct snd_pcm_runtime *runtime = substream->runtime; - if (runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) + switch (runtime->status->state) { + case SNDRV_PCM_STATE_SUSPENDED: return -EBUSY; + /* unresumable PCM state; return -EBUSY for skipping suspend */ + case SNDRV_PCM_STATE_OPEN: + case SNDRV_PCM_STATE_SETUP: + case SNDRV_PCM_STATE_DISCONNECTED: + return -EBUSY; + } runtime->trigger_master = substream; return 0; }