linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/intel_rdt: Fix a silent failure when writing zero value schemata
@ 2017-11-10 19:16 Tony Luck
  2017-11-12  8:04 ` [tip:x86/cache] " tip-bot for Xiaochen Shen
  0 siblings, 1 reply; 2+ messages in thread
From: Tony Luck @ 2017-11-10 19:16 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Xiaochen Shen, Tony Luck, linux-kernel, Vikas Shivappa, Fenghua Yu

From: Xiaochen Shen <xiaochen.shen@intel.com>

When writing an invalid schemata with no domain values (e.g., "(L3|MB):"), we
get a silent failure.

There isn't a good reason to allow writing zero value, we'd better
return error and set diagnostics information in last_cmd_status.

1. Before the fix:
 # mkdir /sys/fs/resctrl/p1

 # echo "L3:" > /sys/fs/resctrl/p1/schemata
 (silent failure)
 # cat /sys/fs/resctrl/info/last_cmd_status
 ok

 # echo "MB:" > /sys/fs/resctrl/p1/schemata
 (silent failure)
 # cat /sys/fs/resctrl/info/last_cmd_status
 ok

2. After the fix:
 # mkdir /sys/fs/resctrl/p1

 # echo "L3:" > /sys/fs/resctrl/p1/schemata
 -bash: echo: write error: Invalid argument
 # cat /sys/fs/resctrl/info/last_cmd_status
 Missing 'L3' value

 # echo "MB:" > /sys/fs/resctrl/p1/schemata
 -bash: echo: write error: Invalid argument
 # cat /sys/fs/resctrl/info/last_cmd_status
 Missing 'MB' value

[ Tony: This is an unintended side effect of the patch earlier to allow
    the user to just write the value they want to change.
    While allowing user to specify less than all of the values, it also
    allows zero value. ]

Fixes: c4026b7b95a4 ("x86/intel_rdt: Implement "update" mode when writing schemata file")
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
---
[apply to TIP x86/cache]

 arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
index 30aeb267cbd2..23e1d5c249c6 100644
--- a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
+++ b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
@@ -257,6 +257,11 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 			ret = -EINVAL;
 			goto out;
 		}
+		if (tok[0] == '\0') {
+			rdt_last_cmd_printf("Missing '%s' value\n", resname);
+			ret = -EINVAL;
+			goto out;
+		}
 		ret = rdtgroup_parse_resource(resname, tok, closid);
 		if (ret)
 			goto out;
-- 
2.14.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [tip:x86/cache] x86/intel_rdt: Fix a silent failure when writing zero value schemata
  2017-11-10 19:16 [PATCH] x86/intel_rdt: Fix a silent failure when writing zero value schemata Tony Luck
@ 2017-11-12  8:04 ` tip-bot for Xiaochen Shen
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot for Xiaochen Shen @ 2017-11-12  8:04 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tony.luck, xiaochen.shen, fenghua.yu, hpa, tglx, vikas.shivappa,
	linux-kernel, mingo

Commit-ID:  2244645ab194fe45ffcbaa08f235c8f0c7fb54fc
Gitweb:     https://git.kernel.org/tip/2244645ab194fe45ffcbaa08f235c8f0c7fb54fc
Author:     Xiaochen Shen <xiaochen.shen@intel.com>
AuthorDate: Fri, 10 Nov 2017 11:16:24 -0800
Committer:  Thomas Gleixner <tglx@linutronix.de>
CommitDate: Sun, 12 Nov 2017 09:01:40 +0100

x86/intel_rdt: Fix a silent failure when writing zero value schemata

Writing an invalid schemata with no domain values (e.g., "(L3|MB):"),
results in a silent failure, i.e. the last_cmd_status returns OK,

Check for an empty value and set the result string with a proper error
message and return -EINVAL.

Before the fix:
 # mkdir /sys/fs/resctrl/p1

 # echo "L3:" > /sys/fs/resctrl/p1/schemata
 (silent failure)
 # cat /sys/fs/resctrl/info/last_cmd_status
 ok

 # echo "MB:" > /sys/fs/resctrl/p1/schemata
 (silent failure)
 # cat /sys/fs/resctrl/info/last_cmd_status
 ok

After the fix:
 # mkdir /sys/fs/resctrl/p1

 # echo "L3:" > /sys/fs/resctrl/p1/schemata
 -bash: echo: write error: Invalid argument
 # cat /sys/fs/resctrl/info/last_cmd_status
 Missing 'L3' value

 # echo "MB:" > /sys/fs/resctrl/p1/schemata
 -bash: echo: write error: Invalid argument
 # cat /sys/fs/resctrl/info/last_cmd_status
 Missing 'MB' value

[ Tony: This is an unintended side effect of the patch earlier to allow the
    	user to just write the value they want to change.  While allowing
    	user to specify less than all of the values, it also allows an
    	empty value. ]

Fixes: c4026b7b95a4 ("x86/intel_rdt: Implement "update" mode when writing schemata file")
Signed-off-by: Xiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Vikas Shivappa <vikas.shivappa@linux.intel.com>
Cc: Fenghua Yu <fenghua.yu@intel.com>
Link: https://lkml.kernel.org/r/20171110191624.20280-1-tony.luck@intel.com

---
 arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
index 30aeb26..23e1d5c 100644
--- a/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
+++ b/arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c
@@ -257,6 +257,11 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
 			ret = -EINVAL;
 			goto out;
 		}
+		if (tok[0] == '\0') {
+			rdt_last_cmd_printf("Missing '%s' value\n", resname);
+			ret = -EINVAL;
+			goto out;
+		}
 		ret = rdtgroup_parse_resource(resname, tok, closid);
 		if (ret)
 			goto out;

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-11-12  8:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-10 19:16 [PATCH] x86/intel_rdt: Fix a silent failure when writing zero value schemata Tony Luck
2017-11-12  8:04 ` [tip:x86/cache] " tip-bot for Xiaochen Shen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).