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>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <1408459062-19120-2-git-send-email-daniel.thompson@linaro.org>
Date:	Tue, 19 Aug 2014 15:37:40 +0100
From:	Daniel Thompson <daniel.thompson@...aro.org>
To:	Jason Wessel <jason.wessel@...driver.com>
Cc:	Daniel Thompson <daniel.thompson@...aro.org>,
	kgdb-bugreport@...ts.sourceforge.net, patches@...aro.org,
	linaro-kernel@...ts.linaro.org, linux-kernel@...r.kernel.org,
	Paul Gortmaker <paul.gortmaker@...driver.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Mike Travis <travis@....com>,
	Dimitri Sivanich <sivanich@....com>,
	Hedi Berriche <hedi@....com>,
	John Stultz <john.stultz@...aro.org>,
	Anton Vorontsov <anton.vorontsov@...aro.org>,
	Colin Cross <ccross@...roid.com>, kernel-team@...roid.com
Subject: [PATCH v3 1/3] kdb: Add framework to display sequence files

Lots of useful information about the system is held in pseudo filesystems
and presented using the seq_file mechanism. Unfortunately during both boot
up and kernel panic (both good times to break out kdb) it is difficult to
examine these files. This patch introduces a means to display sequence
files via kdb.

Signed-off-by: Daniel Thompson <daniel.thompson@...aro.org>
---
 include/linux/kdb.h       |  5 +++++
 kernel/debug/kdb/kdb_io.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/include/linux/kdb.h b/include/linux/kdb.h
index 290db12..fb46dd4 100644
--- a/include/linux/kdb.h
+++ b/include/linux/kdb.h
@@ -25,6 +25,7 @@ typedef int (*kdb_func_t)(int, const char **);
 #include <linux/init.h>
 #include <linux/sched.h>
 #include <linux/atomic.h>
+#include <linux/seq_file.h>
 
 #define KDB_POLL_FUNC_MAX	5
 extern int kdb_poll_idx;
@@ -117,6 +118,8 @@ extern __printf(1, 0) int vkdb_printf(const char *fmt, va_list args);
 extern __printf(1, 2) int kdb_printf(const char *, ...);
 typedef __printf(1, 2) int (*kdb_printf_t)(const char *, ...);
 
+extern int kdb_print_seq_file(const struct seq_operations *ops);
+
 extern void kdb_init(int level);
 
 /* Access to kdb specific polling devices */
@@ -151,6 +154,8 @@ extern int kdb_register_repeat(char *, kdb_func_t, char *, char *,
 extern int kdb_unregister(char *);
 #else /* ! CONFIG_KGDB_KDB */
 static inline __printf(1, 2) int kdb_printf(const char *fmt, ...) { return 0; }
+static inline int
+kdb_print_seq_file(const struct seq_operations *ops) { return 0; }
 static inline void kdb_init(int level) {}
 static inline int kdb_register(char *cmd, kdb_func_t func, char *usage,
 			       char *help, short minlen) { return 0; }
diff --git a/kernel/debug/kdb/kdb_io.c b/kernel/debug/kdb/kdb_io.c
index 7c70812..46aae57 100644
--- a/kernel/debug/kdb/kdb_io.c
+++ b/kernel/debug/kdb/kdb_io.c
@@ -850,3 +850,56 @@ int kdb_printf(const char *fmt, ...)
 	return r;
 }
 EXPORT_SYMBOL_GPL(kdb_printf);
+
+/*
+ * Display a seq_file on the kdb console.
+ */
+
+static int __kdb_print_seq_file(struct seq_file *m, void *v)
+{
+	int i, res;
+
+	res = m->op->show(m, v);
+	if (0 != res)
+		return KDB_BADLENGTH;
+
+	for (i = 0; i < m->count && !KDB_FLAG(CMD_INTERRUPT); i++)
+		kdb_printf("%c", m->buf[i]);
+	m->count = 0;
+
+	return 0;
+}
+
+int kdb_print_seq_file(const struct seq_operations *ops)
+{
+	static char seq_buf[4096];
+	static DEFINE_SPINLOCK(seq_buf_lock);
+	unsigned long flags;
+	struct seq_file m = {
+		.buf = seq_buf,
+		.size = sizeof(seq_buf),
+		/* .lock is deliberately left uninitialized because it is
+		 * used by seq_file read/lseek wrapper functions. It cannot be
+		 * used from any of the seq_operations (assuming the ops are
+		 * deadlock free with the normal interface).
+		 */
+		.op = ops,
+	};
+	loff_t pos = 0;
+	void *v;
+	int res = 0;
+
+	v = ops->start(&m, &pos);
+	while (v) {
+		spin_lock_irqsave(&seq_buf_lock, flags);
+		res = __kdb_print_seq_file(&m, v);
+		spin_unlock_irqrestore(&seq_buf_lock, flags);
+		if (res != 0 || KDB_FLAG(CMD_INTERRUPT))
+			break;
+
+		v = ops->next(&m, v, &pos);
+	}
+	ops->stop(&m, v);
+
+	return res;
+}
-- 
1.9.3

--
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