Re: [PATCH printk v4 7/8] printk: use printk_buffers for devkmsg

From: John Ogness
Date: Thu Jan 05 2023 - 07:14:54 EST


On 2023-01-05, John Ogness <john.ogness@xxxxxxxxxxxxx> wrote:
> /* /dev/kmsg - userspace message inject/listen interface */
> struct devkmsg_user {
> atomic64_t seq;
> struct ratelimit_state rs;
> struct mutex lock;
> - char buf[CONSOLE_EXT_LOG_MAX];
>
> + struct printk_buffers pbufs;
> struct printk_info info;
> - char text_buf[CONSOLE_EXT_LOG_MAX];
> struct printk_record record;
> };

There is also no need for the printk_info and printk_record
structs. printk_get_next_message() uses its own on the stack.

> @@ -797,7 +801,7 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
> if (ret)
> return ret;
>
> - if (!prb_read_valid(prb, atomic64_read(&user->seq), r)) {
> + if (!printk_get_next_message(&pmsg, atomic64_read(&user->seq), true)) {

This needs to be a while loop because printk_get_next_message() should
be the only function reading from the ringbuffer. The
wait_event_interruptible() in this loop should just wait for the
existence of the new record. It should not be the one reading it.

I will reply to this message with the correct patch to replace this
patch.

John Ogness