]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
core/driver: Switch to ID-based cell addressing scheme
authorJan Kiszka <jan.kiszka@siemens.com>
Sun, 2 Mar 2014 18:31:12 +0000 (19:31 +0100)
committerJan Kiszka <jan.kiszka@siemens.com>
Wed, 5 Mar 2014 08:39:54 +0000 (09:39 +0100)
Return the cell ID on cell creation and request this ID instead of the
cell name for destruction. Will also help to keep future per-cell
hypercalls simple.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
driver.c
hypervisor/control.c
hypervisor/include/jailhouse/control.h

index eefa6ab7284f2092e657d3742d678d2ade78ca8c..da5277d8e58597582678d1de880e4f4e335fb2e6 100644 (file)
--- a/driver.c
+++ b/driver.c
@@ -45,6 +45,7 @@
 struct cell {
        struct kobject kobj;
        struct list_head entry;
+       unsigned int id;
 };
 
 MODULE_DESCRIPTION("Loader for Jailhouse partitioning hypervisor");
@@ -256,6 +257,7 @@ static int jailhouse_enable(struct jailhouse_system __user *arg)
        release_firmware(hypervisor);
 
        enabled = true;
+       root_cell->id = 0;
        register_cell(root_cell);
 
        mutex_unlock(&lock);
@@ -406,7 +408,7 @@ static int jailhouse_cell_create(struct jailhouse_new_cell __user *arg)
        struct jailhouse_cell_desc *config;
        unsigned int cpu, n;
        struct cell *cell;
-       int err;
+       int id, err;
 
        if (copy_from_user(&cell_params, arg, sizeof(cell_params)))
                return -EFAULT;
@@ -458,10 +460,13 @@ static int jailhouse_cell_create(struct jailhouse_new_cell __user *arg)
                        cpu_set(cpu, offlined_cpus);
                }
 
-       err = jailhouse_call1(JAILHOUSE_HC_CELL_CREATE, __pa(config));
-       if (err)
+       id = jailhouse_call1(JAILHOUSE_HC_CELL_CREATE, __pa(config));
+       if (id < 0) {
+               err = id;
                goto error_cpu_online;
+       }
 
+       cell->id = id;
        register_cell(cell);
 
        pr_info("Created Jailhouse cell \"%s\"\n", config->name);
@@ -521,7 +526,7 @@ static int jailhouse_cell_destroy(const char __user *arg)
                goto unlock_out;
        }
 
-       err = jailhouse_call1(JAILHOUSE_HC_CELL_DESTROY, __pa(config->name));
+       err = jailhouse_call1(JAILHOUSE_HC_CELL_DESTROY, cell->id);
        if (err)
                goto unlock_out;
 
index 920e6b104eef8f11084e7c8b0cccf2a8497ada8c..9e05dc931548c012231bf8d4e5206edab0a3b41f 100644 (file)
@@ -153,36 +153,36 @@ int cell_create(struct per_cpu *cpu_data, unsigned long config_address)
                              cfg_header_size, mapping_addr,
                              PAGE_READONLY_FLAGS, PAGE_MAP_NON_COHERENT);
        if (err)
-               goto resume_out;
+               goto err_resume;
 
        cfg = (struct jailhouse_cell_desc *)(mapping_addr +
                                             (config_address & ~PAGE_MASK));
        cfg_total_size = jailhouse_cell_config_size(cfg);
        if (cfg_total_size > NUM_TEMPORARY_PAGES * PAGE_SIZE) {
                err = -E2BIG;
-               goto resume_out;
+               goto err_resume;
        }
 
        if (cell_find(cfg->name)) {
                err = -EEXIST;
-               goto resume_out;
+               goto err_resume;
        }
 
        err = page_map_create(&hv_paging_structs, config_address & PAGE_MASK,
                              cfg_total_size, mapping_addr,
                              PAGE_READONLY_FLAGS, PAGE_MAP_NON_COHERENT);
        if (err)
