From: Luca Miccio <[email protected]>

Currently Jailhouse loads inmate's binaries by mapping its memory region
to the root cell. When coloring is enabled this operation becomes
not trivial. To avoid logic duplication in the driver module,
use a special memory space when loading to colored regions. This
convenient memory space starts from a fixed address defined by
`col_loads_address` and will be mapped by the hypervisor using the same
size and coloring configuration as the inmate.
Since there could be platforms with different memory space layouts, the
choice of `col_loads_address` has to be done accordingly.
Allow the user to set this value in the root-cell configuration and set
the default to 16 GiB. The latter has been empirically choosen as default
value.

Signed-off-by: Luca Miccio <[email protected]>
Signed-off-by: Marco Solieri <[email protected]>
Acked-by: Angelo Ruocco <[email protected]>
---
 driver/Makefile                 |  4 ++++
 driver/cell.h                   |  3 +++
 driver/main.c                   | 15 +++++++++++++++
 include/jailhouse/cell-config.h |  6 ++++++
 4 files changed, 28 insertions(+)

diff --git a/driver/Makefile b/driver/Makefile
index 8dded848..c69d1991 100644
--- a/driver/Makefile
+++ b/driver/Makefile
@@ -18,6 +18,10 @@ ccflags-y := -I$(src)/../hypervisor/arch/$(SRCARCH)/include \
             -I$(src)/../include/arch/$(SRCARCH) \
             -I$(src)/../include
 
+ifneq ($(wildcard $(obj)/../include/jailhouse/config.h),)
+KBUILD_CFLAGS += -include $(src)/../include/jailhouse/config.h
+endif
+
 jailhouse-y := cell.o main.o sysfs.o
 jailhouse-$(CONFIG_PCI) += pci.o
 jailhouse-$(CONFIG_OF) += vpci_template.dtb.o
diff --git a/driver/cell.h b/driver/cell.h
index 92afbff8..0207e189 100644
--- a/driver/cell.h
+++ b/driver/cell.h
@@ -36,6 +36,9 @@ struct cell {
        u32 num_pci_devices;
        struct jailhouse_pci_device *pci_devices;
 #endif /* CONFIG_PCI */
+#ifdef CONFIG_COLORING
+       u64 col_load_address;
+#endif /* CONFIG_COLORING */
 };
 
 extern struct cell *root_cell;
diff --git a/driver/main.c b/driver/main.c
index 01e9c049..25bdc15c 100644
--- a/driver/main.c
+++ b/driver/main.c
@@ -118,6 +118,9 @@ static typeof(__boot_cpu_mode) *__boot_cpu_mode_sym;
 #if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
 static typeof(__hyp_stub_vectors) *__hyp_stub_vectors_sym;
 #endif
+#ifdef CONFIG_COLORING
+#define DEFAULT_JAILHOUSE_CELL_LOAD_VADDR      0x400000000
+#endif
 
 /* last_console contains three members:
  *   - valid: indicates if content in the page member is present
@@ -566,6 +569,18 @@ static int jailhouse_cmd_enable(struct jailhouse_system 
__user *arg)
        if (err)
                goto error_unmap;
 
+#ifdef CONFIG_COLORING
+       /**
+        * Be sure that col_load_address is set if coloring is enabled.
+        */
+       if (!config->platform_info.col_load_address) {
+               pr_notice("No coloring load address defined, using default\n");
+               config->platform_info.col_load_address =
+                       DEFAULT_JAILHOUSE_CELL_LOAD_VADDR;
+       }
+
+       root_cell->col_load_address = config->platform_info.col_load_address;
+#endif
        error_code = 0;
 
        preempt_disable();
diff --git a/include/jailhouse/cell-config.h b/include/jailhouse/cell-config.h
index 8985f8a3..25f6860d 100644
--- a/include/jailhouse/cell-config.h
+++ b/include/jailhouse/cell-config.h
@@ -314,6 +314,12 @@ struct jailhouse_system {
                 * the platform in use.
                 */
                __u64 llc_way_size;
+               /**
+                * Start address used when loading binaries into colored memory
+                * regions. This value should be set so that it does not overlap
+                * with platform memory mappings.
+                */
+               __u64 col_load_address;
                union {
                        struct {
                                __u16 pm_timer_address;
-- 
2.25.1

-- 
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/20200421100351.292395-4-ms%40xt3.it.

Reply via email to