Commit 753694a8 authored by Xiaochen Shen's avatar Xiaochen Shen Committed by Thomas Gleixner

x86/intel_rdt: Fix data type in parsing callbacks

Each resource is associated with a parsing callback to parse the data
provided from user space when writing schemata file.

The 'data' parameter in the callbacks is defined as a void pointer which
is error prone due to lack of type check.

parse_bw() processes the 'data' parameter as a string while its caller
actually passes the parameter as a pointer to struct rdt_cbm_parse_data.
Thus, parse_bw() takes wrong data and causes failure of parsing MBA
throttle value.

To fix the issue, the 'data' parameter in all parsing callbacks is defined
and handled as a pointer to struct rdt_parse_data (renamed from struct
rdt_cbm_parse_data).

Fixes: 7604df6e ("x86/intel_rdt: Support flexible data to parsing callbacks")
Fixes: 9ab9aa15 ("x86/intel_rdt: Ensure requested schemata respects mode")
Signed-off-by: default avatarXiaochen Shen <xiaochen.shen@intel.com>
Signed-off-by: default avatarReinette Chatre <reinette.chatre@intel.com>
Signed-off-by: default avatarFenghua Yu <fenghua.yu@intel.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Cc: "H Peter Anvin" <hpa@zytor.com>
Cc: "Tony Luck" <tony.luck@intel.com>
Cc: "Chen Yu" <yu.c.chen@intel.com>
Link: https://lkml.kernel.org/r/1537048707-76280-2-git-send-email-fenghua.yu@intel.com
parent 6a1cac56
...@@ -382,6 +382,11 @@ static inline bool is_mbm_event(int e) ...@@ -382,6 +382,11 @@ static inline bool is_mbm_event(int e)
e <= QOS_L3_MBM_LOCAL_EVENT_ID); e <= QOS_L3_MBM_LOCAL_EVENT_ID);
} }
struct rdt_parse_data {
struct rdtgroup *rdtgrp;
char *buf;
};
/** /**
* struct rdt_resource - attributes of an RDT resource * struct rdt_resource - attributes of an RDT resource
* @rid: The index of the resource * @rid: The index of the resource
...@@ -423,7 +428,8 @@ struct rdt_resource { ...@@ -423,7 +428,8 @@ struct rdt_resource {
struct rdt_cache cache; struct rdt_cache cache;
struct rdt_membw membw; struct rdt_membw membw;
const char *format_str; const char *format_str;
int (*parse_ctrlval) (void *data, struct rdt_resource *r, int (*parse_ctrlval)(struct rdt_parse_data *data,
struct rdt_resource *r,
struct rdt_domain *d); struct rdt_domain *d);
struct list_head evt_list; struct list_head evt_list;
int num_rmid; int num_rmid;
...@@ -431,8 +437,10 @@ struct rdt_resource { ...@@ -431,8 +437,10 @@ struct rdt_resource {
unsigned long fflags; unsigned long fflags;
}; };
int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d); int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
int parse_bw(void *_buf, struct rdt_resource *r, struct rdt_domain *d); struct rdt_domain *d);
int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r,
struct rdt_domain *d);
extern struct mutex rdtgroup_mutex; extern struct mutex rdtgroup_mutex;
......
...@@ -64,19 +64,19 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r) ...@@ -64,19 +64,19 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
return true; return true;
} }
int parse_bw(void *_buf, struct rdt_resource *r, struct rdt_domain *d) int parse_bw(struct rdt_parse_data *data, struct rdt_resource *r,
struct rdt_domain *d)
{ {
unsigned long data; unsigned long bw_val;
char *buf = _buf;
if (d->have_new_ctrl) { if (d->have_new_ctrl) {
rdt_last_cmd_printf("duplicate domain %d\n", d->id); rdt_last_cmd_printf("duplicate domain %d\n", d->id);
return -EINVAL; return -EINVAL;
} }
if (!bw_validate(buf, &data, r)) if (!bw_validate(data->buf, &bw_val, r))
return -EINVAL; return -EINVAL;
d->new_ctrl = data; d->new_ctrl = bw_val;
d->have_new_ctrl = true; d->have_new_ctrl = true;
return 0; return 0;
...@@ -123,18 +123,13 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r) ...@@ -123,18 +123,13 @@ static bool cbm_validate(char *buf, u32 *data, struct rdt_resource *r)
return true; return true;
} }
struct rdt_cbm_parse_data {
struct rdtgroup *rdtgrp;
char *buf;
};
/* /*
* Read one cache bit mask (hex). Check that it is valid for the current * Read one cache bit mask (hex). Check that it is valid for the current
* resource type. * resource type.
*/ */
int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d) int parse_cbm(struct rdt_parse_data *data, struct rdt_resource *r,
struct rdt_domain *d)
{ {
struct rdt_cbm_parse_data *data = _data;
struct rdtgroup *rdtgrp = data->rdtgrp; struct rdtgroup *rdtgrp = data->rdtgrp;
u32 cbm_val; u32 cbm_val;
...@@ -195,7 +190,7 @@ int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d) ...@@ -195,7 +190,7 @@ int parse_cbm(void *_data, struct rdt_resource *r, struct rdt_domain *d)
static int parse_line(char *line, struct rdt_resource *r, static int parse_line(char *line, struct rdt_resource *r,
struct rdtgroup *rdtgrp) struct rdtgroup *rdtgrp)
{ {
struct rdt_cbm_parse_data data; struct rdt_parse_data data;
char *dom = NULL, *id; char *dom = NULL, *id;
struct rdt_domain *d; struct rdt_domain *d;
unsigned long dom_id; unsigned long dom_id;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment