From 84432e3aed420288f631182504d3776c18dac60c Mon Sep 17 00:00:00 2001 From: Jan Kiszka Date: Mon, 25 Jan 2016 18:20:37 +0100 Subject: [PATCH] core, driver: Pass rounded-up core size in hypervisor header Hypervisor and root kernel may have different ideas about PAGE_SIZE. This will cause wrong hypervisor core size calculations as seen on arm64 with 64K Linux PAGE_SIZE. Avoid this trap by moving the round-up into the hypervisor code, passing a ready-to-be-used size value in the header. Signed-off-by: Jan Kiszka --- driver/main.c | 2 +- hypervisor/hypervisor.lds.S | 1 - hypervisor/include/jailhouse/header.h | 2 +- hypervisor/setup.c | 4 ++-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/driver/main.c b/driver/main.c index 9bb3d5e..60b67bd 100644 --- a/driver/main.c +++ b/driver/main.c @@ -228,7 +228,7 @@ static int jailhouse_cmd_enable(struct jailhouse_system __user *arg) hypervisor->size >= hv_mem->size) goto error_release_fw; - hv_core_and_percpu_size = PAGE_ALIGN(header->core_size) + + hv_core_and_percpu_size = header->core_size + max_cpus * header->percpu_size; config_size = jailhouse_system_config_size(&config_header); if (hv_core_and_percpu_size >= hv_mem->size || diff --git a/hypervisor/hypervisor.lds.S b/hypervisor/hypervisor.lds.S index e5b1551..09b1a0b 100644 --- a/hypervisor/hypervisor.lds.S +++ b/hypervisor/hypervisor.lds.S @@ -34,7 +34,6 @@ SECTIONS . = ALIGN(16); .bss : { *(.bss) } - __hv_core_end = .; . = ALIGN(PAGE_SIZE); __page_pool = .; diff --git a/hypervisor/include/jailhouse/header.h b/hypervisor/include/jailhouse/header.h index db87b60..4a4d1cb 100644 --- a/hypervisor/include/jailhouse/header.h +++ b/hypervisor/include/jailhouse/header.h @@ -29,7 +29,7 @@ struct jailhouse_header { /** Signature "JAILHOUS". * @note Filled at build time. */ char signature[8]; - /** Size of hypervisor core. + /** Size of hypervisor core, rounded up to page boundary. * @note Filled at build time. */ unsigned long core_size; /** Size of per-CPU data structure. diff --git a/hypervisor/setup.c b/hypervisor/setup.c index 14a98d3..79f5696 100644 --- a/hypervisor/setup.c +++ b/hypervisor/setup.c @@ -20,7 +20,7 @@ #include #include -extern u8 __text_start[], __hv_core_end[]; +extern u8 __text_start[], __page_pool[]; static const __attribute__((aligned(PAGE_SIZE))) u8 empty_page[PAGE_SIZE]; @@ -202,7 +202,7 @@ int entry(unsigned int cpu_id, struct per_cpu *cpu_data) struct jailhouse_header __attribute__((section(".header"))) hypervisor_header = { .signature = JAILHOUSE_SIGNATURE, - .core_size = (unsigned long)__hv_core_end - JAILHOUSE_BASE, + .core_size = (unsigned long)__page_pool - JAILHOUSE_BASE, .percpu_size = sizeof(struct per_cpu), .entry = arch_entry, }; -- 2.39.2