aboutsummaryrefslogtreecommitdiffstats
path: root/arch/m32r/kernel/sys_m32r.c
diff options
context:
space:
mode:
authorHirokazu Takata <takata@linux-m32r.org>2006-02-20 21:28:17 -0500
committerLinus Torvalds <torvalds@g5.osdl.org>2006-02-20 23:00:12 -0500
commitcf535ea52e68e3ee6f4a90cc383faa1ee857f14d (patch)
tree1217d6b27e99c81b4e9cf003ddd4f71a93ad0c2b /arch/m32r/kernel/sys_m32r.c
parentb04ec261bd64f927bf3fce5cf9eeb0225557939d (diff)
[PATCH] m32r: update sys_tas() routine
This patch updates and fixes sys_tas() routine for m32r. In the previous implementation, a lockup rarely caused at sys_tas() routine in SMP environment. > > The problem is that touching *addr will generate an oops if that page isn't > > paged in. If we convert it to use get_user() then that's an improvement, > > but we must not run get_user() under spinlock or local_irq_disable(). I rewrote sys_tas() routine by using "lock -> unlock" instructions, and utilizing the m32r's interrupt handling characteristics; the m32r processor can accept interrupts only at the 32-bit instruction boundary. So, the "unlock" instruction can be executed continuously after the "lock" instruction execution without any interruptions. In addition, to solve such a page_fault problem, I use a fixup code like get_user(). And, as for the kernel lockup problem, we found that a calling do_page_fault() routine with disabling interrupts might cause a lockup at flush_tlb_others(), because we checked a completion of IPI handler's operations in a spin-locked critical section. Therefore, by using "lock -> unlock" code, we can implement the sys_tas() rouitine without disabling interrupts explicitly, then no lockups would happen at flush_tlb_others(), I hope. Compile check and some working test in SMP environment have done. Signed-off-by: Hirokazu Takata <takata@linux-m32r.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/m32r/kernel/sys_m32r.c')
-rw-r--r--arch/m32r/kernel/sys_m32r.c61
1 files changed, 34 insertions, 27 deletions
diff --git a/arch/m32r/kernel/sys_m32r.c b/arch/m32r/kernel/sys_m32r.c
index fe55b28d3725..670cb49210af 100644
--- a/arch/m32r/kernel/sys_m32r.c
+++ b/arch/m32r/kernel/sys_m32r.c
@@ -29,28 +29,7 @@
29 29
30/* 30/*
31 * sys_tas() - test-and-set 31 * sys_tas() - test-and-set
32 * linuxthreads testing version
33 */ 32 */
34#ifndef CONFIG_SMP
35asmlinkage int sys_tas(int *addr)
36{
37 int oldval;
38 unsigned long flags;
39
40 if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
41 return -EFAULT;
42 local_irq_save(flags);
43 oldval = *addr;
44 if (!oldval)
45 *addr = 1;
46 local_irq_restore(flags);
47 return oldval;
48}
49#else /* CONFIG_SMP */
50#include <linux/spinlock.h>
51
52static DEFINE_SPINLOCK(tas_lock);
53
54asmlinkage int sys_tas(int *addr) 33asmlinkage int sys_tas(int *addr)
55{ 34{
56 int oldval; 35 int oldval;
@@ -58,15 +37,43 @@ asmlinkage int sys_tas(int *addr)
58 if (!access_ok(VERIFY_WRITE, addr, sizeof (int))) 37 if (!access_ok(VERIFY_WRITE, addr, sizeof (int)))
59 return -EFAULT; 38 return -EFAULT;
60 39
61 _raw_spin_lock(&tas_lock); 40 /* atomic operation:
62 oldval = *addr; 41 * oldval = *addr; *addr = 1;
63 if (!oldval) 42 */
64 *addr = 1; 43 __asm__ __volatile__ (
65 _raw_spin_unlock(&tas_lock); 44 DCACHE_CLEAR("%0", "r4", "%1")
45 " .fillinsn\n"
46 "1:\n"
47 " lock %0, @%1 -> unlock %2, @%1\n"
48 "2:\n"
49 /* NOTE:
50 * The m32r processor can accept interrupts only
51 * at the 32-bit instruction boundary.
52 * So, in the above code, the "unlock" instruction
53 * can be executed continuously after the "lock"
54 * instruction execution without any interruptions.
55 */
56 ".section .fixup,\"ax\"\n"
57 " .balign 4\n"
58 "3: ldi %0, #%3\n"
59 " seth r14, #high(2b)\n"
60 " or3 r14, r14, #low(2b)\n"
61 " jmp r14\n"
62 ".previous\n"
63 ".section __ex_table,\"a\"\n"
64 " .balign 4\n"
65 " .long 1b,3b\n"
66 ".previous\n"
67 : "=&r" (oldval)
68 : "r" (addr), "r" (1), "i"(-EFAULT)
69 : "r14", "memory"
70#ifdef CONFIG_CHIP_M32700_TS1
71 , "r4"
72#endif /* CONFIG_CHIP_M32700_TS1 */
73 );
66 74
67 return oldval; 75 return oldval;
68} 76}
69#endif /* CONFIG_SMP */
70 77
71/* 78/*
72 * sys_pipe() is the normal C calling standard for creating 79 * sys_pipe() is the normal C calling standard for creating