Skip to content

Commit

Permalink
configs, driver, tools: Add and validate config revision
Browse files Browse the repository at this point in the history
A common source of breakages during development and testing is to run
with outdated configuration files against newer binaries, or vice versa.
Catch and report this by converting the last 2 bytes of the system and
cell config signatures into a revision number. Whenever we change their
layout or semantic, this number shall be increased.

Configs were auto-converted via

sed -i -e '/\.signature =/a\\t\t.revision = JAILHOUSE_CONFIG_REVISION,' \
    `git ls-files configs/*.c`

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
  • Loading branch information
jan-kiszka committed Nov 27, 2016
1 parent c295bdb commit 80226df
Show file tree
Hide file tree
Showing 39 changed files with 61 additions and 6 deletions.
1 change: 1 addition & 0 deletions configs/amd-seattle-gic-demo.c
Expand Up @@ -22,6 +22,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "gic-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/amd-seattle-linux-demo.c
Expand Up @@ -24,6 +24,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "linux-inmate-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/amd-seattle-uart-demo.c
Expand Up @@ -22,6 +22,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "pl011-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/amd-seattle.c
Expand Up @@ -24,6 +24,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0x82fc000000,
.size = 0x4000000,
Expand Down
1 change: 1 addition & 0 deletions configs/apic-demo.c
Expand Up @@ -26,6 +26,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "apic-demo",

.cpu_set_size = sizeof(config.cpus),
Expand Down
1 change: 1 addition & 0 deletions configs/bananapi-gic-demo.c
Expand Up @@ -25,6 +25,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "bananapi-gic-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/bananapi-linux-demo.c
Expand Up @@ -27,6 +27,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "bananapi-linux-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/bananapi-uart-demo.c
Expand Up @@ -25,6 +25,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "bananapi-uart-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/bananapi.c
Expand Up @@ -26,6 +26,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0x7c000000,
.size = 0x4000000,
Expand Down
1 change: 1 addition & 0 deletions configs/e1000-demo.c
Expand Up @@ -28,6 +28,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "e1000-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/f2a88xm-hd3.c
Expand Up @@ -33,6 +33,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0x3b000000,
.size = 0x4000000,
Expand Down
1 change: 1 addition & 0 deletions configs/foundation-v8-gic-demo.c
Expand Up @@ -22,6 +22,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "gic-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/foundation-v8-linux-demo.c
Expand Up @@ -23,6 +23,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "linux-inmate-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/foundation-v8-uart-demo.c
Expand Up @@ -22,6 +22,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "pl011-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/foundation-v8.c
Expand Up @@ -23,6 +23,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0xfc000000,
.size = 0x4000000,
Expand Down
1 change: 1 addition & 0 deletions configs/h87i.c
Expand Up @@ -28,6 +28,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0x3b000000,
.size = 0x4000000,
Expand Down
1 change: 1 addition & 0 deletions configs/hikey-gic-demo.c
Expand Up @@ -22,6 +22,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "gic-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/hikey-linux-demo.c
Expand Up @@ -27,6 +27,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "hikey-linux-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/hikey.c
Expand Up @@ -24,6 +24,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0x7c000000,
.size = 0x04000000,
Expand Down
1 change: 1 addition & 0 deletions configs/imb-a180.c
Expand Up @@ -32,6 +32,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0x3b000000,
.size = 0x4000000,
Expand Down
1 change: 1 addition & 0 deletions configs/ioapic-demo.c
Expand Up @@ -27,6 +27,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "ioapic-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/ivshmem-demo.c
Expand Up @@ -25,6 +25,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "ivshmem-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/jetson-tk1-demo.c
Expand Up @@ -25,6 +25,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "jetson-tk1-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/jetson-tk1-linux-demo.c
Expand Up @@ -27,6 +27,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "jetson-tk1-linux-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG|JAILHOUSE_CELL_DEBUG_CONSOLE,

