powerpc/64s: dt_cpu_ftrs boot time setup option

Submitted by Nicholas Piggin on May 11, 2017, 11:24 a.m.

Details

Message ID 20170511112441.30287-1-npiggin@gmail.com
State Accepted
Commit a2b05b7aa60e1e9b60faf01dfb1cca35638d1ab1
Headers show

Commit Message

Nicholas Piggin May 11, 2017, 11:24 a.m.
Provide a dt_cpu_ftrs= cmdline option to disable the dt_cpu_ftrs CPU
feature discovery, and fall back to the "cputable" based version.

Also allow control of advertising unknown features to userspace and
with this parameter, and remove the clunky CONFIG option.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 Documentation/admin-guide/kernel-parameters.txt | 10 ++++++
 arch/powerpc/Kconfig                            |  5 ---
 arch/powerpc/kernel/dt_cpu_ftrs.c               | 41 +++++++++++++++++++------
 3 files changed, 42 insertions(+), 14 deletions(-)

Comments

Paul Clarke May 11, 2017, 1:25 p.m.
On 05/11/2017 06:24 AM, Nicholas Piggin wrote:
> Provide a dt_cpu_ftrs= cmdline option to disable the dt_cpu_ftrs CPU
> feature discovery, and fall back to the "cputable" based version.

This boat has already sailed, I think, but "ftrs"?  Was it too difficult to type "features"?  This seems like something that should be easy and intuitive to find and understand.

:-)

PC
Michael Ellerman May 12, 2017, 3:46 a.m.
Paul Clarke <pc@us.ibm.com> writes:

> On 05/11/2017 06:24 AM, Nicholas Piggin wrote:
>> Provide a dt_cpu_ftrs= cmdline option to disable the dt_cpu_ftrs CPU
>> feature discovery, and fall back to the "cputable" based version.
>
> This boat has already sailed, I think, but "ftrs"?

What you think vowels grow on trees! :)

> Was it too difficult to type "features"?

For the command line option we could spell out features.

But should we also expand "dt", and "cpu" ?

device_tree_central_processing_unit_features=off

:P

> This seems like something that should be easy and intuitive to find
> and understand.

Maybe. Ideally no one will ever use it, certainly not end users, it's
primarily intended for developers doing bring-up.

cheers
Paul Clarke May 12, 2017, 12:32 p.m.
On 05/11/2017 10:46 PM, Michael Ellerman wrote:
> Paul Clarke <pc@us.ibm.com> writes:
>> On 05/11/2017 06:24 AM, Nicholas Piggin wrote:
>>> Provide a dt_cpu_ftrs= cmdline option to disable the dt_cpu_ftrs CPU
>>> feature discovery, and fall back to the "cputable" based version.
>>
>> This boat has already sailed, I think, but "ftrs"?
> 
> What you think vowels grow on trees! :)

At least you're using lower-case, which takes less space.  ;-)

>> Was it too difficult to type "features"?

I see "ftrs" and think "footers".

> For the command line option we could spell out features.
> 
> But should we also expand "dt", and "cpu" ?
> 
> device_tree_central_processing_unit_features=off

I'm not the biggest fan of "dt" ("devtree", anyone?), but that's certainly established.

So _that's_ what "cpu" stands for!  ;-)

> :P
> 
>> This seems like something that should be easy and intuitive to find
>> and understand.
> 
> Maybe. Ideally no one will ever use it, certainly not end users, it's
> primarily intended for developers doing bring-up.

I'm a developer, and I like to be able to understand something at a glance.  (Hmm, what are "CPU footers"?)

:-P

PC
Michael Ellerman May 15, 2017, 9:43 a.m.
Paul Clarke <pc@us.ibm.com> writes:

> On 05/11/2017 10:46 PM, Michael Ellerman wrote:
>> Paul Clarke <pc@us.ibm.com> writes:
>>> On 05/11/2017 06:24 AM, Nicholas Piggin wrote:
>>>> Provide a dt_cpu_ftrs= cmdline option to disable the dt_cpu_ftrs CPU
>>>> feature discovery, and fall back to the "cputable" based version.
>>>
>>> This boat has already sailed, I think, but "ftrs"?
>> 
>> What you think vowels grow on trees! :)
>
> At least you're using lower-case, which takes less space.  ;-)
>
>>> Was it too difficult to type "features"?
>
> I see "ftrs" and think "footers".

"FTR" - the shouty version - has meant "feature" in the powerpc code
base since at least 2002.

So it may be a crappy abbreviation but it's at least consistent :)

