Skip to content

Commit c8bf380

Browse files
heiherpaulburton
authored andcommitted
MIPS: Fix ejtag handler on SMP
On SMP systems, the shared ejtag debug buffer may be overwritten by other cores, because every cores can generate ejtag exception at same time. Unfortunately, in that context, it's difficult to relax more registers to access per cpu buffers. so use ll/sc to serialize the access. [paul.burton@mips.com: This could in theory be backported at least as far back as the beginning of the git era, however in general it's exceedingly rare that anyone would hit this without further changes, so it doesn't seem worthwhile marking for backport.] Signed-off-by: Heiher <r@hev.cc> Patchwork: https://patchwork.linux-mips.org/patch/19507/ Signed-off-by: Paul Burton <paul.burton@mips.com> Cc: jhogan@kernel.org Cc: ralf@linux-mips.org
1 parent be462bd commit c8bf380

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

arch/mips/kernel/genex.S

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,16 +354,56 @@ NESTED(ejtag_debug_handler, PT_SIZE, sp)
354354
sll k0, k0, 30 # Check for SDBBP.
355355
bgez k0, ejtag_return
356356

357+
#ifdef CONFIG_SMP
358+
1: PTR_LA k0, ejtag_debug_buffer_spinlock
359+
ll k0, 0(k0)
360+
bnez k0, 1b
361+
PTR_LA k0, ejtag_debug_buffer_spinlock
362+
sc k0, 0(k0)
363+
beqz k0, 1b
364+
# ifdef CONFIG_WEAK_REORDERING_BEYOND_LLSC
365+
sync
366+
# endif
367+
368+
PTR_LA k0, ejtag_debug_buffer
369+
LONG_S k1, 0(k0)
370+
371+
ASM_CPUID_MFC0 k1, ASM_SMP_CPUID_REG
372+
PTR_SRL k1, SMP_CPUID_PTRSHIFT
373+
PTR_SLL k1, LONGLOG
374+
PTR_LA k0, ejtag_debug_buffer_per_cpu
375+
PTR_ADDU k0, k1
376+
377+
PTR_LA k1, ejtag_debug_buffer
378+
LONG_L k1, 0(k1)
379+
LONG_S k1, 0(k0)
380+
381+
PTR_LA k0, ejtag_debug_buffer_spinlock
382+
sw zero, 0(k0)
383+
#else
357384
PTR_LA k0, ejtag_debug_buffer
358385
LONG_S k1, 0(k0)
386+
#endif
387+
359388
SAVE_ALL
360389
move a0, sp
361390
jal ejtag_exception_handler
362391
RESTORE_ALL
392+
393+
#ifdef CONFIG_SMP
394+
ASM_CPUID_MFC0 k1, ASM_SMP_CPUID_REG
395+
PTR_SRL k1, SMP_CPUID_PTRSHIFT
396+
PTR_SLL k1, LONGLOG
397+
PTR_LA k0, ejtag_debug_buffer_per_cpu
398+
PTR_ADDU k0, k1
399+
LONG_L k1, 0(k0)
400+
#else
363401
PTR_LA k0, ejtag_debug_buffer
364402
LONG_L k1, 0(k0)
403+
#endif
365404

366405
ejtag_return:
406+
back_to_back_c0_hazard
367407
MFC0 k0, CP0_DESAVE
368408
.set mips32
369409
deret
@@ -377,6 +417,12 @@ ejtag_return:
377417
.data
378418
EXPORT(ejtag_debug_buffer)
379419
.fill LONGSIZE
420+
#ifdef CONFIG_SMP
421+
EXPORT(ejtag_debug_buffer_spinlock)
422+
.fill LONGSIZE
423+
EXPORT(ejtag_debug_buffer_per_cpu)
424+
.fill LONGSIZE * NR_CPUS
425+
#endif
380426
.previous
381427

382428
__INIT

0 commit comments

Comments
 (0)