Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp904379imu; Tue, 11 Dec 2018 09:19:37 -0800 (PST) X-Google-Smtp-Source: AFSGD/X70JMP9cJwk169iOw72vbgcMJ0aHl7TusRU7fB+dYgC9WTAnIScqXR916cYLa1qxlp0CZG X-Received: by 2002:a62:8985:: with SMTP id n5mr17359201pfk.255.1544548776948; Tue, 11 Dec 2018 09:19:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544548776; cv=none; d=google.com; s=arc-20160816; b=tAUdP4V850K4RNlL+O7heiHvQnVoAVPS1ybqtHP3WY0W0F/3KlHbXt9psiAPZP4E3X uIWLWFWNiYKYjNs0VoGpnU6tCb9o0rrzqGl3m/xwhma8jbZC8jZ/dqcSrfX5/DI8R3zl AyD6tvQ1sxLm63M631Tv0ins39361yaorhjoevwmYMJhblSBrbI6guCt+qJEZBqqbsXx +X32t8xXfZ3adPKUko6TtykxjvzDShU4BzjCRTwJw+LNwLAEuZjHSiD04ZGcI2VOY9/q /JUtSIX+/mInFpDwe6Q4m0Zwh9SktFkC2+ZVCxy5Ku1Vm/7E/XeqTgUGMdcEzMg/8SnU xK/w== 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=CjhmSeUaicFi+S41EeabmkYeVdMiau4zNdfroBqMiwc=; b=MxQ64oxDVtrt2Y/eVdmfbSwFVe40eq8QcCHJWerx7YPqZOwxBMWv+fqIePNm/4U+Y1 CEdyXE57cd4ai7irtl+xJA9Mi0Yo1WE7eK9IVuM2zz4ABAJ4LniVWNbUYj528vlWR/BH /6Hy1zzGpetDjuA+wEGmO4KjSfARRZSQ66cx6nqs5GH3pao6Lsc5Er+3l1nnN8YTdKDT nsjPhL0/vr9iGTFIKxqSyIy7y9LsPUArHg/nIMRu/iZ4xh93geY/SvCPsnNibwS6babn 0RjV8ft1tFfEwHsnwhyh6npsiDkKt/2uZJmOBsN9Fca5Sopj2wNH804jmwavgXXO4+sI UxBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=B8GdngnA; 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 b24si2176524pgg.288.2018.12.11.09.19.21; Tue, 11 Dec 2018 09:19:36 -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=B8GdngnA; 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 S1729005AbeLKQQh (ORCPT + 99 others); Tue, 11 Dec 2018 11:16:37 -0500 Received: from mail.kernel.org ([198.145.29.99]:36224 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728656AbeLKPrr (ORCPT ); Tue, 11 Dec 2018 10:47:47 -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 6FFCD20989; Tue, 11 Dec 2018 15:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543266; bh=X3Lr5a8bw7CkPJ/1qBznnjqBqZnWWI1ScVNEd2xW7gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B8GdngnAtm+GdZcVbBm9zceypOHj8p9l3BSLPQnSZ017flNt83q9IbR1RYl7gFGhU cvioRf2rw8awVSU2OPgkM2sVfMwvmVx58cXWwvaB0D6EvfndHYRYBI8GZCM8lFdNN8 C25w9qsTbpwIMhEYCcvvhovI9sgqbFMEsLEQY2Eo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chanho Min , Takashi Iwai Subject: [PATCH 4.4 76/91] ALSA: pcm: Call snd_pcm_unlink() conditionally at closing Date: Tue, 11 Dec 2018 16:41:35 +0100 Message-Id: <20181211151612.682070420@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151606.026852373@linuxfoundation.org> References: <20181211151606.026852373@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.4-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 @@ -2225,7 +2225,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)