Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1751567pxb; Sat, 16 Oct 2021 19:10:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqJbmasweQVb+oj2wxfiUquipEqDhimwrkYkLZJtbIX340EWRDry2CqykNYxRL6OuuUeCm X-Received: by 2002:a17:902:f281:b0:13f:3be8:b160 with SMTP id k1-20020a170902f28100b0013f3be8b160mr19498231plc.32.1634436651652; Sat, 16 Oct 2021 19:10:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634436651; cv=none; d=google.com; s=arc-20160816; b=WADUquu19CXyzvaJOslUEF/UT2qoDJqY4VpLgTPEwS+HOWhcg2Nc6z6xQ7UjFYg3Q6 TtguVE+SA3ABFHUI2P3ru4bwmrFYjxDDnqp2gje5lbFCCdLTtdIa1yMjDJtPz37Xm82s a7sanuJB2LBnYKbV57NBW3dYdIe0HH9qWgiU91OoDefWJ6ZEUp6mW6uVyc1mKeUV5Rgi brh2aWMjdg2FxxwFF7k0zJdjx5VmwBaJ1m9QIAPD3q2LGfhOed6RpNgwEKxJaCdnjSE/ wnxHrOgC0T/sNKR5i3EX2elimoyi230+HFuKN3X/c1Ue5WQQmh7FPX7hS52HBrBhVUQD 7inA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=grVqWpmCE60Fs7k/DM1xnC579l+jeht3VRJFKplSg3k=; b=KFUp3a0XhyYjRUklvyUbOyMiUyuPCNaMZvBD+/FsK3L8zrWjIYX9V9HY5vkpPrafaE BZ5Jzwv39GPVMGtAcOOLsJD4+SnPBIhI69k2VJfguXbAts0sSKaFI8v25geA0kNQQ8D2 bEgBX3GqEEWuw/S3yhfKyl3rZ7eSFImU9NgSDFnF+Mju0SDdAj1bh9V+auq2ZqHv3/YB Gmps9r4hdg0a63PUxRXb2reEQYDhlQ5GJzweqDKR+0R9ZfkvlJqBRbM7GeIZxkkTZGMJ Hl4b/lnFYViAVzKYgaE84hmofZgk2ROpH1Lg6NZOobZ8feY3pDzNfcXywtyeI6at+Oeg gN4g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rj1si27990036pjb.154.2021.10.16.19.10.24; Sat, 16 Oct 2021 19:10:51 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241232AbhJOQZJ (ORCPT + 99 others); Fri, 15 Oct 2021 12:25:09 -0400 Received: from mga11.intel.com ([192.55.52.93]:5041 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241225AbhJOQZJ (ORCPT ); Fri, 15 Oct 2021 12:25:09 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10138"; a="225406966" X-IronPort-AV: E=Sophos;i="5.85,376,1624345200"; d="scan'208";a="225406966" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2021 09:23:02 -0700 X-IronPort-AV: E=Sophos;i="5.85,376,1624345200"; d="scan'208";a="492623169" Received: from liminghu-mobl.ccr.corp.intel.com (HELO [10.212.23.213]) ([10.212.23.213]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Oct 2021 09:23:01 -0700 Subject: Re: [RFC PATCH v3 05/13] ASoC: soc-pcm: align BE 'atomicity' with that of the FE To: Takashi Iwai 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 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> From: Pierre-Louis Bossart Message-ID: <8aa4fa07-2b55-3927-f482-c2fd2b01a22e@linux.intel.com> Date: Fri, 15 Oct 2021 11:22:58 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > 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? 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. >>> 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. 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