: mtdoops: fixes and improvements
v7 cover : mtdoops: fixes and improvements
Hi!
(I'm taking the most of the discussion back to the mtd-list since most of it is now pure mtdoops stuff).
Here are a couple of patches to mtdoops which I've been working on for a while and which were recently discussed on the MTD list. They are applied on top of Artems tree,
http://git.infradead.org/users/dedekind/l2-mtd-2.6.git
which apart from the mainline tree contains a panic fix from Aaro and Artems mtdoops style cleanup patch.
Now, I'd like to warn sensitive readers that patch 5 *does* contain work queue elements. However, I believe there is a good reason for this: The mtd->write call is not good to call while oopsing, and mtd->panic_write is sort of a last resort. Now, if we panic anyhow, mtd->panic_write will be called, so the oops will still be written and the scheduled work won't run anyway.
The patches are:
1. Avoid erasing already empty areas (the area would be erased at each module load otherwise)
2. Keep track of mtdoops page cleanliness in an array. This allows mtdoops_inc_counter to be called during panic (which fails in my case with the current code in mtd->read, although I believe this is MTD-driver dependent).
3. Make page size configurable to support longer messages. Mainly needed for patch 4, but also allows longer messages to be stored during panics (when the next oops area cannot be erased).
4. (kernel/printk.c) Add a kmsg_dumper as per Linus suggestion which includes a dump_kmsg function which dumps the kernel log buffer to registered devices.
5. Refactor mtdoops as a kmsg_dumper device instead of a console device.
ChangeLog:
v2:
* Patches have been reordered to keep the least controversial (?) first.
* Implement Artems suggestion to keep cleanliness in an array
* Use Aaros patch to fix the panic_on_oops problem
v3:
* Correct checkpatch issues
v4: Review corrections
* Rebase on top of "[PATCH] mtd: mtdoops: several minor cleanups"
* Patch 1 has been added
* Use 1 bit per oops page, and rename clean/dirty unused/used
* Don't initialize oops_page_dirty (it's a global structure anyway so it will be cleared together with the rest of BSS)
* Rename mtdoops_page_size record_size (although only for the page size setting)
v5: Corrections after panic_on_oops discussion
* Add dump_device
* Refactor mtdoops as a dump device.
v6: More corrections (panic_on_oops and Anders Grafström, my room-mate at work)
* Patches 2-5 modified
* Use set_bit/clear_bit primitives in patch 2
* Set permissions for mtdoops arguments correct in patch 3 and 5
* Rename files and structures after Linus suggestions in patch 4
* Correct output under some conditions in patch 5
v7: Even more corrections:
* Patches 4-5 modified
* Remove the priv pointer from the kmsg_dumper structure
* Add Kconfig description of how to use mtdoops
* Fix kfree bug
// Simon
PATCH v7 1/5 : mtdoops: avoid erasing already empty areas
After having scanned the entire mtdoops area, mtdoops will erase it if there are no mtdoops headers in it. However, empty and already erased areas (i.e., without mtdoops headers) will therefore also be erased at each startup.
This patch counts the number of unclean pages (neither empty nor with the mtdoops header) and only erases if no headers are found and the area is still unclean.
--- drivers/mtd/mtdoops.c | 18 ++++++++++++++---- 1 files changed, 14 insertions(+), 4 deletions(-)
drivers/mtd/mtdoops.c +14 -4
@@ -225,7 +225,7 @@ static void mtdoops_workfunc_write(struct work_struct *work)static void find_next_position (struct mtdoops_context *cxt) {struct mtd_info *mtd = cxt->mtd; -int ret, page, maxpos =0 ; +int ret, page, maxpos =0 , unclean_pages =0 ;u32 count[2 ], maxcount =0xffffffff ;size_t retlen;
@@ -237,10 +237,13 @@ static void find_next_position(struct mtdoops_context *cxt)continue ; } -if (count[1 ] !=MTDOOPS_KERNMSG_MAGIC ) -continue ;if (count[0 ] ==0xffffffff )continue ; +if (count[1 ] !=MTDOOPS_KERNMSG_MAGIC ) { +/* Page is neither clean nor empty */ + unclean_pages++; +continue ; + }if (maxcount ==0xffffffff ) { maxcount = count[0 ]; maxpos = page;
@@ -259,7 +262,14 @@ static void find_next_position(struct mtdoops_context *cxt)if (maxcount ==0xffffffff ) { cxt->nextpage =0 ; cxt->nextcount =1 ; -schedule_work (&cxt->work_erase); +if (unclean_pages !=0 ) { +printk (KERN_INFO "mtdoops: cleaning area\n" ); +schedule_work (&cxt->work_erase); + }else { +printk (KERN_DEBUG "mtdoops: ready %d, %d (clean)\n" , + cxt->nextpage, cxt->nextcount); + cxt->ready =1 ; + }return ; }
Signature · 1 line
1.6.0.4
Re: [PATCH v7 1/5]: mtdoops: avoid erasing already empty areas
Quoted 10 lines · Simon Kagstrom
After having scanned the entire mtdoops area, mtdoops will erase it if there are no mtdoops headers in it. However, empty and already erased areas (i.e., without mtdoops headers) will therefore also be erased at each startup.
This patch counts the number of unclean pages (neither empty nor with the mtdoops header) and only erases if no headers are found and the area is still unclean.
Signed-off-by Simon Kagstrom <[email protected]>
Actually, it is safer to erase the partition. This is exactly why JFFS2 has erase markers. On NOR flash, if you interrupt an erase operation (e.g., by re-booting), you may end up with unstable bits, which are read as '1' sometimes, but sometimes they may be read as '1'. Or you may end up with 0xFF's at the beginning, and garbage at the end.
When you erase the partition before starting using it, you make sure you start with eraseblocks in normal state.
In practice, we observed stuff like that only on NOR, so if this is a performance issue for you, you can make the erasure to be mandatory only on NOR, but this won't be very nice.
BTW, we could also add some limit to the partition size of MTD oops. If users use mtdoops with 256MiB partition, e.g., by mistake, it does not make sense and we may just refuse it, instead of erasing.
-----
Side note, not a request to implement, but if you add a comment to the code about this, it may be nice
-----
BTW, this suggests that before erasing eraseblocks in MTD oops, you need to "invalidate" them by writing, say zeroes, to the second byte of the eraseblock, if this is NOR. This is what we added to UBI recently, because otherwise unclean reboots made it fail horribly on NOR, If you are interested, you may take a look at the 'nor_erase_prepare()' function in drivers/mtd/ubi/io.c
But again, this is NOR-specific.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
PATCH v7 2/5 : mtdoops: Keep track of used/unused mtdoops pages in an array
In reply to Simon KagstromThis patch makes mtdoops keep track of used/unused pages in an array instead of scanning the flash after a write. The advantage with this approach is that it avoids calling mtd->read on a panic, which is not possible for all mtd drivers.
--- drivers/mtd/mtdoops.c | 62 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 44 insertions(+), 18 deletions(-)
drivers/mtd/mtdoops.c +44 -18
@@ -44,6 +44,7 @@ static struct mtdoops_context {int oops_pages;int nextpage;int nextcount; +unsigned long *oops_page_used;char *name;void *oops_buf;
@@ -54,18 +55,38 @@ static struct mtdoops_context {int writecount; } oops_cxt; +static void mark_page_used (struct mtdoops_context *cxt,int page) +{ +set_bit (page, cxt->oops_page_used); +} + +static void mark_page_unused (struct mtdoops_context *cxt,int page) +{ +clear_bit (page, cxt->oops_page_used); +} + +static int page_is_used (struct mtdoops_context *cxt,int page) +{ +return test_bit (page, cxt->oops_page_used); +} +static void mtdoops_erase_callback (struct erase_info *done) {wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;wake_up (wait_q); } -static int mtdoops_erase_block (struct mtd_info *mtd,int offset) +static int mtdoops_erase_block (struct mtdoops_context *cxt,int offset) { +struct mtd_info *mtd = cxt->mtd; +u32 start_page_offset =mtd_div_by_eb (offset, mtd) * mtd->erasesize; +u32 start_page = start_page_offset /OOPS_PAGE_SIZE ; +u32 erase_pages = mtd->erasesize /OOPS_PAGE_SIZE ;struct erase_info erase;DECLARE_WAITQUEUE (wait, current);wait_queue_head_t wait_q;int ret; +int page;init_waitqueue_head (&wait_q); erase.mtd = mtd;
@@ -90,16 +111,15 @@ static int mtdoops_erase_block(struct mtd_info *mtd, int offset)schedule ();/* Wait for erase to finish. */ remove_wait_queue (&wait_q, &wait); +/* Mark pages as unused */ +for (page = start_page; page < start_page + erase_pages; page++) +mark_page_unused (cxt, page); +return 0 ; }static void mtdoops_inc_counter (struct mtdoops_context *cxt) { -struct mtd_info *mtd = cxt->mtd; -size_t retlen; -u32 count; -int ret; - cxt->nextpage++;if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage =0 ;
@@ -107,17 +127,7 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt)if (cxt->nextcount ==0xffffffff ) cxt->nextcount =0 ; - ret = mtd->read (mtd, cxt->nextpage *OOPS_PAGE_SIZE ,4 , - &retlen, (u_char *) &count); -if (retlen !=4 || (ret <0 && ret != -EUCLEAN )) { -printk (KERN_ERR "mtdoops: read failure at %d (%td of 4 read), err %d\n" , - cxt->nextpage *OOPS_PAGE_SIZE , retlen, ret); -schedule_work (&cxt->work_erase); -return ; - } - -/* See if we need to erase the next block */ -if (count !=0xffffffff ) { +if (page_is_used (cxt, cxt->nextpage)) {schedule_work (&cxt->work_erase);return ; }
@@ -168,7 +178,7 @@ badblock: }for (j =0 , ret =-1 ; (j <3 ) && (ret <0 ); j++) - ret =mtdoops_erase_block (mtd, cxt->nextpage *OOPS_PAGE_SIZE ); + ret =mtdoops_erase_block (cxt, cxt->nextpage *OOPS_PAGE_SIZE );if (ret >=0 ) { printk(KERN_DEBUG "mtdoops: ready %d, %d\n",
@@ -209,6 +219,7 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)if (retlen !=OOPS_PAGE_SIZE || ret <0 )printk (KERN_ERR "mtdoops: write failure at %d (%td of %d written), error %d\n" , cxt->nextpage *OOPS_PAGE_SIZE , retlen,OOPS_PAGE_SIZE , ret); +mark_page_used (cxt, cxt->nextpage);mtdoops_inc_counter (cxt); }
@@ -230,6 +241,8 @@ static void find_next_position(struct mtdoops_context *cxt)size_t retlen;for (page =0 ; page < cxt->oops_pages; page++) { +/* Assume the page is used */ +mark_page_used (cxt, page); ret = mtd->read (mtd, page *OOPS_PAGE_SIZE ,8 , &retlen, (u_char *) &count[0 ]);if (retlen !=8 || (ret <0 && ret != -EUCLEAN )) { printk(KERN_ERR "mtdoops: read failure at %d (%td of 8 read), err %d\n",
@@ -237,6 +250,8 @@ static void find_next_position(struct mtdoops_context *cxt)continue ; } +if (count[0 ] ==0xffffffff && count[1 ] ==0xffffffff ) +mark_page_unused (cxt, page);if (count[0 ] ==0xffffffff )continue ;if (count[1 ] !=MTDOOPS_KERNMSG_MAGIC ) {
@@ -283,6 +298,9 @@ static void find_next_position(struct mtdoops_context *cxt)static void mtdoops_notify_add (struct mtd_info *mtd) {struct mtdoops_context *cxt = &oops_cxt; +u64 mtdoops_pages = mtd->size; + +do_div (mtdoops_pages,OOPS_PAGE_SIZE );if (cxt->name && !strcmp (mtd->name, cxt->name)) cxt->mtd_index = mtd->index;
@@ -302,6 +320,13 @@ static void mtdoops_notify_add(struct mtd_info *mtd)return ; } +/* oops_page_used is a bit field */ + cxt->oops_page_used =vmalloc (DIV_ROUND_UP (mtdoops_pages, +BITS_PER_LONG )); +if (!cxt->oops_page_used) { +printk (KERN_ERR "Could not allocate page array\n" ); +return ; + } cxt->mtd = mtd;if (mtd->size >INT_MAX ) cxt->oops_pages =INT_MAX /OOPS_PAGE_SIZE ;
@@ -454,6 +479,7 @@ static void __exit mtdoops_console_exit(void)unregister_console (&mtdoops_console);kfree (cxt->name);vfree (cxt->oops_buf); +vfree (cxt->oops_page_used); }
Signature · 1 line
1.6.0.4
Re: [PATCH v7 2/5]: mtdoops: Keep track of used/unused mtdoops pages in an array
Quoted 7 lines · Simon Kagstrom
This patch makes mtdoops keep track of used/unused pages in an array instead of scanning the flash after a write. The advantage with this approach is that it avoids calling
mtd->readon a panic, which is not possible for all mtd drivers.Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
PATCH v7 3/5 : mtdoops: Make page (record) size configurable
In reply to Simon KagstromThe main justification for this is to allow catching long messages during a panic, where the top part might otherwise be lost since moving to the next block can require a flash erase.
--- drivers/mtd/mtdoops.c | 76 ++++++++++++++++++++++++++++-------------------- 1 files changed, 44 insertions(+), 32 deletions(-)
drivers/mtd/mtdoops.c +44 -32
@@ -34,7 +34,11 @@#include <linux/mtd/mtd.h> #define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 -#define OOPS_PAGE_SIZE 4096 + +static unsigned long record_size =4096 ; +module_param (record_size, ulong,0400 ); +MODULE_PARM_DESC (record_size, +"record size for MTD OOPS pages in bytes (default 4096)" ); static struct mtdoops_context { int mtd_index;
@@ -80,8 +84,8 @@ static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) {struct mtd_info *mtd = cxt->mtd;u32 start_page_offset =mtd_div_by_eb (offset, mtd) * mtd->erasesize; -u32 start_page = start_page_offset /OOPS_PAGE_SIZE ; -u32 erase_pages = mtd->erasesize /OOPS_PAGE_SIZE ; +u32 start_page = start_page_offset / record_size; +u32 erase_pages = mtd->erasesize / record_size;struct erase_info erase;DECLARE_WAITQUEUE (wait, current);wait_queue_head_t wait_q;
@@ -149,15 +153,15 @@ static void mtdoops_workfunc_erase(struct work_struct *work)if (!mtd)return ; - mod = (cxt->nextpage *OOPS_PAGE_SIZE ) % mtd->erasesize; + mod = (cxt->nextpage * record_size) % mtd->erasesize;if (mod !=0 ) { - cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) /OOPS_PAGE_SIZE ); + cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size);if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage =0 ; }while (mtd->block_isbad) { - ret = mtd->block_isbad (mtd, cxt->nextpage *OOPS_PAGE_SIZE ); + ret = mtd->block_isbad (mtd, cxt->nextpage * record_size);if (!ret)break ;if (ret <0 ) {
@@ -165,20 +169,20 @@ static void mtdoops_workfunc_erase(struct work_struct *work)return ; } badblock: -printk (KERN_WARNING "mtdoops: bad block at %08x\n" , - cxt->nextpage *OOPS_PAGE_SIZE ); +printk (KERN_WARNING "mtdoops: bad block at %08lx\n" , + cxt->nextpage * record_size); i++; - cxt->nextpage = cxt->nextpage + (mtd->erasesize /OOPS_PAGE_SIZE ); + cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size);if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage =0 ; -if (i == cxt->oops_pages / (mtd->erasesize /OOPS_PAGE_SIZE )) { +if (i == cxt->oops_pages / (mtd->erasesize / record_size)) {printk (KERN_ERR "mtdoops: all blocks bad!\n" );return ; } }for (j =0 , ret =-1 ; (j <3 ) && (ret <0 ); j++) - ret =mtdoops_erase_block (cxt, cxt->nextpage *OOPS_PAGE_SIZE ); + ret =mtdoops_erase_block (cxt, cxt->nextpage * record_size);if (ret >=0 ) { printk(KERN_DEBUG "mtdoops: ready %d, %d\n",
@@ -188,7 +192,7 @@ badblock: }if (mtd->block_markbad && ret == -EIO ) { - ret = mtd->block_markbad (mtd, cxt->nextpage *OOPS_PAGE_SIZE ); + ret = mtd->block_markbad (mtd, cxt->nextpage * record_size);if (ret <0 ) {printk (KERN_ERR "mtdoops: block_markbad failed, aborting\n" );return ;
@@ -203,22 +207,22 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)size_t retlen;int ret; -if (cxt->writecount <OOPS_PAGE_SIZE ) +if (cxt->writecount < record_size)memset (cxt->oops_buf + cxt->writecount,0xff , -OOPS_PAGE_SIZE - cxt->writecount); + record_size - cxt->writecount);if (panic) - ret = mtd->panic_write (mtd, cxt->nextpage *OOPS_PAGE_SIZE , -OOPS_PAGE_SIZE , &retlen, cxt->oops_buf); + ret = mtd->panic_write (mtd, cxt->nextpage * record_size, + record_size, &retlen, cxt->oops_buf);else - ret = mtd->write (mtd, cxt->nextpage *OOPS_PAGE_SIZE , -OOPS_PAGE_SIZE , &retlen, cxt->oops_buf); + ret = mtd->write (mtd, cxt->nextpage * record_size, + record_size, &retlen, cxt->oops_buf); cxt->writecount =0 ; -if (retlen !=OOPS_PAGE_SIZE || ret <0 ) -printk (KERN_ERR "mtdoops: write failure at %d (%td of %d written), error %d\n" , - cxt->nextpage *OOPS_PAGE_SIZE , retlen,OOPS_PAGE_SIZE , ret); +if (retlen != record_size || ret <0 ) +printk (KERN_ERR "mtdoops: write failure at %ld (%td of %ld written), error %d\n" , + cxt->nextpage * record_size, retlen, record_size, ret);mark_page_used (cxt, cxt->nextpage);mtdoops_inc_counter (cxt);
@@ -243,10 +247,10 @@ static void find_next_position(struct mtdoops_context *cxt)for (page =0 ; page < cxt->oops_pages; page++) {/* Assume the page is used */ mark_page_used (cxt, page); - ret = mtd->read (mtd, page *OOPS_PAGE_SIZE ,8 , &retlen, (u_char *) &count[0 ]); + ret = mtd->read (mtd, page * record_size,8 , &retlen, (u_char *) &count[0 ]);if (retlen !=8 || (ret <0 && ret != -EUCLEAN )) { -printk (KERN_ERR "mtdoops: read failure at %d (%td of 8 read), err %d\n" , - page *OOPS_PAGE_SIZE , retlen, ret); +printk (KERN_ERR "mtdoops: read failure at %ld (%td of 8 read), err %d\n" , + page * record_size, retlen, ret);continue ; }
@@ -300,7 +304,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)struct mtdoops_context *cxt = &oops_cxt;u64 mtdoops_pages = mtd->size; -do_div (mtdoops_pages,OOPS_PAGE_SIZE ); +do_div (mtdoops_pages, record_size);if (cxt->name && !strcmp (mtd->name, cxt->name)) cxt->mtd_index = mtd->index;
@@ -314,7 +318,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)return ; } -if (mtd->erasesize <OOPS_PAGE_SIZE ) { +if (mtd->erasesize < record_size) {printk (KERN_ERR "mtdoops: eraseblock size of MTD partition %d too small\n" , mtd->index);return ;
@@ -329,9 +333,9 @@ static void mtdoops_notify_add(struct mtd_info *mtd) } cxt->mtd = mtd;if (mtd->size >INT_MAX ) - cxt->oops_pages =INT_MAX /OOPS_PAGE_SIZE ; + cxt->oops_pages =INT_MAX / record_size;else - cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ; + cxt->oops_pages = (int )mtd->size / record_size;find_next_position (cxt);
@@ -408,15 +412,15 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count) cxt->writecount =8 ; } -if (count + cxt->writecount >OOPS_PAGE_SIZE ) - count =OOPS_PAGE_SIZE - cxt->writecount; +if (count + cxt->writecount > record_size) + count = record_size - cxt->writecount;memcpy (cxt->oops_buf + cxt->writecount, s, count); cxt->writecount += count;spin_unlock_irqrestore (&cxt->writecount_lock, flags); -if (cxt->writecount ==OOPS_PAGE_SIZE ) +if (cxt->writecount == record_size)mtdoops_console_sync (); }
@@ -455,8 +459,16 @@ static int __init mtdoops_console_init(void) {struct mtdoops_context *cxt = &oops_cxt; +if ((record_size &4095 ) !=0 ) { +printk (KERN_ERR "mtdoops: record_size must be a multiple of 4096\n" ); +return -EINVAL ; + } +if (record_size <4096 ) { +printk (KERN_ERR "mtdoops: record_size must be over 4096 bytes\n" ); +return -EINVAL ; + } cxt->mtd_index =-1 ; - cxt->oops_buf =vmalloc (OOPS_PAGE_SIZE ); + cxt->oops_buf =vmalloc (record_size);if (!cxt->oops_buf) {printk (KERN_ERR "mtdoops: failed to allocate buffer workspace\n" );return -ENOMEM ;
Signature · 1 line
1.6.0.4
Re: [PATCH v7 3/5]: mtdoops: Make page (record) size configurable
Quoted 6 lines · Simon Kagstrom
The main justification for this is to allow catching long messages during a panic, where the top part might otherwise be lost since moving to the next block can require a flash erase.
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>
What will happen if I have a partition with 8192-bytes records, and then attach it to mtdoops with default 4096 ?
drivers/mtd/mtdoops.c static void mtdoops_notify_add(struct mtd_info *mtd) · line 338
Quoted 7 lines
drivers/mtd/mtdoops.c +2
-2cxt->mtd = mtd;if (mtd->size >INT_MAX ) - cxt->oops_pages =INT_MAX /OOPS_PAGE_SIZE ; + cxt->oops_pages =INT_MAX / record_size;else - cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ; + cxt->oops_pages = (int )mtd->size / record_size;
BTW, this INT_MAX and the (int) cast also suggests we need to limit the maximum partition size and add a check for this.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v7 3/5]: mtdoops: Make page (record) size configurable
Quoted 10 lines · On Fri, 23 Oct 2009 07:13:49 +0300 Artem Bityutskiy <[email protected]> wrote:
Quoted 6 lines · Simon Kagstrom
The main justification for this is to allow catching long messages during a panic, where the top part might otherwise be lost since moving to the next block can require a flash erase.
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>What will happen if I have a partition with 8192-bytes records, and then attach it to mtdoops with default 4096 ?
Assuming you have a crash stored, it will keep the first 4KB of it and mark the second 4KB as unclean. This will then trigger an erase where it will first move to the next erase block above and erase that (see mtdoops_inc_counter and mtdoops_workfunc_erase).
So until you've wrapped around to the 8KB record again, it will be kept. Userspace code to readout the mtdoops partition would have to be prepared for different sized blocks in this case.
In practice, I think that it's best to erase the oops area if you decide to change the size.
Quoted 10 lines
drivers/mtd/mtdoops.c static void mtdoops_notify_add(struct mtd_info *mtd) · line 338
Quoted 7 lines
drivers/mtd/mtdoops.c +2
-2cxt->mtd = mtd;if (mtd->size >INT_MAX ) - cxt->oops_pages =INT_MAX /OOPS_PAGE_SIZE ; + cxt->oops_pages =INT_MAX / record_size;else - cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ; + cxt->oops_pages = (int )mtd->size / record_size;BTW, this
INT_MAXand the (int) cast also suggests we need to limit the maximum partition size and add a check for this.
OK, I'll make a patch to limit this.
// Simon
PATCH v7 4/5 : core: Add kernel message dumper to call on oopses and panics
In reply to Simon KagstromThe core functionality is implemented as per Linus suggestion from
http://lists.infradead.org/pipermail/linux-mtd/2009-October/027620.html
(with the dump_kmsg implementation by Linus). A struct kmsg_dumper has been added which contains a callback to dump the kernel log buffers on crashes. The dump_kmsg function gets called from oops_exit() and panic() and invokes this callbacks with the crash reason.
---
ChangeLog:
* (The other patches are sent only to linux-mtd since they are really just mtdoops-specific now)
* (Linus) remove the priv pointer in the structure and
let users determine the address of their own structure with container_of
include/linux/kmsg_dump.h | 36 +++++++++++++++ kernel/panic.c | 3 + kernel/printk.c | 104 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 0 deletions(-) create mode 100644 include/linux/kmsg_dump.h
include/linux/kmsg_dump.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* linux/include/kmsg_dump.h +* +* Copyright (C) 2009 Net Insight AB +* +* Author: Simon Kagstrom <[email protected]> +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file COPYING in the main directory of this archive +* for more details. +*/ +#ifndef _LINUX_KMSG_DUMP_H +#define _LINUX_KMSG_DUMP_H + +#include <linux/list.h> + +enum kmsg_dump_reason { + kmsg_dump_oops, + kmsg_dump_panic, +}; + +struct kmsg_dumper { +void (*dump)(struct kmsg_dumper *dumper,enum kmsg_dump_reason reason, +const char *s1,unsigned long l1, +const char *s2,unsigned long l2); +struct list_head list; +int registered; +}; + +void dump_kmsg (enum kmsg_dump_reason reason); + +int register_kmsg_dumper (struct kmsg_dumper *dumper); + +void unregister_kmsg_dumper (struct kmsg_dumper *dumper); + +#endif /* _LINUX_DUMP_DEVICE_H */
kernel/panic.c +3 -0
@@ -10,6 +10,7 @@*/ #include <linux/debug_locks.h> #include <linux/interrupt.h> +#include <linux/kmsg_dump.h> #include <linux/kallsyms.h> #include <linux/notifier.h> #include <linux/module.h>
@@ -76,6 +77,7 @@ NORET_TYPE void panic(const char * fmt, ...)dump_stack ();#endif +dump_kmsg (kmsg_dump_panic);/* * If we have crashed and we have a crash kernel loaded let it handle * everything else.
@@ -341,6 +343,7 @@ void oops_exit(void) {do_oops_enter_exit ();print_oops_end_marker (); +dump_kmsg (kmsg_dump_oops); }#ifdef WANT_WARN_ON_SLOWPATH
kernel/printk.c +104 -0
113 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Re: [PATCH v7 4/5]: core: Add kernel message dumper to call on oopses and panics
include/linux/kmsg_dump.h line 20
Quoted 7 lines · Simon Kagstrom
include/linux/kmsg_dump.h new file +4
-0+enum kmsg_dump_reason { + kmsg_dump_oops, + kmsg_dump_panic, +};
Please capitalize constants - lower case suggests it's some sort of variable which it is not.
include/linux/kmsg_dump.h line 34
Quoted 5 lines
include/linux/kmsg_dump.h new file +5
-0+void dump_kmsg (enum kmsg_dump_reason reason); + +int register_kmsg_dumper (struct kmsg_dumper *dumper); + +void unregister_kmsg_dumper (struct kmsg_dumper *dumper);
Please rename these APIs to be more in line with how we name new kernel APIs. Something like:
kmsg_dump()
kmsg_dumper_register()
kmsg_dumper_unregister()
(we start with the subsystem as a prefix, then we go from more generic to less generic words.)
Might even make sense to name them all kmsg_dump:
kmsg_dump()
kmsg_dump_register()
kmsg_dump_unregister()
Thanks,
Ingo
PATCH v8 4/5 core: Add kernel message dumper to call on oopses and panics
The core functionality is implemented as per Linus suggestion from
http://lists.infradead.org/pipermail/linux-mtd/2009-October/027620.html
(with the kmsg_dump implementation by Linus). A struct kmsg_dumper has been added which contains a callback to dump the kernel log buffers on crashes. The kmsg_dump function gets called from oops_exit() and panic() and invokes this callbacks with the crash reason.
---
ChangeLog:
* (Ingo Molnar) rename functions to new standard
* (Ingo Molnar) use capitals for constants
include/linux/kmsg_dump.h | 36 +++++++++++++++ kernel/panic.c | 3 + kernel/printk.c | 104 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 143 insertions(+), 0 deletions(-) create mode 100644 include/linux/kmsg_dump.h
include/linux/kmsg_dump.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* linux/include/kmsg_dump.h +* +* Copyright (C) 2009 Net Insight AB +* +* Author: Simon Kagstrom <[email protected]> +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file COPYING in the main directory of this archive +* for more details. +*/ +#ifndef _LINUX_KMSG_DUMP_H +#define _LINUX_KMSG_DUMP_H + +#include <linux/list.h> + +enum kmsg_dump_reason { +KMSG_DUMP_OOPS , +KMSG_DUMP_PANIC , +}; + +struct kmsg_dumper { +void (*dump)(struct kmsg_dumper *dumper,enum kmsg_dump_reason reason, +const char *s1,unsigned long l1, +const char *s2,unsigned long l2); +struct list_head list; +int registered; +}; + +void kmsg_dump (enum kmsg_dump_reason reason); + +int kmsg_dump_register (struct kmsg_dumper *dumper); + +void kmsg_dump_unregister (struct kmsg_dumper *dumper); + +#endif /* _LINUX_DUMP_DEVICE_H */
kernel/panic.c +3 -0
@@ -10,6 +10,7 @@*/ #include <linux/debug_locks.h> #include <linux/interrupt.h> +#include <linux/kmsg_dump.h> #include <linux/kallsyms.h> #include <linux/notifier.h> #include <linux/module.h>
@@ -76,6 +77,7 @@ NORET_TYPE void panic(const char * fmt, ...)dump_stack ();#endif +kmsg_dump (KMSG_DUMP_PANIC );/* * If we have crashed and we have a crash kernel loaded let it handle * everything else.
@@ -341,6 +343,7 @@ void oops_exit(void) {do_oops_enter_exit ();print_oops_end_marker (); +kmsg_dump (KMSG_DUMP_OOPS ); }#ifdef WANT_WARN_ON_SLOWPATH
kernel/printk.c +104 -0
113 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Re: [PATCH v8 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 11 lines · Simon Kagstrom
The core functionality is implemented as per Linus suggestion from
http://lists.infradead.org/pipermail/linux-mtd/2009-October/027620.html
(with the
kmsg_dumpimplementation by Linus). A structkmsg_dumperhas been added which contains a callback to dump the kernel log buffers on crashes. Thekmsg_dumpfunction gets called fromoops_exit()andpanic()and invokes this callbacks with the crash reason.Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>
The general structure looks very nice now! Assuming my review comments below are addressed all patches are:
kernel/printk.c line 37
Quoted 10 lines
kernel/printk.c +2
-0@@ -33,6 +33,8 @@#include <linux/bootmem.h> #include <linux/syscalls.h> #include <linux/kexec.h> +#include <linux/kmsg_dump.h> +#include <linux/spinlock.h>
( Small nit: in theory the spinlock.h include should not be needed as
printk.c already uses spinlocks and gets the types via mutex.h. )
kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1412
Quoted 10 lines
kernel/printk.c +3
-0#include <asm/uaccess.h> @@ -1405,3 +1407,105 @@ bool printk_timed_ratelimit(unsigned long *caller_jiffies, }EXPORT_SYMBOL (printk_timed_ratelimit);#endif + +static LIST_HEAD (dump_list); +static DEFINE_SPINLOCK (dump_list_lock);
Please switch it around to be:
static DEFINE_SPINLOCK(dump_list_lock); static LIST_HEAD(dump_list);
as the lock will be cacheline aligned on SMP, so the list head can come after it 'for free'.
If it's the other way around we'll use 8/16 more .data bytes on average.
Quoted 20 lines
kernel/printk.c +20
-0+ +/** +* kmsg_dump_register - register a kernel log dumper. +* @dump: pointer to the kmsg_dumper structure +* @priv: private data for the structure +* +* Adds a kernel log dumper to the system. The dump callback in the +* structure will be called when the kernel oopses or panics and must be +* set. Returns zero on success and -EINVAL or -EBUSY otherwise. +*/ +int kmsg_dump_register (struct kmsg_dumper *dumper) +{ +unsigned long flags; + +/* The dump callback needs to be set */ +if (!dumper->dump) +return -EINVAL ; + +/* Don't allow registering multiple times */ +if (dumper->registered)
kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1442
Quoted 10 lines
kernel/printk.c +10
-0+return -EBUSY ; + + dumper->registered =1 ; + +spin_lock_irqsave (&dump_list_lock, flags); +list_add (&dumper->list, &dump_list); +spin_unlock_irqrestore (&dump_list_lock, flags); +return 0 ; +} +EXPORT_SYMBOL (kmsg_dump_register);
There's a race here: dumper->registered should be set to 1 inside the spinlock - to make the register/unregister API SMP safe.
It probably doesnt matter much in practice right now (as the dumper will be registered during bootup and unregistered during shutdown), but still
- it could matter to modular loading of multiple dumpers at once, in the future.
Also, the check for ->registered should be done inside too.
Plus a style nit: please put a newline before the 'return 0' - it looks more symmetric and separates the return from other code flow.
Quoted 6 lines
kernel/printk.c +6
-0+ +/** +* kmsg_dump_unregister - unregister a kmsg dumper. +* @dump: pointer to the kmsg_dumper structure +* +* Removes a dump device from the system.
kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1458
Quoted 10 lines
kernel/printk.c +10
-0+*/ +void kmsg_dump_unregister (struct kmsg_dumper *dumper) +{ +unsigned long flags; + +spin_lock_irqsave (&dump_list_lock, flags); +list_del (&dumper->list); +spin_unlock_irqrestore (&dump_list_lock, flags); +} +EXPORT_SYMBOL (kmsg_dump_unregister);
I'd suggest for this API to use an error return as well, and to do it safely - i.e. any combination of these APIs should result in a safe result.
Right now a call sequence kmsg_dump_register() + kmsg_dump_unregister()
+ kmsg_dump_register() will corrupt memory.
kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1463
Quoted 5 lines
kernel/printk.c +5
-0+ +static const char *kmsg_reasons[] = { + [KMSG_DUMP_OOPS ] ="oops" , + [KMSG_DUMP_PANIC ] ="panic" , +};
Should be 'const char const' for max constness.
kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1468
Quoted 4 lines
kernel/printk.c +4
-0+static const char *kmsg_to_str (enum kmsg_dump_reason reason) +{ +if (reason >ARRAY_SIZE (kmsg_reasons) || reason <0 ) +return "unknown" ;
That should be ">=" i guess, for the check to be correct.
Quoted 33 lines
kernel/printk.c +33
-0+ +return kmsg_reasons[reason]; +} + +/** +* dump_kmsg - dump kernel log to kernel message dumpers. +* @reason: the reason (oops, panic etc) for dumping +* +* Iterate through each of the dump devices and call the oops/panic +* callbacks with the log buffer. +*/ +void kmsg_dump (enum kmsg_dump_reason reason) +{ +unsigned long len =ACCESS_ONCE (log_end); +struct kmsg_dumper *dumper; +const char *s1, *s2; +unsigned long l1, l2; + + s1 ="" ; + l1 =0 ; + s2 = log_buf; + l2 = len; + +/* Have we rotated around the circular buffer? */ +if (len > log_buf_len) { +unsigned long pos = len &LOG_BUF_MASK ; + + s1 = log_buf + pos; + l1 = log_buf_len - pos; + + s2 = log_buf; + l2 = pos; + }
kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1511
Quoted 10 lines
kernel/printk.c +10
-0+ +if (!spin_trylock (&dump_list_lock)) { +printk (KERN_ERR "dump_kmsg: dump list lock is held during %s, skipping dump\n" , +kmsg_to_str (reason)); +return ; + } +list_for_each_entry (dumper, &dump_list, list) + dumper->dump (dumper, reason, s1, l1, s2, l2); +spin_unlock (&dump_list_lock); +}
( Might make sense to use _irqsave()/_irqrestore() variants here - so
that if an IRQ comes in and panics too we dont recurse. The trylock protects us above, but we are already non-preempt here - going irqsafe is even better i guess. )
Ingo
PATCH v9 4/5 core: Add kernel message dumper to call on oopses and panics
The core functionality is implemented as per Linus suggestion from
http://lists.infradead.org/pipermail/linux-mtd/2009-October/027620.html
(with the kmsg_dump implementation by Linus). A struct kmsg_dumper has been added which contains a callback to dump the kernel log buffers on crashes. The kmsg_dump function gets called from oops_exit() and panic() and invokes this callbacks with the crash reason.
---
ChangeLog:
* (Arjan van de Ven): Use EXPORT_SYMBOL_GPL
* (Ingo Molnar): Switch list/spinlock definition order
* (Ingo Molnar): Set/check ->registered within spinlocked region
* (Ingo Molnar): Return error from unregister and check that the dumper really is registered
* (Ingo Molnar): Maximise constness and correct array check
* (Ingo Molnar): Use _irqsave/_irqrestore also in kmsg_dump
* (Ingo Molnar): Style fixes
* (Anders Grafström): Correct kerneldoc names
include/linux/kmsg_dump.h | 36 ++++++++++++++ kernel/panic.c | 3 + kernel/printk.c | 116 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 155 insertions(+), 0 deletions(-) create mode 100644 include/linux/kmsg_dump.h
include/linux/kmsg_dump.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* linux/include/kmsg_dump.h +* +* Copyright (C) 2009 Net Insight AB +* +* Author: Simon Kagstrom <[email protected]> +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file COPYING in the main directory of this archive +* for more details. +*/ +#ifndef _LINUX_KMSG_DUMP_H +#define _LINUX_KMSG_DUMP_H + +#include <linux/list.h> + +enum kmsg_dump_reason { +KMSG_DUMP_OOPS , +KMSG_DUMP_PANIC , +}; + +struct kmsg_dumper { +void (*dump)(struct kmsg_dumper *dumper,enum kmsg_dump_reason reason, +const char *s1,unsigned long l1, +const char *s2,unsigned long l2); +struct list_head list; +int registered; +}; + +void kmsg_dump (enum kmsg_dump_reason reason); + +int kmsg_dump_register (struct kmsg_dumper *dumper); + +int kmsg_dump_unregister (struct kmsg_dumper *dumper); + +#endif /* _LINUX_DUMP_DEVICE_H */
kernel/panic.c +3 -0
@@ -10,6 +10,7 @@*/ #include <linux/debug_locks.h> #include <linux/interrupt.h> +#include <linux/kmsg_dump.h> #include <linux/kallsyms.h> #include <linux/notifier.h> #include <linux/module.h>
@@ -76,6 +77,7 @@ NORET_TYPE void panic(const char * fmt, ...)dump_stack ();#endif +kmsg_dump (KMSG_DUMP_PANIC );/* * If we have crashed and we have a crash kernel loaded let it handle * everything else.
@@ -341,6 +343,7 @@ void oops_exit(void) {do_oops_enter_exit ();print_oops_end_marker (); +kmsg_dump (KMSG_DUMP_OOPS ); }#ifdef WANT_WARN_ON_SLOWPATH
kernel/printk.c +116 -0
125 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Re: [PATCH v9 4/5] core: Add kernel message dumper to call on oopses and panics
* Simon Kagstrom <[email protected]> wrote:
/**
* kmsg_dump_register - register a kernel log dumper.
* @dump: pointer to the kmsg_dumper structure
*
* Adds a kernel log dumper to the system. The dump callback in the
* structure will be called when the kernel oopses or panics and must be
* set. Returns zero on success and -EINVAL or -EBUSY otherwise.
*/
Small detail - please use the KernelDoc style used in existing printk.c facilities, i.e. use a single space instead of a tab:
/**
* kmsg_dump_register - register a kernel log dumper.
* @dump: pointer to the kmsg_dumper structure
*
* Adds a kernel log dumper to the system. The dump callback in the
* structure will be called when the kernel oopses or panics and must be
* set. Returns zero on success and -EINVAL or -EBUSY otherwise. */
(in the other functions as well)
Ingo
Re: [PATCH v9 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 14 lines · Ingo Molnar
* Simon Kagstrom <[email protected]> wrote:
/**
*kmsg_dump_register- register a kernel log dumper.
* @dump: pointer to thekmsg_dumperstructure
*
* Adds a kernel log dumper to the system. The dump callback in the
* structure will be called when the kernel oopses or panics and must be
* set. Returns zero on success and-EINVALor-EBUSYotherwise.
*/Small detail - please use the KernelDoc style used in existing
printk.cfacilities, i.e. use a single space instead of a tab:
Quoted 8 lines
/**
*kmsg_dump_register- register a kernel log dumper.
* @dump: pointer to thekmsg_dumperstructure
*
* Adds a kernel log dumper to the system. The dump callback in the
* structure will be called when the kernel oopses or panics and must be
* set. Returns zero on success and-EINVALor-EBUSYotherwise. */
And then %-EINVAL and %-EBUSY.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
PATCH v10 4/5 core: Add kernel message dumper to call on oopses and panics
The core functionality is implemented as per Linus suggestion from
http://lists.infradead.org/pipermail/linux-mtd/2009-October/027620.html
(with the kmsg_dump implementation by Linus). A struct kmsg_dumper has been added which contains a callback to dump the kernel log buffers on crashes. The kmsg_dump function gets called from oops_exit() and panic() and invokes this callbacks with the crash reason.
---
ChangeLog:
* (Ingo Molnar): tabs->spaces in KernelDoc comments
* (Artem Bityutskiy): %-EINVAL
* (me): Add KernelDoc for the structure as well
include/linux/kmsg_dump.h | 44 +++++++++++++++++ kernel/panic.c | 3 + kernel/printk.c | 117 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 0 deletions(-) create mode 100644 include/linux/kmsg_dump.h
include/linux/kmsg_dump.h new file +44 -0
@@ -0,0 +1,44 @@ +/* +* linux/include/kmsg_dump.h +* +* Copyright (C) 2009 Net Insight AB +* +* Author: Simon Kagstrom <[email protected]> +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file COPYING in the main directory of this archive +* for more details. +*/ +#ifndef _LINUX_KMSG_DUMP_H +#define _LINUX_KMSG_DUMP_H + +#include <linux/list.h> + +enum kmsg_dump_reason { +KMSG_DUMP_OOPS , +KMSG_DUMP_PANIC , +}; + +/** +* struct kmsg_dumper - kernel crash message dumper structure +* @dump: The callback which gets called on crashes. The buffer is passed +* as two sections, where s1 (length l1) contains the older +* messages and s2 (length l2) contains the newer. +* @list: Entry in the dumper list (private) +* @registered: Flag that specifies if this is already registered +*/ +struct kmsg_dumper { +void (*dump)(struct kmsg_dumper *dumper,enum kmsg_dump_reason reason, +const char *s1,unsigned long l1, +const char *s2,unsigned long l2); +struct list_head list; +int registered; +}; + +void kmsg_dump (enum kmsg_dump_reason reason); + +int kmsg_dump_register (struct kmsg_dumper *dumper); + +int kmsg_dump_unregister (struct kmsg_dumper *dumper); + +#endif /* _LINUX_DUMP_DEVICE_H */
kernel/panic.c +3 -0
@@ -10,6 +10,7 @@*/ #include <linux/debug_locks.h> #include <linux/interrupt.h> +#include <linux/kmsg_dump.h> #include <linux/kallsyms.h> #include <linux/notifier.h> #include <linux/module.h>
@@ -76,6 +77,7 @@ NORET_TYPE void panic(const char * fmt, ...)dump_stack ();#endif +kmsg_dump (KMSG_DUMP_PANIC );/* * If we have crashed and we have a crash kernel loaded let it handle * everything else.
@@ -341,6 +343,7 @@ void oops_exit(void) {do_oops_enter_exit ();print_oops_end_marker (); +kmsg_dump (KMSG_DUMP_OOPS ); }#ifdef WANT_WARN_ON_SLOWPATH
kernel/printk.c +117 -0
126 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Re: [PATCH v10 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 14 lines · Simon Kagstrom
kernel/printk.c +14
-0+int kmsg_dump_register (struct kmsg_dumper *dumper) +{ +unsigned long flags; + +/* The dump callback needs to be set */ +if (!dumper->dump) +return -EINVAL ; + +spin_lock_irqsave (&dump_list_lock, flags); + +/* Don't allow registering multiple times */ +if (dumper->registered) { +spin_unlock_irqrestore (&dump_list_lock, flags); +
kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1444
Quoted 10 lines
kernel/printk.c +10
-0+return -EBUSY ; + } + + dumper->registered =1 ; +list_add (&dumper->list, &dump_list); +spin_unlock_irqrestore (&dump_list_lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (kmsg_dump_register);
i dont want to bikeshed paint this but this sequence caught my eyes. We generally do flatter and clearer locking sequences:
int kmsg_dump_register(struct kmsg_dumper *dumper)
{
unsigned long flags;
int err = -EBUSY;
/* The dump callback needs to be set */
if (!dumper->dump)
return -EINVAL;
spin_lock_irqsave(&dump_list_lock, flags);
/* Don't allow registering multiple times */
if (!dumper->registered) {
dumper->registered = 1;
list_add_tail(&dumper->list, &dump_list);
err = 0;
}
spin_unlock_irqrestore(&dump_list_lock, flags);
return err;
}EXPORT_SYMBOL_GPL(kmsg_dump_register);
(warning: untested, written in mail editor)
Same goes for kmsg_dump_unregister().
Ingo
Re: [PATCH v10 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 53 lines · Ingo Molnar
Quoted 14 lines · Simon Kagstrom
kernel/printk.c +14
-0+int kmsg_dump_register (struct kmsg_dumper *dumper) +{ +unsigned long flags; + +/* The dump callback needs to be set */ +if (!dumper->dump) +return -EINVAL ; + +spin_lock_irqsave (&dump_list_lock, flags); + +/* Don't allow registering multiple times */ +if (dumper->registered) { +spin_unlock_irqrestore (&dump_list_lock, flags); +kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1444
Quoted 10 lines
kernel/printk.c +10
-0+return -EBUSY ; + } + + dumper->registered =1 ; +list_add (&dumper->list, &dump_list); +spin_unlock_irqrestore (&dump_list_lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (kmsg_dump_register);i dont want to bikeshed paint this but this sequence caught my eyes. We generally do flatter and clearer locking sequences:
int
kmsg_dump_register(struct kmsg_dumper *dumper){ unsigned long flags; int err = -EBUSY; /* The dump callback needs to be set */ if (!dumper->dump) return -EINVAL; spin_lock_irqsave(&dump_list_lock, flags); /* Don't allow registering multiple times */ if (!dumper->registered) { dumper->registered = 1; list_add_tail(&dumper->list, &dump_list); err = 0; } spin_unlock_irqrestore(&dump_list_lock, flags); return err; }
Quoted 1 line
EXPORT_SYMBOL_GPL(kmsg_dump_register);
And while we are on it, I think these extra lines before and after spinlocks are unneeded and even a bit annoying :-)
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v10 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 50 lines · Artem Bityutskiy
Quoted 49 lines · Ingo Molnar
Quoted 14 lines · Simon Kagstrom
kernel/printk.c +14
-0+int kmsg_dump_register (struct kmsg_dumper *dumper) +{ +unsigned long flags; + +/* The dump callback needs to be set */ +if (!dumper->dump) +return -EINVAL ; + +spin_lock_irqsave (&dump_list_lock, flags); + +/* Don't allow registering multiple times */ +if (dumper->registered) { +spin_unlock_irqrestore (&dump_list_lock, flags); +kernel/printk.c bool printk_timed_ratelimit(unsigned long *caller_jiffies, · line 1444
Quoted 10 lines
kernel/printk.c +10
-0+return -EBUSY ; + } + + dumper->registered =1 ; +list_add (&dumper->list, &dump_list); +spin_unlock_irqrestore (&dump_list_lock, flags); + +return 0 ; +} +EXPORT_SYMBOL_GPL (kmsg_dump_register);i dont want to bikeshed paint this but this sequence caught my eyes. We generally do flatter and clearer locking sequences:
int
kmsg_dump_register(struct kmsg_dumper *dumper){ unsigned long flags; int err = -EBUSY; /* The dump callback needs to be set */ if (!dumper->dump) return -EINVAL; spin_lock_irqsave(&dump_list_lock, flags); /* Don't allow registering multiple times */ if (!dumper->registered) { dumper->registered = 1; list_add_tail(&dumper->list, &dump_list); err = 0; }
Quoted 8 lines
Quoted 5 lines
spin_unlock_irqrestore(&dump_list_lock, flags); return err; }
EXPORT_SYMBOL_GPL(kmsg_dump_register);And while we are on it, I think these extra lines before and after spinlocks are unneeded and even a bit annoying :-)
To me they increase readability quite a bit as it allows me to concentrate on just the inner critical section without the distraction of the lock/unlock sequence. YMMV.
Ingo
PATCH v11 4/5 core: Add kernel message dumper to call on oopses and panics
In reply to Ingo MolnarThe core functionality is implemented as per Linus suggestion from
http://lists.infradead.org/pipermail/linux-mtd/2009-October/027620.html
(with the kmsg_dump implementation by Linus). A struct kmsg_dumper has been added which contains a callback to dump the kernel log buffers on crashes. The kmsg_dump function gets called from oops_exit() and panic() and invokes this callbacks with the crash reason.
---
The bikeshed paint is drying:
ChangeLog:
* (Ingo Molnar): Flatten lock use
* (Artem, Aaro): Fix style issues
include/linux/kmsg_dump.h | 44 ++++++++++++++++++ kernel/panic.c | 3 + kernel/printk.c | 112 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 include/linux/kmsg_dump.h
include/linux/kmsg_dump.h new file +44 -0
@@ -0,0 +1,44 @@ +/* +* linux/include/kmsg_dump.h +* +* Copyright (C) 2009 Net Insight AB +* +* Author: Simon Kagstrom <[email protected]> +* +* This file is subject to the terms and conditions of the GNU General Public +* License. See the file COPYING in the main directory of this archive +* for more details. +*/ +#ifndef _LINUX_KMSG_DUMP_H +#define _LINUX_KMSG_DUMP_H + +#include <linux/list.h> + +enum kmsg_dump_reason { +KMSG_DUMP_OOPS , +KMSG_DUMP_PANIC , +}; + +/** +* struct kmsg_dumper - kernel crash message dumper structure +* @dump: The callback which gets called on crashes. The buffer is passed +* as two sections, where s1 (length l1) contains the older +* messages and s2 (length l2) contains the newer. +* @list: Entry in the dumper list (private) +* @registered: Flag that specifies if this is already registered +*/ +struct kmsg_dumper { +void (*dump)(struct kmsg_dumper *dumper,enum kmsg_dump_reason reason, +const char *s1,unsigned long l1, +const char *s2,unsigned long l2); +struct list_head list; +int registered; +}; + +void kmsg_dump (enum kmsg_dump_reason reason); + +int kmsg_dump_register (struct kmsg_dumper *dumper); + +int kmsg_dump_unregister (struct kmsg_dumper *dumper); + +#endif /* _LINUX_KMSG_DUMP_H */
kernel/panic.c +3 -0
@@ -10,6 +10,7 @@*/ #include <linux/debug_locks.h> #include <linux/interrupt.h> +#include <linux/kmsg_dump.h> #include <linux/kallsyms.h> #include <linux/notifier.h> #include <linux/module.h>
@@ -76,6 +77,7 @@ NORET_TYPE void panic(const char * fmt, ...)dump_stack ();#endif +kmsg_dump (KMSG_DUMP_PANIC );/* * If we have crashed and we have a crash kernel loaded let it handle * everything else.
@@ -341,6 +343,7 @@ void oops_exit(void) {do_oops_enter_exit ();print_oops_end_marker (); +kmsg_dump (KMSG_DUMP_OOPS ); }#ifdef WANT_WARN_ON_SLOWPATH
kernel/printk.c +112 -0
121 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 19 lines · Simon Kagstrom
The core functionality is implemented as per Linus suggestion from
http://lists.infradead.org/pipermail/linux-mtd/2009-October/027620.html
(with the
kmsg_dumpimplementation by Linus). A structkmsg_dumperhas been added which contains a callback to dump the kernel log buffers on crashes. Thekmsg_dumpfunction gets called fromoops_exit()andpanic()and invokes this callbacks with the crash reason.Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>Reviewed-by Ingo Molnar <[email protected]>---
The bikeshed paint is drying:ChangeLog:
* (Ingo Molnar): Flatten lock use
* (Artem, Aaro): Fix style issues
Quoted 5 lines
include/linux/kmsg_dump.h | 44 ++++++++++++++++++ kernel/panic.c | 3 + kernel/printk.c | 112 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 include/linux/kmsg_dump.h
I wonder, via which tree this should go in. We are going to have mtdoops depend on this. Should we go one of these ways:
* this patch goes to one of Ingo's tip trees, so we can pull it and work on top.
* we have Ingo's / Linus' acks, and this goes via the MTD tree.
?
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 26 lines · Artem Bityutskiy
Quoted 19 lines · Simon Kagstrom
The core functionality is implemented as per Linus suggestion from
http://lists.infradead.org/pipermail/linux-mtd/2009-October/027620.html
(with the
kmsg_dumpimplementation by Linus). A structkmsg_dumperhas been added which contains a callback to dump the kernel log buffers on crashes. Thekmsg_dumpfunction gets called fromoops_exit()andpanic()and invokes this callbacks with the crash reason.Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>Reviewed-by Ingo Molnar <[email protected]>---
The bikeshed paint is drying:ChangeLog:
* (Ingo Molnar): Flatten lock use
* (Artem, Aaro): Fix style issuesQuoted 5 lines
include/linux/kmsg_dump.h | 44 ++++++++++++++++++ kernel/panic.c | 3 + kernel/printk.c | 112 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+), 0 deletions(-) create mode 100644 include/linux/kmsg_dump.h
Quoted 7 lines
I wonder, via which tree this should go in. We are going to have mtdoops depend on this. Should we go one of these ways:
* this patch goes to one of Ingo's tip trees, so we can pull it and work on top.
* we have Ingo's / Linus' acks, and this goes via the MTD tree.
?
Either way is good to me. Linus, do you have any preferences?
Ingo
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 10 lines · Ingo Molnar
Quoted 8 lines
I wonder, via which tree this should go in. We are going to have mtdoops depend on this. Should we go one of these ways:
* this patch goes to one of Ingo's tip trees, so we can pull it and work on top.
* we have Ingo's / Linus' acks, and this goes via the MTD tree.
?Either way is good to me. Linus, do you have any preferences?
Either works for me.
Linus
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 11 lines · On Thu, 22 Oct 2009 08:33:11 +0900 (JST) Linus Torvalds…
Quoted 9 lines
Quoted 7 lines
I wonder, via which tree this should go in. We are going to have mtdoops depend on this. Should we go one of these ways:
* this patch goes to one of Ingo's tip trees, so we can pull it and work on top.
* we have Ingo's / Linus' acks, and this goes via the MTD tree.
?Either way is good to me. Linus, do you have any preferences?
Either works for me.
I would put it all through Artems MTD tree then so that we keep the new API and the user of it close together then.
Thanks to everyone for the reviewing and suggestions!
// Simon
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 11 lines · Simon Kagstrom
Quoted 8 lines · On Thu, 22 Oct 2009 08:33:11 +0900 (JST) Linus Torvalds…
Quoted 8 lines
Quoted 7 lines
I wonder, via which tree this should go in. We are going to have mtdoops depend on this. Should we go one of these ways:
* this patch goes to one of Ingo's tip trees, so we can pull it and work on top.
* we have Ingo's / Linus' acks, and this goes via the MTD tree.
?
Quoted 9 lines
Quoted 3 lines
Quoted 1 line
Either way is good to me. Linus, do you have any preferences?
Either works for me.
I would put it all through Artems MTD tree then so that we keep the new API and the user of it close together then.
Thanks to everyone for the reviewing and suggestions!
It's dwmw2's tree actually. I just act as his secretary :-)
David, could you push this patch to your tree? Ingo's and Linus' acks are there, AFAIU.
Simon, I'll look at your other mtdoops patches as well a bit later.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
(Removing some people from Cc:)
Quoted 7 lines · On Thu, 22 Oct 2009 09:36:08 +0300 Artem Bityutskiy <[email protected]> wrote:
Quoted 2 lines
I would put it all through Artems MTD tree then so that we keep the new API and the user of it close together then.
It's dwmw2's tree actually. I just act as his secretary :-)
David, could you push this patch to your tree? Ingo's and Linus' acks are there, AFAIU.
I know it's Davids tree :-)
I just thought it would be a good idea to keep everything together through your tree first before asking David to merge it.
But it's better to take in only the core patch first as you suggest.
// Simon
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 12 lines · Simon Kagstrom
(Removing some people from Cc:)
Quoted 7 lines · On Thu, 22 Oct 2009 09:36:08 +0300 Artem Bityutskiy <[email protected]> wrote:
Quoted 2 lines
I would put it all through Artems MTD tree then so that we keep the new API and the user of it close together then.
It's dwmw2's tree actually. I just act as his secretary :-)
David, could you push this patch to your tree? Ingo's and Linus' acks are there, AFAIU.
Quoted 7 lines
I know it's Davids tree :-)
I just thought it would be a good idea to keep everything together through your tree first before asking David to merge it.
But it's better to take in only the core patch first as you suggest.
Well, let's wait for what dwmw2 does. But for now I just put this patch to my l2 tree.
FYI, I never meant to have this tree for developers, so I always rebased it. Can you leave with this? Or you want me to create a branch which I won't re-base?
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 6 lines · On Thu, 22 Oct 2009 11:52:56 +0300 Artem Bityutskiy <[email protected]> wrote:
Well, let's wait for what dwmw2 does. But for now I just put this patch to my l2 tree.
FYI, I never meant to have this tree for developers, so I always rebased it. Can you leave with this? Or you want me to create a branch which I won't re-base?
I'm fine with having it rebased.
Thanks,
// Simon
Ingo Molnar
Acked-byRe: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
In reply to Artem BityutskiyQuoted 19 lines · Artem Bityutskiy
Quoted 18 lines · Simon Kagstrom
Quoted 11 lines · On Thu, 22 Oct 2009 08:33:11 +0900 (JST) Linus Torvalds…
Quoted 9 lines
Quoted 7 lines
I wonder, via which tree this should go in. We are going to have mtdoops depend on this. Should we go one of these ways:
* this patch goes to one of Ingo's tip trees, so we can pull it and work on top.
* we have Ingo's / Linus' acks, and this goes via the MTD tree.
?Either way is good to me. Linus, do you have any preferences?
Either works for me.
I would put it all through Artems MTD tree then so that we keep the new API and the user of it close together then.
Quoted 7 lines
Quoted 2 lines
Thanks to everyone for the reviewing and suggestions!
It's dwmw2's tree actually. I just act as his secretary :-)
David, could you push this patch to your tree? Ingo's and Linus' acks are there, AFAIU.
Yeah, the latest bits also have my:
Ingo
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
In reply to Simon KagstromHi all,
Quoted 2 lines · ext Simon Kagstrom
Thanks to everyone for the reviewing and suggestions!
I have a couple of questions:
1. If somebody writes a module that uses dumper for uploading the oopses/panics logs via some pay-per-byte medium, since he has no way to know in a module if the panic_on_oops flag is set, he'll have to upload both oops and the following panic, because he does not know for sure that the panic was caused by the oops. Hence he pays twice for the same information, right?
I can think of a couple of way to figure it out in the module itself, but I could not think of any clean way to do it.
2. We tried to use panic notifiers mechanism to print additional information that we want to see in mtdoops logs and it worked well, but having the kmsg_dump(KMSG_DUMP_PANIC) before the atomic_notifier_call_chain() breaks this functionality. Can we the call kmsg_dump() after the notifiers had been invoked?
Thanks,
Atal.
Quoted 6 lines
// Simon
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 7 lines · Shargorodsky Atal (EXT-Teleca/Helsinki)
Hi all,
Quoted 2 lines · ext Simon Kagstrom
Thanks to everyone for the reviewing and suggestions!
Quoted 8 lines
I have a couple of questions:
1. If somebody writes a module that uses dumper for uploading the oopses/panics logs via some pay-per-byte medium, since he has no way to know in a module if the
panic_on_oopsflag is set, he'll have to upload both oops and the following panic, because he does not know for sure that the panic was caused by the oops. Hence he pays twice for the same information, right?
Looks like a valid point to me. Indeed, in this case we will first call 'kmsg_dump(KMSG_DUMP_OOPS)' from 'oops_exit()', and then call it from 'panic()'. And the dumper may dump the same information, which is not nice.
I've looked briefly and tried to figure out how to fix this. But I cannot find an clean way. And I was confused by the die/oops/etc code. My question is, why the code does not work the following way instead?
arch/x86/kernel/dumpstack.c +2 -3
@@ -235,13 +235,12 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)raw_local_irq_restore (flags);oops_exit (); -if (!signr) -return ;if (in_interrupt ())panic ("Fatal exception in interrupt" );if (panic_on_oops)panic ("Fatal exception" ); -do_exit (signr); +if (signr) +do_exit (signr); }int __kprobes __die (const char *str,struct pt_regs *regs,long err)
If the code worked like this, I think the problem indicated by Atal could be easily fixed.
Quoted 5 lines
2. We tried to use panic notifiers mechanism to print additional information that we want to see in mtdoops logs and it worked well, but having the
kmsg_dump(KMSG_DUMP_PANIC)before theatomic_notifier_call_chain()breaks this functionality. Can we the callkmsg_dump()after the notifiers had been invoked?
Atal, I think you should just attach your patch, it is easier to express what you mean.
But for me it looks like atomic_notifier_call_chain() can be moved up.
Anyway, please, show your patch.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 48 lines · Artem Bityutskiy
Quoted 7 lines · Shargorodsky Atal (EXT-Teleca/Helsinki)
Hi all,
Quoted 2 lines · ext Simon Kagstrom
Thanks to everyone for the reviewing and suggestions!
Quoted 8 lines
I have a couple of questions:
1. If somebody writes a module that uses dumper for uploading the oopses/panics logs via some pay-per-byte medium, since he has no way to know in a module if the
panic_on_oopsflag is set, he'll have to upload both oops and the following panic, because he does not know for sure that the panic was caused by the oops. Hence he pays twice for the same information, right?Looks like a valid point to me. Indeed, in this case we will first call '
kmsg_dump(KMSG_DUMP_OOPS)' from 'oops_exit()', and then call it from 'panic()'. And the dumper may dump the same information, which is not nice.I've looked briefly and tried to figure out how to fix this. But I cannot find an clean way. And I was confused by the die/oops/etc code. My question is, why the code does not work the following way instead?
arch/x86/kernel/dumpstack.c +2
-3@@ -235,13 +235,12 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)raw_local_irq_restore (flags);oops_exit (); -if (!signr) -return ;if (in_interrupt ())panic ("Fatal exception in interrupt" );if (panic_on_oops)panic ("Fatal exception" ); -do_exit (signr); +if (signr) +do_exit (signr); }int __kprobes __die (const char *str,struct pt_regs *regs,long err)
Quoted 3 lines
If the code worked like this, I think the problem indicated by Atal could be easily fixed.
Could as well be, but will not help us much on arch/arm. :)
Quoted 6 lines
Quoted 5 lines
2. We tried to use panic notifiers mechanism to print additional information that we want to see in mtdoops logs and it worked well, but having the
kmsg_dump(KMSG_DUMP_PANIC)before theatomic_notifier_call_chain()breaks this functionality. Can we the callkmsg_dump()after the notifiers had been invoked?
Quoted 7 lines
Atal, I think you should just attach your patch, it is easier to express what you mean.
But for me it looks like
atomic_notifier_call_chain()can be moved up.Anyway, please, show your patch.
Inlined:
Quoted 1 line
From
12343c0918853f326b042c6e285b0e184565564fMon Sep 17 00:00:00 2001
Message-Id:
<12343c0918853f326b042c6e285b0e184565564f.1256223642.git.ext-atal.shargorodsky@nokia.com>
From: Atal Shargorodsky <[email protected]>
Date: Fri, 2 Oct 2009 17:34:56 +0300
Subject: [PATCH 1/3] debug: introduction of panic info buffer module
The feature of having an option for application to add some data to be printed at panic could be useful for debugging systems where the hardware, the kernel, the firmware for supplementary chips, etc. are under constant development and kernel version does not identify the exact setup in which the panic occurred.
The way to supply the string is to write it to debugfs file named panic_info_buff. Currently the buffer length is limited to 1KB - 1B.
--- drivers/misc/panic_info_buff.c | 92 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 92 insertions(+), 0 deletions(-) create mode 100644 drivers/misc/panic_info_buff.c
(quoted diff) +0 -0
b/drivers/misc/panic_info_buff.c
new file mode 100644
index 0000000..fa6d2b1
drivers/misc/panic_info_buff.c new file +16 -0
@@ -0,0 +1,92 @@ +/* +* Copyright (C) Nokia Corporation +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/uaccess.h>
+#include <linux/debugfs.h>
+#include <linux/notifier.h>
+
+#define PANIC_BUFFER_MAX_LEN 1024
+static char panic_info_buff[PANIC_BUFFER_MAX_LEN];
+static struct dentry *panic_info_buff_debugfs;
+
+static int panic_info_buff_open(struct inode *inode, struct file *file) +{
+ return 0;
+}
+
+static ssize_t panic_info_buff_write(struct file *file,
+ const char __user *buf, size_t len, loff_t *off)
+{
+ if (len >= PANIC_BUFFER_MAX_LEN)
+ return -EINVAL;
+ if (copy_from_user(panic_info_buff, buf, len))
+ return -EFAULT;
+ panic_info_buff[len] = '\0';
+ return len;
+}
+
+static struct file_operations panic_info_buff_fops = {
+ .open = panic_info_buff_open,
+ .write = panic_info_buff_write,
+ .llseek = no_llseek,
+ .owner = THIS_MODULE,
+};
+
+static int panic_info_buff_event(struct notifier_block *this,
+ unsigned long event, void *ptr)
+{
+ if (panic_info_buff[0] == '\0')
+ printk(KERN_EMERG "Panic info buffer is empty.\n");
+ else
+ printk(KERN_EMERG "Panic info buffer:\n"
+ "%s\nBuffer total length: %d characters.\n",
+ panic_info_buff,
+ strlen(panic_info_buff));
+ return NOTIFY_OK;
+}
+
+static struct notifier_block panic_info_buff_block = {
+ .notifier_call = panic_info_buff_event,
+ .priority = 1,
+};
+
+static int __devinit panic_info_buff_init(void)
+{
+ panic_info_buff_debugfs = debugfs_create_file("panic_info_buff",
+ S_IFREG | S_IWUSR | S_IWGRP,
+ NULL, NULL, &panic_info_buff_fops);
+ atomic_notifier_chain_register(&panic_notifier_list,
+ &panic_info_buff_block);
+ return 0;
+}
+module_init(panic_info_buff_init);
+
+static void __devexit panic_info_buff_exit(void)
+{
+ debugfs_remove(panic_info_buff_debugfs);
+ atomic_notifier_chain_unregister(&panic_notifier_list,
+ &panic_info_buff_block);
+
+}
+module_exit(panic_info_buff_exit);
+
+MODULE_AUTHOR("Nokia Corporation");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("panic_info_buff");
Signature · 1 line
1.5.4.3
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
In reply to Shargorodsky Atal (EXT-Teleca/Helsinki)Quoted 9 lines · On Fri, 23 Oct 2009 18:53:22 +0300 "Shargorodsky Atal (EXT-Teleca/Helsinki)"…
1. If somebody writes a module that uses dumper for uploading the oopses/panics logs via some pay-per-byte medium, since he has no way to know in a module if the
panic_on_oopsflag is set, he'll have to upload both oops and the following panic, because he does not know for sure that the panic was caused by the oops. Hence he pays twice for the same information, right?I can think of a couple of way to figure it out in the module itself, but I could not think of any clean way to do it.
This is correct, and the mtdoops driver has some provisions to handle this. First, there is a parameter to the module to specify whether oopses should be dumped at all - I added this for the particular case that someone has panic_on_oops set.
Second, it does not dump oopses directly anyway, but puts it in a work queue. That way, if panic_on_oops is set, it will store the panic but the oops (called from the workqueue) will not get written anyway.
Quoted 5 lines
2. We tried to use panic notifiers mechanism to print additional information that we want to see in mtdoops logs and it worked well, but having the
kmsg_dump(KMSG_DUMP_PANIC)before theatomic_notifier_call_chain()breaks this functionality. Can we the callkmsg_dump()after the notifiers had been invoked?
Well, it depends I think. The code currently looks like this:
kmsg_dump(KMSG_DUMP_PANIC); /* * If we have crashed and we have a crash kernel loaded let it handle * everything else. * Do we want to call this before we try to display a message? */ crash_kexec(NULL); [... Comments removed] atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
And moving kdump_msg() after crash_kexec() will make us miss the message if we have a kexec crash kernel as well. I realise that these two approaches might be complementary and are not likely to be used at the same time, but it's still something to think about.
Then again, maybe it's possible to move the panic notifiers above crash_kexec() as well, which would solve things nicely.
// Simon
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 10 lines · ext Simon Kagstrom
Quoted 7 lines · On Fri, 23 Oct 2009 18:53:22 +0300 "Shargorodsky Atal (EXT-Teleca/Helsinki)"…
1. If somebody writes a module that uses dumper for uploading the oopses/panics logs via some pay-per-byte medium, since he has no way to know in a module if the
panic_on_oopsflag is set, he'll have to upload both oops and the following panic, because he does not know for sure that the panic was caused by the oops. Hence he pays twice for the same information, right?
Quoted 8 lines
Quoted 2 lines
I can think of a couple of way to figure it out in the module itself, but I could not think of any clean way to do it.
This is correct, and the mtdoops driver has some provisions to handle this. First, there is a parameter to the module to specify whether oopses should be dumped at all - I added this for the particular case that someone has
panic_on_oopsset.
It takes care of most of the situations, but panic_on_oops can be changed any time, even after the module is loaded.
While I think that exporting oops_on_panic is a wrong thing to do, I believe that dumpers differ a bit from the rest of the modules in that aspect and should be at least hinted about this flag setting. Does it not make sense?
Quoted 4 lines
Second, it does not dump oopses directly anyway, but puts it in a work queue. That way, if
panic_on_oopsis set, it will store the panic but the oops (called from the workqueue) will not get written anyway.
AFAIK, mtdoops does not put oopses in a work queue. And if by any chance it does, then I think it's wrong and might lead to missed oopses, as the oops might be because of the work queues themselves, or it might look to the kernel like some non-fatal fault, but actually it's a sign of a much more catastrophic failure - IOMMU device garbaging memory, for instance.
But anyway, I was not talking about mtdoops. In fact, I was not talking about any particular module, I just described some situation which looks a bit problematic to me.
Quoted 18 lines
Quoted 5 lines
2. We tried to use panic notifiers mechanism to print additional information that we want to see in mtdoops logs and it worked well, but having the
kmsg_dump(KMSG_DUMP_PANIC)before theatomic_notifier_call_chain()breaks this functionality. Can we the callkmsg_dump()after the notifiers had been invoked?Well, it depends I think. The code currently looks like this:
kmsg_dump(KMSG_DUMP_PANIC); /* * If we have crashed and we have a crash kernel loaded let it handle * everything else. * Do we want to call this before we try to display a message? */ crash_kexec(NULL); [... Comments removed] atomic_notifier_call_chain(&panic_notifier_list, 0, buf);
Quoted 8 lines
And moving
kdump_msg()aftercrash_kexec()will make us miss the message if we have a kexec crash kernel as well. I realise that these two approaches might be complementary and are not likely to be used at the same time, but it's still something to think about.Then again, maybe it's possible to move the panic notifiers above
crash_kexec()as well, which would solve things nicely.
Which leaves me no choice but just ask the question, as it bothering me for some time: does anybody know why we try to crash_kexec() at so early stage?
Quoted 1 line
// Simon
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 10 lines · On Mon, 26 Oct 2009 12:36:33 +0200 "Shargorodsky Atal (EXT-Teleca/Helsinki)"…
Quoted 7 lines
Quoted 2 lines
I can think of a couple of way to figure it out in the module itself, but I could not think of any clean way to do it.
This is correct, and the mtdoops driver has some provisions to handle this. First, there is a parameter to the module to specify whether oopses should be dumped at all - I added this for the particular case that someone has
panic_on_oopsset.It takes care of most of the situations, but
panic_on_oopscan be changed any time, even after the module is loaded.
Yes, but this parameter is settable at runtime as well by writing to /sys/module/mtdoops/parameters/dump_oops.
Quoted 11 lines
Quoted 4 lines
Second, it does not dump oopses directly anyway, but puts it in a work queue. That way, if
panic_on_oopsis set, it will store the panic but the oops (called from the workqueue) will not get written anyway.AFAIK, mtdoops does not put oopses in a work queue. And if by any chance it does, then I think it's wrong and might lead to missed oopses, as the oops might be because of the work queues themselves, or it might look to the kernel like some non-fatal fault, but actually it's a sign of a much more catastrophic failure - IOMMU device garbaging memory, for instance.
I was referring to my patches to it, sorry. It's in the patch "[PATCH v7 5/5]:
mtdoops: refactor as a kmsg_dumper" (as well as the parameter to dump oopses at all).
There are other situations which will make dumping problematic as well, e.g., crashes in the mtd code, so there are certainly some cases which will be difficult to catch. But in the panic_on_oops case or oops-in-interrupt, the oops won't be missed and won't be outputted twice for mtdoops.
Anyway, I understand your problem and agree that it would be good to fix. Moving up crash_kexec() and the notifiers will at least fix your second issue. For the double-output-of-oopses, I don't see a good way to fix it unless relying on the module to correct it like above.
// Simon
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 40 lines · ext Simon Kagstrom
Quoted 10 lines · On Mon, 26 Oct 2009 12:36:33 +0200 "Shargorodsky Atal (EXT-Teleca/Helsinki)"…
Quoted 7 lines
Quoted 2 lines
I can think of a couple of way to figure it out in the module itself, but I could not think of any clean way to do it.
This is correct, and the mtdoops driver has some provisions to handle this. First, there is a parameter to the module to specify whether oopses should be dumped at all - I added this for the particular case that someone has
panic_on_oopsset.It takes care of most of the situations, but
panic_on_oopscan be changed any time, even after the module is loaded.Yes, but this parameter is settable at runtime as well by writing to
/sys/module/mtdoops/parameters/dump_oops.Quoted 11 lines
Quoted 4 lines
Second, it does not dump oopses directly anyway, but puts it in a work queue. That way, if
panic_on_oopsis set, it will store the panic but the oops (called from the workqueue) will not get written anyway.AFAIK, mtdoops does not put oopses in a work queue. And if by any chance it does, then I think it's wrong and might lead to missed oopses, as the oops might be because of the work queues themselves, or it might look to the kernel like some non-fatal fault, but actually it's a sign of a much more catastrophic failure - IOMMU device garbaging memory, for instance.
I was referring to my patches to it, sorry. It's in the patch "[PATCH v7 5/5]:
mtdoops: refactor as akmsg_dumper" (as well as the parameter to dump oopses at all).There are other situations which will make dumping problematic as well, e.g., crashes in the mtd code, so there are certainly some cases which will be difficult to catch. But in the
panic_on_oopscase or oops-in-interrupt, the oops won't be missed and won't be outputted twice for mtdoops.
Quoted 5 lines
Anyway, I understand your problem and agree that it would be good to fix. Moving up
crash_kexec()and the notifiers will at least fix your second issue. For the double-output-of-oopses, I don't see a good way to fix it unless relying on the module to correct it like above.
How about adding KMSG_DUMP_LAST_OOPS_BEFORE_PANIC or something to the kmsg_dump_reason enum, and making the kmsg_dump look like kmsg_dump(panic_on_oops ? KMSG_DUMP_LAST_OOPS_BEFORE_PANIC : KMSG_DUMP_OOPS); in oops_exit. Then let the dumpers decide what they want to do about it. Just a thought.
And since you have no objections about moving notifiers up, it looks like the second issue will be resolved, I believe Artem will take care of it. :)
Thanks a lot,
Atal.
Quoted 1 line
// Simon
Re: [PATCH v11 4/5] core: Add kernel message dumper to call on oopses and panics
Quoted 5 lines · On Mon, 26 Oct 2009 17:13:27 +0200 "Shargorodsky Atal (EXT-Teleca/Helsinki)"…
How about adding
KMSG_DUMP_LAST_OOPS_BEFORE_PANICor something to thekmsg_dump_reasonenum, and making thekmsg_dumplook likekmsg_dump(panic_on_oops ? KMSG_DUMP_LAST_OOPS_BEFORE_PANIC : KMSG_DUMP_OOPS); inoops_exit. Then let the dumpers decide what they want to do about it. Just a thought.
It would also have to take in_interrupt() in account since that will also lead to a panic.
Quoted 3 lines
And since you have no objections about moving notifiers up, it looks like the second issue will be resolved, I believe Artem will take care of it. :)
Well, I have no objections to it, but I also know very little of the reasoning to put it there in the first place, so don't count my vote for very much here :-)
// Simon
Re: [PATCH v10 4/5] core: Add kernel message dumper to call on oopses and panics
In reply to Simon KagstromHello,
Quoted 23 lines · Simon Kagstrom
include/linux/kmsg_dump.h new file +23
-0+#ifndef _LINUX_KMSG_DUMP_H +#define _LINUX_KMSG_DUMP_H + +#include <linux/list.h> + +enum kmsg_dump_reason { + KMSG_DUMP_OOPS, + KMSG_DUMP_PANIC, +}; + +/** + * struct kmsg_dumper - kernel crash message dumper structure + * @dump: The callback which gets called on crashes. The buffer is passed + * as two sections, where s1 (length l1) contains the older + * messages and s2 (length l2) contains the newer. + * @list: Entry in the dumper list (private) + * @registered: Flag that specifies if this is already registered + */ +struct kmsg_dumper { + void (*dump)(struct kmsg_dumper *dumper, enum kmsg_dump_reason reason, + const char *s1, unsigned long l1, + const char *s2, unsigned long l2); + struct list_head list;
include/linux/kmsg_dump.h line 44
Quoted 10 lines
include/linux/kmsg_dump.h new file +10
-0+ int registered; +}; + +void kmsg_dump (enum kmsg_dump_reason reason); + +int kmsg_dump_register (struct kmsg_dumper *dumper); + +int kmsg_dump_unregister (struct kmsg_dumper *dumper); + +#endif /* _LINUX_DUMP_DEVICE_H */
If you still make a new version of the patch, please correct the "_LINUX_DUMP_DEVICE_H" comment.
A.
PATCH v7 5/5 : mtdoops: refactor as a kmsg_dumper
In reply to Simon KagstromThe last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the kmsg_dumper support instead of a console, which simplifies the code and also includes the messages before the oops started.
On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular mtd->write call), while panics call mtd->panic_write directly. Thus, if panic_on_oops is set, the oops will be written out during the panic.
A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
---
ChangeLog:
* (Vimal Singh) Correct Kconfig instructions on how to load the module
* Correct kfree of unallocated area
* More descriptive error message on wrong module parameters
* Rebase against new patch 4 (use container_of instead of private pointer)
drivers/mtd/Kconfig | 5 +- drivers/mtd/mtdoops.c | 211 ++++++++++++++++++++----------------------------- 2 files changed, 88 insertions(+), 128 deletions(-)
drivers/mtd/Kconfig +3 -2
@@ -312,8 +312,9 @@ config MTD_OOPS buffer in a flash partition where it can be read back at some later point. - To use, add console=ttyMTDx to the kernel command line, - where x is the MTD device number to use. + To use, add mtddev=name/number to the kernel command line, + where name/number is the name or number of the MTD device + to use (e.g., mtddev=7 for /dev/mtd7). source "drivers/mtd/chips/Kconfig"
drivers/mtd/mtdoops.c +85 -126
354 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH v8 5/5 : mtdoops: refactor as a kmsg_dumper
The last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the kmsg_dumper support instead of a console, which simplifies the code and also includes the messages before the oops started.
On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular mtd->write call), while panics call mtd->panic_write directly. Thus, if panic_on_oops is set, the oops will be written out during the panic.
A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
---
ChangeLog:
* Refactor against new version of patch 4
drivers/mtd/Kconfig | 5 +- drivers/mtd/mtdoops.c | 211 ++++++++++++++++++++----------------------------- 2 files changed, 88 insertions(+), 128 deletions(-)
drivers/mtd/Kconfig +3 -2
@@ -312,8 +312,9 @@ config MTD_OOPS buffer in a flash partition where it can be read back at some later point. - To use, add console=ttyMTDx to the kernel command line, - where x is the MTD device number to use. + To use, add mtddev=name/number to the kernel command line, + where name/number is the name or number of the MTD device + to use (e.g., mtddev=7 for /dev/mtd7). source "drivers/mtd/chips/Kconfig"
drivers/mtd/mtdoops.c +85 -126
354 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH v9 5/5 : mtdoops: refactor as a kmsg_dumper
The last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the kmsg_dumper support instead of a console, which simplifies the code and also includes the messages before the oops started.
On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular mtd->write call), while panics call mtd->panic_write directly. Thus, if panic_on_oops is set, the oops will be written out during the panic.
A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
---
ChangeLog:
* Rebase against new P4
* Check return values from kmsg_dump_register/unregister
drivers/mtd/Kconfig | 5 +- drivers/mtd/mtdoops.c | 219 +++++++++++++++++++++---------------------------- 2 files changed, 96 insertions(+), 128 deletions(-)
drivers/mtd/Kconfig +3 -2
@@ -312,8 +312,9 @@ config MTD_OOPS buffer in a flash partition where it can be read back at some later point. - To use, add console=ttyMTDx to the kernel command line, - where x is the MTD device number to use. + To use, add mtddev=name/number to the kernel command line, + where name/number is the name or number of the MTD device + to use (e.g., mtddev=7 for /dev/mtd7). source "drivers/mtd/chips/Kconfig"
drivers/mtd/mtdoops.c +93 -126
362 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Re: [PATCH v7 5/5]: mtdoops: refactor as a kmsg_dumper
In reply to Simon KagstromQuoted 25 lines · Simon Kagstrom
The last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the
kmsg_dumpersupport instead of a console, which simplifies the code and also includes the messages before the oops started.On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular
mtd->writecall), while panics callmtd->panic_writedirectly. Thus, ifpanic_on_oopsis set, the oops will be written out during the panic.A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>---
ChangeLog:
* (Vimal Singh) CorrectKconfiginstructions on how to load the module
* Correct kfree of unallocated area
* More descriptive error message on wrong module parameters
* Rebase against new patch 4 (usecontainer_ofinstead of private pointer)
Quoted 3 lines
drivers/mtd/Kconfig | 5 +- drivers/mtd/mtdoops.c | 211 ++++++++++++++++++++----------------------------- 2 files changed, 88 insertions(+), 128 deletions(-)
Looks good, thanks for doing this. Did you actually test this with oopses and panics, with and without panic_on_oops?
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v7 5/5]: mtdoops: refactor as a kmsg_dumper
Quoted 8 lines · On Fri, 23 Oct 2009 07:32:42 +0300 Artem Bityutskiy <[email protected]> wrote:
Quoted 4 lines · Simon Kagstrom
The last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the
kmsg_dumpersupport instead of a console, which simplifies the code and also includes the messages before the oops started.Looks good, thanks for doing this. Did you actually test this with oopses and panics, with and without
panic_on_oops?
Yes, I've tested it with the kinds of crashes I could think of on a device (OpenRD) with a NAND flash. It works well for all cases I've tested.
I wrote a small kernel module which registers a sysfs interface where you can crash or cause problems for the kernel in various ways to test this. If there is interest for it I could post it.
// Simon
Re: [PATCH v7 5/5]: mtdoops: refactor as a kmsg_dumper
In reply to Simon KagstromHmmm.
drivers/mtd/mtdoops.c static void find_next_position(struct mtdoops_context *cxt) · line 340
Quoted 9 lines · Simon Kagstrom
drivers/mtd/mtdoops.c +9
-0+/* Panics must be written immediately */ +if (reason == kmsg_dump_panic) { +if (!cxt->mtd->panic_write) +printk (KERN_ERR "mtdoops: Cannot write from panic without panic_write\n" ); +else +mtdoops_write (cxt,1 ); +return ; + } +
...replaces...
drivers/mtd/mtdoops.c static void mtdoops_notify_remove(struct mtd_info *mtd) · line 382
Quoted 6 lines
drivers/mtd/mtdoops.c +0
-6-if (mtd->panic_write && (in_interrupt () || panic_on_oops)) -/* Interrupt context, we're going to panic so try and log */ -mtdoops_write (cxt,1 ); -else -schedule_work (&cxt->work_write); -}
So in the case where the device driver doesn't provide a ->panic_oops() function, we now don't even bother with a best-effort attempt to dump; we just give up.
Would there be any harm in scheduling the work_write function _anyway_, just in case it manages to run?
The bug report at http://bugzilla.kernel.org/show_bug.cgi?id=14102 seems to be suggesting that sometimes it _did_ manage to work, with a bit of luck and a following wind.
Also, it looks like in the (in_interrupt() || panic_on_oops) case we end up calling kmsg_dump(KMSG_DUMP_OOPS) from oops_exit(), almost immediately followed by kmsg_dump(KMSG_DUMP_PANIC). Is that going to do the right thing?
Signature · 2 lines
David Woodhouse Open Source Technology Centre [email protected] Intel Corporation
Re: [PATCH v7 5/5]: mtdoops: refactor as a kmsg_dumper
Quoted 11 lines · On Wed, 06 Jan 2010 14:33:16 +0000 David Woodhouse <[email protected]> wrote:
drivers/mtd/mtdoops.c static void find_next_position(struct mtdoops_context *cxt) · line 338
Quoted 7 lines
drivers/mtd/mtdoops.c +7
-0+/* Panics must be written immediately */ +if (reason == kmsg_dump_panic) { +if (!cxt->mtd->panic_write) +printk (KERN_ERR "mtdoops: Cannot write from panic without panic_write\n" ); +else +mtdoops_write (cxt,1 ); +return ;Would there be any harm in scheduling the
work_writefunction _anyway_, just in case it manages to run?
Quoted 3 lines
The bug report at http://bugzilla.kernel.org/show_bug.cgi?id=14102 seems to be suggesting that sometimes it _did_ manage to work, with a bit of luck and a following wind.
In my tests, I never got it to write out anything when using scheduled work on panics. I did the tests on a uniprocessor though, maybe that could be a reason.
But you are right, probably it doesn't hurt anyway.
Quoted 4 lines
Also, it looks like in the (
in_interrupt()||panic_on_oops) case we end up callingkmsg_dump(KMSG_DUMP_OOPS)fromoops_exit(), almost immediately followed bykmsg_dump(KMSG_DUMP_PANIC). Is that going to do the right thing?
Well, since I never got it to dump anything with the work queue, the dump will be done when KMSG_DUMP_PANIC is called. The work queue never gets to run, so I never saw double dumps with this approach.
Anyway, perhaps one could do a cancel_work() when running the panic handler to avoid situations when both are written (since it apparently is possible as above).
// Simon
v12 cover : mtdoops: fixes and improvements
In reply to Simon KagstromHi again!
Here is another round of the mtdoops fixes for Artems tree. The patches are:
1. Keep track of mtdoops page cleanliness in an array. This allows mtdoops_inc_counter to be called during panic (which fails in my case with the current code in mtd->read, although I believe this is MTD-driver dependent).
2. Add a maximum MTD partition size for mtdoops.
3. Make page size configurable to support longer messages. Mainly needed for patch 4, but also allows longer messages to be stored during panics (when the next oops area cannot be erased).
4. Refactor mtdoops as a kmsg_dumper device instead of a console device.
Apart from the changelog in each patch, the patch that removes the always-erase-empty-areas has been dropped.
// Simon
PATCH v12 1/4 : mtdoops: Keep track of used/unused mtdoops pages in an array
This patch makes mtdoops keep track of used/unused pages in an array instead of scanning the flash after a write. The advantage with this approach is that it avoids calling mtd->read on a panic, which is not possible for all mtd drivers.
--- drivers/mtd/mtdoops.c | 62 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 44 insertions(+), 18 deletions(-)
drivers/mtd/mtdoops.c +44 -18
@@ -44,6 +44,7 @@ static struct mtdoops_context {int oops_pages;int nextpage;int nextcount; +unsigned long *oops_page_used;char *name;void *oops_buf;
@@ -54,18 +55,38 @@ static struct mtdoops_context {int writecount; } oops_cxt; +static void mark_page_used (struct mtdoops_context *cxt,int page) +{ +set_bit (page, cxt->oops_page_used); +} + +static void mark_page_unused (struct mtdoops_context *cxt,int page) +{ +clear_bit (page, cxt->oops_page_used); +} + +static int page_is_used (struct mtdoops_context *cxt,int page) +{ +return test_bit (page, cxt->oops_page_used); +} +static void mtdoops_erase_callback (struct erase_info *done) {wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;wake_up (wait_q); } -static int mtdoops_erase_block (struct mtd_info *mtd,int offset) +static int mtdoops_erase_block (struct mtdoops_context *cxt,int offset) { +struct mtd_info *mtd = cxt->mtd; +u32 start_page_offset =mtd_div_by_eb (offset, mtd) * mtd->erasesize; +u32 start_page = start_page_offset /OOPS_PAGE_SIZE ; +u32 erase_pages = mtd->erasesize /OOPS_PAGE_SIZE ;struct erase_info erase;DECLARE_WAITQUEUE (wait, current);wait_queue_head_t wait_q;int ret; +int page;init_waitqueue_head (&wait_q); erase.mtd = mtd;
@@ -90,16 +111,15 @@ static int mtdoops_erase_block(struct mtd_info *mtd, int offset)schedule ();/* Wait for erase to finish. */ remove_wait_queue (&wait_q, &wait); +/* Mark pages as unused */ +for (page = start_page; page < start_page + erase_pages; page++) +mark_page_unused (cxt, page); +return 0 ; }static void mtdoops_inc_counter (struct mtdoops_context *cxt) { -struct mtd_info *mtd = cxt->mtd; -size_t retlen; -u32 count; -int ret; - cxt->nextpage++;if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage =0 ;
@@ -107,17 +127,7 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt)if (cxt->nextcount ==0xffffffff ) cxt->nextcount =0 ; - ret = mtd->read (mtd, cxt->nextpage *OOPS_PAGE_SIZE ,4 , - &retlen, (u_char *) &count); -if (retlen !=4 || (ret <0 && ret != -EUCLEAN )) { -printk (KERN_ERR "mtdoops: read failure at %d (%td of 4 read), err %d\n" , - cxt->nextpage *OOPS_PAGE_SIZE , retlen, ret); -schedule_work (&cxt->work_erase); -return ; - } - -/* See if we need to erase the next block */ -if (count !=0xffffffff ) { +if (page_is_used (cxt, cxt->nextpage)) {schedule_work (&cxt->work_erase);return ; }
@@ -168,7 +178,7 @@ badblock: }for (j =0 , ret =-1 ; (j <3 ) && (ret <0 ); j++) - ret =mtdoops_erase_block (mtd, cxt->nextpage *OOPS_PAGE_SIZE ); + ret =mtdoops_erase_block (cxt, cxt->nextpage *OOPS_PAGE_SIZE );if (ret >=0 ) { printk(KERN_DEBUG "mtdoops: ready %d, %d\n",
@@ -209,6 +219,7 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)if (retlen !=OOPS_PAGE_SIZE || ret <0 )printk (KERN_ERR "mtdoops: write failure at %d (%td of %d written), error %d\n" , cxt->nextpage *OOPS_PAGE_SIZE , retlen,OOPS_PAGE_SIZE , ret); +mark_page_used (cxt, cxt->nextpage);mtdoops_inc_counter (cxt); }
@@ -230,6 +241,8 @@ static void find_next_position(struct mtdoops_context *cxt)size_t retlen;for (page =0 ; page < cxt->oops_pages; page++) { +/* Assume the page is used */ +mark_page_used (cxt, page); ret = mtd->read (mtd, page *OOPS_PAGE_SIZE ,8 , &retlen, (u_char *) &count[0 ]);if (retlen !=8 || (ret <0 && ret != -EUCLEAN )) { printk(KERN_ERR "mtdoops: read failure at %d (%td of 8 read), err %d\n",
@@ -237,6 +250,8 @@ static void find_next_position(struct mtdoops_context *cxt)continue ; } +if (count[0 ] ==0xffffffff && count[1 ] ==0xffffffff ) +mark_page_unused (cxt, page);if (count[1 ] !=MTDOOPS_KERNMSG_MAGIC )continue ;if (count[0 ] ==0xffffffff )
@@ -273,6 +288,9 @@ static void find_next_position(struct mtdoops_context *cxt)static void mtdoops_notify_add (struct mtd_info *mtd) {struct mtdoops_context *cxt = &oops_cxt; +u64 mtdoops_pages = mtd->size; + +do_div (mtdoops_pages,OOPS_PAGE_SIZE );if (cxt->name && !strcmp (mtd->name, cxt->name)) cxt->mtd_index = mtd->index;
@@ -292,6 +310,13 @@ static void mtdoops_notify_add(struct mtd_info *mtd)return ; } +/* oops_page_used is a bit field */ + cxt->oops_page_used =vmalloc (DIV_ROUND_UP (mtdoops_pages, +BITS_PER_LONG )); +if (!cxt->oops_page_used) { +printk (KERN_ERR "Could not allocate page array\n" ); +return ; + } cxt->mtd = mtd;if (mtd->size >INT_MAX ) cxt->oops_pages =INT_MAX /OOPS_PAGE_SIZE ;
@@ -444,6 +469,7 @@ static void __exit mtdoops_console_exit(void)unregister_console (&mtdoops_console);kfree (cxt->name);vfree (cxt->oops_buf); +vfree (cxt->oops_page_used); }
Signature · 1 line
1.6.0.4
Re: [PATCH v12 1/4]: mtdoops: Keep track of used/unused mtdoops pages in an array
Quoted 7 lines · Simon Kagstrom
This patch makes mtdoops keep track of used/unused pages in an array instead of scanning the flash after a write. The advantage with this approach is that it avoids calling
mtd->readon a panic, which is not possible for all mtd drivers.Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>
Pushed this one to my tree, thanks.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
PATCH v12 2/4 : mtdoops: Add a maximum MTD partition size
In reply to Simon KagstromA configurable maximum MTD partition size for mtdoops avoids mistakes where the user gives e.g., a rootfs partition to mtdoops (which will happily erase it).
--- drivers/mtd/Kconfig | 13 +++++++++++++ drivers/mtd/mtdoops.c | 11 +++++++---- 2 files changed, 20 insertions(+), 4 deletions(-)
drivers/mtd/Kconfig +13 -0
@@ -315,6 +315,19 @@ config MTD_OOPS To use, add console=ttyMTDx to the kernel command line, where x is the MTD device number to use. +config MTD_OOPS_MAX_MTD_SIZE + int "Maximum MTD oops partition size (kbytes)" + default 4096 + range 8 1048576 + depends on MTD_OOPS + help + This parameter sets the maximum MTD partition size for use with + MTD oops. The default value is used as a safeguard against using + e.g., a root filesystem partition as a MTDoops device (in which + case it will be erased). + + No need to change unless you have a very large MTDoops partition. + source "drivers/mtd/chips/Kconfig" source "drivers/mtd/maps/Kconfig"
drivers/mtd/mtdoops.c +7 -4
@@ -298,6 +298,12 @@ static void mtdoops_notify_add(struct mtd_info *mtd)if (mtd->index != cxt->mtd_index || cxt->mtd_index <0 )return ; +if (mtd->size >CONFIG_MTD_OOPS_MAX_MTD_SIZE *1024 ) { +printk (KERN_ERR "mtdoops: MTD partition %d too big for mtdoops (limit %d KiB)\n" , + mtd->index,CONFIG_MTD_OOPS_MAX_MTD_SIZE ); +return ; + } +if (mtd->size < mtd->erasesize *2 ) {printk (KERN_ERR "mtdoops: MTD partition %d not big enough for mtdoops\n" , mtd->index);
@@ -318,10 +324,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)return ; } cxt->mtd = mtd; -if (mtd->size >INT_MAX ) - cxt->oops_pages =INT_MAX /OOPS_PAGE_SIZE ; -else - cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ; + cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ;find_next_position (cxt);
Signature · 1 line
1.6.0.4
Re: [PATCH v12 2/4]: mtdoops: Add a maximum MTD partition size
Quoted 22 lines · Simon Kagstrom
A configurable maximum MTD partition size for mtdoops avoids mistakes where the user gives e.g., a rootfs partition to mtdoops (which will happily erase it).
Signed-off-by Simon Kagstrom <[email protected]>--- drivers/mtd/Kconfig | 13 +++++++++++++ drivers/mtd/mtdoops.c | 11 +++++++---- 2 files changed, 20 insertions(+), 4 deletions(-)drivers/mtd/Kconfig +4
-0@@ -315,6 +315,19 @@ config MTD_OOPS To use, add console=ttyMTDx to the kernel command line, where x is the MTD device number to use. +config MTD_OOPS_MAX_MTD_SIZE + int "Maximum MTD oops partition size (kbytes)" + default 4096 + range 8 1048576
drivers/mtd/Kconfig config MTD_OOPS · line 331
Quoted 10 lines
drivers/mtd/Kconfig +9
-0+ depends on MTD_OOPS + help + This parameter sets the maximum MTD partition size for use with + MTD oops. The default value is used as a safeguard against using + e.g., a root filesystem partition as a MTDoops device (in which + case it will be erased). + + No need to change unless you have a very large MTDoops partition. + source "drivers/mtd/chips/Kconfig"
Could we please just make it hard limited to something like 64MiB in the driver itself. This configuration option is not really needed. There are not many users of this driver, and I do not think any of them would ever need a big partition for mtdoops, so there is not reason to make things more complex than they are by introducing this configuration option.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v12 2/4]: mtdoops: Add a maximum MTD partition size
In reply to Simon KagstromQuoted 5 lines · Simon Kagstrom
A configurable maximum MTD partition size for mtdoops avoids mistakes where the user gives e.g., a rootfs partition to mtdoops (which will happily erase it).
Signed-off-by Simon Kagstrom <[email protected]>
I've amended your patch and pushed the amended version to my tree. Please, validate.
Quoted 1 line
From
9483bcb6b097ef3078e5a8798012e06e5156e54eMon Sep 17 00:00:00 2001
From: Simon Kagstrom <[email protected]>
Date: Tue, 3 Nov 2009 08:08:41 +0200
Subject: mtd: mtdoops: limit the maximum mtd partition size
Make the maximum mtdoops partition size to be 32MiB. Indeed, it does not make sense to use anything larger than that anyway. This limit makes it possible to catch stupid mistakes where the user gives e.g., a rootfs partition to mtdoops (which will happily erase it).
--- drivers/mtd/mtdoops.c | 16 ++++++++++------ 1 files changed, 10 insertions(+), 6 deletions(-)
drivers/mtd/mtdoops.c +10 -6
@@ -33,6 +33,8 @@#include <linux/interrupt.h> #include <linux/mtd/mtd.h> +/* Maximum MTD partition size, MiB */ +#define MTDOOPS_MAX_MTD_SIZE 32#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00#define OOPS_PAGE_SIZE 4096
@@ -310,6 +312,12 @@ static void mtdoops_notify_add(struct mtd_info *mtd)return ; } +if (mtd->size >MTDOOPS_MAX_MTD_SIZE ) { +printk (KERN_ERR "mtdoops: mtd%d is too large (limit is %d MiB)\n" , + mtd->index,MTDOOPS_MAX_MTD_SIZE ); +return ; + } +/* oops_page_used is a bit field */ cxt->oops_page_used =vmalloc (DIV_ROUND_UP (mtdoops_pages,BITS_PER_LONG ));
@@ -317,14 +325,10 @@ static void mtdoops_notify_add(struct mtd_info *mtd)printk (KERN_ERR "Could not allocate page array\n" );return ; } - cxt->mtd = mtd; -if (mtd->size >INT_MAX ) - cxt->oops_pages =INT_MAX /OOPS_PAGE_SIZE ; -else - cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ; + cxt->mtd = mtd; + cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ;find_next_position (cxt); -printk (KERN_INFO "mtdoops: Attached to MTD device %d\n" , mtd->index); }
Signature · 5 lines
1.6.2.5 -- Best Regards, Artem Bityutskiy (Артём Битюцкий)
PATCH v12 3/4 : mtdoops: Make page (record) size configurable
In reply to Simon KagstromThe main justification for this is to allow catching long messages during a panic, where the top part might otherwise be lost since moving to the next block can require a flash erase.
---
ChangeLog:
* Rebased over "[PATCH v12 2/4]: mtdoops: Add a maximum MTD partition size"
drivers/mtd/mtdoops.c | 75 ++++++++++++++++++++++++++++-------------------- 1 files changed, 44 insertions(+), 31 deletions(-)
drivers/mtd/mtdoops.c +44 -31
@@ -34,7 +34,11 @@#include <linux/mtd/mtd.h> #define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 -#define OOPS_PAGE_SIZE 4096 + +static unsigned long record_size =4096 ; +module_param (record_size, ulong,0400 ); +MODULE_PARM_DESC (record_size, +"record size for MTD OOPS pages in bytes (default 4096)" ); static struct mtdoops_context { int mtd_index;
@@ -80,8 +84,8 @@ static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) {struct mtd_info *mtd = cxt->mtd;u32 start_page_offset =mtd_div_by_eb (offset, mtd) * mtd->erasesize; -u32 start_page = start_page_offset /OOPS_PAGE_SIZE ; -u32 erase_pages = mtd->erasesize /OOPS_PAGE_SIZE ; +u32 start_page = start_page_offset / record_size; +u32 erase_pages = mtd->erasesize / record_size;struct erase_info erase;DECLARE_WAITQUEUE (wait, current);wait_queue_head_t wait_q;
@@ -149,15 +153,15 @@ static void mtdoops_workfunc_erase(struct work_struct *work)if (!mtd)return ; - mod = (cxt->nextpage *OOPS_PAGE_SIZE ) % mtd->erasesize; + mod = (cxt->nextpage * record_size) % mtd->erasesize;if (mod !=0 ) { - cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) /OOPS_PAGE_SIZE ); + cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size);if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage =0 ; }while (mtd->block_isbad) { - ret = mtd->block_isbad (mtd, cxt->nextpage *OOPS_PAGE_SIZE ); + ret = mtd->block_isbad (mtd, cxt->nextpage * record_size);if (!ret)break ;if (ret <0 ) {
@@ -165,20 +169,20 @@ static void mtdoops_workfunc_erase(struct work_struct *work)return ; } badblock: -printk (KERN_WARNING "mtdoops: bad block at %08x\n" , - cxt->nextpage *OOPS_PAGE_SIZE ); +printk (KERN_WARNING "mtdoops: bad block at %08lx\n" , + cxt->nextpage * record_size); i++; - cxt->nextpage = cxt->nextpage + (mtd->erasesize /OOPS_PAGE_SIZE ); + cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size);if (cxt->nextpage >= cxt->oops_pages) cxt->nextpage =0 ; -if (i == cxt->oops_pages / (mtd->erasesize /OOPS_PAGE_SIZE )) { +if (i == cxt->oops_pages / (mtd->erasesize / record_size)) {printk (KERN_ERR "mtdoops: all blocks bad!\n" );return ; } }for (j =0 , ret =-1 ; (j <3 ) && (ret <0 ); j++) - ret =mtdoops_erase_block (cxt, cxt->nextpage *OOPS_PAGE_SIZE ); + ret =mtdoops_erase_block (cxt, cxt->nextpage * record_size);if (ret >=0 ) { printk(KERN_DEBUG "mtdoops: ready %d, %d\n",
@@ -188,7 +192,7 @@ badblock: }if (mtd->block_markbad && ret == -EIO ) { - ret = mtd->block_markbad (mtd, cxt->nextpage *OOPS_PAGE_SIZE ); + ret = mtd->block_markbad (mtd, cxt->nextpage * record_size);if (ret <0 ) {printk (KERN_ERR "mtdoops: block_markbad failed, aborting\n" );return ;
@@ -203,22 +207,22 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic)size_t retlen;int ret; -if (cxt->writecount <OOPS_PAGE_SIZE ) +if (cxt->writecount < record_size)memset (cxt->oops_buf + cxt->writecount,0xff , -OOPS_PAGE_SIZE - cxt->writecount); + record_size - cxt->writecount);if (panic) - ret = mtd->panic_write (mtd, cxt->nextpage *OOPS_PAGE_SIZE , -OOPS_PAGE_SIZE , &retlen, cxt->oops_buf); + ret = mtd->panic_write (mtd, cxt->nextpage * record_size, + record_size, &retlen, cxt->oops_buf);else - ret = mtd->write (mtd, cxt->nextpage *OOPS_PAGE_SIZE , -OOPS_PAGE_SIZE , &retlen, cxt->oops_buf); + ret = mtd->write (mtd, cxt->nextpage * record_size, + record_size, &retlen, cxt->oops_buf); cxt->writecount =0 ; -if (retlen !=OOPS_PAGE_SIZE || ret <0 ) -printk (KERN_ERR "mtdoops: write failure at %d (%td of %d written), error %d\n" , - cxt->nextpage *OOPS_PAGE_SIZE , retlen,OOPS_PAGE_SIZE , ret); +if (retlen != record_size || ret <0 ) +printk (KERN_ERR "mtdoops: write failure at %ld (%td of %ld written), error %d\n" , + cxt->nextpage * record_size, retlen, record_size, ret);mark_page_used (cxt, cxt->nextpage);mtdoops_inc_counter (cxt);
@@ -243,10 +247,10 @@ static void find_next_position(struct mtdoops_context *cxt)for (page =0 ; page < cxt->oops_pages; page++) {/* Assume the page is used */ mark_page_used (cxt, page); - ret = mtd->read (mtd, page *OOPS_PAGE_SIZE ,8 , &retlen, (u_char *) &count[0 ]); + ret = mtd->read (mtd, page * record_size,8 , &retlen, (u_char *) &count[0 ]);if (retlen !=8 || (ret <0 && ret != -EUCLEAN )) { -printk (KERN_ERR "mtdoops: read failure at %d (%td of 8 read), err %d\n" , - page *OOPS_PAGE_SIZE , retlen, ret); +printk (KERN_ERR "mtdoops: read failure at %ld (%td of 8 read), err %d\n" , + page * record_size, retlen, ret);continue ; }
@@ -290,7 +294,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)struct mtdoops_context *cxt = &oops_cxt;u64 mtdoops_pages = mtd->size; -do_div (mtdoops_pages,OOPS_PAGE_SIZE ); +do_div (mtdoops_pages, record_size);if (cxt->name && !strcmp (mtd->name, cxt->name)) cxt->mtd_index = mtd->index;
@@ -310,7 +314,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)return ; } -if (mtd->erasesize <OOPS_PAGE_SIZE ) { +if (mtd->erasesize < record_size) {printk (KERN_ERR "mtdoops: eraseblock size of MTD partition %d too small\n" , mtd->index);return ;
@@ -324,7 +328,8 @@ static void mtdoops_notify_add(struct mtd_info *mtd)return ; } cxt->mtd = mtd; - cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ; + + cxt->oops_pages = (int )mtd->size / record_size;find_next_position (cxt);
@@ -401,15 +406,15 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count) cxt->writecount =8 ; } -if (count + cxt->writecount >OOPS_PAGE_SIZE ) - count =OOPS_PAGE_SIZE - cxt->writecount; +if (count + cxt->writecount > record_size) + count = record_size - cxt->writecount;memcpy (cxt->oops_buf + cxt->writecount, s, count); cxt->writecount += count;spin_unlock_irqrestore (&cxt->writecount_lock, flags); -if (cxt->writecount ==OOPS_PAGE_SIZE ) +if (cxt->writecount == record_size)mtdoops_console_sync (); }
@@ -448,8 +453,16 @@ static int __init mtdoops_console_init(void) {struct mtdoops_context *cxt = &oops_cxt; +if ((record_size &4095 ) !=0 ) { +printk (KERN_ERR "mtdoops: record_size must be a multiple of 4096\n" ); +return -EINVAL ; + } +if (record_size <4096 ) { +printk (KERN_ERR "mtdoops: record_size must be over 4096 bytes\n" ); +return -EINVAL ; + } cxt->mtd_index =-1 ; - cxt->oops_buf =vmalloc (OOPS_PAGE_SIZE ); + cxt->oops_buf =vmalloc (record_size);if (!cxt->oops_buf) {printk (KERN_ERR "mtdoops: failed to allocate buffer workspace\n" );return -ENOMEM ;
Signature · 1 line
1.6.0.4
Re: [PATCH v12 3/4]: mtdoops: Make page (record) size configurable
Quoted 4 lines · Simon Kagstrom
The main justification for this is to allow catching long messages during a panic, where the top part might otherwise be lost since moving to the next block can require a flash erase.
Quoted 8 lines
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>---
ChangeLog:
* Rebased over "[PATCH v12 2/4]: mtdoops: Add a maximum MTD partition size"drivers/mtd/mtdoops.c | 75 ++++++++++++++++++++++++++++-------------------- 1 files changed, 44 insertions(+), 31 deletions(-)
Pushed this one to my tree, on top of the previous patch which I tweaked, thanks.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v12 3/4]: mtdoops: Make page (record) size configurable
Quoted 11 lines · On Tue, 03 Nov 2009 08:23:58 +0200 Artem Bityutskiy <[email protected]> wrote:
Quoted 10 lines · Simon Kagstrom
The main justification for this is to allow catching long messages during a panic, where the top part might otherwise be lost since moving to the next block can require a flash erase.
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>---
ChangeLog:
* Rebased over "[PATCH v12 2/4]: mtdoops: Add a maximum MTD partition size"
Quoted 5 lines
Quoted 2 lines
drivers/mtd/mtdoops.c | 75 ++++++++++++++++++++++++++++-------------------- 1 files changed, 44 insertions(+), 31 deletions(-)Pushed this one to my tree, on top of the previous patch which I tweaked, thanks.
Thanks! I was going to send an updated patch in, but I've had some other work to do lately. I'll send in a new version of the final patch before the end of the day.
I noticed a small issue in your updated patch:
Review static void mtdoops_notify_add(struct mtd_info *mtd) · line 317
Quoted 10 lines
(quoted diff) +5
-0+/* Maximum MTD partition size, MiB */ +#define MTDOOPS_MAX_MTD_SIZE 32@@ -310,6 +312,12 @@ static void mtdoops_notify_add(struct mtd_info *mtd) return; } + if (mtd->size > MTDOOPS_MAX_MTD_SIZE) { + printk(KERN_ERR "mtdoops: mtd%d is too large (limit is %d MiB)\n", + mtd->index, MTDOOPS_MAX_MTD_SIZE);
mtd->size should be in bytes, right? So this will only check that it's larger than 32 bytes, which most users will probably want ;-)
// Simon
Re: [PATCH v12 3/4]: mtdoops: Make page (record) size configurable
Quoted 20 lines · Simon Kagstrom
Quoted 11 lines · On Tue, 03 Nov 2009 08:23:58 +0200 Artem Bityutskiy <[email protected]> wrote:
Quoted 10 lines · Simon Kagstrom
The main justification for this is to allow catching long messages during a panic, where the top part might otherwise be lost since moving to the next block can require a flash erase.
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>---
ChangeLog:
* Rebased over "[PATCH v12 2/4]: mtdoops: Add a maximum MTD partition size"Quoted 5 lines
Quoted 2 lines
drivers/mtd/mtdoops.c | 75 ++++++++++++++++++++++++++++-------------------- 1 files changed, 44 insertions(+), 31 deletions(-)Pushed this one to my tree, on top of the previous patch which I tweaked, thanks.
Quoted 6 lines
Thanks! I was going to send an updated patch in, but I've had some other work to do lately. I'll send in a new version of the final patch before the end of the day.
I noticed a small issue in your updated patch:
Fixed, thanks. And made the limit to be 8MiB. Pushed to my tree and inlined below.
Quoted 1 line
From
3d91aca8e7b4c1b6bfa44a941ff4341e73dc665cMon Sep 17 00:00:00 2001
From: Simon Kagstrom <[email protected]>
Date: Tue, 3 Nov 2009 08:08:41 +0200
Subject: [PATCH] mtd: mtdoops: limit the maximum mtd partition size
Make the maximum mtdoops partition size to be 8MiB. Indeed, it does not make sense to use anything larger than that anyway. This limit makes it possible to catch stupid mistakes where the user gives e.g., a rootfs partition to mtdoops (which will happily erase it).
--- drivers/mtd/mtdoops.c | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-)
drivers/mtd/mtdoops.c +11 -6
@@ -33,6 +33,9 @@#include <linux/interrupt.h> #include <linux/mtd/mtd.h> +/* Maximum MTD partition size */ +#define MTDOOPS_MAX_MTD_SIZE (8 * 1024 * 1024) +#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00#define OOPS_PAGE_SIZE 4096
@@ -310,6 +313,12 @@ static void mtdoops_notify_add(struct mtd_info *mtd)return ; } +if (mtd->size >MTDOOPS_MAX_MTD_SIZE ) { +printk (KERN_ERR "mtdoops: mtd%d is too large (limit is %d MiB)\n" , + mtd->index,MTDOOPS_MAX_MTD_SIZE /1024 /1024 ); +return ; + } +/* oops_page_used is a bit field */ cxt->oops_page_used =vmalloc (DIV_ROUND_UP (mtdoops_pages,BITS_PER_LONG ));
@@ -317,14 +326,10 @@ static void mtdoops_notify_add(struct mtd_info *mtd)printk (KERN_ERR "Could not allocate page array\n" );return ; } - cxt->mtd = mtd; -if (mtd->size >INT_MAX ) - cxt->oops_pages =INT_MAX /OOPS_PAGE_SIZE ; -else - cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ; + cxt->mtd = mtd; + cxt->oops_pages = (int )mtd->size /OOPS_PAGE_SIZE ;find_next_position (cxt); -printk (KERN_INFO "mtdoops: Attached to MTD device %d\n" , mtd->index); }
Signature · 6 lines
1.6.2.5 -- Best Regards, Artem Bityutskiy (Артём Битюцкий)
PATCH v12 4/4 : mtdoops: refactor as a kmsg_dumper
In reply to Simon KagstromThe last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the kmsg_dumper support instead of a console, which simplifies the code and also includes the messages before the oops started.
On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular mtd->write call), while panics call mtd->panic_write directly. Thus, if panic_on_oops is set, the oops will be written out during the panic.
A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
---
ChangeLog:
* Rebased on top of "[PATCH v12 3/4]: mtdoops: Make page (record) size configurable"
drivers/mtd/Kconfig | 5 +- drivers/mtd/mtdoops.c | 218 +++++++++++++++++++++---------------------------- 2 files changed, 96 insertions(+), 127 deletions(-)
drivers/mtd/Kconfig +3 -2
@@ -312,8 +312,9 @@ config MTD_OOPS buffer in a flash partition where it can be read back at some later point. - To use, add console=ttyMTDx to the kernel command line, - where x is the MTD device number to use. + To use, add mtddev=name/number to the kernel command line, + where name/number is the name or number of the MTD device + to use (e.g., mtddev=7 for /dev/mtd7). config MTD_OOPS_MAX_MTD_SIZE int "Maximum MTD oops partition size (kbytes)"
drivers/mtd/mtdoops.c +93 -125
355 lines not on this page · raw message
Signature · 1 line
1.6.0.4
Re: [PATCH v12 4/4]: mtdoops: refactor as a kmsg_dumper
Quoted 24 lines · Simon Kagstrom
The last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the
kmsg_dumpersupport instead of a console, which simplifies the code and also includes the messages before the oops started.On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular
mtd->writecall), while panics callmtd->panic_writedirectly. Thus, ifpanic_on_oopsis set, the oops will be written out during the panic.A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>---
ChangeLog:
* Rebased on top of "[PATCH v12 3/4]: mtdoops: Make page (record) size configurable"drivers/mtd/Kconfig | 5 +- drivers/mtd/mtdoops.c | 218 +++++++++++++++++++++---------------------------- 2 files changed, 96 insertions(+), 127 deletions(-)
... snip ...
Quoted 15 lines
drivers/mtd/mtdoops.c +7
-1-static int __init mtdoops_console_init (void ) +static int __init mtdoops_init (void ) {struct mtdoops_context *cxt = &oops_cxt; +int mtd_index; +char *endp; +if (strlen (mtddev) ==0 ) { +printk (KERN_ERR "mtdoops: mtd device (mtddev=name/number) must be supplied\n" ); +return -EINVAL ; + }if ((record_size &4095 ) !=0 ) {printk (KERN_ERR "mtdoops: record_size must be a multiple of 4096\n" );return -EINVAL ;
drivers/mtd/mtdoops.c static int __init mtdoops_console_init(void) · line 434
Quoted 9 lines
drivers/mtd/mtdoops.c +5
-0@@ -461,36 +426,39 @@ static int __init mtdoops_console_init(void)printk (KERN_ERR "mtdoops: record_size must be over 4096 bytes\n" );return -EINVAL ; } + +/* Setup the MTD device to use */ cxt->mtd_index =-1 ; + mtd_index =simple_strtoul (mtddev, &endp,0 ); +if (endp != mtddev) + cxt->mtd_index = mtd_index;
I think you should instead do
if (*endp == '\0')
cxt->mtd_index = mtd_index;
instead. Otherwise the code will tread 'mtddev == 1xyz' as mtd1, which is wrong.
And some sanity check to mtd_index would be nice, e.g., a check against MAX_MTD_DEVICES.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
PATCH v13 4/4 : mtdoops: refactor as a kmsg_dumper
The last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the kmsg_dumper support instead of a console, which simplifies the code and also includes the messages before the oops started.
On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular mtd->write call), while panics call mtd->panic_write directly. Thus, if panic_on_oops is set, the oops will be written out during the panic.
A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
---
ChangeLog:
v13:
* Rebase against http://git.infradead.org/users/dedekind/l2-mtd-2.6.git
* (Artem): Check simple_strtoul output to catch strings which only start with numbers
* (Artem): Check that the mtd_index does not exceed MAX_MTD_DEVICES
drivers/mtd/mtdoops.c | 224 +++++++++++++++++++++---------------------------- 1 files changed, 97 insertions(+), 127 deletions(-)
drivers/mtd/mtdoops.c +97 -127
@@ -29,21 +29,34 @@#include <linux/sched.h> #include <linux/wait.h> #include <linux/delay.h> -#include <linux/spinlock.h> #include <linux/interrupt.h> #include <linux/mtd/mtd.h> +#include <linux/kmsg_dump.h> /* Maximum MTD partition size */ #define MTDOOPS_MAX_MTD_SIZE (8 * 1024 * 1024)#define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 +#define MTDOOPS_HEADER_SIZE 8static unsigned long record_size =4096 ;module_param (record_size, ulong,0400 );MODULE_PARM_DESC (record_size,"record size for MTD OOPS pages in bytes (default 4096)" ); +static char mtddev[80 ]; +module_param_string (mtddev, mtddev,80 ,0400 ); +MODULE_PARM_DESC (mtddev, +"name or index number of the MTD device to use" ); + +static int dump_oops =1 ; +module_param (dump_oops, int,0600 ); +MODULE_PARM_DESC (dump_oops, +"set to 1 to dump oopses, 0 to only dump panics (default 1)" ); + static struct mtdoops_context { + struct kmsg_dumper dump; + int mtd_index; struct work_struct work_erase; struct work_struct work_write;
@@ -52,14 +65,8 @@ static struct mtdoops_context {int nextpage;int nextcount;unsigned long *oops_page_used; -char *name;void *oops_buf; - -/* writecount and disabling ready are spin lock protected */ -spinlock_t writecount_lock; -int ready; -int writecount; } oops_cxt;static void mark_page_used (struct mtdoops_context *cxt,int page)
@@ -111,7 +118,7 @@ static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset)remove_wait_queue (&wait_q, &wait);printk (KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] on \"%s\" failed\n" , (unsigned long long )erase.addr, - (unsigned long long )erase.len, mtd->name); + (unsigned long long )erase.len, mtddev);return ret; }
@@ -141,7 +148,6 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt)printk (KERN_DEBUG "mtdoops: ready %d, %d (no erase)\n" , cxt->nextpage, cxt->nextcount); - cxt->ready =1 ; }/* Scheduled work - when we can't proceed without erasing a block */
@@ -190,7 +196,6 @@ badblock:if (ret >=0 ) {printk (KERN_DEBUG "mtdoops: ready %d, %d\n" , cxt->nextpage, cxt->nextcount); - cxt->ready =1 ;return ; }
@@ -208,11 +213,13 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) {struct mtd_info *mtd = cxt->mtd;size_t retlen; +u32 *hdr;int ret; -if (cxt->writecount < record_size) -memset (cxt->oops_buf + cxt->writecount,0xff , - record_size - cxt->writecount); +/* Add mtdoops header to the buffer */ + hdr = cxt->oops_buf; + hdr[0 ] = cxt->nextcount; + hdr[1 ] =MTDOOPS_KERNMSG_MAGIC ;if (panic) ret = mtd->panic_write(mtd, cxt->nextpage * record_size,
@@ -221,17 +228,15 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) ret = mtd->write (mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf); - cxt->writecount =0 ; -if (retlen != record_size || ret <0 )printk (KERN_ERR "mtdoops: write failure at %ld (%td of %ld written), error %d\n" , cxt->nextpage * record_size, retlen, record_size, ret);mark_page_used (cxt, cxt->nextpage); +memset (cxt->oops_buf,0xff , record_size);mtdoops_inc_counter (cxt); } -static void mtdoops_workfunc_write (struct work_struct *work) { struct mtdoops_context *cxt =
@@ -250,17 +255,18 @@ static void find_next_position(struct mtdoops_context *cxt)for (page =0 ; page < cxt->oops_pages; page++) {/* Assume the page is used */ mark_page_used (cxt, page); - ret = mtd->read (mtd, page * record_size,8 , &retlen, (u_char *) &count[0 ]); -if (retlen !=8 || (ret <0 && ret != -EUCLEAN )) { -printk (KERN_ERR "mtdoops: read failure at %ld (%td of 8 read), err %d\n" , - page * record_size, retlen, ret); + ret = mtd->read (mtd, page * record_size,MTDOOPS_HEADER_SIZE , + &retlen, (u_char *) &count[0 ]); +if (retlen !=MTDOOPS_HEADER_SIZE || + (ret <0 && ret != -EUCLEAN )) { +printk (KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n" , + page * record_size, retlen, +MTDOOPS_HEADER_SIZE , ret);continue ; }if (count[0 ] ==0xffffffff && count[1 ] ==0xffffffff )mark_page_unused (cxt, page); -if (count[1 ] !=MTDOOPS_KERNMSG_MAGIC ) -continue ;if (count[0 ] ==0xffffffff )continue ;if (maxcount ==0xffffffff ) {
@@ -291,6 +297,42 @@ static void find_next_position(struct mtdoops_context *cxt)mtdoops_inc_counter (cxt); } +static void mtdoops_do_dump (struct kmsg_dumper *dumper, +enum kmsg_dump_reason reason,const char *s1,unsigned long l1, +const char *s2,unsigned long l2) +{ +struct mtdoops_context *cxt =container_of (dumper, + struct mtdoops_context, dump); +unsigned long s1_start, s2_start; +unsigned long l1_cpy, l2_cpy; +char *dst; + +/* Only dump oopses if dump_oops is set */ +if (reason ==KMSG_DUMP_OOPS && !dump_oops) +return ; + + dst = cxt->oops_buf +MTDOOPS_HEADER_SIZE ;/* Skip the header */ + l2_cpy =min (l2, record_size -MTDOOPS_HEADER_SIZE ); + l1_cpy =min (l1, record_size -MTDOOPS_HEADER_SIZE - l2_cpy); + + s2_start = l2 - l2_cpy; + s1_start = l1 - l1_cpy; + +memcpy (dst, s1 + s1_start, l1_cpy); +memcpy (dst + l1_cpy, s2 + s2_start, l2_cpy); + +/* Panics must be written immediately */ +if (reason ==KMSG_DUMP_PANIC ) { +if (!cxt->mtd->panic_write) +printk (KERN_ERR "mtdoops: Cannot write from panic without panic_write\n" ); +else +mtdoops_write (cxt,1 ); +return ; + } + +/* For other cases, schedule work to write it "nicely" */ +schedule_work (&cxt->work_write); +}static void mtdoops_notify_add (struct mtd_info *mtd) {
@@ -299,7 +341,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd)do_div (mtdoops_pages, record_size); -if (cxt->name && !strcmp (mtd->name, cxt->name)) +if (!strcmp (mtd->name, mtddev)) cxt->mtd_index = mtd->index;if (mtd->index != cxt->mtd_index || cxt->mtd_index <0 )
@@ -330,6 +372,13 @@ static void mtdoops_notify_add(struct mtd_info *mtd)printk (KERN_ERR "Could not allocate page array\n" );return ; } + cxt->dump.dump = mtdoops_do_dump; +if (kmsg_dump_register (&cxt->dump) <0 ) { +printk (KERN_ERR "Registering kmsg dumper failed\n" ); +vfree (cxt->oops_page_used); + cxt->oops_page_used =NULL ; +return ; + } cxt->mtd = mtd; cxt->oops_pages = (int )mtd->size / record_size;
@@ -344,116 +393,29 @@ static void mtdoops_notify_remove(struct mtd_info *mtd)if (mtd->index != cxt->mtd_index || cxt->mtd_index <0 )return ; +if (kmsg_dump_unregister (&cxt->dump) <0 ) +printk (KERN_WARNING "Could not unregister kmsg_dumper??\n" ); + cxt->mtd =NULL ;flush_scheduled_work (); } -static void mtdoops_console_sync (void ) -{ -struct mtdoops_context *cxt = &oops_cxt; -struct mtd_info *mtd = cxt->mtd; -unsigned long flags; - -if (!cxt->ready || !mtd || cxt->writecount ==0 ) -return ; - -/* -* Once ready is 0 and we've held the lock no further writes to the -* buffer will happen -*/ -spin_lock_irqsave (&cxt->writecount_lock, flags); -if (!cxt->ready) { -spin_unlock_irqrestore (&cxt->writecount_lock, flags); -return ; - } - cxt->ready =0 ; -spin_unlock_irqrestore (&cxt->writecount_lock, flags); - -if (mtd->panic_write &&in_interrupt ()) -/* Interrupt context, we're going to panic so try and log */ -mtdoops_write (cxt,1 ); -else -schedule_work (&cxt->work_write); -} - -static void -mtdoops_console_write (struct console *co,const char *s,unsigned int count) -{ -struct mtdoops_context *cxt = co->data; -struct mtd_info *mtd = cxt->mtd; -unsigned long flags; - -if (!oops_in_progress) { -mtdoops_console_sync (); -return ; - } - -if (!cxt->ready || !mtd) -return ; - -/* Locking on writecount ensures sequential writes to the buffer */ -spin_lock_irqsave (&cxt->writecount_lock, flags); - -/* Check ready status didn't change whilst waiting for the lock */ -if (!cxt->ready) { -spin_unlock_irqrestore (&cxt->writecount_lock, flags); -return ; - } - -if (cxt->writecount ==0 ) { -u32 *stamp = cxt->oops_buf; - *stamp++ = cxt->nextcount; - *stamp =MTDOOPS_KERNMSG_MAGIC ; - cxt->writecount =8 ; - } - -if (count + cxt->writecount > record_size) - count = record_size - cxt->writecount; - -memcpy (cxt->oops_buf + cxt->writecount, s, count); - cxt->writecount += count; - -spin_unlock_irqrestore (&cxt->writecount_lock, flags); - -if (cxt->writecount == record_size) -mtdoops_console_sync (); -} - -static int __init mtdoops_console_setup (struct console *co,char *options) -{ -struct mtdoops_context *cxt = co->data; - -if (cxt->mtd_index !=-1 || cxt->name) -return -EBUSY ; -if (options) { - cxt->name =kstrdup (options,GFP_KERNEL ); -return 0 ; - } -if (co->index ==-1 ) -return -EINVAL ; - - cxt->mtd_index = co->index; -return 0 ; -}static struct mtd_notifier mtdoops_notifier = { .add = mtdoops_notify_add, .remove = mtdoops_notify_remove, }; -static struct console mtdoops_console = { - .name ="ttyMTD" , - .write = mtdoops_console_write, - .setup = mtdoops_console_setup, - .unblank = mtdoops_console_sync, - .index =-1 , - .data = &oops_cxt, -}; - -static int __init mtdoops_console_init (void ) +static int __init mtdoops_init (void ) {struct mtdoops_context *cxt = &oops_cxt; +int mtd_index; +char *endp; +if (strlen (mtddev) ==0 ) { +printk (KERN_ERR "mtdoops: mtd device (mtddev=name/number) must be supplied\n" ); +return -EINVAL ; + }if ((record_size &4095 ) !=0 ) {printk (KERN_ERR "mtdoops: record_size must be a multiple of 4096\n" );return -EINVAL ;
@@ -462,36 +424,44 @@ static int __init mtdoops_console_init(void)printk (KERN_ERR "mtdoops: record_size must be over 4096 bytes\n" );return -EINVAL ; } + +/* Setup the MTD device to use */ cxt->mtd_index =-1 ; + mtd_index =simple_strtoul (mtddev, &endp,0 ); +if (*endp =='\0' ) + cxt->mtd_index = mtd_index; +if (cxt->mtd_index >MAX_MTD_DEVICES ) { +printk (KERN_ERR "mtdoops: invalid mtd device number (%u) given\n" , + mtd_index); +return -EINVAL ; + } + cxt->oops_buf =vmalloc (record_size);if (!cxt->oops_buf) {printk (KERN_ERR "mtdoops: failed to allocate buffer workspace\n" );return -ENOMEM ; } +memset (cxt->oops_buf,0xff , record_size); -spin_lock_init (&cxt->writecount_lock);INIT_WORK (&cxt->work_erase, mtdoops_workfunc_erase);INIT_WORK (&cxt->work_write, mtdoops_workfunc_write); -register_console (&mtdoops_console);register_mtd_user (&mtdoops_notifier);return 0 ; } -static void __exit mtdoops_console_exit(void) +static void __exit mtdoops_exit(void) {struct mtdoops_context *cxt = &oops_cxt;unregister_mtd_user (&mtdoops_notifier); -unregister_console (&mtdoops_console); -kfree (cxt->name);vfree (cxt->oops_buf);vfree (cxt->oops_page_used); } -subsys_initcall (mtdoops_console_init); -module_exit (mtdoops_console_exit); +module_init (mtdoops_init); +module_exit (mtdoops_exit);MODULE_LICENSE ("GPL" );MODULE_AUTHOR ("Richard Purdie <[email protected]>" );
Signature · 1 line
1.6.0.4
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
Hi Artem,
Quoted 8 lines · On Tue, 3 Nov 2009 14:19:03 +0100 Simon Kagstrom…
The last messages which happens before a crash might contain interesting information about the crash. [...]
ChangeLog:
v13:
* Rebase against http://git.infradead.org/users/dedekind/l2-mtd-2.6.git
* (Artem): Checksimple_strtouloutput to catch strings which only start with numbers
* (Artem): Check that themtd_indexdoes not exceedMAX_MTD_DEVICES
Are there any more issues which I should fix for this patch to get it to an acceptable state?
Thanks,
// Simon
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
Quoted 14 lines · Simon Kagstrom
Hi Artem,
Quoted 8 lines · On Tue, 3 Nov 2009 14:19:03 +0100 Simon Kagstrom…
The last messages which happens before a crash might contain interesting information about the crash. [...]
ChangeLog:
v13:
* Rebase against http://git.infradead.org/users/dedekind/l2-mtd-2.6.git
* (Artem): Checksimple_strtouloutput to catch strings which only start with numbers
* (Artem): Check that themtd_indexdoes not exceedMAX_MTD_DEVICES
Quoted 2 lines
Are there any more issues which I should fix for this patch to get it to an acceptable state?
Sorry Simon, I just do not have enough time ATM. But I will look at this ASAP. It is in my TODO queue.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
Quoted 5 lines · On Tue, 10 Nov 2009 13:53:41 +0200 Artem Bityutskiy <[email protected]> wrote:
Quoted 2 lines
Are there any more issues which I should fix for this patch to get it to an acceptable state?
Sorry Simon, I just do not have enough time ATM. But I will look at this ASAP. It is in my TODO queue.
No hurry, I just thought it might have slipped into the holes between the floor boards.
// Simon
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
In reply to Simon KagstromQuoted 10 lines · Simon Kagstrom
The last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the
kmsg_dumpersupport instead of a console, which simplifies the code and also includes the messages before the oops started.On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular
mtd->writecall), while panics callmtd->panic_writedirectly. Thus, ifpanic_on_oopsis set, the oops will be written out during the panic.
Quoted 6 lines
A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>
Pushed to my l2-mtd-2.6 tree with the following amendments on top, please, review:
drivers/mtd/mtdoops.c +8 -9
@@ -337,9 +337,8 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper,static void mtdoops_notify_add (struct mtd_info *mtd) {struct mtdoops_context *cxt = &oops_cxt; -u64 mtdoops_pages = mtd->size; - -do_div (mtdoops_pages, record_size); +u64 mtdoops_pages =div_u64 (mtd->size, record_size); +int err;if (!strcmp (mtd->name, mtddev)) cxt->mtd_index = mtd->index;
@@ -352,13 +351,11 @@ static void mtdoops_notify_add(struct mtd_info *mtd) mtd->index);return ; } -if (mtd->erasesize < record_size) {printk (KERN_ERR "mtdoops: eraseblock size of MTD partition %d too small\n" , mtd->index);return ; } -if (mtd->size >MTDOOPS_MAX_MTD_SIZE ) {printk (KERN_ERR "mtdoops: mtd%d is too large (limit is %d MiB)\n" , mtd->index,MTDOOPS_MAX_MTD_SIZE /1024 /1024 );
@@ -369,12 +366,14 @@ static void mtdoops_notify_add(struct mtd_info *mtd) cxt->oops_page_used =vmalloc (DIV_ROUND_UP (mtdoops_pages,BITS_PER_LONG ));if (!cxt->oops_page_used) { -printk (KERN_ERR "Could not allocate page array\n" ); +printk (KERN_ERR "mtdoops: could not allocate page array\n" );return ; } + cxt->dump.dump = mtdoops_do_dump; -if (kmsg_dump_register (&cxt->dump) <0 ) { -printk (KERN_ERR "Registering kmsg dumper failed\n" ); + err =kmsg_dump_register (&cxt->dump); +if (err) { +printk (KERN_ERR "mtdoops: registering kmsg dumper failed, error %d\n" , err);vfree (cxt->oops_page_used); cxt->oops_page_used =NULL ;return ;
@@ -394,7 +393,7 @@ static void mtdoops_notify_remove(struct mtd_info *mtd)return ;if (kmsg_dump_unregister (&cxt->dump) <0 ) -printk (KERN_WARNING "Could not unregister kmsg_dumper??\n" ); +printk (KERN_WARNING "mtdoops: could not unregister kmsg_dumper\n" ); cxt->mtd =NULL ;flush_scheduled_work ();
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
In reply to Simon KagstromQuoted 10 lines · Simon Kagstrom
The last messages which happens before a crash might contain interesting information about the crash. This patch reworks mtdoops using the
kmsg_dumpersupport instead of a console, which simplifies the code and also includes the messages before the oops started.On oops callbacks, the MTD device write is scheduled in a work queue (to be able to use the regular
mtd->writecall), while panics callmtd->panic_writedirectly. Thus, ifpanic_on_oopsis set, the oops will be written out during the panic.
Quoted 6 lines
A parameter to specify which mtd device to use (number or name), as well as a flag, writable at runtime, to toggle wheter to dump oopses or only panics (since oopses can often be handled by regular syslog).
Signed-off-by Simon Kagstrom <[email protected]>Reviewed-by Anders Grafstrom <[email protected]>
Do we really need this notifiers? Would not it be better to open mtd device straight in the module_init function instead?
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
On Tue, 10 Nov 2009 18:11:33 +0200
Quoted 2 lines
Do we really need this notifiers? Would not it be better to open mtd device straight in the
module_initfunction instead?
If the mtdoops driver is built into the kernel, module_init might be (and I believe will be) called before the MTD partitions have been created. With the MTD notifiers, this problem is worked around.
// Simon
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
Quoted 8 lines · Simon Kagstrom
On Tue, 10 Nov 2009 18:11:33 +0200
Quoted 2 lines
Do we really need this notifiers? Would not it be better to open mtd device straight in the
module_initfunction instead?If the mtdoops driver is built into the kernel,
module_initmight be (and I believe will be) called before the MTD partitions have been created. With the MTD notifiers, this problem is worked around.
But this is why we have late_initcall(), which we can use instead of module_init().
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
Quoted 6 lines · On Wed, 11 Nov 2009 12:29:42 +0200 Artem Bityutskiy <[email protected]> wrote:
Quoted 5 lines · Simon Kagstrom
On Tue, 10 Nov 2009 18:11:33 +0200
Quoted 2 lines
Do we really need this notifiers? Would not it be better to open mtd device straight in the
module_initfunction instead?
Quoted 6 lines
Quoted 3 lines
If the mtdoops driver is built into the kernel,
module_initmight be (and I believe will be) called before the MTD partitions have been created. With the MTD notifiers, this problem is worked around.But this is why we have
late_initcall(), which we can use instead ofmodule_init().
OK, makes sense (you learn something new every day!). But I still have one, perhaps artificial, use-case for keeping it as-is: MTD devices might show up later if they are loaded as modules. In my case I use phram as a module, and if I were to use that with MTDoops in the kernel, I still need the notifiers.
But loading mtdoops after phram would also work obviously.
// Simon
Re: [PATCH v13 4/4]: mtdoops: refactor as a kmsg_dumper
Quoted 13 lines · Simon Kagstrom
Quoted 10 lines · On Wed, 11 Nov 2009 12:29:42 +0200 Artem Bityutskiy <[email protected]> wrote:
Quoted 8 lines · Simon Kagstrom
On Tue, 10 Nov 2009 18:11:33 +0200
Quoted 2 lines
Do we really need this notifiers? Would not it be better to open mtd device straight in the
module_initfunction instead?If the mtdoops driver is built into the kernel,
module_initmight be (and I believe will be) called before the MTD partitions have been created. With the MTD notifiers, this problem is worked around.
Quoted 8 lines
Quoted 2 lines
But this is why we have
late_initcall(), which we can use instead ofmodule_init().OK, makes sense (you learn something new every day!). But I still have one, perhaps artificial, use-case for keeping it as-is: MTD devices might show up later if they are loaded as modules. In my case I use phram as a module, and if I were to use that with MTDoops in the kernel, I still need the notifiers.
I do not insist at all, but I thought this is just error prone way. You load mtdoops, which then lurks, and when appropriate MTD device appears, it grabs it. But what if I just forgot to unload mtdoops and it grabs my mtd1 device and formats it?
Besides, currently mtdoops may fail to grab the mtd device for some reasons (an error), and all you have is an error message. If you do not notice it, you may happily think you have working mtdoops, while you do not.
Signature · 2 lines
Best Regards, Artem Bityutskiy (Артём Битюцкий)