aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc64/kernel/ptrace.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/sparc64/kernel/ptrace.c')
-rw-r--r--arch/sparc64/kernel/ptrace.c101
1 files changed, 55 insertions, 46 deletions
diff --git a/arch/sparc64/kernel/ptrace.c b/arch/sparc64/kernel/ptrace.c
index 1722dc51b0d8..5f080cf04b33 100644
--- a/arch/sparc64/kernel/ptrace.c
+++ b/arch/sparc64/kernel/ptrace.c
@@ -103,6 +103,55 @@ void ptrace_disable(struct task_struct *child)
103 /* nothing to do */ 103 /* nothing to do */
104} 104}
105 105
106/* To get the necessary page struct, access_process_vm() first calls
107 * get_user_pages(). This has done a flush_dcache_page() on the
108 * accessed page. Then our caller (copy_{to,from}_user_page()) did
109 * to memcpy to read/write the data from that page.
110 *
111 * Now, the only thing we have to do is:
112 * 1) flush the D-cache if it's possible than an illegal alias
113 * has been created
114 * 2) flush the I-cache if this is pre-cheetah and we did a write
115 */
116void flush_ptrace_access(struct vm_area_struct *vma, struct page *page,
117 unsigned long uaddr, void *kaddr,
118 unsigned long len, int write)
119{
120 BUG_ON(len > PAGE_SIZE);
121
122#ifdef DCACHE_ALIASING_POSSIBLE
123 /* If bit 13 of the kernel address we used to access the
124 * user page is the same as the virtual address that page
125 * is mapped to in the user's address space, we can skip the
126 * D-cache flush.
127 */
128 if ((uaddr ^ kaddr) & (1UL << 13)) {
129 unsigned long start = __pa(kaddr);
130 unsigned long end = start + len;
131
132 if (tlb_type == spitfire) {
133 for (; start < end; start += 32)
134 spitfire_put_dcache_tag(va & 0x3fe0, 0x0);
135 } else {
136 for (; start < end; start += 32)
137 __asm__ __volatile__(
138 "stxa %%g0, [%0] %1\n\t"
139 "membar #Sync"
140 : /* no outputs */
141 : "r" (va),
142 "i" (ASI_DCACHE_INVALIDATE));
143 }
144 }
145#endif
146 if (write && tlb_type == spitfire) {
147 unsigned long start = (unsigned long) kaddr;
148 unsigned long end = start + len;
149
150 for (; start < end; start += 32)
151 flushi(start);
152 }
153}
154
106asmlinkage void do_ptrace(struct pt_regs *regs) 155asmlinkage void do_ptrace(struct pt_regs *regs)
107{ 156{
108 int request = regs->u_regs[UREG_I0]; 157 int request = regs->u_regs[UREG_I0];
@@ -227,7 +276,7 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
227 pt_error_return(regs, -res); 276 pt_error_return(regs, -res);
228 else 277 else
229 pt_os_succ_return(regs, tmp64, (void __user *) data); 278 pt_os_succ_return(regs, tmp64, (void __user *) data);
230 goto flush_and_out; 279 goto out_tsk;
231 } 280 }
232 281
233 case PTRACE_POKETEXT: /* write the word at location addr. */ 282 case PTRACE_POKETEXT: /* write the word at location addr. */
@@ -253,7 +302,7 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
253 pt_error_return(regs, -res); 302 pt_error_return(regs, -res);
254 else 303 else
255 pt_succ_return(regs, res); 304 pt_succ_return(regs, res);
256 goto flush_and_out; 305 goto out_tsk;
257 } 306 }
258 307
259 case PTRACE_GETREGS: { 308 case PTRACE_GETREGS: {
@@ -485,12 +534,12 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
485 (char __user *)addr2, data); 534 (char __user *)addr2, data);
486 if (res == data) { 535 if (res == data) {
487 pt_succ_return(regs, 0); 536 pt_succ_return(regs, 0);
488 goto flush_and_out; 537 goto out_tsk;
489 } 538 }
490 if (res >= 0) 539 if (res >= 0)
491 res = -EIO; 540 res = -EIO;
492 pt_error_return(regs, -res); 541 pt_error_return(regs, -res);
493 goto flush_and_out; 542 goto out_tsk;
494 } 543 }
495 544
496 case PTRACE_WRITETEXT: 545 case PTRACE_WRITETEXT:
@@ -499,12 +548,12 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
499 addr, data); 548 addr, data);
500 if (res == data) { 549 if (res == data) {
501 pt_succ_return(regs, 0); 550 pt_succ_return(regs, 0);
502 goto flush_and_out; 551 goto out_tsk;
503 } 552 }
504 if (res >= 0) 553 if (res >= 0)
505 res = -EIO; 554 res = -EIO;
506 pt_error_return(regs, -res); 555 pt_error_return(regs, -res);
507 goto flush_and_out; 556 goto out_tsk;
508 } 557 }
509 case PTRACE_SYSCALL: /* continue and stop at (return from) syscall */ 558 case PTRACE_SYSCALL: /* continue and stop at (return from) syscall */
510 addr = 1; 559 addr = 1;
@@ -514,25 +563,6 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
514 pt_error_return(regs, EIO); 563 pt_error_return(regs, EIO);
515 goto out_tsk; 564 goto out_tsk;
516 } 565 }
517 if (addr != 1) {
518 unsigned long pc_mask = ~0UL;
519
520 if ((child->thread_info->flags & _TIF_32BIT) != 0)
521 pc_mask = 0xffffffff;
522
523 if (addr & 3) {
524 pt_error_return(regs, EINVAL);
525 goto out_tsk;
526 }
527#ifdef DEBUG_PTRACE
528 printk ("Original: %016lx %016lx\n",
529 child->thread_info->kregs->tpc,
530 child->thread_info->kregs->tnpc);
531 printk ("Continuing with %016lx %016lx\n", addr, addr+4);
532#endif
533 child->thread_info->kregs->tpc = (addr & pc_mask);
534 child->thread_info->kregs->tnpc = ((addr + 4) & pc_mask);
535 }
536 566
537 if (request == PTRACE_SYSCALL) { 567 if (request == PTRACE_SYSCALL) {
538 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE); 568 set_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
@@ -590,27 +620,6 @@ asmlinkage void do_ptrace(struct pt_regs *regs)
590 goto out_tsk; 620 goto out_tsk;
591 } 621 }
592 } 622 }
593flush_and_out:
594 {
595 unsigned long va;
596
597 if (tlb_type == cheetah || tlb_type == cheetah_plus) {
598 for (va = 0; va < (1 << 16); va += (1 << 5))
599 spitfire_put_dcache_tag(va, 0x0);
600 /* No need to mess with I-cache on Cheetah. */
601 } else {
602 for (va = 0; va < L1DCACHE_SIZE; va += 32)
603 spitfire_put_dcache_tag(va, 0x0);
604 if (request == PTRACE_PEEKTEXT ||
605 request == PTRACE_POKETEXT ||
606 request == PTRACE_READTEXT ||
607 request == PTRACE_WRITETEXT) {
608 for (va = 0; va < (PAGE_SIZE << 1); va += 32)
609 spitfire_put_icache_tag(va, 0x0);
610 __asm__ __volatile__("flush %g6");
611 }
612 }
613 }
614out_tsk: 623out_tsk:
615 if (child) 624 if (child)
616 put_task_struct(child); 625 put_task_struct(child);