linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab@redhat.com>
To: "Steinar H. Gunderson" <sgunderson@bigfoot.com>
Cc: linux-media@vger.kernel.org, "Steinar H. Gunderson" <sesse@samfundet.no>
Subject: Re: [PATCH 03/11] Hack to fix a mutex issue in the DVB layer.
Date: Tue, 10 Apr 2012 23:17:54 -0300	[thread overview]
Message-ID: <4F84E9D2.7000405@redhat.com> (raw)
In-Reply-To: <1333295631-31866-3-git-send-email-sgunderson@bigfoot.com>

Em 01-04-2012 12:53, Steinar H. Gunderson escreveu:
> From: "Steinar H. Gunderson" <sesse@samfundet.no>
> 
> dvb_usercopy(), which is called on all ioctls, not only copies data to and from
> userspace, but also takes a lock on the file descriptor, which means that only
> one ioctl can run at a time. This means that if one thread of mumudvb is busy
> trying to get, say, the SNR from the frontend (which can hang due to the issue
> above), the CAM thread's ioctl(fd, CA_GET_SLOT_INFO, ...) will hang, even
> though it doesn't need to communicate with the hardware at all.  This obviously
> requires a better fix, but I don't know the generic DVB layer well enough to
> say what it is. Maybe it's some sort of remnant of from when all ioctl()s took
> the BKL. Note that on UMP kernels without preemption, mutex_lock is to the best
> of my knowledge a no-op, so these delay issues would not show up on non-SMP.
> 
> Signed-off-by: Steinar H. Gunderson <sesse@samfundet.no>
> ---
>  drivers/media/dvb/dvb-core/dvbdev.c |    2 --
>  1 file changed, 2 deletions(-)
> 
> diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
> index 00a6732..e1217f6 100644
> --- a/drivers/media/dvb/dvb-core/dvbdev.c
> +++ b/drivers/media/dvb/dvb-core/dvbdev.c
> @@ -417,10 +417,8 @@ int dvb_usercopy(struct file *file,
>  	}
>  
>  	/* call driver */
> -	mutex_lock(&dvbdev_mutex);
>  	if ((err = func(file, cmd, parg)) == -ENOIOCTLCMD)
>  		err = -EINVAL;
> -	mutex_unlock(&dvbdev_mutex);

As-is, this would be too risky, as it may break random drivers. 

A change like that would require to push down the mutex lock into each caller for
dvb_user_copy:

drivers/media/dvb/dvb-core/dmxdev.c:      return dvb_usercopy(file, cmd, arg, dvb_demux_do_ioctl);
drivers/media/dvb/dvb-core/dmxdev.c:      return dvb_usercopy(file, cmd, arg, dvb_dvr_do_ioctl);
drivers/media/dvb/dvb-core/dvb_ca_en50221.c:      return dvb_usercopy(file, cmd, arg, dvb_ca_en50221_io_do_ioctl);
drivers/media/dvb/dvb-core/dvb_net.c:     return dvb_usercopy(file, cmd, arg, dvb_net_do_ioctl);
drivers/media/dvb/dvb-core/dvbdev.c:      return dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
drivers/media/dvb/dvb-core/dvbdev.c:int dvb_usercopy(struct file *file,
drivers/media/dvb/dvb-core/dvbdev.h:we simply define out own dvb_usercopy(), which will hopefully become
drivers/media/dvb/dvb-core/dvbdev.h:extern int dvb_usercopy(struct file *file, unsigned int cmd, unsigned long arg,

$ git grep kernel_ioctl drivers/media/dvb/
drivers/media/dvb/dvb-core/dvb_frontend.c:                .kernel_ioctl = dvb_frontend_ioctl
drivers/media/dvb/dvb-core/dvbdev.c:      if (!dvbdev->kernel_ioctl)
drivers/media/dvb/dvb-core/dvbdev.c:      return dvb_usercopy(file, cmd, arg, dvbdev->kernel_ioctl);
drivers/media/dvb/dvb-core/dvbdev.h:      int (*kernel_ioctl)(struct file *file, unsigned int cmd, void *arg);
drivers/media/dvb/firewire/firedtv-ci.c:  .kernel_ioctl   = fdtv_ca_ioctl,
drivers/media/dvb/ttpci/av7110.c: .kernel_ioctl   = dvb_osd_ioctl,
drivers/media/dvb/ttpci/av7110_av.c:      .kernel_ioctl   = dvb_video_ioctl,
drivers/media/dvb/ttpci/av7110_av.c:      .kernel_ioctl   = dvb_audio_ioctl,
drivers/media/dvb/ttpci/av7110_ca.c:      .kernel_ioctl   = dvb_ca_ioctl,

And optimize the code there to avoid uneeded locks.

>  
>  	if (err < 0)
>  		goto out;


  reply	other threads:[~2012-04-11  2:18 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-01 15:53 [PATCH] Various fixes, hacks and patches for Mantis CA support Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 01/11] Don't reset IRQ0 if it's not already set Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 02/11] Clear out MANTIS_INT_RISCSTAT when printing status bits Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 03/11] Hack to fix a mutex issue in the DVB layer Steinar H. Gunderson
2012-04-11  2:17   ` Mauro Carvalho Chehab [this message]
2012-04-01 15:53 ` [PATCH 04/11] Show timeouts on I2C transfers Steinar H. Gunderson
2012-04-04 15:43   ` Marko Ristola
2012-04-04 16:32     ` Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 05/11] Slightly more friendly debugging output Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 06/11] Replace ca_lock by a slightly more general int_stat_lock Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 07/11] Fix a ton of SMP-unsafe accesses Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 08/11] Remove some unused structure members Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 09/11] Correct wait_event_timeout error return check Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 10/11] Ignore timeouts waiting for the IRQ0 flag Steinar H. Gunderson
2012-04-01 15:53 ` [PATCH 11/11] Enable Mantis CA support Steinar H. Gunderson
2012-04-18 18:38 ` [PATCH] Various fixes, hacks and patches for " Ninja
2012-04-18 18:53   ` Steinar H. Gunderson

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=4F84E9D2.7000405@redhat.com \
    --to=mchehab@redhat.com \
    --cc=linux-media@vger.kernel.org \
    --cc=sesse@samfundet.no \
    --cc=sgunderson@bigfoot.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).