Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp841995imu; Tue, 11 Dec 2018 08:22:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/W1meqKcY+Bf2ACDXjixC25gfW9Je1CkfxRfun9RSfDmYDQ3f/X1BlErBhFtiKOHXe0zQuh X-Received: by 2002:a63:2d82:: with SMTP id t124mr15061413pgt.260.1544545362195; Tue, 11 Dec 2018 08:22:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544545362; cv=none; d=google.com; s=arc-20160816; b=YNNwOv1PriVwSN+rwFhzaPWJQSDfnTU+VTux2LJPGLt4QhU5Bnj8OVwg+Yc+6f/GsG PAdRTVFFphUdc2x3OFBI55O6hkVW9BNM6qjSlXdAFVqwFZJqSMANvZDEOjbaN4yLABUV nANft5N7k1bTFKqGlXDW7unbw7lSpmXqvlIDTDylQ4yAAH5GDDkgM+bZ0j9CsEwzmQd5 jHWGU/QDnPvG+yGMcRh+Liqg7NYtqbUTIsyM4WmarjT7Jac0BIeNZSvIiXJs2KEjFwWV U5S+33d6k3b4tRM4a5tfu6rwN7lmWeewOC64UviVseNFgZgAxP3/NHKMzjQQ2x4tkAin LLlw== 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=eCwPOJhD1agFytz2bATK/7+9ZOuwbNzv5y9Onduiu7A=; b=SIXwwVw5gKrxSWciLIn6WIuini+f2qntzYxmyMZwdaeiRB/MYulkV9gcCwj/EnYBPd Z2bqx2Q5cJT4kcB6zN527YC09g+KYLv8PSSE9mafx2r1JzjXLZ3fas9Zok5D3SC3xh9D FXq6n7a5QMEQA3oM8Hou0ES0rdVJ3SRFMKM1+vWUdIxwFhbqFkeynuJDqAnRhlmkEHW8 UbWele3/Z3JS12zcnSA1PF+cD0IsFfsv4hQGRTqPHOIHiGQmfZaGSFJrxl6YARY+XMIQ Bw6uCbhYFeoUIbt0PcjTfts+nuNO6NvLozbeqAoG9gbpvJ47nvzoEb1inuXgFCAFoCuV 98rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P1jonFGV; 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 76si13703283pfw.66.2018.12.11.08.22.27; Tue, 11 Dec 2018 08:22:42 -0800 (PST) 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=P1jonFGV; 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 S1728540AbeLKQUr (ORCPT + 99 others); Tue, 11 Dec 2018 11:20:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:33192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727925AbeLKPos (ORCPT ); Tue, 11 Dec 2018 10:44:48 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 2971320855; Tue, 11 Dec 2018 15:44:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543087; bh=bNqmYzFVdSI04s6CDUnHpgpq6IaLy1txBZ8txt/GIQI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P1jonFGVsj5xXmOU+UV0zglIy/GUeOgepjsTS9XF2Tr9ccJKseRZSU5eAtipN58m4 XbE7rcIo5hiszYslxv5E+5lH/gawB0oFhsUvfKgaEqSnxpbflZW+EFTcO2EG3Tc3sM pqplOOvs/dNPIG2SrllwG6mbG5vwiY+rpvryMZcI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chanho Min , Takashi Iwai Subject: [PATCH 3.18 45/54] ALSA: pcm: Call snd_pcm_unlink() conditionally at closing Date: Tue, 11 Dec 2018 16:41:33 +0100 Message-Id: <20181211151548.595323479@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151546.010073210@linuxfoundation.org> References: <20181211151546.010073210@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 3.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit b51abed8355e5556886623b2772fa6b7598d2282 upstream. Currently the PCM core calls snd_pcm_unlink() always unconditionally at closing a stream. However, since snd_pcm_unlink() invokes the global rwsem down, the lock can be easily contended. More badly, when a thread runs in a high priority RT-FIFO, it may stall at spinning. Basically the call of snd_pcm_unlink() is required only for the linked streams that are already rare occasion. For normal use cases, this code path is fairly superfluous. As an optimization (and also as a workaround for the RT problem above in normal situations without linked streams), this patch adds a check before calling snd_pcm_unlink() and calls it only when needed. Reported-by: Chanho Min Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/core/pcm_native.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -2193,7 +2193,8 @@ int snd_pcm_hw_constraints_complete(stru static void pcm_release_private(struct snd_pcm_substream *substream) { - snd_pcm_unlink(substream); + if (snd_pcm_stream_linked(substream)) + snd_pcm_unlink(substream); } void snd_pcm_release_substream(struct snd_pcm_substream *substream)