From f392164b40a5bfaf7d822eb317cba0e6212de7fe Mon Sep 17 00:00:00 2001 From: Junjie Mao Date: Wed, 2 Mar 2022 17:13:12 +0800 Subject: [PATCH] config_tools: add ivshmem providers A shared memory region can be provided either by the hypervisor or by the device model. Before recent schema changes this is telled by the "hv:/" or "dm:/" prefix. This patch adds another node under an IVSHMEM region to represent the provider, following the practice that information in the old-school encodings is split and put as separate XML nodes. Tracked-On: #6690 Signed-off-by: Junjie Mao --- .../data/cfl-k700-i7/hybrid_rt.xml | 4 +- .../data/generic_board/hybrid_rt.xml | 4 +- .../data/whl-ipc-i5/hybrid_rt.xml | 4 +- misc/config_tools/scenario_config/upgrader.py | 21 ++++++---- misc/config_tools/schema/types.xsd | 39 +++++++++++++++---- .../config_tools/static_allocators/lib/lib.py | 7 +++- misc/config_tools/xforms/config_common.xsl | 2 +- misc/config_tools/xforms/ivshmem_cfg.h.xsl | 13 +++---- misc/config_tools/xforms/lib.xsl | 8 ++-- misc/config_tools/xforms/pci_dev.c.xsl | 6 +-- 10 files changed, 73 insertions(+), 35 deletions(-) mode change 100755 => 100644 misc/config_tools/xforms/ivshmem_cfg.h.xsl diff --git a/misc/config_tools/data/cfl-k700-i7/hybrid_rt.xml b/misc/config_tools/data/cfl-k700-i7/hybrid_rt.xml index d7f54ddcd..bdbff8db0 100644 --- a/misc/config_tools/data/cfl-k700-i7/hybrid_rt.xml +++ b/misc/config_tools/data/cfl-k700-i7/hybrid_rt.xml @@ -25,7 +25,9 @@ n n - + + shm_region_0 + Hypervisor 2 diff --git a/misc/config_tools/data/generic_board/hybrid_rt.xml b/misc/config_tools/data/generic_board/hybrid_rt.xml index 316411c5e..b8c74ef67 100644 --- a/misc/config_tools/data/generic_board/hybrid_rt.xml +++ b/misc/config_tools/data/generic_board/hybrid_rt.xml @@ -38,7 +38,9 @@ n n - + + shm_region_0 + Hypervisor 2 diff --git a/misc/config_tools/data/whl-ipc-i5/hybrid_rt.xml b/misc/config_tools/data/whl-ipc-i5/hybrid_rt.xml index e38f0fc2c..79bc50b88 100644 --- a/misc/config_tools/data/whl-ipc-i5/hybrid_rt.xml +++ b/misc/config_tools/data/whl-ipc-i5/hybrid_rt.xml @@ -25,7 +25,9 @@ n n - + + shm_region_0 + Hypervisor 2 diff --git a/misc/config_tools/scenario_config/upgrader.py b/misc/config_tools/scenario_config/upgrader.py index 8866f861d..7dfafed13 100755 --- a/misc/config_tools/scenario_config/upgrader.py +++ b/misc/config_tools/scenario_config/upgrader.py @@ -124,12 +124,14 @@ class VirtualUartConnections: return [new_parent_node] class SharedMemoryRegions: - class SharedMemoryRegion(namedtuple("SharedMemoryRegion", ["name", "size", "shared_vms"])): + class SharedMemoryRegion(namedtuple("SharedMemoryRegion", ["provided_by", "name", "size", "shared_vms"])): # The BDF of IVSHMEM PCI functions starts from 00:08.0 next_dev = defaultdict(lambda: 8) + nr_regions = 0 @classmethod - def from_hypervisor_encoding(cls, text, old_xml_etree): + def from_encoding(cls, text, old_xml_etree): + provided_by = "Device Model" if text.startswith("dm:/") else "Hypervisor" parts = [p.strip() for p in text[text.find("/") + 1 :].split(",")] name = parts[0] size = parts[1] @@ -147,22 +149,27 @@ class SharedMemoryRegions: cls.next_dev[vm_name] += 1 shared_vms.append((vm_name, f"00:{dev:02x}.0")) - return cls(name, size, shared_vms) + return cls(provided_by, name, size, shared_vms) @classmethod def from_xml_node(cls, node): - name = node.get("name") + cls.nr_regions += 1 + name = node.get("name") if "name" in node.keys() else \ + node.find("NAME").text if node.find("NAME") is not None else \ + f"shared_memory_region_{nr_regions}" + provided_by = node.find("PROVIDED_BY").text if node.find("PROVIDED_BY") is not None else "Hypervisor" size = node.find("IVSHMEM_SIZE").text shared_vms = [] for shared_vm_node in node.find("IVSHMEM_VMS"): vm_name = shared_vm_node.find("VM_NAME").text vbdf = shared_vm_node.find("VBDF").text shared_vms.append((vm_name, vbdf)) - return cls(name, size, shared_vms) + return cls(provided_by, name, size, shared_vms) def format_xml_element(self): node = etree.Element("IVSHMEM_REGION") - node.set("name", self.name) + etree.SubElement(node, "NAME").text = self.name + etree.SubElement(node, "PROVIDED_BY").text = self.provided_by etree.SubElement(node, "IVSHMEM_SIZE").text = self.size vms_node = etree.SubElement(node, "IVSHMEM_VMS") @@ -182,7 +189,7 @@ class SharedMemoryRegions: if len(ivshmem_region_node) == 0: # ACRN v2.x format - region = self.SharedMemoryRegion.from_hypervisor_encoding(ivshmem_region_node.text, self.old_xml_etree) + region = self.SharedMemoryRegion.from_encoding(ivshmem_region_node.text, self.old_xml_etree) self.regions[region.name] = region else: # ACRN v3.x format diff --git a/misc/config_tools/schema/types.xsd b/misc/config_tools/schema/types.xsd index ccb14249a..70d1d99b2 100644 --- a/misc/config_tools/schema/types.xsd +++ b/misc/config_tools/schema/types.xsd @@ -1,5 +1,7 @@ - + @@ -152,7 +154,7 @@ Read more about the available scheduling options in :ref:`cpu_sharing`. - + @@ -161,10 +163,17 @@ Read more about the available scheduling options in :ref:`cpu_sharing`. + + + + + + + - + Name of the VM which use this IVSHMEM. @@ -202,21 +211,35 @@ device in VM . Set in hex. - + + + + Name of the shared memory region. + + + + + + + + + + Whether the shared memory region is emulated by the hypervisor or device model. + + - + Memory size of inter-VM shared memory (IVSHMEM) in megabytes. The value should be a power of 2 and no more than 512. - + Set all VMs which use this IVSHMEM. - - + diff --git a/misc/config_tools/static_allocators/lib/lib.py b/misc/config_tools/static_allocators/lib/lib.py index 7971987d8..cc12f342f 100644 --- a/misc/config_tools/static_allocators/lib/lib.py +++ b/misc/config_tools/static_allocators/lib/lib.py @@ -97,7 +97,10 @@ def get_ivshmem_regions_by_tree(etree): ivshmem_regions = etree.xpath("//IVSHMEM_REGION") shmem_regions = {} for idx in range(len(ivshmem_regions)): - shm_name = ivshmem_regions[idx].get('name') + provided_by = common.get_node("./PROVIDED_BY/text()", ivshmem_regions[idx]) + if provided_by != "Hypervisor": + continue + shm_name = common.get_node("./NAME/text()", ivshmem_regions[idx]) if shm_name is None: continue shm_size = common.get_node("./IVSHMEM_SIZE/text()", ivshmem_regions[idx]) @@ -117,7 +120,7 @@ def get_ivshmem_enabled_by_tree(etree): if len(ivshmem_vms) != 0: shmem_enabled = 'y' return shmem_enabled - + def is_pre_launched_vm(vm_type): if vm_type == 'PRE_LAUNCHED_VM': return True diff --git a/misc/config_tools/xforms/config_common.xsl b/misc/config_tools/xforms/config_common.xsl index 677101e0d..e2b77351a 100644 --- a/misc/config_tools/xforms/config_common.xsl +++ b/misc/config_tools/xforms/config_common.xsl @@ -143,7 +143,7 @@ - + diff --git a/misc/config_tools/xforms/ivshmem_cfg.h.xsl b/misc/config_tools/xforms/ivshmem_cfg.h.xsl old mode 100755 new mode 100644 index 439c9ff59..ee89369a0 --- a/misc/config_tools/xforms/ivshmem_cfg.h.xsl +++ b/misc/config_tools/xforms/ivshmem_cfg.h.xsl @@ -26,7 +26,7 @@ - + @@ -39,9 +39,8 @@ - - - + + @@ -49,12 +48,12 @@ - + - + @@ -62,7 +61,7 @@ - + { \ diff --git a/misc/config_tools/xforms/lib.xsl b/misc/config_tools/xforms/lib.xsl index 27bd7d174..6b3631d8c 100644 --- a/misc/config_tools/xforms/lib.xsl +++ b/misc/config_tools/xforms/lib.xsl @@ -307,8 +307,8 @@ - - + + @@ -322,9 +322,9 @@ - + - + diff --git a/misc/config_tools/xforms/pci_dev.c.xsl b/misc/config_tools/xforms/pci_dev.c.xsl index 250fe74b4..8626dae94 100644 --- a/misc/config_tools/xforms/pci_dev.c.xsl +++ b/misc/config_tools/xforms/pci_dev.c.xsl @@ -143,7 +143,7 @@ - + { @@ -153,14 +153,14 @@ - + - + },