Skip to contentSkip to conversation

kgdb: core

PATCH In review Ingo Molnar 8 participants 39 messages Feb 10, 2008 – Feb 11, 2008

Subsystems (10)
lore
Share & tools
lore
#0 lore raw

PATCH 3/6 kgdb: core

From: Jason Wessel <[email protected]>

kgdb core code. Handles the protocol and the arch details.

[ [email protected]: heavily modified, simplified and cleaned up. ]

---
 include/asm-generic/kgdb.h |   93 ++
 include/linux/kgdb.h       |  264 +++++
 kernel/Makefile            |    1 
 kernel/kgdb.c              | 2020 +++++++++++++++++++++++++++++++++++++++++++++
 lib/Kconfig.debug          |    2 
 lib/Kconfig.kgdb           |   37 
 6 files changed, 2417 insertions(+)
include/asm-generic/kgdb.h new file +93 -0
Index: linux-kgdb.q/include/asm-generic/kgdb.h
===================================================================
@@ -0,0 +1,93 @@
+/*
+ * include/asm-generic/kgdb.h
+ *
+ * This provides the assembly level information so that KGDB can provide
+ * a GDB that has been patched with enough information to know to stop
+ * trying to unwind the function.
+ *
+ * Author: Tom Rini <[email protected]>
+ *
+ * 2005 (c) MontaVista Software, Inc.
+ * 2006 (c) Embedded Alley Solutions, Inc.
+ *
+ * This file is licensed under the terms of the GNU General Public License
+ * version 2. This program is licensed "as is" without any warranty of any
+ * kind, whether express or implied.
+ */
+
+#ifndef __ASM_GENERIC_KGDB_H__
+#define __ASM_GENERIC_KGDB_H__
+
+struct pt_regs;
+
+/**
+ *	kgdb_skipexception - Bail of of KGDB when we've been triggered.
+ *	@exception: Exception vector number
+ *	@regs: Current &struct pt_regs.
+ *
+ *	On some architectures we need to skip a breakpoint exception when
+ *	it occurs after a breakpoint has been removed.
+ */
+int kgdb_skipexception(int exception, struct pt_regs *regs);
+
+/**
+ *	kgdb_post_master_code - Save error vector/code numbers.
+ *	@regs: Original pt_regs.
+ *	@e_vector: Original error vector.
+ *	@err_code: Original error code.
+ *
+ *	This is needed on architectures which support SMP and KGDB.
+ *	This function is called after all the slave cpus have been put
+ *	to a know spin state and the master CPU has control over KGDB.
+ */
+extern void kgdb_post_master_code(struct pt_regs *regs, int e_vector,
+				  int err_code);
+
+/**
+ *	kgdb_disable_hw_debug - Disable hardware debugging while we in kgdb.
+ *	@regs: Current &struct pt_regs.
+ *
+ *	This function will be called if the particular architecture must
+ *	disable hardware debugging while it is processing gdb packets or
+ *	handling exception.
+ */
+extern void kgdb_disable_hw_debug(struct pt_regs *regs);
+
+#ifdef CONFIG_KGDB_ARCH_HAS_SHADOW_INFO
+/**
+ *	kgdb_shadowinfo - Get shadowed information on @threadid.
+ *	@regs: The &struct pt_regs of the current process.
+ *	@buffer: A buffer of %BUFMAX size.
+ *	@threadid: The thread id of the shadowed process to get information on.
+ */
+extern void kgdb_shadowinfo(struct pt_regs *regs, char *buffer,
+			    unsigned threadid);
+
+/**
+ *	kgdb_get_shadow_thread - Get the shadowed &task_struct of @threadid.
+ *	@regs: The &struct pt_regs of the current thread.
+ *	@threadid: The thread id of the shadowed process to get information on.
+ *
+ *	RETURN:
+ *	This returns a pointer to the &struct task_struct of the shadowed
+ *	thread, @threadid.
+ */
+extern struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs,
+						  int threadid);
+
+/**
+ *	kgdb_shadow_regs - Return the shadowed registers of @threadid.
+ *	@regs: The &struct pt_regs of the current thread.
+ *	@threadid: The thread id we want the &struct pt_regs for.
+ *
+ *	RETURN:
+ *	The a pointer to the &struct pt_regs of the shadowed thread @threadid.
+ */
+extern struct pt_regs *kgdb_shadow_regs(struct pt_regs *regs, int threadid);
+#else
+#define kgdb_shadowinfo(regs, buf, threadid)		do { } while (0)
+#define kgdb_get_shadow_thread(regs, threadid)		NULL
+#define kgdb_shadow_regs(regs, threadid)		NULL
+#endif
+
+#endif				/* __ASM_GENERIC_KGDB_H__ */
include/linux/kgdb.h new file +264 -0

264 lines not on this page · raw message

kernel/Makefile +1 -0
Index: linux-kgdb.q/kernel/Makefile
===================================================================
@@ -53,6 +53,7 @@ obj-$(CONFIG_AUDIT) += audit.o auditfilt
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
 obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KGDB) += kgdb.o
 obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
kernel/kgdb.c new file +2020 -0

2,020 lines not on this page · raw message

lib/Kconfig.debug +2 -0
Index: linux-kgdb.q/lib/Kconfig.debug
===================================================================
@@ -632,3 +632,5 @@ config PROVIDE_OHCI1394_DMA_INIT
 	  See Documentation/debugging-via-ohci1394.txt for more information.
 
 source "samples/Kconfig"
+
+source "lib/Kconfig.kgdb"
lib/Kconfig.kgdb new file +37 -0
Index: linux-kgdb.q/lib/Kconfig.kgdb
===================================================================
@@ -0,0 +1,37 @@
+
+menuconfig KGDB
+	bool "KGDB: kernel debugging with remote gdb"
+	select FRAME_POINTER
+	depends on ARCH_SUPPORTS_KGDB
+	depends on DEBUG_KERNEL && EXPERIMENTAL
+	help
+	  If you say Y here, it will be possible to remotely debug the
+	  kernel using gdb.  Documentation of kernel debugger is available
+	  at http://kgdb.sourceforge.net as well as in DocBook form
+	  in Documentation/DocBook/.  If unsure, say N.
+
+config KGDB_ARCH_HAS_SHADOW_INFO
+	bool
+
+config KGDB_CONSOLE_OUTPUT
+	bool "KGDB: Console messages through gdb"
+	depends on KGDB
+	help
+	  If you say Y here, console messages will appear through gdb.
+	  Other consoles such as tty or ttyS will continue to work as usual.
+	  Note that if you use this in conjunction with KGDBOE, if the
+	  ethernet driver runs into an error condition during use with KGDB,
+	  it is possible to hit an infinite recursion, causing the kernel
+	  to crash, and typically reboot.  For this reason, it is preferable
+	  to use NETCONSOLE in conjunction with KGDBOE instead of
+	  KGDB_CONSOLE.
+
+config KGDBOC
+	tristate "KGDB: use kgdb over the serial console"
+	depends on KGDB
+	select CONSOLE_POLL
+	select MAGIC_SYSRQ
+	default y
+	help
+	  Share a serial console with kgdb. Sysrq-g must be used
+	  to break in initially.
#1 lore raw
Quoted 5 lines · Ingo Molnar

From: Jason Wessel <[email protected]>

kgdb core code. Handles the protocol and the arch details.

[ [email protected]: heavily modified, simplified and cleaned up. ]

Hi Ingo.

I see that only a very few of my comments posted yesterday got addressed. On purpose or did you miss them?

Sam

#2 lore raw
Quoted 2 lines · Sam Ravnborg

I see that only a very few of my comments posted yesterday got addressed. On purpose or did you miss them?

no, they went into another thread :-)

i've now read your mail and addressed the majority of them - see the details below.

i've trickled all these fixes back to keep a clean split, test-built and test-booted the result, and updated the kgdb.git tree, which can be pulled from:

git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

updated shortlog further below. I've re-tested kgdb on x86 and it still works (as expected).

Quoted 5 lines

kernel/kgdb.c line 73

Quoted 4 lines
kernel/kgdb.c new file +4 -0
+struct debuggerinfo_struct {
+	void			*debuggerinfo;
+	struct task_struct	*task;
+} kgdb_info[NR_CPUS];

static?

fixed.

Quoted 6 lines

kernel/kgdb.c line 83

Quoted 4 lines
kernel/kgdb.c new file +4 -0
+
+/* Is a host GDB connected to us? */
+int				kgdb_connected;
+EXPORT_SYMBOL_GPL(kgdb_connected);

Drop additional spaces.
Add kernel-doc comments explaining the usage.

if you look at the resulting kernel/kgdb.c not the patch itself then you'll see that this is consistent style that aligns this variable with other fields. I agree that it looks ugly in isolation in the quote above.

Quoted 3 lines

kernel/kgdb.c line 86

Quoted 2 lines
kernel/kgdb.c new file +2 -0
+/* All the KGDB handlers are installed */
+int				kgdb_io_module_registered;

static? drop spaces.

static: fixed. Spaces: see above.

Quoted 3 lines

kernel/kgdb.c line 89

Quoted 2 lines
kernel/kgdb.c new file +2 -0
+/* Guard for recursive entry */
+static int			exception_level;

drop spaces. In more places below - but they are obvious.

really, please look at the resulting kernel/kgdb.c file. It's visually consistent.

Quoted 4 lines

kernel/kgdb.c line 100

Quoted 3 lines
kernel/kgdb.c new file +3 -0
+struct kgdb_bkpt		kgdb_break[KGDB_MAX_BREAKPOINTS] = {
+	[0 ... KGDB_MAX_BREAKPOINTS-1] = { .state = BP_UNDEFINED }
+};

static?

fixed.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+extern int pid_max;

extern must be moved to a .h file.

i did that in my series.

Quoted 2 lines
Quoted 1 line

+atomic_t kgdb_setting_breakpoint;

static?

fixed.

Quoted 1 line

Many more variables are static candidates. I will not repeat it.

i think i fixed all of them.

Quoted 4 lines
Quoted 4 lines
kernel/kgdb.c new file +4 -0
+#ifdef __BIG_ENDIAN
+		*buf++ = hexchars[(tmp_s >> 12) & 0xf];
+		*buf++ = hexchars[(tmp_s >> 8) & 0xf];
+		*buf++ = hexchars[(tmp_s >> 4) & 0xf];
Quoted 8 lines

kernel/kgdb.c line 388

Quoted 7 lines
kernel/kgdb.c new file +7 -0
+		*buf++ = hexchars[tmp_s & 0xf];
+#else
+		*buf++ = hexchars[(tmp_s >> 4) & 0xf];
+		*buf++ = hexchars[tmp_s & 0xf];
+		*buf++ = hexchars[(tmp_s >> 12) & 0xf];
+		*buf++ = hexchars[(tmp_s >> 8) & 0xf];
+#endif

small helper function?

this is already part of a small helper function. (kgdb_mem2hex())

Quoted 4 lines
Quoted 4 lines
kernel/kgdb.c new file +4 -0
+int kgdb_isremovedbreak(unsigned long addr)
+{
+	int i;
+
Quoted 8 lines

kernel/kgdb.c line 876

Quoted 7 lines
kernel/kgdb.c new file +7 -0
+	for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+		if ((kgdb_break[i].state == BP_REMOVED) &&
+					(kgdb_break[i].bpt_addr == addr))
+			return 1;
+	}
+	return 0;
+}

static?

no, needed by architectures.

Quoted 3 lines
Quoted 1 line

+int remove_all_break(void)

static?

no.

Quoted 3 lines
Quoted 1 line

+int kgdb_io_ready(int print_wait)

static?

yes, fixed.

Quoted 9 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+	bool "KGDB: kernel debugging with remote gdb"
+	select KGDB_ARCH_HAS_SHADOW_INFO if X86_64
+	select DEBUG_INFO
+	select FRAME_POINTER
+	depends on DEBUG_KERNEL && ADD_A_KGDB_ARCH

Replace ADD_A_...
with
HAVE_KGDB

fixed.

Ingo

------------------>
Ingo Molnar (3):
pids: add pid_max prototype
uaccess: add probe_kernel_write()
x86: kgdb support

Jan Kiszka (1):
consoles: polling support, kgdboc

Jason Wessel (2):
kgdb: core
kgdb: document parameters

 Documentation/kernel-parameters.txt |    5 +
 arch/x86/Kconfig                    |    4 +
 arch/x86/kernel/Makefile            |    1 +
 arch/x86/kernel/kgdb.c              |  550 ++++++++++
 drivers/char/tty_io.c               |   47 +
 drivers/serial/8250.c               |   62 ++
 drivers/serial/Kconfig              |    3 +
 drivers/serial/Makefile             |    1 +
 drivers/serial/kgdboc.c             |  164 +++
 drivers/serial/serial_core.c        |   67 ++-
 include/asm-generic/kgdb.h          |   93 ++
 include/asm-x86/kgdb.h              |   87 ++
 include/linux/kgdb.h                |  264 +++++
 include/linux/pid.h                 |    2 +
 include/linux/serial_core.h         |    4 +
 include/linux/tty_driver.h          |   12 +
 include/linux/uaccess.h             |   22 +
 kernel/Makefile                     |    1 +
 kernel/kgdb.c                       | 2020 +++++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    2 +-
 lib/Kconfig.debug                   |    2 +
 lib/Kconfig.kgdb                    |   37 +
 22 files changed, 3448 insertions(+), 2 deletions(-)
 create mode 100644 arch/x86/kernel/kgdb.c
 create mode 100644 drivers/serial/kgdboc.c
 create mode 100644 include/asm-generic/kgdb.h
 create mode 100644 include/asm-x86/kgdb.h
 create mode 100644 include/linux/kgdb.h
 create mode 100644 kernel/kgdb.c
 create mode 100644 lib/Kconfig.kgdb
