diff mbox series

[v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided

Message ID 20220429032621.674865-1-starzhangzsd@gmail.com (mailing list archive)
State Superseded
Headers show
Series [v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided | expand

Commit Message

Stephen Zhang April 29, 2022, 3:26 a.m. UTC
From: Shida Zhang <zhangshida@kylinos.cn>

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

Suggested-by: Maciej W. Rozycki <macro@orcam.me.uk>
Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
---
 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(+)

Comments

Maciej W. Rozycki April 29, 2022, 9:19 a.m. UTC | #1
On Fri, 29 Apr 2022, Stephen Zhang wrote:

> 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
Thomas Bogendoerfer April 29, 2022, 9:51 a.m. UTC | #2
On Fri, Apr 29, 2022 at 11:26:21AM +0800, Stephen Zhang wrote:
> From: Shida Zhang <zhangshida@kylinos.cn>
> 
> Undefine and redefine cpu_has_fpu to 0 when it is overridden with
> the "nofpu" option.
> 
> Suggested-by: Maciej W. Rozycki <macro@orcam.me.uk>
> Signed-off-by: Shida Zhang <zhangshida@kylinos.cn>
> ---
>  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(+)
> 
> diff --git a/arch/mips/include/asm/cpu-features.h b/arch/mips/include/asm/cpu-features.h
> index de8cb2ccb781..38eb469008b6 100644
> --- a/arch/mips/include/asm/cpu-features.h
> +++ b/arch/mips/include/asm/cpu-features.h
> @@ -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)
> -- 
> 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.
Maciej W. Rozycki April 29, 2022, 3:11 p.m. UTC | #3
On Fri, 29 Apr 2022, Thomas Bogendoerfer wrote:

> > diff --git a/arch/mips/include/asm/cpu-features.h b/arch/mips/include/asm/cpu-features.h
> > index de8cb2ccb781..38eb469008b6 100644
> > --- a/arch/mips/include/asm/cpu-features.h
> > +++ b/arch/mips/include/asm/cpu-features.h
> > @@ -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)
> > -- 
> > 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
Stephen Zhang April 30, 2022, 3:36 a.m. UTC | #4
Maciej W. Rozycki <macro@orcam.me.uk> 于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:
>
> #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.

Thomas Bogendoerfer <tsbogend@alpha.franken.de> 于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.
Maciej W. Rozycki April 30, 2022, 3:38 p.m. UTC | #5
On Sat, 30 Apr 2022, Stephen Zhang wrote:

> >  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.
> 
> 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.

> > 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
Stephen Zhang May 1, 2022, 2:54 a.m. UTC | #6
Maciej W. Rozycki <macro@orcam.me.uk> 于2022年4月30日周六 23:38写道:
>
>  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

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.
Maciej W. Rozycki May 1, 2022, 11:31 a.m. UTC | #7
On Sun, 1 May 2022, Stephen Zhang wrote:

> 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.

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

  Maciej
diff mbox series

Patch

diff --git a/arch/mips/include/asm/cpu-features.h b/arch/mips/include/asm/cpu-features.h
index de8cb2ccb781..38eb469008b6 100644
--- a/arch/mips/include/asm/cpu-features.h
+++ b/arch/mips/include/asm/cpu-features.h
@@ -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)