config_tools: implement existing scenario checks in XSD

Now we have transitioned to use XML schema to record all data validation
rules against board and scenario XMLs. While most checks originally in the
Python scripts are about the syntax of the XML files and thus naturally
covered by the XML schemas, there are still a few that conduct cross-check
on data consistency.

This patch migrates those checks into XML schema as assertions.

Tracked-On: #6690
Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2022-01-21 16:55:59 +08:00 committed by acrnsi-robot
parent 44f0c32735
commit d781b7bf17
7 changed files with 113 additions and 74 deletions

View File

@ -0,0 +1,35 @@
<?xml version="1.0"?>
<!-- Copyright (C) 2022 Intel Corporation. -->
<!-- SPDX-License-Identifier: BSD-3-Clause -->
<xs:schema xml:id="root"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:acrn="https://projectacrn.org">
<xs:assert test="every $cpu in vm//cpu_affinity/pcpu_id satisfies count(processors//thread[cpu_id = $cpu]) = 1">
<xs:annotation acrn:severity="warning" acrn:report-on="$cpu">
<xs:documentation>The physical CPU {$cpu} allocated to VM "{$cpu/ancestor::vm/name}" does not exist on the target board. Remove this CPU from the CPU affinity setting.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="every $vm in /acrn-config/vm satisfies
count(distinct-values($vm//cpu_affinity/pcpu_id)) = count($vm//cpu_affinity/pcpu_id)">
<xs:annotation acrn:severity="warning" acrn:report-on="$vm/cpu_affinity">
<xs:documentation>VM "{$vm/name}" repeats a physical CPU affinity assignment: {$vm//cpu_affinity/pcpu_id}. Remove the duplicates.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="every $pcpu in /acrn-config/vm[load_order = 'PRE_LAUNCHED_VM']//cpu_affinity/pcpu_id satisfies
count(/acrn-config/vm[@id != $pcpu/ancestor::vm//companion_vmid ]//cpu_affinity[pcpu_id = $pcpu]) &lt;= 1">
<xs:annotation acrn:severity="error" acrn:report-on="//vm//cpu_affinity[pcpu_id = $pcpu]">
<xs:documentation>Physical CPU {$pcpu} is assigned to pre-launched VM "{$pcpu/ancestor::vm/name}" and thus cannot be shared among multiple VMs. Look for, and probably remove any affinity assignments to {$pcpu} in these VM's settings: {//vm[cpu_affinity/pcpu_id = $pcpu]/name}.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="every $vm in vm satisfies
count(distinct-values(processors//thread[cpu_id = $vm//cpu_affinity/pcpu_id]/core_type)) &lt;= 1">
<xs:annotation acrn:severity="error" acrn:report-on="$vm//cpu_affinity">
<xs:documentation>The physical CPUs allocated to the VM "{$vm/name}" have both performance cores {processors//thread[cpu_id = $vm//cpu_affinity/pcpu_id and core_type = 'Core']/cpu_id} and efficient cores {processors//thread[cpu_id = $vm//cpu_affinity/pcpu_id and core_type = 'Atom']/cpu_id}, which is unsupported. Remove either all performance or all efficient cores from the CPU affinity.</xs:documentation>
</xs:annotation>
</xs:assert>
</xs:schema>

View File

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<!-- Copyright (C) 2022 Intel Corporation. -->
<!-- SPDX-License-Identifier: BSD-3-Clause -->
<xs:schema xml:id="root"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:acrn="https://projectacrn.org">
<xs:assert test="every $vm in /acrn-config/vm satisfies
not($vm//mmio_resources/TPM2 = 'y') or not($vm//mmio_resources/p2sb = 'y')">
<xs:annotation acrn:severity="error" acrn:report-on="$vm//mmio_resources">
<xs:documentation>VM "{$vm/name}" is assigned both a TPM2 and P2SB (Primary-to-Sideband bridge), which is not a supported configuration. Remove one of these choices.</xs:documentation>
</xs:annotation>
</xs:assert>
</xs:schema>

View File

@ -1,71 +0,0 @@
<?xml version="1.0"?>
<xs:schema xml:id="root"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:acrn="https://projectacrn.org">
<xs:assert test="every $cpu in vm/cpu_affinity/pcpu_id satisfies count(processors//thread[cpu_id = $cpu]) = 1">
<xs:annotation acrn:severity="warning">
<xs:documentation>The physical CPUs allocated to VMs shall exist on the target board.
This assertion checks that the physical CPUs that are explicitly allocated to VMs do exist on the target board. Failures
in meeting this assertion may cause the following.
- The hypervisor may access wrong per CPU regions, leading to random memory corruption.
- A VM may failed wake (by sending INIT-SIPI-SIPI IPIs) all the vCPUs allocated to it.
To fix this error, you can
- In the board XML, check whether all physical CPUs are encoded under the processors/ node. When generating the board
XML on the target board, make sure the native OS has not make any CPU offline.
- In the scenario XML, check whether the allocated CPUs are specified using consecutive integers starting from 0, not
their APIC IDs or x2APIC IDs.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="every $vm in vm satisfies
every $cpu in $vm/cpu_affinity/pcpu_id satisfies
processors//thread[cpu_id = $cpu]/core_type = processors//thread[cpu_id = $vm/cpu_affinity/pcpu_id[1]]/core_type">
<xs:annotation acrn:severity="error">
<xs:documentation>The physical CPUs allocated to the same VM shall have the same core types.
On platforms having both big and little cores, the current design of ACRN only allows allocating the same type of cores
to a pre-launched VM.
To fix this error, double check the allocation of physical CPUs to each pre-launched VM and ensure that only big cores
or little cores are assigned, but not both.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="hv//SSRAM_ENABLED = 'n' or empty(vm[load_order ='PRE_LAUNCHED_VM' and vm_type='RTVM']) or
every $cap in caches/cache[@level=3]/capability[@id='Software SRAM'] satisfies
(compare($cap/end, '0x80000000') &lt; 0 or compare($cap/start, '0xf8000000') &gt;= 0)">
<xs:annotation acrn:severity="warning">
<xs:documentation>The physical software SRAM region shall not overlap with pre-defined regions in guest.
When a pre-launched RT VM is enabled, the physical software SRAM is allocated to it at the same guest physical
address. Thus it is assumed that the software SRAM region does not overlap with any pre-defined region in the
pre-launched VM, such as the guest PCI hole which resides at 2G - 3.5G.
This error cannot be fixed by tweaking the configurations. Report to _GitHub:
https://github.com/projectacrn/acrn-hypervisor/issues if you meet this.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="(count(vm[load_order ='PRE_LAUNCHED_VM' and vm_type ='RTVM']) = 1 and count(vm[load_order ='POST_LAUNCHED_VM' and vm_type ='RTVM']) = 0)
or (count(vm[load_order ='PRE_LAUNCHED_VM' and vm_type ='RTVM']) = 0 and count(vm[load_order ='POST_LAUNCHED_VM' and vm_type ='RTVM']) &gt;= 0)">
<xs:annotation acrn:severity="error">
<xs:documentation>There should not be both pre-launched RTVM and post-launched RTVM.
And two or more pre-launched RTVM are not allowed.
This assertion checks below invalid scenario:
- Two or more pre-launched RTVM
- One pre-launched RTVM and one or more post-launched RTVM
To fix this error, please check the RTVM number to ensure the scenario configuration is valid.</xs:documentation>
</xs:annotation>
</xs:assert>
</xs:schema>

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<xs:schema xml:id="root"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:acrn="https://projectacrn.org">
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:acrn="https://projectacrn.org">
<xs:assert test="if (//VCAT_ENABLED = 'y')
then (//CDP_ENABLED = 'n' and //RDT_ENABLED = 'y')
@ -83,4 +83,20 @@
<xs:assert test="not (//hv//RDT/RDT_ENABLED = 'y' and //hv//SSRAM/SSRAM_ENABLED = 'y')"/>
<xs:assert test="hv//SSRAM_ENABLED = 'n' or empty(vm[load_order ='PRE_LAUNCHED_VM' and vm_type='RTVM']) or
every $cap in caches/cache[@level=3]/capability[@id='Software SRAM'] satisfies
(compare($cap/end, '0x80000000') &lt; 0 or compare($cap/start, '0xf8000000') &gt;= 0)">
<xs:annotation acrn:severity="warning">
<xs:documentation>The physical software SRAM region shall not overlap with pre-defined regions in guest.
When a pre-launched RT VM is enabled, the physical software SRAM is allocated to it at the same guest physical
address. Thus it is assumed that the software SRAM region does not overlap with any pre-defined region in the
pre-launched VM, such as the guest PCI hole which resides at 2G - 3.5G.
This error cannot be fixed by tweaking the configurations. Report to _GitHub:
https://github.com/projectacrn/acrn-hypervisor/issues if you meet this.</xs:documentation>
</xs:annotation>
</xs:assert>
</xs:schema>

View File

@ -0,0 +1,42 @@
<?xml version="1.0"?>
<!-- Copyright (C) 2022 Intel Corporation. -->
<!-- SPDX-License-Identifier: BSD-3-Clause -->
<xs:schema xml:id="root"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:acrn="https://projectacrn.org">
<xs:assert test="count(/acrn-config/vm[.//load_order = 'SERVICE_VM']) &lt; 2">
<xs:annotation acrn:severity="error" acrn:report-on="//vm[.//load_order = 'SERVICE_VM']">
<xs:documentation>There can be at most one service VM, but more than one was configured. Verify there is only one VM with vm_type set to SERVICE_VM. </xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="every $pre_vm in /acrn-config/vm[.//load_order = 'PRE_LAUNCHED_VM'] satisfies
every $svm in /acrn-config/vm[.//load_order = 'SERVICE_VM'] satisfies
$pre_vm/@id &lt; $svm/@id">
<xs:annotation acrn:severity="error" acrn:report-on="$pre_vm">
<xs:documentation>This pre-launched VM "{$pre_vm/name}" (ID: {$pre_vm/@id}) must have a VM ID value less than the service VM (ID: {$svm/@id}). Adjust the VM ID values to fix this.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="every $post_vm in /acrn-config/vm[.//load_order = 'POST_LAUNCHED_VM'] satisfies
every $svm in /acrn-config/vm[.//load_order = 'SERVICE_VM'] satisfies
$post_vm/@id &gt; $svm/@id">
<xs:annotation acrn:severity="error" acrn:report-on="$post_vm">
<xs:documentation>This post-launched VM "{$post_vm/name}" (ID: {$post_vm/@id}) must have a VM ID value greater than the service VM (ID: {$svm/@id}). Adjust the VM ID values to fix this.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="count(vm[load_order = 'PRE_LAUNCHED_VM' and vm_type = 'RTVM']) &lt;= 1">
<xs:annotation acrn:severity="warning" acrn:report-on="//vm[load_order = 'PRE_LAUNCHED_VM']/vm_type[text() = 'RTVM']">
<xs:documentation>Multiple pre-launched VMs {//vm[load_order = 'PRE_LAUNCHED_VM' and vm_type = 'RTVM']/name} are defined as RT VMs, but ACRN supports at most one pre-launched RT VM in one scenario. Adjust the VM types of those VMs to STANDARD_VM to fix this.</xs:documentation>
</xs:annotation>
</xs:assert>
<xs:assert test="count(distinct-values(vm[vm_type = 'RTVM']/load_order)) &lt;= 1">
<xs:annotation acrn:severity="warning" acrn:report-on="//vm/vm_type[text() = 'RTVM']">
<xs:documentation>Pre-launched RT VM(s) {//vm[load_order = 'PRE_LAUNCHED_VM' and vm_type = 'RTVM']/name} and post-launched RT VMs {//vm[load_order = 'POST_LAUNCHED_VM' and vm_type = 'RTVM']/name} cannot coexist. Adjust the VM types of those VMs to STANDARD_VM to fix this.</xs:documentation>
</xs:annotation>
</xs:assert>
</xs:schema>

View File

@ -10,7 +10,9 @@
</xs:sequence>
<xs:anyAttribute processContents="skip"/>
<xi:include href="checks/pre_launched_vm_support.xsd" xpointer="xpointer(id('root')/*)" />
<xi:include href="checks/cpu_assignment.xsd" xpointer="xpointer(id('root')/*)" />
<xi:include href="checks/vm_types.xsd" xpointer="xpointer(id('root')/*)" />
<xi:include href="checks/passthrough_devices.xsd" xpointer="xpointer(id('root')/*)" />
</xs:complexType>
</xs:element>