#4 lore raw
Quoted 2 lines · Christoph Hellwig

This still doesn't address a lot of the review comments from Jason's last posting.

sorry, which mails are those?

Ingo

#6 lore raw
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Ingo Molnar
Quoted 2 lines · Christoph Hellwig

This still doesn't address a lot of the review comments from Jason's last posting.

Quoted 6 lines
Quoted 1 line

sorry, which mails are those?

It's all in the thread starting with '[PATCH 0/8] kgdb 2.6.25 version', msgid [email protected] or at
http://lkml.org/lkml/2008/2/9/104

thanks - i found Sam's mail meanwhile and addressed most of the observations and updated the kgdb.git tree. I'll now check the threads above whether i missed anything. (feel free to point it out if you notice anything outright) As the changes have been janitorial only i refrain from reposting the series once again. The latest shortlog is below.

Ingo

------------------>
Ingo Molnar (3):
pids: add pid_max prototype
uaccess: add probe_kernel_write()
x86: kgdb support

Jan Kiszka (1):
consoles: polling support, kgdboc

Jason Wessel (2):
kgdb: core
kgdb: document parameters

 Documentation/kernel-parameters.txt |    5 +
 arch/x86/Kconfig                    |    4 +
 arch/x86/kernel/Makefile            |    1 +
 arch/x86/kernel/kgdb.c              |  550 ++++++++++
 drivers/char/tty_io.c               |   47 +
 drivers/serial/8250.c               |   62 ++
 drivers/serial/Kconfig              |    3 +
 drivers/serial/Makefile             |    1 +
 drivers/serial/kgdboc.c             |  164 +++
 drivers/serial/serial_core.c        |   67 ++-
 include/asm-generic/kgdb.h          |   93 ++
 include/asm-x86/kgdb.h              |   87 ++
 include/linux/kgdb.h                |  264 +++++
 include/linux/pid.h                 |    2 +
 include/linux/serial_core.h         |    4 +
 include/linux/tty_driver.h          |   12 +
 include/linux/uaccess.h             |   22 +
 kernel/Makefile                     |    1 +
 kernel/kgdb.c                       | 2020 +++++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    2 +-
 lib/Kconfig.debug                   |    2 +
 lib/Kconfig.kgdb                    |   37 +
 22 files changed, 3448 insertions(+), 2 deletions(-)
 create mode 100644 arch/x86/kernel/kgdb.c
 create mode 100644 drivers/serial/kgdboc.c
 create mode 100644 include/asm-generic/kgdb.h
 create mode 100644 include/asm-x86/kgdb.h
 create mode 100644 include/linux/kgdb.h
 create mode 100644 kernel/kgdb.c
 create mode 100644 lib/Kconfig.kgdb
#7 lore raw
Quoted 11 lines · Ingo Molnar
Quoted 4 lines

It's all in the thread starting with '[PATCH 0/8] kgdb 2.6.25 version', msgid [email protected] or at
http://lkml.org/lkml/2008/2/9/104

thanks - i found Sam's mail meanwhile and addressed most of the observations and updated the kgdb.git tree. I'll now check the threads above whether i missed anything. (feel free to point it out if you notice anything outright) As the changes have been janitorial only i refrain from reposting the series once again. The latest shortlog is below.

i've read all that thread now and i think all your observations are addressed in the latest tree i posted. In fact, most of the non-syntactic observations you made i already addressed in my series from yesterday. Find the latest tree at:

git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

with tip commit 8fbf71f7636bd26843de01b4bdf819c9a9777427. Shortlog and diffstat below. I backmerged all the fixlets into their original commits, to keep the splitup clean.

Here are my replies to your feedback:

Date: Sat, 9 Feb 2008 12:10:26 -0500
From: Christoph Hellwig <[email protected]>
To: [email protected]
Subject: Re: [PATCH 2/8] pid, kgdb: add pid_max prototype

addressed.

Date: Sat, 9 Feb 2008 12:15:03 -0500
From: Christoph Hellwig <[email protected]>
Subject: Re: [PATCH 3/8] kgdb, modules: Always allow module sect info for

addressed: this was mooted by my original posting from yesterday already - i removed this complication.

Date: Sat, 9 Feb 2008 12:16:05 -0500
From: Christoph Hellwig <[email protected]>
Subject: Re: [PATCH 4/8] kgdb: COPTIMIZE flag

addressed: this was mooted by my original posting from yesterday already - i removed this complication.

Quoted 6 lines
Quoted 1 line

+ * include/asm-generic/kgdb.h

Please don't mention the file name in the top-of-file comments. This information is redundant and will easily get out of date when moving files around or copying them. Note that this applies to basically any file in this patch.

fixed.

Quoted 6 lines

include/asm-generic/kgdb.h line 24

Quoted 3 lines
include/asm-generic/kgdb.h new file +3 -0
+#ifdef CONFIG_X86
+/**
+ *	kgdb_skipexception - Bail of of KGDB when we've been triggered.

arch ifdefs don't belong into an asm-generic/ file. Please have a proper asm-x86/kgdb.h that defines these things.

addressed: this was fixed in my submission yesterday.

Quoted 2 lines

Kerneldoc comments don't belong above the prototype of a function but the function body.

disagree - the best is to have it in both places - and in many places we do that. Anyway, this is up to maintainer discretion.

Quoted 5 lines
Quoted 5 lines
include/asm-generic/kgdb.h new file +5 -0
+#ifdef CONFIG_KGDB_ARCH_HAS_SHADOW_INFO
+/**
+ *	kgdb_shadowinfo - Get shadowed information on @threadid.
+ *	@regs: The &struct pt_regs of the current process.
+ *	@buffer: A buffer of %BUFMAX size.
Quoted 8 lines

include/asm-generic/kgdb.h line 64

Quoted 4 lines

+ * @threadid: The thread id of the shadowed process to get information on.
+ */

include/asm-generic/kgdb.h new file +2 -0
+extern void kgdb_shadowinfo(struct pt_regs *regs, char *buffer,
+			    unsigned threadid);

I don't really thing this belongs into an asm-generic header, again. ARchitectures having shadow info should just provide this in their own asm-foo/kgdb.h. Or better yet just kill it for the first submission.

disagree. Many architectures will select shadow-info support so having this in asm-generic/kgdb.h is straightforward. I am actually an architecture who had to deal with this stuff in 32-bit (no shadow info support) and 64-bit (shadow info support) and this was handy and obvious. (But note that the patch submitted by Jason had a few uglinesses in this area that i fixed so please re-check the ones in my tree.)

Quoted 7 lines

kernel/kgdb.c line 73

Quoted 4 lines
kernel/kgdb.c new file +4 -0
+struct debuggerinfo_struct {
+	void			*debuggerinfo;
+	struct task_struct	*task;
+} kgdb_info[NR_CPUS];

shouldn't this use per-cpu data? Or is that in some way to fragile for a debugger?

yes, eventually we might want to use kgdb earlier than the per CPU areas are set up.

Quoted 8 lines

kernel/kgdb.c line 147

Quoted 6 lines
kernel/kgdb.c new file +6 -0
+/* reboot notifier block */
+static struct notifier_block kgdb_reboot_notifier = {
+	.notifier_call		= kgdb_notify_reboot,
+	.next			= NULL,
+	.priority		= INT_MAX,
+};

No need to initialize fields to 0 or NULL in static variables.

agreed, fixed.

Quoted 9 lines

kernel/kgdb.c line 243

Quoted 6 lines
kernel/kgdb.c new file +6 -0
+	if ((ch >= 'a') && (ch <= 'f'))
+		return ch - 'a' + 10;
+	if ((ch >= '0') && (ch <= '9'))
+		return ch - '0';
+	if ((ch >= 'A') && (ch <= 'F'))
+		return ch - 'A' + 10;

lots of superflous braces. More of them later in this file in the same style.

maintainer discretion item. I prefer having such clarity in operator ordering.

Quoted 6 lines
Quoted 6 lines
kernel/kgdb.c new file +6 -0
+#ifdef __BIG_ENDIAN
+		*buf++ = hexchars[(tmp_s >> 12) & 0xf];
+		*buf++ = hexchars[(tmp_s >> 8) & 0xf];
+		*buf++ = hexchars[(tmp_s >> 4) & 0xf];
+		*buf++ = hexchars[tmp_s & 0xf];
+#else
Quoted 8 lines

kernel/kgdb.c line 388

Quoted 5 lines
kernel/kgdb.c new file +5 -0
+		*buf++ = hexchars[(tmp_s >> 4) & 0xf];
+		*buf++ = hexchars[tmp_s & 0xf];
+		*buf++ = hexchars[(tmp_s >> 12) & 0xf];
+		*buf++ = hexchars[(tmp_s >> 8) & 0xf];
+#endif

This is really ugly, but I don't really know a good way around it either.

yeah. Agreed about the ugliness and i volunteer to implement any sensible suggestions later on :-)

Quoted 7 lines

kernel/kgdb.c line 1030

