Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 b87570f5d349 ("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: Mikulas Patocka <mpatocka@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Mikulas Patocka and committed by
Linus Torvalds
1a25b1c4 1bf11c53

+35 -2
+35 -2
fs/block_dev.c
··· 1661 1661 return ret; 1662 1662 } 1663 1663 1664 + static ssize_t blkdev_splice_read(struct file *file, loff_t *ppos, 1665 + struct pipe_inode_info *pipe, size_t len, 1666 + unsigned int flags) 1667 + { 1668 + ssize_t ret; 1669 + struct block_device *bdev = I_BDEV(file->f_mapping->host); 1670 + 1671 + percpu_down_read(&bdev->bd_block_size_semaphore); 1672 + 1673 + ret = generic_file_splice_read(file, ppos, pipe, len, flags); 1674 + 1675 + percpu_up_read(&bdev->bd_block_size_semaphore); 1676 + 1677 + return ret; 1678 + } 1679 + 1680 + static ssize_t blkdev_splice_write(struct pipe_inode_info *pipe, 1681 + struct file *file, loff_t *ppos, size_t len, 1682 + unsigned int flags) 1683 + { 1684 + ssize_t ret; 1685 + struct block_device *bdev = I_BDEV(file->f_mapping->host); 1686 + 1687 + percpu_down_read(&bdev->bd_block_size_semaphore); 1688 + 1689 + ret = generic_file_splice_write(pipe, file, ppos, len, flags); 1690 + 1691 + percpu_up_read(&bdev->bd_block_size_semaphore); 1692 + 1693 + return ret; 1694 + } 1695 + 1696 + 1664 1697 /* 1665 1698 * Try to release a page associated with block device when the system 1666 1699 * is under memory pressure. ··· 1732 1699 #ifdef CONFIG_COMPAT 1733 1700 .compat_ioctl = compat_blkdev_ioctl, 1734 1701 #endif 1735 - .splice_read = generic_file_splice_read, 1736 - .splice_write = generic_file_splice_write, 1702 + .splice_read = blkdev_splice_read, 1703 + .splice_write = blkdev_splice_write, 1737 1704 }; 1738 1705 1739 1706 int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg)