Skip to contentSkip to conversation

pstore: Move timestamp collection code to common pstore place

PATCH In review Ankit Kumar 2 participants 7 messages May 22, 2017 – Aug 7, 2017 Pstore filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 pstore: Move timestamp collection code to common pstore place

Current pstore code(ram.c) gets dump timestamp and make it part of header. Different diffent architecture uses different header format and hence it won't be good idea to make ramoops_write_kmsg_hdr/ramoops_read_kmsg_hdr part of generic pstore code.

ramoops_write_kmsg_hdr calls __getnstimeofday to get timestamp and also takes care of condition if timekeeping has not resumed.

This patch moves code for retrieving timestamp to common place and hence can be used by other functions as well.

---
 fs/pstore/internal.h |  1 +
 fs/pstore/platform.c | 13 +++++++++++++
 fs/pstore/ram.c      |  9 ++++-----
 3 files changed, 18 insertions(+), 5 deletions(-)
fs/pstore/internal.h +1 -0
index c416e65..339dcdc 100644
@@ -22,6 +22,7 @@ static inline void pstore_unregister_pmsg(void) {}
 #endif
 
 extern struct pstore_info *psinfo;
+void pstore_get_timestamp(struct timespec *timestamp);
 
 extern void	pstore_set_kmsg_bytes(int);
 extern void	pstore_get_records(int);
fs/pstore/platform.c +13 -0
index d468eec..5cb25b0 100644
@@ -474,6 +474,19 @@ static size_t copy_kmsg_to_buffer(int hsize, size_t len)
 	return total_len;
 }
 
+void pstore_get_timestamp(struct timespec *timestamp)
+{
+	if (!timestamp)
+		return;
+
+	/* Report zeroed timestamp if called before timekeeping has resumed. */
+	if (__getnstimeofday(timestamp)) {
+		timestamp->tv_sec = 0;
+		timestamp->tv_nsec = 0;
+	}
+}
+EXPORT_SYMBOL_GPL(pstore_get_timestamp);
+
 /*
  * callback from kmsg_dump. (s2,l2) has the most recently
  * written bytes, older bytes are in (s1,l1). Save as much
fs/pstore/ram.c +4 -5
index 5cb022c..e39297d 100644
@@ -37,6 +37,8 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 
+#include "internal.h"
+
 #define RAMOOPS_KERNMSG_HDR "===="
 #define MIN_MEM_SIZE 4096UL
 
@@ -362,11 +364,8 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
 	struct timespec timestamp;
 	size_t len;
 
-	/* Report zeroed timestamp if called before timekeeping has resumed. */
-	if (__getnstimeofday(&timestamp)) {
-		timestamp.tv_sec = 0;
-		timestamp.tv_nsec = 0;
-	}
+	pstore_get_timestamp(&timestamp);
+
 	hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n",
 		(long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000),
 		compressed ? 'C' : 'D');
Signature · 1 line
2.7.4
#1 lore raw

PATCH 2/2 Save current timestamp part of dmesg while writing oops message to pstore

Currently on panic or Oops, kernel saves the last few bytes from dmesg buffer to nvram. Usually kdump does capture kernel memory and provide dmesg logs as well. But in some cases where kdump fails to capture vmcore, the dmesg buffer stored in nvram/pstore turns out to be very helpful in analyzing root cause.

Present code creates pstore dump file(/sys/fs/pstore/dmesg-***) based on timestamp(retrieved from header). Current pstore code creates dump file (/sys/fs/pstore/dmesg-***) with that timestamp. Dump file can be analyzed based on file creation time and we can make out whether dump file has latest data or not.

But when we transfer pstore dump file(/sys/fs/pstore/dmesg-***) to other machine or collect file using some utilities(sosreport/supportconfig) then file timestamp gets changed and hence by looking at device file (dmesg-***) we won't be able to identify whether dump has latest data or not.

Above issue can be fixed if we also have timestamp(dump creation time) as initial few bytes while capturing dmesg buffer to pstore dump file (/sys/fs/pstore/dmesg-***).

This patch enhances pstore write code to also write timestamp as part of data.

Here is sample log of dump file:(/sys/fs/pstore/dmesg-***)

Oops#1 Part1 [timestamp:1494939359.590463]

Above timestamp can be converted to current zone using date command.
#date -d @1494939359.590463
# Tue May 16 18:25:59 IST 2017

---
 fs/pstore/platform.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
fs/pstore/platform.c +5 -2
index 4fedf83..f65000e 100644
@@ -501,6 +501,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
 	unsigned long	flags = 0;
 	int		is_locked;
 	int		ret;
+	struct timespec timestamp;
 
 	why = get_reason_str(reason);
 
@@ -540,9 +541,11 @@ static void pstore_dump(struct kmsg_dumper *dumper,
 			dst_size = psinfo->bufsize;
 		}
 
+		pstore_get_timestamp(&timestamp);
 		/* Write dump header. */
-		header_size = snprintf(dst, dst_size, "%s#%d Part%u\n", why,
-				 oopscount, part);
+		header_size = snprintf(dst, dst_size, "%s#%d Part%u [timestamp:%lu.%lu]\n",
+				why, oopscount, part, (long)timestamp.tv_sec,
+				(long)(timestamp.tv_nsec / 1000));
 		dst_size -= header_size;
 
 		/* Write dump contents. */
Signature · 1 line
2.7.4
#2 lore raw

Re: [PATCH 2/2] Save current timestamp part of dmesg while writing oops message to pstore

Quoted 22 lines · Ankit Kumar

Currently on panic or Oops, kernel saves the last few bytes from dmesg buffer to nvram. Usually kdump does capture kernel memory and provide dmesg logs as well. But in some cases where kdump fails to capture vmcore, the dmesg buffer stored in nvram/pstore turns out to be very helpful in analyzing root cause.

Present code creates pstore dump file(/sys/fs/pstore/dmesg-***) based on timestamp(retrieved from header). Current pstore code creates dump file (/sys/fs/pstore/dmesg-***) with that timestamp. Dump file can be analyzed based on file creation time and we can make out whether dump file has latest data or not.

But when we transfer pstore dump file(/sys/fs/pstore/dmesg-***) to other machine or collect file using some utilities(sosreport/supportconfig) then file timestamp gets changed and hence by looking at device file (dmesg-***) we won't be able to identify whether dump has latest data or not.

Above issue can be fixed if we also have timestamp(dump creation time) as initial few bytes while capturing dmesg buffer to pstore dump file (/sys/fs/pstore/dmesg-***).

Quoted 4 lines

This patch enhances pstore write code to also write timestamp as part of data.

Here is sample log of dump file:(/sys/fs/pstore/dmesg-***)

Oops#1 Part1 [timestamp:1494939359.590463]

While I understand your rationale about possibly losing file timestamp information in userspace, I think this is a solvable problem on the collection side. If an additional header is needed, perhaps copy the dmesg files like this:

for i in dmesg-*; do

    (stat --format=%y /sys/fs/pstore/$i; \
     cat /sys/fs/pstore/$i) > $collect_dir/$i

done

One of the primary concerns for pstore is the stored dump size, even to the point of adding compression to the routines to squeeze out every last bit of space. I'd really rather avoid adding the timestamp to the stored data like this. It's up to the backends already to efficiently store this, and it's exposed via the file timestamp, so I really can't justify adding redundant data.

-Kees

Signature · 2 lines
Kees Cook
Pixel Security
#3 lore raw

Re: [PATCH 2/2] Save current timestamp part of dmesg while writing oops message to pstore

Hi Kees,

Quoted 32 lines · Kees Cook
Quoted 22 lines · Ankit Kumar

Currently on panic or Oops, kernel saves the last few bytes from dmesg buffer to nvram. Usually kdump does capture kernel memory and provide dmesg logs as well. But in some cases where kdump fails to capture vmcore, the dmesg buffer stored in nvram/pstore turns out to be very helpful in analyzing root cause.

Present code creates pstore dump file(/sys/fs/pstore/dmesg-***) based on timestamp(retrieved from header). Current pstore code creates dump file (/sys/fs/pstore/dmesg-***) with that timestamp. Dump file can be analyzed based on file creation time and we can make out whether dump file has latest data or not.

But when we transfer pstore dump file(/sys/fs/pstore/dmesg-***) to other machine or collect file using some utilities(sosreport/supportconfig) then file timestamp gets changed and hence by looking at device file (dmesg-***) we won't be able to identify whether dump has latest data or not.

Above issue can be fixed if we also have timestamp(dump creation time) as initial few bytes while capturing dmesg buffer to pstore dump file (/sys/fs/pstore/dmesg-***).

Quoted 4 lines

This patch enhances pstore write code to also write timestamp as part of data.

Here is sample log of dump file:(/sys/fs/pstore/dmesg-***)

Oops#1 Part1 [timestamp:1494939359.590463]

While I understand your rationale about possibly losing file timestamp information in userspace, I think this is a solvable problem on the collection side. If an additional header is needed, perhaps copy the dmesg files like this:

Quoted 4 lines

for i in dmesg-*; do

     (stat --format=%y /sys/fs/pstore/$i; \
      cat /sys/fs/pstore/$i) > $collect_dir/$i

done

Yes. We can handle this in userspace. But we wanted to see if we can add this as part of pstore log itself.

Quoted 1 line

One of the primary concerns for pstore is the stored dump size,

I understand. How about adding timestamp to file name itself? Something like below

index 792a4e5..0837365 100644

fs/pstore/inode.c +3 -2
@@ -349,9 +349,10 @@ int pstore_mkfile(struct dentry *root, struct pstore_record *record)
 
        switch (record->type) {
        case PSTORE_TYPE_DMESG:
-               scnprintf(name, sizeof(name), "dmesg-%s-%lld%s",
+               scnprintf(name, sizeof(name), "dmesg-%s-%lld%s-%lu.%lu",
                          record->psi->name, record->id,
-                         record->compressed ? ".enc.z" : "");
+                         record->compressed ? ".enc.z" : "",
+                         record->time.tv_sec, record->time.tv_nsec / 1000);
                break;
        case PSTORE_TYPE_CONSOLE:
 

~Ankit

#4 lore raw

Re: [PATCH 2/2] Save current timestamp part of dmesg while writing oops message to pstore

Hi Kees,

Quoted 42 lines · Ankit Kumar

Hi Kees,

Quoted 32 lines · Kees Cook
Quoted 22 lines · Ankit Kumar

Currently on panic or Oops, kernel saves the last few bytes from dmesg buffer to nvram. Usually kdump does capture kernel memory and provide dmesg logs as well. But in some cases where kdump fails to capture vmcore, the dmesg buffer stored in nvram/pstore turns out to be very helpful in analyzing root cause.

Present code creates pstore dump file(/sys/fs/pstore/dmesg-***) based on timestamp(retrieved from header). Current pstore code creates dump file (/sys/fs/pstore/dmesg-***) with that timestamp. Dump file can be analyzed based on file creation time and we can make out whether dump file has latest data or not.

But when we transfer pstore dump file(/sys/fs/pstore/dmesg-***) to other machine or collect file using some utilities(sosreport/supportconfig) then file timestamp gets changed and hence by looking at device file (dmesg-***) we won't be able to identify whether dump has latest data or not.

Above issue can be fixed if we also have timestamp(dump creation time) as initial few bytes while capturing dmesg buffer to pstore dump file (/sys/fs/pstore/dmesg-***).

Quoted 4 lines

This patch enhances pstore write code to also write timestamp as part of data.

Here is sample log of dump file:(/sys/fs/pstore/dmesg-***)

Oops#1 Part1 [timestamp:1494939359.590463]

While I understand your rationale about possibly losing file timestamp information in userspace, I think this is a solvable problem on the collection side. If an additional header is needed, perhaps copy the dmesg files like this:

Quoted 4 lines

for i in dmesg-*; do

     (stat --format=%y /sys/fs/pstore/$i; \
      cat /sys/fs/pstore/$i) > $collect_dir/$i

done

Quoted 7 lines

Yes. We can handle this in userspace. But we wanted to see if we can add this as part of pstore log itself.

Quoted 1 line

One of the primary concerns for pstore is the stored dump size,

I understand. How about adding timestamp to file name itself? Something like below

How about appending time as part of file name itself. ? Did you get time to look at above approach. Code can be something like below piece.

~Ankit

Quoted 21 lines

index 792a4e5..0837365 100644

fs/pstore/inode.c +3 -2
@@ -349,9 +349,10 @@ int pstore_mkfile(struct dentry *root, struct 
 pstore_record *record)
 
        switch (record->type) {
        case PSTORE_TYPE_DMESG:
-               scnprintf(name, sizeof(name), "dmesg-%s-%lld%s",
+               scnprintf(name, sizeof(name), "dmesg-%s-%lld%s-%lu.%lu",
                          record->psi->name, record->id,
-                         record->compressed ? ".enc.z" : "");
+                         record->compressed ? ".enc.z" : "",
+                         record->time.tv_sec, record->time.tv_nsec / 
 1000);
                break;

case PSTORE_TYPE_CONSOLE:

~Ankit

#5 lore raw
In reply to Ankit Kumar
Quoted 10 lines · Ankit Kumar

Current pstore code(ram.c) gets dump timestamp and make it part of header. Different diffent architecture uses different header format and hence it won't be good idea to make ramoops_write_kmsg_hdr/ramoops_read_kmsg_hdr part of generic pstore code.

ramoops_write_kmsg_hdr calls __getnstimeofday to get timestamp and also takes care of condition if timekeeping has not resumed.

This patch moves code for retrieving timestamp to common place and hence can be used by other functions as well.

Ah! Heh, funny, I had just done a version of this while working on EFI pstore fixes. Here's what I did instead:

https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=pstore/fixes&id=ea209b760f104daf0cf62953090b66c5628b0842

This makes it so the time field is prepopulated for all backend writes, which should simplify things (no need to have the backends call out).

-Kees

Quoted 74 lines
---
 fs/pstore/internal.h |  1 +
 fs/pstore/platform.c | 13 +++++++++++++
 fs/pstore/ram.c      |  9 ++++-----
 3 files changed, 18 insertions(+), 5 deletions(-)
fs/pstore/internal.h +1 -0
index c416e65..339dcdc 100644
@@ -22,6 +22,7 @@ static inline void pstore_unregister_pmsg(void) {}
 #endif
 
 extern struct pstore_info *psinfo;
+void pstore_get_timestamp(struct timespec *timestamp);
 
 extern void    pstore_set_kmsg_bytes(int);
 extern void    pstore_get_records(int);
fs/pstore/platform.c +13 -0
index d468eec..5cb25b0 100644
@@ -474,6 +474,19 @@ static size_t copy_kmsg_to_buffer(int hsize, size_t len)
        return total_len;
 }
 
+void pstore_get_timestamp(struct timespec *timestamp)
+{
+       if (!timestamp)
+               return;
+
+       /* Report zeroed timestamp if called before timekeeping has resumed. */
+       if (__getnstimeofday(timestamp)) {
+               timestamp->tv_sec = 0;
+               timestamp->tv_nsec = 0;
+       }
+}
+EXPORT_SYMBOL_GPL(pstore_get_timestamp);
+
 /*
  * callback from kmsg_dump. (s2,l2) has the most recently
  * written bytes, older bytes are in (s1,l1). Save as much
fs/pstore/ram.c +4 -6
index 5cb022c..e39297d 100644
@@ -37,6 +37,8 @@
 #include <linux/of.h>
 #include <linux/of_address.h>
 
+#include "internal.h"
+
 #define RAMOOPS_KERNMSG_HDR "===="
 #define MIN_MEM_SIZE 4096UL
 
@@ -362,11 +364,8 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
        struct timespec timestamp;
        size_t len;
 
-       /* Report zeroed timestamp if called before timekeeping has resumed. */
-       if (__getnstimeofday(&timestamp)) {
-               timestamp.tv_sec = 0;
-               timestamp.tv_nsec = 0;
-       }
+       pstore_get_timestamp(&timestamp);
+
        hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n",
                (long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000),
                compressed ? 'C' : 'D');
--

2.7.4

Signature · 2 lines
Kees Cook
Pixel Security
#6 lore raw

Hi Kees,

Thank you so much for your response.

Quoted 11 lines · Kees Cook
Quoted 10 lines · Ankit Kumar

Current pstore code(ram.c) gets dump timestamp and make it part of header. Different diffent architecture uses different header format and hence it won't be good idea to make ramoops_write_kmsg_hdr/ramoops_read_kmsg_hdr part of generic pstore code.

ramoops_write_kmsg_hdr calls __getnstimeofday to get timestamp and also takes care of condition if timekeeping has not resumed.

This patch moves code for retrieving timestamp to common place and hence can be used by other functions as well.

Quoted 8 lines

Ah! Heh, funny, I had just done a version of this while working on EFI pstore fixes. Here's what I did instead:

https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=pstore/fixes&id=ea209b760f104daf0cf62953090b66c5628b0842

This makes it so the time field is prepopulated for all backend writes, which should simplify things (no need to have the backends call out).

Above mentioned patch moves code to common place and also simplifies things. I agree, My patch is not required anymore.

Thank you;

~Ankit

Quoted 77 lines

-Kees

Quoted 73 lines
---
  fs/pstore/internal.h |  1 +
  fs/pstore/platform.c | 13 +++++++++++++
  fs/pstore/ram.c      |  9 ++++-----
  3 files changed, 18 insertions(+), 5 deletions(-)
fs/pstore/internal.h +1 -0
index c416e65..339dcdc 100644
@@ -22,6 +22,7 @@ static inline void pstore_unregister_pmsg(void) {}
  #endif
 
  extern struct pstore_info *psinfo;
+void pstore_get_timestamp(struct timespec *timestamp);
 
  extern void    pstore_set_kmsg_bytes(int);
  extern void    pstore_get_records(int);
fs/pstore/platform.c +13 -0
index d468eec..5cb25b0 100644
@@ -474,6 +474,19 @@ static size_t copy_kmsg_to_buffer(int hsize, size_t len)
         return total_len;
  }
 
+void pstore_get_timestamp(struct timespec *timestamp)
+{
+       if (!timestamp)
+               return;
+
+       /* Report zeroed timestamp if called before timekeeping has resumed. */
+       if (__getnstimeofday(timestamp)) {
+               timestamp->tv_sec = 0;
+               timestamp->tv_nsec = 0;
+       }
+}
+EXPORT_SYMBOL_GPL(pstore_get_timestamp);
+
  /*
   * callback from kmsg_dump. (s2,l2) has the most recently
   * written bytes, older bytes are in (s1,l1). Save as much
fs/pstore/ram.c +4 -6
index 5cb022c..e39297d 100644
@@ -37,6 +37,8 @@
  #include <linux/of.h>
  #include <linux/of_address.h>
 
+#include "internal.h"
+
  #define RAMOOPS_KERNMSG_HDR "===="
  #define MIN_MEM_SIZE 4096UL
 
@@ -362,11 +364,8 @@ static size_t ramoops_write_kmsg_hdr(struct persistent_ram_zone *prz,
         struct timespec timestamp;
         size_t len;
 
-       /* Report zeroed timestamp if called before timekeeping has resumed. */
-       if (__getnstimeofday(&timestamp)) {
-               timestamp.tv_sec = 0;
-               timestamp.tv_nsec = 0;
-       }
+       pstore_get_timestamp(&timestamp);
+
         hdr = kasprintf(GFP_ATOMIC, RAMOOPS_KERNMSG_HDR "%lu.%lu-%c\n",
                 (long)timestamp.tv_sec, (long)(timestamp.tv_nsec / 1000),
                 compressed ? 'C' : 'D');
--

2.7.4