clean up kernel_{read,write} & friends v2
Subsystems (14)
Hi Al,
this series fixes a few issues and cleans up the helpers that read from or write to kernel space buffers, and ensures that we don't change the address limit if we are using the ->read_iter and ->write_iter methods that don't need the changed address limit.
Changes since v2:
- picked up a few ACKs
Changes since v1:
- __kernel_write must not take sb_writers
- unexport __kernel_write
PATCH 1/14 cachefiles: switch to kernel_write
__kernel_write doesn't take a sb_writers references, which we need here.
--- fs/cachefiles/rdwr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/cachefiles/rdwr.c +1 -1
@@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page) } data =kmap (page); - ret =__kernel_write (file, data, len, &pos); + ret =kernel_write (file, data, len, &pos);kunmap (page);fput (file);if (ret != len)
Signature · 1 line
2.26.2
PATCH 2/14 autofs: switch to kernel_write
In reply to Christoph HellwigWhile pipes don't really need sb_writers projection, __kernel_write is an interface better kept private, and the additional rw_verify_area does not hurt here.
--- fs/autofs/waitq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/autofs/waitq.c +1 -1
@@ -53,7 +53,7 @@ static int autofs_write(struct autofs_sb_info *sbi,mutex_lock (&sbi->pipe_mutex);while (bytes) { - wr =__kernel_write (file, data, bytes, &file->f_pos); + wr =kernel_write (file, data, bytes, &file->f_pos);if (wr <=0 )break ; data += wr;
Signature · 1 line
2.26.2
PATCH 3/14 bpfilter: switch to kernel_write
In reply to Christoph HellwigWhile pipes don't really need sb_writers projection, __kernel_write is an interface better kept private, and the additional rw_verify_area does not hurt here.
--- net/bpfilter/bpfilter_kern.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/bpfilter/bpfilter_kern.c +1 -1
@@ -50,7 +50,7 @@ static int __bpfilter_process_sockopt(struct sock *sk, int optname, req.len = optlen;if (!bpfilter_ops.info.pid) goto out; - n =__kernel_write (bpfilter_ops.info.pipe_to_umh, &req,sizeof (req), + n =kernel_write (bpfilter_ops.info.pipe_to_umh, &req,sizeof (req), &pos);if (n !=sizeof (req)) {pr_err ("write fail %zd\n" , n);
Signature · 1 line
2.26.2
PATCH 4/14 fs: unexport __kernel_write
In reply to Christoph HellwigThis is a very special interface that skips sb_writes protection, and not used by modules anymore.
--- fs/read_write.c | 1 - 1 file changed, 1 deletion(-)
fs/read_write.c +0 -1
@@ -522,7 +522,6 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_tinc_syscw (current);return ret; } -EXPORT_SYMBOL (__kernel_write);ssize_t kernel_write (struct file *file,const void *buf,size_t count,loff_t *pos)
Signature · 1 line
2.26.2
PATCH 5/14 fs: check FMODE_WRITE in __kernel_write
In reply to Christoph HellwigWe still need to check if the fѕ is open write, even for the low-level helper.
--- fs/read_write.c | 2 ++ 1 file changed, 2 insertions(+)
fs/read_write.c +2 -0
@@ -505,6 +505,8 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_tconst char __user *p;ssize_t ret; +if (!(file->f_mode &FMODE_WRITE )) +return -EBADF ;if (!(file->f_mode &FMODE_CAN_WRITE ))return -EINVAL ;
Signature · 1 line
2.26.2
PATCH 6/14 fs: remove the call_{read,write}_iter functions
In reply to Christoph HellwigJust open coding the methods calls is a lot easier to follow.
--- drivers/block/loop.c | 4 ++-- drivers/target/target_core_file.c | 4 ++-- fs/aio.c | 4 ++-- fs/io_uring.c | 4 ++-- fs/read_write.c | 12 ++++++------ fs/splice.c | 2 +- include/linux/fs.h | 12 ------------ 7 files changed, 15 insertions(+), 27 deletions(-)
drivers/block/loop.c +2 -2
@@ -572,9 +572,9 @@ static int lo_rw_aio(struct loop_device *lo, struct loop_cmd *cmd,kthread_associate_blkcg (cmd->css);if (rw ==WRITE ) - ret =call_write_iter (file, &cmd->iocb, &iter); + ret = file->f_op->write_iter (&cmd->iocb, &iter);else - ret =call_read_iter (file, &cmd->iocb, &iter); + ret = file->f_op->read_iter (&cmd->iocb, &iter);lo_rw_aio_do_completion (cmd);kthread_associate_blkcg (NULL );
drivers/target/target_core_file.c +2 -2
@@ -303,9 +303,9 @@ fd_execute_rw_aio(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents, aio_cmd->iocb.ki_flags |=IOCB_DSYNC ;if (is_write) - ret =call_write_iter (file, &aio_cmd->iocb, &iter); + ret = file->f_op->write_iter (&aio_cmd->iocb, &iter);else - ret =call_read_iter (file, &aio_cmd->iocb, &iter); + ret = file->f_op->read_iter (&aio_cmd->iocb, &iter);kfree (bvec);
fs/aio.c +2 -2
@@ -1540,7 +1540,7 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb,return ret; ret =rw_verify_area (READ , file, &req->ki_pos,iov_iter_count (&iter));if (!ret) -aio_rw_done (req,call_read_iter (file, req, &iter)); +aio_rw_done (req, file->f_op->read_iter (req, &iter));kfree (iovec);return ret; }
@@ -1580,7 +1580,7 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb,__sb_writers_release (file_inode (file)->i_sb,SB_FREEZE_WRITE ); } req->ki_flags |=IOCB_WRITE ; -aio_rw_done (req,call_write_iter (file, req, &iter)); +aio_rw_done (req, file->f_op->write_iter (req, &iter)); }kfree (iovec);return ret;
fs/io_uring.c +2 -2
@@ -2579,7 +2579,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock)ssize_t ret2;if (req->file->f_op->read_iter) - ret2 =call_read_iter (req->file, kiocb, &iter); + ret2 = req->file->f_op->read_iter (kiocb, &iter);else ret2 =loop_rw_iter (READ , req->file, kiocb, &iter);
@@ -2694,7 +2694,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock) current->signal->rlim[RLIMIT_FSIZE ].rlim_cur = req->fsize;if (req->file->f_op->write_iter) - ret2 =call_write_iter (req->file, kiocb, &iter); + ret2 = req->file->f_op->write_iter (kiocb, &iter);else ret2 =loop_rw_iter (WRITE , req->file, kiocb, &iter);
fs/read_write.c +6 -6
@@ -412,7 +412,7 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo kiocb.ki_pos = (ppos ? *ppos :0 );iov_iter_init (&iter,READ , &iov,1 , len); - ret =call_read_iter (filp, &kiocb, &iter); + ret = filp->f_op->read_iter (&kiocb, &iter);BUG_ON (ret == -EIOCBQUEUED );if (ppos) *ppos = kiocb.ki_pos;
@@ -481,7 +481,7 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t kiocb.ki_pos = (ppos ? *ppos :0 );iov_iter_init (&iter,WRITE , &iov,1 , len); - ret =call_write_iter (filp, &kiocb, &iter); + ret = filp->f_op->write_iter (&kiocb, &iter);BUG_ON (ret == -EIOCBQUEUED );if (ret >0 && ppos) *ppos = kiocb.ki_pos;
@@ -690,9 +690,9 @@ static ssize_t do_iter_readv_writev(struct file *filp, struct iov_iter *iter, kiocb.ki_pos = (ppos ? *ppos :0 );if (type ==READ ) - ret =call_read_iter (filp, &kiocb, iter); + ret = filp->f_op->read_iter (&kiocb, iter);else - ret =call_write_iter (filp, &kiocb, iter); + ret = filp->f_op->write_iter (&kiocb, iter);BUG_ON (ret == -EIOCBQUEUED );if (ppos) *ppos = kiocb.ki_pos;
@@ -961,7 +961,7 @@ ssize_t vfs_iocb_iter_read(struct file *file, struct kiocb *iocb,if (ret <0 )return ret; - ret =call_read_iter (file, iocb, iter); + ret = file->f_op->read_iter (iocb, iter); out:if (ret >=0 )fsnotify_access (file);
@@ -1025,7 +1025,7 @@ ssize_t vfs_iocb_iter_write(struct file *file, struct kiocb *iocb,if (ret <0 )return ret; - ret =call_write_iter (file, iocb, iter); + ret = file->f_op->write_iter (iocb, iter);if (ret >0 )fsnotify_modify (file);
fs/splice.c +1 -1
@@ -310,7 +310,7 @@ ssize_t generic_file_splice_read(struct file *in, loff_t *ppos, i_head = to.head;init_sync_kiocb (&kiocb, in); kiocb.ki_pos = *ppos; - ret =call_read_iter (in, &kiocb, &to); + ret = in->f_op->read_iter (&kiocb, &to);if (ret >0 ) { *ppos = kiocb.ki_pos;file_accessed (in);
include/linux/fs.h +0 -12
@@ -1895,18 +1895,6 @@ struct inode_operations {int (*set_acl)(struct inode *,struct posix_acl *,int ); }____cacheline_aligned ; -static inline ssize_t call_read_iter (struct file *file,struct kiocb *kio, -struct iov_iter *iter) -{ -return file->f_op->read_iter (kio, iter); -} - -static inline ssize_t call_write_iter (struct file *file,struct kiocb *kio, -struct iov_iter *iter) -{ -return file->f_op->write_iter (kio, iter); -} -static inline int call_mmap (struct file *file,struct vm_area_struct *vma) {return file->f_op->mmap (file, vma);
Signature · 1 line
2.26.2
Al Viro
maintainerRe: [PATCH 06/14] fs: remove the call_{read,write}_iter functions
Quoted 1 line · Christoph Hellwig
Just open coding the methods calls is a lot easier to follow.
Not sure about this one, TBH - it's harder to grep that way, since you get all the initializers for read_iter/write_iter thrown into
the mix. Sure, you can do something like '\->[ ]*read_iter\>',
but it's a PITA.
Re: [PATCH 06/14] fs: remove the call_{read,write}_iter functions
Quoted 7 lines · Al Viro
Quoted 1 line · Christoph Hellwig
Just open coding the methods calls is a lot easier to follow.
Not sure about this one, TBH - it's harder to grep that way, since you get all the initializers for read_iter/write_iter thrown into
the mix. Sure, you can do something like '\->[ ]*read_iter\>',
but it's a PITA.
Which you have to do anyway as not all calls go through these weird helpers.
PATCH 7/14 fs: implement kernel_write using __kernel_write
In reply to Christoph HellwigConsolidate the two in-kernel write helpers to make upcoming changes easier. The only difference are the missing call to rw_verify_area in kernel_write, and an access_ok check that doesn't make sense for kernel buffers to start with.
--- fs/read_write.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
fs/read_write.c +9 -8
@@ -499,6 +499,7 @@ static ssize_t __vfs_write(struct file *file, const char __user *p,return -EINVAL ; } +/* caller is responsible for file_start_write/file_end_write */ ssize_t __kernel_write (struct file *file,const void *buf,size_t count,loff_t *pos) {mm_segment_t old_fs;
@@ -528,16 +529,16 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_tssize_t kernel_write (struct file *file,const void *buf,size_t count,loff_t *pos) { -mm_segment_t old_fs; -ssize_t res; +ssize_t ret; - old_fs =get_fs (); -set_fs (KERNEL_DS ); -/* The cast to a user pointer is valid due to the set_fs() */ - res =vfs_write (file, (__force const char __user *)buf, count, pos); -set_fs (old_fs); + ret =rw_verify_area (WRITE , file, pos, count); +if (ret) +return ret; -return res; +file_start_write (file); + ret =__kernel_write (file, buf, count, pos); +file_end_write (file); +return ret; }EXPORT_SYMBOL (kernel_write);
Signature · 1 line
2.26.2
PATCH 8/14 fs: remove __vfs_write
In reply to Christoph HellwigFold it into the two callers.
--- fs/read_write.c | 46 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 24 deletions(-)
fs/read_write.c +22 -24
@@ -488,17 +488,6 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_treturn ret; } -static ssize_t __vfs_write (struct file *file,const char __user *p, -size_t count,loff_t *pos) -{ -if (file->f_op->write) -return file->f_op->write (file, p, count, pos); -else if (file->f_op->write_iter) -return new_sync_write (file, p, count, pos); -else -return -EINVAL ; -} -/* caller is responsible for file_start_write/file_end_write */ ssize_t __kernel_write (struct file *file,const void *buf,size_t count,loff_t *pos) {
@@ -516,7 +505,12 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t p = (__force const char __user *)buf;if (count >MAX_RW_COUNT ) count =MAX_RW_COUNT ; - ret =__vfs_write (file, p, count, pos); +if (file->f_op->write) + ret = file->f_op->write (file, p, count, pos); +else if (file->f_op->write_iter) + ret =new_sync_write (file, p, count, pos); +else + ret = -EINVAL ;set_fs (old_fs);if (ret >0 ) {fsnotify_modify (file);
@@ -554,19 +548,23 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_return -EFAULT ; ret =rw_verify_area (WRITE , file, pos, count); -if (!ret) { -if (count >MAX_RW_COUNT ) - count =MAX_RW_COUNT ; -file_start_write (file); - ret =__vfs_write (file, buf, count, pos); -if (ret >0 ) { -fsnotify_modify (file); -add_wchar (current, ret); - } -inc_syscw (current); -file_end_write (file); +if (ret) +return ret; +if (count >MAX_RW_COUNT ) + count =MAX_RW_COUNT ; +file_start_write (file); +if (file->f_op->write) + ret = file->f_op->write (file, buf, count, pos); +else if (file->f_op->write_iter) + ret =new_sync_write (file, buf, count, pos); +else + ret = -EINVAL ; +if (ret >0 ) { +fsnotify_modify (file); +add_wchar (current, ret); } - +inc_syscw (current); +file_end_write (file);return ret; }
Signature · 1 line
2.26.2
PATCH 9/14 fs: don't change the address limit for ->write_iter in __kernel_write
In reply to Christoph HellwigIf we write to a file that implements ->write_iter there is no need to change the address limit if we send a kvec down. Implement that case, and prefer it over using plain ->write with a changed address limit if available.
--- fs/read_write.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
fs/read_write.c +22 -12
@@ -489,10 +489,9 @@ static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t }/* caller is responsible for file_start_write/file_end_write */ -ssize_t __kernel_write (struct file *file,const void *buf,size_t count,loff_t *pos) +ssize_t __kernel_write (struct file *file,const void *buf,size_t count, +loff_t *pos) { -mm_segment_t old_fs; -const char __user *p;ssize_t ret;if (!(file->f_mode &FMODE_WRITE ))
@@ -500,18 +499,29 @@ ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_tif (!(file->f_mode &FMODE_CAN_WRITE ))return -EINVAL ; - old_fs =get_fs (); -set_fs (KERNEL_DS ); - p = (__force const char __user *)buf;if (count >MAX_RW_COUNT ) count =MAX_RW_COUNT ; -if (file->f_op->write) - ret = file->f_op->write (file, p, count, pos); -else if (file->f_op->write_iter) - ret =new_sync_write (file, p, count, pos); -else +if (file->f_op->write_iter) { +struct kvec iov = { .iov_base = (void *)buf, .iov_len = count }; +struct kiocb kiocb; +struct iov_iter iter; + +init_sync_kiocb (&kiocb, file); + kiocb.ki_pos = *pos; +iov_iter_kvec (&iter,WRITE , &iov,1 , count); + ret = file->f_op->write_iter (&kiocb, &iter); +if (ret >0 ) + *pos = kiocb.ki_pos; + }else if (file->f_op->write) { +mm_segment_t old_fs =get_fs (); + +set_fs (KERNEL_DS ); + ret = file->f_op->write (file, (__force const char __user *)buf, + count, pos); +set_fs (old_fs); + }else { ret = -EINVAL ; -set_fs (old_fs); + }if (ret >0 ) {fsnotify_modify (file);add_wchar (current, ret);
Signature · 1 line
2.26.2
Re: [PATCH 09/14] fs: don't change the address limit for ->write_iter in __kernel_write
fs/read_write.c static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t · line 493
Quoted 4 lines · Christoph Hellwig
fs/read_write.c +2
-1-ssize_t __kernel_write (struct file *file,const void *buf,size_t count,loff_t *pos) +ssize_t __kernel_write (struct file *file,const void *buf,size_t count, +loff_t *pos)
Please don't do these kinds of pointless whitespace changes.
If you have an actual 80x25 vt100 sitting in a corner, it's not really conducive to kernel development any more.
Yes, yes, we'd like to have shorter lines for new code, but no, don't do silly line breaks that just makes old code look and grep worse.
Linus
Re: [PATCH 09/14] fs: don't change the address limit for ->write_iter in __kernel_write
Quoted 10 lines · Linus Torvalds
fs/read_write.c static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t · line 493
Quoted 4 lines · Christoph Hellwig
fs/read_write.c +2
-1-ssize_t __kernel_write (struct file *file,const void *buf,size_t count,loff_t *pos) +ssize_t __kernel_write (struct file *file,const void *buf,size_t count, +loff_t *pos)Please don't do these kinds of pointless whitespace changes.
If you have an actual 80x25 vt100 sitting in a corner, it's not really conducive to kernel development any more.
I have real 80x25 xterms, as that allows me to comfortably fit 4 of them onto my latop screen.
Re: Re: [PATCH 09/14] fs: don't change the address limit for ->write_iter in __kernel_write
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Linus Torvalds
fs/read_write.c static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t · line 493
Quoted 4 lines · Christoph Hellwig
fs/read_write.c +2
-1-ssize_t __kernel_write (struct file *file,const void *buf,size_t count,loff_t *pos) +ssize_t __kernel_write (struct file *file,const void *buf,size_t count, +loff_t *pos)Please don't do these kinds of pointless whitespace changes.
Quoted 5 lines
Quoted 2 lines
If you have an actual 80x25 vt100 sitting in a corner, it's not really conducive to kernel development any more.
I have real 80x25 xterms, as that allows me to comfortably fit 4 of them onto my latop screen.
I second this. Doing work on a compact laptop is a legitimate use case and we can't all lug around big monitors with our laptops. I also find more terminals on a screen to be more productive.
I'd also like to make the point that I never thought the width limit was all that related to the hardware. It's been widely accepted for ages that it's easier to read narrower blocks of text (try reading a book on a landscape tablet: it's very difficult and causes eye strain). This is why newspapers and magazines have always laid out their text in columns and professional websites limit the width of their content. They have the hardware to write much longer lines but chose not to for readability. (Sadly, the *one* news source that I respect that doesn't do this is LWN and I have to resort to reader view in Firefox to make it readable.)
Furthermore, I find enforcing a line length limit on newer coders is one of the easiest ways to improve the readability of their code. Without it, I've seen developers generate lines of code that don't even fit in the full width of a standard monitor. Putting in a little extra effort to try to be clear in a shorter line (or adding more lines) usually pays off in spades for readability. Or, it at least gets them to start thinking about readability as an important concern. 90% of the time it is better to refactor code that doesn't fit comfortably within the line length limit than it is to violate it.
I personally set my terminal size to 80 chars because I believe it helps the readability of the code I write. It has nothing to do with the width of my monitor or the amount of characters I could theoretically fit across my screen.
Logan
Al Viro
maintainerRe: [PATCH 09/14] fs: don't change the address limit for ->write_iter in __kernel_write
In reply to Christoph HellwigQuoted 4 lines · Christoph Hellwig
If we write to a file that implements ->write_iter there is no need to change the address limit if we send a kvec down. Implement that case, and prefer it over using plain ->write with a changed address limit if available.
Umm... It needs a comment along the lines of "weird shits like /dev/sg that currently check for uaccess_kernel() will just have to make sure they never switch to ->write_iter()"
Re: [PATCH 09/14] fs: don't change the address limit for ->write_iter in __kernel_write
Quoted 9 lines · Al Viro
Quoted 4 lines · Christoph Hellwig
If we write to a file that implements ->write_iter there is no need to change the address limit if we send a kvec down. Implement that case, and prefer it over using plain ->write with a changed address limit if available.
Umm... It needs a comment along the lines of "weird shits like
/dev/sgthat currently check foruaccess_kernel()will just have to make sure they never switch to ->write_iter()"
sg and hid has the uaccess_kernel because it accesses userspace memory not in the range passed to it. Something using write_iter/read_iter should never access any memory outside the iter passed to. rdma has it because it uses write as a bidirectional interface, which obviously can't work at all with an iter. So I'm not sure what we should comment on, but if you have a desire and a proposal for a comment I'll happily add it.
Re: [PATCH 09/14] fs: don't change the address limit for ->write_iter in __kernel_write
Quoted 11 lines · Christoph Hellwig
Quoted 9 lines · Al Viro
Quoted 4 lines · Christoph Hellwig
If we write to a file that implements ->write_iter there is no need to change the address limit if we send a kvec down. Implement that case, and prefer it over using plain ->write with a changed address limit if available.
Umm... It needs a comment along the lines of "weird shits like
/dev/sgthat currently check foruaccess_kernel()will just have to make sure they never switch to ->write_iter()"
Quoted 6 lines
sg and hid has the
uaccess_kernelbecause it accesses userspace memory not in the range passed to it. Something using write_iter/read_iter should never access any memory outside the iter passed to. rdma has it because it uses write as a bidirectional interface, which obviously can't work at all with an iter. So I'm not sure what we should comment on, but if you have a desire and a proposal for a comment I'll happily add it.
And looking over all three again they actually comment why they check uaccess_kernel. More importantly if someone switched them to the ->write_iter carelessly that means the uaccess outside of the range would actually aways fail now as we didn't allow access to userspace memory, so this should show up when testing instantly.
PATCH 10/14 fs: add a __kernel_read helper
In reply to Christoph HellwigThis is the counterpart to __kernel_write, and skip the rw_verify_area call compared to kernel_read.
--- fs/read_write.c | 21 +++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 22 insertions(+)
fs/read_write.c +21 -0
@@ -430,6 +430,27 @@ ssize_t __vfs_read(struct file *file, char __user *buf, size_t count,return -EINVAL ; } +ssize_t __kernel_read (struct file *file,void *buf,size_t count,loff_t *pos) +{ +mm_segment_t old_fs =get_fs (); +ssize_t ret; + +if (!(file->f_mode &FMODE_CAN_READ )) +return -EINVAL ; + +if (count >MAX_RW_COUNT ) + count =MAX_RW_COUNT ; +set_fs (KERNEL_DS ); + ret =__vfs_read (file, (void __user *)buf, count, pos); +set_fs (old_fs); +if (ret >0 ) { +fsnotify_access (file); +add_rchar (current, ret); + } +inc_syscr (current); +return ret; +} +ssize_t kernel_read (struct file *file,void *buf,size_t count,loff_t *pos) {mm_segment_t old_fs;
include/linux/fs.h +1 -0
@@ -3011,6 +3011,7 @@ extern int kernel_read_file_from_path_initns(const char *, void **, loff_t *, loextern int kernel_read_file_from_fd (int ,void **,loff_t *,loff_t ,enum kernel_read_file_id );extern ssize_t kernel_read (struct file *,void *,size_t ,loff_t *); +ssize_t __kernel_read (struct file *file,void *buf,size_t count,loff_t *pos);extern ssize_t kernel_write (struct file *,const void *,size_t ,loff_t *);extern ssize_t __kernel_write (struct file *,const void *,size_t ,loff_t *);extern struct file *open_exec (const char *);
Signature · 1 line
2.26.2
PATCH 11/14 integrity/ima: switch to using __kernel_read
In reply to Christoph Hellwig__kernel_read has a bunch of additional sanity checks, and this moves the set_fs out of non-core code.
--- security/integrity/iint.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
security/integrity/iint.c +1 -13
@@ -188,19 +188,7 @@ DEFINE_LSM(integrity) = {int integrity_kernel_read (struct file *file,loff_t offset,void *addr,unsigned long count) { -mm_segment_t old_fs; -char __user *buf = (char __user *)addr; -ssize_t ret; - -if (!(file->f_mode &FMODE_READ )) -return -EBADF ; - - old_fs =get_fs (); -set_fs (KERNEL_DS ); - ret =__vfs_read (file, buf, count, &offset); -set_fs (old_fs); - -return ret; +return __kernel_read (file, addr, count, &offset); }/*
Signature · 1 line
2.26.2
PATCH 12/14 fs: implement kernel_read using __kernel_read
In reply to Christoph HellwigConsolidate the two in-kernel read helpers to make upcoming changes easier. The only difference are the missing call to rw_verify_area in kernel_read, and an access_ok check that doesn't make sense for kernel buffers to start with.
--- fs/read_write.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-)
fs/read_write.c +5 -8
@@ -453,15 +453,12 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)ssize_t kernel_read (struct file *file,void *buf,size_t count,loff_t *pos) { -mm_segment_t old_fs; -ssize_t result; +ssize_t ret; - old_fs =get_fs (); -set_fs (KERNEL_DS ); -/* The cast to a user pointer is valid due to the set_fs() */ - result =vfs_read (file, (void __user *)buf, count, pos); -set_fs (old_fs); -return result; + ret =rw_verify_area (READ , file, pos, count); +if (ret) +return ret; +return __kernel_read (file, buf, count, pos); }EXPORT_SYMBOL (kernel_read);
Signature · 1 line
2.26.2
PATCH 13/14 fs: remove __vfs_read
In reply to Christoph HellwigFold it into the two callers.
--- fs/read_write.c | 43 +++++++++++++++++++++---------------------- include/linux/fs.h | 1 - 2 files changed, 21 insertions(+), 23 deletions(-)
fs/read_write.c +21 -22
@@ -419,17 +419,6 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, loreturn ret; } -ssize_t __vfs_read (struct file *file,char __user *buf,size_t count, -loff_t *pos) -{ -if (file->f_op->read) -return file->f_op->read (file, buf, count, pos); -else if (file->f_op->read_iter) -return new_sync_read (file, buf, count, pos); -else -return -EINVAL ; -} -ssize_t __kernel_read (struct file *file,void *buf,size_t count,loff_t *pos) {mm_segment_t old_fs =get_fs ();
@@ -441,7 +430,12 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)if (count >MAX_RW_COUNT ) count =MAX_RW_COUNT ;set_fs (KERNEL_DS ); - ret =__vfs_read (file, (void __user *)buf, count, pos); +if (file->f_op->read) + ret = file->f_op->read (file, (void __user *)buf, count, pos); +else if (file->f_op->read_iter) + ret =new_sync_read (file, (void __user *)buf, count, pos); +else + ret = -EINVAL ;set_fs (old_fs);if (ret >0 ) {fsnotify_access (file);
@@ -474,17 +468,22 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos)return -EFAULT ; ret =rw_verify_area (READ , file, pos, count); -if (!ret) { -if (count >MAX_RW_COUNT ) - count =MAX_RW_COUNT ; - ret =__vfs_read (file, buf, count, pos); -if (ret >0 ) { -fsnotify_access (file); -add_rchar (current, ret); - } -inc_syscr (current); - } +if (ret) +return ret; +if (count >MAX_RW_COUNT ) + count =MAX_RW_COUNT ; +if (file->f_op->read) + ret = file->f_op->read (file, buf, count, pos); +else if (file->f_op->read_iter) + ret =new_sync_read (file, buf, count, pos); +else + ret = -EINVAL ; +if (ret >0 ) { +fsnotify_access (file); +add_rchar (current, ret); + } +inc_syscr (current);return ret; }
include/linux/fs.h +0 -1
@@ -1905,7 +1905,6 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector,struct iovec *fast_pointer, struct iovec **ret_pointer); -extern ssize_t __vfs_read (struct file *,char __user *,size_t ,loff_t *);extern ssize_t vfs_read (struct file *,char __user *,size_t ,loff_t *);extern ssize_t vfs_write (struct file *,const char __user *,size_t ,loff_t *); extern ssize_t vfs_readv(struct file *, const struct iovec __user *,
Signature · 1 line
2.26.2
PATCH 14/14 fs: don't change the address limit for ->read_iter in __kernel_read
In reply to Christoph HellwigIf we read to a file that implements ->read_iter there is no need to change the address limit if we send a kvec down. Implement that case, and prefer it over using plain ->read with a changed address limit if available.
--- fs/read_write.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-)
fs/read_write.c +17 -7
@@ -421,7 +421,6 @@ static ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lossize_t __kernel_read (struct file *file,void *buf,size_t count,loff_t *pos) { -mm_segment_t old_fs =get_fs ();ssize_t ret;if (!(file->f_mode &FMODE_CAN_READ ))
@@ -429,14 +428,25 @@ ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)if (count >MAX_RW_COUNT ) count =MAX_RW_COUNT ; -set_fs (KERNEL_DS ); -if (file->f_op->read) +if (file->f_op->read_iter) { +struct kvec iov = { .iov_base = buf, .iov_len = count }; +struct kiocb kiocb; +struct iov_iter iter; + +init_sync_kiocb (&kiocb, file); + kiocb.ki_pos = *pos; +iov_iter_kvec (&iter,READ , &iov,1 , count); + ret = file->f_op->read_iter (&kiocb, &iter); + *pos = kiocb.ki_pos; + }else if (file->f_op->read) { +mm_segment_t old_fs =get_fs (); + +set_fs (KERNEL_DS ); ret = file->f_op->read (file, (void __user *)buf, count, pos); -else if (file->f_op->read_iter) - ret =new_sync_read (file, (void __user *)buf, count, pos); -else +set_fs (old_fs); + }else { ret = -EINVAL ; -set_fs (old_fs); + }if (ret >0 ) {fsnotify_access (file);add_rchar (current, ret);
Signature · 1 line
2.26.2
Al Viro
maintainerRe: [PATCH 14/14] fs: don't change the address limit for ->read_iter in __kernel_read
Quoted 4 lines · Christoph Hellwig
If we read to a file that implements ->read_iter there is no need to change the address limit if we send a kvec down. Implement that case, and prefer it over using plain ->read with a changed address limit if available.
Ditto re never converting something that bails out on uaccess_kernel() in ->read() over to ->read_iter().
Quoted 5 lines · Christoph Hellwig
this series fixes a few issues and cleans up the helpers that read from or write to kernel space buffers, and ensures that we don't change the address limit if we are using the ->read_iter and ->write_iter methods that don't need the changed address limit.
Apart from the "please don't mix irrelevant whitespace changes with other changes" comment, this looks fine to me.
And a rant related to that change: I'm really inclined to remove the checkpatch check for 80 columns entirely, but it shouldn't have been triggering for old lines even now.
Or maybe make it check for something more reasonable, like 100 characters.
I find it ironic and annoying how "checkpatch" warns about that silly legacy limit, when checkpatch itself then on the very next few lines has a line that is 124 columns wide
And yes, that 124 character line has a good reason for it. But that's kind of the point. There are lots of perfectly fine reasons for longer lines.
I'd much rather check for "no deep indentation" or "no unnecessarily complex conditionals" or other issues that are more likely to be _real_ problems. But do we really have 80x25 terminals any more that we'd care about?
Linus
Quoted 21 lines · Linus Torvalds
Quoted 5 lines · Christoph Hellwig
this series fixes a few issues and cleans up the helpers that read from or write to kernel space buffers, and ensures that we don't change the address limit if we are using the ->read_iter and ->write_iter methods that don't need the changed address limit.
Apart from the "please don't mix irrelevant whitespace changes with other changes" comment, this looks fine to me.
And a rant related to that change: I'm really inclined to remove the checkpatch check for 80 columns entirely, but it shouldn't have been triggering for old lines even now.
Or maybe make it check for something more reasonable, like 100 characters.
I find it ironic and annoying how "checkpatch" warns about that silly legacy limit, when checkpatch itself then on the very next few lines has a line that is 124 columns wide
Quoted 9 lines
And yes, that 124 character line has a good reason for it. But that's kind of the point. There are lots of perfectly fine reasons for longer lines.
I'd much rather check for "no deep indentation" or "no unnecessarily complex conditionals" or other issues that are more likely to be _real_ problems. But do we really have 80x25 terminals any more that we'd care about?
Please kill that 80-columns-checkpatch-rule for more human-readability of code.
- Sedat -
Joe Perches
maintainerQuoted 13 lines · Linus Torvalds
Quoted 4 lines · Christoph Hellwig
this series fixes a few issues and cleans up the helpers that read from or write to kernel space buffers, and ensures that we don't change the address limit if we are using the ->read_iter and ->write_iter methods that don't need the changed address limit.
Apart from the "please don't mix irrelevant whitespace changes with other changes" comment, this looks fine to me.
And a rant related to that change: I'm really inclined to remove the checkpatch check for 80 columns entirely, but it shouldn't have been triggering for old lines even now.
Quoted 5 lines
Or maybe make it check for something more reasonable, like 100 characters.
I find it ironic and annoying how "checkpatch" warns about that silly legacy limit, when checkpatch itself then on the very next few lines has a line that is 124 columns wide
Yeah. perl ain't c.
And this discussion has been had many times.
Here's one from 2009
https://lkml.org/lkml/2009/12/15/490
Another from 2012
https://lkml.org/lkml/2012/2/5/141
Line lengths checks are normally pretty silly.
Hard limits at 80 really don't work well, especially with some of the 25+ character length identifiers used today.
I think a line length warning at 132 is generally reasonable but it could depend on complexity and identifier lengths.
Quoted 7 lines
And yes, that 124 character line has a good reason for it. But that's kind of the point. There are lots of perfectly fine reasons for longer lines.
I'd much rather check for "no deep indentation" or "no unnecessarily complex conditionals" or other issues that are more likely to be _real_ problems.
That deep indentation test already exists at 6 tabs. Maybe it should be 5 instead. Or maybe even 4, but that's a pretty easy to need and common use case.
Tab depth use in the kernel is more or less
$ git grep -Poh '^\t+(if|do|while|for|switch)\b' | \
sed -r 's/\w+//g' | \
awk '{print length($0);}' | \
sort | uniq -c | sort -rn
903993 1
339059 2
89334 3
18216 4
3282 5
605 6
148 7
36 8
4 9
1 10Quoted 2 lines
But do we really have 80x25 terminals any more that we'd care about?
trivial btw: VT100s were 80x24 or 132x24, PCs were 80x25
Al Viro
maintainerQuoted 2 lines · Joe Perches
Hard limits at 80 really don't work well, especially with some of the 25+ character length identifiers used today.
IMO any such identifier is a good reason for a warning.
The litmus test is actually very simple: how unpleasant would it be to mention the identifiers while discussing the code over the phone?
Quoted 9 lines · Al Viro
Quoted 2 lines · Joe Perches
Hard limits at 80 really don't work well, especially with some of the 25+ character length identifiers used today.
IMO any such identifier is a good reason for a warning.
The litmus test is actually very simple: how unpleasant would it be to mention the identifiers while discussing the code over the phone?
Here's a good example of a function which should be taken out and shot:
int amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct amdgpu_devic e *adev,
...
switch (frev) {
case 2:
switch (crev) {
...
if (profile->ucElbVDDC_Num > 0) {
for (i = 0; i < profile->ucElbVDDC_Num; i++) {
if (vddc_id_buf[i] == virtual_voltage_id) {
for (j = 0; j < profile->ucLeakageBinNum; j++) {
if (vbios_voltage_id <= leakage_bin[j]) {
*vddc = vddc_buf[j * profile->ucElbVDDC_Num + i];I mean, I get it that AMD want to show off just how studly a monitor they support, but good grief ...
Al Viro
maintainerQuoted 27 lines · Matthew Wilcox
Quoted 9 lines · Al Viro
Quoted 2 lines · Joe Perches
Hard limits at 80 really don't work well, especially with some of the 25+ character length identifiers used today.
IMO any such identifier is a good reason for a warning.
The litmus test is actually very simple: how unpleasant would it be to mention the identifiers while discussing the code over the phone?
Here's a good example of a function which should be taken out and shot:
int amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct
amdgpu_device *adev,
...switch (frev) { case 2: switch (crev) { ... if (profile->ucElbVDDC_Num > 0) { for (i = 0; i < profile->ucElbVDDC_Num; i++) { if (vddc_id_buf[i] == virtual_voltage_id) { for (j = 0; j < profile->ucLeakageBinNum; j++) { if (vbios_voltage_id <= leakage_bin[j]) { *vddc = vddc_buf[j * profile->ucElbVDDC_Num + i];
Quoted 2 lines
I mean, I get it that AMD want to show off just how studly a monitor they support, but good grief ...
I must respectfully disagree. It clearly needs to be hanged, drawn and quartered...
[AMD Official Use Only - Internal Distribution Only]
Quoted 43 lines
-----Original Message-----
From: Al Viro <[email protected]> On Behalf Of Al Viro
Sent: Thursday, May 28, 2020 4:06 PM
To: Matthew Wilcox <[email protected]>
Cc: Joe Perches <[email protected]>; Linus Torvalds <torvalds@linux- foundation.org>; Christoph Hellwig <[email protected]>; Ian Kent <[email protected]>; David Howells <[email protected]>; Linux Kernel Mailing List <[email protected]>; linux-fsdevel <linux- [email protected]>; LSM List <linux-security- [email protected]>; NetFilter <[email protected]>; Deucher, Alexander <[email protected]>; David Airlie <[email protected]>
Subject: Re: clean up kernel_{read,write} & friends v2Quoted 6 lines · Matthew Wilcox
Quoted 5 lines · Al Viro
Quoted 2 lines · Joe Perches
Hard limits at 80 really don't work well, especially with some of the 25+ character length identifiers used today.
Quoted 8 lines
Quoted 4 lines
IMO any such identifier is a good reason for a warning.
The litmus test is actually very simple: how unpleasant would it be to mention the identifiers while discussing the code over the phone?
Here's a good example of a function which should be taken out and shot:
int
amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct
Quoted 13 lines
amdgpu_device *adev, ...switch (frev) { case 2: switch (crev) { ... if (profile->ucElbVDDC_Num > 0) { for (i = 0; i < profile->ucElbVDDC_Num; i++) { if (vddc_id_buf[i] == virtual_voltage_id) { for (j = 0; j < profile->ucLeakageBinNum; j++) { if (vbios_voltage_id <= leakage_bin[j]) { *vddc= vddc_buf[j *
profile->ucElbVDDC_Num+ i];
Quoted 5 lines
Quoted 2 lines
I mean, I get it that AMD want to show off just how studly a monitor they support, but good grief ...
I must respectfully disagree. It clearly needs to be hanged, drawn and quartered...
You found it necessary to add me to a random thread with no context to complain about the coding style? How about sending a patch to clean it up if you find it that unsavory.
Alex
Joe Perches
maintainerQuoted 8 lines · Matthew Wilcox
Quoted 7 lines · Al Viro
Quoted 2 lines · Joe Perches
Hard limits at 80 really don't work well, especially with some of the 25+ character length identifiers used today.
IMO any such identifier is a good reason for a warning.
Quoted 7 lines
Quoted 2 lines
The litmus test is actually very simple: how unpleasant would it be to mention the identifiers while discussing the code over the phone?
Here's a good example of a function which should be taken out and shot:
int amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct
amdgpu_device *adev,
Ick.
Seems simple enough as it doesn't appear to be used...
$ git grep amdgpu_atombios_get_leakage_vddc_based_on_leakage_params drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c:int amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct amdgpu_device *adev, drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h:int amdgpu_atombios_get_leakage_vddc_based_on_leakage_params(struct amdgpu_device *adev,
Quoted 10 lines · Al Viro
Quoted 2 lines · Joe Perches
Hard limits at 80 really don't work well, especially with some of the 25+ character length identifiers used today.
IMO any such identifier is a good reason for a warning.
The litmus test is actually very simple: how unpleasant would it be to mention the identifiers while discussing the code over the phone?
That doesn't make sense though,
if you write the full english words out for something it'll be long but easier to say over the phone,
if you use shortened kernel abbreviations it will be short but you'd have to read out every letter.
To take an example:
this would read pretty well on the phone, maybe params could be parameters amdgpu_atombios_get_leakage_vddc_based_on_leakage_params
vddc would be a stumbler.
try saying O_CREAT over the phone to someone not steeped in UNIX folklore.
Dave.
Joe Perches
maintainerQuoted 14 lines · Joe Perches
Quoted 13 lines · Linus Torvalds
Quoted 4 lines · Christoph Hellwig
this series fixes a few issues and cleans up the helpers that read from or write to kernel space buffers, and ensures that we don't change the address limit if we are using the ->read_iter and ->write_iter methods that don't need the changed address limit.
Apart from the "please don't mix irrelevant whitespace changes with other changes" comment, this looks fine to me.
And a rant related to that change: I'm really inclined to remove the checkpatch check for 80 columns entirely, but it shouldn't have been triggering for old lines even now.
Quoted 5 lines
Quoted 5 lines
Or maybe make it check for something more reasonable, like 100 characters.
I find it ironic and annoying how "checkpatch" warns about that silly legacy limit, when checkpatch itself then on the very next few lines has a line that is 124 columns wide
Another option is to only warn by default when a line in a patch but not a file exceeds the line length maximum.
--- scripts/checkpatch.pl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
scripts/checkpatch.pl +4 -2
@@ -3282,8 +3282,10 @@ sub process { if ($msg_type ne "" && (show_type("LONG_LINE") || show_type($msg_type))) { - WARN($msg_type, - "line over $max_line_length characters\n" . $herecurr); + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + &{$msg_level}($msg_type, + "line over $max_line_length characters\n" . $herecurr); } }
David Howells
maintainerQuoted 1 line · Linus Torvalds
Or maybe make it check for something more reasonable, like 100 characters.
Yes please!
David
Quoted 4 lines · David Howells
Quoted 1 line · Linus Torvalds
Or maybe make it check for something more reasonable, like 100 characters.
Yes please!
No, thank you!
C is a symbolic language, not a text language. Encouraging newbies to declare
int iterator;
instead of
int i;
does the language a disservice.
It's true, nobody uses a TTY33 anymore. Those of us who have done so understand how "{" is preferable to "BEGIN" and why tabs are better than multiple spaces. A narrow "terminal" requires less neck and mouse movement. Any width limit is arbitrary, so to the extent anyone might care, I advocate 80 forever.
Quoted 2 lines
David
From: Casey Schaufler
Quoted 6 lines
Sent: 28 May 2020 22:21
It's true, nobody uses a TTY33 anymore. Those of us who have done so understand how "{" is preferable to "BEGIN" and why tabs are better than multiple spaces. A narrow "terminal" requires less neck and mouse movement. Any width limit is arbitrary, so to the extent anyone might care, I advocate 80 forever.
A wide monitor is for looking at lots of files.
Not dead space because of deep intents and very long variable names.
Although i don't understand the 'indent continuations under "("' rule. It hides some indents and makes other excessive.
A simple 'double indent' (or half indent) makes code more readable.
A different rule for function definitions would make real sense. They only need a single indent - the '{' marks the end.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 2 lines · David Laight
A wide monitor is for looking at lots of files.
Not necessarily.
Excessive line breaks are BAD. They cause real and every-day problems.
They cause problems for things like "grep" both in the patterns and in the output, since grep (and a lot of other very basic unix utilities) is fundamentally line-based.
So the fact is, many of us have long long since skipped the whole "80-column terminal" model, for the same reason that we have many more lines than 25 lines visible at a time.
And honestly, I don't want to see patches that make the kernel reading experience worse for me and likely for the vast majority of people, based on the argument that some odd people have small terminal windows.
If you or Christoph have 80 character lines, you'll get possibly ugly wrapped output. Tough. That's _your_ choice. Your hardware limitations shouldn't be a pain for the rest of us.
Longer lines are fundamentally useful. My monitor is not only a lot wider than it is tall, my fonts are universally narrower than they are tall. Long lines are natural.
When I tile my terminal windows on my display, I can have 6 terminals visible at one time, and that's because I have them three wide. And I could still fit 80% of a fourth one side-by-side.
And guess what? That's with my default "100x50" terminal window (go to your gnome terminal settings, you'll find that the 80x25 thing is just an initial default that you can change), not with some 80x25 one. And that's with a font that has anti-aliasing and isn't some pixelated mess.
And most of my terminals actually end up being dragged wider and taller than that. I checked, and my main one is 142x76 characters right now, because it turns out that wider (and taller) terminals are useful not just for source code.
Have you looked at "ps ax" output lately? Or used "top"? Or done "git diff --stat" or any number of things where it turns out that 80x25 is really really limiting, and is simply NO LONGER RELEVANT to most of us.
So no. I do not care about somebody with a 80x25 terminal window getting line wrapping.
For exactly the same reason I find it completely irrelevant if somebody says that their kernel compile takes 10 hours because they are doing kernel development on a Raspberry PI with 4GB of RAM.
People with restrictive hardware shouldn't make it more inconvenient for people who have better resources. Yes, we'll accommodate things to within reasonable limits. But no, 80-column terminals in 2020 isn't "reasonable" any more as far as I'm concerned. People commonly used 132-column terminals even back in the 80's, for chrissake, don't try to make 80 columns some immovable standard.
If you choose to use a 80-column terminal, you can live with the line wrapping. It's just that simple.
And longer lines are simply useful. Part of that is that we aren't programming in the 80's any more, and our source code is fundamentally wider as a result.
Yes, local iteration variables are still called 'i', because more context just isn't helpful for some anonymous counter. Being concise is still a good thing, and overly verbose names are not inherently better.
But still - it's entirely reasonable to have variable names that are 10-15 characters and it makes the code more legible. Writing things out instead of using abbreviations etc.
And yes, we do use wide tabs, because that makes indentation something you can visually see in the structure at a glance and on a whole-function basis, rather than something you have to try to visually "line up" things for or count spaces.
So we have lots of fairly fundamental issues that fairly easily make for longer lines in many circumstances.
And yes, we do line breaks at some point. But there really isn't any reason to make that point be 80 columns any more.
Linus
Quoted 42 lines · Linus Torvalds
Quoted 1 line · David Laight
A wide monitor is for looking at lots of files.
Not necessarily.
Excessive line breaks are BAD. They cause real and every-day problems.
They cause problems for things like "grep" both in the patterns and in the output, since grep (and a lot of other very basic unix utilities) is fundamentally line-based.
So the fact is, many of us have long long since skipped the whole "80-column terminal" model, for the same reason that we have many more lines than 25 lines visible at a time.
And honestly, I don't want to see patches that make the kernel reading experience worse for me and likely for the vast majority of people, based on the argument that some odd people have small terminal windows.
If you or Christoph have 80 character lines, you'll get possibly ugly wrapped output. Tough. That's _your_ choice. Your hardware limitations shouldn't be a pain for the rest of us.
Longer lines are fundamentally useful. My monitor is not only a lot wider than it is tall, my fonts are universally narrower than they are tall. Long lines are natural.
When I tile my terminal windows on my display, I can have 6 terminals visible at one time, and that's because I have them three wide. And I could still fit 80% of a fourth one side-by-side.
And guess what? That's with my default "100x50" terminal window (go to your gnome terminal settings, you'll find that the 80x25 thing is just an initial default that you can change), not with some 80x25 one. And that's with a font that has anti-aliasing and isn't some pixelated mess.
And most of my terminals actually end up being dragged wider and taller than that. I checked, and my main one is 142x76 characters right now, because it turns out that wider (and taller) terminals are useful not just for source code.
Quoted 7 lines
Have you looked at "ps ax" output lately? Or used "top"? Or done "git diff --stat" or any number of things where it turns out that 80x25 is really really limiting, and is simply NO LONGER RELEVANT to most of us.
So no. I do not care about somebody with a 80x25 terminal window getting line wrapping.
The first law of good C programming is:
"Thou shalt adhere to the One True Brace Style"
It extrapolates into indentation, line width, and a number of other things. Since Linux is a trademark of Linus Torvalds, you get to define what the "One Truth" is. Time to resize my terminals.
Quoted 40 lines
For exactly the same reason I find it completely irrelevant if somebody says that their kernel compile takes 10 hours because they are doing kernel development on a Raspberry PI with 4GB of RAM.
People with restrictive hardware shouldn't make it more inconvenient for people who have better resources. Yes, we'll accommodate things to within reasonable limits. But no, 80-column terminals in 2020 isn't "reasonable" any more as far as I'm concerned. People commonly used 132-column terminals even back in the 80's, for chrissake, don't try to make 80 columns some immovable standard.
If you choose to use a 80-column terminal, you can live with the line wrapping. It's just that simple.
And longer lines are simply useful. Part of that is that we aren't programming in the 80's any more, and our source code is fundamentally wider as a result.
Yes, local iteration variables are still called 'i', because more context just isn't helpful for some anonymous counter. Being concise is still a good thing, and overly verbose names are not inherently better.
But still - it's entirely reasonable to have variable names that are 10-15 characters and it makes the code more legible. Writing things out instead of using abbreviations etc.
And yes, we do use wide tabs, because that makes indentation something you can visually see in the structure at a glance and on a whole-function basis, rather than something you have to try to visually "line up" things for or count spaces.
So we have lots of fairly fundamental issues that fairly easily make for longer lines in many circumstances.
And yes, we do line breaks at some point. But there really isn't any reason to make that point be 80 columns any more.
Linus
Joe Perches
maintainerPATCH 1/1 checkpatch/coding-style: Allow 100 column lines
In reply to Linus TorvaldsChange the maximum allowed line length to 100 from 80.
Miscellanea:
o to avoid unnecessary whitespace changes in files, checkpatch will no longer emit a warning about line length when scanning files unless --strict is also used
o Add a bit to coding-style about alignment to open parenthesis
--- Documentation/process/coding-style.rst | 25 ++++++++++++++++--------- scripts/checkpatch.pl | 14 +++++++++----- 2 files changed, 25 insertions(+), 14 deletions(-)
Documentation/process/coding-style.rst +16 -9
@@ -84,15 +84,22 @@ Get a decent editor and don't leave whitespace at the end of lines. Coding style is all about readability and maintainability using commonly available tools. -The limit on the length of lines is 80 columns and this is a strongly -preferred limit. - -Statements longer than 80 columns will be broken into sensible chunks, unless -exceeding 80 columns significantly increases readability and does not hide -information. Descendants are always substantially shorter than the parent and -are placed substantially to the right. The same applies to function headers -with a long argument list. However, never break user-visible strings such as -printk messages, because that breaks the ability to grep for them. +The preferred limit on the length of a single line is 80 columns. + +Statements longer than 80 columns should be broken into sensible chunks, +unless exceeding 80 columns significantly increases readability and does +not hide information. + +Statements may be up to 100 columns when appropriate. + +Descendants are always substantially shorter than the parent and are +are placed substantially to the right. A very commonly used style +is to align descendants to a function open parenthesis. + +These same rules are applied to function headers with a long argument list. + +However, never break user-visible strings such as printk messages because +that breaks the ability to grep for them. 3) Placing Braces and Spaces
scripts/checkpatch.pl +9 -5
@@ -53,7 +53,7 @@ my %ignore_type = (); my @ignore = (); my $help = 0; my $configuration_file = ".checkpatch.conf"; -my $max_line_length = 80; +my $max_line_length = 100; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4;
@@ -99,9 +99,11 @@ Options: --types TYPE(,TYPE2...) show only these comma separated message types --ignore TYPE(,TYPE2...) ignore various comma separated message types --show-types show the specific message type in the output - --max-line-length=n set the maximum line length, if exceeded, warn + --max-line-length=n set the maximum line length, (default $max_line_length) + if exceeded, warn on patches + requires --strict for use with --file --min-conf-desc-length=n set the min description length, if shorter, warn - --tab-size=n set the number of spaces for tab (default 8) + --tab-size=n set the number of spaces for tab (default $tabsize) --root=PATH PATH to the kernel tree root --no-summary suppress the per-file summary --mailback only produce a report in case of warnings/errors
@@ -3282,8 +3284,10 @@ sub process { if ($msg_type ne "" && (show_type("LONG_LINE") || show_type($msg_type))) { - WARN($msg_type, - "line over $max_line_length characters\n" . $herecurr); + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + &{$msg_level}($msg_type, + "line length of $length exceeds $max_line_length columns\n" . $herecurr); } }
Re: [PATCH] checkpatch/coding-style: Allow 100 column lines
Quoted 2 lines · Joe Perches
Change the maximum allowed line length to 100 from 80.
What is the benefit/motivation for changing this? The vast majority of files are wrapped at 80 columns, and if some files start being wrapped at 100 columns they will either display poorly on 80-column terminals, or a lot of dead space will show in 100-column terminals.
Quoted 80 lines
Miscellanea:
o to avoid unnecessary whitespace changes in files, checkpatch will no longer emit a warning about line length when scanning files unless --strict is also used
o Add a bit to coding-style about alignment to open parenthesisSigned-off-by Joe Perches <[email protected]>---
Documentation/process/coding-style.rst| 25 ++++++++++++++++---------scripts/checkpatch.pl| 14 +++++++++-----2 files changed, 25 insertions(+), 14 deletions(-)Documentation/process/coding-style.rst +0
-0@@ -84,15 +84,22 @@ Get a decent editor and don't leave whitespace at the end of lines.Coding style is all about readability and maintainability using commonly available tools.
Documentation/process/coding-style.rst +16
-9-The limit on the length of lines is 80 columns and this is a strongly -preferred limit. - -Statements longer than 80 columns will be broken into sensible chunks, unless -exceeding 80 columns significantly increases readability and does not hide -information. Descendants are always substantially shorter than the parent and -are placed substantially to the right. The same applies to function headers -with a long argument list. However, never break user-visible strings such as -printk messages, because that breaks the ability to grep for them. +The preferred limit on the length of a single line is 80 columns. + +Statements longer than 80 columns should be broken into sensible chunks, +unless exceeding 80 columns significantly increases readability and does +not hide information. + +Statements may be up to 100 columns when appropriate. + +Descendants are always substantially shorter than the parent and are +are placed substantially to the right. A very commonly used style +is to align descendants to a function open parenthesis. + +These same rules are applied to function headers with a long argument list. + +However, never break user-visible strings such as printk messages because +that breaks the ability to grep for them.3) Placing Braces and Spaces
scripts/checkpatch.pl +5
-3@@ -53,7 +53,7 @@ my %ignore_type = (); my @ignore = (); my $help = 0; my $configuration_file = ".checkpatch.conf"; -my $max_line_length = 80; +my $max_line_length = 100; my $ignore_perl_version = 0; my $minimum_perl_version = 5.10.0; my $min_conf_desc_length = 4;@@ -99,9 +99,11 @@ Options: --types TYPE(,TYPE2...) show only these comma separated message types --ignore TYPE(,TYPE2...) ignore various comma separated message types --show-types show the specific message type in the output - --max-line-length=n set the maximum line length, if exceeded, warn + --max-line-length=n set the maximum line length, (default $max_line_length) + if exceeded, warn on patches + requires --strict for use with --file --min-conf-desc-length=n set the min description length, if shorter, warn - --tab-size=n set the number of spaces for tab (default 8) + --tab-size=n set the number of spaces for tab (default $tabsize) --root=PATH PATH to the kernel tree root --no-summary suppress the per-file summary --mailback only produce a report in case of warnings/errors@@ -3282,8 +3284,10 @@ sub process { if ($msg_type ne "" &&
scripts/checkpatch.pl sub process { · line 3293
Quoted 10 lines
scripts/checkpatch.pl +4
-2(show_type("LONG_LINE") || show_type($msg_type))) { - WARN($msg_type, - "line over $max_line_length characters\n" . $herecurr); + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + &{$msg_level}($msg_type, + "line length of $length exceeds $max_line_length columns\n" . $herecurr); } }
Cheers, Andreas
Joe Perches
maintainerRe: [PATCH] checkpatch/coding-style: Allow 100 column lines
Quoted 7 lines · Andreas Dilger
Quoted 1 line · Joe Perches
Change the maximum allowed line length to 100 from 80.
What is the benefit/motivation for changing this? The vast majority of files are wrapped at 80 columns, and if some files start being wrapped at 100 columns they will either display poorly on 80-column terminals, or a lot of dead space will show in 100-column terminals.
YA Linus bleat in this thread.
I don't much care one way or any other.
https://lore.kernel.org/lkml/CAHk-=wj3iGQqjpvc+gf6+C29Jo4COj6OQQFzdY0h5qvYKTdCow@mail.gmail.com/
and
https://lore.kernel.org/lkml/CAHk-=wjR0H3+2ba0UUWwoYzYBH0GX9yTf5dj2MZyo0xvyzvJnA@mail.gmail.com/
Hi Linus,
Quoted 16 lines · Linus Torvalds
Quoted 2 lines · David Laight
A wide monitor is for looking at lots of files.
Not necessarily.
Excessive line breaks are BAD. They cause real and every-day problems.
They cause problems for things like "grep" both in the patterns and in the output, since grep (and a lot of other very basic unix utilities) is fundamentally line-based.
So the fact is, many of us have long long since skipped the whole "80-column terminal" model, for the same reason that we have many more lines than 25 lines visible at a time.
Quoted 8 lines
And honestly, I don't want to see patches that make the kernel reading experience worse for me and likely for the vast majority of people, based on the argument that some odd people have small terminal windows.
If you or Christoph have 80 character lines, you'll get possibly ugly wrapped output. Tough. That's _your_ choice. Your hardware limitations shouldn't be a pain for the rest of us.
Unfortunately refreshable braille displays have that "hardware limitations". 80 cells displays are very expensive. Visual impairments is rarely a "choice".
Relaxing the 80-char limit make it harder for blind developers to contribute.
Quoted 59 lines
Longer lines are fundamentally useful. My monitor is not only a lot wider than it is tall, my fonts are universally narrower than they are tall. Long lines are natural.
When I tile my terminal windows on my display, I can have 6 terminals visible at one time, and that's because I have them three wide. And I could still fit 80% of a fourth one side-by-side.
And guess what? That's with my default "100x50" terminal window (go to your gnome terminal settings, you'll find that the 80x25 thing is just an initial default that you can change), not with some 80x25 one. And that's with a font that has anti-aliasing and isn't some pixelated mess.
And most of my terminals actually end up being dragged wider and taller than that. I checked, and my main one is 142x76 characters right now, because it turns out that wider (and taller) terminals are useful not just for source code.
Have you looked at "ps ax" output lately? Or used "top"? Or done "git diff --stat" or any number of things where it turns out that 80x25 is really really limiting, and is simply NO LONGER RELEVANT to most of us.
So no. I do not care about somebody with a 80x25 terminal window getting line wrapping.
For exactly the same reason I find it completely irrelevant if somebody says that their kernel compile takes 10 hours because they are doing kernel development on a Raspberry PI with 4GB of RAM.
People with restrictive hardware shouldn't make it more inconvenient for people who have better resources. Yes, we'll accommodate things to within reasonable limits. But no, 80-column terminals in 2020 isn't "reasonable" any more as far as I'm concerned. People commonly used 132-column terminals even back in the 80's, for chrissake, don't try to make 80 columns some immovable standard.
If you choose to use a 80-column terminal, you can live with the line wrapping. It's just that simple.
And longer lines are simply useful. Part of that is that we aren't programming in the 80's any more, and our source code is fundamentally wider as a result.
Yes, local iteration variables are still called 'i', because more context just isn't helpful for some anonymous counter. Being concise is still a good thing, and overly verbose names are not inherently better.
But still - it's entirely reasonable to have variable names that are 10-15 characters and it makes the code more legible. Writing things out instead of using abbreviations etc.
And yes, we do use wide tabs, because that makes indentation something you can visually see in the structure at a glance and on a whole-function basis, rather than something you have to try to visually "line up" things for or count spaces.
Quoted 7 lines
So we have lots of fairly fundamental issues that fairly easily make for longer lines in many circumstances.
And yes, we do line breaks at some point. But there really isn't any reason to make that point be 80 columns any more.
Linus
Regards,
Phil.
Quoted 5 lines · Philippe Mathieu-Daudé
Unfortunately refreshable braille displays have that "hardware limitations". 80 cells displays are very expensive. Visual impairments is rarely a "choice".
Relaxing the 80-char limit make it harder for blind developers to contribute.
Well, not really.
It is true that 80-cells displays are awfully expensive. IMHO they are also unwieldy due to their size: they are hardly portable, and they require your hands to move twice as far which may sometimes impair reading efficiency. So I never liked them.
My braille display has 40 cells only. So even with a 80-cells limit I always had to pan the display to see the whole line anyway.
My text console is set to 160x128. The trick here is to have the number of columns be a multiple of the braille display's width to avoid dead areas when panning to the right.
So if you ask me, I'm not against relaxing the 80 columns limit for code. What really matters to me is that I can stay clear of any GUI.
Nicolas