Skip to contentSkip to conversation

x86/resctrl: Enable user to view and select thread throttling mode

PATCH Superseded Reinette Chatre 3 participants 8 messages Apr 1, 2020 – Apr 3, 2020

Subsystems (3)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Reinette Chatre

author maintainer
#0 lore raw

cover x86/resctrl: Enable user to view and select thread throttling mode

The first patch in this series introduces a new resctrl file, "thread_throttle_mode", on Intel systems that exposes to the user how per-thread values are allocated to a core. This is added in support of newer Intel systems that can be configured to allocate either maximum or minimum throttling of the per-thread CLOS values to the core.

Details about the feature can be found in the commit description and in Chapter 9 of the most recent Intel ISE available from
https://software.intel.com/sites/default/files/managed/c5/15/architecture-instruction-set-extensions-programming-reference.pdf

The first patch parses user input with the appropriate sysfs API that has not previously been used in resctrl. The second patch is added as a subsequent cleanup that switches existing resctrl string parsing code to also use this appropriate API.

Reinette Chatre (2):
x86/resctrl: Enable user to view and select thread throttling mode x86/resctrl: Use appropriate API for strings terminated by newline

 Documentation/x86/resctrl_ui.rst       |  21 ++-
 arch/x86/kernel/cpu/resctrl/core.c     |  29 ++++
 arch/x86/kernel/cpu/resctrl/internal.h |   9 +
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 221 +++++++++++++++++++++++--
 4 files changed, 266 insertions(+), 14 deletions(-)
Signature · 1 line
2.21.0
author maintainer
#1 lore raw

PATCH 1/2 x86/resctrl: Enable user to view and select thread throttling mode

Intel Memory Bandwidth Allocation (MBA) control is provided per processor core. At the same time different CLOS, configured with different bandwidth percentages, can be assigned to the hardware threads sharing a core. In the original implementation of MBA the maximum throttling of the per-thread CLOS is allocated to the core. Specifically, the lower bandwidth percentage is allocated to the core.

Newer systems can be configured to allocate either maximum or minimum throttling of the per-thread CLOS values to the core.

Introduce a new resctrl file, "thread_throttle_mode", on Intel systems that exposes to the user how per-thread values are allocated to a core. On systems that support the original MBA implementation the file will always display "max". On systems that can be configured the possible values are "min" or "max" that the user can modify by writing these same words to the file.

---
 Documentation/x86/resctrl_ui.rst       |  21 ++-
 arch/x86/kernel/cpu/resctrl/core.c     |  29 ++++
 arch/x86/kernel/cpu/resctrl/internal.h |   9 ++
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 196 +++++++++++++++++++++++++
 4 files changed, 253 insertions(+), 2 deletions(-)
Documentation/x86/resctrl_ui.rst +19 -2
index 5368cedfb530..c9888d530c8d 100644
@@ -138,6 +138,21 @@ with respect to allocation:
 		non-linear. This field is purely informational
 		only.
 
+"thread_throttle_mode":
+		The memory bandwidth control applied to a core when
+		control is provided per core but each hardware
+		thread can be assigned a unique CLOSID.
+		"thread_throttle_mode" displays how the bandwidth
+		percentage allocated to the core is selected:
+		either "max" or "min" throttling of the bandwidth
+		percentages of the per-thread CLOS. Specifically, when
+		throttling is "max" then the lowest bandwidth percentage
+		is allocated to the core and when throttling is "min"
+		then the highest bandwidth percentage is allocated to
+		the core.
+		Configurable on systems that support both modes by
+		writing "min" or "max" to the file.
+
 If RDT monitoring is available there will be an "L3_MON" directory
 with the following files:
 
@@ -364,8 +379,10 @@ to the next control step available on the hardware.
 
 The bandwidth throttling is a core specific mechanism on some of Intel
 SKUs. Using a high bandwidth and a low bandwidth setting on two threads
