generic: mt7530: fix null pointer dereferencing in port5 setup
[oweals/openwrt.git] / target / linux / generic / backport-5.4 / 300-MIPS-Exclude-more-dsemul-code-when-CONFIG_MIPS_FP_SU.patch
1 From d96c3157f9ca177727fbad960fcf6f52f145f471 Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Thu, 9 Jan 2020 11:33:19 +0800
4 Subject: [PATCH] MIPS: Exclude more dsemul code when CONFIG_MIPS_FP_SUPPORT=n
5
6 This furthers what commit 42b10815d559 ("MIPS: Don't compile math-emu
7 when CONFIG_MIPS_FP_SUPPORT=n") has done
8
9 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
10 ---
11  arch/mips/include/asm/processor.h | 12 ++++++------
12  arch/mips/kernel/process.c        | 10 ++++++++--
13  arch/mips/kernel/vdso.c           | 26 +++++++++++++++-----------
14  3 files changed, 29 insertions(+), 19 deletions(-)
15
16 diff --git a/arch/mips/include/asm/processor.h b/arch/mips/include/asm/processor.h
17 index 7619ad319400..813ba94d87bb 100644
18 --- a/arch/mips/include/asm/processor.h
19 +++ b/arch/mips/include/asm/processor.h
20 @@ -253,13 +253,13 @@ struct thread_struct {
21  #ifdef CONFIG_MIPS_FP_SUPPORT
22         /* Saved fpu/fpu emulator stuff. */
23         struct mips_fpu_struct fpu FPU_ALIGN;
24 -#endif
25         /* Assigned branch delay slot 'emulation' frame */
26         atomic_t bd_emu_frame;
27         /* PC of the branch from a branch delay slot 'emulation' */
28         unsigned long bd_emu_branch_pc;
29         /* PC to continue from following a branch delay slot 'emulation' */
30         unsigned long bd_emu_cont_pc;
31 +#endif
32  #ifdef CONFIG_MIPS_MT_FPAFF
33         /* Emulated instruction count */
34         unsigned long emulated_fp;
35 @@ -302,7 +302,11 @@ struct thread_struct {
36                 .fpr            = {{{0,},},},                   \
37                 .fcr31          = 0,                            \
38                 .msacsr         = 0,                            \
39 -       },
40 +       },                                                      \
41 +       /* Delay slot emulation */                              \
42 +       .bd_emu_frame = ATOMIC_INIT(BD_EMUFRAME_NONE),          \
43 +       .bd_emu_branch_pc = 0,                                  \
44 +       .bd_emu_cont_pc = 0,
45  #else
46  # define FPU_INIT
47  #endif
48 @@ -334,10 +338,6 @@ struct thread_struct {
49          * FPU affinity state (null if not FPAFF)               \
50          */                                                     \
51         FPAFF_INIT                                              \
52 -       /* Delay slot emulation */                              \
53 -       .bd_emu_frame = ATOMIC_INIT(BD_EMUFRAME_NONE),          \
54 -       .bd_emu_branch_pc = 0,                                  \
55 -       .bd_emu_cont_pc = 0,                                    \
56         /*                                                      \
57          * Saved DSP stuff                                      \
58          */                                                     \
59 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
60 index 339870ed92f7..b2a797557825 100644
61 --- a/arch/mips/kernel/process.c
62 +++ b/arch/mips/kernel/process.c
63 @@ -75,7 +75,9 @@ void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp)
64         lose_fpu(0);
65         clear_thread_flag(TIF_MSA_CTX_LIVE);
66         clear_used_math();
67 +#ifdef CONFIG_MIPS_FP_SUPPORT
68         atomic_set(&current->thread.bd_emu_frame, BD_EMUFRAME_NONE);
69 +#endif
70         init_dsp();
71         regs->cp0_epc = pc;
72         regs->regs[29] = sp;
73 @@ -176,7 +178,9 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
74         clear_tsk_thread_flag(p, TIF_FPUBOUND);
75  #endif /* CONFIG_MIPS_MT_FPAFF */
76  
77 +#ifdef CONFIG_MIPS_FP_SUPPORT
78         atomic_set(&p->thread.bd_emu_frame, BD_EMUFRAME_NONE);
79 +#endif
80  
81         if (clone_flags & CLONE_SETTLS)
82                 ti->tp_value = tls;
83 @@ -650,8 +654,10 @@ unsigned long mips_stack_top(void)
84  {
85         unsigned long top = TASK_SIZE & PAGE_MASK;
86  
87 -       /* One page for branch delay slot "emulation" */
88 -       top -= PAGE_SIZE;
89 +       if (IS_ENABLED(CONFIG_MIPS_FP_SUPPORT)) {
90 +               /* One page for branch delay slot "emulation" */
91 +               top -= PAGE_SIZE;
92 +       }
93  
94         /* Space for the VDSO, data page & GIC user page */
95         top -= PAGE_ALIGN(current->thread.abi->vdso->size);
96 diff --git a/arch/mips/kernel/vdso.c b/arch/mips/kernel/vdso.c
97 index bc35f8499111..3adb7354bc01 100644
98 --- a/arch/mips/kernel/vdso.c
99 +++ b/arch/mips/kernel/vdso.c
100 @@ -71,10 +71,12 @@ subsys_initcall(init_vdso);
101  
102  static unsigned long vdso_base(void)
103  {
104 -       unsigned long base;
105 +       unsigned long base = STACK_TOP;
106  
107 -       /* Skip the delay slot emulation page */
108 -       base = STACK_TOP + PAGE_SIZE;
109 +       if (IS_ENABLED(CONFIG_MIPS_FP_SUPPORT)) {
110 +               /* Skip the delay slot emulation page */
111 +               base += PAGE_SIZE;
112 +       }
113  
114         if (current->flags & PF_RANDOMIZE) {
115                 base += get_random_int() & (VDSO_RANDOMIZE_SIZE - 1);
116 @@ -95,14 +97,16 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
117         if (down_write_killable(&mm->mmap_sem))
118                 return -EINTR;
119  
120 -       /* Map delay slot emulation page */
121 -       base = mmap_region(NULL, STACK_TOP, PAGE_SIZE,
122 -                          VM_READ | VM_EXEC |
123 -                          VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
124 -                          0, NULL);
125 -       if (IS_ERR_VALUE(base)) {
126 -               ret = base;
127 -               goto out;
128 +       if (IS_ENABLED(CONFIG_MIPS_FP_SUPPORT)) {
129 +               /* Map delay slot emulation page */
130 +               base = mmap_region(NULL, STACK_TOP, PAGE_SIZE,
131 +                               VM_READ | VM_EXEC |
132 +                               VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
133 +                               0, NULL);
134 +               if (IS_ERR_VALUE(base)) {
135 +                       ret = base;
136 +                       goto out;
137 +               }
138         }
139  
140         /*