HV: init one dev config with service vm config param

When we do init_all_dev_config() in pci.c, the pdevs added to pci dev_config
will be exposed to Service VM or passthru to prelauched VM. The original code
would find service VM config in every pci pdev init loop, this is unnecessary
and definitely impact performance. Here we generate Service VM config pointer
with config tool so that init_one_dev_config() could refer service VM config
directly.

Tracked-On: #8491
Reviewed-by: Junjie Mao <junjie.mao@intel.com>
Signed-off-by: Qiang Zhang <qiang4.zhang@intel.com>
Signed-off-by: Victor Sun <victor.sun@intel.com>
This commit is contained in:
Qiang Zhang 2023-08-24 09:32:26 +08:00 committed by acrnsi-robot
parent deccb22ea8
commit bf653d277b
3 changed files with 34 additions and 26 deletions

View File

@ -52,38 +52,36 @@ static bool allocate_to_prelaunched_vm(struct pci_pdev *pdev)
*/
struct acrn_vm_pci_dev_config *init_one_dev_config(struct pci_pdev *pdev)
{
uint16_t vmid;
struct acrn_vm_config *vm_config;
struct acrn_vm_pci_dev_config *dev_config = NULL;
bool is_allocated_to_prelaunched_vm = allocate_to_prelaunched_vm(pdev);
bool is_allocated_to_hv = is_hv_owned_pdev(pdev->bdf);
if (!allocate_to_prelaunched_vm(pdev)) {
for (vmid = 0U; vmid < CONFIG_MAX_VM_NUM; vmid++) {
vm_config = get_vm_config(vmid);
if (vm_config->load_order != SERVICE_VM) {
continue;
}
if (service_vm_config != NULL) {
dev_config = &service_vm_config->pci_devs[service_vm_config->pci_dev_num];
dev_config = &vm_config->pci_devs[vm_config->pci_dev_num];
if (is_hv_owned_pdev(pdev->bdf)) {
/* Service VM need to emulate the type1 pdevs owned by HV */
dev_config->emu_type = PCI_DEV_TYPE_SERVICE_VM_EMUL;
if (is_bridge(pdev)) {
dev_config->vdev_ops = &vpci_bridge_ops;
} else if (is_host_bridge(pdev)) {
dev_config->vdev_ops = &vhostbridge_ops;
} else {
/* May have type0 device, E.g. debug pci uart */
break;
}
if (is_allocated_to_hv) {
/* Service VM need to emulate the type1 pdevs owned by HV */
dev_config->emu_type = PCI_DEV_TYPE_SERVICE_VM_EMUL;
if (is_bridge(pdev)) {
dev_config->vdev_ops = &vpci_bridge_ops;
} else if (is_host_bridge(pdev)) {
dev_config->vdev_ops = &vhostbridge_ops;
} else {
dev_config->emu_type = PCI_DEV_TYPE_PTDEV;
/* May have type0 device, E.g. debug pci uart */
dev_config = NULL;
}
dev_config->vbdf.value = pdev->bdf.value;
dev_config->pbdf.value = pdev->bdf.value;
dev_config->pdev = pdev;
vm_config->pci_dev_num++;
} else if (is_allocated_to_prelaunched_vm) {
dev_config = NULL;
} else {
dev_config->emu_type = PCI_DEV_TYPE_PTDEV;
}
}
if (dev_config != NULL) {
dev_config->vbdf.value = pdev->bdf.value;
dev_config->pbdf.value = pdev->bdf.value;
dev_config->pdev = pdev;
service_vm_config->pci_dev_num++;
}
return dev_config;
}

View File

@ -217,5 +217,6 @@ uint8_t get_vm_severity(uint16_t vm_id);
bool vm_has_matched_name(uint16_t vmid, const char *name);
extern struct acrn_vm_config vm_configs[CONFIG_MAX_VM_NUM];
extern struct acrn_vm_config *const service_vm_config;
#endif /* VM_CONFIG_H_ */

View File

@ -87,6 +87,15 @@
</xsl:if>
<xsl:value-of select="$newline"/>
<xsl:value-of select="$end_of_array_initializer" />
<xsl:value-of select="$newline"/>
<xsl:choose>
<xsl:when test="count(vm[load_order='SERVICE_VM'])">
<xsl:value-of select="concat('struct acrn_vm_config *const service_vm_config = &amp;vm_configs[', vm[load_order='SERVICE_VM']/@id, '];')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('struct acrn_vm_config *const service_vm_config =', ' NULL;')" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="vm">