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=-6.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 C1DE9C07E85 for ; Tue, 11 Dec 2018 16:16:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 85A202084E for ; Tue, 11 Dec 2018 16:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544544999; bh=X3Lr5a8bw7CkPJ/1qBznnjqBqZnWWI1ScVNEd2xW7gk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=jasGxijjO/Uo4m4gFxTN41X6Wjpcnr5AyEyIpw9DYWzN0moYiI6hjylE8cm2xsj57 3z3cdJ7Eg7d1aSu/gc4/TwUzHO9N1/R7HO73X/BFwKPKHDxEWgJUasQUXIfedhvqdl Bjg1+kN5+SHJT/qI/Eeiz0g0hJ00bl5NWjSQ2Kz0= DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85A202084E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729162AbeLKQQi (ORCPT ); Tue, 11 Dec 2018 11:16:38 -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)