linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: Mark Brown <broonie@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-spi@vger.kernel.org, Lukas Wunner <lukas@wunner.de>,
	Mika Westerberg <mika.westerberg@linux.intel.com>,
	Jarkko Nikula <jarkko.nikula@intel.com>
Subject: Re: Deadlock in spi_add_device() -- device core problem
Date: Tue, 12 Oct 2021 21:30:05 +0200	[thread overview]
Message-ID: <20211012193005.lxqzbsdeh4k7nxe2@pengutronix.de> (raw)
In-Reply-To: <YWBITX2Wbfx/QHCE@sirena.org.uk>

[-- Attachment #1: Type: text/plain, Size: 1741 bytes --]

Hi Mark,

On Fri, Oct 08, 2021 at 02:31:57PM +0100, Mark Brown wrote:
> On Thu, Oct 07, 2021 at 06:52:14PM +0200, Uwe Kleine-König wrote:
> > On Thu, Oct 07, 2021 at 06:19:46PM +0200, Greg Kroah-Hartman wrote:
> > > On Thu, Oct 07, 2021 at 06:05:24PM +0200, Uwe Kleine-König wrote:
> 
> > > Drivers for a bus bind to the bus, they should not be creating new
> > > devices for that same bus, as that does not seem correct.
> 
> > That's not the culprit here. We have a spi-device (spi-mux) that is a
> > bus device on the SoC's bus and a bus master for it's own bus. And
> > spi_add_device for the spi-mux device triggers the probe function for
> > the spi-mux driver which creates a new bus controller which triggers
> > spi_add_device() for the devices on the inner bus.
> 
> I think we need to be arranging for spi_add_lock to be per bus
> rather than global - putting it into the controller ought to do
> the trick.

Yeah, that's what I consider the second best option that I already
mentioned in the initial mail of this thread.

@Greg: Would you expect that it should be possible (and benificial) to
rework the code to not hold a lock at all during device_add()?

This would then need something like:

	lock() # either per controller or global
	if bus already has a device for the same chipselect:
	    error out;
	register chipselect as busy
	unlock();

	ret = device_add(...)

	if ret:
	    lock()
	    unregister chipselect
	    unlock()

Is this worth the effort?

Anyhow, will try the suggested patch next.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2021-10-12 19:30 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-07 16:05 Deadlock in spi_add_device() -- device core problem Uwe Kleine-König
2021-10-07 16:19 ` Greg Kroah-Hartman
2021-10-07 16:52   ` Uwe Kleine-König
2021-10-08 13:31     ` Mark Brown
2021-10-12 19:30       ` Uwe Kleine-König [this message]
2021-10-13  6:52         ` Greg Kroah-Hartman
2021-10-13  7:33           ` Uwe Kleine-König
2021-10-07 17:23 ` Lukas Wunner

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=20211012193005.lxqzbsdeh4k7nxe2@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=broonie@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jarkko.nikula@intel.com \
    --cc=linux-spi@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mika.westerberg@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;
as well as URLs for NNTP newsgroup(s).