cheers
Balbir Singh May 29, 2017, 10:29 p.m.
On Thu, 2017-05-11 at 21:24 +1000, Nicholas Piggin wrote:
> Provide a dt_cpu_ftrs= cmdline option to disable the dt_cpu_ftrs CPU
> feature discovery, and fall back to the "cputable" based version.
> 
> Also allow control of advertising unknown features to userspace and
> with this parameter, and remove the clunky CONFIG option.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
> ---
>  Documentation/admin-guide/kernel-parameters.txt | 10 ++++++
>  arch/powerpc/Kconfig                            |  5 ---
>  arch/powerpc/kernel/dt_cpu_ftrs.c               | 41 +++++++++++++++++++------
>  3 files changed, 42 insertions(+), 14 deletions(-)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index facc20a3f962..7a7c1cc80f9f 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -867,6 +867,16 @@
>  
>  	dscc4.setup=	[NET]
>  
> +	dt_cpu_ftrs=	[PPC]
> +			Format: {"off" | "known"}
> +			Control how the dt_cpu_ftrs device-tree binding is
> +			used for CPU feature discovery and setup (if it
> +			exists).
> +			off: Do not use it, fall back to legacy cpu table.
> +			known: Do not pass through unknown features to guests
> +			or userspace, only those that the kernel is not aware
> +			of.
> +
>  	dump_apple_properties	[X86]
>  			Dump name and content of EFI device properties on
>  			x86 Macs.  Useful for driver authors to determine
> diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
> index 5bd868f2e813..c924710e5bc7 100644
> --- a/arch/powerpc/Kconfig
> +++ b/arch/powerpc/Kconfig
> @@ -391,11 +391,6 @@ config PPC_DT_CPU_FTRS
>  	  firmware provides this binding.
>  	  If you're not sure say Y.
>  
> -config PPC_CPUFEATURES_ENABLE_UNKNOWN
> -	bool "cpufeatures pass through unknown features to guest/userspace"
> -	depends on PPC_DT_CPU_FTRS
> -	default y
> -
>  config HIGHMEM
>  	bool "High memory support"
>  	depends on PPC32
> diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c b/arch/powerpc/kernel/dt_cpu_ftrs.c
> index fcc7588a96d6..050925b5b451 100644
> --- a/arch/powerpc/kernel/dt_cpu_ftrs.c
> +++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
> @@ -671,12 +671,24 @@ static struct dt_cpu_feature_match __initdata
>  	{"wait-v3", feat_enable, 0},
>  };
>  
> -/* XXX: how to configure this? Default + boot time? */
> -#ifdef CONFIG_PPC_CPUFEATURES_ENABLE_UNKNOWN
> -#define CPU_FEATURE_ENABLE_UNKNOWN 1
> -#else
> -#define CPU_FEATURE_ENABLE_UNKNOWN 0
> -#endif
> +static bool __initdata using_dt_cpu_ftrs = true;
> +static bool __initdata dt_cpu_ftrs_enable_unknown = true;
> +
> +static int __init dt_cpu_ftrs_parse(char *str)
> +{
> +	if (!str)
> +		return 0;
> +
> +	if (!strcmp(str, "off"))
> +		using_dt_cpu_ftrs = false;
> +	else if (!strcmp(str, "known"))
> +		dt_cpu_ftrs_enable_unknown = false;
> +	else
> +		return 1;
> +
> +	return 0;
> +}
> +early_param("dt_cpu_ftrs", dt_cpu_ftrs_parse);

I wouldn't use strcmp with user passed parameters.

Balbir Singh.
Michael Ellerman May 30, 2017, 5:29 a.m.
Balbir Singh <bsingharora@gmail.com> writes:
> On Thu, 2017-05-11 at 21:24 +1000, Nicholas Piggin wrote:
>> diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c b/arch/powerpc/kernel/dt_cpu_ftrs.c
>> index fcc7588a96d6..050925b5b451 100644
>> --- a/arch/powerpc/kernel/dt_cpu_ftrs.c
>> +++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
>> @@ -671,12 +671,24 @@ static struct dt_cpu_feature_match __initdata
>>  	{"wait-v3", feat_enable, 0},
>>  };
>>  
>> -/* XXX: how to configure this? Default + boot time? */
>> -#ifdef CONFIG_PPC_CPUFEATURES_ENABLE_UNKNOWN
>> -#define CPU_FEATURE_ENABLE_UNKNOWN 1
>> -#else
>> -#define CPU_FEATURE_ENABLE_UNKNOWN 0
>> -#endif
>> +static bool __initdata using_dt_cpu_ftrs = true;
>> +static bool __initdata dt_cpu_ftrs_enable_unknown = true;
>> +
>> +static int __init dt_cpu_ftrs_parse(char *str)
>> +{
>> +	if (!str)
>> +		return 0;
>> +
>> +	if (!strcmp(str, "off"))
>> +		using_dt_cpu_ftrs = false;
>> +	else if (!strcmp(str, "known"))
>> +		dt_cpu_ftrs_enable_unknown = false;
>> +	else
>> +		return 1;
>> +
>> +	return 0;
>> +}
>> +early_param("dt_cpu_ftrs", dt_cpu_ftrs_parse);
>
> I wouldn't use strcmp with user passed parameters.

Why not? Especially considering the generic code has already parsed the
string to find the = delimiter, and is just passing us the tail.

