question on sparc64 switch_to macro
(Background: am attempting to debug a squirrely problem with kgdb on SMP system, in which the kgdb "master" CPU -- whichever one takes the kgdb trap -- works OK, but one or more "slaves", captured by the kgdb "client capture" code, behaves extremely oddly when it is resumed. The problem is very timing-dependent and relatively rare.)
In the switch_to code, we have (converting to "normal" asm for readability and adding markers A and B):
... mov thread_info_reg, %g6 ldub [thread_info_reg + TI_CWP], %g1 A--> wrpr %g1, %cwp ldx [%g6 + TI_KSP], %o6 ldub [%g6 + TI_WSTATE], %o5 ldub [%g6 + TI_NEW_CHILD], %o7 B--> wrpr %o5, 0x0, %wstate ...
Aside from the fact that one could use %g6 for the first ldub :-) (but not for the rest due to the %cwp change), here's what I am wondering:
Suppose we get a trap anywhere between point A and point B (from "right after A" to "right before B finishes", really). We will not get regular (software) interrupts because we have %pil set to 15 (blocking even the "NMI"), but we can still take traps. But we have a potentially inconsistent window state: %o6 is not yet correct (up to the ldx anyway), and %wstate likewise.
Most traps do all their work in the trap globals (PSTATE_AG, PSTATE_MG, %gl=1, or whatever this particular CPU uses) and then simply "retry", so that part is OK. Most of the remaining trap cases are pretty fatal ("cpu is on fire" or whatever) so we might not worry about them much either.
The kgdb slave capture trap, however, is quite different. It arrives in xcall_kgdb_capture (in "trap globals" as usual). It raises %pil to "high", uses etrap_irq to batten down the hatches, and calls the C routine smp_kgdb_capture_client():
... magic patchy code to switch to interrupt globals [snipped] rdpr %pil, %g2 wrpr %g0, PIL_NORMAL_MAX, %pil sethi %hi(109f), %g7 ba,pt %xcc, etrap_irq
109: or %g7, %lo(109b), %g7
#ifdef CONFIG_TRACE_IRQFLAGS
call trace_hardirqs_off
nop
#endif call smp_kgdb_capture_client add %sp, PTREGS_OFF, %o0
(I'll note that a one-instruction cleanup is possible here, we could "rd %pc, %g7" in the delay slot, instead of using the 109:
label. I think I saw one or two more cases like this scattered about, if anyone wants to go bum a few instructions. :-) )
For normal interrupts, this is fine, because the switch_to code has those blocked. But shouldn't switch_to clear PSTATE_IE during the "sensitive" code in the thread-switch? Or, perhaps, the kgdb "capture client" should run off a software interrupt. (This presents other possible problems. You want the capture to be a "mostly non-maskable" interrupt. sparc-next now has the pseudo-NMI at %pil=15, but the kernel I am working on is older.)
I would (and probably will as soon as I can decide on a "safe" code path, ie, which %g registers can I use here...) test this, but I'm not at all sure this is the problem we are seeing now, and whether or not the change makes it go away, I'm not sure if fussing with PSTATE_IE in switch_to() is a good or bad idea. And in particular, I believe %wstate is almost always the same from one thread to the next, which makes the window *really* tiny, which means that this is probably not causing the problem we have observed, so we would leave it unchanged. In which case, if it is actually a problem, it will still be lurking. So I figured I should enlist the minds of other sparc gurus. :-)
(I also wonder whether, in the sparc-next tree, the kgdb capture code shown above should be using PIL_NORMAL_MAX, which lets in "nmi"s, or 15, to block them too. 15 seems more likely correct to me.)
Chris
(PS: I have not thought nearly enough about this, but: in the ultrasparc code I did in another lifetime, I did not bother fiddling %cwp in the task-switch code, because we know the register windows are empty both before and after, so %cwp does not really matter:
we are going to fault in all the "above" windows as usual, and in that system, nothing ever let you peek at the %cwp value. It may be possible to do the same in the linux code. In which case the switch code has many more registers available to it, plus this saves you one whole "wrpr" instruction. :-) Something for those better-versed than I to consider, anyway.)
David Miller
maintainerFrom: Chris Torek <[email protected]>
Date: Sat, 14 Mar 2009 12:53:52 -0600
Quoted 10 lines
(PS: I have not thought nearly enough about this, but: in the ultrasparc code I did in another lifetime, I did not bother fiddling %cwp in the task-switch code, because we know the register windows are empty both before and after, so %cwp does not really matter:
we are going to fault in all the "above" windows as usual, and in that system, nothing ever let you peek at the %cwp value. It may be possible to do the same in the linux code. In which case the switch code has many more registers available to it, plus this saves you one whole "wrpr" instruction. :-) Something for those better-versed than I to consider, anyway.)
Oh, CWP _does_ matter.
You have to specifically use the saved CWP in the task switch because when we later get to the trap return into userspace we'll restore the %tstate register from the trap stack and that has a very specific CWP encoded into it. So it all has to line up properly.
I suppose we could mask out the CWP in the pt_regs we restore in trap return, but that seems like more work than the CWP writes here :-)
I'll address the rest of your email soon.
David Miller
maintainerFrom: Chris Torek <[email protected]>
Date: Sat, 14 Mar 2009 12:53:52 -0600
Quoted 12 lines
In the
switch_tocode, we have (converting to "normal" asm for readability and adding markers A and B):... mov thread_info_reg, %g6 ldub [thread_info_reg + TI_CWP], %g1 A--> wrpr %g1, %cwp ldx [%g6 + TI_KSP], %o6 ldub [%g6 + TI_WSTATE], %o5 ldub [%g6 + TI_NEW_CHILD], %o7 B--> wrpr %o5, 0x0, %wstate ...
Quoted 1 line
Aside from the fact that one could use %g6 for the first ldub :-)
Using %g6 wouldn't allow the ldub to issue in the same group as the previous instruction, as that would create a dependency. Not using %g6 is therefore very deliberate here.
Quoted 6 lines
Suppose we get a trap anywhere between point A and point B (from "right after A" to "right before B finishes", really). We will not get regular (software) interrupts because we have %pil set to 15 (blocking even the "NMI"), but we can still take traps. But we have a potentially inconsistent window state: %o6 is not yet correct (up to the ldx anyway), and %wstate likewise.
Nothing that cares about window state is supposed to trap here. That is a very important invariant.
Quoted 1 line
The kgdb slave capture trap, however, is quite different.
Yes, this is broken and won't work, we can't allow cross-call vectored interrupts to run C code otherwise we create problems like the one you describe.
All of the other cross cpu interrupts reschedule the event to a PIL based interrupt, and that's probably what we should do here as well (see xcall_capture, for example).
Quoted 4 lines
(I'll note that a one-instruction cleanup is possible here, we could "rd %pc, %g7" in the delay slot, instead of using the 109:
label. I think I saw one or two more cases like this scattered about, if anyone wants to go bum a few instructions. :-) )
"rd %pc, X" doesn't schedule very well at all, it flushes the pipeline completely and cannot issue alongside other instructions.
Quoted 7 lines
For normal interrupts, this is fine, because the
switch_tocode has those blocked. But shouldn'tswitch_toclearPSTATE_IEduring the "sensitive" code in the thread-switch? Or, perhaps, the kgdb "capture client" should run off a software interrupt. (This presents other possible problems. You want the capture to be a "mostly non-maskable" interrupt. sparc-next now has the pseudo-NMI at %pil=15, but the kernel I am working on is older.)
No, we don't want to turn off PSTATE_IE, that makes the profiling NMI interrupt less useful.
I'm pretty sure using a software interrupt is the best solution.
Quoted 4 lines
(I also wonder whether, in the sparc-next tree, the kgdb capture code shown above should be using
PIL_NORMAL_MAX, which lets in "nmi"s, or 15, to block them too. 15 seems more likely correct to me.)
We use 15 explicitly to block out NMIs, I actually triggered a crash when using PIL_NORMAL_MAX and it was because of the %cwp et al. issues you have discovered here.
It's so easy to reschedule this kgdb capture thing into a software interrupt, please code that up and give it a whirl.
Or, as usual, I'll do it :-/
Quoted 2 lines
"rd %pc, X" doesn't schedule very well at all, it flushes the pipeline completely and cannot issue alongside other instructions.
Oh, in that case maybe the other code that does the "rd %pc" version should be switched to using sethi/or sequences. (Or maybe it is already in places where there is no good scheduling.)
Quoted 1 line
I'm pretty sure using a software interrupt is the best solution.
OK.
Quoted 4 lines
It's so easy to reschedule this kgdb capture thing into a software interrupt, please code that up and give it a whirl.
Or, as usual, I'll do it :-/
Heh. In my case, I will have to go work out how the software interrupts work, so as to make sure I don't step on some other interrupt.
I'll probably get a chance to try sometime Monday or Tuesday though -- actually I'm working with other folks and they'd be doing the "try" part -- as I have a pile of other work I have to get done this weekend and Monday.
Chris
David Miller
maintainerFrom: Chris Torek <[email protected]>
Date: Sat, 14 Mar 2009 16:24:41 -0600
Quoted 6 lines
Quoted 2 lines
"rd %pc, X" doesn't schedule very well at all, it flushes the pipeline completely and cannot issue alongside other instructions.
Oh, in that case maybe the other code that does the "rd %pc" version should be switched to using sethi/or sequences. (Or maybe it is already in places where there is no good scheduling.)
In many places where we use rd %pc, X we are doing so because we are limited by the number of instructions. For example, in trap table entries.
Quoted 5 lines
Quoted 4 lines
It's so easy to reschedule this kgdb capture thing into a software interrupt, please code that up and give it a whirl.
Or, as usual, I'll do it :-/
Quoted 8 lines
Heh. In my case, I will have to go work out how the software interrupts work, so as to make sure I don't step on some other interrupt.
I'll probably get a chance to try sometime Monday or Tuesday though -- actually I'm working with other folks and they'd be doing the "try" part -- as I have a pile of other work I have to get done this weekend and Monday.
It's a 2 minute hack, just test this patch below.
BTW, there are things which we know won't work with KGDB on platforms like sparc that do single-step in software. SMP KGDB usage on such platforms is basically hit-or-miss because it's very racy. See:
http://kerneltrap.org/mailarchive/linux-kernel/2008/4/29/1647204
Just FYI.
arch/sparc/include/asm/pil.h +1 -0
@@ -24,6 +24,7 @@#define PIL_DEVICE_IRQ 5#define PIL_SMP_CALL_FUNC_SNGL 6#define PIL_DEFERRED_PCR_WORK 7 +#define PIL_KGDB_CAPTURE 8#define PIL_NORMAL_MAX 14#define PIL_NMI 15
arch/sparc/kernel/kgdb_64.c +1 -1
@@ -108,7 +108,7 @@ void gdb_regs_to_pt_regs(unsigned long *gdb_regs, struct pt_regs *regs) }#ifdef CONFIG_SMP -void smp_kgdb_capture_client (struct pt_regs *regs) +void smp_kgdb_capture_client (int irq,struct pt_regs *regs) {unsigned long flags;
arch/sparc/kernel/ttable.S +6 -1
@@ -64,7 +64,12 @@ tl0_irq6: TRAP_IRQ(smp_call_function_single_client, 6) tl0_irq6: BTRAP(0x46) #endif tl0_irq7: TRAP_IRQ(deferred_pcr_work_irq, 7) -tl0_irq8: BTRAP(0x48) BTRAP(0x49) +#ifdef CONFIG_KGDB +tl0_irq8: TRAP_IRQ(smp_kgdb_capture_client, 8) +#else +tl0_irq8: BTRAP(0x48) +#endif +tl0_irq9: BTRAP(0x49) tl0_irq10: BTRAP(0x4a) BTRAP(0x4b) BTRAP(0x4c) BTRAP(0x4d) tl0_irq14: TRAP_IRQ(timer_interrupt, 14) tl0_irq15: TRAP_NMI_IRQ(perfctr_irq, 15)
arch/sparc/mm/ultra.S +2 -22
@@ -679,28 +679,8 @@ xcall_new_mmu_context_version: #ifdef CONFIG_KGDB .globl xcall_kgdb_capture xcall_kgdb_capture: -661: rdpr %pstate, %g2 - wrpr %g2, PSTATE_IG | PSTATE_AG, %pstate - .section .sun4v_2insn_patch, "ax" - .word 661b - nop - nop - .previous - - rdpr %pil, %g2 - wrpr %g0, PIL_NORMAL_MAX, %pil - sethi %hi(109f), %g7 - ba,pt %xcc, etrap_irq -109: or %g7, %lo(109b), %g7 -#ifdef CONFIG_TRACE_IRQFLAGS - call trace_hardirqs_off - nop -#endif - call smp_kgdb_capture_client - add %sp, PTREGS_OFF, %o0 - /* Has to be a non-v9 branch due to the large distance. */ - ba rtrap_xcall - ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 + wr %g0, (1 << PIL_KGDB_CAPTURE), %set_softint + retry #endif #endif /* CONFIG_SMP */
Quoted 1 line
It's a 2 minute hack, just test this patch below.
I'll give it to our guys here (the guy who has been working on it for a couple of weeks now, and we now have Jason poking at it too:
we've fixed a couple of other machine-independent buglets in trying to make the kgdbts code work, I assume Jason will send them on once we have finalized them).
Quoted 5 lines
BTW, there are things which we know won't work with KGDB on platforms like sparc that do single-step in software. SMP KGDB usage on such platforms is basically hit-or-miss because it's very racy. See:
http://kerneltrap.org/mailarchive/linux-kernel/2008/4/29/1647204
WRT this, I'll toss you this code that does part (but not all) of what I think you are talking about in that mail archive thread. This is not necessarily the final "we think it works" version yet though :-) (and of course is for an older kernel, viz arch/sparc64/ path).
Chris
arch/sparc64/kernel/kgdb.c +312 -0
@@ -5,11 +5,21 @@#include <linux/kgdb.h> #include <linux/kdebug.h> +#include <linux/uaccess.h> #include <asm/kdebug.h> #include <asm/ptrace.h> #include <asm/irq.h> +#include "../kernel/kstack.h" + +/* #define DEBUG_SPARC64_KGDB 1 */ + +static unsigned long stepped_address_npc =0 ; +static unsigned int stepped_opcode_npc =0 ; +static unsigned long stepped_address_nnpc =0 ; +static unsigned int stepped_opcode_nnpc =0 ; +void pt_regs_to_gdb_regs (unsigned long *gdb_regs,struct pt_regs *regs) {
@@ -134,6 +144,220 @@ void smp_kgdb_capture_client(struct pt_regs *regs) }#endif + +/* Macros below and sparc64GetNpc() code is mainly borrowed +* from gdb::sparc-tdep.c and gdb::sparc64-linux-tdep.c +*/ + +#define X_OP (i) (((i) >> 30) & 0x3) +#define X_RD (i) (((i) >> 25) & 0x1f) +#define X_A (i) (((i) >> 29) & 1) +#define X_COND (i) (((i) >> 25) & 0xf) +#define X_OP2 (i) (((i) >> 22) & 0x7) +#define X_IMM22 (i) ((i) & 0x3fffff) +#define X_OP3 (i) (((i) >> 19) & 0x3f) +#define X_RS1 (i) (((i) >> 14) & 0x1f) +#define X_RS2 (i) ((i) & 0x1f) +#define X_I (i) (((i) >> 13) & 1) + +/* Sign extension macros. */ +#define X_DISP22 (i) ((X_IMM22 (i) ^ 0x200000) - 0x200000) +#define X_DISP19 (i) ((((i) & 0x7ffff) ^ 0x40000) - 0x40000) +#define X_SIMM13 (i) ((((i) & 0x1fff) ^ 0x1000) - 0x1000) + + +static unsigned long sparc64GetNpc (unsigned long pc,unsigned long *npc,const struct pt_regs *regs) +{ +unsigned int insn; +int conditional_p; +int branch_p =0 ; +long offset =0 ;/* Must be signed for sign-extend. */ +int error; + +/* Read the current instruction at the PC */ + error =probe_kernel_read (&insn, (char *)pc,BREAK_INSTR_SIZE ); +if (error) { +return -EINVAL ; + } + + conditional_p =X_COND (insn) &0x7 ; + +if (X_OP (insn) =0 &&X_OP2 (insn) =3 && (insn &0x1000000 ) =0 ) { +/* Branch on Integer Register with Prediction (BPr). */ + branch_p =1 ; + conditional_p =1 ; + } +else if (X_OP (insn) =0 &&X_OP2 (insn) =6 ) { +/* Branch on Floating-Point Condition Codes (FBfcc). */ + branch_p =1 ; + offset =4 *X_DISP22 (insn); + } +else if (X_OP (insn) =0 &&X_OP2 (insn) =5 ) { +/* Branch on Floating-Point Condition Codes with Prediction (FBPfcc). */ + branch_p =1 ; + offset =4 *X_DISP19 (insn); + } +else if (X_OP (insn) =0 &&X_OP2 (insn) =2 ) { +/* Branch on Integer Condition Codes (Bicc). */ + branch_p =1 ; + offset =4 *X_DISP22 (insn); + } +else if (X_OP (insn) =0 &&X_OP2 (insn) =1 ) { +/* Branch on Integer Condition Codes with Prediction (BPcc). */ + branch_p =1 ; + offset =4 *X_DISP19 (insn); + } +else if (X_OP (insn) =2 &&X_OP3 (insn) =0x3a ) { +/* Trap instruction (TRAP). */ +if (insn =0x91d0206d ) { + +/* +* 0x91d0206d = "ta 0x16d" = tl0_linux64 (LINUX_64BIT_SYSCALL_TRAP). +* Return the address of a system call's alternative return +* address. +*/ + +unsigned long trap_nnpc, trap_nnpc_addr; +unsigned long top_fp = regs->u_regs[UREG_FP ]; + +if (top_fp &1 ) + top_fp +=STACK_BIAS ; + +/* +* The kernel puts the sigreturn registers on the stack, +* and this is where the signal unwinding state is take from +* when returning from a signal. +* A siginfo_t sits 192 bytes from the base of the stack. This +* siginfo_t is 128 bytes, and is followed by the sigreturn +* register save area. The saved PC sits at a 136 byte offset +* into there. +*/ + + trap_nnpc_addr = top_fp +192 +128 +136 ; +if (!probe_kernel_read ((char *)trap_nnpc_addr, &trap_nnpc,8 )) +return trap_nnpc; +else +printk (KERN_CRIT "KGDB: Cannot read address 0x%lx\n" , trap_nnpc_addr); + } +return 0 ; + } +else if (X_OP (insn) =2 &&X_OP3 (insn) =0x3e ) { +/* +* DONE and RETRY instructions. +* Here kgdb must happen in an irq trap handler. +* Therefore need to find pt_regs of the irq trap +* handler. Note that "regs" is not actually valid +* unless kstack_is_trap_frame() is true. +* The kstack_is_trap_frame() code handles this properly, +* but we must use "regs" only if it says "yes". +*/ + +unsigned long top_fp = regs->u_regs[UREG_FP ]; +struct sparc_stackf *sf; +struct pt_regs *regs_irq; + +if (top_fp &1 ) + top_fp +=STACK_BIAS ; + + sf = (struct sparc_stackf *) top_fp; + regs_irq = (struct pt_regs *) (sf +1 ); + +if (kstack_is_trap_frame (current_thread_info (), regs_irq)) { +if (X_RD (insn) =0 ) { +/* DONE instruction */ +return regs_irq->tnpc; + } +else if (X_RD (insn) =1 ) { +/* RETRY instruction */ +return regs_irq->tpc; + } + } +else +printk (KERN_CRIT "KGDB: Not in irq trap handler ???\n" ); + +return 0 ; + } + +#ifdef DEBUG_SPARC64_KGDB +printk (KERN_CRIT "%s(%d): insn=0x%x branch=%d cond=%d offset=%ld\n" , + __FUNCTION__, __LINE__, insn, branch_p, conditional_p, offset); +#endif + +if (branch_p) { +if (conditional_p) { +/* For conditional branches, return nPC + 4 iff the annul bit is 1. */ +return (X_A (insn) ? *npc +4 :0 ); + } +else { +/* +* For unconditional branches, return the target if its +* specified condition is "always" and return nPC + 4 if the +* condition is "never". If the annul bit is 1, set *NPC to +* zero. +*/ +if (X_COND (insn) =0x0 ) { + pc = *npc, offset =4 ; + } +if (X_A (insn)) { + *npc =0 ; + } + +if (!offset) { +printk (KERN_CRIT "KGDB: offset for inst=0x%x must no be 0\n" , insn); + } + +return pc + offset; + } + } + +return 0 ; +} + + +struct kgdb_arch arch_kgdb_ops; +static int sparc64_set_singlestep_breakpoint (unsigned long addr,unsigned int *opcode_p) +{ +int error; + +/* First get the orignal opcode */ + error =probe_kernel_read (opcode_p, (char *)addr,BREAK_INSTR_SIZE ); +if (error !=0 ) { +printk (KERN_CRIT "KGDB: Unable to access opcode at next pc 0x%lx\n" , addr); +return error; + } + +/* Set the temporary breakpoint which put me back into kgdb trap */ + error =probe_kernel_write ((char *)addr, arch_kgdb_ops.gdb_bpt_instr,BREAK_INSTR_SIZE ); +if (error !=0 ) { +printk (KERN_CRIT "KGDB: Unable to write tmp BP at next pc 0x%lx\n" , addr); +return error; + } + +flushi (addr); +flushi (addr +4 ); +return 0 ; +} + + +static int sparc64_remove_singlestep_breakpoint (unsigned long *addr_p,unsigned int *opcode_p) +{ +/* restores original instruction */ +int error =probe_kernel_write ((char *)(*addr_p), opcode_p,BREAK_INSTR_SIZE ); +if (error !=0 ) { +printk (KERN_CRIT "KGDB: FATAL ERROR on instruction " +"restore at 0x%lx\n" , *addr_p); +return error; + } + +flushi (*addr_p); +flushi (*addr_p +4 ); + + *addr_p =0 ; + *opcode_p =0 ; +return 0 ; +} + +int kgdb_arch_handle_exception (int e_vector,int signo,int err_code,char *remcomInBuffer,char *remcomOutBuffer,struct pt_regs *linux_regs)
@@ -141,7 +365,57 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,unsigned long addr;char *ptr; +#ifdef DEBUG_SPARC64_KGDB +printk (KERN_CRIT "%s(%d): entering, cmd=%c\n" , + __FUNCTION__, __LINE__, remcomInBuffer[0 ]); + +#endif + +atomic_set (&kgdb_cpu_doing_single_step,-1 ); +switch (remcomInBuffer[0 ]) { +case 's' : + { +int error; +unsigned long pc, npc, nnpc; + +/* Try to read optional parameter, pc unchanged if no parm */ + ptr = &remcomInBuffer[1 ]; +if (kgdb_hex2long (&ptr, &addr)) { + linux_regs->tpc = addr; + linux_regs->tnpc = addr +4 ; + } + +/* Now try to predict the next instructions to put breakpoints */ + pc = linux_regs->tpc; + npc = linux_regs->tnpc; + nnpc =sparc64GetNpc (pc, &npc, linux_regs); + +if (npc !=0 ) { + stepped_address_npc = npc; + error =sparc64_set_singlestep_breakpoint (npc, &stepped_opcode_npc); +if (error !=0 ) { +return error; + } + } + +if (nnpc !=0 ) { + stepped_address_nnpc = nnpc; + error =sparc64_set_singlestep_breakpoint (nnpc, &stepped_opcode_nnpc); +if (error !=0 ) { +return error; + } + } + +if (linux_regs->tpc = (unsigned long ) arch_kgdb_breakpoint) { + linux_regs->tpc = linux_regs->tnpc; + linux_regs->tnpc +=4 ; + } + +atomic_set (&kgdb_cpu_doing_single_step,raw_smp_processor_id ()); + +return 0 ; + }case 'c' :/* try to read optional parameter, pc unchanged if no parm */ ptr = &remcomInBuffer[1 ];
@@ -166,6 +440,17 @@ asmlinkage void kgdb_trap(unsigned long trap_level, struct pt_regs *regs) {unsigned long flags; +#ifdef DEBUG_SPARC64_KGDB +printk (KERN_CRIT "\n%s(%d): ENTER KGDB - ad_npc=0x%lx, op_npc=0x%x, ad_nnpc=0x%lx, " +"op_nnpc=0x%x, pc=0x%lx, npc=0x%lx, cpu=%d, kgdb_active=%d, kgdb_single_step=%d, " +"ss_cpu=%d, kgdb_contthread=0x%lx, tl=0x%lx, pid=%d \n" , + __FUNCTION__, __LINE__, stepped_address_npc, stepped_opcode_npc, + stepped_address_nnpc, stepped_opcode_nnpc, regs->tpc, regs->tnpc, +raw_smp_processor_id (),atomic_read (&kgdb_active), kgdb_single_step, +atomic_read (&kgdb_cpu_doing_single_step), kgdb_contthread, + trap_level, (current!=0 ?current->pid:0 )); +#endif +if (user_mode (regs)) {bad_trap (regs, trap_level);return ;
@@ -174,8 +459,35 @@ asmlinkage void kgdb_trap(unsigned long trap_level, struct pt_regs *regs)flushw_all ();local_irq_save (flags); + +if (atomic_read (&kgdb_active) !=-1 ) +kgdb_nmicallback (raw_smp_processor_id (), regs); + +/* Need to clean up the existing single step breakpoints */ +if (stepped_address_npc !=0 && stepped_opcode_npc !=0 ) { +if (sparc64_remove_singlestep_breakpoint (&stepped_address_npc, &stepped_opcode_npc) !=0 ) { +return ; + } + } +if (stepped_address_nnpc !=0 && stepped_opcode_nnpc !=0 ) { +if (sparc64_remove_singlestep_breakpoint (&stepped_address_nnpc, &stepped_opcode_nnpc) !=0 ) { +return ; + } + } +kgdb_handle_exception (0x172 ,SIGTRAP ,0 , regs);local_irq_restore (flags); + +#ifdef DEBUG_SPARC64_KGDB +printk (KERN_CRIT "%s(%d): LEAVE KGDB - ad_npc=0x%lx, op_npc=0x%x, ad_nnpc=0x%lx, " +"op_nnpc=0x%x, pc=0x%lx, npc=0x%lx, cpu=%d, kgdb_active=%d, kgdb_single_step=%d, " +"ss_cpu=%d, kgdb_contthread=0x%lx, tl=0x%lx, pid=%d \n" , + __FUNCTION__, __LINE__, stepped_address_npc, stepped_opcode_npc, + stepped_address_nnpc, stepped_opcode_nnpc, regs->tpc, regs->tnpc, +raw_smp_processor_id (),atomic_read (&kgdb_active), kgdb_single_step, +atomic_read (&kgdb_cpu_doing_single_step), kgdb_contthread, + trap_level, (current!=0 ?current->pid:0 )); +#endif }int kgdb_arch_init (void )
drivers/misc/kgdbts.c +0 -4
@@ -133,11 +133,7 @@ static int force_hwbrks;static int hwbreaks_ok;static int hw_break_val;static int hw_break_val2; -#if defined(CONFIG_SPARC ) -static int arch_needs_sstep_emulation =1 ; -#else static int arch_needs_sstep_emulation; -#endif static unsigned long sstep_addr;static int sstep_state;
Quoted 1 line
It's a 2 minute hack, just test this patch below.
The report: works great (well, after the needed dain-bramaging to fit it back into the older kernel :-) ). Makes kgdbts solid.
[patch snipped]
Chris
David Miller
maintainerFrom: Chris Torek <[email protected]>
Date: Mon, 16 Mar 2009 12:00:40 -0600
Quoted 4 lines
Quoted 1 line
It's a 2 minute hack, just test this patch below.
The report: works great (well, after the needed dain-bramaging to fit it back into the older kernel :-) ). Makes kgdbts solid.
Thanks for testing.
David Miller
maintainerFrom: Chris Torek <[email protected]>
Date: Sat, 14 Mar 2009 17:32:39 -0600
Quoted 12 lines
(quoted diff) +12
-0+/* Macros below and sparc64GetNpc() code is mainly borrowed + * from gdb::sparc-tdep.c and gdb::sparc64-linux-tdep.c + */ + +#define X_OP(i) (((i) >> 30) & 0x3) +#define X_RD(i) (((i) >> 25) & 0x1f) +#define X_A(i) (((i) >> 29) & 1) +#define X_COND(i) (((i) >> 25) & 0xf) +#define X_OP2(i) (((i) >> 22) & 0x7) +#define X_IMM22(i) ((i) & 0x3fffff) +#define X_OP3(i) (((i) >> 19) & 0x3f) +#define X_RS1(i) (((i) >> 14) & 0x1f)
Review
Quoted 10 lines
(quoted diff) +10
-0+#define X_RS2(i) ((i) & 0x1f) +#define X_I(i) (((i) >> 13) & 1) + +/* Sign extension macros. */ +#define X_DISP22(i) ((X_IMM22 (i) ^ 0x200000) - 0x200000) +#define X_DISP19(i) ((((i) & 0x7ffff) ^ 0x40000) - 0x40000) +#define X_SIMM13(i) ((((i) & 0x1fff) ^ 0x1000) - 0x1000) + + +static unsigned long sparc64GetNpc(unsigned long pc, unsigned long *npc, const struct pt_regs *regs)
arch/sparc/kernel/kprobes.c has this same code, I think it would be wise to put that into a common place and use it instead of adding yet another copy of the same logic.
Otherwise, looks mostly fine.