public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Richard Fitzgerald <rf@opensource.cirrus.com>,
	vkoul@kernel.org, yung-chuan.liao@linux.intel.com
Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com
Subject: Re: [PATCH 2/2] soundwire: stream: Make master_list ordered to prevent deadlocks
Date: Thu, 15 Jun 2023 18:46:06 +0200	[thread overview]
Message-ID: <9eca7ccc-7955-43d3-178a-998d0f430a4c@linux.intel.com> (raw)
In-Reply-To: <20230615141208.679011-2-rf@opensource.cirrus.com>



On 6/15/23 16:12, Richard Fitzgerald wrote:
> Always add buses to the stream->master_list in a fixed order.
> The unique bus->id is used to order the adding of buses to the
> list.
> 
> This prevents lockdep asserts and possible deadlocks on streams
> that have multiple buses.
> 
> sdw_acquire_bus_lock() takes bus_lock in the order that buses
> are listed in stream->master_list. do_bank_switch() takes all
> the msg_lock in the same order.
> 
> To prevent a lockdep assert, and a possible real deadlock, the
> relative order of taking these mutexes must always be the same.
> 
> For example, if a stream takes the mutexes in the order
> (bus0, bus1) lockdep will assert if another stream takes them
> in the order (bus1, bus0).
> 
> More complex relative ordering will also assert, for example
> if two streams take (bus0, bus1) and (bus1, bus2), then a third
> stream takes (bus2, bus0).
> 
> Previously sdw_stream_add_master() simply added the given bus
> to the end of the list, requiring the caller to guarantee that
> buses are added in a fixed order. This isn't reasonable or
> necessary - it's an internal implementation detail that should
> not be exposed by the API. It doesn't really make sense when
> there could be multiple independent calling drivers, to say
> "you must add your buses in the same order as a different driver,
> that you don't know about, added them".

Makes sense to me. The other way to look at this is that the notion of
'stream' and dailink are virtually synonyms, and 'sdw_stream_add_master'
is called from each DAI of a dailink, hence in a fixed order. But
nothing really defines how dailinks include the dais, and in a
hypothetical case with multiple controllers, each with multiple links,
there would be an ambiguity anyways so using the ida-allocated bus->id
is a good solution indeed.

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>

  reply	other threads:[~2023-06-15 16:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 14:12 [PATCH 1/2] soundwire: bus: Prevent lockdep asserts when stream has multiple buses Richard Fitzgerald
2023-06-15 14:12 ` [PATCH 2/2] soundwire: stream: Make master_list ordered to prevent deadlocks Richard Fitzgerald
2023-06-15 16:46   ` Pierre-Louis Bossart [this message]
2023-06-15 16:31 ` [PATCH 1/2] soundwire: bus: Prevent lockdep asserts when stream has multiple buses Pierre-Louis Bossart
2023-06-21 10:53 ` Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9eca7ccc-7955-43d3-178a-998d0f430a4c@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@opensource.cirrus.com \
    --cc=rf@opensource.cirrus.com \
    --cc=vkoul@kernel.org \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox