ext4: remove redundant check for encrypted file on dio write path
PATCH 1/1 ext4: remove redundant check for encrypted file on dio write path
From: Eric Biggers <[email protected]>
Currently we don't allow direct I/O on encrypted regular files, so in such cases we return 0 early in ext4_direct_IO(). There was also an additional BUG_ON() check in ext4_direct_IO_write(), but it can never be hit because of the earlier check for the exact same condition in ext4_direct_IO(). There was also no matching check on the read path, which made the write path specific check seem very ad-hoc.
Just remove the unnecessary BUG_ON().
--- fs/ext4/inode.c | 3 --- 1 file changed, 3 deletions(-)
fs/ext4/inode.c +0 -3
@@ -3629,9 +3629,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) get_block_func = ext4_dio_get_block_unwritten_async; dio_flags =DIO_LOCKING ; } -#ifdef CONFIG_EXT4_FS_ENCRYPTION -BUG_ON (ext4_encrypted_inode (inode) &&S_ISREG (inode->i_mode)); -#endif ret =__blockdev_direct_IO (iocb, inode, inode->i_sb->s_bdev, iter, get_block_func, ext4_end_io_dio,NULL , dio_flags);
Signature · 1 line
2.13.0.303.g4ebf302169-goog
Hi Eric,
Quoted 34 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Currently we don't allow direct I/O on encrypted regular files, so in such cases we return 0 early in
ext4_direct_IO(). There was also an additionalBUG_ON()check inext4_direct_IO_write(), but it can never be hit because of the earlier check for the exact same condition inext4_direct_IO(). There was also no matching check on the read path, which made the write path specific check seem very ad-hoc.Just remove the unnecessary
BUG_ON().Signed-off-by Eric Biggers <[email protected]>---
fs/ext4/inode.c| 3 ---1 file changed, 3 deletions(-)fs/ext4/inode.c +0
-3@@ -3629,9 +3629,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) get_block_func = ext4_dio_get_block_unwritten_async; dio_flags =DIO_LOCKING ; } -#ifdef CONFIG_EXT4_FS_ENCRYPTION -BUG_ON (ext4_encrypted_inode (inode) &&S_ISREG (inode->i_mode)); -#endif ret =__blockdev_direct_IO (iocb, inode, inode->i_sb->s_bdev, iter, get_block_func, ext4_end_io_dio,NULL , dio_flags);Signature · 1 line
2.13.0.303.g4ebf302169-goog
LGTM.
David
Jan Kara
reviewerQuoted 9 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Currently we don't allow direct I/O on encrypted regular files, so in such cases we return 0 early in
ext4_direct_IO(). There was also an additionalBUG_ON()check inext4_direct_IO_write(), but it can never be hit because of the earlier check for the exact same condition inext4_direct_IO(). There was also no matching check on the read path, which made the write path specific check seem very ad-hoc.
Quoted 3 lines
Just remove the unnecessary
BUG_ON().Signed-off-by Eric Biggers <[email protected]>
Yeah, the check is rather before the BUG_ON so I guess that there's no big point in the BUG_ON. When looking at this code I have one question though:
So when you mount the filesystem with 'dioread_nolock', do overwriting direct write to the file, and just after we do inode_unlock() in ext4_direct_IO_write() someone calls EXT4_IOC_SET_ENCRYPTION_POLICY ioctl on the file, the BUG_ON could actually trigger. So I think you need to wait for outstanding direct IO for the file when setting encryption policy. Likely in ext4_set_context() or maybe in the generic fscrypt code (you need to wait after acquiring inode_lock), I'm not sure how other filesystems using fscrypt handle this and whether it would make more sense in the generic code or in ext4 specific one.
Honza
Quoted 21 lines
--- fs/ext4/inode.c | 3 --- 1 file changed, 3 deletions(-)fs/ext4/inode.c +0
-3@@ -3629,9 +3629,6 @@ static ssize_t ext4_direct_IO_write(struct kiocb *iocb, struct iov_iter *iter) get_block_func = ext4_dio_get_block_unwritten_async; dio_flags =DIO_LOCKING ; } -#ifdef CONFIG_EXT4_FS_ENCRYPTION -BUG_ON (ext4_encrypted_inode (inode) &&S_ISREG (inode->i_mode)); -#endif ret =__blockdev_direct_IO (iocb, inode, inode->i_sb->s_bdev, iter, get_block_func, ext4_end_io_dio,NULL , dio_flags);Signature · 1 line
2.13.0.303.g4ebf302169-goog
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Hi Jan,
Quoted 17 lines · Jan Kara
Quoted 9 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Currently we don't allow direct I/O on encrypted regular files, so in such cases we return 0 early in
ext4_direct_IO(). There was also an additionalBUG_ON()check inext4_direct_IO_write(), but it can never be hit because of the earlier check for the exact same condition inext4_direct_IO(). There was also no matching check on the read path, which made the write path specific check seem very ad-hoc.Quoted 3 lines
Just remove the unnecessary
BUG_ON().Signed-off-by Eric Biggers <[email protected]>Yeah, the check is rather before the
BUG_ONso I guess that there's no big point in theBUG_ON. When looking at this code I have one question though:
Quoted 10 lines
So when you mount the filesystem with '
dioread_nolock', do overwriting direct write to the file, and just after we doinode_unlock()inext4_direct_IO_write()someone callsEXT4_IOC_SET_ENCRYPTION_POLICYioctl on the file, theBUG_ONcould actually trigger. So I think you need to wait for outstanding direct IO for the file when setting encryption policy. Likely inext4_set_context()or maybe in the generic fscrypt code (you need to wait after acquiringinode_lock), I'm not sure how other filesystems using fscrypt handle this and whether it would make more sense in the generic code or in ext4 specific one.
That's not possible because the ioctl can only set an encryption policy on a directory, and specifically an empty one. Other files can only acquire an encryption policy through inheritance. There have been thoughts about implementing "in-place" encryption but it's not something we currently support.
Eric
Quoted 32 lines · Eric Biggers
Hi Jan,
Quoted 18 lines · Jan Kara
Quoted 9 lines · Eric Biggers
From: Eric Biggers <[email protected]>
Currently we don't allow direct I/O on encrypted regular files, so in such cases we return 0 early in
ext4_direct_IO(). There was also an additionalBUG_ON()check inext4_direct_IO_write(), but it can never be hit because of the earlier check for the exact same condition inext4_direct_IO(). There was also no matching check on the read path, which made the write path specific check seem very ad-hoc.Quoted 3 lines
Just remove the unnecessary
BUG_ON().Signed-off-by Eric Biggers <[email protected]>Yeah, the check is rather before the
BUG_ONso I guess that there's no big point in theBUG_ON. When looking at this code I have one question though:Quoted 10 lines
So when you mount the filesystem with '
dioread_nolock', do overwriting direct write to the file, and just after we doinode_unlock()inext4_direct_IO_write()someone callsEXT4_IOC_SET_ENCRYPTION_POLICYioctl on the file, theBUG_ONcould actually trigger. So I think you need to wait for outstanding direct IO for the file when setting encryption policy. Likely inext4_set_context()or maybe in the generic fscrypt code (you need to wait after acquiringinode_lock), I'm not sure how other filesystems using fscrypt handle this and whether it would make more sense in the generic code or in ext4 specific one.
Quoted 5 lines
That's not possible because the ioctl can only set an encryption policy on a directory, and specifically an empty one. Other files can only acquire an encryption policy through inheritance. There have been thoughts about implementing "in-place" encryption but it's not something we currently support.
Ah, good. Thanks for explanation. Then you can add:
to your patch.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Thanks, applied.
- Ted