-sharing a core will result in both threads being throttled to use the
-low bandwidth. The fact that Memory bandwidth allocation(MBA) is a core
+sharing a core may result in both threads being throttled to use the
+low bandwidth (see "thread_throttle_mode").
+
+The fact that Memory bandwidth allocation(MBA) may be a core
 specific mechanism where as memory bandwidth monitoring(MBM) is done at
 the package level may lead to confusion when users try to apply control
 via the MBA and then monitor the bandwidth to see if the controls are
arch/x86/kernel/cpu/resctrl/core.c +29 -0
index 89049b343c7a..00c8a948fe2e 100644
@@ -250,6 +250,30 @@ static inline bool rdt_get_mb_table(struct rdt_resource *r)
 	return false;
 }
 
+/*
+ * Model-specific test to determine if platform where memory bandwidth
+ * control is applied to a core can be configured to apply either the
+ * maximum or minimum of the per-thread delay values.
+ * By default, platforms where memory bandwidth control is applied to a
+ * core will select the maximum delay value of the per-thread CLOS.
+ *
+ * NOTE: delay value programmed to hardware is inverse of bandwidth
+ * percentage configured via user interface.
+ */
+bool mba_cfg_supports_min_max_intel(void)
+{
+	switch (boot_cpu_data.x86_model) {
+	case INTEL_FAM6_ATOM_TREMONT_D:
+	case INTEL_FAM6_ICELAKE_X:
+	case INTEL_FAM6_ICELAKE_D:
+		return true;
+	default:
+		return false;
+	}
+
+	return false;
+}
+
 static bool __get_mem_config_intel(struct rdt_resource *r)
 {
 	union cpuid_0x10_3_eax eax;
@@ -270,6 +294,11 @@ static bool __get_mem_config_intel(struct rdt_resource *r)
 	}
 	r->data_width = 3;
 
+	if (mba_cfg_supports_min_max_intel())
+		thread_throttle_mode_init_intel_rw();
+	else
+		thread_throttle_mode_init_intel_ro();
+
 	r->alloc_capable = true;
 	r->alloc_enabled = true;
 
arch/x86/kernel/cpu/resctrl/internal.h +9 -0
index 3a16d1c0ff40..a7b63b948ce8 100644
@@ -9,6 +9,7 @@
 
 #define MSR_IA32_L3_QOS_CFG		0xc81
 #define MSR_IA32_L2_QOS_CFG		0xc82
+#define MSR_MBA_CFG			0xc84
 #define MSR_IA32_L3_CBM_BASE		0xc90
 #define MSR_IA32_L2_CBM_BASE		0xd10
 #define MSR_IA32_MBA_THRTL_BASE		0xd50
@@ -21,6 +22,8 @@
 
 #define L2_QOS_CDP_ENABLE		0x01ULL
 
+#define MBA_THROTTLE_MODE_MIN		0x01ULL
+
 /*
  * Event IDs are used to program IA32_QM_EVTSEL before reading event
  * counter from IA32_QM_CTR
@@ -38,6 +41,8 @@
 #define MBA_MAX_MBPS			U32_MAX
 #define MAX_MBA_BW_AMD			0x800
 
+#define MBA_THREAD_THROTTLE_MODE	BIT_ULL(0)
+
 #define RMID_VAL_ERROR			BIT_ULL(63)
 #define RMID_VAL_UNAVAIL		BIT_ULL(62)
 /*
@@ -241,6 +246,7 @@ struct rdtgroup {
 #define RF_MON_INFO			(RFTYPE_INFO | RFTYPE_MON)
 #define RF_TOP_INFO			(RFTYPE_INFO | RFTYPE_TOP)
 #define RF_CTRL_BASE			(RFTYPE_BASE | RFTYPE_CTRL)
+#define RF_UNINITIALIZED		ULONG_MAX
 
 /* List of all resource groups */
 extern struct list_head rdt_all_groups;