Quoted 2 lines
kernel/kgdb.c new file +2 -0
+	if (arch_kgdb_ops.shadowth &&
+			ks->kgdb_usethreadid >= pid_max + num_online_cpus()) {
	if (arch_kgdb_ops.shadowth &&
	    ks->kgdb_usethreadid >= pid_max + num_online_cpus()) {

similar odd indentation in a few other spots.

check out the full context, not just the patch. It's often done for a reason to make the full visual appearance of that particular code nice.

Quoted 5 lines

lib/Kconfig.kgdb

Quoted 3 lines
lib/Kconfig.kgdb new file +3 -0
+menuconfig KGDB
+	bool "KGDB: kernel debugging with remote gdb"
+	select KGDB_ARCH_HAS_SHADOW_INFO if X86_64

Why can't this be set in the X86_64 config?

addressed: it is in my series.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+	select DEBUG_INFO
+	select FRAME_POINTER

I think these two would be better as depends on

selecting FRAME_POINTER is totally sensible and other debugging code does it too. I agree about the DEBUG_INFO and it was addressed in yesterday's series already.

Ingo

------------------>
Ingo Molnar (3):
pids: add pid_max prototype
uaccess: add probe_kernel_write()
x86: kgdb support

Jan Kiszka (1):
consoles: polling support, kgdboc

Jason Wessel (2):
kgdb: core
kgdb: document parameters

 Documentation/kernel-parameters.txt |    5 +
 arch/x86/Kconfig                    |    4 +
 arch/x86/kernel/Makefile            |    1 +
 arch/x86/kernel/kgdb.c              |  550 ++++++++++
 drivers/char/tty_io.c               |   47 +
 drivers/serial/8250.c               |   62 ++
 drivers/serial/Kconfig              |    3 +
 drivers/serial/Makefile             |    1 +
 drivers/serial/kgdboc.c             |  164 +++
 drivers/serial/serial_core.c        |   67 ++-
 include/asm-generic/kgdb.h          |   91 ++
 include/asm-x86/kgdb.h              |   87 ++
 include/linux/kgdb.h                |  264 +++++
 include/linux/pid.h                 |    2 +
 include/linux/serial_core.h         |    4 +
 include/linux/tty_driver.h          |   12 +
 include/linux/uaccess.h             |   22 +
 kernel/Makefile                     |    1 +
 kernel/kgdb.c                       | 2019 +++++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    2 +-
 lib/Kconfig.debug                   |    2 +
 lib/Kconfig.kgdb                    |   37 +
 22 files changed, 3445 insertions(+), 2 deletions(-)
 create mode 100644 arch/x86/kernel/kgdb.c
 create mode 100644 drivers/serial/kgdboc.c
 create mode 100644 include/asm-generic/kgdb.h
 create mode 100644 include/asm-x86/kgdb.h
 create mode 100644 include/linux/kgdb.h
 create mode 100644 kernel/kgdb.c
 create mode 100644 lib/Kconfig.kgdb
#8 lore raw
Quoted 5 lines · Ingo Molnar
Quoted 2 lines

Kerneldoc comments don't belong above the prototype of a function but the function body.

disagree - the best is to have it in both places - and in many places we do that. Anyway, this is up to maintainer discretion.

Huh? In both places is the worst idea ever. It just means things will 100% sure get out of sync. And the reason why it should be at the function declaration is because that's where the kerneldoc tool picks it up.

#9 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 5 lines · Ingo Molnar
Quoted 2 lines

Kerneldoc comments don't belong above the prototype of a function but the function body.

disagree - the best is to have it in both places - and in many places we do that. Anyway, this is up to maintainer discretion.

Huh? In both places is the worst idea ever. It just means things will 100% sure get out of sync. And the reason why it should be at the function declaration is because that's where the kerneldoc tool picks it up.

Anyway, to resolve this i've turning them into non-docbook, descriptive comments. Please submit any docbook patch to arch/x86/kernel/kgdb.c to x86.git if you'd like more documentation. KGDB is already quite well documented.

Trivially updated kgdb tree can be pulled from:

git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

tip a92381ae1a93b6e3bdba60a63972d2ebd6eb73f5. Shortlog and diffstat below.

( but i believe you are missing the big picture: duplicating the same
information in all places, for functions that do _the same thing_ is pointless. It's much better to have a single, consistent set of information at the prototypes site. If docbook does not pick that up that's a docbook problem. Anyway, it's moot now with the latest tree. )

test-built and test-booted on x86.

Ingo

------------------>
Ingo Molnar (3):
pids: add pid_max prototype
uaccess: add probe_kernel_write()
x86: kgdb support

Jan Kiszka (1):
consoles: polling support, kgdboc

Jason Wessel (2):
kgdb: core
kgdb: document parameters

 Documentation/kernel-parameters.txt |    5 +
 arch/x86/Kconfig                    |    4 +
 arch/x86/kernel/Makefile            |    1 +
 arch/x86/kernel/kgdb.c              |  550 ++++++++++
 drivers/char/tty_io.c               |   47 +
 drivers/serial/8250.c               |   62 ++
 drivers/serial/Kconfig              |    3 +
 drivers/serial/Makefile             |    1 +
 drivers/serial/kgdboc.c             |  164 +++
 drivers/serial/serial_core.c        |   67 ++-
 include/asm-generic/kgdb.h          |   91 ++
 include/asm-x86/kgdb.h              |   85 ++
 include/linux/kgdb.h                |  333 ++++++
 include/linux/pid.h                 |    2 +
 include/linux/serial_core.h         |    4 +
 include/linux/tty_driver.h          |   12 +
 include/linux/uaccess.h             |   22 +
 kernel/Makefile                     |    1 +
 kernel/kgdb.c                       | 2019 +++++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    2 +-
 lib/Kconfig.debug                   |    2 +
 lib/Kconfig.kgdb                    |   37 +
 22 files changed, 3512 insertions(+), 2 deletions(-)
 create mode 100644 arch/x86/kernel/kgdb.c
 create mode 100644 drivers/serial/kgdboc.c
 create mode 100644 include/asm-generic/kgdb.h
 create mode 100644 include/asm-x86/kgdb.h
 create mode 100644 include/linux/kgdb.h
 create mode 100644 kernel/kgdb.c
 create mode 100644 lib/Kconfig.kgdb
#10 lore raw
Quoted 3 lines · Ingo Molnar

Anyway, to resolve this i've turning them into non-docbook, descriptive comments. Please submit any docbook patch to arch/x86/kernel/kgdb.c to x86.git if you'd like more documentation.

no need for that btw, i just added the docbook entries to arch/x86/kernel/kgdb.c myself and fixed all of kgdb.h. Tree is at:

git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

tip 2e3ebf25b0bd8646e517806073e1991be1fec8a2. Shortlog, diffstat and the full patch can be found below, with all relevant review feedback addressed. Builds, boots and works fine on x86.

Ingo

------------------>
Ingo Molnar (3):
pids: add pid_max prototype
uaccess: add probe_kernel_write()
x86: kgdb support

Jan Kiszka (1):
consoles: polling support, kgdboc

Jason Wessel (2):
kgdb: core
kgdb: document parameters

 Documentation/kernel-parameters.txt |    5 +
 arch/x86/Kconfig                    |    4 +
 arch/x86/kernel/Makefile            |    1 +
 arch/x86/kernel/kgdb.c              |  672 ++++++++++++
 drivers/char/tty_io.c               |   47 +
 drivers/serial/8250.c               |   62 ++
 drivers/serial/Kconfig              |    3 +
 drivers/serial/Makefile             |    1 +
 drivers/serial/kgdboc.c             |  164 +++
 drivers/serial/serial_core.c        |   67 ++-
 include/asm-generic/kgdb.h          |   91 ++
 include/asm-x86/kgdb.h              |   85 ++
 include/linux/kgdb.h                |  333 ++++++
 include/linux/pid.h                 |    2 +
 include/linux/serial_core.h         |    4 +
 include/linux/tty_driver.h          |   12 +
 include/linux/uaccess.h             |   22 +
 kernel/Makefile                     |    1 +
 kernel/kgdb.c                       | 2019 +++++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    2 +-
 lib/Kconfig.debug                   |    2 +
 lib/Kconfig.kgdb                    |   37 +
 22 files changed, 3634 insertions(+), 2 deletions(-)
 create mode 100644 arch/x86/kernel/kgdb.c
 create mode 100644 drivers/serial/kgdboc.c
 create mode 100644 include/asm-generic/kgdb.h
 create mode 100644 include/asm-x86/kgdb.h
 create mode 100644 include/linux/kgdb.h
 create mode 100644 kernel/kgdb.c
 create mode 100644 lib/Kconfig.kgdb
Documentation/kernel-parameters.txt +5 -0
index a4fc7fc..6e97307 100644
@@ -930,6 +930,11 @@ and is between 256 and 4096 characters. It is defined in the file
 	kstack=N	[X86-32,X86-64] Print N words from the kernel stack
 			in oops dumps.
 
+	kgdboc=		[HW] kgdb over consoles.
+			Requires a tty driver that supports console polling.
+			(only serial suported for now)
+			Format: <serial_device>[,baud]
+
 	l2cr=		[PPC]
 
 	lapic		[X86-32,APIC] Enable the local APIC even if BIOS
arch/x86/Kconfig +4 -0
index aaed1a3..85bcc23 100644
@@ -14,6 +14,7 @@ config X86_32
 
 config X86_64
 	def_bool 64BIT
+	select HAVE_ARCH_KGDB_SHADOW_INFO
 
 ### Arch settings
 config X86
@@ -143,6 +144,9 @@ config AUDIT_ARCH
 config ARCH_SUPPORTS_AOUT
 	def_bool y
 
+config HAVE_ARCH_KGDB
+	def_bool y
+
 # Use the generic interrupt handling code in kernel/irq/:
 config GENERIC_HARDIRQS
 	bool
arch/x86/kernel/Makefile +1 -0
index 76ec0f8..4cd39cd 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_MODULES)		+= module_$(BITS).o
 obj-$(CONFIG_ACPI_SRAT) 	+= srat_32.o
 obj-$(CONFIG_EFI) 		+= efi.o efi_$(BITS).o efi_stub_$(BITS).o
 obj-$(CONFIG_DOUBLEFAULT) 	+= doublefault_32.o
+obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_VM86)		+= vm86_32.o
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
arch/x86/kernel/kgdb.c new file +672 -0

672 lines not on this page · raw message

drivers/char/tty_io.c +47 -0

59 lines not on this page · raw message

drivers/serial/8250.c +62 -0

74 lines not on this page · raw message

drivers/serial/Kconfig +3 -0
index b82595c..5d9667c 100644
@@ -961,6 +961,9 @@ config SERIAL_CORE
 config SERIAL_CORE_CONSOLE
 	bool
 
+config CONSOLE_POLL
+	bool
+
 config SERIAL_68328
 	bool "68328 serial support"
 	depends on M68328 || M68EZ328 || M68VZ328
drivers/serial/Makefile +1 -0
index 640cfe4..1d8ee05 100644
@@ -66,4 +66,5 @@ obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
 obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o
 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
+obj-$(CONFIG_KGDBOC) += kgdboc.o
 obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
drivers/serial/kgdboc.c new file +164 -0

164 lines not on this page · raw message

drivers/serial/serial_core.c +66 -1

85 lines not on this page · raw message

include/asm-generic/kgdb.h new file +91 -0

91 lines not on this page · raw message

include/asm-x86/kgdb.h new file +85 -0

85 lines not on this page · raw message

include/linux/kgdb.h new file +333 -0

333 lines not on this page · raw message

include/linux/pid.h +2 -0
index f84d532..e066d3d 100644
@@ -86,6 +86,8 @@ extern struct task_struct *FASTCALL(get_pid_task(struct pid *pid,
 
 extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type);
 
+extern int pid_max;
+
 /*
  * attach_pid() and detach_pid() must be called with the tasklist_lock
  * write-held.
include/linux/serial_core.h +4 -0
index 1a0b6cf..7d1a46b 100644
@@ -211,6 +211,10 @@ struct uart_ops {
 	void		(*config_port)(struct uart_port *, int);
 	int		(*verify_port)(struct uart_port *, struct serial_struct *);
 	int		(*ioctl)(struct uart_port *, unsigned int, unsigned long);
+#ifdef CONFIG_CONSOLE_POLL
+	void	(*poll_put_char)(struct uart_port *, unsigned char);
+	int		(*poll_get_char)(struct uart_port *);
+#endif
 };
 
 #define UART_CONFIG_TYPE	(1 << 0)
include/linux/tty_driver.h +12 -0
index 85c95cd..21f69ac 100644
@@ -125,6 +125,7 @@
 #include <linux/cdev.h>
 
 struct tty_struct;
+struct tty_driver;
 
 struct tty_operations {
 	int  (*open)(struct tty_struct * tty, struct file * filp);
@@ -157,6 +158,11 @@ struct tty_operations {
 	int (*tiocmget)(struct tty_struct *tty, struct file *file);
 	int (*tiocmset)(struct tty_struct *tty, struct file *file,
 			unsigned int set, unsigned int clear);
+#ifdef CONFIG_CONSOLE_POLL
+	int (*poll_init)(struct tty_driver *driver, int line, char *options);
+	int (*poll_get_char)(struct tty_driver *driver, int line);
+	void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
+#endif
 };
 
 struct tty_driver {
@@ -220,6 +226,11 @@ struct tty_driver {
 	int (*tiocmget)(struct tty_struct *tty, struct file *file);
 	int (*tiocmset)(struct tty_struct *tty, struct file *file,
 			unsigned int set, unsigned int clear);
+#ifdef CONFIG_CONSOLE_POLL
+	int (*poll_init)(struct tty_driver *driver, int line, char *options);
+	int (*poll_get_char)(struct tty_driver *driver, int line);
+	void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
+#endif
 
 	struct list_head tty_drivers;
 };
@@ -230,6 +241,7 @@ struct tty_driver *alloc_tty_driver(int lines);
 void put_tty_driver(struct tty_driver *driver);
 void tty_set_operations(struct tty_driver *driver,
 			const struct tty_operations *op);
+extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
 
 /* tty driver magic number */
 #define TTY_DRIVER_MAGIC		0x5402
include/linux/uaccess.h +22 -0
index 975c963..98cfe02 100644
@@ -84,4 +84,26 @@ static inline unsigned long __copy_from_user_nocache(void *to,
 		ret;					\
 	})
 
+/**
+ * probe_kernel_write(): safely attempt to write to a location
+ * @addr: address to write to - its type is type typeof(rdval)*
+ * @rdval: write to this variable
+ *
+ * Safely write to address @addr from variable @rdval.  If a kernel fault
+ * happens, handle that and return -EFAULT.
+ */
+#define probe_kernel_write(addr, rdval)			\
+	({						\
+		long ret;				\
+		mm_segment_t old_fs = get_fs();		\
+							\
+		set_fs(KERNEL_DS);			\
+		pagefault_disable();			\
+		ret = __put_user(rdval,			\
+	 (__force typeof(rdval) __user *)(addr));	\
+		pagefault_enable();			\
+		set_fs(old_fs);				\
+		ret;					\
+	})
+
 #endif		/* __LINUX_UACCESS_H__ */
kernel/Makefile +1 -0
index 6c584c5..05c8003 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
 obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KGDB) += kgdb.o
 obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
kernel/kgdb.c new file +2019 -0

1,302 lines not on this page · raw message

kernel/sysctl.c +1 -1
index d41ef6b..97a152c 100644

Lines of this file are not shown. View the raw message.

lib/Kconfig.debug +2 -0
index a370fe8..a904916 100644

Lines of this file are not shown. View the raw message.

lib/Kconfig.kgdb new file +37 -0
new file mode 100644
index 0000000..00263c0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#11 lore raw
Quoted 6 lines · Ingo Molnar
Quoted 3 lines · Ingo Molnar

Anyway, to resolve this i've turning them into non-docbook, descriptive comments. Please submit any docbook patch to arch/x86/kernel/kgdb.c to x86.git if you'd like more documentation.

Quoted 8 lines

no need for that btw, i just added the docbook entries to arch/x86/kernel/kgdb.c myself and fixed all of kgdb.h. Tree is at:

   git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

tip 2e3ebf25b0bd8646e517806073e1991be1fec8a2. Shortlog, diffstat and the full patch can be found below, with all relevant review feedback addressed. Builds, boots and works fine on x86.

here's gdb test-output from this 2e3ebf25b0bd kernel:

(gdb) target remote /dev/ttyS0
Remote debugging using /dev/ttyS0
0x00000046 in ?? ()
(gdb) i r

eax            0x11     17
ecx            0x0      0
edx            0xf4f4   62708
ebx            0x0      0
esp            0x80d09400       0x80d09400
ebp            0xfffe37a7       0xfffe37a7
esi            0x809162d0       -2137955632
edi            0xffffffff       -1
eip            0x46     0x46
eflags         0x0      [ ]
cs             0x80d093e4       -2133814300
ss             0xffffffff       -1
ds             0x3fa6fe18       1067908632
es             0xffff8100       -32512
fs             0x3fa6fe18       1067908632
gs             0xffff8100       -32512

(gdb)

Ingo

#12 lore raw
Quoted 5 lines · Ingo Molnar
Quoted 3 lines

tip 2e3ebf25b0bd8646e517806073e1991be1fec8a2. Shortlog, diffstat and the full patch can be found below, with all relevant review feedback addressed. Builds, boots and works fine on x86.

here's gdb test-output from this 2e3ebf25b0bd kernel:

i should also mention that yesterday's tree passed 200 randconfig bootup tests on 32-bit and 64-bit x86. (i excluded CONFIG_WMI from ACPI, plus 3 other ACPI commits because they keept crashing boxes or broke the build)

Today's kgdb updates are in the trivial category so i'd not expect them to break anything, but nevertheless, out of caution i threw the latest tree into the qa mix as well and they already passed 10 randconfig bootup tests.

[ and this matches my experience with KGDB stability in the last few
months while we carried and tested it in x86.git: even the old, much wider-scope and uglier/riskier patches that hooked in a lot of places never broke anything unrelated (or anything in fact) - and this matches kgdb's -mm track record as well. ]

Ingo

#13 lore raw
In reply to Ingo Molnar

drivers/serial/8250.c static inline void wait_for_xmitr(struct uart_8250_port *up, int bits) · line 1775

Quoted 5 lines
drivers/serial/8250.c +5 -0
+#ifdef UART_CAP_UUE
+	if (up->capabilities & UART_CAP_UUE)
+#else
+	if (up->port.type == PORT_XSCALE)
+#endif

This looks very odd. Can anyone explain what's going on here? Especially as UART_CAP_UUE is defined in drivers/serial/8250.h unconditionally.

drivers/serial/kgdboc.c line 2

Quoted 8 lines
drivers/serial/kgdboc.c new file +2 -0
new file mode 100644
index 0000000..5079d32
@@ -0,0 +1,164 @@
+/*
+ * drivers/serial/kgdboc.c

Didn't you say there was no file left with these?

include/asm-generic/kgdb.h

Quoted 5 lines
include/asm-generic/kgdb.h new file +0 -0
new file mode 100644
index 0000000..115972e

Didn't you agree to kill this file in one of the last mails?

include/asm-generic/kgdb.h

Quoted 8 lines
include/asm-generic/kgdb.h new file +8 -0
+#ifndef __ASSEMBLY__
+static inline void arch_kgdb_breakpoint(void)
+{
+	asm("   int $3");
+}
+# define BREAK_INSTR_SIZE	1
+# define CACHE_FLUSH_IS_SAFE	1
+#endif

this ifdef should go away.

include/asm-generic/kgdb.h

Quoted 2 lines
include/asm-generic/kgdb.h new file +2 -0
+#endif				/* _ASM_KGDB_H_ */
+#endif				/* __KERNEL__ */

and the __KERNEL__ aswell as these files are in no way exported to userspace.

include/asm-generic/kgdb.h line 74

Quoted 11 lines
include/asm-generic/kgdb.h new file +11 -0
+/*
+ *	kgdb_get_shadow_thread - Get the shadowed &task_struct of @threadid.
+ *	@regs: The &struct pt_regs of the current thread.
+ *	@threadid: The thread id of the shadowed process to get information on.
+ *
+ *	RETURN:
+ *	This returns a pointer to the &struct task_struct of the shadowed
+ *	thread, @threadid.
+ */
+extern struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs,
+						  int threadid);

So we have kerneldoc comments in both places now? Didn't you say you converted these to something else?

include/asm-generic/kgdb.h line 2

Quoted 4 lines

+++ b/kernel/kgdb.c

include/asm-generic/kgdb.h new file +2 -0
@@ -0,0 +1,2019 @@
+/*
+ * kernel/kgdb.c

Another one.

#14 lore raw

PATCH 1/1 kgdb light, v6

Quoted 9 lines · Christoph Hellwig

Review

Quoted 5 lines
(quoted diff) +5 -0
+#ifdef UART_CAP_UUE
+	if (up->capabilities & UART_CAP_UUE)
+#else
+	if (up->port.type == PORT_XSCALE)
+#endif

This looks very odd. Can anyone explain what's going on here? Especially as UART_CAP_UUE is defined in drivers/serial/8250.h unconditionally.

sharp eyes! This is embedded crap leftover :) Fixed.

Quoted 3 lines
Quoted 1 line

+ * drivers/serial/kgdboc.c

Didn't you say there was no file left with these?

fixed. (i meant no include file originally)

I also removed it from kernel/kgdb.c.

Quoted 3 lines
Quoted 1 line

+++ b/include/asm-generic/kgdb.h

Didn't you agree to kill this file in one of the last mails?

yes, it's killed.

Quoted 10 lines

Review

Quoted 8 lines
(quoted diff) +8 -0
+#ifndef __ASSEMBLY__
+static inline void arch_kgdb_breakpoint(void)
+{
+	asm("   int $3");
+}
+# define BREAK_INSTR_SIZE	1
+# define CACHE_FLUSH_IS_SAFE	1
+#endif

this ifdef should go away.

yes, done.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#endif				/* _ASM_KGDB_H_ */
+#endif				/* __KERNEL__ */

and the __KERNEL__ aswell as these files are in no way exported to userspace.

fixed.

Quoted 6 lines
Quoted 6 lines

+/*
+ * kgdb_get_shadow_thread - Get the shadowed &task_struct of @threadid.
+ * @regs: The &struct pt_regs of the current thread.
+ * @threadid: The thread id of the shadowed process to get information on.
+ *
+ * RETURN:

Quoted 8 lines

Review

Quoted 5 lines

+ * This returns a pointer to the &struct task_struct of the shadowed
+ * thread, @threadid.
+ */

(quoted diff) +2 -0
+extern struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs,
+						  int threadid);

So we have kerneldoc comments in both places now? Didn't you say you converted these to something else?

no. These are not DocBook comments, if you look carefully at the format [it's not a leading '/**' comment block]. But obviously documenting this in the include file is very useful, because that's where people look first, so i kept it. (the APIs will not deviate across architectures)

all fixes are backmerged and the result is uploaded. Tree against latest -git can be pulled from:

git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

not surpringly it builds, boots and works just fine :-)

Updated shortlog, diffstat and patches below.

Ingo

------------------>
Ingo Molnar (3):
pids: add pid_max prototype
uaccess: add probe_kernel_write()
x86: kgdb support

Jason Wessel (3):
kgdb: core
consoles: polling support, kgdboc
kgdb: document parameters

 Documentation/kernel-parameters.txt |    5 +
 arch/x86/Kconfig                    |    2 +
 arch/x86/kernel/Makefile            |    1 +
 arch/x86/kernel/kgdb.c              |  672 ++++++++++++
 drivers/char/tty_io.c               |   47 +
 drivers/serial/8250.c               |   58 +
 drivers/serial/Kconfig              |    3 +
 drivers/serial/Makefile             |    1 +
 drivers/serial/kgdboc.c             |  162 +++
 drivers/serial/serial_core.c        |   71 ++-
 include/asm-x86/kgdb.h              |   81 ++
 include/linux/kgdb.h                |  329 ++++++
 include/linux/pid.h                 |    2 +
 include/linux/serial_core.h         |    4 +
 include/linux/tty_driver.h          |   12 +
 include/linux/uaccess.h             |   22 +
 kernel/Makefile                     |    1 +
 kernel/kgdb.c                       | 2002 +++++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    2 +-
 lib/Kconfig.debug                   |    2 +
 lib/Kconfig.kgdb                    |   40 +
 21 files changed, 3515 insertions(+), 4 deletions(-)
 create mode 100644 arch/x86/kernel/kgdb.c
 create mode 100644 drivers/serial/kgdboc.c
 create mode 100644 include/asm-x86/kgdb.h
 create mode 100644 include/linux/kgdb.h
 create mode 100644 kernel/kgdb.c
 create mode 100644 lib/Kconfig.kgdb
Documentation/kernel-parameters.txt +5 -0
index a4fc7fc..6e97307 100644
@@ -930,6 +930,11 @@ and is between 256 and 4096 characters. It is defined in the file
 	kstack=N	[X86-32,X86-64] Print N words from the kernel stack
 			in oops dumps.
 
+	kgdboc=		[HW] kgdb over consoles.
+			Requires a tty driver that supports console polling.
+			(only serial suported for now)
+			Format: <serial_device>[,baud]
+
 	l2cr=		[PPC]
 
 	lapic		[X86-32,APIC] Enable the local APIC even if BIOS
arch/x86/Kconfig +2 -0
index aaed1a3..5e0fab5 100644
@@ -14,6 +14,7 @@ config X86_32
 
 config X86_64
 	def_bool 64BIT
+	select HAVE_ARCH_KGDB_SHADOW_INFO
 
 ### Arch settings
 config X86
@@ -21,6 +22,7 @@ config X86
 	select HAVE_IDE
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_ARCH_KGDB
 
 config GENERIC_LOCKBREAK
 	def_bool n
arch/x86/kernel/Makefile +1 -0
index 76ec0f8..4cd39cd 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_MODULES)		+= module_$(BITS).o
 obj-$(CONFIG_ACPI_SRAT) 	+= srat_32.o
 obj-$(CONFIG_EFI) 		+= efi.o efi_$(BITS).o efi_stub_$(BITS).o
 obj-$(CONFIG_DOUBLEFAULT) 	+= doublefault_32.o
+obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_VM86)		+= vm86_32.o
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
arch/x86/kernel/kgdb.c new file +672 -0

672 lines not on this page · raw message

drivers/char/tty_io.c +47 -0

59 lines not on this page · raw message

drivers/serial/8250.c +58 -0

70 lines not on this page · raw message

drivers/serial/Kconfig +3 -0
index b82595c..5d9667c 100644
@@ -961,6 +961,9 @@ config SERIAL_CORE
 config SERIAL_CORE_CONSOLE
 	bool
 
+config CONSOLE_POLL
+	bool
+
 config SERIAL_68328
 	bool "68328 serial support"
 	depends on M68328 || M68EZ328 || M68VZ328
drivers/serial/Makefile +1 -0
index 640cfe4..3cbea54 100644
@@ -66,4 +66,5 @@ obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
 obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o
 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
+obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
 obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
drivers/serial/kgdboc.c new file +162 -0

162 lines not on this page · raw message

drivers/serial/serial_core.c +68 -3

101 lines not on this page · raw message

include/asm-x86/kgdb.h new file +81 -0

81 lines not on this page · raw message

include/linux/kgdb.h new file +329 -0

329 lines not on this page · raw message

include/linux/pid.h +2 -0
index f84d532..e066d3d 100644
@@ -86,6 +86,8 @@ extern struct task_struct *FASTCALL(get_pid_task(struct pid *pid,
 
 extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type);
 
+extern int pid_max;
+
 /*
  * attach_pid() and detach_pid() must be called with the tasklist_lock
  * write-held.
include/linux/serial_core.h +4 -0
index 1a0b6cf..7d1a46b 100644
@@ -211,6 +211,10 @@ struct uart_ops {
 	void		(*config_port)(struct uart_port *, int);
 	int		(*verify_port)(struct uart_port *, struct serial_struct *);
 	int		(*ioctl)(struct uart_port *, unsigned int, unsigned long);
+#ifdef CONFIG_CONSOLE_POLL
+	void	(*poll_put_char)(struct uart_port *, unsigned char);
+	int		(*poll_get_char)(struct uart_port *);
+#endif
 };
 
 #define UART_CONFIG_TYPE	(1 << 0)
include/linux/tty_driver.h +12 -0
index 85c95cd..21f69ac 100644
@@ -125,6 +125,7 @@
 #include <linux/cdev.h>
 
 struct tty_struct;
+struct tty_driver;
 
 struct tty_operations {
 	int  (*open)(struct tty_struct * tty, struct file * filp);
@@ -157,6 +158,11 @@ struct tty_operations {
 	int (*tiocmget)(struct tty_struct *tty, struct file *file);
 	int (*tiocmset)(struct tty_struct *tty, struct file *file,
 			unsigned int set, unsigned int clear);
+#ifdef CONFIG_CONSOLE_POLL
+	int (*poll_init)(struct tty_driver *driver, int line, char *options);
+	int (*poll_get_char)(struct tty_driver *driver, int line);
+	void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
+#endif
 };
 
 struct tty_driver {
@@ -220,6 +226,11 @@ struct tty_driver {
 	int (*tiocmget)(struct tty_struct *tty, struct file *file);
 	int (*tiocmset)(struct tty_struct *tty, struct file *file,
 			unsigned int set, unsigned int clear);
+#ifdef CONFIG_CONSOLE_POLL
+	int (*poll_init)(struct tty_driver *driver, int line, char *options);
+	int (*poll_get_char)(struct tty_driver *driver, int line);
+	void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
+#endif
 
 	struct list_head tty_drivers;
 };
@@ -230,6 +241,7 @@ struct tty_driver *alloc_tty_driver(int lines);
 void put_tty_driver(struct tty_driver *driver);
 void tty_set_operations(struct tty_driver *driver,
 			const struct tty_operations *op);
+extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
 
 /* tty driver magic number */
 #define TTY_DRIVER_MAGIC		0x5402
include/linux/uaccess.h +22 -0
index 975c963..98cfe02 100644
@@ -84,4 +84,26 @@ static inline unsigned long __copy_from_user_nocache(void *to,
 		ret;					\
 	})
 
+/**
+ * probe_kernel_write(): safely attempt to write to a location
+ * @addr: address to write to - its type is type typeof(rdval)*
+ * @rdval: write to this variable
+ *
+ * Safely write to address @addr from variable @rdval.  If a kernel fault
+ * happens, handle that and return -EFAULT.
+ */
+#define probe_kernel_write(addr, rdval)			\
+	({						\
+		long ret;				\
+		mm_segment_t old_fs = get_fs();		\
+							\
+		set_fs(KERNEL_DS);			\
+		pagefault_disable();			\
+		ret = __put_user(rdval,			\
+	 (__force typeof(rdval) __user *)(addr));	\
+		pagefault_enable();			\
+		set_fs(old_fs);				\
+		ret;					\
+	})
+
 #endif		/* __LINUX_UACCESS_H__ */
kernel/Makefile +1 -0
index 6c584c5..05c8003 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
 obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KGDB) += kgdb.o
 obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
kernel/kgdb.c new file +2002 -0

1,376 lines not on this page · raw message

kernel/sysctl.c +1 -1
index d41ef6b..97a152c 100644

Lines of this file are not shown. View the raw message.

lib/Kconfig.debug +2 -0
index a370fe8..a904916 100644

Lines of this file are not shown. View the raw message.

lib/Kconfig.kgdb new file +40 -0
new file mode 100644
index 0000000..a739e9d

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#15 lore raw

Re: [patch] kgdb light, v6

On Sunday 10 February 2008, Ingo Molnar wrote:

[...]

Quoted 15 lines
Quoted 6 lines
Quoted 6 lines

