2022-04-30 11:51:16

by Stephen Zhang

[permalink] [raw]
Subject: [PATCH v2] 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.

Suggested-by: Maciej W. Rozycki <[email protected]>
Signed-off-by: Shida Zhang <[email protected]>
---
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


2022-04-30 17:00:08

by Maciej W. Rozycki

[permalink] [raw]
Subject: Re: [PATCH v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided

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

2022-05-01 12:43:10

by Maciej W. Rozycki

[permalink] [raw]
Subject: Re: [PATCH v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided

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

2022-05-02 12:32:15

by Thomas Bogendoerfer

[permalink] [raw]
Subject: Re: [PATCH v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided

On Fri, Apr 29, 2022 at 11:26:21AM +0800, Stephen Zhang wrote:
> From: Shida Zhang <[email protected]>
>
> Undefine and redefine cpu_has_fpu to 0 when it is overridden with
> the "nofpu" option.
>
> Suggested-by: Maciej W. Rozycki <[email protected]>
> Signed-off-by: Shida Zhang <[email protected]>
> ---
> 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.

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

2022-05-02 23:26:15

by Stephen Zhang

[permalink] [raw]
Subject: Re: [PATCH v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided

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

2022-05-03 00:28:30

by Maciej W. Rozycki

[permalink] [raw]
Subject: Re: [PATCH v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided

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

2022-05-03 00:32:35

by Stephen Zhang

[permalink] [raw]
Subject: Re: [PATCH v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided

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:
>
> #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 <[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.

2022-05-03 00:56:32

by Maciej W. Rozycki

[permalink] [raw]
Subject: Re: [PATCH v2] MIPS: undefine and redefine cpu_has_fpu when it is overrided

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