Skip to contentSkip to conversation

MIPS: undefine and redefine cpu_has_fpu when it is overrided

PATCH In review Stephen Zhang 3 participants 8 messages Apr 29, 2022 – May 1, 2022 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 MIPS: undefine and redefine cpu_has_fpu when it is overrided

From: Shida Zhang <[email protected]>

Undefine and redefine cpu_has_fpu to 0 when it is overridden with the "nofpu" option.

---
Changelog in v1 -> v2:
- Choose to redefine cpu_has_fpu to solve the problem.

 arch/mips/include/asm/cpu-features.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/mips/include/asm/cpu-features.h +4 -0
index de8cb2ccb781..38eb469008b6 100644
@@ -134,6 +134,10 @@
 # endif
 #else
 # define raw_cpu_has_fpu	cpu_has_fpu
+# ifndef CONFIG_MIPS_FP_SUPPORT
+#  undef cpu_has_fpu
+#  define cpu_has_fpu		0
+# endif
 #endif
 #ifndef cpu_has_32fpr
 #define cpu_has_32fpr		__isa_ge_or_opt(1, MIPS_CPU_32FPR)
Signature · 1 line
2.30.2
#1 lore raw
Quoted 2 lines · Stephen Zhang

Undefine and redefine cpu_has_fpu to 0 when it is overridden with the "nofpu" option.

Umm, `nofpu' is a kernel parameter, not the CONFIG_MIPS_FP_SUPPORT config
option; cf. Documentation/admin-guide/kernel-parameters.txt.

Maciej

#2 lore raw
In reply to Stephen Zhang
Quoted 31 lines · Stephen Zhang

From: Shida Zhang <[email protected]>

Undefine and redefine cpu_has_fpu to 0 when it is overridden with the "nofpu" option.

---
Changelog in v1 -> v2:
- Choose to redefine cpu_has_fpu to solve the problem.

 arch/mips/include/asm/cpu-features.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/mips/include/asm/cpu-features.h +4 -0
index de8cb2ccb781..38eb469008b6 100644
@@ -134,6 +134,10 @@
 # endif
 #else
 # define raw_cpu_has_fpu	cpu_has_fpu
+# ifndef CONFIG_MIPS_FP_SUPPORT
+#  undef cpu_has_fpu
+#  define cpu_has_fpu		0
+# endif
 #endif
 #ifndef cpu_has_32fpr
 #define cpu_has_32fpr		__isa_ge_or_opt(1, MIPS_CPU_32FPR)
Signature · 1 line
2.30.2

I prefer just removing the #defines from ip27/ip30 cpu-feasture-overrides.h. Or isn't that enough for fixing the problem ?

Thomas.

Signature · 2 lines
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]
#3 lore raw
Quoted 12 lines · Thomas Bogendoerfer
Quoted 12 lines
arch/mips/include/asm/cpu-features.h +4 -0
index de8cb2ccb781..38eb469008b6 100644
@@ -134,6 +134,10 @@
 # endif
 #else
 # define raw_cpu_has_fpu	cpu_has_fpu
+# ifndef CONFIG_MIPS_FP_SUPPORT
+#  undef cpu_has_fpu
+#  define cpu_has_fpu		0
+# endif
Quoted 8 lines
Quoted 5 lines
arch/mips/include/asm/cpu-features.h +0 -0
 #endif
 #ifndef cpu_has_32fpr
 #define cpu_has_32fpr		__isa_ge_or_opt(1, MIPS_CPU_32FPR)
Signature · 1 line
2.30.2

I prefer just removing the #defines from ip27/ip30 cpu-feasture-overrides.h. Or isn't that enough for fixing the problem ?

That's what I've meant, and I have now posted fixes, successfully
build-tested.

Additionally I've thought of adding something like:

#if cpu_has_fpu

# undef cpu_has_fpu
#endif

or maybe even:

#if cpu_has_fpu

# error "Forcing `cpu_has_fpu' to non-zero is not supported"
#endif

to arch/mips/include/asm/cpu-features.h, but maybe that's an overkill.

Maciej

#4 lore raw
Quoted 9 lines · Maciej W. Rozycki <[email protected]> 于2022年4月29日周五 23:11写道:

Additionally I've thought of adding something like:

#if cpu_has_fpu

