Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2035786pxb; Sun, 17 Oct 2021 04:17:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySIotOFWH00mjszQ9D6dnB1OB55pvShmRRm9SH7ImXW20McjP11pQiF/iune0DTrSUw+u2 X-Received: by 2002:a63:7542:: with SMTP id f2mr10626822pgn.147.1634469431659; Sun, 17 Oct 2021 04:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634469431; cv=none; d=google.com; s=arc-20160816; b=utygb+O1D8pbM70avi1ipXxhD3gihXa4D2Tsvse8bv0HG4XQW9/BtU4MyGjSPMG/f/ jiquEtBQQIxzCPbiAnYsSXlmOrwh04iVjNwxtZA3oAkbumYvYPwldUiBPvCQQBh0RrD8 tKoEsuwpyoT7mwMQrrzJuneXEueFoWbTwBZSPgNclHJdxf3QQ7TerzVA+A/mjt2UWWhO duQ8f2XY99CWQgwktuNcjuYkrEsyaOnCWQkBDRLTgIKs6gvbhPkpJ7TlWjgg7lUUDdzG +q1TqTNrb/9Qhq9U28sgoyglvstLLEAOzcv4FDcAog9mNXD2G9IUGnVpfXYntwt3wzRP Tnvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date:dkim-signature:dkim-signature; bh=dhDQfRzdWjoQAA9wLkDzmZrDRzBCVOaY+5kBnn+OZ+g=; b=fWZKKTx4FKVEoR9QFWggnZbnneV6M1/ngxDyBTzNccl3LxoKKsG8VKObsEs2sNsVrl nkxnXAPhutyGnVOtuN+rv2PbHsjs6T10I0ofLoKRnm033kDCDLrgTMCunR/krxjxiegY TkuvskURRv4+hwcJpf71mOQ6FWTCrVkkebzM4REE8Oz6AyD+22mSbq7wbGPjIEudwTe8 oIYnAV/sygdjAm1kzYLeAms7R1+EzmQdqJPmHixxKsXaGw+VVg3fOLxE/WX9UZ/C/KVT 7e5vvL8lRCULmkWFVmaK3C0bxQtjqcCVW/whXTrfEhOaAARiFzYtXlaYqbkb+WvvXC3F w9AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NSSOPO5d; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 21si15481141pgb.269.2021.10.17.04.16.58; Sun, 17 Oct 2021 04:17:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=NSSOPO5d; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237756AbhJOQ64 (ORCPT + 99 others); Fri, 15 Oct 2021 12:58:56 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:34122 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237724AbhJOQ6z (ORCPT ); Fri, 15 Oct 2021 12:58:55 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 356E821A6D; Fri, 15 Oct 2021 16:56:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1634317008; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dhDQfRzdWjoQAA9wLkDzmZrDRzBCVOaY+5kBnn+OZ+g=; b=NSSOPO5dO3DmBJs2cFghl1oPUO8fa6oH3Cpq0EZQg+Gc8L09smGJgx7ubuCrnvChFWJ9HH m8msQ1ifgDIAsHgr12GDWTmRFe8NFwR1TfeQO66yRY4qp9QBZVQ2GzYnhIKHYoE+VAQSmz R8ZdT5nPEDt11oj3hUSzD9SNgkCtp7c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1634317008; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dhDQfRzdWjoQAA9wLkDzmZrDRzBCVOaY+5kBnn+OZ+g=; b=WerHXpzNkZtBKCeOCuB72DTfG8Sa4VnztHlHvr6o6NJ2f1SUvngyoqyaHaajqMg1Nc/xY8 GJpVf05XfRxqbDAw== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 967BBA3B89; Fri, 15 Oct 2021 16:56:47 +0000 (UTC) Date: Fri, 15 Oct 2021 18:56:47 +0200 Message-ID: From: Takashi Iwai To: Pierre-Louis Bossart Cc: alsa-devel@alsa-project.org, Kuninori Morimoto , open list , Sameer Pujar , Liam Girdwood , Takashi Iwai , vkoul@kernel.org, broonie@kernel.org, Gyeongtaek Lee , Peter Ujfalusi Subject: Re: [RFC PATCH v3 05/13] ASoC: soc-pcm: align BE 'atomicity' with that of the FE In-Reply-To: <8aa4fa07-2b55-3927-f482-c2fd2b01a22e@linux.intel.com> References: <20211013143050.244444-1-pierre-louis.bossart@linux.intel.com> <20211013143050.244444-6-pierre-louis.bossart@linux.intel.com> <2847a6d1-d97f-4161-c8b6-03672cf6645c@nvidia.com> <8aa4fa07-2b55-3927-f482-c2fd2b01a22e@linux.intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 15 Oct 2021 18:22:58 +0200, Pierre-Louis Bossart wrote: > > > > The FE stream locks are necessary only two points: at adding and > > deleting the BE in the link. We used dpcm_lock in other places, but > > those are superfluous or would make problem if converted to a FE > > stream lock. > > I must be missing a fundamental concept here - possibly a set of concepts... > > It is my understanding that the FE-BE connection can be updated > dynamically without any relationship to the usual ALSA steps, e.g. as a > result of a control being changed by a user. > > So if you only protect the addition/removal, isn't there a case where > the for_each_dpcm_be() loop would either miss a BE or point to an > invalid one? No, for sleepable context, pcm_mutex is *always* taken when adding/deleting a BE, and that's the main protection for the link. The BE stream lock is taken additionally over it at adding/deleting a BE, just for the code path via FE and BE trigger. > In other words, don't we need the *same* lock to be used > a) before changing and > b) walking through the list? > I also don't get what would happen if the dpcm_lock was converted to an > FE stream lock. It works fine in my tests, so if there's limitation I > didn't see it. dpcm_lock was put in the places that could be recursively taken. So this caused some deadlock, I suppose. > >>> In addition, a lock around dpcm_show_state() might be needed to be > >>> replaced with card->pcm_mutex, and we may need to revisit whether all > >>> other paths take card->pcm_mutex. > >> > >> What happens if we show the state while a trigger happens? That's my > >> main concern with using two separate locks (pcm_mutex and FE stream > >> lock) to protect the same list, there are still windows of time where > >> the list is not protected. > > > > With the proper use of mutex, the list itself is protected. > > If we need to protect the concurrent access to each BE in the show > > method, an additional BE lock is needed in that part. But that's a > > subtle issue, as the link traversal itself is protected by the mutex. > > If I look at your patch2, dpcm_be_disconnect() protects the list removal > with the fe stream lock, but the show state is protected by both the > pcm_mutex and the fe stream lock. No, show_state() itself doesn't take any lock, but its caller dpcm_state_read_file() takes the pcm_mutex. That protects the list addition / deletion. > I have not been able to figure out when you need > a) the pcm_mutex only > b) the fe stream lock only > c) both pcm_mutex and fe stream lock The pcm_mutex is needed for every sleepable function that treat DPCM FE link, but the mutex is taken only at the upper level, i.e. the top-most caller like PCM ops FE itself or the DAPM calls. That said, pcm_mutex is the top-most protection of BE links in FE. But, there is a code path where a mutex can't be used, and that's the FE and BE trigger. For protecting against this, the FE stream lock is taken only at the placing both adding and deleting a BE *in addition*. At those places, both pcm_mutex and FE stream lock are taken. BE stream lock is taken in addition below the above mutex and FE locks. Takashi