"tty: implement write_iter" breaks TIOCCONS
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 5 lines · Hans de Goede
While testing 5.11-rc5 I noticed that flicker-free boot was no longer flicker free, when plymouth loads and tells systemd to start logging detailed messages these start showing upon the fbcon instead of being redirected to the ptmx which plymouth is trying to redirect the messages too.
I think this should already be fixed in current -git by commit 9f12e37cae44.
Can you check?
Linus
Hi,
Quoted 10 lines · Linus Torvalds
Quoted 5 lines · Hans de Goede
While testing 5.11-rc5 I noticed that flicker-free boot was no longer flicker free, when plymouth loads and tells systemd to start logging detailed messages these start showing upon the fbcon instead of being redirected to the ptmx which plymouth is trying to redirect the messages too.
I think this should already be fixed in current -git by commit
9f12e37cae44.Can you check?
So I just did the following
1. Started with my local tree (5.11-rc5 + patches I'm working on, nothing tty related) ( https://github.com/jwrdegoede/linux-sunxi/commits/master )
2. Dropped the 2 reverts which I was carrying to workaround this locally
3. Cherry-picked 9f12e37cae44
4. Build + installed a new bzImage
Unfortunately this does not resolve the problem, after this the problem is back.
I can build a kernel from a clean torvalds/linux/master but I don't expect any different results from that. Let me know if you still want me to do a clean build to make sure this is not something in my local tree.
Regards,
Hans
Hi Linus,
Quoted 22 lines · Hans de Goede
Hi,
Quoted 10 lines · Linus Torvalds
Quoted 5 lines · Hans de Goede
While testing 5.11-rc5 I noticed that flicker-free boot was no longer flicker free, when plymouth loads and tells systemd to start logging detailed messages these start showing upon the fbcon instead of being redirected to the ptmx which plymouth is trying to redirect the messages too.
I think this should already be fixed in current -git by commit
9f12e37cae44.Can you check?
So I just did the following
1. Started with my local tree (5.11-rc5 + patches I'm working on, nothing tty related) ( https://github.com/jwrdegoede/linux-sunxi/commits/master )
2. Dropped the 2 reverts which I was carrying to workaround this locally
3. Cherry-picked9f12e37cae44
4. Build + installed a new bzImage
Quoted 5 lines
Unfortunately this does not resolve the problem, after this the problem is back.
I can build a kernel from a clean torvalds/linux/master but I don't expect any different results from that. Let me know if you still want me to do a clean build to make sure this is not something in my local tree.
p.s.
You are using Fedora now a days, right ? In that case you should be able to reproduce this yourself (depending on how custom your kernel setup is) if you are using the standard Fedora initrd generated by dracut and have "rhgb" on your kernel cmdline, then you can check for this problem by doing:
sudo cat /var/log/boot.log
For me the end of that file looks like this:
------------ Wed Jan 27 08:28:15 CET 2021 ------------ ------------ Wed Jan 27 17:27:53 CET 2021 ------------ ------------ Thu Jan 28 11:11:50 CET 2021 ------------ ------------ Fri Jan 29 10:32:04 CET 2021 ------------ ------------ Fri Jan 29 19:16:40 CET 2021 ------------ ------------ Fri Jan 29 19:19:05 CET 2021 ------------
There should be lines like this in between those separators (each separator is the start of the logs of a new boot):
[ OK ] Started User Login Management. [ OK ] Started GNOME Display Manager.
etc.
Regards,
Hans
Quoted 6 lines · Hans de Goede
You are using Fedora now a days, right ? In that case you should be able to reproduce this yourself (depending on how custom your kernel setup is) if you are using the standard Fedora initrd generated by dracut and have "rhgb" on your kernel cmdline, then you can check for this problem by doing:
Thanks, I can see it, that should make it much easier to figure out.
Linus
Quoted 10 lines · Linus Torvalds
Quoted 6 lines · Hans de Goede
You are using Fedora now a days, right ? In that case you should be able to reproduce this yourself (depending on how custom your kernel setup is) if you are using the standard Fedora initrd generated by dracut and have "rhgb" on your kernel cmdline, then you can check for this problem by doing:
Thanks, I can see it, that should make it much easier to figure out.
Ahh, interesting.
It turns out that the problem isn't actually really in the tty layer, it's that vfs_iocb_iter_write() is very very subtly buggy.
So the tty layer "trivial" conversion from using "vfs_write()" - for the old redirected tty_write() call - to using "vfs_iocb_iter_write()" caused problems.
Why? Because both vfs_write() and vfs_iocb_iter_write() take the target "struct file *file" as an argument, but vfs_iocb_iter_write() doesn't actually *use* that target file!
Well, to be specific, it does actually use the target file pointer for two things:
- the security checks
- to pick the actual ->write_iter function.
But once you actually call ->write_iter() to do the IO, the 'file' pointer isn't actually passed down at all, and the write_iter() function depends not on 'file', but on 'iocb->ki_filp".
In other words, vfs_iocb_iter_write() is completely broken, because it will do the preliminary work using one 'struct file *', but then do the actual IO using _another_ 'struct file *' entirely.
In the case of the console redirect code, that meant that the "redirect" never actually redirected anything, it really just called tty_write() with the original iocb, which used the original target file pointer.
Let's just say that I stared at those tty changes for a while, saying "there is no *POSSIBLE* way that introduces a bug". And yeah, the tty changes themselves were actually not the real culprit.
Of course, there is only one other user of vfs_iocb_iter_write() - ovlfs - and that one fills in the iocb with the same file pointer that it uses as the first argument, so nobody has ever noticed this oddity before.
The function has been buggy like this since the very first implementation, and vfs_iocb_iter_read() has the exact same issue.
It's fairly easy to work around in this in the tty layer by just avoiding that function entirely, so I'll cook up a patch to do that. But I'm adding the appropriate people to the participants here because this really is very subtle if you ever hit it.
It might be best to just remove the "struct file *file" argument from vfs_iocb_iter_{read,write}(), because it really is very wrong to use anything but iocb.ki_file, and it's really subtle.
Linus
Quoted 5 lines · Linus Torvalds
It's fairly easy to work around in this in the tty layer by just avoiding that function entirely, so I'll cook up a patch to do that. But I'm adding the appropriate people to the participants here because this really is very subtle if you ever hit it.
Here's the patch to make the tty layer just do the redirection entirely internally, avoiding that mis-designed vfs_iocb_iter_write() function.
Hans, does this fix things for you? I'm pretty confident it will, but always best to double-check..
Linus
Hi,
Quoted 8 lines · Linus Torvalds
Quoted 5 lines · Linus Torvalds
It's fairly easy to work around in this in the tty layer by just avoiding that function entirely, so I'll cook up a patch to do that. But I'm adding the appropriate people to the participants here because this really is very subtle if you ever hit it.
Quoted 6 lines
Here's the patch to make the tty layer just do the redirection entirely internally, avoiding that mis-designed
vfs_iocb_iter_write()function.Hans, does this fix things for you? I'm pretty confident it will, but always best to double-check..
I can confirm that the attached patch fixes things for me, thanks.
Regards,
Hans