Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp517345yba; Mon, 1 Apr 2019 10:53:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqzvy7TPK8wAMk/W9wQ4EWy5w2C/7nNEjnL2KN68VBbW4GEkSjpl9pLbeaa68XCG7+shZqAg X-Received: by 2002:a63:3fc3:: with SMTP id m186mr30152813pga.151.1554141226296; Mon, 01 Apr 2019 10:53:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554141226; cv=none; d=google.com; s=arc-20160816; b=Eo56YjoRRyeP7tcPtfeq6Xvr1EOIP8Vb31dOfWTsRNFWM0t8FQn6Kx4LoYcGTb9s9x M7bNo926mJEKHD34s74XR39xYXhY3ucIcDAHtzxmrl2aQR0kJxoVOCFuobmKLGWOva5m J2hJ3KaeBe3nb45CVRV/muaP6SRQ0mOpIPdGZznIUx3t8RQp6RRRBTB+4q8UnxsOpQMi zCwaM4NcGUIi6pTeVf2ae+c861eyyJIUPcF77VTg9JWyt4PZI2tIahI13Mfdth5d44Bl adUD/S9pGGc/5w+e30aWfn/vlgHbsGdSrn8Mg82VAwghniKWjL86kZ9RqvipIAaJqX5E VWmQ== 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=VTvLs490kpGsZutucVbG92t0GpdaPmCwpQjfukPgM8c=; b=ijMebalEGp/rk4q2jZM8BzoKGjaV/BfXob/4Z7+E2cRFg9YSKM1KXmi91Duyv+gfH+ UGFYkMWK8LOuE8Nl9pjWi0suv+2n1wnJ/2AK1pclOESfsz/vDu5ldQy8y2IQMfZYPmBu TlBljwl9OgSoiFdlD8wDDcy65Cj8L/hvBiVY9beIPdclYrmjpem/DxajXDOEuubk9BDP pNHjbMrDfdafVPMjYf2SknRvhOzRzJhXbcr3TQhBGlOtXAVuBENO/SBe/HKF+nYP2pmz Ka6gus6PqWT6zi0NGC5vdb1IKzT6VR2kexW9Re0lgpzz7G3hobnSgIB00pB1L1Lsc4NU 7sJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ce01RgJj; 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 q77si9321599pfa.102.2019.04.01.10.53.31; Mon, 01 Apr 2019 10:53:46 -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=Ce01RgJj; 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 S1732659AbfDAR1W (ORCPT + 99 others); Mon, 1 Apr 2019 13:27:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:60124 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732654AbfDAR1T (ORCPT ); Mon, 1 Apr 2019 13:27:19 -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 B2E26208E4; Mon, 1 Apr 2019 17:27:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554139638; bh=vQs0JiH6HUzPnYfc7ObyDz9dd/lSO1+fiOwn7RD3Ycs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ce01RgJj+6QNi2R+oQz9gQ0Tkxk/zRPalGMIoOIyMvlmcTP94hcueecA8ae/p89Ho /8zVVYYtpz/kdu6HFYliImO/IDsEOkgb0uuy9I/7mLZQ7BxsrtFo5KGwSrBk66mfWE 2QptJrjPCKRxNZ+0HCnmcyOXegL0Xg4w+1mpLrfk= 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.9 26/56] ALSA: pcm: Dont suspend stream in unrecoverable PCM state Date: Mon, 1 Apr 2019 19:02:42 +0200 Message-Id: <20190401170105.387430791@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190401170103.398401360@linuxfoundation.org> References: <20190401170103.398401360@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.9-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 @@ -1258,8 +1258,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; }