From: Luca Miccio <206497@studenti.unimore.it> Date: Wed, 21 Aug 2019 14:05:56 +0000 (+0200) Subject: xen/arm: add coloring basic initialization X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=200c4f2804a57ab036f14cb932cc012191fff3d7;p=people%2Fsstabellini%2Fxen-unstable.git%2F.git xen/arm: add coloring basic initialization Introduce a first and simple initialization function for the cache coloring support. A helper function computes 'addr_col_mask', the platform-dependent bitmask asserting the bits in memory addresses that can be used for the coloring mechanism. This, in turn is used to determine the total amount of available colors. Signed-off-by: Luca Miccio <206497@studenti.unimore.it> Signed-off-by: Marco Solieri --- diff --git a/xen/arch/arm/coloring.c b/xen/arch/arm/coloring.c index ae1f370703..eb9426d696 100644 --- a/xen/arch/arm/coloring.c +++ b/xen/arch/arm/coloring.c @@ -37,8 +37,13 @@ static uint64_t xen_col_mask; static uint64_t dom0_colors_num; /* Coloring configuration of Dom0 as bitmask */ static uint64_t dom0_colors_mask; +/* Maximum number of available color(s) */ +static uint64_t col_num_max; +/* Maximum available coloring configuration as bitmask */ +static uint64_t col_val_max; static uint64_t way_size; +static uint64_t addr_col_mask; #define CTR_LINESIZE_MASK 0x7 #define CTR_SIZE_SHIFT 13 @@ -113,6 +118,67 @@ static uint64_t get_llc_way_size(void) return (cache_line_size * cache_set_num); } +/* + * Return the coloring mask based on the value of @param llc_way_size. + * This mask represents the bits in the address that can be used + * for defining available colors. + * + * @param llc_way_size Last level cache way size. + * @return unsigned long The coloring bitmask. + */ +static __init unsigned long calculate_addr_col_mask(unsigned int llc_way_size) +{ + unsigned long addr_col_mask = 0; + unsigned int i; + unsigned int low_idx, high_idx; + + low_idx = PAGE_SHIFT; + high_idx = get_count_order(llc_way_size) - 1; + + for ( i = low_idx; i <= high_idx; i++ ) + addr_col_mask |= (1 << i); + + return addr_col_mask; +} + +bool __init coloring_init(void) +{ + int i; + + C_DEBUG("Initialize XEN coloring: \n"); + /* + * If the way size is not provided by the configuration, try to get + * this information from hardware. + */ + if ( !way_size ) + { + way_size = get_llc_way_size(); + + if ( !way_size ) + { + C_DEBUG("ERROR: way size is null\n"); + return false; + } + } + + addr_col_mask = calculate_addr_col_mask(way_size); + if ( !addr_col_mask ) + { + C_DEBUG("ERROR: addr_col_mask is null\n"); + return false; + } + + col_num_max = ((addr_col_mask >> PAGE_SHIFT) + 1); + for ( i = 0; i < col_num_max; i++ ) + col_val_max |= (1 << i); + + C_DEBUG("Way size: 0x%lx\n", way_size); + C_DEBUG("Color bits in address: 0x%lx\n", addr_col_mask); + C_DEBUG("Max number of colors: %lu (0x%lx)\n", col_num_max, col_val_max); + + return true; +} + /************************* * PARSING COLORING BOOTARGS */ diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c index 9c89c7d8fe..c504ec6a0e 100644 --- a/xen/arch/arm/setup.c +++ b/xen/arch/arm/setup.c @@ -53,6 +53,7 @@ #include #include #include +#include struct bootinfo __initdata bootinfo; @@ -818,6 +819,12 @@ void __init start_xen(unsigned long boot_phys_offset, fdt_size = boot_fdt_info(device_tree_flattened, fdt_paddr); + if ( !coloring_init() ) + panic("Xen Coloring support: setup failed\n"); + + xen_paddr = get_xen_paddr(); + setup_pagetables(boot_phys_offset, xen_paddr); + cmdline = boot_fdt_cmdline(device_tree_flattened); printk("Command line: %s\n", cmdline); cmdline_parse(cmdline); diff --git a/xen/include/asm-arm/coloring.h b/xen/include/asm-arm/coloring.h index 97d8550680..3b84dc3fb5 100644 --- a/xen/include/asm-arm/coloring.h +++ b/xen/include/asm-arm/coloring.h @@ -30,5 +30,11 @@ #else #define C_DEBUG(fmt, args...) { } #endif - +#ifdef CONFIG_COLORING +bool __init coloring_init(void); +#else +static bool inline __init coloring_init(void) +{ + return true; +} #endif /* !__ASM_ARM_COLORING_H__ */