All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marco Solieri <marco.solieri@minervasys.tech>
To: xen-devel@lists.xenproject.org
Cc: Marco Solieri <marco.solieri@minervasys.tech>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	George Dunlap <george.dunlap@citrix.com>,
	Jan Beulich <jbeulich@suse.com>, Julien Grall <julien@xen.org>,
	Stefano Stabellini <sstabellini@kernel.org>, Wei Liu <wl@xen.org>,
	Marco Solieri <marco.solieri@unimore.it>,
	Andrea Bastoni <andrea.bastoni@minervasys.tech>,
	Luca Miccio <lucmiccio@gmail.com>
Subject: [PATCH 06/36] xen/arm: add coloring basic initialization
Date: Fri,  4 Mar 2022 18:46:31 +0100	[thread overview]
Message-ID: <20220304174701.1453977-7-marco.solieri@minervasys.tech> (raw)
In-Reply-To: <20220304174701.1453977-1-marco.solieri@minervasys.tech>

From: Luca Miccio <lucmiccio@gmail.com>

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 <lucmiccio@gmail.com>
Signed-off-by: Marco Solieri <marco.solieri@minervasys.tech>
---
 xen/arch/arm/coloring.c             | 83 +++++++++++++++++++++++++++++
 xen/arch/arm/include/asm/coloring.h |  8 +++
 xen/arch/arm/setup.c                |  4 ++
 3 files changed, 95 insertions(+)

diff --git a/xen/arch/arm/coloring.c b/xen/arch/arm/coloring.c
index e3d490b453..af75b536a7 100644
--- a/xen/arch/arm/coloring.c
+++ b/xen/arch/arm/coloring.c
@@ -39,8 +39,13 @@ static uint32_t xen_col_mask[MAX_COLORS_CELLS];
 static uint32_t dom0_col_num;
 /* Coloring configuration of Dom0 as bitmask */
 static uint32_t dom0_col_mask[MAX_COLORS_CELLS];
+/* Maximum number of available color(s) */
+static uint32_t max_col_num;
+/* Maximum available coloring configuration as bitmask */
+static uint32_t max_col_mask[MAX_COLORS_CELLS];
 
 static uint64_t way_size;
+static uint64_t addr_col_mask;
 
 #define CTR_LINESIZE_MASK 0x7
 #define CTR_SIZE_SHIFT 13
@@ -115,6 +120,84 @@ 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 uint64_t calculate_addr_col_mask(uint64_t llc_way_size)
+{
+    uint64_t 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;
+
+    printk(XENLOG_INFO "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 )
+        {
+            printk(XENLOG_ERR "ERROR: way size is null\n");
+            return false;
+        }
+    }
+
+    addr_col_mask = calculate_addr_col_mask(way_size);
+    if ( !addr_col_mask )
+    {
+        printk(XENLOG_ERR "ERROR: addr_col_mask is null\n");
+        return false;
+    }
+
+    max_col_num = ((addr_col_mask >> PAGE_SHIFT) + 1);
+
+   /*
+    * If the user or the platform itself provide a way_size
+    * configuration that corresponds to a number of max.
+    * colors greater than the one we support, we cannot
+    * continue. So the check on offset value is necessary.
+    */
+    if ( max_col_num > 32 * MAX_COLORS_CELLS )
+    {
+        printk(XENLOG_ERR "ERROR: max. color value not supported\n");
+        return false;
+    }
+
+    for ( i = 0; i < max_col_num; i++ )
+    {
+        unsigned int offset = i / 32;
+
+        max_col_mask[offset] |= (1 << i % 32);
+    }
+
+    printk(XENLOG_INFO "Way size: 0x%"PRIx64"\n", way_size);
+    printk(XENLOG_INFO "Color bits in address: 0x%"PRIx64"\n", addr_col_mask);
+    printk(XENLOG_INFO "Max number of colors: %u\n", max_col_num);
+
+    return true;
+}
+
 /*************************
  * PARSING COLORING BOOTARGS
  */
diff --git a/xen/arch/arm/include/asm/coloring.h b/xen/arch/arm/include/asm/coloring.h
index 60958d1244..70e1dbd09b 100644
--- a/xen/arch/arm/include/asm/coloring.h
+++ b/xen/arch/arm/include/asm/coloring.h
@@ -25,4 +25,12 @@
 
 #define MAX_COLORS_CELLS 4
 
