On 10.01.23 22:14, Ralf Ramsauer wrote:
> Signed-off-by: Ralf Ramsauer <[email protected]>
> ---
>  pyjailhouse/config_parser.py | 23 ++++++++++++++++++++---
>  tools/jailhouse-config-check | 30 ++++++++----------------------
>  2 files changed, 28 insertions(+), 25 deletions(-)
> 
> diff --git a/pyjailhouse/config_parser.py b/pyjailhouse/config_parser.py
> index e60b2ce9..2a59b651 100644
> --- a/pyjailhouse/config_parser.py
> +++ b/pyjailhouse/config_parser.py
> @@ -20,6 +20,21 @@ from .extendedenum import ExtendedEnum
>  
>  # Keep the whole file in sync with include/jailhouse/cell-config.h.
>  _CONFIG_REVISION = 14
> +JAILHOUSE_X86 = 0
> +JAILHOUSE_ARM = 1
> +JAILHOUSE_ARM64 = 2
> +
> +JAILHOUSE_ARCH_MAX = 2
> +
> +
> +def convert_arch(arch):
> +    if arch > JAILHOUSE_ARCH_MAX:
> +        raise RuntimeError('Configuration has unsupported architecture')
> +    return {
> +        JAILHOUSE_X86: 'x86',
> +        JAILHOUSE_ARM: 'arm',
> +        JAILHOUSE_ARM64: 'arm64',
> +    }[arch]
>  
>  
>  def flag_str(enum_class, value, separator=' | '):
> @@ -163,6 +178,7 @@ class CellConfig:
>                  if revision != _CONFIG_REVISION:
>                      raise RuntimeError('Configuration file revision 
> mismatch')
>              self.name = str(name.decode().strip('\0'))
> +            self.arch = convert_arch(self.arch)
>  
>              mem_region_offs = struct.calcsize(CellConfig._HEADER_FORMAT) + \
>                  self.cpu_set_size
> @@ -242,7 +258,7 @@ class SystemConfig:
>      _ARCH_ARM_FORMAT = '=BB2xQQQQQ'
>      _ARCH_X86_FORMAT = '=HBxIII28x'
>  
> -    def __init__(self, data, arch):
> +    def __init__(self, data):
>          self.data = data
>  
>          try:
> @@ -253,6 +269,7 @@ class SystemConfig:
>                  raise RuntimeError('Not a root cell configuration')
>              if revision != _CONFIG_REVISION:
>                  raise RuntimeError('Configuration file revision mismatch')
> +            self.arch = convert_arch(self.arch)
>  
>              offs = struct.calcsize(self._HEADER_FORMAT)
>              self.hypervisor_memory = MemRegion(self.data[offs:])
> @@ -273,7 +290,7 @@ class SystemConfig:
>                      self.iommus.append(iommu)
>                  offs += IOMMU.SIZE
>  
> -            if arch in ('arm', 'arm64'):
> +            if self.arch in ('arm', 'arm64'):
>                  (self.arm_maintenance_irq,
>                   self.arm_gic_version,
>                   self.arm_gicd_base,
> @@ -282,7 +299,7 @@ class SystemConfig:
>                   self.arm_gicv_base,
>                   self.arm_gicr_base) = \
>                       struct.unpack_from(self._ARCH_ARM_FORMAT, 
> self.data[offs:])
> -            elif arch == 'x86':
> +            elif self.arch == 'x86':
>                  (self.x86_pm_timer_address,
>                   self.x86_apic_mode,
>                   self.x86_vtd_interrupt_limit,
> diff --git a/tools/jailhouse-config-check b/tools/jailhouse-config-check
> index d6ea7079..95de6fd4 100755
> --- a/tools/jailhouse-config-check
> +++ b/tools/jailhouse-config-check
> @@ -37,8 +37,6 @@ class ResourceRegion(config_parser.MemRegion):
>  sys.argv[0] = sys.argv[0].replace('-', ' ')
>  
>  parser = argparse.ArgumentParser(description='Check system and cell 
> configurations.')
> -parser.add_argument('-a', '--arch', metavar='ARCH',
> -                    help='target architecture')
>  parser.add_argument('syscfg', metavar='SYSCONFIG',
>                      type=argparse.FileType('rb'),
>                      help='system configuration file')
> @@ -52,36 +50,23 @@ except IOError as e:
>      print(e.strerror, file=sys.stderr)
>      exit(1)
>  
> -arch = args.arch
> -if not arch:
> -    arch_str = os.uname()[4]
> -    if arch_str in ('i686', 'x86_64'):
> -        arch = 'x86'
> -    elif arch_str == 'armv7l':
> -        arch = 'arm'
> -    elif arch_str == 'aarch64':
> -        arch = 'arm64'
> -    else:
> -        arch = None
> -if not arch in ('x86', 'arm', 'arm64'):
> -    print('Unsupported architecture', file=sys.stderr)
> -    exit(1)
> -
>  print("Reading configuration set:")
> -
>  try:
> -    sysconfig = config_parser.SystemConfig(args.syscfg.read(), arch)
> +    sysconfig = config_parser.SystemConfig(args.syscfg.read())
>      root_cell = sysconfig.root_cell
>  except RuntimeError as e:
>      print(str(e) + ": " + args.syscfg.name, file=sys.stderr)
>      exit(1)
>  cells = [root_cell]
> +print("  Architecture:  %s" % sysconfig.arch)
>  print("  Root cell:     %s (%s)" % (root_cell.name, args.syscfg.name))
>  
>  non_root_cells = []
>  for cfg in args.cellcfgs:
>      try:
>          cell = config_parser.CellConfig(cfg.read())
> +        if cell.arch != sysconfig.arch:
> +            raise RuntimeError('Cell architecture mismatch: %s' % cell.arch)
>      except RuntimeError as e:
>          print(str(e) + ": " + cfg.name, file=sys.stderr)
>          exit(1)
> @@ -162,9 +147,10 @@ if len(iommu_resources) > 0:
>                      ret=1
>      print("\n" if found else " None")
>  
> -print("Missing resource interceptions for architecture %s:" % arch, end='')
> +print("Missing resource interceptions for architecture %s:" % sysconfig.arch,
> +      end='')
>  found=False
> -if arch in ('arm', 'arm64'):
> +if sysconfig.arch in ('arm', 'arm64'):
>      arch_resources = []
>      if sysconfig.arm_gic_version == 2:
>          arch_resources.append(ResourceRegion(sysconfig.arm_gicd_base, 0x1000,
> @@ -183,7 +169,7 @@ if arch in ('arm', 'arm64'):
>      else:
>          raise RuntimeError("Unknown GIC version: %d" %
>                             sysconfig.arm_gic_version)
> -elif arch == 'x86':
> +elif sysconfig.arch == 'x86':
>      arch_resources = [ResourceRegion(0xfee00000, 0x1000, "xAPIC")]
>      for irqchip in root_cell.irqchips:
>          arch_resources.append(ResourceRegion(irqchip.address, 0x1000,

Thanks, all 3 applied to next.

Jan

-- 
Siemens AG, Technology
Competence Center Embedded Linux

-- 
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/a3144999-eb39-c18d-dc67-e38a5c2078af%40siemens.com.

Reply via email to