Commit 1a25b1c4 authored by Mikulas Patocka's avatar Mikulas Patocka Committed by Linus Torvalds

Lock splice_read and splice_write functions

Functions generic_file_splice_read and generic_file_splice_write access
the pagecache directly. For block devices these functions must be locked
so that block size is not changed while they are in progress.

This patch is an additional fix for commit b87570f5 ("Fix a crash
when block device is read and block size is changed at the same time")
that locked aio_read, aio_write and mmap against block size change.
Signed-off-by: default avatarMikulas Patocka <mpatocka@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 1bf11c53
...@@ -1661,6 +1661,39 @@ static int blkdev_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -1661,6 +1661,39 @@ static int blkdev_mmap(struct file *file, struct vm_area_struct *vma)
return ret; return ret;
} }
static ssize_t blkdev_splice_read(struct file *file, loff_t *ppos,
struct pipe_inode_info *pipe, size_t len,
unsigned int flags)
{
ssize_t ret;
struct block_device *bdev = I_BDEV(file->f_mapping->host);
percpu_down_read(&bdev->bd_block_size_semaphore);
ret = generic_file_splice_read(file, ppos, pipe, len, flags);
percpu_up_read(&bdev->bd_block_size_semaphore);
return ret;
}
static ssize_t blkdev_splice_write(struct pipe_inode_info *pipe,
struct file *file, loff_t *ppos, size_t len,
unsigned int flags)
{
ssize_t ret;
struct block_device *bdev = I_BDEV(file->f_mapping->host);
percpu_down_read(&bdev->bd_block_size_semaphore);
ret = generic_file_splice_write(pipe, file, ppos, len, flags);
percpu_up_read(&bdev->bd_block_size_semaphore);
return ret;
}
/* /*
* Try to release a page associated with block device when the system * Try to release a page associated with block device when the system
* is under memory pressure. * is under memory pressure.
...@@ -1699,8 +1732,8 @@ const struct file_operations def_blk_fops = { ...@@ -1699,8 +1732,8 @@ const struct file_operations def_blk_fops = {
#ifdef CONFIG_COMPAT #ifdef CONFIG_COMPAT
.compat_ioctl = compat_blkdev_ioctl, .compat_ioctl = compat_blkdev_ioctl,
#endif #endif
.splice_read = generic_file_splice_read, .splice_read = blkdev_splice_read,
.splice_write = generic_file_splice_write, .splice_write = blkdev_splice_write,
}; };
int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg) int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment