pstore: ramoops: support multiple pmsg instances
Subsystems (4)
cover pstore: ramoops: support multiple pmsg instances
The following series implements multiple pmsg. This feature allows userspace program to control individual content aging or priority.
If a pstore backend module(e.g. ramoops) requires the multiple pmsg instances when registering itself to pstore, multiple /dev/pmsg[ID] are created. Writes to each /dev/pmsg[ID] are isolated each other. After reboot, the contents are available in /sys/fs/pstore/pmsg-[backend]-[ID].
In addition, we add multiple pmsg support for ramoops. We can specify multiple pmsg area size by its module parameter as follows.
pmsg_size=0x1000,0x2000,...
---
Hiraku Toyooka (5):
ramoops: use persistent_ram_free() instead of kfree() for freeing prz
ramoops: introduce generic init/free functions for prz
pstore: support multiple pmsg instances
ramoops: support multiple pmsg instances selftests/pstore: add testcases for multiple pmsg instances
Documentation/ramoops.txt | 22 ++ fs/pstore/pmsg.c | 20 ++ fs/pstore/ram.c | 213 +++++++++++++++----- include/linux/pstore.h | 1 include/linux/pstore_ram.h | 8 + tools/testing/selftests/pstore/common_tests | 21 ++ .../selftests/pstore/pstore_post_reboot_tests | 27 +-- tools/testing/selftests/pstore/pstore_tests | 16 +- 8 files changed, 257 insertions(+), 71 deletions(-)
--
Hiraku Toyooka
PATCH 1/5 ramoops: use persistent_ram_free() instead of kfree() for freeing prz
persistent_ram_zone(=prz) structures are allocated by persistent_ram_new(), which includes vmap() or ioremap(). But they are currently freed by kfree(). We should use persistent_ram_free() to correct this asymmetry usage.
--- fs/pstore/ram.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/pstore/ram.c +3 -3
@@ -567,11 +567,11 @@ fail_buf:kfree (cxt->pstore.buf); fail_clear: cxt->pstore.bufsize =0 ; -kfree (cxt->mprz); +persistent_ram_free (cxt->mprz); fail_init_mprz: -kfree (cxt->fprz); +persistent_ram_free (cxt->fprz); fail_init_fprz: -kfree (cxt->cprz); +persistent_ram_free (cxt->cprz); fail_init_cprz:ramoops_free_przs (cxt); fail_out:
PATCH 2/5 ramoops: introduce generic init/free functions for prz
In reply to Hiraku ToyookaWe modifies initialization and freeing code for prz for generic usage. This change
* add generic function __ramoops_init_prz() to reduce redundancy between ramoops_init_prz() and ramoops_init_przs().
* rename 'przs' member in struct ramoops_context to 'dprzs' so that it stands for 'dump przs'.
* rename ramoops_init_prz() to ramoops_init_dprzs().
* change parameter of ramoops_free_przs() from struct ramoops_context * into struct persistent_ram_zone * in order to make it available for all prz array.
--- fs/pstore/ram.c | 63 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 28 deletions(-)
fs/pstore/ram.c +35 -28
@@ -83,7 +83,7 @@ MODULE_PARM_DESC(ramoops_ecc, "bytes ECC)");struct ramoops_context { -struct persistent_ram_zone **przs; +struct persistent_ram_zone **dprzs;struct persistent_ram_zone *cprz;struct persistent_ram_zone *fprz;struct persistent_ram_zone *mprz;
@@ -199,7 +199,7 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,/* Find the next valid persistent_ram_zone for DMESG */ while (cxt->dump_read_cnt < cxt->max_dump_cnt && !prz) { - prz =ramoops_get_next_prz (cxt->przs, &cxt->dump_read_cnt, + prz =ramoops_get_next_prz (cxt->dprzs, &cxt->dump_read_cnt, cxt->max_dump_cnt, id, type,PSTORE_TYPE_DMESG ,1 );if (!prz_ok (prz))
@@ -314,10 +314,10 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,if (part !=1 )return -ENOSPC ; -if (!cxt->przs) +if (!cxt->dprzs)return -ENOSPC ; - prz = cxt->przs[cxt->dump_write_cnt]; + prz = cxt->dprzs[cxt->dump_write_cnt]; hlen =ramoops_write_kmsg_hdr (prz, compressed);if (size + hlen > prz->buffer_size)
@@ -339,7 +339,7 @@ static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, int count,case PSTORE_TYPE_DMESG :if (id >= cxt->max_dump_cnt)return -EINVAL ; - prz = cxt->przs[id]; + prz = cxt->dprzs[id];break ;case PSTORE_TYPE_CONSOLE : prz = cxt->cprz;
@@ -371,21 +371,24 @@ static struct ramoops_context oops_cxt = { }, }; -static void ramoops_free_przs (struct ramoops_context *cxt) +static void ramoops_free_przs (struct persistent_ram_zone **przs) {int i; - cxt->max_dump_cnt =0 ; -if (!cxt->przs) +if (!przs)return ; -for (i =0 ; !IS_ERR_OR_NULL (cxt->przs[i]); i++) -persistent_ram_free (cxt->przs[i]); -kfree (cxt->przs); +for (i =0 ; i < !IS_ERR_OR_NULL (przs[i]); i++) +persistent_ram_free (przs[i]); +kfree (przs); } -static int ramoops_init_przs (struct device *dev,struct ramoops_context *cxt, -phys_addr_t *paddr,size_t dump_mem_sz) +static int __ramoops_init_prz (struct device *dev,struct ramoops_context *cxt, +struct persistent_ram_zone **prz, +phys_addr_t *paddr,size_t sz,u32 sig,bool zap); + +static int ramoops_init_dprzs (struct device *dev,struct ramoops_context *cxt, +phys_addr_t *paddr,size_t dump_mem_sz) {int err = -ENOMEM ;int i;
@@ -402,29 +405,24 @@ static int ramoops_init_przs(struct device *dev, struct ramoops_context *cxt,if (!cxt->max_dump_cnt)return -ENOMEM ; - cxt->przs =kzalloc (sizeof (*cxt->przs) * cxt->max_dump_cnt, + cxt->dprzs =kcalloc (cxt->max_dump_cnt,sizeof (*cxt->dprzs),GFP_KERNEL ); -if (!cxt->przs) { +if (!cxt->dprzs) {dev_err (dev,"failed to initialize a prz array for dumps\n" ); goto fail_prz; }for (i =0 ; i < cxt->max_dump_cnt; i++) { - cxt->przs[i] =persistent_ram_new (*paddr, cxt->record_size,0 , - &cxt->ecc_info, - cxt->memtype); -if (IS_ERR (cxt->przs[i])) { - err =PTR_ERR (cxt->przs[i]); -dev_err (dev,"failed to request mem region (0x%zx@0x%llx): %d\n" , - cxt->record_size, (unsigned long long )*paddr, err); + err =__ramoops_init_prz (dev, cxt, &cxt->dprzs[i], paddr, + cxt->record_size,0 , false); +if (err) goto fail_prz; - } - *paddr += cxt->record_size; }return 0 ; fail_prz: -ramoops_free_przs (cxt); + cxt->max_dump_cnt =0 ; +ramoops_free_przs (cxt->dprzs);return err; }
@@ -432,6 +430,13 @@ static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,struct persistent_ram_zone **prz, phys_addr_t *paddr, size_t sz, u32 sig) { + return __ramoops_init_prz(dev, cxt, prz, paddr, sz, sig, true); +} + +static int __ramoops_init_prz (struct device *dev,struct ramoops_context *cxt, +struct persistent_ram_zone **prz, +phys_addr_t *paddr,size_t sz,u32 sig,bool zap) +{if (!sz)return 0 ;
@@ -451,7 +456,8 @@ static int ramoops_init_prz(struct device *dev, struct ramoops_context *cxt,return err; } -persistent_ram_zap (*prz); +if (zap) +persistent_ram_zap (*prz); *paddr += sz;
@@ -503,7 +509,7 @@ static int ramoops_probe(struct platform_device *pdev) dump_mem_sz = cxt->size - cxt->console_size - cxt->ftrace_size - cxt->pmsg_size; - err =ramoops_init_przs (dev, cxt, &paddr, dump_mem_sz); + err =ramoops_init_dprzs (dev, cxt, &paddr, dump_mem_sz);if (err) goto fail_out;
@@ -573,7 +579,8 @@ fail_init_mprz: fail_init_fprz:persistent_ram_free (cxt->cprz); fail_init_cprz: -ramoops_free_przs (cxt); + cxt->max_dump_cnt =0 ; +ramoops_free_przs (cxt->dprzs); fail_out:return err; }
PATCH 3/5 pstore: support multiple pmsg instances
In reply to Hiraku ToyookaThis patch enables pmsg to deal with multiple instances. One possible use is content priority control on limited persistent store space. By using different buffers, we can prevent important messages from being overwritten by less important messages.
When a pstore backend module specifies the number of instances (num_pmsg) in pstore_info, multiple /dev/pmsg[ID] appear. (ID is an integer starting at 0. It corresponds to minor number of the each char device.) Writes to each /dev/pmsg[ID] are isolated each other. After reboot, the contents are available in /sys/fs/pstore/pmsg-[backend]-[ID].
--- fs/pstore/pmsg.c | 20 ++++++++++++++++++-- include/linux/pstore.h | 1 + 2 files changed, 19 insertions(+), 2 deletions(-)
fs/pstore/pmsg.c +18 -2
@@ -50,8 +50,8 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,vfree (buffer);return -EFAULT ; } - psinfo->write_buf (PSTORE_TYPE_PMSG ,0 , &id,0 , buffer,0 , c, - psinfo); + psinfo->write_buf (PSTORE_TYPE_PMSG ,0 , &id, +iminor (file->f_inode), buffer,0 , c, psinfo); i += c; }
@@ -83,6 +83,7 @@ static char *pmsg_devnode(struct device *dev, umode_t *mode)void pstore_register_pmsg (void ) {struct device *pmsg_device; +int i =0 ; pmsg_major =register_chrdev (0 ,PMSG_NAME , &pmsg_fops);if (pmsg_major <0 ) {
@@ -103,9 +104,24 @@ void pstore_register_pmsg(void)pr_err ("failed to create device\n" ); goto err_device; } + +/* allocate additional /dev/pmsg[ID] */ +for (i =1 ; i < psinfo->num_pmsg; i++) { +struct device *pmsg_device; + + pmsg_device =device_create (pmsg_class,NULL , +MKDEV (pmsg_major, i),NULL ,"%s%d" , +PMSG_NAME , i); +if (IS_ERR (pmsg_device)) { +pr_err ("failed to create device\n" ); + goto err_device; + } + }return ; err_device: +for (i--; i >=0 ; i--) +device_destroy (pmsg_class,MKDEV (pmsg_major, i));class_destroy (pmsg_class); err_class:unregister_chrdev (pmsg_major,PMSG_NAME );
include/linux/pstore.h +1 -0
@@ -54,6 +54,7 @@ struct pstore_info {size_t bufsize;struct mutex read_mutex;/* serialize open/read/close */ int flags; +unsigned int num_pmsg;int (*open)(struct pstore_info *psi);int (*close)(struct pstore_info *psi); ssize_t (*read)(u64 *id, enum pstore_type_id *type,
PATCH 4/5 ramoops: support multiple pmsg instances
In reply to Hiraku ToyookaThis patch enables ramoops to deal with multiple pmsg instances. We can configure the size of each buffers by its module parameter as follows.
pmsg_size=0x1000,0x2000,...
Then, the ramoops allocates multiple buffers and tells the number of buffers to pstore to create multiple /dev/pmsg[ID].
--- Documentation/ramoops.txt | 22 +++++++ fs/pstore/ram.c | 146 ++++++++++++++++++++++++++++++++++++++------ include/linux/pstore_ram.h | 8 ++ 3 files changed, 154 insertions(+), 22 deletions(-)
Documentation/ramoops.txt +22 -0
@@ -126,3 +126,25 @@ file. Here is an example of usage: 0 ffffffff811d9c54 ffffffff8101a7a0 __const_udelay <- native_machine_emergency_restart+0x110/0x1e0 0 ffffffff811d9c34 ffffffff811d9c80 __delay <- __const_udelay+0x30/0x40 0 ffffffff811d9d14 ffffffff811d9c3f delay_tsc <- __delay+0xf/0x20 + +6. Pmsg support + +Ramoops supports pmsg - logging userspace mesages in persistent store. By +default, one pmsg area becomes available in ramoops. You can write data into +/dev/pmsg0, e.g.: + + # echo foo > /dev/pmsg0 + +After reboot, the stored data can be read from pmsg-ramoops-0 on the pstore +filesystem. + +You can specify size of the pmsg area by additional kernel command line, e.g.: + + "ramoops.pmsg_size=0x1000" + +You can also use multiple pmsg areas, e.g.: + + "ramoops.pmsg_size=0x1000,0x2000,..." + +Then, pmsg0, pmsg1, ... will appear on /dev. This is useful to control +individual content aging or priority.
fs/pstore/ram.c +125 -21
279 lines not on this page · raw message
include/linux/pstore_ram.h +7 -1
@@ -72,6 +72,12 @@ ssize_t persistent_ram_ecc_string(struct persistent_ram_zone *prz,* Ramoops platform data * @mem_size memory size for ramoops * @mem_address physical memory address to contain ramoops +* @pmsg_size array containing size of each pmsg area. 0 value in the array +* indicates the end of the content. For example, if the following +* array is given, +* .pmsg_size = { 0x1000, 0x2000, 0x0, 0x3000, }; +* then, pmsg areas are allocated for the first two size values +* and '0x3000' is just ignored. */ struct ramoops_platform_data {
@@ -81,7 +87,7 @@ struct ramoops_platform_data {unsigned long record_size;unsigned long console_size;unsigned long ftrace_size; -unsigned long pmsg_size; +unsigned long *pmsg_size;int dump_oops;struct persistent_ram_ecc_info ecc_info; };
PATCH 5/5 selftests/pstore: add testcases for multiple pmsg instances
In reply to Hiraku ToyookaTo test multiple pmsg, we should check that /dev/pmsg[N] (N > 0) is available. After reboot, we should check that pmsg-[backend]-[N] which keeps content is detected even if pmsg-[backend]-[N-M] (0 < M <= N) doesn't exist due to lack of contents.
So we add the following testcases.
- pstore_tests
- Write unique string to the last /dev/pmsgN
- pstore_post_reboot_tests
- Check the last pmsg area is detected
--- tools/testing/selftests/pstore/common_tests | 21 ++++++++++++++-- .../selftests/pstore/pstore_post_reboot_tests | 27 +++++++++++--------- tools/testing/selftests/pstore/pstore_tests | 16 ++++++++++-- 3 files changed, 47 insertions(+), 17 deletions(-)
tools/testing/selftests/pstore/common_tests +19 -2
@@ -27,9 +27,9 @@ show_result() { # result_value } check_files_exist() { # type of pstorefs file - if [ -e ${1}-${backend}-0 ]; then + if [ -e ${1}0 ]; then prlog "ok" - for f in `ls ${1}-${backend}-*`; do + for f in `ls ${1}*`; do prlog -e "\t${f}" done else
@@ -53,6 +53,23 @@ operate_files() { # tested value, files, operation fi } +check_pmsg_content() { # pmsg filename + prev_uuid=`cat $TOP_DIR/prev_uuid` + if [ $? -eq 0 ]; then + nr_matched=`grep -c "$TEST_STRING_PATTERN" $1` + if [ "$nr_matched" = "1" ]; then + grep -q "$TEST_STRING_PATTERN"$prev_uuid $1 + show_result $? + else + prlog "FAIL" + rc=1 + fi + else + prlog "FAIL" + rc=1 + fi +} + # Parameters TEST_STRING_PATTERN="Testing pstore: uuid=" UUID=`cat /proc/sys/kernel/random/uuid`
tools/testing/selftests/pstore/pstore_post_reboot_tests +15 -12
@@ -35,13 +35,13 @@ fi cd ${mount_point} prlog -n "Checking dmesg files exist in pstore filesystem ... " -check_files_exist dmesg +check_files_exist dmesg-${backend}- prlog -n "Checking console files exist in pstore filesystem ... " -check_files_exist console +check_files_exist console-${backend}- prlog -n "Checking pmsg files exist in pstore filesystem ... " -check_files_exist pmsg +check_files_exist pmsg-${backend}- prlog -n "Checking dmesg files contain oops end marker" grep_end_trace() {
@@ -54,16 +54,19 @@ prlog -n "Checking console file contains oops end marker ... " grep -q "\---\[ end trace" console-${backend}-0 show_result $? -prlog -n "Checking pmsg file properly keeps the content written before crash ... " -prev_uuid=`cat $TOP_DIR/prev_uuid` -if [ $? -eq 0 ]; then - nr_matched=`grep -c "$TEST_STRING_PATTERN" pmsg-${backend}-0` - if [ $nr_matched -eq 1 ]; then - grep -q "$TEST_STRING_PATTERN"$prev_uuid pmsg-${backend}-0 - show_result $? +prlog -n "Checking pmsg-"${backend}"-0 properly keeps the content written before crash ... " +check_pmsg_content pmsg-${backend}-0 + +prlog -n "Checking the last pmsg area is detected " +last_num_pmsg=`ls -v pmsg-* | tail -n1 | sed -e "s/^pmsg-${backend}-\([0-9]*\).*$/\1/"` +last_num_devpmsg=`ls -v /dev/pmsg* | tail -n1 | sed -e "s/^\/dev\/pmsg\([0-9]*\).*$/\1/"` +#checks the last number of pmsg-*-* and /dev/pmsg* correspond. +if [ "$last_num_pmsg" -eq "$last_num_devpmsg" ]; then + if [ "$last_num_pmsg" = "0" ]; then + prlog "... No multiple pmsg-*-* exists. We skip this testcase." else - prlog "FAIL" - rc=1 + prlog -n "(pmsg-${backend}-${last_num_pmsg}) ... " + check_pmsg_content pmsg-${backend}-${last_num_pmsg} fi else prlog "FAIL"
tools/testing/selftests/pstore/pstore_tests +13 -3
@@ -13,9 +13,8 @@ prlog -n "Checking pstore console is registered ... " dmesg | grep -q "console \[pstore" show_result $? -prlog -n "Checking /dev/pmsg0 exists ... " -test -e /dev/pmsg0 -show_result $? +prlog -n "Checking /dev/pmsg files exist ... " +check_files_exist /dev/pmsg prlog -n "Writing unique string to /dev/pmsg0 ... " if [ -e "/dev/pmsg0" ]; then
@@ -27,4 +26,15 @@ else rc=1 fi +last_devpmsg=`ls -v /dev/pmsg* | tail -n1` +prlog -n "Writing unique string to the last /dev/pmsgN " +if [ "$last_devpmsg" = "/dev/pmsg0" ]; then + prlog "... No multiple /dev/pmsg* exists. We skip this testcase." +else + prlog -n "(${last_devpmsg}) ... " + echo "${TEST_STRING_PATTERN}""$UUID" > ${last_devpmsg} + show_result $? + +fi + exit $rc