From 8b192b158376b3dfb5e84fa805d92cb29d7a2227 Mon Sep 17 00:00:00 2001 From: Tianhua Sun Date: Tue, 2 Apr 2019 15:16:35 +0800 Subject: [PATCH] hv: check vector count when set/reset msix info 'vector_cnt' is vector count of MSI/MSIX, and it come from 'table_count' in the the pci_msix struct. 'CONFIG_MAX_MSIX_TABLE_NUM' is the maximum number of MSI-X tables per device, so 'vector_cnt' must be less then or equal to 'CONFIG_MAX_MSIX_TABLE_NUM'. Tracked-On: #2881 Signed-off-by: Tianhua Sun Reviewed-by: Yonghua Huang Acked-by: Eddie Dong --- hypervisor/common/hypercall.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/hypervisor/common/hypercall.c b/hypervisor/common/hypercall.c index cf24d5dff..96b2fab12 100644 --- a/hypervisor/common/hypercall.c +++ b/hypervisor/common/hypercall.c @@ -952,12 +952,14 @@ int32_t hcall_set_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t pa if (irq.type == IRQ_INTX) { ret = ptirq_add_intx_remapping(target_vm, irq.is.intx.virt_pin, irq.is.intx.phys_pin, irq.is.intx.pic_pin); - } else if ((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) { + } else if (((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) && + (irq.is.msix.vector_cnt <= CONFIG_MAX_MSIX_TABLE_NUM)) { ret = ptirq_add_msix_remapping(target_vm, irq.virt_bdf, irq.phys_bdf, irq.is.msix.vector_cnt); } else { - pr_err("%s: Invalid irq type: %u\n", __func__, irq.type); + pr_err("%s: Invalid irq type: %u or MSIX vector count: %u\n", + __func__, irq.type, irq.is.msix.vector_cnt); ret = -1; } } @@ -993,7 +995,8 @@ hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param) ptirq_remove_intx_remapping(target_vm, irq.is.intx.virt_pin, irq.is.intx.pic_pin); - } else if ((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) { + } else if (((irq.type == IRQ_MSI) || (irq.type == IRQ_MSIX)) && + (irq.is.msix.vector_cnt <= CONFIG_MAX_MSIX_TABLE_NUM)) { /* * Inform vPCI about the interupt info changes @@ -1007,7 +1010,8 @@ hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param) irq.virt_bdf, irq.is.msix.vector_cnt); } else { - pr_err("%s: Invalid irq type: %u\n", __func__, irq.type); + pr_err("%s: Invalid irq type: %u or MSIX vector count: %u\n", + __func__, irq.type, irq.is.msix.vector_cnt); ret = -1; } } else {