Skip to contentSkip to conversation

cpufreq: intel_pstate: Allow enable/disable energy efficiency

PATCH Superseded Srinivas Pandruvada 7 participants 10 messages Jun 25, 2020 – Jul 1, 2020

Subsystems (5)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

PATCH v3 1/2 cpufreq: intel_pstate: Allow enable/disable energy efficiency

By default intel_pstate driver disables energy efficiency by setting MSR_IA32_POWER_CTL bit 19 for Kaby Lake desktop CPU model in HWP mode. This CPU model is also shared by Coffee Lake desktop CPUs. This allows these systems to reach maximum possible frequency. But this adds power penalty, which some customers don't want. They want some way to enable/ disable dynamically.

So, add an additional attribute "energy_efficiency_enable" under /sys/devices/system/cpu/intel_pstate/ for these CPU models. This allows to read and write bit 19 ("Disable Energy Efficiency Optimization") in the MSR IA32_POWER_CTL.

This attribute is present in both HWP and non-HWP mode as this has an effect in both modes. Refer to Intel Software Developer's manual for details. The scope of this bit is package wide. Also these systems support only one package. So read/write MSR on the current CPU is enough.

---
v3 update
Moved the MSR bit definition to msr-index.h from intel_pstate.c as Doug wanted. Offline checking with Borislav, for MSR defintion it is fine to move to msr-index.h even for single user of the definition. But here the MSR definition is already in msr-index.h, but adding the MSR bit definition also.

 Documentation/admin-guide/pm/intel_pstate.rst |  9 ++++
 arch/x86/include/asm/msr-index.h              |  1 +
 drivers/cpufreq/intel_pstate.c                | 47 ++++++++++++++++++-
 3 files changed, 55 insertions(+), 2 deletions(-)
Documentation/admin-guide/pm/intel_pstate.rst +9 -0
index 39d80bc29ccd..1ca2684a94d7 100644
@@ -431,6 +431,15 @@ argument is passed to the kernel in the command line.
 	supported in the current configuration, writes to this attribute will
 	fail with an appropriate error.
 
+``energy_efficiency_enable``
+	This attribute is only present on platforms, which has CPUs matching
+	Kaby Lake or Coffee Lake desktop CPU model. By default
+	"energy_efficiency" is disabled on these CPU models in HWP mode by this
+	driver. Enabling energy efficiency may limit maximum operating
+	frequency in both HWP and non HWP mode. In non HWP mode, this attribute
+	has an effect in turbo range only. But in HWP mode, this attribute also
+	has an effect in non turbo range.
+
 Interpretation of Policy Attributes
 -----------------------------------
 
arch/x86/include/asm/msr-index.h +1 -0
index e8370e64a155..fec86ad14f8d 100644
@@ -254,6 +254,7 @@
 #define MSR_PEBS_FRONTEND		0x000003f7
 
 #define MSR_IA32_POWER_CTL		0x000001fc
+#define MSR_IA32_POWER_CTL_BIT_EE	19
 
 #define MSR_IA32_MC0_CTL		0x00000400
 #define MSR_IA32_MC0_STATUS		0x00000401
drivers/cpufreq/intel_pstate.c +45 -2

77 lines not on this page · raw message

Signature · 1 line
2.25.4
maintainer
#1 lore raw
Quoted 11 lines · Srinivas Pandruvada

By default intel_pstate driver disables energy efficiency by setting MSR_IA32_POWER_CTL bit 19 for Kaby Lake desktop CPU model in HWP mode. This CPU model is also shared by Coffee Lake desktop CPUs. This allows these systems to reach maximum possible frequency. But this adds power penalty, which some customers don't want. They want some way to enable/ disable dynamically.

So, add an additional attribute "energy_efficiency_enable" under /sys/devices/system/cpu/intel_pstate/ for these CPU models. This allows to read and write bit 19 ("Disable Energy Efficiency Optimization") in the MSR IA32_POWER_CTL.

