@@ -162,6 +162,10 @@ with the following properties:
An integer specifying the number of vcpus to allocate to the guest.
+- llc-colors
+ A string specifying the LLC color configuration for the guest.
+ Refer to docs/misc/cache_coloring.rst for syntax.
+
- vpl011
An empty property to enable/disable a virtual pl011 for the guest to
@@ -12,6 +12,7 @@ If needed, change the maximum number of colors with
``CONFIG_MAX_LLC_COLORS_ORDER=<n>``.
Runtime configuration is done via `Command line parameters`_.
+For DomUs follow `DomUs configuration`_.
Background
**********
@@ -147,6 +148,53 @@ LLC specs can be manually set via the above command line parameters. This
bypasses any auto-probing and it's used to overcome failing situations, such as
flawed probing logic, or for debugging/testing purposes.
+DomUs configuration
+*******************
+
+DomUs colors can be set either in the ``xl`` configuration file (documentation
+at `docs/man/xl.cfg.pod.5.in`) or via Device Tree, also for Dom0less
+configurations (documentation at `docs/misc/arm/device-tree/booting.txt`) using
+the ``llc-colors`` option. For example:
+
+::
+
+ xen,xen-bootargs = "console=dtuart dtuart=serial0 dom0_mem=1G dom0_max_vcpus=1 sched=null llc-coloring=on dom0-llc-colors=2-6";
+ xen,dom0-bootargs "console=hvc0 earlycon=xen earlyprintk=xen root=/dev/ram0"
+
+ dom0 {
+ compatible = "xen,linux-zimage" "xen,multiboot-module";
+ reg = <0x0 0x1000000 0x0 15858176>;
+ };
+
+ dom0-ramdisk {
+ compatible = "xen,linux-initrd" "xen,multiboot-module";
+ reg = <0x0 0x2000000 0x0 20638062>;
+ };
+
+ domU0 {
+ #address-cells = <0x1>;
+ #size-cells = <0x1>;
+ compatible = "xen,domain";
+ memory = <0x0 0x40000>;
+ llc-colors = "4-8,10,11,12";
+ cpus = <0x1>;
+ vpl011 = <0x1>;
+
+ module@2000000 {
+ compatible = "multiboot,kernel", "multiboot,module";
+ reg = <0x2000000 0xffffff>;
+ bootargs = "console=ttyAMA0";
+ };
+
+ module@30000000 {
+ compatible = "multiboot,ramdisk", "multiboot,module";
+ reg = <0x3000000 0xffffff>;
+ };
+ };
+
+**Note:** If no color configuration is provided for a domain, the default one,
+which corresponds to all available colors is used instead.
+
Known issues and limitations
****************************
@@ -807,6 +807,7 @@ void __init create_domUs(void)
struct dt_device_node *node;
const struct dt_device_node *cpupool_node,
*chosen = dt_find_node_by_path("/chosen");
+ const char *llc_colors_str = NULL;
BUG_ON(chosen == NULL);
dt_for_each_child_node(chosen, node)
@@ -950,6 +951,10 @@ void __init create_domUs(void)
#endif
}
+ dt_property_read_string(node, "llc-colors", &llc_colors_str);
+ if ( !llc_coloring_enabled && llc_colors_str )
+ panic("'llc-colors' found, but LLC coloring is disabled\n");
+
/*
* The variable max_init_domid is initialized with zero, so here it's
* very important to use the pre-increment operator to call
@@ -960,6 +965,11 @@ void __init create_domUs(void)
panic("Error creating domain %s (rc = %ld)\n",
dt_node_name(node), PTR_ERR(d));
+ if ( llc_coloring_enabled &&
+ (rc = domain_set_llc_colors_from_str(d, llc_colors_str)) )
+ panic("Error initializing LLC coloring for domain %s (rc = %d)\n",
+ dt_node_name(node), rc);
+
d->is_console = true;
dt_device_set_used_by(node, d->domain_id);
@@ -4,6 +4,7 @@
*
* Copyright (C) 2022 Xilinx Inc.
*/
+#include "xen/xmalloc.h"
#include <xen/guest_access.h>
#include <xen/keyhandler.h>
#include <xen/llc-coloring.h>
@@ -266,6 +267,47 @@ int domain_set_llc_colors(struct domain *d,
return 0;
}
+int __init domain_set_llc_colors_from_str(struct domain *d, const char *str)
+{
+ int err;
+ unsigned int *colors, num_colors;
+
+ if ( !str )
+ {
+ domain_set_default_colors(d);
+ return 0;
+ }
+
+ colors = xmalloc_array(unsigned int, max_nr_colors);
+ if ( !colors )
+ return -ENOMEM;
+
+ err = parse_color_config(str, colors, max_nr_colors, &num_colors);
+ if ( err )
+ {
+ printk(XENLOG_ERR "Error parsing LLC color configuration");
+ xfree(colors);
+ return err;
+ }
+
+ if ( !check_colors(colors, num_colors) )
+ {
+ printk(XENLOG_ERR "Bad LLC color config for %pd\n", d);
+ xfree(colors);
+ return -EINVAL;
+ }
+
+ /* Adjust the size cause it was initially set to max_nr_colors */
+ colors = xrealloc_array(colors, num_colors);
+ if ( !colors )
+ return -ENOMEM;
+
+ d->llc_colors = colors;
+ d->num_llc_colors = num_colors;
+
+ return 0;
+}
+
/*
* Local variables:
* mode: C
@@ -31,6 +31,7 @@ void arch_llc_coloring_init(void);
int dom0_set_llc_colors(struct domain *d);
int domain_set_llc_colors(struct domain *d,
const struct xen_domctl_set_llc_colors *config);
+int domain_set_llc_colors_from_str(struct domain *d, const char *str);
#endif /* __COLORING_H__ */
@@ -34,6 +34,9 @@
((_type *)_xmalloc_array(sizeof(_type), __alignof__(_type), _num))
#define xzalloc_array(_type, _num) \
((_type *)_xzalloc_array(sizeof(_type), __alignof__(_type), _num))
+#define xrealloc_array(_ptr, _num) \
+ ((typeof(_ptr))_xrealloc_array(_ptr, sizeof(typeof(*(_ptr))), \
+ __alignof__(typeof(*(_ptr))), _num))
/* Allocate space for a structure with a flexible array of typed objects. */
#define xzalloc_flex_struct(type, field, nr) \
@@ -95,6 +98,15 @@ static inline void *_xzalloc_array(
return _xzalloc(size * num, align);
}
+static inline void *_xrealloc_array(
+ void *ptr, unsigned long size, unsigned long align, unsigned long num)
+{
+ /* Check for overflow. */
+ if ( size && num > UINT_MAX / size )
+ return NULL;
+ return _xrealloc(ptr, size * num, align);
+}
+
/*
* Pooled allocator interface.
*/