On 15.03.2024 11:58, Carlo Nonato wrote: > --- a/xen/common/llc-coloring.c > +++ b/xen/common/llc-coloring.c > @@ -18,6 +18,63 @@ integer_param("llc-nr-ways", llc_nr_ways); > /* Number of colors available in the LLC */ > static unsigned int __ro_after_init max_nr_colors; > > +static unsigned int __initdata dom0_colors[CONFIG_NR_LLC_COLORS]; > +static unsigned int __initdata dom0_num_colors; > + > +/* > + * Parse the coloring configuration given in the buf string, following the > + * syntax below. > + * > + * COLOR_CONFIGURATION ::= COLOR | RANGE,...,COLOR | RANGE > + * RANGE ::= COLOR-COLOR > + * > + * Example: "0,2-6,15-16" represents the set of colors: 0,2,3,4,5,6,15,16. > + */ > +static int __init parse_color_config(const char *buf, unsigned int *colors, > + unsigned int max_num_colors, > + unsigned int *num_colors) > +{ > + const char *s = buf; > + > + *num_colors = 0; > + > + while ( *s != '\0' ) > + { > + unsigned int color, start, end; > + > + start = simple_strtoul(s, &s, 0); > + > + if ( *s == '-' ) /* Range */ > + { > + s++; > + end = simple_strtoul(s, &s, 0); > + } > + else /* Single value */ > + end = start; > + > + if ( start > end || (end - start) > (UINT_MAX - *num_colors) || > + (*num_colors + (end - start)) >= max_num_colors ) > + return -EINVAL; > + > + for ( color = start; color <= end; color++ ) > + colors[(*num_colors)++] = color; > + > + if ( *s == ',' ) > + s++; > + else if ( *s != '\0' ) > + break; > + } > + > + return *s ? -EINVAL : 0; > +} > + > +static int __init parse_dom0_colors(const char *s) > +{ > + return parse_color_config(s, dom0_colors, ARRAY_SIZE(dom0_colors),
With it not being possible to pass max_nr_colors here (due to the value not having been established yet), don't you need to check somewhere else that ... > + &dom0_num_colors); ... dom0_num_colors isn't too large? Jan