# undef cpu_has_fpu
#endif

or maybe even:

Quoted 7 lines

#if cpu_has_fpu

# error "Forcing `cpu_has_fpu' to non-zero is not supported"
#endif

to arch/mips/include/asm/cpu-features.h, but maybe that's an overkill.

Maciej

Yeah, but why do you think that's an overkill? There is a great chance people will ignore the note of 'cpu_has_fpu', and it did happen. When that happens, there should exist a way to point out or fix that.

Quoted 5 lines · Thomas Bogendoerfer <[email protected]> 于2022年4月29日周五 18:01写道:

I prefer just removing the #defines from ip27/ip30 cpu-feasture-overrides.h. Or isn't that enough for fixing the problem ?

Thomas.

So maybe that's why I don't think just removing the #defines from ip27/ip30 cpu-feasture-overrides.h. is enough for fixing the problem.

Stephen.

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

Additionally I've thought of adding something like:

#if cpu_has_fpu

# undef cpu_has_fpu
#endif

or maybe even:

#if cpu_has_fpu

# error "Forcing `cpu_has_fpu' to non-zero is not supported"
#endif
Quoted 5 lines
Quoted 1 line

to arch/mips/include/asm/cpu-features.h, but maybe that's an overkill.

Yeah, but why do you think that's an overkill? There is a great chance people will ignore the note of 'cpu_has_fpu', and it did happen. When that happens, there should exist a way to point out or fix that.

Maybe it's the language, but my intent has been to express my uncertainty
here rather than asserting that indeed it is an overkill.

People do make mistakes from time to time, both code writers and
reviewers do. It's not clear to me where to draw the line for safety checks though.

Here `cpu_has_fpu' is a bit unusual in that unlike with the other feature
override macros we don't want it to expand to a non-zero constant. The comment didn't work twice, though I suspect both cpu-feature-overrides.h files may have been written before the comment went in (I'm fairly sure the IP30 port lived outside the tree for a while). But I have only added the comment in the first place when I tripped over the `nofpu' option not working for the machine I needed to run FPU emulator verification with, and several platforms were fixed alongside.

Given these circumstances it probably makes sense to have such a safety
check after all.

Quoted 7 lines
Quoted 4 lines

I prefer just removing the #defines from ip27/ip30 cpu-feasture-overrides.h. Or isn't that enough for fixing the problem ?

Thomas.

So maybe that's why I don't think just removing the #defines from ip27/ip30 cpu-feasture-overrides.h. is enough for fixing the problem.

Well, that *is* the fix for the problem at hand, as this macro is not
supposed to be defined such as to expand to a non-zero constant.

Adding a safety check would be a separate improvement. Please feel free
to submit one.

We need to keep fixes and improvements as separate changes. For one
fixes can be candidates for backporting while improvements are never backported; cf. Documentation/process/stable-kernel-rules.rst.

I hope this clears your concerns. Let me know if you have further
questions.

Maciej

#6 lore raw
Quoted 4 lines · Maciej W. Rozycki <[email protected]> 于2022年4月30日周六 23:38写道:

Adding a safety check would be a separate improvement. Please feel free
to submit one.

Quoted 8 lines

We need to keep fixes and improvements as separate changes. For one
fixes can be candidates for backporting while improvements are never backported; cf. Documentation/process/stable-kernel-rules.rst.

I hope this clears your concerns. Let me know if you have further
questions.

Maciej

Thanks for your elaboration.It helps a lot.
I want to submit a v3 patch like:

#if cpu_has_fpu

# error "Forcing `cpu_has_fpu' to non-zero is not supported"
#endif

but this will cause the link error if not combined with the fix:

MIPS: IP30: Remove incorrect `cpu_has_fpu' override

Maybe I should submit one first, and see how it goes then.

#7 lore raw
Quoted 4 lines · Stephen Zhang

Thanks for your elaboration.It helps a lot.
I want to submit a v3 patch like:

#if cpu_has_fpu

Quoted 8 lines
# error "Forcing `cpu_has_fpu' to non-zero is not supported"
#endif

but this will cause the link error if not combined with the fix:

MIPS: IP30: Remove incorrect `cpu_has_fpu' override

Maybe I should submit one first, and see how it goes then.

Let's wait a couple of days until the fixes required have been queued.

Maciej