Messages in this thread Patch in this message | | | From | Seiji Aguchi <> | Date | Thu, 31 May 2012 17:49:19 -0400 | Subject | [Patch -tip]Skip spin_lock of pstore_dump in panic case |
| |
Hi
I would like to discuss a way to avoid deadlocking of pstore_dump(), kmsg_dump() and platform drivers. At first, I post pstore_dump() part.
This patch is based on following comments on my previous patch. http://marc.info/?l=linux-kernel&m=131914554220738&w=2 http://marc.info/?l=linux-kernel&m=132370565114963&w=2
The points are skipping spin_lock in panic case and adding WARN_ON in preparation for future change.
Any comments are welcome.
Seiji
[Patch Description]
This patch does followings.
- Skip a spin_lock of pstore_dump() in panic case because pstore_dump() is serialized via smp_send_stop.
- Add WARN_ON() in "in_nmi() and !panic" case into pstore_dump(). Currently, this condition never becomes true. But if someone adds new kmsg_dump() into NMI path in the future, error record may corrupt. We can trap it and complain with it.
Signed-off-by: Seiji Aguchi <seiji.aguchi@hds.com>
--- fs/pstore/platform.c | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/fs/pstore/platform.c b/fs/pstore/platform.c index 82c585f..e5a0354 100644 --- a/fs/pstore/platform.c +++ b/fs/pstore/platform.c @@ -31,6 +31,8 @@ #include <linux/hardirq.h> #include <linux/workqueue.h> +#include <asm-generic/bug.h> + #include "internal.h" /* @@ -107,15 +109,21 @@ static void pstore_dump(struct kmsg_dumper *dumper, int hsize, ret; unsigned int part = 1; unsigned long flags = 0; - int is_locked = 0; why = get_reason_str(reason); - if (in_nmi()) { - is_locked = spin_trylock(&psinfo->buf_lock); - if (!is_locked) - pr_err("pstore dump routine blocked in NMI, may corrupt error record\n"); - } else + /* + * Currently, this condition never becomes true. + * But if someone adds new kmsg_dump() into NMI path in the future, + * error record may corrupt. We can trap it and complain with it. + */ + WARN_ON(in_nmi() && reason != KMSG_DUMP_PANIC); + + /* + * pstore_dump() is serialized in panic case. + * So, we don't need to take any locks. + */ + if (reason != KMSG_DUMP_PANIC) spin_lock_irqsave(&psinfo->buf_lock, flags); oopscount++; while (total < kmsg_bytes) { @@ -145,10 +153,8 @@ static void pstore_dump(struct kmsg_dumper *dumper, total += l1_cpy + l2_cpy; part++; } - if (in_nmi()) { - if (is_locked) - spin_unlock(&psinfo->buf_lock); - } else + + if (reason != KMSG_DUMP_PANIC) spin_unlock_irqrestore(&psinfo->buf_lock, flags); } -- 1.7.1
| |