Re: Naughty ramdrives

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 8 Sep 2006 02:08:53 +0400
Alexey Dobriyan <[email protected]> wrote:

> > So I assume udev is still madly crunching on its message backlog while
> > this is happening?
> >
> > If so, ug.
> 
> OK. I'll let it stabilize, sorry.

You shouldn't have to.

> > > This was noticed while investigating #4899
> > > http://bugme.osdl.org/show_bug.cgi?id=4899
> > > where /dev/ram0 when opened, pins module indefinitely. It seems that
> > > adding ->release() which undoes
> > >
> > > 	inode = igrab(bdev->bd_inode);
> > >
> > > should do the trick. Am I right?
> 
> > Looks right.
> >
> > I'm not sure that igrab() is needed though.  Probably bd_openers is
> > sufficient.
> >
> > I'm also not sure that rd_open() needs to play with bd_openers.
> > fs/block_dev.c:do_open() already does that.
> 
> Maybe start with closing open/open race?
> That's what drivers/char/raw.c does...
> ------------------------------------------------
> [PATCH 1/2] rd: protect rd_bdev[] with mutex
> 
> Signed-off-by: Alexey Dobriyan <[email protected]>
> ---
> 
>  drivers/block/rd.c |    4 ++++
>  1 file changed, 4 insertions(+)
> 
> --- a/drivers/block/rd.c
> +++ b/drivers/block/rd.c
> @@ -56,6 +56,7 @@ #include <linux/buffer_head.h>		/* for i
>  #include <linux/backing-dev.h>
>  #include <linux/blkpg.h>
>  #include <linux/writeback.h>
> +#include <linux/mutex.h>
>  
>  #include <asm/uaccess.h>
>  
> @@ -63,6 +64,7 @@ #include <asm/uaccess.h>
>   */
>  
>  static struct gendisk *rd_disks[CONFIG_BLK_DEV_RAM_COUNT];
> +static DEFINE_MUTEX(rd_mutex);

This could be static to rd_open().

>  static struct block_device *rd_bdev[CONFIG_BLK_DEV_RAM_COUNT];/* Protected device data */
>  static struct request_queue *rd_queue[CONFIG_BLK_DEV_RAM_COUNT];
>  
> @@ -343,6 +345,7 @@ static int rd_open(struct inode *inode, 
>  {
>  	unsigned unit = iminor(inode);
>  
> +	mutex_lock(&rd_mutex);

I suspect that we've inherited enough locking from the caller to not need
this.  That's if fs/block_dev.c:do_open() is the only caller.  Not sure if
that's true if someone goes and partitions a ramdisk (is that possible?).

All this gendisk/blockdev/contains/partitions/bd_inode stuff is quite
ghastly.  Every six months I spend long enough staring at it to
half-understand it and then promptly forget how it all works.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux