Bug 44211
Summary: | /proc/kmsg does not (always) block for 1-byte reads (bisected) | ||
---|---|---|---|
Product: | File System | Reporter: | Jukka Ollila (jiiksteri) |
Component: | Other | Assignee: | fs_other |
Status: | RESOLVED CODE_FIX | ||
Severity: | normal | CC: | alan, greg, jbeulich, kay |
Priority: | P1 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | 3.5-rc5+ | Subsystem: | |
Regression: | Yes | Bisected commit-id: |
Description
Jukka Ollila
2012-07-03 16:30:59 UTC
I hacked together a simple kernel module that just printk():s a message periodically and took a look at /proc/kmsg. With <6>[23715.200075] Hello2 (ffff88004a3b6488) in /proc/kmsg, I can /bin/dd if=/proc/kmsg bs=44 just fine, 44 being the length of the message. That will block nicely and run seemingly forever. Or until someone logs something that's not 44 bytes. Anything below bs=44 results in 0 bytes read, ie. EOF. If I try with "Hello" instead of "Hello2", bs=43 works and so on. Probably best to also email this to the mailing list (and Jan Beulich/GregKH) initially. Alan With the new one-message-at-a-time approach, I don't think reading single bytes works this way anymore: The entire message gets consumed, and returning just a single byte of it to user space would make it impossible to obtain the rest of the message. Please also Cc kay@vrfy.org (whom I can't Cc here as he doesn't appear to be known to bugzilla, yet whom I would like to check whether this my understanding is correct, as he did the underlying large re-write). Patch posted: https://lkml.org/lkml/2012/7/7/118 Side note: This will still not make dd bs=1 work reliably. It never was. The /proc/kmsg interface might always return 0 for read, not indicating EOF, but telling try-again. This was always the case, and dd was never safe to use here. You find years old bugs for this on the net. Before filing this I saw some reports that had issues with multiple readers, and as mentioned on lkml that would be tricky to get right on the kernel side. Or even figure out what could be correct and defined behaviour for multiple readers. So I'd imagine it's safe to ignore those. But this is a single blocking reader. So unless the old code had cases where it would return 0 to a single blocking short read, the dd bs=1 _did_ work reliably :) Not that I'm defending it. But multiple readers is a different case altogether. Anyway, thanks for working on this :) On Sun, Jul 8, 2012 at 9:42 PM, <bugzilla-daemon@bugzilla.kernel.org> wrote: > --- Comment #5 from Jukka Ollila <jiiksteri@gmail.com> 2012-07-08 19:42:44 > --- > Before filing this I saw some reports that had issues with multiple readers, Yss, it was always the case. > and as mentioned on lkml that would be tricky to get right on the kernel > side. It's rather trivial, just quite some code to change. > Or even figure out what could be correct and defined behaviour for multiple > readers. So I'd imagine it's safe to ignore those. It can't be fixed properly for multiple readers, it has kernel internal global state, that is shared. The new /dev/kmsg structured data/record interface supports as many readers as wanted, and it also never keeps an kernel global state, and never flushes the buffer. It can be read as many times as wanted. > But this is a single blocking reader. So unless the old code had cases where > it > would return 0 to a single blocking short read, the dd bs=1 _did_ work > reliably It should be safe. But building system tools on the assumption that nobody ever does "cat /proc/kmsg" is just crazy. > Not that I'm defending it. But multiple readers is a different case > altogether. Yes, and no. But building such fragile with assumptions like "don't touch it or it breaks" things is just wrong. > Anyway, thanks for working on this :) Sure, hope that will all work now. Thanks! Marking this as resolved. Kay's fix (eb02dac93708f581c99858a19162af8ca2b6bfcb) is in 3.5-rc7. The dd log shovel works again. |