Skip to contentSkip to conversation

arch/mips/kernel/traps: add CONFIG_MIPS_FP_SUPPORT when using handle_fpe

PATCH In review Stephen Zhang 2 participants 7 messages Apr 26, 2022 – Apr 29, 2022 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arch/mips/kernel/traps: add CONFIG_MIPS_FP_SUPPORT when using handle_fpe

From: Shida Zhang <[email protected]>

handle_fpe gets defined when CONFIG_MIPS_FP_SUPPORT is defined. So add CONFIG_MIPS_FP_SUPPORT when using handle_fpe.

---
 arch/mips/kernel/traps.c | 4 ++++
 1 file changed, 4 insertions(+)
arch/mips/kernel/traps.c +4 -0
index 246c6a6b0261..ef9792261f91 100644
@@ -90,7 +90,9 @@ extern asmlinkage void handle_cpu(void);
 extern asmlinkage void handle_ov(void);
 extern asmlinkage void handle_tr(void);
 extern asmlinkage void handle_msa_fpe(void);
+#ifdef CONFIG_MIPS_FP_SUPPORT
 extern asmlinkage void handle_fpe(void);
+#endif
 extern asmlinkage void handle_ftlb(void);
 extern asmlinkage void handle_gsexc(void);
 extern asmlinkage void handle_msa(void);
@@ -2489,8 +2491,10 @@ void __init trap_init(void)
 	if (board_nmi_handler_setup)
 		board_nmi_handler_setup();
 
+#ifdef CONFIG_MIPS_FP_SUPPORT
 	if (cpu_has_fpu && !cpu_has_nofpuex)
 		set_except_vector(EXCCODE_FPE, handle_fpe);
+#endif
 
 	if (cpu_has_ftlbparex)
 		set_except_vector(MIPS_EXCCODE_TLBPAR, handle_ftlb);
Signature · 1 line
2.30.2
#1 lore raw

arch/mips/kernel/traps.c extern asmlinkage void handle_cpu(void); · line 95

Quoted 11 lines · Stephen Zhang
arch/mips/kernel/traps.c +2 -0
index 246c6a6b0261..ef9792261f91 100644
@@ -90,7 +90,9 @@ extern asmlinkage void handle_cpu(void);
 extern asmlinkage void handle_ov(void);
 extern asmlinkage void handle_tr(void);
 extern asmlinkage void handle_msa_fpe(void);
+#ifdef CONFIG_MIPS_FP_SUPPORT
 extern asmlinkage void handle_fpe(void);
+#endif

No need to conditionalise declarations ever.

arch/mips/kernel/traps.c void __init trap_init(void) · line 2497

Quoted 8 lines
arch/mips/kernel/traps.c +2 -0
@@ -2489,8 +2491,10 @@ void __init trap_init(void)
 	if (board_nmi_handler_setup)
 		board_nmi_handler_setup();
 
+#ifdef CONFIG_MIPS_FP_SUPPORT
 	if (cpu_has_fpu && !cpu_has_nofpuex)
 		set_except_vector(EXCCODE_FPE, handle_fpe);
+#endif

No need to conditionalise this either, because `cpu_has_fpu' is forced 0
(in arch/mips/include/asm/cpu-features.h) if !CONFIG_MIPS_FP_SUPPORT. So this code translates to:

if (0 && !0)
set_except_vector(15, handle_fpe);

in the preprocessor if CONFIG_MIPS_FP_SUPPORT is unset and is optimised away. Otherwise it should be written as:

	if (IS_ENABLED(CONFIG_MIPS_FP_SUPPORT) && ...

so as not to clutter C code with #ifdef, as per our coding style.

Maciej

#2 lore raw
Quoted 8 lines · Maciej W. Rozycki <[email protected]> 于2022年4月27日周三 08:40写道:

No need to conditionalise this either, because `cpu_has_fpu' is forced 0
(in arch/mips/include/asm/cpu-features.h) if !CONFIG_MIPS_FP_SUPPORT. So this code translates to:

if (0 && !0)
set_except_vector(15, handle_fpe);

Quoted 8 lines

in the preprocessor if CONFIG_MIPS_FP_SUPPORT is unset and is optimised away. Otherwise it should be written as:

        if (IS_ENABLED(CONFIG_MIPS_FP_SUPPORT) && ...

so as not to clutter C code with #ifdef, as per our coding style.

Maciej

Thanks for your comment. Do you mean the following code:

if (0 && !0)

    set_except_vector(15, handle_fpe);

will be optimised away if !CONFIG_MIPS_FP_SUPPORT?
But we did get “undefined reference to `handle_fpe” error when compiled with !CONFIG_MIPS_FP_SUPPORT.

#3 lore raw
Quoted 6 lines · Stephen Zhang

Thanks for your comment. Do you mean the following code:

if (0 && !0)

    set_except_vector(15, handle_fpe);

will be optimised away if !CONFIG_MIPS_FP_SUPPORT?

Yes. Or more specifically the LHS of the conditional expression will be
0 then, as shown above, and the whole statement will be gone.

Quoted 2 lines

But we did get “undefined reference to `handle_fpe” error when compiled with !CONFIG_MIPS_FP_SUPPORT.

Please send me .config causing it and tell me what compiler and version
you have seen this error with. We rely on things being optimised away heavily throughout the Linux kernel, so this is certainly something to investigate. I have built such a config just fine, but maybe there's a bug somewhere my setup does not trigger.

Maciej

#4 lore raw
Quoted 7 lines · Maciej W. Rozycki <[email protected]> 于2022年4月27日周三 18:57写道:

Please send me .config causing it and tell me what compiler and version
you have seen this error with. We rely on things being optimised away heavily throughout the Linux kernel, so this is certainly something to investigate. I have built such a config just fine, but maybe there's a bug somewhere my setup does not trigger.

Maciej

Okay. The compiler we used is:

Compiler gcc
Compiler version 10
Compiler string mips-linux-gnu-gcc (Debian 10.2.1-6) 10.2.1 20210110 Cross-compile mips-linux-gnu

the commit id of kernel is c00c5e1d157bec0ef0b0b59aa5482eb8dc7e8e49

and the .config file is sent as an attachment.

#5 lore raw
Quoted 8 lines · Stephen Zhang
Quoted 5 lines

Please send me .config causing it and tell me what compiler and version
you have seen this error with. We rely on things being optimised away heavily throughout the Linux kernel, so this is certainly something to investigate. I have built such a config just fine, but maybe there's a bug somewhere my setup does not trigger.

Okay. The compiler we used is:

Quoted 8 lines

Compiler gcc
Compiler version 10
Compiler string mips-linux-gnu-gcc (Debian 10.2.1-6) 10.2.1 20210110 Cross-compile mips-linux-gnu

the commit id of kernel is c00c5e1d157bec0ef0b0b59aa5482eb8dc7e8e49

and the .config file is sent as an attachment.

Thanks.

The bug is in arch/mips/include/asm/mach-ip27/cpu-feature-overrides.h,
which has:

#define cpu_has_fpu 1

(and similarly arch/mips/include/asm/mach-ip30/cpu-feature-overrides.h). This is not supported, as noted in arch/mips/include/asm/cpu-features.h:

/* Don't override `cpu_has_fpu' to 1 or the "nofpu" option won't work. */

Perhaps we should explicitly undefine `cpu_has_fpu' if set to 1?

Maciej

#6 lore raw
Quoted 9 lines · Maciej W. Rozycki <[email protected]> 于2022年4月28日周四 17:00写道:

On Thu, 28 Apr 2022, Stephen Zhang wrote:
Thanks.

The bug is in arch/mips/include/asm/mach-ip27/cpu-feature-overrides.h,
which has:

#define cpu_has_fpu 1

Quoted 8 lines

(and similarly arch/mips/include/asm/mach-ip30/cpu-feature-overrides.h). This is not supported, as noted in arch/mips/include/asm/cpu-features.h:

/* Don't override `cpu_has_fpu' to 1 or the "nofpu" option won't work. */

Perhaps we should explicitly undefine `cpu_has_fpu' if set to 1?

Maciej

Thanks for your detailed explanation and suggestion. I will make a v2 patch.