+/*
+ * kgdb_get_shadow_thread - Get the shadowed &task_struct of @threadid.
+ * @regs: The &struct pt_regs of the current thread.
+ * @threadid: The thread id of the shadowed process to get information on.
+ *
+ * RETURN:

Quoted 8 lines

Review

Quoted 5 lines

+ * This returns a pointer to the &struct task_struct of the shadowed
+ * thread, @threadid.
+ */

(quoted diff) +2 -0
+extern struct task_struct *kgdb_get_shadow_thread(struct pt_regs *regs,
+						  int threadid);

So we have kerneldoc comments in both places now? Didn't you say you converted these to something else?

Quoted 4 lines

no. These are not DocBook comments, if you look carefully at the format [it's not a leading '/**' comment block]. But obviously documenting this in the include file is very useful, because that's where people look first, so i kept it. (the APIs will not deviate across architectures)

comments and variable names in include files have a tendency for going out-of-sync in the long term so IMO having a DocBook to point people at would be a better solution (+ it would shrink <linux/kgdb.h> by 122 lines)

while at it:

kgdb.h renamed from kernel/kgdb.c +5 -3
@@ -128,11 +131,13 @@
  *	process more packets, and a %0 or %1 if it wants to exit from the
  *	kgdb callback.
  */
-int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
-			       char *remcomInBuffer, char *remcomOutBuffer,
-			       struct pt_regs *linux_regs)
+extern int
+kgdb_arch_handle_exception(int vector, int signo, int err_code,
+			   char *remcom_in_buffer,
+			   char *remcom_out_buffer,
+			   struct pt_regs *regs);
#16 lore raw

Re: [patch] kgdb light, v6

Quoted 10 lines · Bartlomiej Zolnierkiewicz
Quoted 5 lines

no. These are not DocBook comments, if you look carefully at the format [it's not a leading '/**' comment block]. But obviously documenting this in the include file is very useful, because that's where people look first, so i kept it. (the APIs will not deviate across architectures)

comments and variable names in include files have a tendency for going out-of-sync in the long term so IMO having a DocBook to point people at would be a better solution (+ it would shrink <linux/kgdb.h> by 122 lines)

yes, i very much agree in general, but this is a _SPECIAL CASE_, and i already tried to point that out to Christoph but he's not the type of guy who listens to others all that easily when it comes to his pet peeves ;-)

this is a special case because it's an _architecture facility_.

read: right now we have 25 architectures, and this means that in a year we'll have 25 arch/*/kernel/kgdb.c files. What will be more likely to get out of sync, 25 full sets of DocBook entries of the same thing, spread across 25 architectures - or that lone single include/linux/kgdb.h file that is looked at by everyone? And what will be easier to update if we extend any of the APIs?

so the DocBook rules are fine, but in this SPECIAL CASE they cause the possibly worst solution: total information anarchy!

the correct approach is to put the _arch specific_ details into the arch/*/kernel/kgdb.c files, and to keep the generic bits in include/linux/kgdb.h. KGDB did exactly that and it's by far the cleanest and most maintainable approach.

If DocBook does not pick that up then it's a _DocBook problem_. I dont mind adding some dummy weak aliases to kernel/kgdb.c for DocBook to pick up, to help solve this DocBook problem - but to blame it on KGDB is way off the mark. It used to be the crappiest piece of sh*t everyone would laugh about when looking at (right before suffering permanent brain damage), but now it's one of the cleanest and most CodingStyle conform kernel subsystems :-)

case in point:

errors lines of code errors/KLOC
kernel/kgdb.c 0 1839 0
fs/xfs/ 2102 106019 19.8

right, XFS has more than 2 thousand bona fide CodingStyle violations!

But yeah, it has the luxory of upstream integration ... ;-)

[ not that i want to pick on XFS - it's a very clean codebase in my
opinion, considering its fundamental complexity. It's just that anyone who wants to find a style error in KGDB now has to search _hard_ ;-) ]

Ingo

#17 lore raw

Re: [patch] kgdb light, v6

In reply to Ingo Molnar

few minor issues (some may have been addressed already)

On Sunday 10 February 2008, Ingo Molnar wrote:

[...]

Quoted 5 lines
arch/x86/kernel/kgdb.c new file +0 -0
new file mode 100644
index 0000000..7130273

[...]

arch/x86/kernel/kgdb.c line 194

Quoted 11 lines
arch/x86/kernel/kgdb.c new file +11 -0
+static struct hw_breakpoint {
+	unsigned		enabled;
+	unsigned		type;
+	unsigned		len;
+	unsigned long		addr;
+} breakinfo[4] = {
+	{ .enabled = 0 },
+	{ .enabled = 0 },
+	{ .enabled = 0 },
+	{ .enabled = 0 },
+};

is this initialization really needed? the whole thing is static anyway

Quoted 23 lines
arch/x86/kernel/kgdb.c new file +23 -0
+static void kgdb_correct_hw_break(void)
+{
+	unsigned long dr7;
+	int correctit = 0;
+	int breakbit;
+	int breakno;
+
+	get_debugreg(dr7, 7);
+	for (breakno = 0; breakno < 4; breakno++) {
+		breakbit = 2 << (breakno << 1);
+		if (!(dr7 & breakbit) && breakinfo[breakno].enabled) {
+			correctit = 1;
+			dr7 |= breakbit;
+			dr7 &= ~(0xf0000 << (breakno << 2));
+			dr7 |= ((breakinfo[breakno].len << 2) |
+				 breakinfo[breakno].type) <<
+			       ((breakno << 2) + 16);
+			switch (breakno) {
+			case 0:
+				set_debugreg(breakinfo[0].addr, 0);
+				break;
+
+			case 1:

arch/x86/kernel/kgdb.c line 228

Quoted 10 lines
arch/x86/kernel/kgdb.c new file +10 -0
+				set_debugreg(breakinfo[1].addr, 1);
+				break;
+
+			case 2:
+				set_debugreg(breakinfo[2].addr, 2);
+				break;
+
+			case 3:
+				set_debugreg(breakinfo[3].addr, 3);
+				break;
			if (breakno >= 0 && breakno <= 3)
				set_debugreg(breakinfo[breakno].addr, breakno);

[...]

arch/x86/kernel/kgdb.c line 617

Quoted 10 lines
arch/x86/kernel/kgdb.c new file +10 -0
+/**
+ *	kgdb_arch_init - Perform any architecture specific initalization.
+ *
+ *	This function will handle the initalization of any architecture
+ *	specific callbacks.
+ */
+int kgdb_arch_init(void)
+{
+	register_die_notifier(&kgdb_notifier);
+	return 0;

return register_die_notifier();

[...]

Quoted 5 lines
drivers/serial/kgdboc.c new file +0 -0
new file mode 100644
index 0000000..a5d2d00

[...]

drivers/serial/kgdboc.c line 27

Quoted 2 lines
drivers/serial/kgdboc.c new file +2 -0
+MODULE_DESCRIPTION("KGDB Console TTY Driver");
+MODULE_LICENSE("GPL");

should be at the bottom of the file

drivers/serial/kgdboc.c line 37

Quoted 10 lines
drivers/serial/kgdboc.c new file +10 -0
+static char config[MAX_KGDB_SERIAL_CONSOLE_CONFIG_STR];
+static struct kparam_string kps = {
+	.string			= config,
+	.maxlen			= MAX_KGDB_SERIAL_CONSOLE_CONFIG_STR,
+};
+
+static struct tty_driver	*kgdb_tty_driver;
+static int			kgdb_tty_line;
+
+static int kgdboc_option_setup(char *opt)

__init

drivers/serial/kgdboc.c line 47

Quoted 10 lines
drivers/serial/kgdboc.c new file +10 -0
+{
+	if (strlen(opt) > MAX_KGDB_SERIAL_CONSOLE_CONFIG_STR) {
+		printk(KERN_ERR "kgdboc: config string too long\n");
+		return -ENOSPC;
+	}
+	strcpy(config, opt);
+
+	return 0;
+}
+__setup("kgdboc=", kgdboc_option_setup);

no need for obsolete __setup, we have module_param_call() below

Quoted 1 line

+static int configure_kgdboc(void)

__init

Quoted 24 lines
drivers/serial/kgdboc.c new file +24 -0
+{
+	struct tty_driver *p;
+	int tty_line = 0;
+	int err;
+
+	err = kgdboc_option_setup(config);
+	if (err || !strlen(config) || isspace(config[0]))
+		goto noconfig;
+
+	err = -ENODEV;
+
+	p = tty_find_polling_driver(config, &tty_line);
+	if (!p)
+		goto noconfig;
+
+	kgdb_tty_driver = p;
+	kgdb_tty_line = tty_line;
+
+	err = kgdb_register_io_module(&kgdboc_io_ops);
+	if (err)
+		goto noconfig;
+
+	configured = 1;
+

drivers/serial/kgdboc.c line 83

Quoted 10 lines
drivers/serial/kgdboc.c new file +10 -0
+	return 0;
+
+noconfig:
+	config[0] = 0;
+	configured = 0;
+
+	return err;
+}
+
+static int init_kgdboc(void)

__init

drivers/serial/kgdboc.c line 92

Quoted 9 lines
drivers/serial/kgdboc.c new file +9 -0
+{
+	/* Already configured? */
+	if (configured == 1)
+		return 0;
+
+	return configure_kgdboc();
+}
+
+static void cleanup_kgdboc(void)

I would suggest __exit but it can be called from param_set_kgdboc_var()

[ I have a feeling that somethings is wrong with this but I'm too lazy
to read the code in depth... ]

Quoted 4 lines
drivers/serial/serial_core.c +0 -0
index 0f5a179..a72116a 100644

[...]

drivers/serial/serial_core.c

Quoted 2 lines
drivers/serial/serial_core.c +2 -0
+#ifdef CONFIG_CONSOLE_POLL
+

unnecessary new line

[...]

Quoted 6 lines
include/linux/kgdb.h new file +0 -0
new file mode 100644
index 0000000..7f4ee55
@@ -0,0 +1,329 @@

[...]

include/linux/kgdb.h line 133

Quoted 2 lines
include/linux/kgdb.h new file +2 -0
+/* The maximum number of KGDB I/O modules that can be loaded */
+#define KGDB_MAX_IO_HANDLERS	3

unused

include/linux/kgdb.h line 139

Quoted 5 lines
include/linux/kgdb.h new file +5 -0
+#ifndef KGDB_MAX_BREAKPOINTS
+# define KGDB_MAX_BREAKPOINTS	1000
+#endif
+
+#define KGDB_HW_BREAKPOINT	1

unused

[...]

Quoted 8 lines

+/*
+ * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
+ * @name: Name of the I/O driver.
+ * @read_char: Pointer to a function that will return one char.
+ * @write_char: Pointer to a function that will write one char.
+ * @flush: Pointer to a function that will flush any pending writes.
+ * @init: Pointer to a function that will initialize the device.
+ * @late_init: Pointer to a function that will do any setup that has

there is no late_init in the structure

Quoted 25 lines

+ * other dependencies.
+ * @pre_exception: Pointer to a function that will do any prep work for
+ * the I/O driver.
+ * @post_exception: Pointer to a function that will do any cleanup work
+ * for the I/O driver.
+ *
+ * The @init and @late_init function pointers allow for an I/O driver
+ * such as a serial driver to fully initialize the port with @init and
+ * be called very early, yet safely call request_irq() later in the boot
+ * sequence.
+ *
+ * @init is allowed to return a non-0 return value to indicate failure.
+ * If this is called early on, then KGDB will try again when it would call
+ * @late_init. If it has failed later in boot as well, the user will be
+ * notified.
+ */

include/linux/kgdb.h new file +9 -0
+struct kgdb_io {
+	const char		*name;
+	int			(*read_char) (void);
+	void			(*write_char) (u8);
+	void			(*flush) (void);
+	int			(*init) (void);
+	void			(*pre_exception) (void);
+	void			(*post_exception) (void);
+};

[...]

Quoted 5 lines
kernel/kgdb.c new file +0 -0
new file mode 100644
index 0000000..b5dd949

[...]

Quoted 18 lines
kernel/kgdb.c new file +18 -0
+/*
+ * SW breakpoint management:
+ */
+static int kgdb_activate_sw_breakpoints(void)
+{
+	unsigned long addr;
+	int error = 0;
+	int i;
+
+	for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+		if (kgdb_break[i].state != BP_SET)
+			continue;
+
+		addr = kgdb_break[i].bpt_addr;
+		error = kgdb_arch_set_breakpoint(addr,
+				kgdb_break[i].saved_instr);
+		if (error)
+			return error;

kernel/kgdb.c line 748

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+
+		if (CACHE_FLUSH_IS_SAFE) {
+			if (current->mm && addr < TASK_SIZE) {
+				flush_cache_range(current->mm->mmap_cache,
+						addr, addr + BREAK_INSTR_SIZE);
+			} else {
+				flush_icache_range(addr, addr +
+						BREAK_INSTR_SIZE);
+			}
+		}

identical cache flushing code is present in
kgdb_deactivate_sw_breakpoints() below

maybe it would make sense to have some common helper

Quoted 16 lines
kernel/kgdb.c new file +16 -0
+		kgdb_break[i].state = BP_ACTIVE;
+	}
+	return 0;
+}
+
+static int kgdb_set_sw_break(unsigned long addr)
+{
+	int error = kgdb_validate_break_address(addr);
+	int breakno = -1;
+	int i;
+
+	if (error < 0)
+		return error;
+
+	for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+		if ((kgdb_break[i].state == BP_SET) &&

kernel/kgdb.c line 774

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+					(kgdb_break[i].bpt_addr == addr))
+			return -EEXIST;
+	}
+	for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+		if (kgdb_break[i].state == BP_REMOVED &&
+					kgdb_break[i].bpt_addr == addr) {
+			breakno = i;
+			break;
+		}
+	}

if kgdb_isremovedbreak() helper is moved before kgdb_set_sw_break() and converted to return 'i' on success and '-1' on failure then it can be used instead the above for () loop

Quoted 45 lines
kernel/kgdb.c new file +45 -0
+
+	if (breakno == -1) {
+		for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+			if (kgdb_break[i].state == BP_UNDEFINED) {
+				breakno = i;
+				break;
+			}
+		}
+	}
+
+	if (breakno == -1)
+		return -E2BIG;
+
+	kgdb_break[breakno].state = BP_SET;
+	kgdb_break[breakno].type = BP_BREAKPOINT;
+	kgdb_break[breakno].bpt_addr = addr;
+
+	return 0;
+}
+
+static int kgdb_deactivate_sw_breakpoints(void)
+{
+	unsigned long addr;
+	int error = 0;
+	int i;
+
+	for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+		if (kgdb_break[i].state != BP_ACTIVE)
+			continue;
+		addr = kgdb_break[i].bpt_addr;
+		error = kgdb_arch_remove_breakpoint(addr,
+					kgdb_break[i].saved_instr);
+		if (error)
+			return error;
+
+		if (CACHE_FLUSH_IS_SAFE && current->mm &&
+				addr < TASK_SIZE) {
+			flush_cache_range(current->mm->mmap_cache,
+					addr, addr + BREAK_INSTR_SIZE);
+		} else if (CACHE_FLUSH_IS_SAFE) {
+			flush_icache_range(addr, addr + BREAK_INSTR_SIZE);
+		}
+		kgdb_break[i].state = BP_SET;
+	}
+	return 0;

kernel/kgdb.c line 829

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+}
+
+static int kgdb_remove_sw_break(unsigned long addr)
+{
+	int i;
+
+	for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+		if ((kgdb_break[i].state == BP_SET) &&
+				(kgdb_break[i].bpt_addr == addr)) {
+			kgdb_break[i].state = BP_REMOVED;

it would make a sense to have to have kgdb_isset() helper to use here and in kgdb_set_sw_break()

Quoted 7 lines
kernel/kgdb.c new file +7 -0
+			return 0;
+		}
+	}
+	return -ENOENT;
+}
+
+int kgdb_isremovedbreak(unsigned long addr)

kernel/kgdb.c line 846

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+{
+	int i;
+
+	for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+		if ((kgdb_break[i].state == BP_REMOVED) &&
+					(kgdb_break[i].bpt_addr == addr))
+			return 1;
+	}
+	return 0;
+}

Thanks,
Bart

#18 lore raw

Re: [patch] kgdb light, v6

Quoted 9 lines · Bartlomiej Zolnierkiewicz

arch/x86/kernel/kgdb.c line 194

Quoted 6 lines
arch/x86/kernel/kgdb.c new file +6 -0
+} breakinfo[4] = {
+	{ .enabled = 0 },
+	{ .enabled = 0 },
+	{ .enabled = 0 },
+	{ .enabled = 0 },
+};

is this initialization really needed? the whole thing is static anyway

good point! It's not needed at all: fixed.

Quoted 6 lines

arch/x86/kernel/kgdb.c line 228

Quoted 3 lines
arch/x86/kernel/kgdb.c new file +3 -0
+			case 3:
+				set_debugreg(breakinfo[3].addr, 3);
+				break;
			if (breakno >= 0 && breakno <= 3)
				set_debugreg(breakinfo[breakno].addr, breakno);

nice! I've added your simplification.

Quoted 7 lines

arch/x86/kernel/kgdb.c line 617

Quoted 5 lines

+ */

