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 4CF50C07E85 for ; Tue, 11 Dec 2018 15:56:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1051B21104 for ; Tue, 11 Dec 2018 15:56:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543792; bh=XY5SW411y3RF0m0AEwQ7B74kBrJorzbAfR88lJx55p0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=qnVi0IFgaHrXylyuWxLgZAHiCrwFYJOe0P7IAAz3bsP/Gt3xGwhUIxU83kIwekwtK Exl2ACBEYCwvB5XIU+q9xAG/xY+fDe1IJvLGXf04Lt3ndgSOnVDrfzjBWYdUyx9Wl2 +EZEES9VFJnie64dSLh1n8URaOAa0IN9SeQStzBs= DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1051B21104 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 S1730595AbeLKP4a (ORCPT ); Tue, 11 Dec 2018 10:56:30 -0500 Received: from mail.kernel.org ([198.145.29.99]:45270 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730577AbeLKP43 (ORCPT ); Tue, 11 Dec 2018 10:56:29 -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 0533A205C9; Tue, 11 Dec 2018 15:56:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543788; bh=XY5SW411y3RF0m0AEwQ7B74kBrJorzbAfR88lJx55p0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hVMBKrFqdrveEpfiXElR/vYQB6Q5/qWI4c44ADyOnXc8C0WjGVZNsInV5Ydwp1MzI eBz4H6jxtY/S4dDAjWgaEe9GsLx8ES13ydlgGu5rJ2ZGpqzU2+tdGyCWPK2BQ+UVaG EbdMsPNS79u7V037QgQrarjgW719OGiHnfM/WsTk= 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.19 064/118] ALSA: pcm: Call snd_pcm_unlink() conditionally at closing Date: Tue, 11 Dec 2018 16:41:23 +0100 Message-Id: <20181211151646.822488652@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151644.216668863@linuxfoundation.org> References: <20181211151644.216668863@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.19-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 @@ -2370,7 +2370,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)