Yes, this is how functionality behind MSRs should be made available to userspace - not poking at naked MSRs. Good.

Quoted 8 lines

This attribute is present in both HWP and non-HWP mode as this has an effect in both modes. Refer to Intel Software Developer's manual for details. The scope of this bit is package wide. Also these systems support only one package. So read/write MSR on the current CPU is enough.

Quoted 7 lines

---
v3 update
Moved the MSR bit definition to msr-index.h from intel_pstate.c as Doug wanted. Offline checking with Borislav, for MSR defintion it is fine to move to msr-index.h even for single user of the definition. But here the MSR definition is already in msr-index.h, but adding the MSR bit definition also.

Yes.

Btw, no need for the "offline checking" - you can do this on the mailing list just fine.

Quoted 10 lines
 Documentation/admin-guide/pm/intel_pstate.rst |  9 ++++
 arch/x86/include/asm/msr-index.h              |  1 +
 drivers/cpufreq/intel_pstate.c                | 47 ++++++++++++++++++-
 3 files changed, 55 insertions(+), 2 deletions(-)
Documentation/admin-guide/pm/intel_pstate.rst +0 -0
index 39d80bc29ccd..1ca2684a94d7 100644

Documentation/admin-guide/pm/intel_pstate.rst argument is passed to the kernel in the command line. · line 435

Quoted 5 lines
Documentation/admin-guide/pm/intel_pstate.rst +2 -0
@@ -431,6 +431,15 @@ argument is passed to the kernel in the command line.
 	supported in the current configuration, writes to this attribute will
 	fail with an appropriate error.
 
+``energy_efficiency_enable``
+	This attribute is only present on platforms, which has CPUs matching

which have

Documentation/admin-guide/pm/intel_pstate.rst argument is passed to the kernel in the command line. · line 441

Quoted 6 lines
Documentation/admin-guide/pm/intel_pstate.rst +6 -0
+	Kaby Lake or Coffee Lake desktop CPU model. By default
+	"energy_efficiency" is disabled on these CPU models in HWP mode by this
+	driver. Enabling energy efficiency may limit maximum operating
+	frequency in both HWP and non HWP mode. In non HWP mode, this attribute
+	has an effect in turbo range only. But in HWP mode, this attribute also
+	has an effect in non turbo range.

Those last two sentences could be simplified - read strange.

arch/x86/include/asm/msr-index.h line 257

Quoted 13 lines
Documentation/admin-guide/pm/intel_pstate.rst +1 -0
+
 Interpretation of Policy Attributes
 -----------------------------------
 
arch/x86/include/asm/msr-index.h +1 -0
index e8370e64a155..fec86ad14f8d 100644
@@ -254,6 +254,7 @@
 #define MSR_PEBS_FRONTEND		0x000003f7
 
 #define MSR_IA32_POWER_CTL		0x000001fc
+#define MSR_IA32_POWER_CTL_BIT_EE	19

Sort that MSR in - I know, the rest is not sorted either but we can start somewhere. So pls put it...

#define MSR_LBR_SELECT 0x000001c8
#define MSR_LBR_TOS 0x000001c9

<--- here.

#define MSR_LBR_NHM_FROM 0x00000680
#define MSR_LBR_NHM_TO 0x000006c0

Quoted 9 lines
arch/x86/include/asm/msr-index.h +0 -0
 #define MSR_IA32_MC0_CTL		0x00000400
 #define MSR_IA32_MC0_STATUS		0x00000401
drivers/cpufreq/intel_pstate.c +0 -0
index 8e23a698ce04..daa1d9c12098 100644
@@ -1218,6 +1218,42 @@ static ssize_t store_hwp_dynamic_boost(struct kobject *a,
 	return count;
 }

