linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch -tip]Skip spin_lock of pstore_dump in panic case
@ 2012-05-31 21:49 Seiji Aguchi
  0 siblings, 0 replies; only message in thread
From: Seiji Aguchi @ 2012-05-31 21:49 UTC (permalink / raw)
  To: linux-kernel, Luck, Tony (tony.luck@intel.com),
	dzickus, akpm, a.p.zijlstra,
	'mingo@elte.hu' (mingo@elte.hu)
  Cc: dle-develop, Satoru Moriya

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-05-31 21:49 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-31 21:49 [Patch -tip]Skip spin_lock of pstore_dump in panic case Seiji Aguchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).