Signed-off-by: Andrea Bastoni <andrea.bast...@tum.de> --- hypervisor/control.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/hypervisor/control.c b/hypervisor/control.c index d6ede805..10f8a271 100644 --- a/hypervisor/control.c +++ b/hypervisor/control.c @@ -300,7 +300,7 @@ static bool address_in_region(unsigned long addr, addr < (region->phys_start + region->size); } -static int unmap_from_root_cell(const struct jailhouse_memory *mem) +static int unmap_from_root_cell(const struct jailhouse_memory *mem, bool create) { /* * arch_unmap_memory_region and mmio_subpage_unregister use the @@ -316,6 +316,11 @@ static int unmap_from_root_cell(const struct jailhouse_memory *mem) return 0; } + if (!create && (mem->flags & JAILHOUSE_MEM_COLORED)) { + assert(tmp.colors != 0); + return arch_color_unmap_from_root(&tmp); + } + return arch_unmap_memory_region(&root_cell, &tmp); } @@ -347,10 +352,21 @@ int remap_to_root_cell(const struct jailhouse_memory *mem, overlap.phys_start - root_mem->phys_start; overlap.flags = root_mem->flags; - if (JAILHOUSE_MEMORY_IS_SUBPAGE(&overlap)) - err = mmio_subpage_register(&root_cell, &overlap); - else - err = arch_map_memory_region(&root_cell, &overlap); + if ((mem->flags & JAILHOUSE_MEM_COLORED) && + (mode == ABORT_ON_ERROR)) { + /* ABORT_ON_ERROR signals that we're loading the + * cell, WARN_ON_ERROR that we're deleting it. + * On deletion, we're already taking the right colors + * into account. + */ + overlap.colors = mem->colors; + err = arch_color_remap_to_root(&overlap); + } else { + if (JAILHOUSE_MEMORY_IS_SUBPAGE(&overlap)) + err = mmio_subpage_register(&root_cell, &overlap); + else + err = arch_map_memory_region(&root_cell, &overlap); + } if (err) { if (mode == ABORT_ON_ERROR) break; @@ -532,7 +548,7 @@ static int cell_create(struct per_cpu *cpu_data, unsigned long config_address) */ if (!(mem->flags & (JAILHOUSE_MEM_COMM_REGION | JAILHOUSE_MEM_ROOTSHARED))) { - err = unmap_from_root_cell(mem); + err = unmap_from_root_cell(mem, true); if (err) goto err_destroy_cell; } @@ -645,11 +661,7 @@ static int cell_start(struct per_cpu *cpu_data, unsigned long id) /* unmap all loadable memory regions from the root cell */ for_each_mem_region(mem, cell->config, n) if (mem->flags & JAILHOUSE_MEM_LOADABLE) { - if (mem->flags & JAILHOUSE_MEM_COLORED) { - err = arch_color_unmap_from_root(mem); - } else { - err = unmap_from_root_cell(mem); - } + err = unmap_from_root_cell(mem, false); if (err) goto out_resume; } @@ -727,11 +739,7 @@ static int cell_set_loadable(struct per_cpu *cpu_data, unsigned long id) /* map all loadable memory regions into the root cell */ for_each_mem_region(mem, cell->config, n) if (mem->flags & JAILHOUSE_MEM_LOADABLE) { - if (mem->flags & JAILHOUSE_MEM_COLORED) { - err = arch_color_remap_to_root(mem); - } else { - err = remap_to_root_cell(mem, ABORT_ON_ERROR); - } + err = remap_to_root_cell(mem, ABORT_ON_ERROR); if (err) goto out_resume; } -- 2.29.2 -- 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 jailhouse-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/jailhouse-dev/20210125120044.56794-24-andrea.bastoni%40tum.de.