All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	kernel test robot <rong.a.chen@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrea Parri <parri.andrea@gmail.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Paul McKenney <paulmck@kernel.org>,
	kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
	lkp@lists.01.org
Subject: Re: [printk] 18a2dc6982: ltp.kmsg01.fail
Date: Thu, 09 Jul 2020 13:23:07 +0206	[thread overview]
Message-ID: <87zh89kkek.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20200709111310.GD11164@alley>

On 2020-07-09, Petr Mladek <pmladek@suse.com> wrote:
> I though more about it. IMHO, it will be better to modify
> prb_first_seq() to do the same cycle as prb_next_seq()
> and return seq number of the first valid entry.

Exactly!

Here is a patch that does just that. I added a prb_first_valid_seq()
function and made prb_first_seq() static. (The ringbuffer still needs
prb_first_seq() for itself.)

John Ogness


diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 0b1337f4188c..fec71229169e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -775,9 +775,9 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
 		logbuf_lock_irq();
 	}
 
-	if (user->seq < prb_first_seq(prb)) {
+	if (user->seq < prb_first_valid_seq(prb)) {
 		/* our last seen message is gone, return error and reset */
-		user->seq = prb_first_seq(prb);
+		user->seq = prb_first_valid_seq(prb);
 		ret = -EPIPE;
 		logbuf_unlock_irq();
 		goto out;
@@ -820,7 +820,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
 	switch (whence) {
 	case SEEK_SET:
 		/* the first record */
-		user->seq = prb_first_seq(prb);
+		user->seq = prb_first_valid_seq(prb);
 		break;
 	case SEEK_DATA:
 		/*
@@ -854,7 +854,7 @@ static __poll_t devkmsg_poll(struct file *file, poll_table *wait)
 	logbuf_lock_irq();
 	if (prb_read_valid(prb, user->seq, NULL)) {
 		/* return error when data has vanished underneath us */
-		if (user->seq < prb_first_seq(prb))
+		if (user->seq < prb_first_valid_seq(prb))
 			ret = EPOLLIN|EPOLLRDNORM|EPOLLERR|EPOLLPRI;
 		else
 			ret = EPOLLIN|EPOLLRDNORM;
@@ -894,7 +894,7 @@ static int devkmsg_open(struct inode *inode, struct file *file)
 			&user->dict_buf[0], sizeof(user->dict_buf));
 
 	logbuf_lock_irq();
-	user->seq = prb_first_seq(prb);
+	user->seq = prb_first_valid_seq(prb);
 	logbuf_unlock_irq();
 
 	file->private_data = user;
@@ -1631,9 +1631,9 @@ int do_syslog(int type, char __user *buf, int len, int source)
 	/* Number of chars in the log buffer */
 	case SYSLOG_ACTION_SIZE_UNREAD:
 		logbuf_lock_irq();
-		if (syslog_seq < prb_first_seq(prb)) {
+		if (syslog_seq < prb_first_valid_seq(prb)) {
 			/* messages are gone, move to first one */
-			syslog_seq = prb_first_seq(prb);
+			syslog_seq = prb_first_valid_seq(prb);
 			syslog_partial = 0;
 		}
 		if (source == SYSLOG_FROM_PROC) {
@@ -2120,7 +2120,7 @@ EXPORT_SYMBOL(printk);
 #define printk_time		false
 
 #define prb_read_valid(rb, seq, r)	false
-#define prb_first_seq(rb)		0
+#define prb_first_valid_seq(rb)		0
 
 static u64 syslog_seq;
 static u64 console_seq;
@@ -2627,7 +2627,7 @@ void console_flush_on_panic(enum con_flush_mode mode)
 		unsigned long flags;
 
 		logbuf_lock_irqsave(flags);
-		console_seq = prb_first_seq(prb);
+		console_seq = prb_first_valid_seq(prb);
 		logbuf_unlock_irqrestore(flags);
 	}
 	console_unlock();
@@ -3395,9 +3395,9 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
 		goto out;
 
 	logbuf_lock_irqsave(flags);
-	if (dumper->cur_seq < prb_first_seq(prb)) {
+	if (dumper->cur_seq < prb_first_valid_seq(prb)) {
 		/* messages are gone, move to first available one */
-		dumper->cur_seq = prb_first_seq(prb);
+		dumper->cur_seq = prb_first_valid_seq(prb);
 	}
 
 	/* last entry */
diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
index f4a670f7289d..70ad5a091e96 100644
--- a/kernel/printk/printk_ringbuffer.c
+++ b/kernel/printk/printk_ringbuffer.c
@@ -1420,22 +1420,8 @@ static int prb_read(struct printk_ringbuffer *rb, u64 seq,
 	return desc_read_committed_seq(desc_ring, id, seq, &desc);
 }
 
-/**
- * prb_first_seq() - Get the sequence number of the tail descriptor.
- *
- * @rb:  The ringbuffer to get the sequence number from.
- *
- * This is the public function available to readers to see what the
- * first/oldest sequence number is.
- *
- * This provides readers a starting point to begin iterating the ringbuffer.
- * Note that the returned sequence number might not belong to a valid record.
- *
- * Context: Any context.
- * Return: The sequence number of the first/oldest record or, if the
- *         ringbuffer is empty, 0 is returned.
- */
-u64 prb_first_seq(struct printk_ringbuffer *rb)
+/* Get the sequence number of the tail descriptor. */
+static u64 prb_first_seq(struct printk_ringbuffer *rb)
 {
 	struct prb_desc_ring *desc_ring = &rb->desc_ring;
 	enum desc_state d_state;
@@ -1576,6 +1562,31 @@ bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq,
 	return _prb_read_valid(rb, &seq, &r, line_count);
 }
 
+/**
+ * prb_first_valid_seq() - Get the sequence number of the oldest available
+ *                         record.
+ *
+ * @rb: The ringbuffer to get the sequence number from.
+ *
+ * This is the public function available to readers to see what the
+ * first/oldest sequence number is.
+ *
+ * This provides readers a starting point to begin iterating the ringbuffer.
+ *
+ * Context: Any context.
+ * Return: The sequence number of the first/oldest record or, if the
+ *         ringbuffer is empty, 0 is returned.
+ */
+u64 prb_first_valid_seq(struct printk_ringbuffer *rb)
+{
+	u64 seq = 0;
+
+	if (!_prb_read_valid(rb, &seq, NULL, NULL))
+		return 0;
+
+	return seq;
+}
+
 /**
  * prb_next_seq() - Get the sequence number after the last available record.
  *
diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h
index 711ced305cc7..3e46a7423c13 100644
--- a/kernel/printk/printk_ringbuffer.h
+++ b/kernel/printk/printk_ringbuffer.h
@@ -393,7 +393,7 @@ bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq,
 bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq,
 			 struct printk_info *info, unsigned int *line_count);
 
-u64 prb_first_seq(struct printk_ringbuffer *rb);
+u64 prb_first_valid_seq(struct printk_ringbuffer *rb);
 u64 prb_next_seq(struct printk_ringbuffer *rb);
 
 #endif /* _KERNEL_PRINTK_RINGBUFFER_H */


WARNING: multiple messages have this Message-ID (diff)
From: John Ogness <john.ogness@linutronix.de>
To: Petr Mladek <pmladek@suse.com>
Cc: Andrea Parri <parri.andrea@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Paul McKenney <paulmck@kernel.org>,
	kernel test robot <rong.a.chen@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	kexec@lists.infradead.org, linux-kernel@vger.kernel.org,
	Steven Rostedt <rostedt@goodmis.org>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	lkp@lists.01.org, Thomas Gleixner <tglx@linutronix.de>,
	Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [printk] 18a2dc6982: ltp.kmsg01.fail
Date: Thu, 09 Jul 2020 13:23:07 +0206	[thread overview]
Message-ID: <87zh89kkek.fsf@jogness.linutronix.de> (raw)
In-Reply-To: <20200709111310.GD11164@alley>

On 2020-07-09, Petr Mladek <pmladek@suse.com> wrote:
> I though more about it. IMHO, it will be better to modify
> prb_first_seq() to do the same cycle as prb_next_seq()
> and return seq number of the first valid entry.

Exactly!

Here is a patch that does just that. I added a prb_first_valid_seq()
function and made prb_first_seq() static. (The ringbuffer still needs
prb_first_seq() for itself.)

John Ogness


diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 0b1337f4188c..fec71229169e 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -775,9 +775,9 @@ static ssize_t devkmsg_read(struct file *file, char __user *buf,
 		logbuf_lock_irq();
 	}
 
-	if (user->seq < prb_first_seq(prb)) {
+	if (user->seq < prb_first_valid_seq(prb)) {
 		/* our last seen message is gone, return error and reset */
-		user->seq = prb_first_seq(prb);
+		user->seq = prb_first_valid_seq(prb);
 		ret = -EPIPE;
 		logbuf_unlock_irq();
 		goto out;
@@ -820,7 +820,7 @@ static loff_t devkmsg_llseek(struct file *file, loff_t offset, int whence)
 	switch (whence) {
 	case SEEK_SET:
 		/* the first record */
-		user->seq = prb_first_seq(prb);
+		user->seq = prb_first_valid_seq(prb);
 		break;
 	case SEEK_DATA:
 		/*
@@ -854,7 +854,7 @@ static __poll_t devkmsg_poll(struct file *file, poll_table *wait)
 	logbuf_lock_irq();
 	if (prb_read_valid(prb, user->seq, NULL)) {
 		/* return error when data has vanished underneath us */
-		if (user->seq < prb_first_seq(prb))
+		if (user->seq < prb_first_valid_seq(prb))
 			ret = EPOLLIN|EPOLLRDNORM|EPOLLERR|EPOLLPRI;
 		else
 			ret = EPOLLIN|EPOLLRDNORM;
@@ -894,7 +894,7 @@ static int devkmsg_open(struct inode *inode, struct file *file)
 			&user->dict_buf[0], sizeof(user->dict_buf));
 
 	logbuf_lock_irq();
-	user->seq = prb_first_seq(prb);
+	user->seq = prb_first_valid_seq(prb);
 	logbuf_unlock_irq();
 
 	file->private_data = user;
@@ -1631,9 +1631,9 @@ int do_syslog(int type, char __user *buf, int len, int source)
 	/* Number of chars in the log buffer */
 	case SYSLOG_ACTION_SIZE_UNREAD:
 		logbuf_lock_irq();
-		if (syslog_seq < prb_first_seq(prb)) {
+		if (syslog_seq < prb_first_valid_seq(prb)) {
 			/* messages are gone, move to first one */
-			syslog_seq = prb_first_seq(prb);
+			syslog_seq = prb_first_valid_seq(prb);
 			syslog_partial = 0;
 		}
 		if (source == SYSLOG_FROM_PROC) {
@@ -2120,7 +2120,7 @@ EXPORT_SYMBOL(printk);
 #define printk_time		false
 
 #define prb_read_valid(rb, seq, r)	false
-#define prb_first_seq(rb)		0
+#define prb_first_valid_seq(rb)		0
 
 static u64 syslog_seq;
 static u64 console_seq;
@@ -2627,7 +2627,7 @@ void console_flush_on_panic(enum con_flush_mode mode)
 		unsigned long flags;
 
 		logbuf_lock_irqsave(flags);
-		console_seq = prb_first_seq(prb);
+		console_seq = prb_first_valid_seq(prb);
 		logbuf_unlock_irqrestore(flags);
 	}
 	console_unlock();
@@ -3395,9 +3395,9 @@ bool kmsg_dump_get_buffer(struct kmsg_dumper *dumper, bool syslog,
 		goto out;
 
 	logbuf_lock_irqsave(flags);
-	if (dumper->cur_seq < prb_first_seq(prb)) {
+	if (dumper->cur_seq < prb_first_valid_seq(prb)) {
 		/* messages are gone, move to first available one */
-		dumper->cur_seq = prb_first_seq(prb);
+		dumper->cur_seq = prb_first_valid_seq(prb);
 	}
 
 	/* last entry */
diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c
index f4a670f7289d..70ad5a091e96 100644
--- a/kernel/printk/printk_ringbuffer.c
+++ b/kernel/printk/printk_ringbuffer.c
@@ -1420,22 +1420,8 @@ static int prb_read(struct printk_ringbuffer *rb, u64 seq,
 	return desc_read_committed_seq(desc_ring, id, seq, &desc);
 }
 
-/**
- * prb_first_seq() - Get the sequence number of the tail descriptor.
- *
- * @rb:  The ringbuffer to get the sequence number from.
- *
- * This is the public function available to readers to see what the
- * first/oldest sequence number is.
- *
- * This provides readers a starting point to begin iterating the ringbuffer.
- * Note that the returned sequence number might not belong to a valid record.
- *
- * Context: Any context.
- * Return: The sequence number of the first/oldest record or, if the
- *         ringbuffer is empty, 0 is returned.
- */
-u64 prb_first_seq(struct printk_ringbuffer *rb)
+/* Get the sequence number of the tail descriptor. */
+static u64 prb_first_seq(struct printk_ringbuffer *rb)
 {
 	struct prb_desc_ring *desc_ring = &rb->desc_ring;
 	enum desc_state d_state;
@@ -1576,6 +1562,31 @@ bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq,
 	return _prb_read_valid(rb, &seq, &r, line_count);
 }
 
+/**
+ * prb_first_valid_seq() - Get the sequence number of the oldest available
+ *                         record.
+ *
+ * @rb: The ringbuffer to get the sequence number from.
+ *
+ * This is the public function available to readers to see what the
+ * first/oldest sequence number is.
+ *
+ * This provides readers a starting point to begin iterating the ringbuffer.
+ *
+ * Context: Any context.
+ * Return: The sequence number of the first/oldest record or, if the
+ *         ringbuffer is empty, 0 is returned.
+ */
+u64 prb_first_valid_seq(struct printk_ringbuffer *rb)
+{
+	u64 seq = 0;
+
+	if (!_prb_read_valid(rb, &seq, NULL, NULL))
+		return 0;
+
+	return seq;
+}
+
 /**
  * prb_next_seq() - Get the sequence number after the last available record.
  *
diff --git a/kernel/printk/printk_ringbuffer.h b/kernel/printk/printk_ringbuffer.h
index 711ced305cc7..3e46a7423c13 100644
--- a/kernel/printk/printk_ringbuffer.h
+++ b/kernel/printk/printk_ringbuffer.h
@@ -393,7 +393,7 @@ bool prb_read_valid(struct printk_ringbuffer *rb, u64 seq,
 bool prb_read_valid_info(struct printk_ringbuffer *rb, u64 seq,
 			 struct printk_info *info, unsigned int *line_count);
 
-u64 prb_first_seq(struct printk_ringbuffer *rb);
+u64 prb_first_valid_seq(struct printk_ringbuffer *rb);
 u64 prb_next_seq(struct printk_ringbuffer *rb);
 
 #endif /* _KERNEL_PRINTK_RINGBUFFER_H */


_______________________________________________
kexec mailing list
kexec@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/kexec

  reply	other threads:[~2020-07-09 11:17 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-07 14:59 [PATCH v4 0/4] printk: replace ringbuffer John Ogness
2020-07-07 14:59 ` John Ogness
2020-07-07 14:59 ` [PATCH v4 1/4] crash: add VMCOREINFO macro to define offset in a struct declared by typedef John Ogness
2020-07-07 14:59   ` John Ogness
2020-07-07 14:59 ` [PATCH v4 2/4] printk: add lockless ringbuffer John Ogness
2020-07-07 14:59   ` John Ogness
2020-07-07 14:59 ` [PATCH v4 3/4] Revert "printk: lock/unlock console only for new logbuf entries" John Ogness
2020-07-07 14:59   ` John Ogness
2020-07-08 14:34   ` Petr Mladek
2020-07-08 14:34     ` Petr Mladek
2020-07-09  1:20   ` Sergey Senozhatsky
2020-07-09  1:20     ` Sergey Senozhatsky
2020-07-07 14:59 ` [PATCH v4 4/4] printk: use the lockless ringbuffer John Ogness
2020-07-07 14:59   ` John Ogness
2020-07-07 19:25   ` kernel test robot
2020-07-07 19:25     ` kernel test robot
2020-07-07 19:25     ` kernel test robot
2020-07-08 13:18     ` John Ogness
2020-07-08 13:18       ` John Ogness
2020-07-08 13:18       ` John Ogness
2020-07-08 14:35   ` Petr Mladek
2020-07-08 14:35     ` Petr Mladek
2020-07-08 19:24   ` kernel test robot
2020-07-08 19:24     ` kernel test robot
2020-07-08 19:24     ` kernel test robot
2020-07-09  7:14   ` [printk] 18a2dc6982: ltp.kmsg01.fail kernel test robot
2020-07-09  7:14     ` kernel test robot
2020-07-09  8:33     ` Sergey Senozhatsky
2020-07-09  8:33       ` Sergey Senozhatsky
2020-07-09 10:14       ` John Ogness
2020-07-09 10:14         ` John Ogness
2020-07-09 10:59         ` Petr Mladek
2020-07-09 10:59           ` Petr Mladek
2020-07-09 11:13           ` Petr Mladek
2020-07-09 11:13             ` Petr Mladek
2020-07-09 11:17             ` John Ogness [this message]
2020-07-09 11:17               ` John Ogness
2020-07-09 12:25               ` Petr Mladek
2020-07-09 12:25                 ` Petr Mladek
2020-07-09 13:07                 ` Sergey Senozhatsky
2020-07-09 13:07                   ` Sergey Senozhatsky
2020-07-09 14:41                   ` Petr Mladek
2020-07-09 14:41                     ` Petr Mladek
2020-07-08 15:20 ` [PATCH v4 0/4] printk: replace ringbuffer Petr Mladek
2020-07-08 15:20   ` Petr Mladek
2020-07-09  7:03   ` John Ogness
2020-07-09  7:03     ` John Ogness
2020-07-10  9:11     ` Petr Mladek
2020-07-10  9:11       ` Petr Mladek
2020-07-10  9:52       ` John Ogness
2020-07-10  9:52         ` John Ogness
2020-07-10 14:15         ` Petr Mladek
2020-07-10 14:15           ` Petr Mladek
2020-07-14  2:56         ` Sergey Senozhatsky
2020-07-14  2:56           ` Sergey Senozhatsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zh89kkek.fsf@jogness.linutronix.de \
    --to=john.ogness@linutronix.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=kexec@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkp@lists.01.org \
    --cc=parri.andrea@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=pmladek@suse.com \
    --cc=rong.a.chen@intel.com \
    --cc=rostedt@goodmis.org \
    --cc=sergey.senozhatsky.work@gmail.com \
    --cc=sergey.senozhatsky@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.