From: Jan Kiszka <[email protected]> This updates the config and sysfs parser as well as the config generator to the new format.
For generating x86 configs, we are parsing /proc/cpuinfo for the initial APIC ID and use that - in Linux order - to fill out the config template. Signed-off-by: Jan Kiszka <[email protected]> --- pyjailhouse/config_parser.py | 13 +++++++++---- pyjailhouse/sysfs_parser.py | 20 ++++++++++++++++++-- tools/jailhouse-config-create | 14 +++----------- tools/root-cell-config.c.tmpl | 15 +++++++-------- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/pyjailhouse/config_parser.py b/pyjailhouse/config_parser.py index 7a7f48a3..fc2158e1 100644 --- a/pyjailhouse/config_parser.py +++ b/pyjailhouse/config_parser.py @@ -1,7 +1,7 @@ # # Jailhouse, a Linux-based partitioning hypervisor # -# Copyright (c) Siemens AG, 2015-2020 +# Copyright (c) Siemens AG, 2015-2022 # # Authors: # Jan Kiszka <[email protected]> @@ -19,7 +19,7 @@ import struct from .extendedenum import ExtendedEnum # Keep the whole file in sync with include/jailhouse/cell-config.h. -_CONFIG_REVISION = 13 +_CONFIG_REVISION = 14 def flag_str(enum_class, value, separator=' | '): @@ -104,6 +104,11 @@ class MemRegion: self.virt_address_in_region(region.virt_start) +class Cpu: + _REGION_FORMAT = 'QI4x' + SIZE = struct.calcsize(_REGION_FORMAT) + + class CacheRegion: _REGION_FORMAT = 'IIBxH' SIZE = struct.calcsize(_REGION_FORMAT) @@ -145,7 +150,7 @@ class CellConfig: revision, name, self.flags, - self.cpu_set_size, + self.num_cpus, self.num_memory_regions, self.num_cache_regions, self.num_irqchips, @@ -164,7 +169,7 @@ class CellConfig: self.name = str(name.decode().strip('\0')) mem_region_offs = struct.calcsize(CellConfig._HEADER_FORMAT) + \ - self.cpu_set_size + self.num_cpus * Cpu.SIZE self.memory_regions = [] for n in range(self.num_memory_regions): self.memory_regions.append( diff --git a/pyjailhouse/sysfs_parser.py b/pyjailhouse/sysfs_parser.py index 7f19fb57..d708d213 100644 --- a/pyjailhouse/sysfs_parser.py +++ b/pyjailhouse/sysfs_parser.py @@ -1,7 +1,7 @@ # # Jailhouse, a Linux-based partitioning hypervisor # -# Copyright (c) Siemens AG, 2014-2017 +# Copyright (c) Siemens AG, 2014-2022 # Copyright (c) Valentine Sinitsyn, 2014-2015 # # Authors: @@ -48,7 +48,6 @@ inputs['files'].add('/proc/cmdline') inputs['files'].add('/proc/ioports') inputs['files'].add('/sys/bus/pci/devices/*/config') inputs['files'].add('/sys/bus/pci/devices/*/resource') -inputs['files'].add('/sys/devices/system/cpu/cpu*/uevent') inputs['files'].add('/sys/firmware/acpi/tables/APIC') inputs['files'].add('/sys/firmware/acpi/tables/MCFG') # optional files @@ -635,6 +634,18 @@ def parse_ivrs(pcidevices, ioapics): return units, regions +def parse_cpus(): + cpus = [] + with input_open('/proc/cpuinfo') as f: + for line in f: + if not line.strip(): + continue + key, value = line.split(':') + if key.strip() == 'initial apicid': + cpus.append(CPU(int(value))) + return cpus + + def get_cpu_vendor(): with open(root_dir + '/proc/cpuinfo') as f: for line in f: @@ -646,6 +657,11 @@ def get_cpu_vendor(): raise RuntimeError('Broken %s/proc/cpuinfo' % root_dir) +class CPU: + def __init__(self, phys_id): + self.phys_id = phys_id + + class PCIBARs: IORESOURCE_IO = 0x00000100 IORESOURCE_MEM = 0x00000200 diff --git a/tools/jailhouse-config-create b/tools/jailhouse-config-create index c2cd5952..bf2589bd 100755 --- a/tools/jailhouse-config-create +++ b/tools/jailhouse-config-create @@ -2,7 +2,7 @@ # # Jailhouse, a Linux-based partitioning hypervisor # -# Copyright (c) Siemens AG, 2014-2017 +# Copyright (c) Siemens AG, 2014-2022 # Copyright (c) Valentine Sinitsyn, 2014-2015 # # Authors: @@ -153,14 +153,6 @@ def alloc_mem(regions, size): raise RuntimeError('failed to allocate memory') -def count_cpus(): - list = sysfs_parser.input_listdir('/sys/devices/system/cpu', ['cpu*/uevent']) - count = 0 - for f in list: - if re.match(r'cpu[0-9]+', f): - count += 1 - return count - class MMConfig: def __init__(self, base, end_bus): self.base = base @@ -252,10 +244,10 @@ product = [ input_readline('/sys/class/dmi/id/sys_vendor', True).rstrip(), input_readline('/sys/class/dmi/id/product_name', True).rstrip(), ] -cpu_count = count_cpus() mmconfig = MMConfig.parse() # Query devices +cpus = sysfs_parser.parse_cpus() pci_devices = sysfs_parser.parse_pcidevices() (mem_regions, dmar_regions) = sysfs_parser.parse_iomem(pci_devices) (port_regions, pm_timer_base) = sysfs_parser.parse_ioports() @@ -312,6 +304,7 @@ mem_regions.append(sysfs_parser.MemRegion(ourmem[0] + hvmem[1], 'JAILHOUSE Inmate Memory')) kwargs = { + 'cpus': cpus, 'mem_regions': mem_regions, 'port_regions': port_regions, 'ourmem': ourmem, @@ -320,7 +313,6 @@ kwargs = { 'product': product, 'pcidevices': pci_devices, 'pcicaps': pci_caps, - 'cpucount': cpu_count, 'irqchips': ioapics, 'pm_timer_base': pm_timer_base, 'vtd_interrupt_limit': vtd_interrupt_limit, diff --git a/tools/root-cell-config.c.tmpl b/tools/root-cell-config.c.tmpl index c28fcfa4..8f133757 100644 --- a/tools/root-cell-config.c.tmpl +++ b/tools/root-cell-config.c.tmpl @@ -1,7 +1,7 @@ /* * Jailhouse, a Linux-based partitioning hypervisor * - * Copyright (c) Siemens AG, 2014-2017 + * Copyright (c) Siemens AG, 2014-2022 * * This work is licensed under the terms of the GNU GPL, version 2. See * the COPYING file in the top-level directory. @@ -44,7 +44,7 @@ struct { struct jailhouse_system header; - __u64 cpus[${int((cpucount + 63) / 64)}]; + struct jailhouse_cpu cpus[${len(cpus)}]; struct jailhouse_memory mem_regions[${len(mem_regions)}]; struct jailhouse_irqchip irqchips[${len(irqchips)}]; struct jailhouse_pio pio_regions[${len([1 for r in port_regions if r.permit])}]; @@ -107,7 +107,7 @@ struct { }, .root_cell = { .name = "RootCell", - .cpu_set_size = sizeof(config.cpus), + .num_cpus = ARRAY_SIZE(config.cpus), .num_memory_regions = ARRAY_SIZE(config.mem_regions), .num_irqchips = ARRAY_SIZE(config.irqchips), .num_pio_regions = ARRAY_SIZE(config.pio_regions), @@ -117,12 +117,11 @@ struct { }, .cpus = { - % for n in range(int(cpucount / 64)): - 0xffffffffffffffff, + % for c in cpus: + { + .phys_id = ${c.phys_id}, + }, % endfor - % if (cpucount % 64): - ${'0x%016x,' % ((1 << (cpucount % 64)) - 1)} - % endif }, .mem_regions = { -- 2.36.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/20220627131329.3659-16-ralf.ramsauer%40oth-regensburg.de.
