Re: [PATCH v2] x86/resctrl: Avoid overflow in MB settings in bw_validate()
From: Reinette Chatre
Date: Mon Sep 23 2024 - 12:51:20 EST
Hi Martin,
On 9/17/24 10:19 AM, Reinette Chatre wrote:
> On 9/17/24 8:47 AM, Martin Kletzander wrote:
>> I wanted but the diff has some weird line numbering and could not be
>> applied. I'll write it manually later, test it out, and send a v3.
>> Thanks!
>
> Apologies. Please try:
>
> diff --git a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
> index 50fa1fe9a073..53defc5a6784 100644
> --- a/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
> +++ b/arch/x86/kernel/cpu/resctrl/ctrlmondata.c
> @@ -29,10 +29,10 @@
> * hardware. The allocated bandwidth percentage is rounded to the next
> * control step available on the hardware.
> */
> -static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
> +static bool bw_validate(char *buf, u32 *data, struct rdt_resource *r)
> {
> - unsigned long bw;
> int ret;
> + u32 bw;
>
> /*
> * Only linear delay values is supported for current Intel SKUs.
> @@ -42,14 +42,19 @@ static bool bw_validate(char *buf, unsigned long *data, struct rdt_resource *r)
> return false;
> }
>
> - ret = kstrtoul(buf, 10, &bw);
> + ret = kstrtou32(buf, 10, &bw);
> if (ret) {
> - rdt_last_cmd_printf("Non-decimal digit in MB value %s\n", buf);
> + rdt_last_cmd_printf("Invalid MB value %s\n", buf);
> return false;
> }
>
> - if ((bw < r->membw.min_bw || bw > r->default_ctrl) &&
> - !is_mba_sc(r)) {
> + /* Nothing else to do if software controller is enabled. */
> + if (is_mba_sc(r)) {
> + *data = bw;
> + return true;
> + }
> +
> + if (bw < r->membw.min_bw || bw > r->default_ctrl) {
> rdt_last_cmd_printf("MB value %ld out of range [%d,%d]\n", bw,
> r->membw.min_bw, r->default_ctrl);
> return false;
> @@ -65,7 +70,7 @@ int parse_bw(struct rdt_parse_data *data, struct resctrl_schema *s,
> struct resctrl_staged_config *cfg;
> u32 closid = data->rdtgrp->closid;
> struct rdt_resource *r = s->res;
> - unsigned long bw_val;
> + u32 bw_val;
>
> cfg = &d->staged_config[s->conf_type];
> if (cfg->have_new_ctrl) {
>
If you do find this appropriate you are welcome to add:
Co-developed-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
Signed-off-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
Reinette