From: "Jan Beulich" <JBeulich@novell.com>
To: "Andreas Kleen" <ak@suse.de>
Cc: <linux-kernel@vger.kernel.org>, <discuss@x86-64.org>
Subject: [PATCH 18/39] NLKD/x86-64 - INT1/INT3 handling changes
Date: Wed, 09 Nov 2005 15:13:15 +0100 [thread overview]
Message-ID: <4372120B.76F0.0078.0@novell.com> (raw)
In-Reply-To: 437210D1.76F0.0078.0@novell.com
[-- Attachment #1: Type: text/plain, Size: 543 bytes --]
This
- switches the INT3 handler to run on an IST stack (to cope with
breakpoints set by a kernel debugger on places where the kernel's
%gs base hasn't been set up, yet); the IST stack used is shared with
the INT1 handler's
- allows nesting of INT1/INT3 handlers so that one can, with a kernel
debugger, debug (at least) the user-mode portions of the INT1/INT3
handling; the nesting isn't actively enabled here since a kernel-
debugger-free kernel doesn't need it
From: Jan Beulich <jbeulich@novell.com>
(actual patch attached)
[-- Attachment #2: linux-2.6.14-nlkd-x86_64-debug-stack.patch --]
[-- Type: application/octet-stream, Size: 8981 bytes --]
This
- switches the INT3 handler to run on an IST stack (to cope with
breakpoints set by a kernel debugger on places where the kernel's
%gs base hasn't been set up, yet); the IST stack used is shared with
the INT1 handler's
- allows nesting of INT1/INT3 handlers so that one can, with a kernel
debugger, debug (at least) the user-mode portions of the INT1/INT3
handling; the nesting isn't actively enabled here since a kernel-
debugger-free kernel doesn't need it
From: Jan Beulich <jbeulich@novell.com>
Index: 2.6.14-nlkd/arch/x86_64/kernel/asm-offsets.c
===================================================================
--- 2.6.14-nlkd.orig/arch/x86_64/kernel/asm-offsets.c 2005-11-09 11:18:26.000000000 +0100
+++ 2.6.14-nlkd/arch/x86_64/kernel/asm-offsets.c 2005-11-04 17:14:08.000000000 +0100
@@ -64,5 +64,10 @@ int main(void)
DEFINE(pbe_address, offsetof(struct pbe, address));
DEFINE(pbe_orig_address, offsetof(struct pbe, orig_address));
DEFINE(pbe_next, offsetof(struct pbe, next));
+ BLANK();
+ DEFINE(EXCEPTION_STACK_SIZE, EXCEPTION_STKSZ);
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+ DEFINE(DEBUG_IST, DEBUG_STACK);
+#endif
return 0;
}
Index: 2.6.14-nlkd/arch/x86_64/kernel/entry.S
===================================================================
--- 2.6.14-nlkd.orig/arch/x86_64/kernel/entry.S 2005-11-09 11:18:26.000000000 +0100
+++ 2.6.14-nlkd/arch/x86_64/kernel/entry.S 2005-11-09 10:45:26.000000000 +0100
@@ -685,7 +685,10 @@ END(spurious_interrupt)
/* error code is on the stack already */
/* handle NMI like exceptions that can happen everywhere */
- .macro paranoidentry sym
+#ifndef DEBUG_IST
+# define DEBUG_IST 0
+#endif
+ .macro paranoidentry sym, ist=0
SAVE_ALL
cld
movl $1,%ebx
@@ -695,10 +698,20 @@ END(spurious_interrupt)
js 1f
swapgs
xorl %ebx,%ebx
-1: movq %rsp,%rdi
+1:
+ .if \ist
+ movq %gs:pda_data_offset, %rbp
+ .endif
+ movq %rsp,%rdi
movq ORIG_RAX(%rsp),%rsi
movq $-1,ORIG_RAX(%rsp)
+ .if \ist
+ subq $EXCEPTION_STACK_SIZE, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
+ .endif
call \sym
+ .if \ist
+ addq $EXCEPTION_STACK_SIZE, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
+ .endif
cli
.endm
@@ -924,7 +937,7 @@ KPROBE_ENTRY(debug)
INTR_FRAME
pushq $0
CFI_ADJUST_CFA_OFFSET 8
- paranoidentry do_debug
+ paranoidentry do_debug, DEBUG_IST
jmp paranoid_exit
CFI_ENDPROC
END(debug)
@@ -981,7 +994,12 @@ paranoid_schedule:
END(nmi)
KPROBE_ENTRY(int3)
- zeroentry do_int3
+ INTR_FRAME
+ pushq $0
+ CFI_ADJUST_CFA_OFFSET 8
+ paranoidentry do_int3, DEBUG_IST
+ jmp paranoid_exit
+ CFI_ENDPROC
END(int3)
.previous .text
Index: 2.6.14-nlkd/arch/x86_64/kernel/setup64.c
===================================================================
--- 2.6.14-nlkd.orig/arch/x86_64/kernel/setup64.c 2005-11-09 11:18:26.000000000 +0100
+++ 2.6.14-nlkd/arch/x86_64/kernel/setup64.c 2005-11-04 16:19:33.000000000 +0100
@@ -146,7 +146,7 @@ void pda_init(int cpu)
pda->irqstackptr += IRQSTACKSIZE-64;
}
-char boot_exception_stacks[N_EXCEPTION_STACKS * EXCEPTION_STKSZ]
+char boot_exception_stacks[(N_EXCEPTION_STACKS - 2) * EXCEPTION_STKSZ + DEBUG_STKSZ]
__attribute__((section(".bss.page_aligned")));
/* May not be marked __init: used by software suspend */
@@ -243,13 +243,27 @@ void __cpuinit cpu_init (void)
*/
for (v = 0; v < N_EXCEPTION_STACKS; v++) {
if (cpu) {
- estacks = (char *)__get_free_pages(GFP_ATOMIC,
- EXCEPTION_STACK_ORDER);
+ static const unsigned int order[N_EXCEPTION_STACKS] = {
+ [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STACK_ORDER,
+ [DEBUG_STACK - 1] = DEBUG_STACK_ORDER
+ };
+
+ estacks = (char *)__get_free_pages(GFP_ATOMIC, order[v]);
if (!estacks)
panic("Cannot allocate exception stack %ld %d\n",
v, cpu);
}
- estacks += EXCEPTION_STKSZ;
+ switch (v + 1) {
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+ case DEBUG_STACK:
+ cpu_pda[cpu].debugstack = (unsigned long)estacks;
+ estacks += DEBUG_STKSZ;
+ break;
+#endif
+ default:
+ estacks += EXCEPTION_STKSZ;
+ break;
+ }
t->ist[v] = (unsigned long)estacks;
}
Index: 2.6.14-nlkd/arch/x86_64/kernel/traps.c
===================================================================
--- 2.6.14-nlkd.orig/arch/x86_64/kernel/traps.c 2005-11-09 11:18:26.000000000 +0100
+++ 2.6.14-nlkd/arch/x86_64/kernel/traps.c 2005-11-09 11:19:36.000000000 +0100
@@ -121,19 +121,31 @@ int printk_address(unsigned long address
static unsigned long *in_exception_stack(unsigned cpu, unsigned long stack,
unsigned *usedp, const char **idp)
{
- static const char ids[N_EXCEPTION_STACKS][8] = {
+ static char ids[][8] = {
[DEBUG_STACK - 1] = "#DB",
[NMI_STACK - 1] = "NMI",
[DOUBLEFAULT_STACK - 1] = "#DF",
[STACKFAULT_STACK - 1] = "#SS",
[MCE_STACK - 1] = "#MC",
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+ [N_EXCEPTION_STACKS ... N_EXCEPTION_STACKS + DEBUG_STKSZ / EXCEPTION_STKSZ - 2] = "#DB[?]"
+#endif
};
unsigned k;
for (k = 0; k < N_EXCEPTION_STACKS; k++) {
unsigned long end;
- end = per_cpu(init_tss, cpu).ist[k];
+ switch (k + 1) {
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+ case DEBUG_STACK:
+ end = cpu_pda[cpu].debugstack + DEBUG_STKSZ;
+ break;
+#endif
+ default:
+ end = per_cpu(init_tss, cpu).ist[k];
+ break;
+ }
if (stack >= end)
continue;
if (stack >= end - EXCEPTION_STKSZ) {
@@ -143,6 +155,22 @@ static unsigned long *in_exception_stack
*idp = ids[k];
return (unsigned long *)end;
}
+#if DEBUG_STKSZ > EXCEPTION_STKSZ
+ if (k == DEBUG_STACK - 1 && stack >= end - DEBUG_STKSZ) {
+ unsigned j = N_EXCEPTION_STACKS - 1;
+
+ do {
+ ++j;
+ end -= EXCEPTION_STKSZ;
+ ids[j][4] = '1' + (j - N_EXCEPTION_STACKS);
+ } while (stack < end - EXCEPTION_STKSZ);
+ if (*usedp & (1U << j))
+ break;
+ *usedp |= 1U << j;
+ *idp = ids[j];
+ return (unsigned long *)end;
+ }
+#endif
}
return NULL;
}
@@ -652,6 +680,7 @@ asmlinkage void default_do_nmi(struct pt
io_check_error(reason, regs);
}
+/* runs on IST stack. */
asmlinkage void __kprobes do_int3(struct pt_regs * regs, long error_code)
{
if (notify_die(DIE_INT3, "int3", regs, error_code, 3, SIGTRAP) == NOTIFY_STOP) {
@@ -942,7 +971,7 @@ void __init trap_init(void)
set_intr_gate(0,÷_error);
set_intr_gate_ist(1,&debug,DEBUG_STACK);
set_intr_gate_ist(2,&nmi,NMI_STACK);
- set_system_gate(3,&int3);
+ set_system_gate_ist(3,&int3,DEBUG_STACK); /* int3 can be called from all */
set_system_gate(4,&overflow); /* int4 can be called from all */
set_intr_gate(5,&bounds);
set_intr_gate(6,&invalid_op);
Index: 2.6.14-nlkd/include/asm-x86_64/desc.h
===================================================================
--- 2.6.14-nlkd.orig/include/asm-x86_64/desc.h 2005-11-09 11:18:27.000000000 +0100
+++ 2.6.14-nlkd/include/asm-x86_64/desc.h 2005-11-04 16:19:34.000000000 +0100
@@ -111,6 +111,11 @@ static inline void set_system_gate(int n
_set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, 0);
}
+static inline void set_system_gate_ist(int nr, void *func, unsigned ist)
+{
+ _set_gate(&idt_table[nr], GATE_INTERRUPT, (unsigned long) func, 3, ist);
+}
+
static inline void set_tssldt_descriptor(void *ptr, unsigned long tss, unsigned type,
unsigned size)
{
Index: 2.6.14-nlkd/include/asm-x86_64/pda.h
===================================================================
--- 2.6.14-nlkd.orig/include/asm-x86_64/pda.h 2005-11-09 11:18:27.000000000 +0100
+++ 2.6.14-nlkd/include/asm-x86_64/pda.h 2005-11-07 10:33:42.000000000 +0100
@@ -12,6 +12,10 @@ struct x8664_pda {
unsigned long data_offset; /* Per cpu data offset from linker address */
unsigned long kernelstack; /* top of kernel stack for current */
unsigned long oldrsp; /* user rsp for system call */
+#ifdef CONFIG_NLKD /* Better would be DEBUG_STKSZ > EXCEPTION_STKSZ, but
+ this file can't include processor.h. */
+ unsigned long debugstack; /* #DB/#BP stack. */
+#endif
int irqcount; /* Irq nesting counter. Starts with -1 */
int cpunumber; /* Logical CPU number */
char *irqstackptr; /* top of irqstack */
Index: 2.6.14-nlkd/include/asm-x86_64/processor.h
===================================================================
--- 2.6.14-nlkd.orig/include/asm-x86_64/processor.h 2005-11-09 11:18:27.000000000 +0100
+++ 2.6.14-nlkd/include/asm-x86_64/processor.h 2005-11-07 10:36:06.000000000 +0100
@@ -271,8 +271,10 @@ struct thread_struct {
#define DEBUG_STACK 4
#define MCE_STACK 5
#define N_EXCEPTION_STACKS 5 /* hw limit: 7 */
-#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER)
#define EXCEPTION_STACK_ORDER 0
+#define EXCEPTION_STKSZ (PAGE_SIZE << EXCEPTION_STACK_ORDER)
+#define DEBUG_STACK_ORDER EXCEPTION_STACK_ORDER
+#define DEBUG_STKSZ (PAGE_SIZE << DEBUG_STACK_ORDER)
#define start_thread(regs,new_rip,new_rsp) do { \
asm volatile("movl %0,%%fs; movl %0,%%es; movl %0,%%ds": :"r" (0)); \
next prev parent reply other threads:[~2005-11-09 14:12 UTC|newest]
Thread overview: 105+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-09 13:54 [PATCH 0/39] NLKD - Novell Linux Kernel Debugger Jan Beulich
2005-11-09 13:56 ` [PATCH 1/39] NLKD - an alternative kallsyms approach Jan Beulich
2005-11-09 13:57 ` [PATCH 2/39] NLKD - an alternative early ioremap approach Jan Beulich
2005-11-09 13:58 ` [PATCH 3/39] NLKD - early/late CPU up/down notification Jan Beulich
2005-11-09 13:59 ` [PATCH 4/39] NLKD/i386 " Jan Beulich
2005-11-09 14:01 ` [PATCH 5/39] NLKD/x86-64 " Jan Beulich
2005-11-10 13:10 ` Andi Kleen
2005-11-14 8:04 ` [discuss] " Jan Beulich
2005-11-14 12:37 ` Andi Kleen
2005-11-09 14:01 ` [PATCH 6/39] NLKD - early panic notification Jan Beulich
2005-11-09 14:02 ` [PATCH 7/39] NLKD - task create/destroy notification Jan Beulich
2005-11-09 14:03 ` [PATCH 8/39] NLKD - rmmod notification Jan Beulich
2005-11-09 14:04 ` [PATCH 9/39] NLKD - hotkey notification Jan Beulich
2005-11-09 14:05 ` [PATCH 10/39] NLKD - console layout change notification Jan Beulich
2005-11-09 14:06 ` [PATCH 11/39] NLKD - time adjustment Jan Beulich
2005-11-09 14:06 ` [PATCH 12/39] NLKD/i386 " Jan Beulich
2005-11-09 19:10 ` George Anzinger
2005-11-10 8:12 ` Jan Beulich
2005-11-11 0:17 ` George Anzinger
2005-11-09 14:08 ` [PATCH 13/39] NLKD/x86-64 " Jan Beulich
2005-11-09 14:13 ` Jan Beulich [this message]
2005-11-09 14:14 ` [PATCH 19/39] NLKD/x86-64 - stack-pointer-invalid markers Jan Beulich
2005-11-09 14:15 ` [PATCH 20/39] NLKD/x86-64 - switch_to() floating point adjustment Jan Beulich
2005-11-09 14:16 ` [PATCH 21/39] NLKD/x86-64 - core adjustments Jan Beulich
2005-11-10 13:24 ` [PATCH 20/39] NLKD/x86-64 - switch_to() floating point adjustment Andi Kleen
2005-11-10 14:07 ` Jan Beulich
2005-11-10 13:23 ` [PATCH 19/39] NLKD/x86-64 - stack-pointer-invalid markers Andi Kleen
2005-11-10 14:25 ` Jan Beulich
2005-11-10 13:21 ` [PATCH 18/39] NLKD/x86-64 - INT1/INT3 handling changes Andi Kleen
2005-11-10 14:07 ` Jan Beulich
2005-11-10 14:25 ` Andi Kleen
2005-11-10 15:00 ` Jan Beulich
2005-11-11 3:39 ` [discuss] " Andi Kleen
2005-11-10 13:19 ` [PATCH 13/39] NLKD/x86-64 - time adjustment Andi Kleen
2005-11-10 14:23 ` Jan Beulich
2005-11-11 2:12 ` Andi Kleen
2005-11-12 9:22 ` Vojtech Pavlik
2005-11-12 17:21 ` Andi Kleen
2005-11-12 20:44 ` Vojtech Pavlik
2005-11-15 0:38 ` George Anzinger
2005-11-15 1:05 ` [discuss] " Andi Kleen
2005-11-15 7:50 ` Vojtech Pavlik
2005-11-15 8:24 ` Jan Beulich
2005-11-10 14:43 ` Vojtech Pavlik
2005-11-09 14:09 ` [PATCH 14/39] NLKD - kernel trace buffer access Jan Beulich
2005-11-09 14:09 ` [PATCH 15/39] NLKD - early pseudo-fs Jan Beulich
2005-11-09 14:11 ` [PATCH 16/39] NLKD - core adjustments Jan Beulich
2005-11-09 14:11 ` [PATCH 17/39] NLKD/i386 " Jan Beulich
2005-11-09 19:00 ` Adrian Bunk
2005-11-10 8:04 ` Jan Beulich
2005-11-10 10:29 ` Adrian Bunk
2005-11-10 11:52 ` Jan Beulich
2005-11-10 12:36 ` Lars Marowsky-Bree
2005-11-09 14:18 ` [PATCH 22/39] NLKD - core Jan Beulich
2005-11-09 14:19 ` [PATCH 23/39] NLKD/x86 " Jan Beulich
2005-11-09 14:20 ` [PATCH 24/39] NLKD/i386 " Jan Beulich
2005-11-09 14:21 ` [PATCH 25/39] NLKD/x86-64 " Jan Beulich
2005-11-10 13:30 ` Andi Kleen
2005-11-09 14:22 ` [PATCH 26/39] NLKD - run time library Jan Beulich
2005-11-09 14:23 ` [PATCH 27/39] NLKD/i386 " Jan Beulich
2005-11-09 14:23 ` [PATCH 28/39] NLKD/x86-64 " Jan Beulich
2005-11-10 13:32 ` Andi Kleen
[not found] ` <437214B7.76F0.0078.0@novell.com>
[not found] ` <4372156A.76F0.0078.0@novell.com>
2005-11-09 14:28 ` [PATCH 34/39] NLKD/x86 - Console Debug Agent Jan Beulich
[not found] ` <43721600.76F0.0078.0@novell.com>
2005-11-09 14:30 ` [PATCH 38/39] NLKD/i386 - Remote " Jan Beulich
2005-11-09 14:31 ` [PATCH 39/39] NLKD/x86-64 " Jan Beulich
2005-11-09 14:29 ` [PATCH 15/39] NLKD - early pseudo-fs Al Viro
2005-11-09 14:37 ` Jan Beulich
2005-11-09 15:00 ` Al Viro
2005-11-09 16:00 ` Jan Beulich
2005-11-10 5:44 ` [PATCH 14/39] NLKD - kernel trace buffer access Keith Owens
2005-11-10 8:02 ` Jan Beulich
2005-11-09 18:51 ` [PATCH 11/39] NLKD - time adjustment George Anzinger
2005-11-09 16:50 ` [PATCH 6/39] NLKD - early panic notification Greg KH
2005-11-09 16:45 ` [PATCH 3/39] NLKD - early/late CPU up/down notification Greg KH
2005-11-09 17:09 ` Jan Beulich
2005-11-09 17:19 ` Greg KH
2005-11-10 7:41 ` Jan Beulich
2005-11-10 20:59 ` Sam Ravnborg
2005-11-11 7:52 ` Jan Beulich
2005-11-12 20:52 ` Randy.Dunlap
2005-11-10 23:01 ` Greg KH
2005-11-11 10:06 ` [PATCH 2/39] NLKD - an alternative early ioremap approach Pavel Machek
2005-11-11 10:19 ` Jan Beulich
2005-11-09 16:50 ` [PATCH 1/39] NLKD - an alternative kallsyms approach Randy.Dunlap
2005-11-09 16:57 ` Greg KH
2005-11-09 17:20 ` Jan Beulich
2005-11-09 16:59 ` [PATCH 0/39] NLKD - Novell Linux Kernel Debugger Jeff Garzik
2005-11-09 17:06 ` Randy.Dunlap
2005-11-09 17:14 ` Jan Beulich
2005-11-09 17:56 ` Alan Cox
2005-11-09 18:05 ` Greg KH
2005-11-09 18:54 ` Paul Jackson
2005-11-10 12:41 ` Christoph Hellwig
2005-11-13 1:09 ` Andi Kleen
2005-11-13 2:53 ` jmerkey
2005-11-13 3:44 ` Andi Kleen
2005-11-13 3:26 ` Jeff V. Merkey
2005-11-13 3:32 ` Jeff V. Merkey
2005-11-09 17:53 ` Alan Cox
2005-11-09 16:25 ` Jeffrey V. Merkey
2005-11-10 14:48 ` Mark Lord
2005-11-10 15:28 ` Tom Rini
2005-11-10 16:37 ` Alan Cox
2005-11-13 1:11 ` Andi Kleen
[not found] ` <437214E4.76F0.0078.0@novell.com>
[not found] ` <4372153C.76F0.0078.0@novell.com>
2005-11-10 13:33 ` [PATCH 32/39] NLKD/x86-64 - Core Debug Engine Andi Kleen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4372120B.76F0.0078.0@novell.com \
--to=jbeulich@novell.com \
--cc=ak@suse.de \
--cc=discuss@x86-64.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.