arch/x86/kernel/kgdb.c new file +4 -0
+int kgdb_arch_init(void)
+{
+	register_die_notifier(&kgdb_notifier);
+	return 0;

return register_die_notifier();

agreed - done. (btw., for kicks i checked kernel/notifier.c - register_die_notifier() never fails and always returns 0!)

Quoted 6 lines

[...]

drivers/serial/kgdboc.c line 27

Quoted 2 lines
drivers/serial/kgdboc.c new file +2 -0
+MODULE_DESCRIPTION("KGDB Console TTY Driver");
+MODULE_LICENSE("GPL");

should be at the bottom of the file

agreed - i moved it.

Quoted 3 lines
Quoted 1 line

+static int kgdboc_option_setup(char *opt)

__init

done.

Quoted 3 lines
Quoted 1 line

+__setup("kgdboc=", kgdboc_option_setup);

no need for obsolete __setup, we have module_param_call() below

it's needed for bzImage kernels. I just tested it and without __setup() no init sequence is run and KGDB is not activated.

Quoted 3 lines
Quoted 1 line

+static int configure_kgdboc(void)

__init

ok, done.

Quoted 3 lines
Quoted 1 line

+static int init_kgdboc(void)

__init

done.

Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+#ifdef CONFIG_CONSOLE_POLL
+

unnecessary new line

(that is a personal taste/style thing - to me it simply looks more readable if there's an empty line before function declarations.)

Quoted 4 lines

include/linux/kgdb.h line 133

Quoted 2 lines
include/linux/kgdb.h new file +2 -0
+/* The maximum number of KGDB I/O modules that can be loaded */
+#define KGDB_MAX_IO_HANDLERS	3

unused

good - zapped it.

Quoted 7 lines

include/linux/kgdb.h line 139

Quoted 5 lines
include/linux/kgdb.h new file +5 -0
+#ifndef KGDB_MAX_BREAKPOINTS
+# define KGDB_MAX_BREAKPOINTS	1000
+#endif
+
+#define KGDB_HW_BREAKPOINT	1

unused

hm, both KGDB_MAX_BREAKPOINTS and KGDB_HW_BREAKPOINT are used.

Quoted 3 lines
Quoted 1 line

+ * @late_init: Pointer to a function that will do any setup that has

there is no late_init in the structure

zapped it.

Quoted 4 lines

identical cache flushing code is present in
kgdb_deactivate_sw_breakpoints() below

maybe it would make sense to have some common helper

agreed. Incidentally, while looking at uaccess patterns i noticed this and i've already written one: kgdb_flush_swbreak_addr().

Quoted 3 lines

if kgdb_isremovedbreak() helper is moved before kgdb_set_sw_break() and converted to return 'i' on success and '-1' on failure then it can be used instead the above for () loop

dunno - that would complicate arch/x86/kernel/kgdb.c's use of kgdb_isremovedbreak() and looks a bit complex. If you feel strongly about it, could you send a patch?

in any case, thanks Bartlomiej for the many very useful comments, i fixed all of the the things you noticed in my current tree.

Ingo

#19 lore raw

Re: [patch] kgdb light, v6

Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line

+static int init_kgdboc(void)

__init

done.

Uuh, careful. We need this for runtime reconfiguration.

Jan

#20 lore raw

Re: [patch] kgdb light, v6

Quoted 8 lines · Jan Kiszka
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line

+static int init_kgdboc(void)

__init

done.

Uuh, careful. We need this for runtime reconfiguration.

it is used only for 'module_init(init_kgdboc);' in v6

#21 lore raw

Re: [patch] kgdb light, v6

Quoted 9 lines · Bartlomiej Zolnierkiewicz
Quoted 6 lines · Jan Kiszka
Quoted 4 lines · Ingo Molnar
Quoted 2 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line

+static int init_kgdboc(void)

__init

done.

Uuh, careful. We need this for runtime reconfiguration.

it is used only for 'module_init(init_kgdboc);' in v6

Yeah, the usage chain is not obvious (given I'm looking at the right version ATM - git just spits at me), the issue moved to param_set_kgdboc_var which has to call into configure_kgdboc - now __init.

Ingo, please keep the original annotations, they where correct and should have been optimal (under the given constraints or runtime reconfiguration).

Jan

#22 lore raw

Re: [patch] kgdb light, v6

Quoted 3 lines · Jan Kiszka

Ingo, please keep the original annotations, they where correct and should have been optimal (under the given constraints or runtime reconfiguration).

agreed. I've regenerated the -v7 tree with this trivial revert. Tip is commit 04b94b1dd5197bf737073ebbd4189ffdfdcea534, updated shortlog, diffstat and patch can be found below. Tree is at:

git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

Ingo

------------------>
Ingo Molnar (3):
pids: add pid_max prototype
uaccess: add probe_kernel_write()
x86: kgdb support

Jason Wessel (3):
kgdb: core
consoles: polling support, kgdboc
kgdb: document parameters

 Documentation/kernel-parameters.txt |    5 +
 arch/x86/Kconfig                    |    2 +
 arch/x86/kernel/Makefile            |    1 +
 arch/x86/kernel/kgdb.c              |  654 +++++++++++++
 drivers/char/tty_io.c               |   47 +
 drivers/serial/8250.c               |   58 ++
 drivers/serial/Kconfig              |    3 +
 drivers/serial/Makefile             |    1 +
 drivers/serial/kgdboc.c             |  163 +++
 drivers/serial/serial_core.c        |   70 ++-
 include/asm-x86/kgdb.h              |   81 ++
 include/linux/kgdb.h                |  314 ++++++
 include/linux/pid.h                 |    2 +
 include/linux/serial_core.h         |    4 +
 include/linux/tty_driver.h          |   12 +
 include/linux/uaccess.h             |   22 +
 kernel/Makefile                     |    1 +
 kernel/kgdb.c                       | 1838 +++++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    2 +-
 lib/Kconfig.debug                   |    2 +
 lib/Kconfig.kgdb                    |   40 +
 mm/Makefile                         |    2 +-
 mm/maccess.c                        |   49 +
 23 files changed, 3368 insertions(+), 5 deletions(-)
 create mode 100644 arch/x86/kernel/kgdb.c
 create mode 100644 drivers/serial/kgdboc.c
 create mode 100644 include/asm-x86/kgdb.h
 create mode 100644 include/linux/kgdb.h
 create mode 100644 kernel/kgdb.c
 create mode 100644 lib/Kconfig.kgdb
 create mode 100644 mm/maccess.c
Documentation/kernel-parameters.txt +5 -0
index a4fc7fc..6e97307 100644
@@ -930,6 +930,11 @@ and is between 256 and 4096 characters. It is defined in the file
 	kstack=N	[X86-32,X86-64] Print N words from the kernel stack
 			in oops dumps.
 
+	kgdboc=		[HW] kgdb over consoles.
+			Requires a tty driver that supports console polling.
+			(only serial suported for now)
+			Format: <serial_device>[,baud]
+
 	l2cr=		[PPC]
 
 	lapic		[X86-32,APIC] Enable the local APIC even if BIOS
arch/x86/Kconfig +2 -0
index aaed1a3..5e0fab5 100644
@@ -14,6 +14,7 @@ config X86_32
 
 config X86_64
 	def_bool 64BIT
+	select HAVE_ARCH_KGDB_SHADOW_INFO
 
 ### Arch settings
 config X86
@@ -21,6 +22,7 @@ config X86
 	select HAVE_IDE
 	select HAVE_OPROFILE
 	select HAVE_KPROBES
+	select HAVE_ARCH_KGDB
 
 config GENERIC_LOCKBREAK
 	def_bool n
arch/x86/kernel/Makefile +1 -0
index 76ec0f8..4cd39cd 100644
@@ -58,6 +58,7 @@ obj-$(CONFIG_MODULES)		+= module_$(BITS).o
 obj-$(CONFIG_ACPI_SRAT) 	+= srat_32.o
 obj-$(CONFIG_EFI) 		+= efi.o efi_$(BITS).o efi_stub_$(BITS).o
 obj-$(CONFIG_DOUBLEFAULT) 	+= doublefault_32.o
+obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_VM86)		+= vm86_32.o
 obj-$(CONFIG_EARLY_PRINTK)	+= early_printk.o
 
arch/x86/kernel/kgdb.c new file +654 -0

654 lines not on this page · raw message

drivers/char/tty_io.c +47 -0

59 lines not on this page · raw message

drivers/serial/8250.c +58 -0

70 lines not on this page · raw message

drivers/serial/Kconfig +3 -0
index b82595c..5d9667c 100644
@@ -961,6 +961,9 @@ config SERIAL_CORE
 config SERIAL_CORE_CONSOLE
 	bool
 
+config CONSOLE_POLL
+	bool
+
 config SERIAL_68328
 	bool "68328 serial support"
 	depends on M68328 || M68EZ328 || M68VZ328
drivers/serial/Makefile +1 -0
index 640cfe4..3cbea54 100644
@@ -66,4 +66,5 @@ obj-$(CONFIG_SERIAL_UARTLITE) += uartlite.o
 obj-$(CONFIG_SERIAL_NETX) += netx-serial.o
 obj-$(CONFIG_SERIAL_OF_PLATFORM) += of_serial.o
 obj-$(CONFIG_SERIAL_KS8695) += serial_ks8695.o
+obj-$(CONFIG_KGDB_SERIAL_CONSOLE) += kgdboc.o
 obj-$(CONFIG_SERIAL_QE) += ucc_uart.o
drivers/serial/kgdboc.c new file +163 -0

163 lines not on this page · raw message

drivers/serial/serial_core.c +67 -3

100 lines not on this page · raw message

include/asm-x86/kgdb.h new file +81 -0

81 lines not on this page · raw message

include/linux/kgdb.h new file +314 -0

314 lines not on this page · raw message

include/linux/pid.h +2 -0
index f84d532..e066d3d 100644
@@ -86,6 +86,8 @@ extern struct task_struct *FASTCALL(get_pid_task(struct pid *pid,
 
 extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type);
 
+extern int pid_max;
+
 /*
  * attach_pid() and detach_pid() must be called with the tasklist_lock
  * write-held.
include/linux/serial_core.h +4 -0
index 1a0b6cf..7d1a46b 100644
@@ -211,6 +211,10 @@ struct uart_ops {
 	void		(*config_port)(struct uart_port *, int);
 	int		(*verify_port)(struct uart_port *, struct serial_struct *);
 	int		(*ioctl)(struct uart_port *, unsigned int, unsigned long);
+#ifdef CONFIG_CONSOLE_POLL
+	void	(*poll_put_char)(struct uart_port *, unsigned char);
+	int		(*poll_get_char)(struct uart_port *);
+#endif
 };
 
 #define UART_CONFIG_TYPE	(1 << 0)
include/linux/tty_driver.h +12 -0
index 85c95cd..21f69ac 100644
@@ -125,6 +125,7 @@
 #include <linux/cdev.h>
 
 struct tty_struct;
+struct tty_driver;
 
 struct tty_operations {
 	int  (*open)(struct tty_struct * tty, struct file * filp);
@@ -157,6 +158,11 @@ struct tty_operations {
 	int (*tiocmget)(struct tty_struct *tty, struct file *file);
 	int (*tiocmset)(struct tty_struct *tty, struct file *file,
 			unsigned int set, unsigned int clear);
+#ifdef CONFIG_CONSOLE_POLL
+	int (*poll_init)(struct tty_driver *driver, int line, char *options);
+	int (*poll_get_char)(struct tty_driver *driver, int line);
+	void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
+#endif
 };
 
 struct tty_driver {
@@ -220,6 +226,11 @@ struct tty_driver {
 	int (*tiocmget)(struct tty_struct *tty, struct file *file);
 	int (*tiocmset)(struct tty_struct *tty, struct file *file,
 			unsigned int set, unsigned int clear);
+#ifdef CONFIG_CONSOLE_POLL
+	int (*poll_init)(struct tty_driver *driver, int line, char *options);
+	int (*poll_get_char)(struct tty_driver *driver, int line);
+	void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
+#endif
 
 	struct list_head tty_drivers;
 };
@@ -230,6 +241,7 @@ struct tty_driver *alloc_tty_driver(int lines);
 void put_tty_driver(struct tty_driver *driver);
 void tty_set_operations(struct tty_driver *driver,
 			const struct tty_operations *op);
+extern struct tty_driver *tty_find_polling_driver(char *name, int *line);
 
 /* tty driver magic number */
 #define TTY_DRIVER_MAGIC		0x5402
include/linux/uaccess.h +22 -0
index 975c963..fec6dec 100644
@@ -84,4 +84,26 @@ static inline unsigned long __copy_from_user_nocache(void *to,
 		ret;					\
 	})
 
+/*
+ * probe_kernel_read(): safely attempt to read from a location
+ * @dst: pointer to the buffer that shall take the data
+ * @src: address to read from
+ * @size: size of the data chunk
+ *
+ * Safely read from address @src to the buffer at @dst.  If a kernel fault
+ * happens, handle that and return -EFAULT.
+ */
+extern long probe_kernel_read(void *dst, void *src, size_t size);
+
+/*
+ * probe_kernel_write(): safely attempt to write to a location
+ * @dst: address to write to
+ * @src: pointer to the data that shall be written
+ * @size: size of the data chunk
+ *
+ * Safely write to address @dst from the buffer at @src.  If a kernel fault
+ * happens, handle that and return -EFAULT.
+ */
+extern long probe_kernel_write(void *dst, void *src, size_t size);
+
 #endif		/* __LINUX_UACCESS_H__ */
kernel/Makefile +1 -0
index 6c584c5..05c8003 100644
@@ -53,6 +53,7 @@ obj-$(CONFIG_AUDIT) += audit.o auditfilter.o
 obj-$(CONFIG_AUDITSYSCALL) += auditsc.o
 obj-$(CONFIG_AUDIT_TREE) += audit_tree.o
 obj-$(CONFIG_KPROBES) += kprobes.o
+obj-$(CONFIG_KGDB) += kgdb.o
 obj-$(CONFIG_DETECT_SOFTLOCKUP) += softlockup.o
 obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
kernel/kgdb.c new file +1838 -0

1,426 lines not on this page · raw message

kernel/sysctl.c +1 -1
index d41ef6b..97a152c 100644

Lines of this file are not shown. View the raw message.

lib/Kconfig.debug +2 -0
index a370fe8..a904916 100644

Lines of this file are not shown. View the raw message.

lib/Kconfig.kgdb new file +40 -0
new file mode 100644
index 0000000..a739e9d

Lines of this file are not shown. View the raw message.

mm/Makefile +1 -1
index 9f117ba..fb9e7ac 100644

Lines of this file are not shown. View the raw message.

mm/maccess.c new file +49 -0

49 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#23 lore raw

Re: [patch] kgdb light, v6

Quoted 7 lines · Ingo Molnar
Quoted 3 lines · Jan Kiszka

Ingo, please keep the original annotations, they where correct and should have been optimal (under the given constraints or runtime reconfiguration).

Quoted 6 lines

agreed. I've regenerated the -v7 tree with this trivial revert. Tip is commit 04b94b1dd5197bf737073ebbd4189ffdfdcea534, updated shortlog, diffstat and patch can be found below. Tree is at:

git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

something related or not.

my server doesn't have serial connector. the SP has serial port to host's internal serial port.
I need to ssh to SP ( service processor) and start console there.

wonder if there is program that is running on SP, and one program on develop workstation --- make it have one virtual serial port

gdb or other legacy serial port program could use that virtual serial port.

YH

#24 lore raw

Re: [patch] kgdb light, v6

In reply to Jan Kiszka
Quoted 8 lines · Jan Kiszka
Quoted 5 lines · Ingo Molnar
Quoted 2 lines · Bartlomiej Zolnierkiewicz
Quoted 1 line

+static int init_kgdboc(void)

__init

done.

Uuh, careful. We need this for runtime reconfiguration.

i think v7 is fine.

worst-case we'll get a nice fat section warning :-)

Ingo

#25 lore raw

Re: [patch] kgdb light, v6

In reply to Ingo Molnar

On Sunday 10 February 2008, Ingo Molnar wrote:

[...]

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+__setup("kgdboc=", kgdboc_option_setup);

no need for obsolete __setup, we have module_param_call() below

it's needed for bzImage kernels. I just tested it and without __setup() no init sequence is run and KGDB is not activated.

weird, should work with "kgdboc.kgdboc=" parameter

[...]

Quoted 9 lines
Quoted 7 lines

include/linux/kgdb.h line 139

Quoted 5 lines
include/linux/kgdb.h new file +5 -0
+#ifndef KGDB_MAX_BREAKPOINTS
+# define KGDB_MAX_BREAKPOINTS	1000
+#endif
+
+#define KGDB_HW_BREAKPOINT	1

unused

hm, both KGDB_MAX_BREAKPOINTS and KGDB_HW_BREAKPOINT are used.

my bad

[...]

Quoted 6 lines
Quoted 3 lines

if kgdb_isremovedbreak() helper is moved before kgdb_set_sw_break() and converted to return 'i' on success and '-1' on failure then it can be used instead the above for () loop

dunno - that would complicate arch/x86/kernel/kgdb.c's use of kgdb_isremovedbreak() and looks a bit complex. If you feel strongly

the whole difference w.r.t. arch/x86/kernel/kgdb.c should be:

- if (exception == 3 && kgdb_isremovedbreak(regs->ip - 1)) {
+ if (exception == 3 && kgdb_isremovedbreak(regs->ip - 1) >= 0) {

Quoted 1 line

about it, could you send a patch?

well, maybe in the future if nobody fixes it :)

[ added as low-prio to my TODO... ]

Thanks for fixing all the other stuff.

Bart

#26 lore raw
In reply to Ingo Molnar
Quoted 6 lines · Ingo Molnar

thanks - i found Sam's mail meanwhile and addressed most of the observations and updated the kgdb.git tree. I'll now check the threads above whether i missed anything. (feel free to point it out if you notice anything outright) As the changes have been janitorial only i refrain from reposting the series once again. The latest shortlog is below.

It would be nice if you could move the kerneldoc comments to the proper place at least. And while you're at it please remove all the filenames in the top-of-file comments, not just in include/asm-generic/kgdb.h.

While we're at it is there a good reason to have that file at all, it's just function prototypes, and I'd say for now they should just go into linux/kgdb.h. If there's a a good reason why architectures should implement them as inlines we can move them back, but looking at the x86 implementation I doubt that's the case.

Also it seems at least some of Jan's patches are missing aswell.

I think we really shouldn't rush this too much. Let's wait until Monday at least when Jason and Jan are back.

#27 lore raw
Quoted 2 lines · Christoph Hellwig

[...] And while you're at it please remove all the filenames in the top-of-file comments, not just in include/asm-generic/kgdb.h.

fixed: there was just one such file remaining: include/linux/kgdb.h.

Quoted 5 lines

While we're at it is there a good reason to have that file at all, it's just function prototypes, and I'd say for now they should just go into linux/kgdb.h. If there's a a good reason why architectures should implement them as inlines we can move them back, but looking at the x86 implementation I doubt that's the case.

agreed, done.

Quoted 10 lines · Ingo Molnar
Quoted 6 lines

thanks - i found Sam's mail meanwhile and addressed most of the observations and updated the kgdb.git tree. I'll now check the threads above whether i missed anything. (feel free to point it out if you notice anything outright) As the changes have been janitorial only i refrain from reposting the series once again. The latest shortlog is below.

It would be nice if you could move the kerneldoc comments to the proper place at least. [...]

i'd agree in general but this is really a special case, please look at the context. This would duplicate all the kerneldoc headers for all architectures. We'd have to move the same kerneldoc header to all architecture arch/*/kernel/kgdb.c files. It's much nicer in asm-generic/kgdb.h.

Quoted 1 line

Also it seems at least some of Jan's patches are missing aswell.

i dont think so. Which ones do you mean? I just reviewed them and they are either already done, or moot (for kgdb complications that i objected to and removed from this kgdb-x86 tree).

anyway, i've implemented all these (trivial) tweaks you just mentioned and re-tested on 32-bit and 64-bit x86, backmerged the fixes to their proper places, and pushed the clean series out again to:

git://git.kernel.org/pub/scm/linux/kernel/git/mingo/linux-2.6-kgdb.git

tip e6ba396b65e2f08afb5d8924140b126427085203. Shortlog below.

Ingo

------------------>
Ingo Molnar (3):
pids: add pid_max prototype
uaccess: add probe_kernel_write()
x86: kgdb support

Jan Kiszka (1):
consoles: polling support, kgdboc

Jason Wessel (2):
kgdb: core
kgdb: document parameters

 Documentation/kernel-parameters.txt |    5 +
 arch/x86/Kconfig                    |    4 +
 arch/x86/kernel/Makefile            |    1 +
 arch/x86/kernel/kgdb.c              |  550 ++++++++++
 drivers/char/tty_io.c               |   47 +
 drivers/serial/8250.c               |   62 ++
 drivers/serial/Kconfig              |    3 +
 drivers/serial/Makefile             |    1 +
 drivers/serial/kgdboc.c             |  164 +++
 drivers/serial/serial_core.c        |   67 ++-
 include/asm-generic/kgdb.h          |   91 ++
 include/asm-x86/kgdb.h              |   85 ++
 include/linux/kgdb.h                |  333 ++++++
 include/linux/pid.h                 |    2 +
 include/linux/serial_core.h         |    4 +
 include/linux/tty_driver.h          |   12 +
 include/linux/uaccess.h             |   22 +
 kernel/Makefile                     |    1 +
 kernel/kgdb.c                       | 2019 +++++++++++++++++++++++++++++++++++
 kernel/sysctl.c                     |    2 +-
 lib/Kconfig.debug                   |    2 +
 lib/Kconfig.kgdb                    |   37 +
 22 files changed, 3512 insertions(+), 2 deletions(-)
 create mode 100644 arch/x86/kernel/kgdb.c
 create mode 100644 drivers/serial/kgdboc.c
 create mode 100644 include/asm-generic/kgdb.h
 create mode 100644 include/asm-x86/kgdb.h
 create mode 100644 include/linux/kgdb.h
 create mode 100644 kernel/kgdb.c
 create mode 100644 lib/Kconfig.kgdb
#28 lore raw
Quoted 8 lines · Ingo Molnar
Quoted 2 lines

It would be nice if you could move the kerneldoc comments to the proper place at least. [...]

i'd agree in general but this is really a special case, please look at the context. This would duplicate all the kerneldoc headers for all architectures. We'd have to move the same kerneldoc header to all architecture arch/*/kernel/kgdb.c files. It's much nicer in asm-generic/kgdb.h.

Well, the point of kerneldoc comments is that they're reasily extractable. If you want to document the arch interface a pure text document in Documentation/ might be a better choice.

Quoted 5 lines
Quoted 1 line

Also it seems at least some of Jan's patches are missing aswell.

i dont think so. Which ones do you mean? I just reviewed them and they are either already done, or moot (for kgdb complications that i objected to and removed from this kgdb-x86 tree).

The one I noticed quickly is the __ASSEMBLY__ removal from asm-x86/kgdb.h. I haven't looked at the serial bits because I don't think I'm qualified to comment on those, but I'm also not seeing any replies to any of his patches. Especially the comments on the arch interface seem like something that should be acted upon to me.

#29 lore raw
Quoted 6 lines · Christoph Hellwig
Quoted 3 lines

i dont think so. Which ones do you mean? I just reviewed them and they are either already done, or moot (for kgdb complications that i objected to and removed from this kgdb-x86 tree).

The one I noticed quickly is the __ASSEMBLY__ removal from asm-x86/kgdb.h. [...]

people might want to experiment with early debug code as well and include asm-x86/kgdb.h in assembly files. So i kept that, it's sensible.

Quoted 4 lines

[...] I haven't looked at the serial bits because I don't think I'm qualified to comment on those, but I'm also not seeing any replies to any of his patches. Especially the comments on the arch interface seem like something that should be acted upon to me.

yeah - i also noticed that the serial subsystem is marked "orphaned" in the MAINTAINERS file:

8250/16?50 (AND CLONE UARTS) SERIAL DRIVER

 L:      [email protected]
 W:      http://serial.sourceforge.net
 S:      Orphan

and compared to the raw-lowlevel-serial-driver hackery that KGDB used to do this is a big step forward. Note that it's all dependent on CONFIG_KGDB.

Ingo

#30 lore raw
Quoted 5 lines · Ingo Molnar
Quoted 2 lines

The one I noticed quickly is the __ASSEMBLY__ removal from asm-x86/kgdb.h. [...]

people might want to experiment with early debug code as well and include asm-x86/kgdb.h in assembly files. So i kept that, it's sensible.

But asm-x86/kgdb.h doesn't have anythign people invoking kgdb might need, it's just the arch interface to the kgdb core. Nor does it compile even with the ifdef as it already contains a C enum.

#31 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Ingo Molnar
Quoted 2 lines

The one I noticed quickly is the __ASSEMBLY__ removal from asm-x86/kgdb.h. [...]

people might want to experiment with early debug code as well and include asm-x86/kgdb.h in assembly files. So i kept that, it's sensible.

But asm-x86/kgdb.h doesn't have anythign people invoking kgdb might need, it's just the arch interface to the kgdb core. Nor does it compile even with the ifdef as it already contains a C enum.

good point - i fixed this. (by following your suggestion of removing the _ASSEMBLY_)

Ingo

#32 lore raw
In reply to Ingo Molnar

kernel/kgdb.c line 471

Quoted 11 lines · Ingo Molnar
kernel/kgdb.c new file +11 -0
+	} else {
+		while (count-- > 0) {
+			unsigned char ch;
+
+			if (probe_kernel_address(mem, ch)) {
+				kgdb_may_fault = 0;
+				return ERR_PTR(-EINVAL);
+			}
+			mem++;
+			*buf++ = hexchars[ch >> 4];
+			*buf++ = hexchars[ch & 0xf];

use pack_hex_byte?

Quoted 11 lines
kernel/kgdb.c new file +11 -0
+/*
+ * While we find nice hex chars, build a long_val.
+ * Return number of chars processed.
+ */
+int kgdb_hex2long(char **ptr, long *long_val)
+{
+	int hex_val;
+	int num = 0;
+
+	*long_val = 0;
+

kernel/kgdb.c line 600

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+	while (**ptr) {
+		hex_val = hex(**ptr);
+		if (hex_val >= 0) {
+			*long_val = (*long_val << 4) | hex_val;
+			num++;
+		} else
+			break;
+
+		(*ptr)++;
+	}

if (hex_val < 0)

	break;

*long_val = (*long_val << 4) | hex_val;
num++;
(*ptr)++;

Quoted 18 lines
kernel/kgdb.c new file +18 -0
+/*
+ * SW breakpoint management:
+ */
+static int kgdb_activate_sw_breakpoints(void)
+{
+	unsigned long addr;
+	int error = 0;
+	int i;
+
+	for (i = 0; i < KGDB_MAX_BREAKPOINTS; i++) {
+		if (kgdb_break[i].state != BP_SET)
+			continue;
+
+		addr = kgdb_break[i].bpt_addr;
+		error = kgdb_arch_set_breakpoint(addr,
+				kgdb_break[i].saved_instr);
+		if (error)
+			return error;

kernel/kgdb.c line 778

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+
+		if (CACHE_FLUSH_IS_SAFE) {
+			if (current->mm && addr < TASK_SIZE) {
+				flush_cache_range(current->mm->mmap_cache,
+						addr, addr + BREAK_INSTR_SIZE);
+			} else {
+				flush_icache_range(addr, addr +
+						BREAK_INSTR_SIZE);
+			}
+		}

unneeded braces (here and in many other places)

Quoted 12 lines
kernel/kgdb.c new file +12 -0
+/* Handle the '?' status packets */
+static void gdb_cmd_status(struct kgdb_state *ks)
+{
+	/*
+	 * We know that this packet is only sent
+	 * during initial connect.  So to be safe,
+	 * we clear out our breakpoints now in case
+	 * GDB is reconnecting.
+	 */
+	remove_all_break();
+
+	/*

kernel/kgdb.c line 995

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+	 * Also, if we haven't been able to roundup all
+	 * CPUs, send an 'O' packet informing the user
+	 * as much.  Only need to do this once.
+	 */
+	if (!ks->all_cpus_synced)
+		kgdb_msg_write("Not all CPUs have been synced for KGDB\n", 39);
+
+	remcom_out_buffer[0] = 'S';
+	remcom_out_buffer[1] = hexchars[ks->signo >> 4];
+	remcom_out_buffer[2] = hexchars[ks->signo % 16];

use pack_hex_byte or & 0xf

Quoted 8 lines
kernel/kgdb.c new file +8 -0
+		if (ks->threadid < pid_max) {
+			kgdb_mem2hex(getthread(ks->linux_regs,
+					ks->threadid)->comm,
+					remcom_out_buffer, 16);
+		} else {
+			if (ks->threadid >= pid_max + num_online_cpus()) {
+				kgdb_shadowinfo(ks->linux_regs,
+					remcom_out_buffer,

kernel/kgdb.c line 1243

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+					ks->threadid - pid_max -
+					num_online_cpus());
+			} else {
+				static char tmpstr[23 + BUF_THREAD_ID_SIZE];
+				sprintf(tmpstr, "Shadow task %d for pid 0",
+						(int)(ks->threadid - pid_max));
+				kgdb_mem2hex(tmpstr, remcom_out_buffer,
+							 strlen(tmpstr));
+			}
+		}

if ()
else if ()
else

will look better

kernel/kgdb.c line 1333

Quoted 4 lines
kernel/kgdb.c new file +4 -0
+	if (*(ptr++) != ',') {
+		error_packet(remcom_out_buffer, -EINVAL);
+		return;
+	} else {

no else needed

kernel/kgdb.c line 1344

Quoted 11 lines
kernel/kgdb.c new file +11 -0
+		if (kgdb_hex2long(&ptr, &addr)) {
+			if (*(ptr++) != ',' ||
+				!kgdb_hex2long(&ptr, &length)) {
+				error_packet(remcom_out_buffer, -EINVAL);
+				return;
+			}
+		} else {
+			error_packet(remcom_out_buffer, -EINVAL);
+			return;
+		}
+	}
if (!kgdb_hex2long()) {
	error_packet();
	return;
}

if (*(ptr++) (...))
(...)

Marcin

#33 lore raw
Quoted 1 line · Marcin Slusarz

On Sun, Feb 10, 2008 at 08:13:31AM +0100, Ingo Molnar wrote:

...

Quoted 10 lines

kernel/kgdb.c line 778

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+
+             if (CACHE_FLUSH_IS_SAFE) {
+                     if (current->mm && addr < TASK_SIZE) {
+                             flush_cache_range(current->mm->mmap_cache,
+                                             addr, addr + BREAK_INSTR_SIZE);
+                     } else {
+                             flush_icache_range(addr, addr +
+                                             BREAK_INSTR_SIZE);
+                     }
+             }
Quoted 2 lines

unneeded braces (here and in many other places)

While they are not strictly needed, I for one would argue they should probably stay.

if (foo)
bar();

is not always safe in case bar() is a macro.

if (foo) {
bar();
}

is always safe and is more robust when the code gets changed later since you don't accidentally end up with someone mistakenly turning it into

if (foo)
bar();
baz();

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#34 lore raw
Quoted 16 lines · Jesper Juhl
Quoted 1 line · Marcin Slusarz

On Sun, Feb 10, 2008 at 08:13:31AM +0100, Ingo Molnar wrote:

...

Quoted 10 lines

kernel/kgdb.c line 778

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+
+             if (CACHE_FLUSH_IS_SAFE) {
+                     if (current->mm && addr < TASK_SIZE) {
+                             flush_cache_range(current->mm->mmap_cache,
+                                             addr, addr + BREAK_INSTR_SIZE);
+                     } else {
+                             flush_icache_range(addr, addr +
+                                             BREAK_INSTR_SIZE);
+                     }
+             }
Quoted 2 lines

unneeded braces (here and in many other places)

Quoted 7 lines

While they are not strictly needed, I for one would argue they should probably stay.

if (foo)
bar();

is not always safe in case bar() is a macro.

then fix this broken macro and leave calling code alone

Quoted 7 lines

is always safe and is more robust when the code gets changed later since you don't accidentally end up with someone mistakenly turning it into

if (foo)
bar();
baz();

following coding style and reading code before submission will catch this kind of bugs

Marcin

#35 lore raw
In reply to Marcin Slusarz
Quoted 13 lines · Marcin Slusarz

kernel/kgdb.c line 471

Quoted 11 lines · Ingo Molnar
kernel/kgdb.c new file +11 -0
+	} else {
+		while (count-- > 0) {
+			unsigned char ch;
+
+			if (probe_kernel_address(mem, ch)) {
+				kgdb_may_fault = 0;
+				return ERR_PTR(-EINVAL);
+			}
+			mem++;
+			*buf++ = hexchars[ch >> 4];
+			*buf++ = hexchars[ch & 0xf];

use pack_hex_byte?

Good point! kgdb introduces this helper but don't use it consequently!

Quoted 22 lines
Quoted 11 lines
kernel/kgdb.c new file +11 -0
+/*
+ * While we find nice hex chars, build a long_val.
+ * Return number of chars processed.
+ */
+int kgdb_hex2long(char **ptr, long *long_val)
+{
+	int hex_val;
+	int num = 0;
+
+	*long_val = 0;
+

kernel/kgdb.c line 600

Quoted 10 lines
kernel/kgdb.c new file +10 -0
+	while (**ptr) {
+		hex_val = hex(**ptr);
+		if (hex_val >= 0) {
+			*long_val = (*long_val << 4) | hex_val;
+			num++;
+		} else
+			break;
+
+		(*ptr)++;
+	}

if (hex_val < 0)

Quoted 4 lines
	break;

*long_val = (*long_val << 4) | hex_val;
num++;
(*ptr)++;

Jep, will include this in the cleanup patch I'm currently baking.

Jan

#36 lore raw
In reply to Marcin Slusarz
Quoted 10 lines · Marcin Slusarz

kernel/kgdb.c line 778

Quoted 9 lines
kernel/kgdb.c new file +9 -0
+		if (CACHE_FLUSH_IS_SAFE) {
+			if (current->mm && addr < TASK_SIZE) {
+				flush_cache_range(current->mm->mmap_cache,
+						addr, addr + BREAK_INSTR_SIZE);
+			} else {
+				flush_icache_range(addr, addr +
+						BREAK_INSTR_SIZE);
+			}
+		}

unneeded braces (here and in many other places)

this is a small detail, but you are wrong. These braces around multi-line statements are unneded _for the compiler_, but are very much wanted by humans. You'll see akpm, me and others reject/fix patches on a routine basis that make this cleanliness mistake. Please watch out for this when writing patches ;-)

Quoted 5 lines

if ()
else if ()
else

will look better

nope. I consciously avoid that construct because it's dangerous: it can quite easily result in the wrong logic. Having _more_ braces than needed by the compiler is a style error in only a single, special case.

Quoted 5 lines

kernel/kgdb.c line 1333

Quoted 4 lines
kernel/kgdb.c new file +4 -0
+	if (*(ptr++) != ',') {
+		error_packet(remcom_out_buffer, -EINVAL);
+		return;
+	} else {

no else needed

agreed - fixed.

Quoted 4 lines
if (!kgdb_hex2long()) {
	error_packet();
	return;
}

fixed.

Ingo

#37 lore raw
Quoted 24 lines · Ingo Molnar
Quoted 10 lines · Marcin Slusarz

kernel/kgdb.c line 778

Quoted 9 lines
kernel/kgdb.c new file +9 -0
+		if (CACHE_FLUSH_IS_SAFE) {
+			if (current->mm && addr < TASK_SIZE) {
+				flush_cache_range(current->mm->mmap_cache,
+						addr, addr + BREAK_INSTR_SIZE);
+			} else {
+				flush_icache_range(addr, addr +
+						BREAK_INSTR_SIZE);
+			}
+		}

unneeded braces (here and in many other places)

this is a small detail, but you are wrong. These braces around multi-line statements are unneded _for the compiler_, but are very much wanted by humans. You'll see akpm, me and others reject/fix patches on a routine basis that make this cleanliness mistake. Please watch out for this when writing patches ;-)

Quoted 4 lines

if ()
else if ()
else

Quoted 5 lines
Quoted 1 line

will look better

nope. I consciously avoid that construct because it's dangerous: it can quite easily result in the wrong logic. Having _more_ braces than needed by the compiler is a style error in only a single, special case.

however it can be still made to:

if () {
	if ()
	else
}

[ not fixed in v6 ]

#38 lore raw
In reply to Marcin Slusarz
Quoted 5 lines · Marcin Slusarz

if (hex_val < 0)

	break;

*long_val = (*long_val << 4) | hex_val;
num++;
(*ptr)++;

agreed, fixed.

Quoted 4 lines

kernel/kgdb.c line 995

Quoted 3 lines
kernel/kgdb.c new file +3 -0
+	remcom_out_buffer[0] = 'S';
+	remcom_out_buffer[1] = hexchars[ks->signo >> 4];
+	remcom_out_buffer[2] = hexchars[ks->signo % 16];

use pack_hex_byte or & 0xf

fixed.

Ingo