Permalink
Browse files

driver/tools: Rework cell destruction API

Reference a cell to be destructed via its config file. The API to the
hypervisor is still based on names, but the driver IOCTL now takes a
reference to a fully loaded config.

This allows the driver to bring the CPUs that were used by the
destructed cell online again. It is also more handy for the user as
creation and destruction now both use the same token to reference a
cell.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information...
1 parent b4acb9f commit 4b2a0631ca0c8353fa8320ac8aa7f0711416a59c @jan-kiszka jan-kiszka committed Dec 2, 2013
Showing with 43 additions and 8 deletions.
  1. +6 −1 jailhouse.h
  2. +29 −5 main.c
  3. +8 −2 tools/jailhouse.c
View
@@ -28,7 +28,12 @@ struct jailhouse_new_cell {
struct jailhouse_preload_image image[];
};
+struct jailhouse_cell {
+ __u64 config_address;
+ __u32 config_size;
+};
+
#define JAILHOUSE_ENABLE _IOW(0, 0, struct jailhouse_system)
#define JAILHOUSE_DISABLE _IO(0, 1)
#define JAILHOUSE_CELL_CREATE _IOW(0, 2, struct jailhouse_new_cell)
-#define JAILHOUSE_CELL_DESTROY _IOW(0, 3, const char *)
+#define JAILHOUSE_CELL_DESTROY _IOW(0, 3, struct jailhouse_cell)
View
@@ -363,12 +363,25 @@ static int jailhouse_cell_create(struct jailhouse_new_cell __user *arg)
static int jailhouse_cell_destroy(const char __user *arg)
{
- char name[JAILHOUSE_CELL_NAME_MAXLEN];
+ struct jailhouse_cell_desc *config;
+ struct jailhouse_cell cell;
+ unsigned int cpu;
int err;
- if (strncpy_from_user(name, arg, sizeof(name) - 1) < 0)
+ if (copy_from_user(&cell, arg, sizeof(cell)))
return -EFAULT;
- name[sizeof(name) - 1] = 0;
+
+ config = kmalloc(cell.config_size, GFP_KERNEL | GFP_DMA);
+ if (!config)
+ return -ENOMEM;
+
+ if (copy_from_user(config, (void *)(unsigned long)cell.config_address,
+ cell.config_size)) {
+ err = -EFAULT;
+ goto kfree_config_out;
+ }
+ config->name[JAILHOUSE_CELL_NAME_MAXLEN] = 0;
+
if (mutex_lock_interruptible(&lock) != 0)
return -EINTR;
@@ -378,15 +391,26 @@ static int jailhouse_cell_destroy(const char __user *arg)
goto unlock_out;
}
- err = jailhouse_call1(JAILHOUSE_HC_CELL_DESTROY, __pa(name));
+ err = jailhouse_call1(JAILHOUSE_HC_CELL_DESTROY, __pa(config->name));
if (err)
goto unlock_out;
- pr_info("Destroyed Jailhouse cell \"%s\"\n", name);
+ for_each_cell_cpu(cpu, config)
+ if (cpu_isset(cpu, offlined_cpus)) {
+ if (cpu_up(cpu) != 0)
+ pr_err("Jailhouse: failed to bring CPU %d "
+ "back online\n", cpu);
+ cpu_clear(cpu, offlined_cpus);
+ }
+
+ pr_info("Destroyed Jailhouse cell \"%s\"\n", config->name);
unlock_out:
mutex_unlock(&lock);
+kfree_config_out:
+ kfree(config);
+
return err;
}
View
@@ -29,7 +29,7 @@ static void help(const char *progname)
" enable CONFIGFILE\n"
" disable\n"
" cell create CONFIGFILE PRELOADIMAGE [-l ADDRESS]\n"
- " cell destroy NAME\n",
+ " cell destroy CONFIGFILE\n",
progname);
}
@@ -154,20 +154,26 @@ static int cell_create(int argc, char *argv[])
static int cell_destroy(int argc, char *argv[])
{
+ struct jailhouse_cell cell;
+ size_t size;
int err, fd;
if (argc != 4) {
help(argv[0]);
exit(1);
}
+ cell.config_address = (unsigned long)read_file(argv[3], &size);
+ cell.config_size = size;
+
fd = open_dev();
- err = ioctl(fd, JAILHOUSE_CELL_DESTROY, argv[3]);
+ err = ioctl(fd, JAILHOUSE_CELL_DESTROY, &cell);
if (err)
perror("JAILHOUSE_CELL_DESTROY");
close(fd);
+ free((void *)(unsigned long)cell.config_address);
return err;
}

0 comments on commit 4b2a063

Please sign in to comment.