@@ -610,5 +616,8 @@ bool has_busy_rmid(struct rdt_resource *r, struct rdt_domain *d);
 void __check_limbo(struct rdt_domain *d, bool force_free);
 bool cbm_validate_intel(char *buf, u32 *data, struct rdt_resource *r);
 bool cbm_validate_amd(char *buf, u32 *data, struct rdt_resource *r);
+bool mba_cfg_supports_min_max_intel(void);
+void thread_throttle_mode_init_intel_rw(void);
+void thread_throttle_mode_init_intel_ro(void);
 
 #endif /* _ASM_X86_RESCTRL_INTERNAL_H */
arch/x86/kernel/cpu/resctrl/rdtgroup.c +196 -0

220 lines not on this page · raw message

Signature · 1 line
2.21.0
author maintainer
#2 lore raw

PATCH 2/2 x86/resctrl: Use appropriate API for strings terminated by newline

In reply to Reinette Chatre

The user input to files in the resctrl filesystem are expected to be terminated with a newline. Testing the user input includes a test for the presence of a newline and then replacing the newline with NUL byte followed by comparison using strcmp().

sysfs_streq() exists to test if strings are equal, treating both NUL and newline-then-NUL as equivalent string terminations. Even more, sysfs_match_string() exists to match a given string in an array using sysfs_streq().

Replace existing strcmp() comparisons of strings that are terminated with a newline with more appropriate sysfs_streq() via the sysfs_match_string() API that can perform the match across the different mode strings that are already maintained in an array.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +13 -12
index fbee891a7d6e..623e33c0a290 100644
@@ -1412,11 +1412,11 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 	struct rdtgroup *rdtgrp;
 	enum rdtgrp_mode mode;
 	int ret = 0;
+	int user_m;
 
 	/* Valid input requires a trailing newline */
 	if (nbytes == 0 || buf[nbytes - 1] != '\n')
 		return -EINVAL;
-	buf[nbytes - 1] = '\0';
 
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
@@ -1428,11 +1428,15 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 
 	mode = rdtgrp->mode;
 
-	if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) ||
-	    (!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE) ||
-	    (!strcmp(buf, "pseudo-locksetup") &&
-	     mode == RDT_MODE_PSEUDO_LOCKSETUP) ||
-	    (!strcmp(buf, "pseudo-locked") && mode == RDT_MODE_PSEUDO_LOCKED))
+	user_m = sysfs_match_string(rdt_mode_str, buf);
+	if (user_m < 0) {
+		rdt_last_cmd_puts("Unknown or unsupported mode\n");
+		ret = user_m;
+		goto out;
+	}
+
+	/* Do nothing and return success if user asks for current mode */
+	if (user_m == mode)
 		goto out;
 
 	if (mode == RDT_MODE_PSEUDO_LOCKED) {
@@ -1441,14 +1445,14 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 		goto out;
 	}
 
-	if (!strcmp(buf, "shareable")) {
+	if (user_m == RDT_MODE_SHAREABLE) {
 		if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
 			ret = rdtgroup_locksetup_exit(rdtgrp);
 			if (ret)
 				goto out;
 		}
 		rdtgrp->mode = RDT_MODE_SHAREABLE;
-	} else if (!strcmp(buf, "exclusive")) {
+	} else if (user_m == RDT_MODE_EXCLUSIVE) {
 		if (!rdtgroup_mode_test_exclusive(rdtgrp)) {
 			ret = -EINVAL;
 			goto out;
@@ -1459,14 +1463,11 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 				goto out;
 		}
 		rdtgrp->mode = RDT_MODE_EXCLUSIVE;
-	} else if (!strcmp(buf, "pseudo-locksetup")) {
+	} else if (user_m == RDT_MODE_PSEUDO_LOCKSETUP) {
 		ret = rdtgroup_locksetup_enter(rdtgrp);
 		if (ret)
 			goto out;
 		rdtgrp->mode = RDT_MODE_PSEUDO_LOCKSETUP;
-	} else {
-		rdt_last_cmd_puts("Unknown or unsupported mode\n");
-		ret = -EINVAL;
 	}
 
 out:
