From bf653d277b8f9400b0fb680d27e5074a928bcf96 Mon Sep 17 00:00:00 2001 From: Qiang Zhang Date: Thu, 24 Aug 2023 09:32:26 +0800 Subject: [PATCH] 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 Signed-off-by: Qiang Zhang Signed-off-by: Victor Sun --- hypervisor/arch/x86/configs/pci_dev.c | 50 +++++++++---------- hypervisor/include/arch/x86/asm/vm_config.h | 1 + .../xforms/vm_configurations.c.xsl | 9 ++++ 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/hypervisor/arch/x86/configs/pci_dev.c b/hypervisor/arch/x86/configs/pci_dev.c index a8c2a069e..144b31253 100644 --- a/hypervisor/arch/x86/configs/pci_dev.c +++ b/hypervisor/arch/x86/configs/pci_dev.c @@ -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; } diff --git a/hypervisor/include/arch/x86/asm/vm_config.h b/hypervisor/include/arch/x86/asm/vm_config.h index b0d48aa88..206ceb8b5 100644 --- a/hypervisor/include/arch/x86/asm/vm_config.h +++ b/hypervisor/include/arch/x86/asm/vm_config.h @@ -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_ */ diff --git a/misc/config_tools/xforms/vm_configurations.c.xsl b/misc/config_tools/xforms/vm_configurations.c.xsl index bb2c3e29d..64dce14d9 100644 --- a/misc/config_tools/xforms/vm_configurations.c.xsl +++ b/misc/config_tools/xforms/vm_configurations.c.xsl @@ -87,6 +87,15 @@ + + + + + + + + +