From: He Zhe Date: Tue, 24 Sep 2019 15:26:39 +0800 Subject: [PATCH] printk: devkmsg: read: Return EPIPE when the first message user-space wants has gone Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/5.4/older/patches-5.4.13-rt7.tar.xz When user-space wants to read the first message, that is when user->seq is 0, and that message has gone, it currently automatically resets user->seq to current first seq. This mis-aligns with mainline kernel. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/testing/dev-kmsg#n39 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/printk/printk.c#n899 We should inform user-space that what it wants has gone by returning EPIPE in such scenario. Link: https://lore.kernel.org/r/20190924072639.25986-1-zhe.he@windriver.com Signed-off-by: He Zhe Signed-off-by: Sebastian Andrzej Siewior --- kernel/printk/printk.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) --- a/kernel/printk/printk.c +++ b/kernel/printk/printk.c @@ -713,14 +713,10 @@ static ssize_t devkmsg_read(struct file goto out; } - if (user->seq == 0) { - user->seq = seq; - } else { - user->seq++; - if (user->seq < seq) { - ret = -EPIPE; - goto restore_out; - } + user->seq++; + if (user->seq < seq) { + ret = -EPIPE; + goto restore_out; } msg = (struct printk_log *)&user->msgbuf[0];