Signature · 1 line
2.21.0
#3 lore raw

Re: [PATCH 2/2] x86/resctrl: Use appropriate API for strings terminated by newline

Quoted 26 lines · Reinette Chatre

The user input to files in the resctrl filesystem are expected to be terminated with a newline. Testing the user input includes a test for the presence of a newline and then replacing the newline with NUL byte followed by comparison using strcmp().

sysfs_streq() exists to test if strings are equal, treating both NUL and newline-then-NUL as equivalent string terminations. Even more, sysfs_match_string() exists to match a given string in an array using sysfs_streq().

Replace existing strcmp() comparisons of strings that are terminated with a newline with more appropriate sysfs_streq() via the sysfs_match_string() API that can perform the match across the different mode strings that are already maintained in an array.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index fbee891a7d6e..623e33c0a290 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1420

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -1
@@ -1412,11 +1412,11 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 	struct rdtgroup *rdtgrp;
 	enum rdtgrp_mode mode;
 	int ret = 0;
+	int user_m;
 
 
 	/* Valid input requires a trailing newline */
 	if (nbytes == 0 || buf[nbytes - 1] != '\n')
 		return -EINVAL;
-	buf[nbytes - 1] = '\0';

The above test is not needed and comment now is misleading. WRT nbytes I believe that kernel fs code checks for that.

Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -1
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
@@ -1428,11 +1428,15 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 
 	mode = rdtgrp->mode;
 
-	if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) ||

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1436

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -4
-	    (!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE) ||
-	    (!strcmp(buf, "pseudo-locksetup") &&
-	     mode == RDT_MODE_PSEUDO_LOCKSETUP) ||
-	    (!strcmp(buf, "pseudo-locked") && mode == RDT_MODE_PSEUDO_LOCKED))
+	user_m = sysfs_match_string(rdt_mode_str, buf);
+	if (user_m < 0) {
+		rdt_last_cmd_puts("Unknown or unsupported mode\n");
+		ret = user_m;
+		goto out;
+	}

You can do it the way

	ret = sysfs_match_string(...);
	if (ret < 0) {
		...
	}
	user_m = ret;
Quoted 41 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +5 -6
+	/* Do nothing and return success if user asks for current mode */
+	if (user_m == mode)
 		goto out;
 
 	if (mode == RDT_MODE_PSEUDO_LOCKED) {
@@ -1441,14 +1445,14 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 		goto out;
 	}
 