cheers
Michael Ellerman June 1, 2017, 1:31 p.m.
On Thu, 2017-05-11 at 11:24:41 UTC, Nicholas Piggin wrote:
> Provide a dt_cpu_ftrs= cmdline option to disable the dt_cpu_ftrs CPU
> feature discovery, and fall back to the "cputable" based version.
> 
> Also allow control of advertising unknown features to userspace and
> with this parameter, and remove the clunky CONFIG option.
> 
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

Applied to powerpc fixes, thanks.

https://git.kernel.org/powerpc/c/a2b05b7aa60e1e9b60faf01dfb1cca

cheers

Patch hide | download patch | download mbox

diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
index facc20a3f962..7a7c1cc80f9f 100644
--- a/Documentation/admin-guide/kernel-parameters.txt
+++ b/Documentation/admin-guide/kernel-parameters.txt
@@ -867,6 +867,16 @@ 
 
 	dscc4.setup=	[NET]
 
+	dt_cpu_ftrs=	[PPC]
+			Format: {"off" | "known"}
+			Control how the dt_cpu_ftrs device-tree binding is
+			used for CPU feature discovery and setup (if it
+			exists).
+			off: Do not use it, fall back to legacy cpu table.
+			known: Do not pass through unknown features to guests
+			or userspace, only those that the kernel is not aware
+			of.
+
 	dump_apple_properties	[X86]
 			Dump name and content of EFI device properties on
 			x86 Macs.  Useful for driver authors to determine
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 5bd868f2e813..c924710e5bc7 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -391,11 +391,6 @@  config PPC_DT_CPU_FTRS
 	  firmware provides this binding.
 	  If you're not sure say Y.
 
-config PPC_CPUFEATURES_ENABLE_UNKNOWN
-	bool "cpufeatures pass through unknown features to guest/userspace"
-	depends on PPC_DT_CPU_FTRS
-	default y
-
 config HIGHMEM
 	bool "High memory support"
 	depends on PPC32
diff --git a/arch/powerpc/kernel/dt_cpu_ftrs.c b/arch/powerpc/kernel/dt_cpu_ftrs.c
index fcc7588a96d6..050925b5b451 100644
--- a/arch/powerpc/kernel/dt_cpu_ftrs.c
+++ b/arch/powerpc/kernel/dt_cpu_ftrs.c
@@ -671,12 +671,24 @@  static struct dt_cpu_feature_match __initdata
 	{"wait-v3", feat_enable, 0},
 };
 
-/* XXX: how to configure this? Default + boot time? */
-#ifdef CONFIG_PPC_CPUFEATURES_ENABLE_UNKNOWN
-#define CPU_FEATURE_ENABLE_UNKNOWN 1
-#else
-#define CPU_FEATURE_ENABLE_UNKNOWN 0
-#endif
+static bool __initdata using_dt_cpu_ftrs = true;
+static bool __initdata dt_cpu_ftrs_enable_unknown = true;
+
+static int __init dt_cpu_ftrs_parse(char *str)
+{
+	if (!str)
+		return 0;
+
+	if (!strcmp(str, "off"))
+		using_dt_cpu_ftrs = false;
+	else if (!strcmp(str, "known"))
+		dt_cpu_ftrs_enable_unknown = false;
+	else
+		return 1;
+
+	return 0;
+}
+early_param("dt_cpu_ftrs", dt_cpu_ftrs_parse);
 
 static void __init cpufeatures_setup_start(u32 isa)
 {
@@ -707,7 +719,7 @@  static bool __init cpufeatures_process_feature(struct dt_cpu_feature *f)
 		}
 	}
 
-	if (!known && CPU_FEATURE_ENABLE_UNKNOWN) {
+	if (!known && dt_cpu_ftrs_enable_unknown) {
 		if (!feat_try_enable_unknown(f)) {
 			pr_info("not enabling: %s (unknown and unsupported by kernel)\n",
 				f->name);
@@ -766,8 +778,6 @@  static int __init fdt_find_cpu_features(unsigned long node, const char *uname,
 	return 0;
 }
 
-static bool __initdata using_dt_cpu_ftrs = false;
-
 bool __init dt_cpu_ftrs_in_use(void)
 {
 	return using_dt_cpu_ftrs;
@@ -775,6 +785,16 @@  bool __init dt_cpu_ftrs_in_use(void)
 
 bool __init dt_cpu_ftrs_init(void *fdt)
 {
+	if (!using_dt_cpu_ftrs) {
+		/*
+		 * This should never happen because this runs before
+		 * early_praam, however if the init ordering changes,
+		 * test if early_param has disabled this.
+		 */
+		return false;
+	}
+	using_dt_cpu_ftrs = false;
+
 	/* Setup and verify the FDT, if it fails we just bail */
 	if (!early_init_dt_verify(fdt))
 		return false;
@@ -1027,5 +1047,8 @@  static int __init dt_cpu_ftrs_scan_callback(unsigned long node, const char
 
 void __init dt_cpu_ftrs_scan(void)
 {
+	if (!using_dt_cpu_ftrs)
+		return;
+
 	of_scan_flat_dt(dt_cpu_ftrs_scan_callback, NULL);
 }