drivers/cpufreq/intel_pstate.c static ssize_t store_hwp_dynamic_boost(struct kobject *a, · line 1229

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +9 -0
 
+static ssize_t show_energy_efficiency_enable(struct kobject *kobj,
+					     struct kobj_attribute *attr,
+					     char *buf)
+{
+	u64 power_ctl;
+	int enable;
+
+	rdmsrl(MSR_IA32_POWER_CTL, power_ctl);
+	enable = (power_ctl & BIT(MSR_IA32_POWER_CTL_BIT_EE)) >> MSR_IA32_POWER_CTL_BIT_EE;

So you can simplify to:

	enable = !!(power_ctl & BIT(MSR_IA32_POWER_CTL_BIT_EE));

methinks.

drivers/cpufreq/intel_pstate.c static ssize_t store_hwp_dynamic_boost(struct kobject *a, · line 1230

Quoted 1 line
drivers/cpufreq/intel_pstate.c +1 -0
+	return sprintf(buf, "%d\n", !enable);

If this bit is called

"Disable Energy Efficiency Optimization"

why do you call your function and sysfs file "enable"? This is making it more confusing.

Why don't you call it simply: "energy_efficiency" and have it intuitive:

1 - enabled
0 - disabled

?

Quoted 5 lines
drivers/cpufreq/intel_pstate.c +5 -0
+static ssize_t store_energy_efficiency_enable(struct kobject *a,
+					      struct kobj_attribute *b,
+					      const char *buf, size_t count)
+{
+	u64 power_ctl;

drivers/cpufreq/intel_pstate.c static ssize_t store_hwp_dynamic_boost(struct kobject *a, · line 1247

Quoted 10 lines
drivers/cpufreq/intel_pstate.c +10 -0
+	u32 input;
+	int ret;
+
+	ret = kstrtouint(buf, 10, &input);
+	if (ret)
+		return ret;
+
+	mutex_lock(&intel_pstate_driver_lock);
+	rdmsrl(MSR_IA32_POWER_CTL, power_ctl);
+	if (input)

This is too lax - it will be enabled for any !0 value. Please accept only 0 and 1.

Thx.

Signature · 4 lines
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
author maintainer
#2 lore raw
Quoted 21 lines · Borislav Petkov
Quoted 18 lines · Srinivas Pandruvada

By default intel_pstate driver disables energy efficiency by setting
MSR_IA32_POWER_CTL bit 19 for Kaby Lake desktop CPU model in HWP mode.
This CPU model is also shared by Coffee Lake desktop CPUs. This allows
these systems to reach maximum possible frequency. But this adds power
penalty, which some customers don't want. They want some way to enable/
disable dynamically.

So, add an additional attribute "energy_efficiency_enable" under /sys/devices/system/cpu/intel_pstate/ for these CPU models. This allows
to read and write bit 19 ("Disable Energy Efficiency Optimization") in
the MSR IA32_POWER_CTL.

[...]

Quoted 6 lines
Quoted 3 lines

+``energy_efficiency_enable``

(quoted diff) +1 -0
+	This attribute is only present on platforms, which has CPUs

matching

which have

Thanks, I will fix that.

Quoted 11 lines

Documentation/admin-guide/pm/intel_pstate.rst argument is passed to the kernel in the command line. · line 441

Quoted 9 lines
(quoted diff) +2 -0
+	Kaby Lake or Coffee Lake desktop CPU model. By default
+	"energy_efficiency" is disabled on these CPU models in HWP mode

by this

(quoted diff) +2 -0
+	driver. Enabling energy efficiency may limit maximum operating
+	frequency in both HWP and non HWP mode. In non HWP mode, this

attribute

(quoted diff) +1 -0
+	has an effect in turbo range only. But in HWP mode, this

attribute also

Documentation/admin-guide/pm/intel_pstate.rst +1 -0
+	has an effect in non turbo range.

Those last two sentences could be simplified - read strange.

I will try to address this.

[...]

Quoted 9 lines

arch/x86/include/asm/msr-index.h line 257

Quoted 5 lines
arch/x86/include/asm/msr-index.h +1 -0
@@ -254,6 +254,7 @@
 #define MSR_PEBS_FRONTEND		0x000003f7
 
 #define MSR_IA32_POWER_CTL		0x000001fc
+#define MSR_IA32_POWER_CTL_BIT_EE	19

Sort that MSR in - I know, the rest is not sorted either but we can start somewhere. So pls put it...

I will.

Quoted 6 lines

#define MSR_LBR_SELECT 0x000001c8
#define MSR_LBR_TOS 0x000001c9

<--- here.

[...]

Quoted 11 lines
Quoted 4 lines
drivers/cpufreq/intel_pstate.c +3 -0
+
+	rdmsrl(MSR_IA32_POWER_CTL, power_ctl);
+	enable = (power_ctl & BIT(MSR_IA32_POWER_CTL_BIT_EE)) >>

MSR_IA32_POWER_CTL_BIT_EE;

So you can simplify to:

	enable = !!(power_ctl & BIT(MSR_IA32_POWER_CTL_BIT_EE));

methinks.

Better.

Quoted 10 lines

drivers/cpufreq/intel_pstate.c static ssize_t store_hwp_dynamic_boost(struct kobject *a, · line 1230

Quoted 1 line
drivers/cpufreq/intel_pstate.c +1 -0
+	return sprintf(buf, "%d\n", !enable);

If this bit is called

"Disable Energy Efficiency Optimization"

why do you call your function and sysfs file "enable"? This is making it
more confusing.

Quoted 6 lines

Why don't you call it simply: "energy_efficiency" and have it intuitive:

1 - enabled
0 - disabled

I think your suggestion is good. The one other attributes under this directory has similar style. I will get rid of "_enable".

Quoted 13 lines

?

Quoted 11 lines
drivers/cpufreq/intel_pstate.c +3 -0
+static ssize_t store_energy_efficiency_enable(struct kobject *a,
+					      struct kobj_attribute *b,
+					      const char *buf, size_t

count)

drivers/cpufreq/intel_pstate.c +7 -0
+{
+	u64 power_ctl;
+	u32 input;
+	int ret;
+
+	ret = kstrtouint(buf, 10, &input);
+	if (ret)
Quoted 9 lines

drivers/cpufreq/intel_pstate.c static ssize_t store_hwp_dynamic_boost(struct kobject *a, · line 1247

Quoted 5 lines
drivers/cpufreq/intel_pstate.c +5 -0
+		return ret;
+
+	mutex_lock(&intel_pstate_driver_lock);
+	rdmsrl(MSR_IA32_POWER_CTL, power_ctl);
+	if (input)

This is too lax - it will be enabled for any !0 value. Please accept only 0 and 1.

OK.

Thanks for the review.

- Srinivas

#3 lore raw
In reply to Borislav Petkov
Quoted 11 lines · Borislav Petkov
Quoted 10 lines · Srinivas Pandruvada
drivers/cpufreq/intel_pstate.c +10 -0
+static ssize_t store_energy_efficiency_enable(struct kobject *a,
+					      struct kobj_attribute *b,
+					      const char *buf, size_t count)
+{
+	u64 power_ctl;
+	u32 input;
+	int ret;
+
+	ret = kstrtouint(buf, 10, &input);
+	if (ret)
Quoted 8 lines

drivers/cpufreq/intel_pstate.c static ssize_t store_hwp_dynamic_boost(struct kobject *a, · line 1247

Quoted 5 lines
drivers/cpufreq/intel_pstate.c +5 -0
+		return ret;
+
+	mutex_lock(&intel_pstate_driver_lock);
+	rdmsrl(MSR_IA32_POWER_CTL, power_ctl);
+	if (input)

This is too lax - it will be enabled for any !0 value. Please accept only 0 and 1.

kstrtobool() ftw

#4 lore raw

PATCH 1/1 lib: Extend kstrtobool() to accept "true"/"false"

Quoted 4 lines · Peter Zijlstra
Quoted 2 lines

This is too lax - it will be enabled for any !0 value. Please accept only 0 and 1.

kstrtobool() ftw

And looking at that, I find it really strange it does not in fact accept "true" / "false", so how about this?

---
Subject: lib: Extend kstrtobool() to accept "true"/"false"

Extend the strings recognised by kstrtobool() to cover:

- 1/0
- y/n
- yes/no (new)
- t/f (new)
- true/false (new)
- on/off

---
 lib/kstrtox.c | 60 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 15 deletions(-)
lib/kstrtox.c +45 -15
index 1006bf70bf74..b8b950325097 100644
@@ -325,9 +325,17 @@ EXPORT_SYMBOL(kstrtos8);
  * @s: input string
  * @res: result
  *
- * This routine returns 0 iff the first character is one of 'Yy1Nn0', or
- * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL.  Value
- * pointed to by res is updated upon finding a match.
+ * This return return 0 on success, otherwise it will return -EINVAL.
+ * It will accept (case invariant):
+ *
+ *  - 1/0
+ *  - y/n
+ *  - yes/no
+ *  - t/f
+ *  - true/false
+ *  - on/off
+ *
+ * and set @*res to either true/false respectively.
  */
 int kstrtobool(const char *s, bool *res)
 {
@@ -335,30 +343,52 @@ int kstrtobool(const char *s, bool *res)
 		return -EINVAL;
 
 	switch (s[0]) {
+	case 't':
+	case 'T':
+		if (!s[1] || !strcasecmp(s, "true"))
+			goto have_true;
+
+		break;
+
 	case 'y':
 	case 'Y':
+		if (!s[1] || !strcasecmp(s, "yes"))
+			goto have_true;
+
+		break;
+
 	case '1':
+have_true:
 		*res = true;
 		return 0;
+
+	case 'f':
+	case 'F':
+		if (!s[1] || !strcasecmp(s, "false"))
+			goto have_false;
+
+		break;
 	case 'n':
 	case 'N':
+		if (!s[1] || !strcasecmp(s, "no"))
+			goto have_false;
+
+		break;
 	case '0':
+have_false:
 		*res = false;
 		return 0;
+
 	case 'o':
 	case 'O':
-		switch (s[1]) {
-		case 'n':
-		case 'N':
-			*res = true;
-			return 0;
-		case 'f':
-		case 'F':
-			*res = false;
-			return 0;
-		default:
-			break;
-		}
+		if (!strcasecmp(s, "on"))
+			goto have_true;
+
+		if (!strcasecmp(s, "off"))
+			goto have_false;
+
+		break;
+
 	default:
 		break;
 	}
author maintainer
#5 lore raw

Re: [PATCH] lib: Extend kstrtobool() to accept "true"/"false"

Quoted 11 lines · Peter Zijlstra
Quoted 5 lines · Peter Zijlstra
Quoted 3 lines

This is too lax - it will be enabled for any !0 value. Please accept
only 0 and 1.

kstrtobool() ftw

And looking at that, I find it really strange it does not in fact accept
"true" / "false", so how about this?

looks good.

Thanks,
Srinvas

Quoted 112 lines

---
Subject: lib: Extend kstrtobool() to accept "true"/"false"

Extend the strings recognised by kstrtobool() to cover:

- 1/0
- y/n
- yes/no (new)
- t/f (new)
- true/false (new)
- on/off

---
 lib/kstrtox.c | 60 ++++++++++++++++++++++++++++++++++++++++++++-----
----------
 1 file changed, 45 insertions(+), 15 deletions(-)
lib/kstrtox.c +0 -1
index 1006bf70bf74..b8b950325097 100644
@@ -325,9 +325,17 @@ EXPORT_SYMBOL(kstrtos8);
  * @s: input string
  * @res: result
  *
- * This routine returns 0 iff the first character is one of

'Yy1Nn0', or
- * [oO][NnFf] for "on" and "off". Otherwise it will return

lib/kstrtox.c +45 -15
-EINVAL.  Value
- * pointed to by res is updated upon finding a match.
+ * This return return 0 on success, otherwise it will return
-EINVAL.
+ * It will accept (case invariant):
+ *
+ *  - 1/0
+ *  - y/n
+ *  - yes/no
+ *  - t/f
+ *  - true/false
+ *  - on/off
+ *
+ * and set @*res to either true/false respectively.
  */
 int kstrtobool(const char *s, bool *res)
 {
@@ -335,30 +343,52 @@ int kstrtobool(const char *s, bool *res)
 		return -EINVAL;
 
 	switch (s[0]) {
+	case 't':
+	case 'T':
+		if (!s[1] || !strcasecmp(s, "true"))
+			goto have_true;
+
+		break;
+
 	case 'y':
 	case 'Y':
+		if (!s[1] || !strcasecmp(s, "yes"))
+			goto have_true;
+
+		break;
+
 	case '1':
+have_true:
 		*res = true;
 		return 0;
+
+	case 'f':
+	case 'F':
+		if (!s[1] || !strcasecmp(s, "false"))
+			goto have_false;
+
+		break;
 	case 'n':
 	case 'N':
+		if (!s[1] || !strcasecmp(s, "no"))
+			goto have_false;
+
+		break;
 	case '0':
+have_false:
 		*res = false;
 		return 0;
+
 	case 'o':
 	case 'O':
-		switch (s[1]) {
-		case 'n':
-		case 'N':
-			*res = true;
-			return 0;
-		case 'f':
-		case 'F':
-			*res = false;
-			return 0;
-		default:
-			break;
-		}
+		if (!strcasecmp(s, "on"))
+			goto have_true;
+
+		if (!strcasecmp(s, "off"))
+			goto have_false;
+
+		break;
+
 	default:
 		break;
 	}
maintainer Reviewed-by on v1 1/1
#6 lore raw

Re: [PATCH] lib: Extend kstrtobool() to accept "true"/"false"

In reply to Peter Zijlstra
Quoted 16 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines

This is too lax - it will be enabled for any !0 value. Please accept only 0 and 1.

kstrtobool() ftw

And looking at that, I find it really strange it does not in fact accept "true" / "false", so how about this?

---
Subject: lib: Extend kstrtobool() to accept "true"/"false"

Extend the strings recognised by kstrtobool() to cover:

Quoted 8 lines

- 1/0
- y/n

  - yes/no      (new)
  - t/f         (new)
  - true/false  (new)

- on/off

Quoted 94 lines
---
 lib/kstrtox.c | 60 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 15 deletions(-)
lib/kstrtox.c +45 -15
index 1006bf70bf74..b8b950325097 100644
@@ -325,9 +325,17 @@ EXPORT_SYMBOL(kstrtos8);
  * @s: input string
  * @res: result
  *
- * This routine returns 0 iff the first character is one of 'Yy1Nn0', or
- * [oO][NnFf] for "on" and "off". Otherwise it will return -EINVAL.  Value
- * pointed to by res is updated upon finding a match.
+ * This return return 0 on success, otherwise it will return -EINVAL.
+ * It will accept (case invariant):
+ *
+ *  - 1/0
+ *  - y/n
+ *  - yes/no
+ *  - t/f
+ *  - true/false
+ *  - on/off
+ *
+ * and set @*res to either true/false respectively.
  */
 int kstrtobool(const char *s, bool *res)
 {
@@ -335,30 +343,52 @@ int kstrtobool(const char *s, bool *res)
                return -EINVAL;
 
        switch (s[0]) {
+       case 't':
+       case 'T':
+               if (!s[1] || !strcasecmp(s, "true"))
+                       goto have_true;
+
+               break;
+
        case 'y':
        case 'Y':
+               if (!s[1] || !strcasecmp(s, "yes"))
+                       goto have_true;
+
+               break;
+
        case '1':
+have_true:
                *res = true;
                return 0;
+
+       case 'f':
+       case 'F':
+               if (!s[1] || !strcasecmp(s, "false"))
+                       goto have_false;
+
+               break;
        case 'n':
        case 'N':
+               if (!s[1] || !strcasecmp(s, "no"))
+                       goto have_false;
+
+               break;
        case '0':
+have_false:
                *res = false;
                return 0;
+
        case 'o':
        case 'O':
-               switch (s[1]) {
-               case 'n':
-               case 'N':
-                       *res = true;
-                       return 0;
-               case 'f':
-               case 'F':
-                       *res = false;
-                       return 0;
-               default:
-                       break;
-               }
+               if (!strcasecmp(s, "on"))
+                       goto have_true;
+
+               if (!strcasecmp(s, "off"))
+                       goto have_false;
+
+               break;
+
        default:
                break;
        }
Reviewed-by on v1 1/1
#7 lore raw

Re: [PATCH] lib: Extend kstrtobool() to accept "true"/"false"

In reply to Peter Zijlstra
Quoted 15 lines · Peter Zijlstra
Quoted 4 lines · Peter Zijlstra
Quoted 2 lines

This is too lax - it will be enabled for any !0 value. Please accept only 0 and 1.

kstrtobool() ftw

And looking at that, I find it really strange it does not in fact accept "true" / "false", so how about this?

---
Subject: lib: Extend kstrtobool() to accept "true"/"false"

Extend the strings recognised by kstrtobool() to cover:

Quoted 8 lines

- 1/0
- y/n
- yes/no (new)
- t/f (new)
- true/false (new)
- on/off

There were some worries about dealing with unterminated strings when I did the original conversion[1], but I think those all got fixed.

[1] https://lore.kernel.org/lkml/CAGXu5jJrFv5Y8Q_i3yFYBDmT0+pO05dS3ijB0gOn-huasxZWmA@mail.gmail.com/

Signature · 1 line
Kees Cook
#8 lore raw

Re: [PATCH] lib: Extend kstrtobool() to accept "true"/"false"

In reply to Peter Zijlstra

Hi!

Quoted 11 lines
Quoted 4 lines
Quoted 2 lines

This is too lax - it will be enabled for any !0 value. Please accept only 0 and 1.

kstrtobool() ftw

And looking at that, I find it really strange it does not in fact accept "true" / "false", so how about this?

---
Subject: lib: Extend kstrtobool() to accept "true"/"false"

Quoted 8 lines

Extend the strings recognised by kstrtobool() to cover:

- 1/0
- y/n
- yes/no (new)
- t/f (new)
- true/false (new)
- on/off

Is it good idea to add more values there? It is easy to do, but... we don't want people to use this by hand, and ideally everyone would just use 1/0...

I also see potential for confusion... as in echo off > enable_off_mode (ok, this is with existing code, but...)

Plus, if programs learn to do "echo true > ..." they will stop working on older kernels.

Plus, this really should be documented somewhere, as it is kernel ABI.

IMO this does not need changing.

NAK.

Best regards,
Pavel

(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

maintainer
#9 lore raw

Re: [PATCH] lib: Extend kstrtobool() to accept "true"/"false"

Quoted 9 lines · On Mon, 29 Jun 2020 14:09:38 +0200 Pavel Machek <[email protected]> wrote:
Quoted 8 lines

Extend the strings recognised by kstrtobool() to cover:

- 1/0
- y/n
- yes/no (new)
- t/f (new)
- true/false (new)
- on/off

Quoted 7 lines

Is it good idea to add more values there? It is easy to do, but... we don't want people to use this by hand, and ideally everyone would just use 1/0...

I also see potential for confusion... as in echo off > enable_off_mode (ok, this is with existing code, but...)

Plus, if programs learn to do "echo true > ..." they will stop working on older kernels.

I'm inclined to agree with this, It is indeed an invitation to write non-back-compatible userspace and it simply makes the kernel interface more complex.