-	if (!strcmp(buf, "shareable")) {
+	if (user_m == RDT_MODE_SHAREABLE) {
 		if (rdtgrp->mode == RDT_MODE_PSEUDO_LOCKSETUP) {
 			ret = rdtgroup_locksetup_exit(rdtgrp);
 			if (ret)
 				goto out;
 		}
 		rdtgrp->mode = RDT_MODE_SHAREABLE;
-	} else if (!strcmp(buf, "exclusive")) {
+	} else if (user_m == RDT_MODE_EXCLUSIVE) {
 		if (!rdtgroup_mode_test_exclusive(rdtgrp)) {
 			ret = -EINVAL;
 			goto out;
@@ -1459,14 +1463,11 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 				goto out;
 		}
 		rdtgrp->mode = RDT_MODE_EXCLUSIVE;
-	} else if (!strcmp(buf, "pseudo-locksetup")) {
+	} else if (user_m == RDT_MODE_PSEUDO_LOCKSETUP) {
 		ret = rdtgroup_locksetup_enter(rdtgrp);
 		if (ret)
 			goto out;
 		rdtgrp->mode = RDT_MODE_PSEUDO_LOCKSETUP;
-	} else {
-		rdt_last_cmd_puts("Unknown or unsupported mode\n");
-		ret = -EINVAL;
 	}
 
 out:
Signature · 1 line
2.21.0
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw

Re: [PATCH 2/2] x86/resctrl: Use appropriate API for strings terminated by newline

Quoted 1 line · Andy Shevchenko

On Wed, Apr 01, 2020 at 11:30:48AM -0700, Reinette Chatre wrote:

...

Quoted 2 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1415

Quoted 2 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
 	int ret = 0;
+	int user_m;

...and forgot to mention this...

	int user_m;
	int ret;
Quoted 28 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1419

Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -1
 	/* Valid input requires a trailing newline */
 	if (nbytes == 0 || buf[nbytes - 1] != '\n')
 		return -EINVAL;
-	buf[nbytes - 1] = '\0';

The above test is not needed and comment now is misleading. WRT nbytes I believe that kernel fs code checks for that.

Quoted 7 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -1
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
@@ -1428,11 +1428,15 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 
 	mode = rdtgrp->mode;
 
-	if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) ||

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1436

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -4
-	    (!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE) ||
-	    (!strcmp(buf, "pseudo-locksetup") &&
-	     mode == RDT_MODE_PSEUDO_LOCKSETUP) ||
-	    (!strcmp(buf, "pseudo-locked") && mode == RDT_MODE_PSEUDO_LOCKED))
+	user_m = sysfs_match_string(rdt_mode_str, buf);
+	if (user_m < 0) {
+		rdt_last_cmd_puts("Unknown or unsupported mode\n");
+		ret = user_m;
+		goto out;
+	}

You can do it the way

Quoted 5 lines
	ret = sysfs_match_string(...);
	if (ret < 0) {
		...
	}
	user_m = ret;

...and this changes

	ret = 0;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#5 lore raw

Re: [PATCH 2/2] x86/resctrl: Use appropriate API for strings terminated by newline

In reply to Andy Shevchenko

Hi Andy,

(Your two responses have been merged)

Quoted 41 lines · Andy Shevchenko
Quoted 26 lines · Reinette Chatre

The user input to files in the resctrl filesystem are expected to be terminated with a newline. Testing the user input includes a test for the presence of a newline and then replacing the newline with NUL byte followed by comparison using strcmp().

sysfs_streq() exists to test if strings are equal, treating both NUL and newline-then-NUL as equivalent string terminations. Even more, sysfs_match_string() exists to match a given string in an array using sysfs_streq().

Replace existing strcmp() comparisons of strings that are terminated with a newline with more appropriate sysfs_streq() via the sysfs_match_string() API that can perform the match across the different mode strings that are already maintained in an array.

---
 arch/x86/kernel/cpu/resctrl/rdtgroup.c | 25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -0
index fbee891a7d6e..623e33c0a290 100644

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1416

Quoted 5 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -1412,11 +1412,11 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 	struct rdtgroup *rdtgrp;
 	enum rdtgrp_mode mode;
 	int ret = 0;
+	int user_m;
 

...and forgot to mention this...

	int user_m;
	int ret;
Quoted 7 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1419

Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -1
 	/* Valid input requires a trailing newline */
 	if (nbytes == 0 || buf[nbytes - 1] != '\n')
 		return -EINVAL;
-	buf[nbytes - 1] = '\0';

The above test is not needed and comment now is misleading. WRT nbytes I believe that kernel fs code checks for that.

If nbytes is 0 it is still passed to this function. You are correct that those tests are not needed though (if nbytes is 0 then sysfs_match_string() will not find a match and return EINVAL via that path).

Thank you for catching this. I'll remove those unnecessary checks.