Expand Down
1 change: 1 addition & 0 deletions configs/jetson-tk1.c
Expand Up @@ -29,6 +29,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0xfc000000,
.size = 0x4000000 - 0x100000, /* -1MB (PSCI) */
Expand Down
1 change: 1 addition & 0 deletions configs/linux-x86-demo.c
Expand Up @@ -27,6 +27,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "linux-x86-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/pci-demo.c
Expand Up @@ -28,6 +28,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "pci-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/qemu-vm.c
Expand Up @@ -42,6 +42,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0x3b000000,
.size = 0x600000,
Expand Down
1 change: 1 addition & 0 deletions configs/smp-demo.c
Expand Up @@ -25,6 +25,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "smp-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/tiny-demo.c
Expand Up @@ -26,6 +26,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "tiny-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/vexpress-gic-demo.c
Expand Up @@ -22,6 +22,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "gic-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/vexpress-linux-demo.c
Expand Up @@ -23,6 +23,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "linux-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/vexpress-uart-demo.c
Expand Up @@ -22,6 +22,7 @@ struct {
} __attribute__((packed)) config = {
.cell = {
.signature = JAILHOUSE_CELL_DESC_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.name = "pl011-demo",
.flags = JAILHOUSE_CELL_PASSIVE_COMMREG,

Expand Down
1 change: 1 addition & 0 deletions configs/vexpress.c
Expand Up @@ -23,6 +23,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = 0xfc000000,
.size = 0x4000000,
Expand Down
5 changes: 5 additions & 0 deletions driver/cell.c
Expand Up @@ -173,6 +173,11 @@ int jailhouse_cmd_cell_create(struct jailhouse_cell_create __user *arg)
err = -EINVAL;
goto kfree_config_out;
}
if (config->revision != JAILHOUSE_CONFIG_REVISION) {
pr_err("jailhouse: Configuration revision mismatch\n");
err = -EINVAL;
goto kfree_config_out;
}

config->name[JAILHOUSE_CELL_NAME_MAXLEN] = 0;

Expand Down
4 changes: 4 additions & 0 deletions driver/main.c
Expand Up @@ -211,6 +211,10 @@ static int jailhouse_cmd_enable(struct jailhouse_system __user *arg)
pr_err("jailhouse: Not a system configuration\n");
return -EINVAL;
}
if (config_header.revision != JAILHOUSE_CONFIG_REVISION) {
pr_err("jailhouse: Configuration revision mismatch\n");
return -EINVAL;
}

config_header.root_cell.name[JAILHOUSE_CELL_NAME_MAXLEN] = 0;

Expand Down
14 changes: 10 additions & 4 deletions hypervisor/include/jailhouse/cell-config.h
Expand Up @@ -39,12 +39,15 @@
#ifndef _JAILHOUSE_CELL_CONFIG_H
#define _JAILHOUSE_CELL_CONFIG_H

/* Incremented on any layout or semantic change of system or cell config. */
#define JAILHOUSE_CONFIG_REVISION 1

#define JAILHOUSE_CELL_NAME_MAXLEN 31

#define JAILHOUSE_CELL_PASSIVE_COMMREG 0x00000001
#define JAILHOUSE_CELL_DEBUG_CONSOLE 0x00000002

#define JAILHOUSE_CELL_DESC_SIGNATURE "JAILCELL"
#define JAILHOUSE_CELL_DESC_SIGNATURE "JHCELL"

/**
* The jailhouse cell configuration.
Expand All @@ -53,7 +56,9 @@
* structure.
*/
struct jailhouse_cell_desc {
char signature[8];
char signature[6];
__u16 revision;

char name[JAILHOUSE_CELL_NAME_MAXLEN+1];
__u32 id; /* set by the driver */
__u32 flags;
Expand Down Expand Up @@ -166,13 +171,14 @@ struct jailhouse_iommu {
__u32 amd_features;
} __attribute__((packed));

#define JAILHOUSE_SYSTEM_SIGNATURE "JAILSYST"
#define JAILHOUSE_SYSTEM_SIGNATURE "JHSYST"

/**
* General descriptor of the system.
*/
struct jailhouse_system {
char signature[8];
char signature[6];
__u16 revision;

/** Jailhouse's location in memory */
struct jailhouse_memory hypervisor_memory;
Expand Down
9 changes: 7 additions & 2 deletions tools/jailhouse-cell-linux
Expand Up @@ -509,12 +509,14 @@ class MemoryRegion:


class Config:
_HEADER_FORMAT = '8s32s4xIIIIIIIII'
_HEADER_FORMAT = '6sH32s4xIIIIIIIII'
_HEADER_REVISION = 1

def __init__(self, config_file):
self.data = config_file.read()

(signature,
revision,
name,
self.flags,
self.cpu_set_size,
Expand All @@ -526,10 +528,13 @@ class Config:
self.num_pci_caps,
self.vpci_irq_base) = \
struct.unpack_from(Config._HEADER_FORMAT, self.data)
if str(signature.decode()) != 'JAILCELL':
if str(signature.decode()) != 'JHCELL':
print('Not a cell configuration: %s' % config_file.name,
file=sys.stderr)
exit(1)
if revision != Config._HEADER_REVISION:
print('Configuration file revision mismatch', file=sys.stderr)
exit(1)
self.name = str(name.decode())

memregion_offs = struct.calcsize(Config._HEADER_FORMAT) + \
Expand Down
1 change: 1 addition & 0 deletions tools/root-cell-config.c.tmpl
Expand Up @@ -55,6 +55,7 @@ struct {
} __attribute__((packed)) config = {
.header = {
.signature = JAILHOUSE_SYSTEM_SIGNATURE,
.revision = JAILHOUSE_CONFIG_REVISION,
.hypervisor_memory = {
.phys_start = ${hex(hvmem[0])},
.size = ${hex(hvmem[1])},
Expand Down

0 comments on commit 80226df

Please sign in to comment.