lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 31 May 2012 17:49:19 -0400
From:	Seiji Aguchi <seiji.aguchi@....com>
To:	"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
	"Luck, Tony (tony.luck@...el.com)" <tony.luck@...el.com>,
	"dzickus@...hat.com" <dzickus@...hat.com>,
	"akpm@...ux-foundation.org" <akpm@...ux-foundation.org>,
	"a.p.zijlstra@...llo.nl" <a.p.zijlstra@...llo.nl>,
	"'mingo@...e.hu' (mingo@...e.hu)" <mingo@...e.hu>
CC:	"dle-develop@...ts.sourceforge.net" 
	<dle-develop@...ts.sourceforge.net>,
	Satoru Moriya <satoru.moriya@....com>
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@....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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