Skip to content

Commit c377dcf

Browse files
aeglKAGA-KOKO
authored andcommitted
x86/intel_rdt: Add diagnostics when writing the schemata file
Save helpful descriptions of what went wrong when writing a schemata file. Signed-off-by: Tony Luck <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Fenghua Yu <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Vikas Shivappa <[email protected]> Cc: Boris Petkov <[email protected]> Cc: Reinette Chatre <[email protected]> Link: https://lkml.kernel.org/r/9d6cef757dc88639c8ab47f1e7bc1b081a84bb88.1506382469.git.tony.luck@intel.com
1 parent 9b3a7fd commit c377dcf

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

arch/x86/kernel/cpu/intel_rdt_ctrlmondata.c

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,22 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
4242
/*
4343
* Only linear delay values is supported for current Intel SKUs.
4444
*/
45-
if (!r->membw.delay_linear)
45+
if (!r->membw.delay_linear) {
46+
rdt_last_cmd_puts("No support for non-linear MB domains\n");
4647
return false;
48+
}
4749

4850
ret = kstrtoul(buf, 10, &bw);
49-
if (ret)
51+
if (ret) {
52+
rdt_last_cmd_printf("Non-decimal digit in MB value %s\n", buf);
5053
return false;
54+
}
5155

52-
if (bw < r->membw.min_bw || bw > r->default_ctrl)
56+
if (bw < r->membw.min_bw || bw > r->default_ctrl) {
57+
rdt_last_cmd_printf("MB value %ld out of range [%d,%d]\n", bw,
58+
r->membw.min_bw, r->default_ctrl);
5359
return false;
60+
}
5461

5562
*data = roundup(bw, (unsigned long)r->membw.bw_gran);
5663
return true;
@@ -60,8 +67,10 @@ int parse_bw(char *buf, struct rdt_resource *r, struct rdt_domain *d)
6067
{
6168
unsigned long data;
6269

63-
if (d->have_new_ctrl)
70+
if (d->have_new_ctrl) {
71+
rdt_last_cmd_printf("duplicate domain %d\n", d->id);
6472
return -EINVAL;
73+
}
6574

6675
if (!bw_validate(buf, &data, r))
6776
return -EINVAL;
@@ -84,20 +93,29 @@ static bool cbm_validate(char *buf, unsigned long *data, struct rdt_resource *r)
8493
int ret;
8594

8695
ret = kstrtoul(buf, 16, &val);
87-
if (ret)
96+
if (ret) {
97+
rdt_last_cmd_printf("non-hex character in mask %s\n", buf);
8898
return false;
99+
}
89100

90-
if (val == 0 || val > r->default_ctrl)
101+
if (val == 0 || val > r->default_ctrl) {
102+
rdt_last_cmd_puts("mask out of range\n");
91103
return false;
104+
}
92105

93106
first_bit = find_first_bit(&val, cbm_len);
94107
zero_bit = find_next_zero_bit(&val, cbm_len, first_bit);
95108

96-
if (find_next_bit(&val, cbm_len, zero_bit) < cbm_len)
109+
if (find_next_bit(&val, cbm_len, zero_bit) < cbm_len) {
110+
rdt_last_cmd_printf("mask %lx has non-consecutive 1-bits\n", val);
97111
return false;
112+
}
98113

99-
if ((zero_bit - first_bit) < r->cache.min_cbm_bits)
114+
if ((zero_bit - first_bit) < r->cache.min_cbm_bits) {
115+
rdt_last_cmd_printf("Need at least %d bits in mask\n",
116+
r->cache.min_cbm_bits);
100117
return false;
118+
}
101119

102120
*data = val;
103121
return true;
@@ -111,8 +129,10 @@ int parse_cbm(char *buf, struct rdt_resource *r, struct rdt_domain *d)
111129
{
112130
unsigned long data;
113131

114-
if (d->have_new_ctrl)
132+
if (d->have_new_ctrl) {
133+
rdt_last_cmd_printf("duplicate domain %d\n", d->id);
115134
return -EINVAL;
135+
}
116136

117137
if(!cbm_validate(buf, &data, r))
118138
return -EINVAL;
@@ -139,8 +159,10 @@ static int parse_line(char *line, struct rdt_resource *r)
139159
return 0;
140160
dom = strsep(&line, ";");
141161
id = strsep(&dom, "=");
142-
if (!dom || kstrtoul(id, 10, &dom_id))
162+
if (!dom || kstrtoul(id, 10, &dom_id)) {
163+
rdt_last_cmd_puts("Missing '=' or non-numeric domain\n");
143164
return -EINVAL;
165+
}
144166
dom = strim(dom);
145167
list_for_each_entry(d, &r->domains, list) {
146168
if (d->id == dom_id) {
@@ -196,6 +218,7 @@ static int rdtgroup_parse_resource(char *resname, char *tok, int closid)
196218
if (!strcmp(resname, r->name) && closid < r->num_closid)
197219
return parse_line(tok, r);
198220
}
221+
rdt_last_cmd_printf("unknown/unsupported resource name '%s'\n", resname);
199222
return -EINVAL;
200223
}
201224

@@ -209,15 +232,18 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
209232
int closid, ret = 0;
210233

211234
/* Valid input requires a trailing newline */
212-
if (nbytes == 0 || buf[nbytes - 1] != '\n')
235+
if (nbytes == 0 || buf[nbytes - 1] != '\n') {
236+
seq_buf_puts(&last_cmd_status, "no trailing newline\n");
213237
return -EINVAL;
238+
}
214239
buf[nbytes - 1] = '\0';
215240

216241
rdtgrp = rdtgroup_kn_lock_live(of->kn);
217242
if (!rdtgrp) {
218243
rdtgroup_kn_unlock(of->kn);
219244
return -ENOENT;
220245
}
246+
rdt_last_cmd_clear();
221247

222248
closid = rdtgrp->closid;
223249

@@ -229,6 +255,7 @@ ssize_t rdtgroup_schemata_write(struct kernfs_open_file *of,
229255
while ((tok = strsep(&buf, "\n")) != NULL) {
230256
resname = strim(strsep(&tok, ":"));
231257
if (!tok) {
258+
rdt_last_cmd_puts("Missing ':'\n");
232259
ret = -EINVAL;
233260
goto out;
234261
}

0 commit comments

Comments
 (0)