Upon cell creation, check whether there exists a cell with an identical
mask as should be created now. In that case, reuse that cell's COS, to
increase the number of available COS's.

Recent Intel Xeon Processors, which have CAT support, can have up to 28
cores. This might exceed the number of COSes available, as this
typically relates to the number of cache ways rather than the number of
cores on the processor. Therefore, creating a cell per core which is
isolated from the root becomes impossible if each core requires a
private COS.

Signed-off-by: Bram Hooimeijer <[email protected]>
---
 hypervisor/arch/x86/cat.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/hypervisor/arch/x86/cat.c b/hypervisor/arch/x86/cat.c
index c91560a2..fc943a0d 100644
--- a/hypervisor/arch/x86/cat.c
+++ b/hypervisor/arch/x86/cat.c
@@ -45,14 +45,22 @@ static void cat_update_cell(struct cell *cell)
                        public_per_cpu(cpu)->update_cat = true;
 }
 
-static u32 get_free_cos(void)
+static u32 get_suitable_cos(struct cell *cell)
 {
-       struct cell *cell;
+       struct cell *other_cell;
        u32 cos = 0;
 
+       /* Check whether a COS can be reused.
+        *
+        * Never reuse the ROOT_COS, as the corresponding CBM can be changed
+        * when new cells are made, collaterally impacting the created cell. */
+       for_each_non_root_cell(other_cell)
+               if (cell->arch.cat_mask == other_cell->arch.cat_mask)
+                       return other_cell->arch.cos;
+
 retry:
-       for_each_cell(cell)
-               if (cell->arch.cos == cos) {
+       for_each_cell(other_cell)
+               if (other_cell->arch.cos == cos) {
                        cos++;
                        goto retry;
                }
@@ -166,12 +174,6 @@ static int cat_cell_init(struct cell *cell)
                return 0;
 
        if (cell->config->num_cache_regions > 0) {
-               if (cell != &root_cell) {
-                       cell->arch.cos = get_free_cos();
-                       if (cell->arch.cos > (u32)cos_max)
-                               return trace_error(-EBUSY);
-               }
-
                cache = jailhouse_cell_cache_regions(cell->config);
 
                if (cell->config->num_cache_regions != 1 ||
@@ -183,6 +185,12 @@ static int cat_cell_init(struct cell *cell)
                cell->arch.cat_mask =
                        BIT_MASK(cache->start + cache->size - 1, cache->start);
 
+               if (cell != &root_cell) {
+                       cell->arch.cos = get_suitable_cos(cell);
+                       if (cell->arch.cos > (u32)cos_max)
+                               return trace_error(-EBUSY);
+               }
+
                if (cell != &root_cell &&
                    !(cache->flags & JAILHOUSE_CACHE_ROOTSHARED) &&
                    (root_cell.arch.cat_mask & cell->arch.cat_mask) != 0)
-- 
2.28.0

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/PA4PR02MB6670F14BBC726C44E8200B2CB6B59%40PA4PR02MB6670.eurprd02.prod.outlook.com.

Reply via email to