* [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed.
@ 2018-12-31 15:32 guoren
2018-12-31 15:32 ` [PATCH 02/14] csky: bugfix gdb coredump error guoren
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:32 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
Glibc function mmap(... O_SYNC) will make page to _PAGE_UNCACHE +
_PAGE_SO and strong-order page couldn't support unalignment access.
So remove _PAGE_SO from _PAGE_UNCACHE, also sync abiv1 with the macro
of _PAGE_SO.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Reported-by: Liu Renwei <Renwei.Liu@verisilicon.com>
Tested-by: Yuan Qiyun <qiyun_yuan@c-sky.com>
---
arch/csky/abiv1/inc/abi/pgtable-bits.h | 1 +
arch/csky/abiv2/inc/abi/pgtable-bits.h | 2 +-
arch/csky/mm/ioremap.c | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/csky/abiv1/inc/abi/pgtable-bits.h b/arch/csky/abiv1/inc/abi/pgtable-bits.h
index 455075b..d605445 100644
--- a/arch/csky/abiv1/inc/abi/pgtable-bits.h
+++ b/arch/csky/abiv1/inc/abi/pgtable-bits.h
@@ -26,6 +26,7 @@
#define _PAGE_CACHE (3<<9)
#define _PAGE_UNCACHE (2<<9)
+#define _PAGE_SO _PAGE_UNCACHE
#define _CACHE_MASK (7<<9)
diff --git a/arch/csky/abiv2/inc/abi/pgtable-bits.h b/arch/csky/abiv2/inc/abi/pgtable-bits.h
index b20ae19..137f793 100644
--- a/arch/csky/abiv2/inc/abi/pgtable-bits.h
+++ b/arch/csky/abiv2/inc/abi/pgtable-bits.h
@@ -32,6 +32,6 @@
#define _CACHE_MASK _PAGE_CACHE
#define _CACHE_CACHED (_PAGE_VALID | _PAGE_CACHE | _PAGE_BUF)
-#define _CACHE_UNCACHED (_PAGE_VALID | _PAGE_SO)
+#define _CACHE_UNCACHED (_PAGE_VALID)
#endif /* __ASM_CSKY_PGTABLE_BITS_H */
diff --git a/arch/csky/mm/ioremap.c b/arch/csky/mm/ioremap.c
index 7ad3ff1..cb7c03e 100644
--- a/arch/csky/mm/ioremap.c
+++ b/arch/csky/mm/ioremap.c
@@ -30,7 +30,7 @@ void __iomem *ioremap(phys_addr_t addr, size_t size)
vaddr = (unsigned long)area->addr;
prot = __pgprot(_PAGE_PRESENT | __READABLE | __WRITEABLE |
- _PAGE_GLOBAL | _CACHE_UNCACHED);
+ _PAGE_GLOBAL | _CACHE_UNCACHED | _PAGE_SO);
if (ioremap_page_range(vaddr, vaddr + size, addr, prot)) {
free_vm_area(area);
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 02/14] csky: bugfix gdb coredump error.
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
@ 2018-12-31 15:32 ` guoren
2018-12-31 15:32 ` [PATCH 03/14] csky: fixup remove vdsp implement for kernel guoren
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:32 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
In gdb/bfd elf32-csky.c, csky_elf_grok_prstatus() use fixed size of
elf_prstatus. It's 148 for abiv1 and 220 for abiv2, the size is enough
for coredump and no need full sizeof(struct pt_regs).
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
Reported-by: Lu Baoquan <lu.baoquan@intellif.com>
Reported-by: Liu Mao <liu.mao@intellif.com>
---
arch/csky/include/asm/elf.h | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/arch/csky/include/asm/elf.h b/arch/csky/include/asm/elf.h
index 48b5366..d6dbc00 100644
--- a/arch/csky/include/asm/elf.h
+++ b/arch/csky/include/asm/elf.h
@@ -31,7 +31,12 @@ typedef unsigned long elf_greg_t;
typedef struct user_fp elf_fpregset_t;
-#define ELF_NGREG (sizeof(struct pt_regs) / sizeof(elf_greg_t))
+/*
+ * In gdb/bfd elf32-csky.c, csky_elf_grok_prstatus() use fixed size of
+ * elf_prstatus. It's 148 for abiv1 and 220 for abiv2, the size is enough
+ * for coredump and no need full sizeof(struct pt_regs).
+ */
+#define ELF_NGREG ((sizeof(struct pt_regs) / sizeof(elf_greg_t)) - 2)
typedef elf_greg_t elf_gregset_t[ELF_NGREG];
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 03/14] csky: fixup remove vdsp implement for kernel.
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
2018-12-31 15:32 ` [PATCH 02/14] csky: bugfix gdb coredump error guoren
@ 2018-12-31 15:32 ` guoren
2018-12-31 15:32 ` [PATCH 04/14] csky: remove syscall_exit_work guoren
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:32 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
The vr regs for vdsp only saved in task_switch not in every
exception trap-in. The memcpy with vdsp instructions will
destroy the vr regs for user space applications.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/abiv2/memcpy.S | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/arch/csky/abiv2/memcpy.S b/arch/csky/abiv2/memcpy.S
index 987fec6..145bf3a 100644
--- a/arch/csky/abiv2/memcpy.S
+++ b/arch/csky/abiv2/memcpy.S
@@ -27,13 +27,7 @@ ENTRY(memcpy)
LABLE_ALIGN
.L_len_larger_16bytes:
-#if defined(__CSKY_VDSPV2__)
- vldx.8 vr0, (r1), r19
- PRE_BNEZAD (r18)
- addi r1, 16
- vstx.8 vr0, (r0), r19
- addi r0, 16
-#elif defined(__CK860__)
+#if defined(__CK860__)
ldw r3, (r1, 0)
stw r3, (r0, 0)
ldw r3, (r1, 4)
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 04/14] csky: remove syscall_exit_work
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
2018-12-31 15:32 ` [PATCH 02/14] csky: bugfix gdb coredump error guoren
2018-12-31 15:32 ` [PATCH 03/14] csky: fixup remove vdsp implement for kernel guoren
@ 2018-12-31 15:32 ` guoren
2018-12-31 15:32 ` [PATCH 05/14] csky: fixup save hi,lo,dspcr regs in switch_stack guoren
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:32 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
Remove syscall_exit_work and union all to ret_from_exception.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/kernel/entry.S | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/arch/csky/kernel/entry.S b/arch/csky/kernel/entry.S
index 79f92b8..2b4a851 100644
--- a/arch/csky/kernel/entry.S
+++ b/arch/csky/kernel/entry.S
@@ -183,18 +183,10 @@ ENTRY(csky_systemcall)
#endif
stw a0, (sp, LSAVE_A0) /* Save return value */
- movi a0, 1 /* leave system call */
- mov a1, sp /* sp = pt_regs pointer */
- jbsr syscall_trace
-
-syscall_exit_work:
- ld syscallid, (sp, LSAVE_PSR)
- btsti syscallid, 31
- bt 2f
-
- jmpi resume_userspace
-
-2: RESTORE_ALL
+ movi a0, 1 /* leave system call */
+ mov a1, sp /* right now, sp --> pt_regs */
+ jbsr syscall_trace
+ br ret_from_exception
ENTRY(ret_from_kernel_thread)
jbsr schedule_tail
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 05/14] csky: fixup save hi,lo,dspcr regs in switch_stack.
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
` (2 preceding siblings ...)
2018-12-31 15:32 ` [PATCH 04/14] csky: remove syscall_exit_work guoren
@ 2018-12-31 15:32 ` guoren
2018-12-31 15:32 ` [PATCH 07/14] csky: CPU-hotplug supported for SMP guoren
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:32 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
HI, LO, DSPCR registers are 807/810 related regs and no need for 610/860.
All of the regs must be saved in pt_regs and switch_stack. This patch
fixup saving dspcr reg in switch_stack and pt_regs.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/abiv1/inc/abi/switch_context.h | 17 ++++++++++++++
arch/csky/abiv2/inc/abi/entry.h | 28 ++++++++++++++++++++---
arch/csky/abiv2/inc/abi/switch_context.h | 32 ++++++++++++++++++++++++++
arch/csky/include/asm/processor.h | 3 +--
arch/csky/include/uapi/asm/ptrace.h | 39 +-------------------------------
arch/csky/kernel/asm-offsets.c | 2 --
arch/csky/kernel/entry.S | 22 ------------------
arch/csky/kernel/ptrace.c | 4 +++-
8 files changed, 79 insertions(+), 68 deletions(-)
create mode 100644 arch/csky/abiv1/inc/abi/switch_context.h
create mode 100644 arch/csky/abiv2/inc/abi/switch_context.h
diff --git a/arch/csky/abiv1/inc/abi/switch_context.h b/arch/csky/abiv1/inc/abi/switch_context.h
new file mode 100644
index 0000000..17c8268
--- /dev/null
+++ b/arch/csky/abiv1/inc/abi/switch_context.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ABI_CSKY_PTRACE_H
+#define __ABI_CSKY_PTRACE_H
+
+struct switch_stack {
+ unsigned long r8;
+ unsigned long r9;
+ unsigned long r10;
+ unsigned long r11;
+ unsigned long r12;
+ unsigned long r13;
+ unsigned long r14;
+ unsigned long r15;
+};
+#endif /* __ABI_CSKY_PTRACE_H */
diff --git a/arch/csky/abiv2/inc/abi/entry.h b/arch/csky/abiv2/inc/abi/entry.h
index acd0521..edc5cc0 100644
--- a/arch/csky/abiv2/inc/abi/entry.h
+++ b/arch/csky/abiv2/inc/abi/entry.h
@@ -57,6 +57,8 @@
stw lr, (sp, 60)
mflo lr
stw lr, (sp, 64)
+ mfcr lr, cr14
+ stw lr, (sp, 68)
#endif
subi sp, 80
.endm
@@ -77,6 +79,8 @@
mthi a0
ldw a0, (sp, 144)
mtlo a0
+ ldw a0, (sp, 148)
+ mtcr a0, cr14
#endif
ldw a0, (sp, 24)
@@ -93,9 +97,9 @@
.endm
.macro SAVE_SWITCH_STACK
- subi sp, 64
+ subi sp, 64
stm r4-r11, (sp)
- stw r15, (sp, 32)
+ stw lr, (sp, 32)
stw r16, (sp, 36)
stw r17, (sp, 40)
stw r26, (sp, 44)
@@ -103,11 +107,29 @@
stw r28, (sp, 52)
stw r29, (sp, 56)
stw r30, (sp, 60)
+#ifdef CONFIG_CPU_HAS_HILO
+ subi sp, 16
+ mfhi lr
+ stw lr, (sp, 0)
+ mflo lr
+ stw lr, (sp, 4)
+ mfcr lr, cr14
+ stw lr, (sp, 8)
+#endif
.endm
.macro RESTORE_SWITCH_STACK
+#ifdef CONFIG_CPU_HAS_HILO
+ ldw lr, (sp, 0)
+ mthi lr
+ ldw lr, (sp, 4)
+ mtlo lr
+ ldw lr, (sp, 8)
+ mtcr lr, cr14
+ addi sp, 16
+#endif
ldm r4-r11, (sp)
- ldw r15, (sp, 32)
+ ldw lr, (sp, 32)
ldw r16, (sp, 36)
ldw r17, (sp, 40)
ldw r26, (sp, 44)
diff --git a/arch/csky/abiv2/inc/abi/switch_context.h b/arch/csky/abiv2/inc/abi/switch_context.h
new file mode 100644
index 0000000..73a8124
--- /dev/null
+++ b/arch/csky/abiv2/inc/abi/switch_context.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ABI_CSKY_PTRACE_H
+#define __ABI_CSKY_PTRACE_H
+
+struct switch_stack {
+#ifdef CONFIG_CPU_HAS_HILO
+ unsigned long rhi;
+ unsigned long rlo;
+ unsigned long cr14;
+ unsigned long pad;
+#endif
+ unsigned long r4;
+ unsigned long r5;
+ unsigned long r6;
+ unsigned long r7;
+ unsigned long r8;
+ unsigned long r9;
+ unsigned long r10;
+ unsigned long r11;
+
+ unsigned long r15;
+ unsigned long r16;
+ unsigned long r17;
+ unsigned long r26;
+ unsigned long r27;
+ unsigned long r28;
+ unsigned long r29;
+ unsigned long r30;
+};
+#endif /* __ABI_CSKY_PTRACE_H */
diff --git a/arch/csky/include/asm/processor.h b/arch/csky/include/asm/processor.h
index b174865..5ac3f32 100644
--- a/arch/csky/include/asm/processor.h
+++ b/arch/csky/include/asm/processor.h
@@ -11,6 +11,7 @@
#include <asm/cache.h>
#include <abi/reg_ops.h>
#include <abi/regdef.h>
+#include <abi/switch_context.h>
#ifdef CONFIG_CPU_HAS_FPU
#include <abi/fpu.h>
#endif
@@ -50,8 +51,6 @@ struct thread_struct {
unsigned long ksp; /* kernel stack pointer */
unsigned long sr; /* saved status register */
unsigned long esp0; /* points to SR of stack frame */
- unsigned long hi;
- unsigned long lo;
/* Other stuff associated with the thread. */
unsigned long address; /* Last user fault */
diff --git a/arch/csky/include/uapi/asm/ptrace.h b/arch/csky/include/uapi/asm/ptrace.h
index f10d02c..a4eaa8d 100644
--- a/arch/csky/include/uapi/asm/ptrace.h
+++ b/arch/csky/include/uapi/asm/ptrace.h
@@ -36,7 +36,7 @@ struct pt_regs {
unsigned long rhi;
unsigned long rlo;
- unsigned long pad; /* reserved */
+ unsigned long dcsr;
#endif
};
@@ -48,43 +48,6 @@ struct user_fp {
unsigned long reserved;
};
-/*
- * Switch stack for switch_to after push pt_regs.
- *
- * ABI_CSKYV2: r4 ~ r11, r15 ~ r17, r26 ~ r30;
- * ABI_CSKYV1: r8 ~ r14, r15;
- */
-struct switch_stack {
-#if defined(__CSKYABIV2__)
- unsigned long r4;
- unsigned long r5;
- unsigned long r6;
- unsigned long r7;
- unsigned long r8;
- unsigned long r9;
- unsigned long r10;
- unsigned long r11;
-#else
- unsigned long r8;
- unsigned long r9;
- unsigned long r10;
- unsigned long r11;
- unsigned long r12;
- unsigned long r13;
- unsigned long r14;
-#endif
- unsigned long r15;
-#if defined(__CSKYABIV2__)
- unsigned long r16;
- unsigned long r17;
- unsigned long r26;
- unsigned long r27;
- unsigned long r28;
- unsigned long r29;
- unsigned long r30;
-#endif
-};
-
#ifdef __KERNEL__
#define PS_S 0x80000000 /* Supervisor Mode */
diff --git a/arch/csky/kernel/asm-offsets.c b/arch/csky/kernel/asm-offsets.c
index 8d3ed81..2f07670 100644
--- a/arch/csky/kernel/asm-offsets.c
+++ b/arch/csky/kernel/asm-offsets.c
@@ -24,8 +24,6 @@ int main(void)
DEFINE(THREAD_FESR, offsetof(struct thread_struct, user_fp.fesr));
DEFINE(THREAD_FCR, offsetof(struct thread_struct, user_fp.fcr));
DEFINE(THREAD_FPREG, offsetof(struct thread_struct, user_fp.vr));
- DEFINE(THREAD_DSPHI, offsetof(struct thread_struct, hi));
- DEFINE(THREAD_DSPLO, offsetof(struct thread_struct, lo));
/* offsets into the thread_info struct */
DEFINE(TINFO_FLAGS, offsetof(struct thread_info, flags));
diff --git a/arch/csky/kernel/entry.S b/arch/csky/kernel/entry.S
index 2b4a851..de378e4 100644
--- a/arch/csky/kernel/entry.S
+++ b/arch/csky/kernel/entry.S
@@ -346,34 +346,12 @@ ENTRY(__switch_to)
stw sp, (a3, THREAD_KSP)
-#ifdef CONFIG_CPU_HAS_HILO
- lrw r10, THREAD_DSPHI
- add r10, a3
- mfhi r6
- mflo r7
- stw r6, (r10, 0) /* THREAD_DSPHI */
- stw r7, (r10, 4) /* THREAD_DSPLO */
- mfcr r6, cr14
- stw r6, (r10, 8) /* THREAD_DSPCSR */
-#endif
-
/* Set up next process to run */
lrw a3, TASK_THREAD
addu a3, a1
ldw sp, (a3, THREAD_KSP) /* Set next kernel sp */
-#ifdef CONFIG_CPU_HAS_HILO
- lrw r10, THREAD_DSPHI
- add r10, a3
- ldw r6, (r10, 8) /* THREAD_DSPCSR */
- mtcr r6, cr14
- ldw r6, (r10, 0) /* THREAD_DSPHI */
- ldw r7, (r10, 4) /* THREAD_DSPLO */
- mthi r6
- mtlo r7
-#endif
-
ldw a2, (a3, THREAD_SR) /* Set next PSR */
mtcr a2, psr
diff --git a/arch/csky/kernel/ptrace.c b/arch/csky/kernel/ptrace.c
index 34b3025..a76d466 100644
--- a/arch/csky/kernel/ptrace.c
+++ b/arch/csky/kernel/ptrace.c
@@ -95,7 +95,9 @@ static int gpr_set(struct task_struct *target,
return ret;
regs.sr = task_pt_regs(target)->sr;
-
+#ifdef CONFIG_CPU_HAS_HILO
+ regs.dcsr = task_pt_regs(target)->dcsr;
+#endif
task_thread_info(target)->tp_value = regs.tls;
*task_pt_regs(target) = regs;
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 07/14] csky: CPU-hotplug supported for SMP
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
` (3 preceding siblings ...)
2018-12-31 15:32 ` [PATCH 05/14] csky: fixup save hi,lo,dspcr regs in switch_stack guoren
@ 2018-12-31 15:32 ` guoren
2018-12-31 15:32 ` [PATCH 08/14] csky: stacktrace supported guoren
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:32 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
This is a simple implement of CPU-hotplug for power saving. CPU use
wait instruction to enter power saving mode and waiting for IPI wakeup
signal.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/Kconfig | 9 ++++++
arch/csky/include/asm/smp.h | 4 +++
arch/csky/kernel/smp.c | 71 +++++++++++++++++++++++++++++++++++----------
3 files changed, 69 insertions(+), 15 deletions(-)
diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
index cb64f8d..8bdbe92 100644
--- a/arch/csky/Kconfig
+++ b/arch/csky/Kconfig
@@ -198,6 +198,15 @@ config RAM_BASE
hex "DRAM start addr (the same with memory-section in dts)"
default 0x0
+config HOTPLUG_CPU
+ bool "Support for hot-pluggable CPUs"
+ select GENERIC_IRQ_MIGRATION
+ depends on SMP
+ help
+ Say Y here to allow turning CPUs off and on. CPUs can be
+ controlled through /sys/devices/system/cpu/cpu1/hotplug/target.
+
+ Say N if you want to disable CPU hotplug.
endmenu
source "kernel/Kconfig.hz"
diff --git a/arch/csky/include/asm/smp.h b/arch/csky/include/asm/smp.h
index 4a929c4..668b79c 100644
--- a/arch/csky/include/asm/smp.h
+++ b/arch/csky/include/asm/smp.h
@@ -21,6 +21,10 @@ void __init set_send_ipi(void (*func)(const struct cpumask *mask), int irq);
#define raw_smp_processor_id() (current_thread_info()->cpu)
+int __cpu_disable(void);
+
+void __cpu_die(unsigned int cpu);
+
#endif /* CONFIG_SMP */
#endif /* __ASM_CSKY_SMP_H */
diff --git a/arch/csky/kernel/smp.c b/arch/csky/kernel/smp.c
index 74d6273..ddc4dd7 100644
--- a/arch/csky/kernel/smp.c
+++ b/arch/csky/kernel/smp.c
@@ -16,6 +16,7 @@
#include <linux/of.h>
#include <linux/sched/task_stack.h>
#include <linux/sched/mm.h>
+#include <linux/sched/hotplug.h>
#include <asm/irq.h>
#include <asm/traps.h>
#include <asm/sections.h>
@@ -112,12 +113,8 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
{
}
-static void __init enable_smp_ipi(void)
-{
- enable_percpu_irq(ipi_irq, 0);
-}
-
static int ipi_dummy_dev;
+
void __init setup_smp_ipi(void)
{
int rc;
@@ -130,7 +127,7 @@ void __init setup_smp_ipi(void)
if (rc)
panic("%s IRQ request failed\n", __func__);
- enable_smp_ipi();
+ enable_percpu_irq(ipi_irq, 0);
}
void __init setup_smp(void)
@@ -161,12 +158,10 @@ volatile unsigned int secondary_stack;
int __cpu_up(unsigned int cpu, struct task_struct *tidle)
{
- unsigned int tmp;
-
- secondary_stack = (unsigned int)tidle->stack + THREAD_SIZE;
+ unsigned long mask = 1 << cpu;
+ secondary_stack = (unsigned int)tidle->stack + THREAD_SIZE - 8;
secondary_hint = mfcr("cr31");
-
secondary_ccr = mfcr("cr18");
/*
@@ -176,10 +171,13 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle)
*/
mtcr("cr17", 0x22);
- /* Enable cpu in SMP reset ctrl reg */
- tmp = mfcr("cr<29, 0>");
- tmp |= 1 << cpu;
- mtcr("cr<29, 0>", tmp);
+ if (mask & mfcr("cr<29, 0>")) {
+ send_arch_ipi(cpumask_of(cpu));
+ } else {
+ /* Enable cpu in SMP reset ctrl reg */
+ mask |= mfcr("cr<29, 0>");
+ mtcr("cr<29, 0>", mask);
+ }
/* Wait for the cpu online */
while (!cpu_online(cpu));
@@ -219,7 +217,7 @@ void csky_start_secondary(void)
init_fpu();
#endif
- enable_smp_ipi();
+ enable_percpu_irq(ipi_irq, 0);
mmget(mm);
mmgrab(mm);
@@ -235,3 +233,46 @@ void csky_start_secondary(void)
preempt_disable();
cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
}
+
+#ifdef CONFIG_HOTPLUG_CPU
+int __cpu_disable(void)
+{
+ unsigned int cpu = smp_processor_id();
+
+ set_cpu_online(cpu, false);
+
+ irq_migrate_all_off_this_cpu();
+
+ clear_tasks_mm_cpumask(cpu);
+
+ return 0;
+}
+
+void __cpu_die(unsigned int cpu)
+{
+ if (!cpu_wait_death(cpu, 5)) {
+ pr_crit("CPU%u: shutdown failed\n", cpu);
+ return;
+ }
+ pr_notice("CPU%u: shutdown\n", cpu);
+}
+
+void arch_cpu_idle_dead(void)
+{
+ idle_task_exit();
+
+ cpu_report_death();
+
+ while (!secondary_stack)
+ arch_cpu_idle();
+
+ local_irq_disable();
+
+ asm volatile(
+ "mov sp, %0\n"
+ "mov r8, %0\n"
+ "jmpi csky_start_secondary"
+ :
+ : "r" (secondary_stack));
+}
+#endif
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 08/14] csky: stacktrace supported.
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
` (4 preceding siblings ...)
2018-12-31 15:32 ` [PATCH 07/14] csky: CPU-hotplug supported for SMP guoren
@ 2018-12-31 15:32 ` guoren
2018-12-31 15:33 ` [PATCH 09/14] csky: optimize kernel panic print guoren
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:32 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
The gcc option "-mbacktrace" will push fp(r8),lr into stack and we could
unwind the stack with:
fp = *fp
lr = (unsigned int *)fp[1]
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/Kconfig | 3 ++
arch/csky/Makefile | 4 +++
arch/csky/include/asm/thread_info.h | 4 +++
arch/csky/kernel/Makefile | 1 +
arch/csky/kernel/process.c | 29 +++++++++++--------
arch/csky/kernel/stacktrace.c | 57 +++++++++++++++++++++++++++++++++++++
6 files changed, 86 insertions(+), 12 deletions(-)
create mode 100644 arch/csky/kernel/stacktrace.c
diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
index 8bdbe92..65804d1 100644
--- a/arch/csky/Kconfig
+++ b/arch/csky/Kconfig
@@ -94,6 +94,9 @@ config MMU
config RWSEM_GENERIC_SPINLOCK
def_bool y
+config STACKTRACE_SUPPORT
+ def_bool y
+
config TIME_LOW_RES
def_bool y
diff --git a/arch/csky/Makefile b/arch/csky/Makefile
index c639fc1..3607a6e 100644
--- a/arch/csky/Makefile
+++ b/arch/csky/Makefile
@@ -47,6 +47,10 @@ ifeq ($(CSKYABI),abiv2)
KBUILD_CFLAGS += -mno-stack-size
endif
+ifdef CONFIG_STACKTRACE
+KBUILD_CFLAGS += -mbacktrace
+endif
+
abidirs := $(patsubst %,arch/csky/%/,$(CSKYABI))
KBUILD_CFLAGS += $(patsubst %,-I$(srctree)/%inc,$(abidirs))
diff --git a/arch/csky/include/asm/thread_info.h b/arch/csky/include/asm/thread_info.h
index a2c69a7..0e9d035 100644
--- a/arch/csky/include/asm/thread_info.h
+++ b/arch/csky/include/asm/thread_info.h
@@ -10,6 +10,7 @@
#include <asm/types.h>
#include <asm/page.h>
#include <asm/processor.h>
+#include <abi/switch_context.h>
struct thread_info {
struct task_struct *task;
@@ -36,6 +37,9 @@ struct thread_info {
#define THREAD_SIZE_ORDER (THREAD_SHIFT - PAGE_SHIFT)
+#define thread_saved_fp(tsk) \
+ ((unsigned long)(((struct switch_stack *)(tsk->thread.ksp))->r8))
+
static inline struct thread_info *current_thread_info(void)
{
unsigned long sp;
diff --git a/arch/csky/kernel/Makefile b/arch/csky/kernel/Makefile
index 4422de7..ba5ca48 100644
--- a/arch/csky/kernel/Makefile
+++ b/arch/csky/kernel/Makefile
@@ -6,3 +6,4 @@ obj-y += process.o cpu-probe.o ptrace.o dumpstack.o
obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_SMP) += smp.o
+obj-$(CONFIG_STACKTRACE) += stacktrace.o
diff --git a/arch/csky/kernel/process.c b/arch/csky/kernel/process.c
index 8ed2002..e555740 100644
--- a/arch/csky/kernel/process.c
+++ b/arch/csky/kernel/process.c
@@ -93,26 +93,31 @@ int dump_task_regs(struct task_struct *tsk, elf_gregset_t *pr_regs)
unsigned long get_wchan(struct task_struct *p)
{
- unsigned long esp, pc;
- unsigned long stack_page;
+ unsigned long lr;
+ unsigned long *fp, *stack_start, *stack_end;
int count = 0;
if (!p || p == current || p->state == TASK_RUNNING)
return 0;
- stack_page = (unsigned long)p;
- esp = p->thread.esp0;
+ stack_start = (unsigned long *)end_of_stack(p);
+ stack_end = (unsigned long *)(task_stack_page(p) + THREAD_SIZE);
+
+ fp = (unsigned long *) thread_saved_fp(p);
do {
- if (esp < stack_page+sizeof(struct task_struct) ||
- esp >= 8184+stack_page)
+ if (fp < stack_start || fp > stack_end)
return 0;
- /*FIXME: There's may be error here!*/
- pc = ((unsigned long *)esp)[1];
- /* FIXME: This depends on the order of these functions. */
- if (!in_sched_functions(pc))
- return pc;
- esp = *(unsigned long *) esp;
+#ifdef CONFIG_STACKTRACE
+ lr = fp[1];
+ fp = (unsigned long *)fp[0];
+#else
+ lr = *fp++;
+#endif
+ if (!in_sched_functions(lr) &&
+ __kernel_text_address(lr))
+ return lr;
} while (count++ < 16);
+
return 0;
}
EXPORT_SYMBOL(get_wchan);
diff --git a/arch/csky/kernel/stacktrace.c b/arch/csky/kernel/stacktrace.c
new file mode 100644
index 0000000..fec777a
--- /dev/null
+++ b/arch/csky/kernel/stacktrace.c
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd. */
+
+#include <linux/sched/debug.h>
+#include <linux/sched/task_stack.h>
+#include <linux/stacktrace.h>
+#include <linux/ftrace.h>
+
+void save_stack_trace(struct stack_trace *trace)
+{
+ save_stack_trace_tsk(current, trace);
+}
+EXPORT_SYMBOL_GPL(save_stack_trace);
+
+void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
+{
+ unsigned long *fp, *stack_start, *stack_end;
+ unsigned long addr;
+ int skip = trace->skip;
+ int savesched;
+ int graph_idx = 0;
+
+ if (tsk == current) {
+ asm volatile("mov %0, r8\n":"=r"(fp));
+ savesched = 1;
+ } else {
+ fp = (unsigned long *)thread_saved_fp(tsk);
+ savesched = 0;
+ }
+
+ addr = (unsigned long) fp & THREAD_MASK;
+ stack_start = (unsigned long *) addr;
+ stack_end = (unsigned long *) (addr + THREAD_SIZE);
+
+ while (fp > stack_start && fp < stack_end) {
+ unsigned long lpp, fpp;
+
+ fpp = fp[0];
+ lpp = fp[1];
+ if (!__kernel_text_address(lpp))
+ break;
+ else
+ lpp = ftrace_graph_ret_addr(tsk, &graph_idx, lpp, NULL);
+
+ if (savesched || !in_sched_functions(lpp)) {
+ if (skip) {
+ skip--;
+ } else {
+ trace->entries[trace->nr_entries++] = lpp;
+ if (trace->nr_entries >= trace->max_entries)
+ break;
+ }
+ }
+ fp = (unsigned long *)fpp;
+ }
+}
+EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 09/14] csky: optimize kernel panic print.
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
` (5 preceding siblings ...)
2018-12-31 15:32 ` [PATCH 08/14] csky: stacktrace supported guoren
@ 2018-12-31 15:33 ` guoren
2018-12-31 15:33 ` [PATCH 10/14] csky: remove unused members in processor.h guoren
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:33 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
Use STACKTRACE to optimize panic print more pretty and align registers
printing.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/kernel/dumpstack.c | 59 ++++++++++++++------------------------------
arch/csky/kernel/ptrace.c | 34 ++++++++++++++-----------
arch/csky/mm/fault.c | 4 +--
3 files changed, 41 insertions(+), 56 deletions(-)
diff --git a/arch/csky/kernel/dumpstack.c b/arch/csky/kernel/dumpstack.c
index a9a03ac..659253e 100644
--- a/arch/csky/kernel/dumpstack.c
+++ b/arch/csky/kernel/dumpstack.c
@@ -7,60 +7,39 @@ int kstack_depth_to_print = 48;
void show_trace(unsigned long *stack)
{
- unsigned long *endstack;
+ unsigned long *stack_end;
+ unsigned long *stack_start;
+ unsigned long *fp;
unsigned long addr;
- int i;
- pr_info("Call Trace:\n");
- addr = (unsigned long)stack + THREAD_SIZE - 1;
- endstack = (unsigned long *)(addr & -THREAD_SIZE);
- i = 0;
- while (stack + 1 <= endstack) {
- addr = *stack++;
- /*
- * If the address is either in the text segment of the
- * kernel, or in the region which contains vmalloc'ed
- * memory, it *may* be the address of a calling
- * routine; if so, print it so that someone tracing
- * down the cause of the crash will be able to figure
- * out the call path that was taken.
- */
- if (__kernel_text_address(addr)) {
-#ifndef CONFIG_KALLSYMS
- if (i % 5 == 0)
- pr_cont("\n ");
+ addr = (unsigned long) stack & THREAD_MASK;
+ stack_start = (unsigned long *) addr;
+ stack_end = (unsigned long *) (addr + THREAD_SIZE);
+
+ fp = stack;
+ pr_info("\nCall Trace:");
+
+ while (fp > stack_start && fp < stack_end) {
+#ifdef CONFIG_STACKTRACE
+ addr = fp[1];
+ fp = (unsigned long *) fp[0];
+#else
+ addr = *fp++;
#endif
- pr_cont(" [<%08lx>] %pS\n", addr, (void *)addr);
- i++;
- }
+ if (__kernel_text_address(addr))
+ pr_cont("\n[<%08lx>] %pS", addr, (void *)addr);
}
pr_cont("\n");
}
void show_stack(struct task_struct *task, unsigned long *stack)
{
- unsigned long *p;
- unsigned long *endstack;
- int i;
-
if (!stack) {
if (task)
- stack = (unsigned long *)task->thread.esp0;
+ stack = (unsigned long *)thread_saved_fp(task);
else
stack = (unsigned long *)&stack;
}
- endstack = (unsigned long *)
- (((unsigned long)stack + THREAD_SIZE - 1) & -THREAD_SIZE);
- pr_info("Stack from %08lx:", (unsigned long)stack);
- p = stack;
- for (i = 0; i < kstack_depth_to_print; i++) {
- if (p + 1 > endstack)
- break;
- if (i % 8 == 0)
- pr_cont("\n ");
- pr_cont(" %08lx", *p++);
- }
- pr_cont("\n");
show_trace(stack);
}
diff --git a/arch/csky/kernel/ptrace.c b/arch/csky/kernel/ptrace.c
index a76d466..eb62e07 100644
--- a/arch/csky/kernel/ptrace.c
+++ b/arch/csky/kernel/ptrace.c
@@ -241,6 +241,7 @@ asmlinkage void syscall_trace(int why, struct pt_regs *regs)
regs->regs[SYSTRACE_SAVENUM] = saved_why;
}
+extern void show_stack(struct task_struct *task, unsigned long *stack);
void show_regs(struct pt_regs *fp)
{
unsigned long *sp;
@@ -263,35 +264,37 @@ void show_regs(struct pt_regs *fp)
(int) (((unsigned long) current) + 2 * PAGE_SIZE));
}
- pr_info("PC: 0x%08lx\n", (long)fp->pc);
+ pr_info("PC: 0x%08lx (%pS)\n", (long)fp->pc, (void *)fp->pc);
+ pr_info("LR: 0x%08lx (%pS)\n", (long)fp->lr, (void *)fp->lr);
+ pr_info("SP: 0x%08lx\n", (long)fp);
pr_info("orig_a0: 0x%08lx\n", fp->orig_a0);
pr_info("PSR: 0x%08lx\n", (long)fp->sr);
- pr_info("a0: 0x%08lx a1: 0x%08lx a2: 0x%08lx a3: 0x%08lx\n",
- fp->a0, fp->a1, fp->a2, fp->a3);
+ pr_info(" a0: 0x%08lx a1: 0x%08lx a2: 0x%08lx a3: 0x%08lx\n",
+ fp->a0, fp->a1, fp->a2, fp->a3);
#if defined(__CSKYABIV2__)
- pr_info("r4: 0x%08lx r5: 0x%08lx r6: 0x%08lx r7: 0x%08lx\n",
+ pr_info(" r4: 0x%08lx r5: 0x%08lx r6: 0x%08lx r7: 0x%08lx\n",
fp->regs[0], fp->regs[1], fp->regs[2], fp->regs[3]);
- pr_info("r8: 0x%08lx r9: 0x%08lx r10: 0x%08lx r11: 0x%08lx\n",
+ pr_info(" r8: 0x%08lx r9: 0x%08lx r10: 0x%08lx r11: 0x%08lx\n",
fp->regs[4], fp->regs[5], fp->regs[6], fp->regs[7]);
- pr_info("r12 0x%08lx r13: 0x%08lx r15: 0x%08lx\n",
+ pr_info("r12: 0x%08lx r13: 0x%08lx r15: 0x%08lx\n",
fp->regs[8], fp->regs[9], fp->lr);
- pr_info("r16:0x%08lx r17: 0x%08lx r18: 0x%08lx r19: 0x%08lx\n",
+ pr_info("r16: 0x%08lx r17: 0x%08lx r18: 0x%08lx r19: 0x%08lx\n",
fp->exregs[0], fp->exregs[1], fp->exregs[2], fp->exregs[3]);
- pr_info("r20 0x%08lx r21: 0x%08lx r22: 0x%08lx r23: 0x%08lx\n",
+ pr_info("r20: 0x%08lx r21: 0x%08lx r22: 0x%08lx r23: 0x%08lx\n",
fp->exregs[4], fp->exregs[5], fp->exregs[6], fp->exregs[7]);
- pr_info("r24 0x%08lx r25: 0x%08lx r26: 0x%08lx r27: 0x%08lx\n",
+ pr_info("r24: 0x%08lx r25: 0x%08lx r26: 0x%08lx r27: 0x%08lx\n",
fp->exregs[8], fp->exregs[9], fp->exregs[10], fp->exregs[11]);
- pr_info("r28 0x%08lx r29: 0x%08lx r30: 0x%08lx tls: 0x%08lx\n",
+ pr_info("r28: 0x%08lx r29: 0x%08lx r30: 0x%08lx tls: 0x%08lx\n",
fp->exregs[12], fp->exregs[13], fp->exregs[14], fp->tls);
- pr_info("hi 0x%08lx lo: 0x%08lx\n",
+ pr_info(" hi: 0x%08lx lo: 0x%08lx\n",
fp->rhi, fp->rlo);
#else
- pr_info("r6: 0x%08lx r7: 0x%08lx r8: 0x%08lx r9: 0x%08lx\n",
+ pr_info(" r6: 0x%08lx r7: 0x%08lx r8: 0x%08lx r9: 0x%08lx\n",
fp->regs[0], fp->regs[1], fp->regs[2], fp->regs[3]);
- pr_info("r10: 0x%08lx r11: 0x%08lx r12: 0x%08lx r13: 0x%08lx\n",
+ pr_info("r10: 0x%08lx r11: 0x%08lx r12: 0x%08lx r13: 0x%08lx\n",
fp->regs[4], fp->regs[5], fp->regs[6], fp->regs[7]);
- pr_info("r14 0x%08lx r1: 0x%08lx r15: 0x%08lx\n",
+ pr_info("r14: 0x%08lx r1: 0x%08lx r15: 0x%08lx\n",
fp->regs[8], fp->regs[9], fp->lr);
#endif
@@ -313,4 +316,7 @@ void show_regs(struct pt_regs *fp)
pr_cont("%08x ", (int) *sp++);
}
pr_cont("\n");
+
+ show_stack(NULL, (unsigned long *)fp->regs[4]);
+ return;
}
diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
index 7df57f9..6a94661 100644
--- a/arch/csky/mm/fault.c
+++ b/arch/csky/mm/fault.c
@@ -188,8 +188,8 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,
* terminate things with extreme prejudice.
*/
bust_spinlocks(1);
- pr_alert("Unable to %s at vaddr: %08lx, epc: %08lx\n",
- __func__, address, regs->pc);
+ pr_alert("Unable to handle kernel paging request at virtual "
+ "address 0x%08lx, pc: 0x%08lx\n", address, regs->pc);
die_if_kernel("Oops", regs, write);
out_of_memory:
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 10/14] csky: remove unused members in processor.h
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
` (6 preceding siblings ...)
2018-12-31 15:33 ` [PATCH 09/14] csky: optimize kernel panic print guoren
@ 2018-12-31 15:33 ` guoren
2018-12-31 15:33 ` [PATCH 11/14] csky: basic ftrace supported guoren
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:33 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
Cleanup struct cpuinfo_csky and struct thread_struct, remove all esp0
related code. We could get pt_regs from sp and backtrace could use fp
in switch_stack.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/include/asm/processor.h | 12 ------------
arch/csky/kernel/asm-offsets.c | 1 -
arch/csky/kernel/entry.S | 12 ------------
arch/csky/kernel/ptrace.c | 4 ----
arch/csky/kernel/signal.c | 2 --
arch/csky/kernel/traps.c | 6 ------
arch/csky/mm/fault.c | 3 ---
7 files changed, 40 deletions(-)
diff --git a/arch/csky/include/asm/processor.h b/arch/csky/include/asm/processor.h
index 5ac3f32..8f45481 100644
--- a/arch/csky/include/asm/processor.h
+++ b/arch/csky/include/asm/processor.h
@@ -17,14 +17,7 @@
#endif
struct cpuinfo_csky {
- unsigned long udelay_val;
unsigned long asid_cache;
- /*
- * Capability and feature descriptor structure for CSKY CPU
- */
- unsigned long options;
- unsigned int processor_id[4];
- unsigned int fpu_id;
} __aligned(SMP_CACHE_BYTES);
extern struct cpuinfo_csky cpu_data[];
@@ -50,11 +43,6 @@ extern struct cpuinfo_csky cpu_data[];
struct thread_struct {
unsigned long ksp; /* kernel stack pointer */
unsigned long sr; /* saved status register */
- unsigned long esp0; /* points to SR of stack frame */
-
- /* Other stuff associated with the thread. */
- unsigned long address; /* Last user fault */
- unsigned long error_code;
/* FPU regs */
struct user_fp __aligned(16) user_fp;
diff --git a/arch/csky/kernel/asm-offsets.c b/arch/csky/kernel/asm-offsets.c
index 2f07670..9b48b1b 100644
--- a/arch/csky/kernel/asm-offsets.c
+++ b/arch/csky/kernel/asm-offsets.c
@@ -20,7 +20,6 @@ int main(void)
/* offsets into the thread struct */
DEFINE(THREAD_KSP, offsetof(struct thread_struct, ksp));
DEFINE(THREAD_SR, offsetof(struct thread_struct, sr));
- DEFINE(THREAD_ESP0, offsetof(struct thread_struct, esp0));
DEFINE(THREAD_FESR, offsetof(struct thread_struct, user_fp.fesr));
DEFINE(THREAD_FCR, offsetof(struct thread_struct, user_fp.fcr));
DEFINE(THREAD_FPREG, offsetof(struct thread_struct, user_fp.vr));
diff --git a/arch/csky/kernel/entry.S b/arch/csky/kernel/entry.S
index de378e4..5137ed9 100644
--- a/arch/csky/kernel/entry.S
+++ b/arch/csky/kernel/entry.S
@@ -122,16 +122,6 @@ ENTRY(csky_systemcall)
psrset ee, ie
- /* Stack frame for syscall, origin call set_esp0 */
- mov r12, sp
-
- bmaski r11, 13
- andn r12, r11
- bgeni r11, 9
- addi r11, 32
- addu r12, r11
- st sp, (r12, 0)
-
lrw r11, __NR_syscalls
cmphs syscallid, r11 /* Check nr of syscall */
bt ret_from_exception
@@ -230,8 +220,6 @@ resume_userspace:
1: RESTORE_ALL
exit_work:
- mov a0, sp /* Stack address is arg[0] */
- jbsr set_esp0 /* Call C level */
btsti r8, TIF_NEED_RESCHED
bt work_resched
/* If thread_info->flag is empty, RESTORE_ALL */
diff --git a/arch/csky/kernel/ptrace.c b/arch/csky/kernel/ptrace.c
index eb62e07..57f1afe 100644
--- a/arch/csky/kernel/ptrace.c
+++ b/arch/csky/kernel/ptrace.c
@@ -50,15 +50,11 @@ static void singlestep_enable(struct task_struct *tsk)
*/
void user_enable_single_step(struct task_struct *child)
{
- if (child->thread.esp0 == 0)
- return;
singlestep_enable(child);
}
void user_disable_single_step(struct task_struct *child)
{
- if (child->thread.esp0 == 0)
- return;
singlestep_disable(child);
}
diff --git a/arch/csky/kernel/signal.c b/arch/csky/kernel/signal.c
index 66e1b72..e680dc1 100644
--- a/arch/csky/kernel/signal.c
+++ b/arch/csky/kernel/signal.c
@@ -238,8 +238,6 @@ static void do_signal(struct pt_regs *regs, int syscall)
if (!user_mode(regs))
return;
- current->thread.esp0 = (unsigned long)regs;
-
/*
* If we were from a system call, check for system call restarting...
*/
diff --git a/arch/csky/kernel/traps.c b/arch/csky/kernel/traps.c
index a8368ed..f487a9b 100644
--- a/arch/csky/kernel/traps.c
+++ b/arch/csky/kernel/traps.c
@@ -106,7 +106,6 @@ void buserr(struct pt_regs *regs)
pr_err("User mode Bus Error\n");
show_regs(regs);
- current->thread.esp0 = (unsigned long) regs;
force_sig_fault(SIGSEGV, 0, (void __user *)regs->pc, current);
}
@@ -162,8 +161,3 @@ asmlinkage void trap_c(struct pt_regs *regs)
}
send_sig(sig, current, 0);
}
-
-asmlinkage void set_esp0(unsigned long ssp)
-{
- current->thread.esp0 = ssp;
-}
diff --git a/arch/csky/mm/fault.c b/arch/csky/mm/fault.c
index 6a94661..d6f4b66 100644
--- a/arch/csky/mm/fault.c
+++ b/arch/csky/mm/fault.c
@@ -172,8 +172,6 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,
bad_area_nosemaphore:
/* User mode accesses just cause a SIGSEGV */
if (user_mode(regs)) {
- tsk->thread.address = address;
- tsk->thread.error_code = write;
force_sig_fault(SIGSEGV, si_code, (void __user *)address, current);
return;
}
@@ -207,6 +205,5 @@ asmlinkage void do_page_fault(struct pt_regs *regs, unsigned long write,
if (!user_mode(regs))
goto no_context;
- tsk->thread.address = address;
force_sig_fault(SIGBUS, BUS_ADRERR, (void __user *)address, current);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 11/14] csky: basic ftrace supported
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
` (7 preceding siblings ...)
2018-12-31 15:33 ` [PATCH 10/14] csky: remove unused members in processor.h guoren
@ 2018-12-31 15:33 ` guoren
2018-12-31 15:33 ` [PATCH 12/14] csky: ftrace call graph supported guoren
2018-12-31 15:33 ` [PATCH 14/14] csky: Add EM_CSKY_OLD 39 guoren
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:33 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
When gcc with -pg, it'll add _mcount stub in every function. We need
implement the _mcount in kernel and ftrace depends on stackstrace.
To do: call-graph, dynamic ftrace
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/Kconfig | 1 +
arch/csky/abiv2/Makefile | 1 +
arch/csky/abiv2/mcount.S | 24 ++++++++++++++++++++++++
arch/csky/include/asm/ftrace.h | 9 +++++++++
arch/csky/kernel/Makefile | 5 +++++
arch/csky/kernel/ftrace.c | 24 ++++++++++++++++++++++++
6 files changed, 64 insertions(+)
create mode 100644 arch/csky/abiv2/mcount.S
create mode 100644 arch/csky/include/asm/ftrace.h
create mode 100644 arch/csky/kernel/ftrace.c
diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
index 65804d1..0b9a290 100644
--- a/arch/csky/Kconfig
+++ b/arch/csky/Kconfig
@@ -29,6 +29,7 @@ config CSKY
select GENERIC_SCHED_CLOCK
select GENERIC_SMP_IDLE_THREAD
select HAVE_ARCH_TRACEHOOK
+ select HAVE_FUNCTION_TRACER
select HAVE_GENERIC_DMA_COHERENT
select HAVE_KERNEL_GZIP
select HAVE_KERNEL_LZO
diff --git a/arch/csky/abiv2/Makefile b/arch/csky/abiv2/Makefile
index 069ca72..b1d44f6 100644
--- a/arch/csky/abiv2/Makefile
+++ b/arch/csky/abiv2/Makefile
@@ -8,3 +8,4 @@ obj-y += strcmp.o
obj-y += strcpy.o
obj-y += strlen.o
obj-y += strksyms.o
+obj-$(CONFIG_FUNCTION_TRACER) += mcount.o
diff --git a/arch/csky/abiv2/mcount.S b/arch/csky/abiv2/mcount.S
new file mode 100644
index 0000000..73377d5
--- /dev/null
+++ b/arch/csky/abiv2/mcount.S
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/linkage.h>
+
+ENTRY (_mcount)
+ subi sp, 20
+ stw a0, (sp, 0)
+ stw a1, (sp, 4)
+ stw a2, (sp, 8)
+ stw a3, (sp, 12)
+ stw lr, (sp, 16)
+ mov a1, lr
+ ldw a0, (sp, 20)
+ jsri csky_mcount
+ ldw a0, (sp, 0)
+ ldw a1, (sp, 4)
+ ldw a2, (sp, 8)
+ ldw a3, (sp, 12)
+ ldw t1, (sp, 16)
+ ldw lr, (sp, 20)
+ addi sp, 24
+ jmp t1
+END (_mcount)
diff --git a/arch/csky/include/asm/ftrace.h b/arch/csky/include/asm/ftrace.h
new file mode 100644
index 0000000..1d22a17
--- /dev/null
+++ b/arch/csky/include/asm/ftrace.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#ifndef __ASM_CSKY_FTRACE_H
+#define __ASM_CSKY_FTRACE_H
+
+extern void _mcount(unsigned long from_pc);
+
+#endif /* __ASM_CSKY_FTRACE_H */
diff --git a/arch/csky/kernel/Makefile b/arch/csky/kernel/Makefile
index ba5ca48..3c0e2d1 100644
--- a/arch/csky/kernel/Makefile
+++ b/arch/csky/kernel/Makefile
@@ -6,4 +6,9 @@ obj-y += process.o cpu-probe.o ptrace.o dumpstack.o
obj-$(CONFIG_MODULES) += module.o
obj-$(CONFIG_SMP) += smp.o
+obj-$(CONFIG_FUNCTION_TRACER) += ftrace.o
obj-$(CONFIG_STACKTRACE) += stacktrace.o
+
+ifdef CONFIG_FUNCTION_TRACER
+CFLAGS_REMOVE_ftrace.o = $(CC_FLAGS_FTRACE)
+endif
diff --git a/arch/csky/kernel/ftrace.c b/arch/csky/kernel/ftrace.c
new file mode 100644
index 0000000..ad054f719
--- /dev/null
+++ b/arch/csky/kernel/ftrace.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
+
+#include <linux/ftrace.h>
+#include <linux/uaccess.h>
+
+extern void (*ftrace_trace_function)(unsigned long, unsigned long,
+ struct ftrace_ops*, struct pt_regs*);
+
+
+noinline void __naked ftrace_stub(unsigned long ip, unsigned long parent_ip,
+ struct ftrace_ops *op, struct pt_regs *regs)
+{
+ asm volatile ("\n");
+}
+
+noinline void csky_mcount(unsigned long from_pc, unsigned long self_pc)
+{
+ if (ftrace_trace_function != ftrace_stub)
+ ftrace_trace_function(self_pc, from_pc, NULL, NULL);
+}
+
+/* _mcount is defined in abi's mcount.S */
+EXPORT_SYMBOL(_mcount);
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 12/14] csky: ftrace call graph supported.
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
` (8 preceding siblings ...)
2018-12-31 15:33 ` [PATCH 11/14] csky: basic ftrace supported guoren
@ 2018-12-31 15:33 ` guoren
2018-12-31 15:33 ` [PATCH 14/14] csky: Add EM_CSKY_OLD 39 guoren
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:33 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
With csky-gcc -pg -mbacktrace, ftrace call graph supported.
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/Kconfig | 1 +
arch/csky/abiv2/mcount.S | 116 ++++++++++++++++++++++++++++++++++++++---
arch/csky/include/asm/ftrace.h | 6 ++-
arch/csky/kernel/ftrace.c | 48 +++++++++++++----
4 files changed, 151 insertions(+), 20 deletions(-)
diff --git a/arch/csky/Kconfig b/arch/csky/Kconfig
index 0b9a290..6e81477 100644
--- a/arch/csky/Kconfig
+++ b/arch/csky/Kconfig
@@ -30,6 +30,7 @@ config CSKY
select GENERIC_SMP_IDLE_THREAD
select HAVE_ARCH_TRACEHOOK
select HAVE_FUNCTION_TRACER
+ select HAVE_FUNCTION_GRAPH_TRACER
select HAVE_GENERIC_DMA_COHERENT
select HAVE_KERNEL_GZIP
select HAVE_KERNEL_LZO
diff --git a/arch/csky/abiv2/mcount.S b/arch/csky/abiv2/mcount.S
index 73377d5..c633379 100644
--- a/arch/csky/abiv2/mcount.S
+++ b/arch/csky/abiv2/mcount.S
@@ -2,23 +2,123 @@
// Copyright (C) 2018 Hangzhou C-SKY Microsystems co.,ltd.
#include <linux/linkage.h>
+#include <asm/ftrace.h>
-ENTRY (_mcount)
- subi sp, 20
+/*
+ * csky-gcc with -pg will put the following asm after prologue:
+ * push r15
+ * jsri _mcount
+ *
+ * stack layout after mcount_enter in _mcount():
+ *
+ * current sp => 0:+-------+
+ * | a0-a3 | -> must save all argument regs
+ * +16:+-------+
+ * | lr | -> _mcount lr (instrumente function's pc)
+ * +20:+-------+
+ * | fp=r8 | -> instrumented function fp
+ * +24:+-------+
+ * | plr | -> instrumented function lr (parent's pc)
+ * +-------+
+ */
+
+.macro mcount_enter
+ subi sp, 24
stw a0, (sp, 0)
stw a1, (sp, 4)
stw a2, (sp, 8)
stw a3, (sp, 12)
stw lr, (sp, 16)
- mov a1, lr
- ldw a0, (sp, 20)
- jsri csky_mcount
+ stw r8, (sp, 20)
+.endm
+
+.macro mcount_exit
ldw a0, (sp, 0)
ldw a1, (sp, 4)
ldw a2, (sp, 8)
ldw a3, (sp, 12)
ldw t1, (sp, 16)
- ldw lr, (sp, 20)
- addi sp, 24
+ ldw r8, (sp, 20)
+ ldw lr, (sp, 24)
+ addi sp, 28
jmp t1
-END (_mcount)
+.endm
+
+.macro save_return_regs
+ subi sp, 16
+ stw a0, (sp, 0)
+ stw a1, (sp, 4)
+ stw a2, (sp, 8)
+ stw a3, (sp, 12)
+.endm
+
+.macro restore_return_regs
+ mov lr, a0
+ ldw a0, (sp, 0)
+ ldw a1, (sp, 4)
+ ldw a2, (sp, 8)
+ ldw a3, (sp, 12)
+ addi sp, 16
+.endm
+
+ENTRY(ftrace_stub)
+ jmp lr
+END(ftrace_stub)
+
+ENTRY(_mcount)
+ mcount_enter
+
+ /* r26 is link register, only used with jsri translation */
+ lrw r26, ftrace_trace_function
+ ldw r26, (r26, 0)
+ lrw a1, ftrace_stub
+ cmpne r26, a1
+ bf skip_ftrace
+
+ mov a0, lr
+ subi a0, MCOUNT_INSN_SIZE
+ ldw a1, (sp, 24)
+
+ jsr r26
+
+#ifndef CONFIG_FUNCTION_GRAPH_TRACER
+skip_ftrace:
+ mcount_exit
+#else
+skip_ftrace:
+ lrw a0, ftrace_graph_return
+ ldw a0, (a0, 0)
+ lrw a1, ftrace_stub
+ cmpne a0, a1
+ bt ftrace_graph_caller
+
+ lrw a0, ftrace_graph_entry
+ ldw a0, (a0, 0)
+ lrw a1, ftrace_graph_entry_stub
+ cmpne a0, a1
+ bt ftrace_graph_caller
+
+ mcount_exit
+#endif
+END(_mcount)
+
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+ENTRY(ftrace_graph_caller)
+ mov a0, sp
+ addi a0, 24
+ ldw a1, (sp, 16)
+ subi a1, MCOUNT_INSN_SIZE
+ mov a2, r8
+ lrw r26, prepare_ftrace_return
+ jsr r26
+ mcount_exit
+END(ftrace_graph_caller)
+
+ENTRY(return_to_handler)
+ save_return_regs
+ mov a0, r8
+ jsri ftrace_return_to_handler
+ restore_return_regs
+ jmp lr
+END(return_to_handler)
+#endif
diff --git a/arch/csky/include/asm/ftrace.h b/arch/csky/include/asm/ftrace.h
index 1d22a17..7547c45 100644
--- a/arch/csky/include/asm/ftrace.h
+++ b/arch/csky/include/asm/ftrace.h
@@ -4,6 +4,10 @@
#ifndef __ASM_CSKY_FTRACE_H
#define __ASM_CSKY_FTRACE_H
-extern void _mcount(unsigned long from_pc);
+#define MCOUNT_INSN_SIZE 4
+
+#define HAVE_FUNCTION_GRAPH_FP_TEST
+
+#define HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
#endif /* __ASM_CSKY_FTRACE_H */
diff --git a/arch/csky/kernel/ftrace.c b/arch/csky/kernel/ftrace.c
index ad054f719..274c431 100644
--- a/arch/csky/kernel/ftrace.c
+++ b/arch/csky/kernel/ftrace.c
@@ -4,21 +4,47 @@
#include <linux/ftrace.h>
#include <linux/uaccess.h>
-extern void (*ftrace_trace_function)(unsigned long, unsigned long,
- struct ftrace_ops*, struct pt_regs*);
+#ifdef CONFIG_FUNCTION_GRAPH_TRACER
+void prepare_ftrace_return(unsigned long *parent, unsigned long self_addr,
+ unsigned long frame_pointer)
+{
+ unsigned long return_hooker = (unsigned long)&return_to_handler;
+ unsigned long old;
+ if (unlikely(atomic_read(¤t->tracing_graph_pause)))
+ return;
-noinline void __naked ftrace_stub(unsigned long ip, unsigned long parent_ip,
- struct ftrace_ops *op, struct pt_regs *regs)
-{
- asm volatile ("\n");
-}
+ old = *parent;
-noinline void csky_mcount(unsigned long from_pc, unsigned long self_pc)
-{
- if (ftrace_trace_function != ftrace_stub)
- ftrace_trace_function(self_pc, from_pc, NULL, NULL);
+ if (!function_graph_enter(old, self_addr,
+ *(unsigned long *)frame_pointer, parent)) {
+ /*
+ * For csky-gcc function has sub-call:
+ * subi sp, sp, 8
+ * stw r8, (sp, 0)
+ * mov r8, sp
+ * st.w r15, (sp, 0x4)
+ * push r15
+ * jl _mcount
+ * We only need set *parent for resume
+ *
+ * For csky-gcc function has no sub-call:
+ * subi sp, sp, 4
+ * stw r8, (sp, 0)
+ * mov r8, sp
+ * push r15
+ * jl _mcount
+ * We need set *parent and *(frame_pointer + 4) for resume,
+ * because lr is resumed twice.
+ */
+ *parent = return_hooker;
+ frame_pointer += 4;
+ if (*(unsigned long *)frame_pointer == old)
+ *(unsigned long *)frame_pointer = return_hooker;
+ }
}
+#endif
/* _mcount is defined in abi's mcount.S */
+extern void _mcount(void);
EXPORT_SYMBOL(_mcount);
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 14/14] csky: Add EM_CSKY_OLD 39
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
` (9 preceding siblings ...)
2018-12-31 15:33 ` [PATCH 12/14] csky: ftrace call graph supported guoren
@ 2018-12-31 15:33 ` guoren
10 siblings, 0 replies; 12+ messages in thread
From: guoren @ 2018-12-31 15:33 UTC (permalink / raw)
To: arnd; +Cc: guoren, linux-kernel, rostedt, mingo, oleg, linux-arch, Guo Ren
From: Guo Ren <ren_guo@c-sky.com>
C-SKY historically used 39, the same value as MCORE, from which the
architecture was derived.
C-SKY binutils support both EM_CSKY and EM_CSKY_OLD, confirmed by
binutils:include/elf/common.h
Signed-off-by: Guo Ren <ren_guo@c-sky.com>
---
arch/csky/include/asm/elf.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/arch/csky/include/asm/elf.h b/arch/csky/include/asm/elf.h
index d6dbc00..e1ec558 100644
--- a/arch/csky/include/asm/elf.h
+++ b/arch/csky/include/asm/elf.h
@@ -8,6 +8,7 @@
#include <abi/regdef.h>
#define ELF_ARCH EM_CSKY
+#define EM_CSKY_OLD 39
/* CSKY Relocations */
#define R_CSKY_NONE 0
@@ -43,7 +44,8 @@ typedef elf_greg_t elf_gregset_t[ELF_NGREG];
/*
* This is used to ensure we don't load something for the wrong architecture.
*/
-#define elf_check_arch(x) ((x)->e_machine == ELF_ARCH)
+#define elf_check_arch(x) (((x)->e_machine == ELF_ARCH) || \
+ ((x)->e_machine == EM_CSKY_OLD))
/*
* These are used to set parameters in the core dumps.
--
2.7.4
^ permalink raw reply related [flat|nested] 12+ messages in thread
end of thread, other threads:[~2018-12-31 15:35 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-31 15:32 [PATCH 01/14] csky: fixup abiv2 mmap(... O_SYNC) failed guoren
2018-12-31 15:32 ` [PATCH 02/14] csky: bugfix gdb coredump error guoren
2018-12-31 15:32 ` [PATCH 03/14] csky: fixup remove vdsp implement for kernel guoren
2018-12-31 15:32 ` [PATCH 04/14] csky: remove syscall_exit_work guoren
2018-12-31 15:32 ` [PATCH 05/14] csky: fixup save hi,lo,dspcr regs in switch_stack guoren
2018-12-31 15:32 ` [PATCH 07/14] csky: CPU-hotplug supported for SMP guoren
2018-12-31 15:32 ` [PATCH 08/14] csky: stacktrace supported guoren
2018-12-31 15:33 ` [PATCH 09/14] csky: optimize kernel panic print guoren
2018-12-31 15:33 ` [PATCH 10/14] csky: remove unused members in processor.h guoren
2018-12-31 15:33 ` [PATCH 11/14] csky: basic ftrace supported guoren
2018-12-31 15:33 ` [PATCH 12/14] csky: ftrace call graph supported guoren
2018-12-31 15:33 ` [PATCH 14/14] csky: Add EM_CSKY_OLD 39 guoren
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).