Skip to contentSkip to conversation

xen/common: llc-coloring parser fixes

PATCH In review Mykola Kvach 4 participants 6 messages May 21 – May 25

lore
Share & tools
lore
#0 lore raw

v2 cover xen/common: llc-coloring parser fixes

From: Mykola Kvach <[email protected]>

Hi all,

This small series fixes two issues in parse_color_config().

The first patch makes parse failures leave the caller-visible color count at zero. This prevents a rejected command-line value from leaving a partially parsed configuration behind for later init paths to consume.

The second patch rejects empty color tokens. Previously, delimiters in places where a color value was expected could be interpreted as color 0, because simple_strtoul() returns zero without advancing the input pointer. The patch checks that each parsed color value consumed input. It also fixes the DT color parsing error message by adding the missing newline and including the domain ID.

Changes in v2:
- Clarify the first commit message.
- Include the domain ID in the DT color parsing error message.
- Add Reviewed-by tags.

Mykola Kvach (2):
xen/common: llc-coloring: clear color count on parse failure xen/common: llc-coloring: reject empty color tokens

 xen/common/llc-coloring.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 xen/common: llc-coloring: clear color count on parse failure

From: Mykola Kvach <[email protected]>

parse_color_config() updates the caller-provided color count while parsing. If parsing later fails, leave the count at zero so callers do not consume a partially parsed configuration.

The bug is reachable in practice: cmdline_parse() ignores the -EINVAL from a custom_param callback, so boot continues with the partial xen_num_colors / dom0_num_colors that llc_coloring_init() and dom0_set_llc_colors() then consume.

Fixes 6cdea3444eaf ("xen/arm: add Dom0 cache coloring support")

---
Changes in v2:
- Clarify that the partial color count can be consumed after a command-line parse failure.
- Add Reviewed-by tags.

---
 xen/common/llc-coloring.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
xen/common/llc-coloring.c +9 -2
index 6dc614739a..2606cb0977 100644
@@ -79,7 +79,7 @@ static int __init parse_color_config(const char *buf, unsigned int colors[],
         if ( end >= NR_LLC_COLORS || start > end ||
              (end - start) >= (UINT_MAX - *num_colors) ||
              (*num_colors + (end - start)) >= max_num_colors )
-            return -EINVAL;
+            goto fail;
 
         /* Colors are range checked in check_colors() */
         for ( color = start; color <= end; color++ )
@@ -91,7 +91,14 @@ static int __init parse_color_config(const char *buf, unsigned int colors[],
             break;
     }
 
-    return *s ? -EINVAL : 0;
+    if ( *s )
+        goto fail;
+
+    return 0;
+
+ fail:
+    *num_colors = 0;
+    return -EINVAL;
 }
 
 static int __init parse_dom0_colors(const char *s)
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/2 xen/common: llc-coloring: reject empty color tokens

In reply to Mykola Kvach

From: Mykola Kvach <[email protected]>

parse_color_config() currently accepts delimiters where a color value is expected because simple_strtoul() returns zero without advancing the input pointer. This makes strings such as ",2-6", "-10,19-20" or "1,,2" look as if an empty value was color 0.

Also fix the DT color parsing error message by adding the missing newline and including the domain ID, matching the style of the color validation error below.

Fixes 6cdea3444eaf ("xen/arm: add Dom0 cache coloring support")

---
Changes in v2:
- Include the domain ID in the LLC color parsing error message.
- Add Reviewed-by tag.

---
 xen/common/llc-coloring.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
xen/common/llc-coloring.c +10 -3
index 2606cb0977..b5de5787c1 100644
@@ -64,14 +64,21 @@ static int __init parse_color_config(const char *buf, unsigned int colors[],
 
     while ( *s != '\0' )
     {
+        const char *endp;
         unsigned int color, start, end;
 
-        start = simple_strtoul(s, &s, 0);
+        start = simple_strtoul(s, &endp, 0);
+        if ( endp == s )
+            goto fail;
+        s = endp;
 
         if ( *s == '-' )    /* Range */
         {
             s++;
-            end = simple_strtoul(s, &s, 0);
+            end = simple_strtoul(s, &endp, 0);
+            if ( endp == s )
+                goto fail;
+            s = endp;
         }
         else                /* Single value */
             end = start;
@@ -334,7 +341,7 @@ int __init domain_set_llc_colors_from_str(struct domain *d, const char *str)
     err = parse_color_config(str, colors, max_nr_colors, &num_colors);
     if ( err )
     {
-        printk(XENLOG_ERR "Error parsing LLC color configuration");
+        printk(XENLOG_ERR "%pd: error parsing LLC color configuration\n", d);
         xfree(colors);
         return err;
     }
Signature · 1 line
2.43.0
Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] xen/common: llc-coloring: reject empty color tokens

Quoted 7 lines · Mykola Kvach

From: Mykola Kvach <[email protected]>

parse_color_config() currently accepts delimiters where a color value is expected because simple_strtoul() returns zero without advancing the input pointer. This makes strings such as ",2-6", "-10,19-20" or "1,,2" look as if an empty value was color 0.

Quoted 7 lines

Also fix the DT color parsing error message by adding the missing newline and including the domain ID, matching the style of the color validation error below.

Fixes 6cdea3444eaf ("xen/arm: add Dom0 cache coloring support")

Looks good, thanks!

#4 lore raw
In reply to Mykola Kvach
CC Oleksii

@Oleksii, can we ask for your release ack for this series?

~Michal

Quoted 29 lines · Mykola Kvach

From: Mykola Kvach <[email protected]>

Hi all,

This small series fixes two issues in parse_color_config().

The first patch makes parse failures leave the caller-visible color count at zero. This prevents a rejected command-line value from leaving a partially parsed configuration behind for later init paths to consume.

The second patch rejects empty color tokens. Previously, delimiters in places where a color value was expected could be interpreted as color 0, because simple_strtoul() returns zero without advancing the input pointer. The patch checks that each parsed color value consumed input. It also fixes the DT color parsing error message by adding the missing newline and including the domain ID.

Changes in v2:
- Clarify the first commit message.
- Include the domain ID in the DT color parsing error message.
- Add Reviewed-by tags.

Mykola Kvach (2):
xen/common: llc-coloring: clear color count on parse failure xen/common: llc-coloring: reject empty color tokens

 xen/common/llc-coloring.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)