Skip to content

Commit

Permalink
driver: ioremap the hypervisor firmware to any kernel address
Browse files Browse the repository at this point in the history
At the moment the Linux driver maps the Jailhouse binary to
JAILHOUSE_BASE. The underlying assumption is that Linux may map the
firmware (in the Linux kernel space), to the same virtual address it
has been built to run from.

This assumption is unworkable on ARMv8 processors running in AArch64
mode. Kernel memory is allocated in a high address region, that is
not addressable from EL2, where the hypervisor will run from.

This patch removes the assumption, by introducing the
JAILHOUSE_BORROW_ROOT_PT define, which signals the behavior of the
current architectures.

We also turn the entry point in the header, into an offset from the
Jailhouse load address, so we can enter the image regardless of
where it  will be mapped.

Signed-off-by: Antonios Motakis <antonios.motakis@huawei.com>
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
tvelocity authored and jan-kiszka committed Jun 26, 2016
1 parent 7287a5a commit eda9305
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
16 changes: 14 additions & 2 deletions driver/main.c
Expand Up @@ -139,11 +139,14 @@ static void enter_hypervisor(void *info)
{
struct jailhouse_header *header = info;
unsigned int cpu = smp_processor_id();
int (*entry)(unsigned int);
int err;

entry = header->entry + (unsigned long) hypervisor_mem;

if (cpu < header->max_cpus)
/* either returns 0 or the same error code across all CPUs */
err = header->entry(cpu);
err = entry(cpu);
else
err = -EINVAL;

Expand Down Expand Up @@ -178,6 +181,7 @@ static int jailhouse_cmd_enable(struct jailhouse_system __user *arg)
struct jailhouse_system *config;
struct jailhouse_memory *hv_mem = &config_header.hypervisor_memory;
struct jailhouse_header *header;
unsigned long remap_addr = 0;
void __iomem *console = NULL;
unsigned long config_size;
const char *fw_name;
Expand Down Expand Up @@ -235,7 +239,10 @@ static int jailhouse_cmd_enable(struct jailhouse_system __user *arg)
config_size >= hv_mem->size - hv_core_and_percpu_size)
goto error_release_fw;

hypervisor_mem = jailhouse_ioremap(hv_mem->phys_start, JAILHOUSE_BASE,
#ifdef JAILHOUSE_BORROW_ROOT_PT
remap_addr = JAILHOUSE_BASE;
#endif
hypervisor_mem = jailhouse_ioremap(hv_mem->phys_start, remap_addr,
hv_mem->size);
if (!hypervisor_mem) {
pr_err("jailhouse: Unable to map RAM reserved for hypervisor "
Expand All @@ -258,6 +265,7 @@ static int jailhouse_cmd_enable(struct jailhouse_system __user *arg)
}

if (config->debug_console.flags & JAILHOUSE_MEM_IO) {
#ifdef JAILHOUSE_BORROW_ROOT_PT
console = ioremap(config->debug_console.phys_start,
config->debug_console.size);
if (!console) {
Expand All @@ -270,6 +278,10 @@ static int jailhouse_cmd_enable(struct jailhouse_system __user *arg)
/* The hypervisor has no notion of address spaces, so we need
* to enforce conversion. */
header->debug_console_base = (void * __force)console;
#else
header->debug_console_base =
(void * __force) config->debug_console.phys_start;
#endif
}

err = jailhouse_cell_prepare_root(&config->root_cell);
Expand Down
1 change: 1 addition & 0 deletions hypervisor/arch/arm/include/asm/jailhouse_hypercall.h
Expand Up @@ -37,6 +37,7 @@
*/

#define JAILHOUSE_BASE 0xf0000000
#define JAILHOUSE_BORROW_ROOT_PT 1

#define JAILHOUSE_CALL_INS ".arch_extension virt\n\t" \
"hvc #0x4a48"
Expand Down
3 changes: 2 additions & 1 deletion hypervisor/arch/x86/include/asm/jailhouse_hypercall.h
Expand Up @@ -36,7 +36,8 @@
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#define JAILHOUSE_BASE __MAKE_UL(0xfffffffff0000000)
#define JAILHOUSE_BASE __MAKE_UL(0xfffffffff0000000)
#define JAILHOUSE_BORROW_ROOT_PT 1

/*
* As this is never called on a CPU without VM extensions,
Expand Down
2 changes: 1 addition & 1 deletion hypervisor/setup.c
Expand Up @@ -210,5 +210,5 @@ hypervisor_header = {
.signature = JAILHOUSE_SIGNATURE,
.core_size = (unsigned long)__page_pool - JAILHOUSE_BASE,
.percpu_size = sizeof(struct per_cpu),
.entry = arch_entry,
.entry = arch_entry - JAILHOUSE_BASE,
};

0 comments on commit eda9305

Please sign in to comment.