Make the "used, dirty" firmware image visible in sysfs. The data segment
contains data that could be useful for all sorts of debugging tools.
This feature is introduced to extract code coverage information (gcov).

Signed-off-by: Henning Schild <[email protected]>
Tested-by: Ralf Ramsauer <[email protected]>

diff --git a/driver/main.c b/driver/main.c
--- a/driver/main.c
+++ b/driver/main.c
@@ -81,9 +81,9 @@ struct console_state {
 
 DEFINE_MUTEX(jailhouse_lock);
 bool jailhouse_enabled;
+void *hypervisor_mem;
 
 static struct device *jailhouse_dev;
-static void *hypervisor_mem;
 static unsigned long hv_core_and_percpu_size;
 static atomic_t call_done;
 static int error_code;
@@ -279,6 +279,7 @@ static int __jailhouse_console_dump_delt
 
 static void jailhouse_firmware_free(void)
 {
+       jailhouse_sysfs_core_exit(jailhouse_dev);
        vunmap(hypervisor_mem);
        hypervisor_mem = NULL;
 }
@@ -419,6 +420,10 @@ static int jailhouse_cmd_enable(struct j
        header = (struct jailhouse_header *)hypervisor_mem;
        header->max_cpus = max_cpus;
 
+       err = jailhouse_sysfs_core_init(jailhouse_dev, header->core_size);
+       if (err)
+               goto error_unmap;
+
        /*
         * ARMv8 requires to clean D-cache and invalidate I-cache for memory
         * containing new instructions. On x86 this is a NOP. On ARMv7 the
diff --git a/driver/main.h b/driver/main.h
--- a/driver/main.h
+++ b/driver/main.h
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2013-2015
+ * Copyright (c) Siemens AG, 2013-2017
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -19,6 +19,7 @@
 
 extern struct mutex jailhouse_lock;
 extern bool jailhouse_enabled;
+extern void *hypervisor_mem;
 
 void *jailhouse_ioremap(phys_addr_t phys, unsigned long virt,
                        unsigned long size);
diff --git a/driver/sysfs.c b/driver/sysfs.c
--- a/driver/sysfs.c
+++ b/driver/sysfs.c
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2014-2015
+ * Copyright (c) Siemens AG, 2014-2017
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -379,6 +379,23 @@ static ssize_t remap_pool_used_show(stru
        return info_show(dev, buffer, JAILHOUSE_INFO_REMAP_POOL_USED);
 }
 
+static ssize_t core_show(struct file *filp, struct kobject *kobj,
+                        struct bin_attribute *attr, char *buf, loff_t off,
+                        size_t count)
+{
+       if (mutex_lock_interruptible(&jailhouse_lock) != 0)
+               return -EINTR;
+
+       if (jailhouse_enabled || hypervisor_mem == NULL) {
+               mutex_unlock(&jailhouse_lock);
+               return -EBUSY;
+       }
+       count = memory_read_from_buffer(buf, count, &off, hypervisor_mem,
+                                       attr->size);
+       mutex_unlock(&jailhouse_lock);
+       return count;
+}
+
 static DEVICE_ATTR_RO(console);
 static DEVICE_ATTR_RO(enabled);
 static DEVICE_ATTR_RO(mem_pool_size);
@@ -401,6 +418,23 @@ static struct attribute_group jailhouse_
        .attrs = jailhouse_sysfs_entries,
 };
 
+static struct bin_attribute bin_attr_core = {
+       .attr.name = "core",
+       .attr.mode = S_IRUSR,
+       .read = core_show
+};
+
+int jailhouse_sysfs_core_init(struct device *dev, size_t hypervisor_size)
+{
+       bin_attr_core.size = hypervisor_size;
+       return sysfs_create_bin_file(&dev->kobj, &bin_attr_core);
+}
+
+void jailhouse_sysfs_core_exit(struct device *dev)
+{
+       sysfs_remove_bin_file(&dev->kobj, &bin_attr_core);
+}
+
 int jailhouse_sysfs_init(struct device *dev)
 {
        int err;
diff --git a/driver/sysfs.h b/driver/sysfs.h
--- a/driver/sysfs.h
+++ b/driver/sysfs.h
@@ -1,7 +1,7 @@
 /*
  * Jailhouse, a Linux-based partitioning hypervisor
  *
- * Copyright (c) Siemens AG, 2014-2015
+ * Copyright (c) Siemens AG, 2014-2017
  *
  * Authors:
  *  Jan Kiszka <[email protected]>
@@ -19,6 +19,8 @@ int jailhouse_sysfs_cell_create(struct c
 void jailhouse_sysfs_cell_register(struct cell *cell);
 void jailhouse_sysfs_cell_delete(struct cell *cell);
 
+int jailhouse_sysfs_core_init(struct device *dev, size_t hypervisor_size);
+void jailhouse_sysfs_core_exit(struct device *dev);
 int jailhouse_sysfs_init(struct device *dev);
 void jailhouse_sysfs_exit(struct device *dev);
 

-- 
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].
For more options, visit https://groups.google.com/d/optout.

Reply via email to