Quoted 27 lines
Quoted 8 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -1
 	rdtgrp = rdtgroup_kn_lock_live(of->kn);
 	if (!rdtgrp) {
@@ -1428,11 +1428,15 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
 
 	mode = rdtgrp->mode;
 
-	if ((!strcmp(buf, "shareable") && mode == RDT_MODE_SHAREABLE) ||

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1436

Quoted 10 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +6 -4
-	    (!strcmp(buf, "exclusive") && mode == RDT_MODE_EXCLUSIVE) ||
-	    (!strcmp(buf, "pseudo-locksetup") &&
-	     mode == RDT_MODE_PSEUDO_LOCKSETUP) ||
-	    (!strcmp(buf, "pseudo-locked") && mode == RDT_MODE_PSEUDO_LOCKED))
+	user_m = sysfs_match_string(rdt_mode_str, buf);
+	if (user_m < 0) {
+		rdt_last_cmd_puts("Unknown or unsupported mode\n");
+		ret = user_m;
+		goto out;
+	}

You can do it the way

	ret = sysfs_match_string(...);
	if (ret < 0) {
		...
	}
	user_m = ret;
Quoted 5 lines

...and this changes

	ret = 0;

ok, I'll do it this way in the next version.

Thank you

Reinette

#6 lore raw

Re: [PATCH 2/2] x86/resctrl: Use appropriate API for strings terminated by newline

Quoted 2 lines · Reinette Chatre
Quoted 1 line · Andy Shevchenko

On Wed, Apr 01, 2020 at 11:30:48AM -0700, Reinette Chatre wrote:

...

Quoted 15 lines
Quoted 15 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1416

Quoted 6 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +1 -0
@@ -1412,11 +1412,11 @@ static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of,
     struct rdtgroup *rdtgrp;
     enum rdtgrp_mode mode;
     int ret = 0;
+    int user_m;
 

...and forgot to mention this...

      int user_m;
      int ret;
Quoted 7 lines
Quoted 7 lines

arch/x86/kernel/cpu/resctrl/rdtgroup.c static ssize_t rdtgroup_mode_write(struct kernfs_open_file *of, · line 1419

Quoted 4 lines
arch/x86/kernel/cpu/resctrl/rdtgroup.c +0 -1
     /* Valid input requires a trailing newline */
     if (nbytes == 0 || buf[nbytes - 1] != '\n')
             return -EINVAL;
-    buf[nbytes - 1] = '\0';

The above test is not needed and comment now is misleading. WRT nbytes I believe that kernel fs code checks for that.

This module provides it's own kernfs_ops...

Quoted 5 lines

If nbytes is 0 it is still passed to this function. You are correct that those tests are not needed though (if nbytes is 0 then sysfs_match_string() will not find a match and return EINVAL via that path).

Thank you for catching this. I'll remove those unnecessary checks.

...which means that nbytes == 0 is a valid check. Please keep it there. It will protect from unnecessary locking and loading CPU for nothing.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#7 lore raw

Re: [PATCH 2/2] x86/resctrl: Use appropriate API for strings terminated by newline

Hi Andy,

Quoted 4 lines · Andy Shevchenko
Quoted 2 lines · Reinette Chatre
Quoted 1 line · Andy Shevchenko

On Wed, Apr 01, 2020 at 11:30:48AM -0700, Reinette Chatre wrote:

...

Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
     /* Valid input requires a trailing newline */
     if (nbytes == 0 || buf[nbytes - 1] != '\n')
             return -EINVAL;

- buf[nbytes - 1] = '\0';

The above test is not needed and comment now is misleading. WRT nbytes I believe that kernel fs code checks for that.

This module provides it's own kernfs_ops...

Quoted 4 lines

If nbytes is 0 it is still passed to this function. You are correct that those tests are not needed though (if nbytes is 0 then sysfs_match_string() will not find a match and return EINVAL via that path).

Quoted 6 lines
Quoted 1 line

Thank you for catching this. I'll remove those unnecessary checks.

...which means that nbytes == 0 is a valid check. Please keep it there. It will protect from unnecessary locking and loading CPU for nothing.

Will do. Thank you.

Reinette