-               goto resume_out;
+               goto err_resume;
 
        err = check_mem_regions(cfg);
        if (err)
-               goto resume_out;
+               goto err_resume;
 
        cell_pages = PAGE_ALIGN(sizeof(*cell) + cfg_total_size) / PAGE_SIZE;
        cell = page_alloc(&mem_pool, cell_pages);
        if (!cell) {
                err = -ENOMEM;
-               goto resume_out;
+               goto err_resume;
        }
 
        cell->data_pages = cell_pages;
@@ -237,10 +237,9 @@ int cell_create(struct per_cpu *cpu_data, unsigned long config_address)
        for_each_cpu(cpu, cell->cpu_set)
                arch_reset_cpu(cpu);
 
-resume_out:
        cell_resume(cpu_data);
 
-       return err;
+       return cell->id;
 
 err_restore_cpu_set:
        for_each_cpu(cpu, cell->cpu_set)
@@ -249,7 +248,11 @@ err_free_cpu_set:
        destroy_cpu_set(cell);
 err_free_cell:
        page_free(&mem_pool, cell, cell_pages);
-       goto resume_out;
+
+err_resume:
+       cell_resume(cpu_data);
+
+       return err;
 }
 
 static bool cell_shutdown_ok(struct cell *cell)
@@ -314,14 +317,11 @@ static void remap_to_linux(const struct jailhouse_memory *mem)
        }
 }
 
-int cell_destroy(struct per_cpu *cpu_data, unsigned long name_address)
+int cell_destroy(struct per_cpu *cpu_data, unsigned long id)
 {
-       unsigned long mapping_addr = TEMPORARY_MAPPING_CPU_BASE(cpu_data);
        const struct jailhouse_memory *mem;
        struct cell *cell, *previous;
-       unsigned long name_size;
        unsigned int cpu, n;
-       const char *name;
        int err = 0;
 
        /* We do not support destruction over non-Linux cells so far. */
@@ -330,17 +330,9 @@ int cell_destroy(struct per_cpu *cpu_data, unsigned long name_address)
 
        cell_suspend(&linux_cell, cpu_data);
 
-       name_size = (name_address & ~PAGE_MASK) + JAILHOUSE_CELL_NAME_MAXLEN;
-
-       err = page_map_create(&hv_paging_structs, name_address & PAGE_MASK,
-                             name_size, mapping_addr, PAGE_READONLY_FLAGS,
-                             PAGE_MAP_NON_COHERENT);
-       if (err)
-               goto resume_out;
-
-       name = (const char *)(mapping_addr + (name_address & ~PAGE_MASK));
-
-       cell = cell_find(name);
+       for_each_cell(cell)
+               if (cell->id == id)
+                       break;
        if (!cell) {
                err = -ENOENT;
                goto resume_out;
@@ -359,7 +351,7 @@ int cell_destroy(struct per_cpu *cpu_data, unsigned long name_address)
 
        cell_suspend(cell, cpu_data);
 
-       printk("Closing cell \"%s\"\n", name);
+       printk("Closing cell \"%s\"\n", cell->config->name);
 
        for_each_cpu(cpu, cell->cpu_set) {
                printk(" Parking CPU %d\n", cpu);
index f8e7e81cef5c6da44034c9281c364186131929af..7881eaa083f7790dde75b559164507834eaef8dd 100644 (file)
@@ -38,7 +38,7 @@ int check_mem_regions(const struct jailhouse_cell_desc *config);
 int cell_init(struct cell *cell, bool copy_cpu_set);
 
 int cell_create(struct per_cpu *cpu_data, unsigned long config_address);
-int cell_destroy(struct per_cpu *cpu_data, unsigned long name_address);
+int cell_destroy(struct per_cpu *cpu_data, unsigned long id);
 
 int shutdown(struct per_cpu *cpu_data);