lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Fri,  6 Aug 2021 12:22:10 +0100
From:   Pavel Begunkov <asml.silence@...il.com>
To:     Alexander Viro <viro@...iv.linux.org.uk>,
        linux-fsdevel@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: [PATCH] fs: optimise generic_write_check_limits()

Even though ->s_maxbytes is used by generic_write_check_limits() only in
case of O_LARGEFILE, the value is loaded unconditionally, which is heavy
and takes 4 indirect loads. Optimise it by not touching ->s_maxbytes,
if it's not going to be used.

Signed-off-by: Pavel Begunkov <asml.silence@...il.com>
---
 fs/read_write.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index 9db7adf160d2..db662d0c3cfa 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -1609,9 +1609,8 @@ SYSCALL_DEFINE6(copy_file_range, int, fd_in, loff_t __user *, off_in,
  */
 int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count)
 {
-	struct inode *inode = file->f_mapping->host;
-	loff_t max_size = inode->i_sb->s_maxbytes;
 	loff_t limit = rlimit(RLIMIT_FSIZE);
+	loff_t max_size = MAX_NON_LFS;
 
 	if (limit != RLIM_INFINITY) {
 		if (pos >= limit) {
@@ -1621,8 +1620,11 @@ int generic_write_check_limits(struct file *file, loff_t pos, loff_t *count)
 		*count = min(*count, limit - pos);
 	}
 
-	if (!(file->f_flags & O_LARGEFILE))
-		max_size = MAX_NON_LFS;
+	if (file->f_flags & O_LARGEFILE) {
+		struct inode *inode = file->f_mapping->host;
+
+		max_size = inode->i_sb->s_maxbytes;
+	}
 
 	if (unlikely(pos >= max_size))
 		return -EFBIG;
-- 
2.32.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