All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info()
@ 2021-01-12 12:29 Jinyang He
  2021-01-12 12:29 ` [PATCH 1/4] MIPS: process: Reorder header files Jinyang He
                   ` (4 more replies)
  0 siblings, 5 replies; 14+ messages in thread
From: Jinyang He @ 2021-01-12 12:29 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

Not familiar with microMIPS. Not test on microMIPS.

Jinyang He (4):
  MIPS: process: Reorder header files
  MIPS: microMIPS: Fix the judgment of mm_jr16_op and mm_jalr_op
  MIPS: Fix get_frame_info() handing of function size
  MIPS: Add is_jr_ra_ins() to end the loop early

 arch/mips/kernel/process.c | 92 +++++++++++++++++++++++++++++++---------------
 1 file changed, 62 insertions(+), 30 deletions(-)

-- 
2.1.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 1/4] MIPS: process: Reorder header files
  2021-01-12 12:29 [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jinyang He
@ 2021-01-12 12:29 ` Jinyang He
  2021-01-13  0:27   ` Huacai Chen
  2021-01-15 14:46   ` Thomas Bogendoerfer
  2021-01-12 12:29 ` [PATCH 2/4] MIPS: microMIPS: Fix the judgment of mm_jr16_op and mm_jalr_op Jinyang He
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 14+ messages in thread
From: Jinyang He @ 2021-01-12 12:29 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

Just reorder the header files.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/kernel/process.c | 44 ++++++++++++++++++++++----------------------
 1 file changed, 22 insertions(+), 22 deletions(-)

diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index d7e288f..361bd28 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -9,28 +9,29 @@
  * Copyright (C) 2004 Thiemo Seufer
  * Copyright (C) 2013  Imagination Technologies Ltd.
  */
+#include <linux/completion.h>
+#include <linux/cpu.h>
 #include <linux/errno.h>
+#include <linux/export.h>
+#include <linux/init.h>
+#include <linux/kallsyms.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/mman.h>
+#include <linux/nmi.h>
+#include <linux/personality.h>
+#include <linux/ptrace.h>
+#include <linux/prctl.h>
+#include <linux/random.h>
 #include <linux/sched.h>
 #include <linux/sched/debug.h>
 #include <linux/sched/task.h>
 #include <linux/sched/task_stack.h>
-#include <linux/tick.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
 #include <linux/stddef.h>
-#include <linux/unistd.h>
-#include <linux/export.h>
-#include <linux/ptrace.h>
-#include <linux/mman.h>
-#include <linux/personality.h>
 #include <linux/sys.h>
-#include <linux/init.h>
-#include <linux/completion.h>
-#include <linux/kallsyms.h>
-#include <linux/random.h>
-#include <linux/prctl.h>
-#include <linux/nmi.h>
-#include <linux/cpu.h>
+#include <linux/tick.h>
+#include <linux/uaccess.h>
+#include <linux/unistd.h>
 
 #include <asm/abi.h>
 #include <asm/asm.h>
@@ -38,21 +39,20 @@
 #include <asm/cpu.h>
 #include <asm/dsemul.h>
 #include <asm/dsp.h>
+#include <asm/elf.h>
+#include <asm/exec.h>
 #include <asm/fpu.h>
+#include <asm/inst.h>
+#include <asm/io.h>
 #include <asm/irq.h>
+#include <asm/irq_regs.h>
+#include <asm/isadep.h>
 #include <asm/mips-cps.h>
 #include <asm/msa.h>
 #include <asm/mipsregs.h>
 #include <asm/processor.h>
 #include <asm/reg.h>
-#include <linux/uaccess.h>
-#include <asm/io.h>
-#include <asm/elf.h>
-#include <asm/isadep.h>
-#include <asm/inst.h>
 #include <asm/stacktrace.h>
-#include <asm/irq_regs.h>
-#include <asm/exec.h>
 
 #ifdef CONFIG_HOTPLUG_CPU
 void arch_cpu_idle_dead(void)
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 2/4] MIPS: microMIPS: Fix the judgment of mm_jr16_op and mm_jalr_op
  2021-01-12 12:29 [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jinyang He
  2021-01-12 12:29 ` [PATCH 1/4] MIPS: process: Reorder header files Jinyang He
@ 2021-01-12 12:29 ` Jinyang He
  2021-01-12 12:29 ` [PATCH 3/4] MIPS: Fix get_frame_info() handing of function size Jinyang He
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 14+ messages in thread
From: Jinyang He @ 2021-01-12 12:29 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

mm16_r5_format.rt is 5 bits, so directly judge the value if equal or not.
mm_jalr_op requires 7th to 16th bits. These 10 which bits generated by
shifting u_format.uimmediate by 6 may be affected by sign extension.
Thus, take out the 10 bits for comparison.

Without this patch, errors may occur, such as these bits are all ones.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/kernel/process.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 361bd28..94dfdf4 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -311,8 +311,8 @@ static inline int is_jump_ins(union mips_instruction *ip)
 	 * microMIPS is kind of more fun...
 	 */
 	if (mm_insn_16bit(ip->word >> 16)) {
-		if ((ip->mm16_r5_format.opcode == mm_pool16c_op &&
-		    (ip->mm16_r5_format.rt & mm_jr16_op) == mm_jr16_op))
+		if (ip->mm16_r5_format.opcode == mm_pool16c_op &&
+		    ip->mm16_r5_format.rt == mm_jr16_op)
 			return 1;
 		return 0;
 	}
@@ -324,7 +324,7 @@ static inline int is_jump_ins(union mips_instruction *ip)
 	if (ip->r_format.opcode != mm_pool32a_op ||
 			ip->r_format.func != mm_pool32axf_op)
 		return 0;
-	return ((ip->u_format.uimmediate >> 6) & mm_jalr_op) == mm_jalr_op;
+	return ((ip->u_format.uimmediate >> 6) & GENMASK(9,0)) == mm_jalr_op;
 #else
 	if (ip->j_format.opcode == j_op)
 		return 1;
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 3/4] MIPS: Fix get_frame_info() handing of function size
  2021-01-12 12:29 [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jinyang He
  2021-01-12 12:29 ` [PATCH 1/4] MIPS: process: Reorder header files Jinyang He
  2021-01-12 12:29 ` [PATCH 2/4] MIPS: microMIPS: Fix the judgment of mm_jr16_op and mm_jalr_op Jinyang He
@ 2021-01-12 12:29 ` Jinyang He
  2021-01-12 12:29 ` [PATCH 4/4] MIPS: Add is_jr_ra_ins() to end the loop early Jinyang He
  2021-01-18  1:51 ` [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jiaxun Yang
  4 siblings, 0 replies; 14+ messages in thread
From: Jinyang He @ 2021-01-12 12:29 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

[1]: Commit b6c7a324df37b ("MIPS: Fix get_frame_info() handling of
                            microMIPS function size")
[2]: Commit 2b424cfc69728 ("MIPS: Remove function size check in
                            get_frame_info()")

First patch added a constant to check the number of iterations against.
Second patch fixed the situation that info->func_size is zero.

However, func_size member became useless after the second commit. Without
ip_end, the get frame_size operation may be out of range although KALLSYMS
enabled. Thus, check func_size first. Then make ip_end be the sum of ip
and a constant (512) if func_size is equal to 0. Otherwise make ip_end be
the sum of ip and func_size.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/kernel/process.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index 94dfdf4..bef8f8d 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -390,10 +390,8 @@ static inline int is_sp_move_ins(union mips_instruction *ip, int *frame_size)
 static int get_frame_info(struct mips_frame_info *info)
 {
 	bool is_mmips = IS_ENABLED(CONFIG_CPU_MICROMIPS);
-	union mips_instruction insn, *ip;
-	const unsigned int max_insns = 128;
+	union mips_instruction insn, *ip, *ip_end;
 	unsigned int last_insn_size = 0;
-	unsigned int i;
 	bool saw_jump = false;
 
 	info->pc_offset = -1;
@@ -403,7 +401,9 @@ static int get_frame_info(struct mips_frame_info *info)
 	if (!ip)
 		goto err;
 
-	for (i = 0; i < max_insns; i++) {
+	ip_end = (void *)ip + (info->func_size ? info->func_size : 512);
+
+	while(ip < ip_end) {
 		ip = (void *)ip + last_insn_size;
 
 		if (is_mmips && mm_insn_16bit(ip->halfword[0])) {
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* [PATCH 4/4] MIPS: Add is_jr_ra_ins() to end the loop early
  2021-01-12 12:29 [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jinyang He
                   ` (2 preceding siblings ...)
  2021-01-12 12:29 ` [PATCH 3/4] MIPS: Fix get_frame_info() handing of function size Jinyang He
@ 2021-01-12 12:29 ` Jinyang He
  2021-10-23 18:32   ` Maciej W. Rozycki
  2021-01-18  1:51 ` [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jiaxun Yang
  4 siblings, 1 reply; 14+ messages in thread
From: Jinyang He @ 2021-01-12 12:29 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

For those leaf functions, they are likely to have no stack operations.
Add is_jr_ra_ins() to determine whether jr ra has been touched before
the frame_size is found. Without this patch, the get frame_size operation
may be out of range and get the frame_size from the next nested function.

Signed-off-by: Jinyang He <hejinyang@loongson.cn>
---
 arch/mips/kernel/process.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
index bef8f8d..9e6f194 100644
--- a/arch/mips/kernel/process.c
+++ b/arch/mips/kernel/process.c
@@ -205,6 +205,36 @@ struct mips_frame_info {
 #define J_TARGET(pc,target)	\
 		(((unsigned long)(pc) & 0xf0000000) | ((target) << 2))
 
+static inline int is_jr_ra_ins(union mips_instruction *ip)
+{
+#ifdef CONFIG_CPU_MICROMIPS
+	/*
+	 * jr16 ra
+	 * jr ra
+	 */
+	if (mm_insn_16bit(ip->word >> 16)) {
+		if (ip->mm16_r5_format.opcode == mm_pool16c_op &&
+		    ip->mm16_r5_format.rt == mm_jr16_op &&
+		    ip->mm16_r5_format.imm == 31)
+			return 1;
+		return 0;
+	}
+
+	if (ip->r_format.opcode == mm_pool32a_op &&
+	    ip->r_format.func == mm_pool32axf_op &&
+	    ((ip->u_format.uimmediate >> 6) & GENMASK(9,0)) == mm_jalr_op &&
+            ip->r_format.rs == 31)
+		return 1;
+	return 0;
+#else
+	if (ip->r_format.opcode == spec_op &&
+	    ip->r_format.func == jr_op &&
+	    ip->r_format.rs == 31)
+		return 1;
+	return 0;
+#endif
+}
+
 static inline int is_ra_save_ins(union mips_instruction *ip, int *poff)
 {
 #ifdef CONFIG_CPU_MICROMIPS
@@ -417,7 +447,9 @@ static int get_frame_info(struct mips_frame_info *info)
 			last_insn_size = 4;
 		}
 
-		if (!info->frame_size) {
+		if (is_jr_ra_ins(ip)) {
+			break;
+		} else if (!info->frame_size) {
 			is_sp_move_ins(&insn, &info->frame_size);
 			continue;
 		} else if (!saw_jump && is_jump_ins(ip)) {
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] MIPS: process: Reorder header files
  2021-01-12 12:29 ` [PATCH 1/4] MIPS: process: Reorder header files Jinyang He
@ 2021-01-13  0:27   ` Huacai Chen
  2021-01-15 14:46   ` Thomas Bogendoerfer
  1 sibling, 0 replies; 14+ messages in thread
From: Huacai Chen @ 2021-01-13  0:27 UTC (permalink / raw)
  To: Jinyang He
  Cc: Thomas Bogendoerfer, open list:MIPS, LKML, Paul Burton, Jun-Ru Chang

Reviewed-by: Huacai Chen <chenhuacai@kernel.org>

On Tue, Jan 12, 2021 at 9:07 PM Jinyang He <hejinyang@loongson.cn> wrote:
>
> Just reorder the header files.
>
> Signed-off-by: Jinyang He <hejinyang@loongson.cn>
> ---
>  arch/mips/kernel/process.c | 44 ++++++++++++++++++++++----------------------
>  1 file changed, 22 insertions(+), 22 deletions(-)
>
> diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
> index d7e288f..361bd28 100644
> --- a/arch/mips/kernel/process.c
> +++ b/arch/mips/kernel/process.c
> @@ -9,28 +9,29 @@
>   * Copyright (C) 2004 Thiemo Seufer
>   * Copyright (C) 2013  Imagination Technologies Ltd.
>   */
> +#include <linux/completion.h>
> +#include <linux/cpu.h>
>  #include <linux/errno.h>
> +#include <linux/export.h>
> +#include <linux/init.h>
> +#include <linux/kallsyms.h>
> +#include <linux/kernel.h>
> +#include <linux/mm.h>
> +#include <linux/mman.h>
> +#include <linux/nmi.h>
> +#include <linux/personality.h>
> +#include <linux/ptrace.h>
> +#include <linux/prctl.h>
> +#include <linux/random.h>
>  #include <linux/sched.h>
>  #include <linux/sched/debug.h>
>  #include <linux/sched/task.h>
>  #include <linux/sched/task_stack.h>
> -#include <linux/tick.h>
> -#include <linux/kernel.h>
> -#include <linux/mm.h>
>  #include <linux/stddef.h>
> -#include <linux/unistd.h>
> -#include <linux/export.h>
> -#include <linux/ptrace.h>
> -#include <linux/mman.h>
> -#include <linux/personality.h>
>  #include <linux/sys.h>
> -#include <linux/init.h>
> -#include <linux/completion.h>
> -#include <linux/kallsyms.h>
> -#include <linux/random.h>
> -#include <linux/prctl.h>
> -#include <linux/nmi.h>
> -#include <linux/cpu.h>
> +#include <linux/tick.h>
> +#include <linux/uaccess.h>
> +#include <linux/unistd.h>
>
>  #include <asm/abi.h>
>  #include <asm/asm.h>
> @@ -38,21 +39,20 @@
>  #include <asm/cpu.h>
>  #include <asm/dsemul.h>
>  #include <asm/dsp.h>
> +#include <asm/elf.h>
> +#include <asm/exec.h>
>  #include <asm/fpu.h>
> +#include <asm/inst.h>
> +#include <asm/io.h>
>  #include <asm/irq.h>
> +#include <asm/irq_regs.h>
> +#include <asm/isadep.h>
>  #include <asm/mips-cps.h>
>  #include <asm/msa.h>
>  #include <asm/mipsregs.h>
>  #include <asm/processor.h>
>  #include <asm/reg.h>
> -#include <linux/uaccess.h>
> -#include <asm/io.h>
> -#include <asm/elf.h>
> -#include <asm/isadep.h>
> -#include <asm/inst.h>
>  #include <asm/stacktrace.h>
> -#include <asm/irq_regs.h>
> -#include <asm/exec.h>
>
>  #ifdef CONFIG_HOTPLUG_CPU
>  void arch_cpu_idle_dead(void)
> --
> 2.1.0
>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] MIPS: process: Reorder header files
  2021-01-12 12:29 ` [PATCH 1/4] MIPS: process: Reorder header files Jinyang He
  2021-01-13  0:27   ` Huacai Chen
@ 2021-01-15 14:46   ` Thomas Bogendoerfer
  2021-01-18 10:02     ` Jinyang He
  1 sibling, 1 reply; 14+ messages in thread
From: Thomas Bogendoerfer @ 2021-01-15 14:46 UTC (permalink / raw)
  To: Jinyang He; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

On Tue, Jan 12, 2021 at 08:29:14PM +0800, Jinyang He wrote:
> Just reorder the header files.

This alone isn't worth a commit, IMHO. I bet there are lots of includes
no longer needed, so removing and sorting them is ok for me.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info()
  2021-01-12 12:29 [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jinyang He
                   ` (3 preceding siblings ...)
  2021-01-12 12:29 ` [PATCH 4/4] MIPS: Add is_jr_ra_ins() to end the loop early Jinyang He
@ 2021-01-18  1:51 ` Jiaxun Yang
  2021-01-19  1:29   ` Jinyang He
  4 siblings, 1 reply; 14+ messages in thread
From: Jiaxun Yang @ 2021-01-18  1:51 UTC (permalink / raw)
  To: Jinyang He, Thomas Bogendoerfer
  Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

在 2021/1/12 下午8:29, Jinyang He 写道:
> Not familiar with microMIPS. Not test on microMIPS.

Hi Jinyang,

I was messing around QEMU microMIPS and found kernel stuck
at loading init process after applied your patches :-(

Thanks.

- Jiaxun

>
> Jinyang He (4):
>    MIPS: process: Reorder header files
>    MIPS: microMIPS: Fix the judgment of mm_jr16_op and mm_jalr_op
>    MIPS: Fix get_frame_info() handing of function size
>    MIPS: Add is_jr_ra_ins() to end the loop early
>
>   arch/mips/kernel/process.c | 92 +++++++++++++++++++++++++++++++---------------
>   1 file changed, 62 insertions(+), 30 deletions(-)
>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] MIPS: process: Reorder header files
  2021-01-15 14:46   ` Thomas Bogendoerfer
@ 2021-01-18 10:02     ` Jinyang He
  2021-01-18 11:27       ` Jinyang He
  2021-01-18 22:11       ` Thomas Bogendoerfer
  0 siblings, 2 replies; 14+ messages in thread
From: Jinyang He @ 2021-01-18 10:02 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

On 01/15/2021 10:46 PM, Thomas Bogendoerfer wrote:

> On Tue, Jan 12, 2021 at 08:29:14PM +0800, Jinyang He wrote:
>> Just reorder the header files.
> This alone isn't worth a commit, IMHO. I bet there are lots of includes
> no longer needed, so removing and sorting them is ok for me.
>
> Thomas.
>

Hi, Thomas,

Thanks for your advice. I analyzed majority of the symbols in this file.
The following are examples of header file references:

Space indicates that it cannot be found. (Maybe I missed it.)

     Header files                                Examples in this file
     #include <linux/completion.h>
*   #include <linux/cpu.h> get_online_cpus
*   #include <linux/errno.h>                    EOPNOTSUPP
     #include <linux/export.h>
*   #include <linux/init.h> arch_initcall
*   #include <linux/kallsyms.h> kallsyms_lookup_name
*   #include <linux/kernel.h> __kernel_text_address
     #include <linux/mm.h>
     #include <linux/mman.h>
*   #include <linux/nmi.h> nmi_cpu_backtrace
*   #include <linux/personality.h> ADDR_NO_RANDOMIZE
     #include <linux/ptrace.h>
*   #include <linux/prctl.h>                    PR_FP_MODE_FR
     #include <linux/random.h>
*   #include <linux/sched.h>                    PF_KTHREAD
*   #include <linux/sched/debug.h> in_sched_functions
     #include <linux/sched/task.h>
*   #include <linux/sched/task_stack.h> task_stack_page
     #include <linux/stddef.h>
     #include <linux/sys.h>
     #include <linux/tick.h>
     #include <linux/uaccess.h>
     #include <linux/unistd.h>

*   #include <asm/abi.h> current->thread.abi->vdso->size
*   #include <asm/asm.h>                        ALMASK
     #include <asm/bootinfo.h>
     #include <asm/cpu.h>
*   #include <asm/dsemul.h> dsemul_thread_cleanup
*   #include <asm/dsp.h>                        init_dsp
     #include <asm/elf.h>
     #include <asm/exec.h>
*   #include <asm/fpu.h>                        lose_fpu
*   #include <asm/inst.h> mips_instruction
     #include <asm/io.h>
*   #include <asm/irq.h>                        on_irq_stack
*   #include <asm/irq_regs.h>                    get_irq_regs
*   #include <asm/isadep.h>                        KU_USER
     #include <asm/mips-cps.h>
*   #include <asm/msa.h>                        is_msa_enabled
*   #include <asm/mipsregs.h>                    ST0_CU0
*   #include <asm/processor.h> VDSO_RANDOMIZE_SIZE
*   #include <asm/reg.h>                        MIPS32_EF_R1
     #include <asm/stacktrace.h>


Here about this file config is:

Enable:
CONFIG_HOTPLUG_CPU, CONFIG_MIPS_FP_SUPPORT, CONFIG_STACKPROTECTOR,
CONFIG_CPU_LOONGSON64, CONFIG_KALLSYMS, CONFIG_64BIT

Disable:
CONFIG_CPU_R3000, CONFIG_CPU_TX39XX, CONFIG_MIPS_MT_FPAFF, 
CONFIG_CPU_MICROMIPS
CONFIG_MIPS_O32_FP64_SUPPORT, CONFIG_32BIT, CONFIG_MIPS32_O32

By including only these header files which marked by '*', I have been able
to compile and use certain functions (unwind_stack) normally. So are other
header files no longer needed?

In addition, <linux/cpu.h> includes <linux/cpumask.h>, and <linux/cpumask.h>
includes <linux/kernel.h>. What should we do?

Thanks,
Jinyang


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] MIPS: process: Reorder header files
  2021-01-18 10:02     ` Jinyang He
@ 2021-01-18 11:27       ` Jinyang He
  2021-01-18 22:11       ` Thomas Bogendoerfer
  1 sibling, 0 replies; 14+ messages in thread
From: Jinyang He @ 2021-01-18 11:27 UTC (permalink / raw)
  To: Thomas Bogendoerfer; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

Ping?

On 01/18/2021 06:02 PM, Jinyang He wrote:
> On 01/15/2021 10:46 PM, Thomas Bogendoerfer wrote:
>
>> On Tue, Jan 12, 2021 at 08:29:14PM +0800, Jinyang He wrote:
>>> Just reorder the header files.
>> This alone isn't worth a commit, IMHO. I bet there are lots of includes
>> no longer needed, so removing and sorting them is ok for me.
>>
>> Thomas.
>>
>
> Hi, Thomas,
>
> Thanks for your advice. I analyzed majority of the symbols in this file.
> The following are examples of header file references:
>
> Space indicates that it cannot be found. (Maybe I missed it.)
>
>     Header files                                          Examples in 
> this file
>     #include <linux/completion.h>
> *   #include <linux/cpu.h> get_online_cpus
> *   #include <linux/errno.h>                    EOPNOTSUPP
>     #include <linux/export.h>
> *   #include <linux/init.h> arch_initcall
> *   #include <linux/kallsyms.h> kallsyms_lookup_name
> *   #include <linux/kernel.h> __kernel_text_address
>     #include <linux/mm.h>
>     #include <linux/mman.h>
> *   #include <linux/nmi.h> nmi_cpu_backtrace
> *   #include <linux/personality.h> ADDR_NO_RANDOMIZE
>     #include <linux/ptrace.h>
> *   #include <linux/prctl.h> PR_FP_MODE_FR
>     #include <linux/random.h>
> *   #include <linux/sched.h>                    PF_KTHREAD
> *   #include <linux/sched/debug.h>       in_sched_functions
>     #include <linux/sched/task.h>
> *   #include <linux/sched/task_stack.h> task_stack_page
>     #include <linux/stddef.h>
>     #include <linux/sys.h>
>     #include <linux/tick.h>
>     #include <linux/uaccess.h>
>     #include <linux/unistd.h>
>
> *   #include <asm/abi.h> current->thread.abi->vdso->size
> *   #include <asm/asm.h>                        ALMASK
>     #include <asm/bootinfo.h>
>     #include <asm/cpu.h>
> *   #include <asm/dsemul.h> dsemul_thread_cleanup
> *   #include <asm/dsp.h>                        init_dsp
>     #include <asm/elf.h>
>     #include <asm/exec.h>
> *   #include <asm/fpu.h>                        lose_fpu
> *   #include <asm/inst.h> mips_instruction
>     #include <asm/io.h>
> *   #include <asm/irq.h>                        on_irq_stack
> *   #include <asm/irq_regs.h> get_irq_regs
> *   #include <asm/isadep.h>                        KU_USER
>     #include <asm/mips-cps.h>
> *   #include <asm/msa.h> is_msa_enabled
> *   #include <asm/mipsregs.h>                    ST0_CU0
> *   #include <asm/processor.h> VDSO_RANDOMIZE_SIZE
> *   #include <asm/reg.h>                        MIPS32_EF_R1
>     #include <asm/stacktrace.h>
>
>
> Here about this file config is:
>
> Enable:
> CONFIG_HOTPLUG_CPU, CONFIG_MIPS_FP_SUPPORT, CONFIG_STACKPROTECTOR,
> CONFIG_CPU_LOONGSON64, CONFIG_KALLSYMS, CONFIG_64BIT
>
> Disable:
> CONFIG_CPU_R3000, CONFIG_CPU_TX39XX, CONFIG_MIPS_MT_FPAFF, 
> CONFIG_CPU_MICROMIPS
> CONFIG_MIPS_O32_FP64_SUPPORT, CONFIG_32BIT, CONFIG_MIPS32_O32
>
> By including only these header files which marked by '*', I have been 
> able
> to compile and use certain functions (unwind_stack) normally. So are 
> other
> header files no longer needed?
>
> In addition, <linux/cpu.h> includes <linux/cpumask.h>, and 
> <linux/cpumask.h>
> includes <linux/kernel.h>. What should we do?
>
> Thanks,
> Jinyang


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 1/4] MIPS: process: Reorder header files
  2021-01-18 10:02     ` Jinyang He
  2021-01-18 11:27       ` Jinyang He
@ 2021-01-18 22:11       ` Thomas Bogendoerfer
  1 sibling, 0 replies; 14+ messages in thread
From: Thomas Bogendoerfer @ 2021-01-18 22:11 UTC (permalink / raw)
  To: Jinyang He; +Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

On Mon, Jan 18, 2021 at 06:02:08PM +0800, Jinyang He wrote:
> On 01/15/2021 10:46 PM, Thomas Bogendoerfer wrote:
> 
> > On Tue, Jan 12, 2021 at 08:29:14PM +0800, Jinyang He wrote:
> > > Just reorder the header files.
> > This alone isn't worth a commit, IMHO. I bet there are lots of includes
> > no longer needed, so removing and sorting them is ok for me.
> > 
> > Thomas.
> > 
> 
> Hi, Thomas,
> 
> Thanks for your advice. I analyzed majority of the symbols in this file.
> The following are examples of header file references:
> 
> Space indicates that it cannot be found. (Maybe I missed it.)
> 
>     Header files                                Examples in this file
>     #include <linux/completion.h>
> *   #include <linux/cpu.h> get_online_cpus
> *   #include <linux/errno.h>                    EOPNOTSUPP
> [..]

thank you for doing this.

> By including only these header files which marked by '*', I have been able
> to compile and use certain functions (unwind_stack) normally. So are other
> header files no longer needed?
> 
> In addition, <linux/cpu.h> includes <linux/cpumask.h>, and <linux/cpumask.h>
> includes <linux/kernel.h>. What should we do?

send a patch, which deletes the not needed #includes ;-)

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info()
  2021-01-18  1:51 ` [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jiaxun Yang
@ 2021-01-19  1:29   ` Jinyang He
  0 siblings, 0 replies; 14+ messages in thread
From: Jinyang He @ 2021-01-19  1:29 UTC (permalink / raw)
  To: Jiaxun Yang, Thomas Bogendoerfer
  Cc: linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

On 01/18/2021 09:51 AM, Jiaxun Yang wrote:

> 在 2021/1/12 下午8:29, Jinyang He 写道:
>> Not familiar with microMIPS. Not test on microMIPS.
>
> Hi Jinyang,
>
> I was messing around QEMU microMIPS and found kernel stuck
> at loading init process after applied your patches :-(
>
> Thanks.
>
> - Jiaxun
>

Hi, Jiaxun,

Thanks you for test.
I think the last patch went wrong.

+    if (ip->r_format.opcode == mm_pool32a_op &&
+        ip->r_format.func == mm_pool32axf_op &&
+        ((ip->u_format.uimmediate >> 6) & GENMASK(9,0)) == mm_jalr_op &&
+            ip->r_format.rs == 31)

There is no POOL32A format in uapi/asm/inst.h, so some bits here use the
format of r_format instead.

---------------------------------------------------------------------
|    format      |  31:26  | 25:21 | 20:16 |    15:6    |    5:0 |
-----------------+---------+-------+-------+------------+------------
| pool32a_format | pool32a |  rt   |  rs   |   jalrc    | pool32axf |
-----------------+---------+-------+-------+------------+------------
|    r_format    |  opcode |  rs   |  rt   | rd:5, re:5 |    func |
---------------------------------------------------------------------

I mistakenly thought that r_format.rs and pool32a_format.rs are the same.

+        return 1;
+    return 0;

Could you help me test it again?

Thanks,
Jinyang

>>
>> Jinyang He (4):
>>    MIPS: process: Reorder header files
>>    MIPS: microMIPS: Fix the judgment of mm_jr16_op and mm_jalr_op
>>    MIPS: Fix get_frame_info() handing of function size
>>    MIPS: Add is_jr_ra_ins() to end the loop early
>>
>>   arch/mips/kernel/process.c | 92 
>> +++++++++++++++++++++++++++++++---------------
>>   1 file changed, 62 insertions(+), 30 deletions(-)
>>


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/4] MIPS: Add is_jr_ra_ins() to end the loop early
  2021-01-12 12:29 ` [PATCH 4/4] MIPS: Add is_jr_ra_ins() to end the loop early Jinyang He
@ 2021-10-23 18:32   ` Maciej W. Rozycki
  2021-10-25  2:11     ` Jinyang He
  0 siblings, 1 reply; 14+ messages in thread
From: Maciej W. Rozycki @ 2021-10-23 18:32 UTC (permalink / raw)
  To: Jinyang He
  Cc: Thomas Bogendoerfer, linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

On Tue, 12 Jan 2021, Jinyang He wrote:

> For those leaf functions, they are likely to have no stack operations.
> Add is_jr_ra_ins() to determine whether jr ra has been touched before
> the frame_size is found. Without this patch, the get frame_size operation
> may be out of range and get the frame_size from the next nested function.
> 
> Signed-off-by: Jinyang He <hejinyang@loongson.cn>
> ---
>  arch/mips/kernel/process.c | 34 +++++++++++++++++++++++++++++++++-
>  1 file changed, 33 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
> index bef8f8d..9e6f194 100644
> --- a/arch/mips/kernel/process.c
> +++ b/arch/mips/kernel/process.c
> @@ -205,6 +205,36 @@ struct mips_frame_info {
>  #define J_TARGET(pc,target)	\
>  		(((unsigned long)(pc) & 0xf0000000) | ((target) << 2))
>  
> +static inline int is_jr_ra_ins(union mips_instruction *ip)
> +{
> +#ifdef CONFIG_CPU_MICROMIPS
> +	/*
> +	 * jr16 ra
> +	 * jr ra
> +	 */
> +	if (mm_insn_16bit(ip->word >> 16)) {
> +		if (ip->mm16_r5_format.opcode == mm_pool16c_op &&
> +		    ip->mm16_r5_format.rt == mm_jr16_op &&
> +		    ip->mm16_r5_format.imm == 31)
> +			return 1;
> +		return 0;
> +	}
> +
> +	if (ip->r_format.opcode == mm_pool32a_op &&
> +	    ip->r_format.func == mm_pool32axf_op &&
> +	    ((ip->u_format.uimmediate >> 6) & GENMASK(9,0)) == mm_jalr_op &&
> +            ip->r_format.rs == 31)
> +		return 1;
> +	return 0;
> +#else

 Without looking into it much, this is likely missing the point, because 
while technically inteed JR and JR16 can be used with $ra in microMIPS 
machine code (there's JRS too), in reality either JRC or JRADDIUSP will.

 [Wading through e-mail recovered from mid-Jan linux-mips.org crash.]

  Maciej

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 4/4] MIPS: Add is_jr_ra_ins() to end the loop early
  2021-10-23 18:32   ` Maciej W. Rozycki
@ 2021-10-25  2:11     ` Jinyang He
  0 siblings, 0 replies; 14+ messages in thread
From: Jinyang He @ 2021-10-25  2:11 UTC (permalink / raw)
  To: Maciej W. Rozycki
  Cc: Thomas Bogendoerfer, linux-mips, linux-kernel, Paul Burton, Jun-Ru Chang

On 10/24/2021 02:32 AM, Maciej W. Rozycki wrote:

> On Tue, 12 Jan 2021, Jinyang He wrote:
>
>> For those leaf functions, they are likely to have no stack operations.
>> Add is_jr_ra_ins() to determine whether jr ra has been touched before
>> the frame_size is found. Without this patch, the get frame_size operation
>> may be out of range and get the frame_size from the next nested function.
>>
>> Signed-off-by: Jinyang He <hejinyang@loongson.cn>
>> ---
>>   arch/mips/kernel/process.c | 34 +++++++++++++++++++++++++++++++++-
>>   1 file changed, 33 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
>> index bef8f8d..9e6f194 100644
>> --- a/arch/mips/kernel/process.c
>> +++ b/arch/mips/kernel/process.c
>> @@ -205,6 +205,36 @@ struct mips_frame_info {
>>   #define J_TARGET(pc,target)	\
>>   		(((unsigned long)(pc) & 0xf0000000) | ((target) << 2))
>>   
>> +static inline int is_jr_ra_ins(union mips_instruction *ip)
>> +{
>> +#ifdef CONFIG_CPU_MICROMIPS
>> +	/*
>> +	 * jr16 ra
>> +	 * jr ra
>> +	 */
>> +	if (mm_insn_16bit(ip->word >> 16)) {
>> +		if (ip->mm16_r5_format.opcode == mm_pool16c_op &&
>> +		    ip->mm16_r5_format.rt == mm_jr16_op &&
>> +		    ip->mm16_r5_format.imm == 31)
>> +			return 1;
>> +		return 0;
>> +	}
>> +
>> +	if (ip->r_format.opcode == mm_pool32a_op &&
>> +	    ip->r_format.func == mm_pool32axf_op &&
>> +	    ((ip->u_format.uimmediate >> 6) & GENMASK(9,0)) == mm_jalr_op &&
>> +            ip->r_format.rs == 31)
>> +		return 1;
>> +	return 0;
>> +#else
>   Without looking into it much, this is likely missing the point, because
> while technically inteed JR and JR16 can be used with $ra in microMIPS
> machine code (there's JRS too), in reality either JRC or JRADDIUSP will.
>
>   [Wading through e-mail recovered from mid-Jan linux-mips.org crash.]
>
>    Maciej

You are right, I missed the point. I have refered to microMIPS64
Instruction Set. JRC and JRADDIUSP also can be used with $ra in
microMIPS. I am not sure what compiler do at epilogue. But when
we call $ra without saving $ra, it means return, I think.
I will fix it later.

Thanks,
Jinyang.


^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2021-10-25  2:11 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-12 12:29 [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jinyang He
2021-01-12 12:29 ` [PATCH 1/4] MIPS: process: Reorder header files Jinyang He
2021-01-13  0:27   ` Huacai Chen
2021-01-15 14:46   ` Thomas Bogendoerfer
2021-01-18 10:02     ` Jinyang He
2021-01-18 11:27       ` Jinyang He
2021-01-18 22:11       ` Thomas Bogendoerfer
2021-01-12 12:29 ` [PATCH 2/4] MIPS: microMIPS: Fix the judgment of mm_jr16_op and mm_jalr_op Jinyang He
2021-01-12 12:29 ` [PATCH 3/4] MIPS: Fix get_frame_info() handing of function size Jinyang He
2021-01-12 12:29 ` [PATCH 4/4] MIPS: Add is_jr_ra_ins() to end the loop early Jinyang He
2021-10-23 18:32   ` Maciej W. Rozycki
2021-10-25  2:11     ` Jinyang He
2021-01-18  1:51 ` [PATCH 0/4] MIPS: process: Some fixes and improvements about get_frame_info() Jiaxun Yang
2021-01-19  1:29   ` Jinyang He

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.