+#ifdef CONFIG_COLORING
+bool __init coloring_init(void);
+#else /* !CONFIG_COLORING */
+static inline bool __init coloring_init(void)
+{
+    return true;
+}
+#endif /* CONFIG_COLORING */
 #endif /* !__ASM_ARM_COLORING_H__ */
diff --git a/xen/arch/arm/setup.c b/xen/arch/arm/setup.c
index b8d4f50d90..f39c62ea70 100644
--- a/xen/arch/arm/setup.c
+++ b/xen/arch/arm/setup.c
@@ -53,6 +53,7 @@
 #include <asm/setup.h>
 #include <xsm/xsm.h>
 #include <asm/acpi.h>
+#include <asm/coloring.h>
 
 struct bootinfo __initdata bootinfo;
 
@@ -893,6 +894,9 @@ void __init start_xen(unsigned long boot_phys_offset,
     printk("Command line: %s\n", cmdline);
     cmdline_parse(cmdline);
 
+    if ( !coloring_init() )
+        panic("Xen Coloring support: setup failed\n");
+
     /* Register Xen's load address as a boot module. */
     xen_bootmodule = add_boot_module(BOOTMOD_XEN, xen_paddr,
                              (paddr_t)(uintptr_t)(_end - _start + 1), false);
-- 
2.30.2



  parent reply	other threads:[~2022-03-04 18:17 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-04 17:46 [PATCH 00/36] Arm cache coloring Marco Solieri
2022-03-04 17:46 ` [PATCH 01/36] Revert "xen/arm: setup: Add Xen as boot module before printing all boot modules" Marco Solieri
2022-03-04 18:50   ` Julien Grall
2022-03-04 17:46 ` [PATCH 02/36] Revert "xen/arm: mm: Initialize page-tables earlier" Marco Solieri
2022-03-04 17:46 ` [PATCH 03/36] xen/arm: restore xen_paddr argument in setup_pagetables Marco Solieri
2022-03-04 17:46 ` [PATCH 04/36] xen/arm: add parsing function for cache coloring configuration Marco Solieri
2022-03-09 19:09   ` Julien Grall
2022-03-22  9:17     ` Luca Miccio
2022-03-23 19:02       ` Julien Grall
2022-05-13 14:22     ` Carlo Nonato
2022-05-13 17:41       ` Julien Grall
2022-03-04 17:46 ` [PATCH 05/36] xen/arm: compute LLC way size by hardware inspection Marco Solieri
2022-03-09 20:12   ` Julien Grall
2022-05-13 14:34     ` Carlo Nonato
2022-05-13 19:08       ` Julien Grall
2022-03-04 17:46 ` Marco Solieri [this message]
2022-03-04 17:46 ` [PATCH 07/36] xen/arm: add coloring data to domains Marco Solieri
2022-03-07  7:22   ` Jan Beulich
2022-03-04 17:46 ` [PATCH 08/36] xen/arm: add colored flag to page struct Marco Solieri
2022-03-04 20:13   ` Julien Grall
2022-03-04 17:46 ` [PATCH 09/36] xen/arch: add default colors selection function Marco Solieri
2022-03-07  7:28   ` Jan Beulich
2022-03-04 17:46 ` [PATCH 10/36] xen/arch: check color " Marco Solieri
2022-03-09 20:17   ` Julien Grall
2022-03-14  6:06   ` Henry Wang
2022-03-04 17:46 ` [PATCH 11/36] xen/include: define hypercall parameter for coloring Marco Solieri
2022-03-07  7:31   ` Jan Beulich
2022-03-09 20:29   ` Julien Grall
2022-03-04 17:46 ` [PATCH 12/36] xen/arm: initialize cache coloring data for Dom0/U Marco Solieri
2022-03-11 19:05   ` Julien Grall
2022-03-04 17:46 ` [PATCH 13/36] xen/arm: A domain is not direct mapped when coloring is enabled Marco Solieri
2022-03-09 20:34   ` Julien Grall
2022-03-04 17:46 ` [PATCH 14/36] xen/arch: add dump coloring info for domains Marco Solieri
2022-03-04 17:46 ` [PATCH 15/36] tools: add support for cache coloring configuration Marco Solieri
2022-03-04 17:46 ` [PATCH 16/36] xen/color alloc: implement color_from_page for ARM64 Marco Solieri
2022-03-04 20:54   ` Julien Grall
2022-03-11 17:39     ` Marco Solieri
2022-03-11 17:57       ` Julien Grall
2022-03-04 17:46 ` [PATCH 17/36] xen/arm: add get_max_color function Marco Solieri
2022-03-11 19:09   ` Julien Grall
2022-03-04 17:46 ` [PATCH 18/36] Alloc: introduce page_list_for_each_reverse Marco Solieri
2022-03-07  7:35   ` Jan Beulich
2022-03-04 17:46 ` [PATCH 19/36] xen/arch: introduce cache-coloring allocator Marco Solieri
2022-03-09 14:35   ` Jan Beulich
2022-03-04 17:46 ` [PATCH 20/36] xen/common: introduce buddy required reservation Marco Solieri
2022-03-09 14:45   ` Jan Beulich
2022-03-09 14:47     ` Jan Beulich
2022-03-04 17:46 ` [PATCH 21/36] xen/common: add colored allocator initialization Marco Solieri
2022-03-09 14:58   ` Jan Beulich
2022-03-04 17:46 ` [PATCH 22/36] xen/arch: init cache coloring conf for Xen Marco Solieri
2022-03-14 18:59   ` Julien Grall
2022-03-04 17:46 ` [PATCH 23/36] xen/arch: coloring: manually calculate Xen physical addresses Marco Solieri
2022-03-14 19:23   ` Julien Grall
2022-03-04 17:46 ` [PATCH 24/36] xen/arm: enable consider_modules for coloring Marco Solieri
2022-03-14 19:24   ` Julien Grall
2022-03-04 17:46 ` [PATCH 25/36] xen/arm: bring back get_xen_paddr Marco Solieri
2022-03-04 17:46 ` [PATCH 26/36] xen/arm: add argument to remove_early_mappings Marco Solieri
2022-03-14 19:59   ` Julien Grall
2022-03-04 17:46 ` [PATCH 27/36] xen/arch: add coloring support for Xen Marco Solieri
2022-03-04 19:47   ` Julien Grall
2022-03-09 11:28     ` Julien Grall
2022-03-14  3:47   ` Henry Wang
2022-03-14 21:58   ` Julien Grall
2022-03-04 17:46 ` [PATCH 28/36] xen/arm: introduce xen_map_text_rw Marco Solieri
2022-03-07  7:39   ` Jan Beulich
2022-03-11 22:28     ` Julien Grall
2022-03-04 17:46 ` [PATCH 29/36] xen/arm: add dump function for coloring info Marco Solieri
2022-03-04 17:46 ` [PATCH 30/36] xen/arm: add coloring support to dom0less Marco Solieri
2022-03-04 17:46 ` [PATCH 31/36] Disable coloring if static memory support is selected Marco Solieri
2022-03-14 20:04   ` Julien Grall
2022-03-04 17:46 ` [PATCH 32/36] xen/arm: reduce the number of supported colors Marco Solieri
2022-03-04 17:46 ` [PATCH 33/36] doc, xen-command-line: introduce coloring options Marco Solieri
2022-03-07  7:42   ` Jan Beulich
2022-03-14 22:07   ` Julien Grall
2022-03-04 17:46 ` [PATCH 34/36] doc, xl.cfg: introduce coloring configuration option Marco Solieri
2022-03-04 17:47 ` [PATCH 35/36] doc, device-tree: introduce 'colors' property Marco Solieri
2022-03-14 22:17   ` Julien Grall
2022-03-04 17:47 ` [PATCH 36/36] doc, arm: add usage documentation for cache coloring support Marco Solieri
2022-03-15 19:23   ` Julien Grall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220304174701.1453977-7-marco.solieri@minervasys.tech \
    --to=marco.solieri@minervasys.tech \
    --cc=andrea.bastoni@minervasys.tech \
    --cc=andrew.cooper3@citrix.com \
    --cc=george.dunlap@citrix.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=lucmiccio@gmail.com \
    --cc=marco.solieri@unimore.it \
    --cc=sstabellini@kernel.org \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.