From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: Chris Rankin <rankincj@yahoo.com>
Cc: Devin Heitmueller <dheitmueller@kernellabs.com>,
linux-media@vger.kernel.org, Antti Palosaari <crope@iki.fi>
Subject: Re: [PATCH 2/2] EM28xx - fix deadlock when unplugging and replugging a DVB adapter
Date: Sat, 20 Aug 2011 05:34:02 -0700 [thread overview]
Message-ID: <4E4FA9BA.1020306@redhat.com> (raw)
In-Reply-To: <4E4F9E86.7030001@yahoo.com>
Em 20-08-2011 04:46, Chris Rankin escreveu:
> The final patch removes the unplug/replug deadlock by not holding the device mutex during dvb_init(). However, this mutex has already been locked during device initialisation by em28xx_usb_probe() and is not released again until all extensions have been initialised successfully.
No. The extension load can happen after the usb probe phase. In practice,
the only case where the extension init will happen together with the
usb probe phase is when the em28xx modules are compiled builtin, as the
module load is done asynchronously, and generally happens after the em28xx
core to load.
> The device mutex is not held during either em28xx_register_extension() or em28xx_unregister_extension() any more. More importantly, I don't believe it can safely be held by these functions because they must both - by their nature - acquire the device list mutex before they can iterate through the device list. In other words, while usb_probe() and usb_disconnect() acquire the device mutex followed by the device list mutex, the register/unregister_extension() functions would need to acquire these mutexes in the opposite order. And that sounds like a potential deadlock.
>
> On the other hand, the new situation is a definite improvement :-).
No, it is a regression for a known bug.
This patch can cause troubles. The point is that, after initializing the
analog part, the device can be accessed via the V4L2 API, while it is
still initializing the DVB part. This actually happens in practice, as
when udev detects a new device, it opens it and calls VIDIOC_QUERYCAP.
So, it ends by having a race issue, as at V4L2 open, or at some analog mode
ioctl's, there are calls for em28xx_set_mode(dev, EM28XX_ANALOG_MODE).
In order words, if the DVB initialization is still happening, the driver
should not allow any V4L2 call, otherwise the DVB detection breaks.
Maybe the proper fix would be to change the logic under em28xx_usb_probe()
to not hold dev->lock anymore when the device is loading the extensions.
>
> Signed-off-by: Chris Rankin <rankincj@yahoo.com>
>
>
> EM28xx-replug-deadlock.diff
>
>
> --- linux-3.0/drivers/media/video/em28xx/em28xx-dvb.c.orig 2011-08-19 00:50:41.000000000 +0100
> +++ linux-3.0/drivers/media/video/em28xx/em28xx-dvb.c 2011-08-19 00:51:03.000000000 +0100
> @@ -542,7 +542,6 @@
> dev->dvb = dvb;
> dvb->fe[0] = dvb->fe[1] = NULL;
>
> - mutex_lock(&dev->lock);
> em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
> /* init frontend */
> switch (dev->model) {
> @@ -711,7 +710,6 @@
> em28xx_info("Successfully loaded em28xx-dvb\n");
> ret:
> em28xx_set_mode(dev, EM28XX_SUSPEND);
> - mutex_unlock(&dev->lock);
> return result;
>
> out_free:
next prev parent reply other threads:[~2011-08-20 12:34 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-18 17:52 [PATCH] Latest version of em28xx / em28xx-dvb patch for PCTV 290e Chris Rankin
2011-08-18 18:43 ` Devin Heitmueller
2011-08-18 18:44 ` Devin Heitmueller
2011-08-18 21:34 ` Chris Rankin
2011-08-18 22:11 ` Chris Rankin
2011-08-19 5:53 ` Mauro Carvalho Chehab
2011-08-20 11:08 ` [PATCH 1/6 ] EM28xx - pass correct buffer size to snprintf Chris Rankin
2011-08-20 11:14 ` [PATCH 2/6] Fix memory leak on disconnect or error Chris Rankin
2011-08-20 11:21 ` [PATCH 3/6] EM28xx - use atomic bit operations for devices-in-use mask Chris Rankin
2011-08-20 11:28 ` [PATCH 4/6] EM28xx - clean up resources should init fail Chris Rankin
2011-08-20 11:31 ` [PATCH 5/6] EM28xx - move printk lines outside mutex lock Chris Rankin
2011-08-20 11:37 ` [PATCH 6/6] EM28xx - don't sleep on disconnect Chris Rankin
2011-08-20 12:17 ` Mauro Carvalho Chehab
2011-08-20 13:46 ` Chris Rankin
2011-08-20 14:20 ` Mauro Carvalho Chehab
2011-08-20 19:01 ` Chris Rankin
2011-08-20 11:42 ` [PATCH 1/2] EM28xx - fix race " Chris Rankin
2011-08-20 12:36 ` Sylwester Nawrocki
2011-08-20 11:46 ` [PATCH 2/2] EM28xx - fix deadlock when unplugging and replugging a DVB adapter Chris Rankin
2011-08-20 12:34 ` Mauro Carvalho Chehab [this message]
2011-08-20 14:40 ` Chris Rankin
2011-08-20 15:02 ` Mauro Carvalho Chehab
2011-08-20 22:38 ` [PATCH 1/1] " Chris Rankin
2011-08-21 12:32 ` Chris Rankin
2011-09-13 20:04 ` Antti Palosaari
2011-09-13 20:47 ` Chris Rankin
2011-08-18 22:28 ` [PATCH] Latest version of em28xx / em28xx-dvb patch for PCTV 290e Chris Rankin
2011-08-18 23:45 ` Chris Rankin
2011-08-19 0:12 ` Chris Rankin
2011-08-18 19:56 ` Chris Rankin
2011-08-19 1:01 ` Mauro Carvalho Chehab
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=4E4FA9BA.1020306@redhat.com \
--to=mchehab@redhat.com \
--cc=crope@iki.fi \
--cc=dheitmueller@kernellabs.com \
--cc=linux-media@vger.kernel.org \
--cc=rankincj@yahoo.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