Skip to content

Commit 9e21c5b

Browse files
Sainath Grandhiwenlingz
authored andcommitted
hv: Move error checking for hypercall parameters out of assign module
Moving checks on validity of IOAPIC interrupt remapping hypercall parameters to hypercall module Tracked-On: #4151 Signed-off-by: Sainath Grandhi <sainath.grandhi@intel.com> Acked-by: Eddie Dong <eddie.dong@Intel.com>
1 parent 37eb369 commit 9e21c5b

File tree

2 files changed

+71
-67
lines changed

2 files changed

+71
-67
lines changed

hypervisor/arch/x86/guest/assign.c

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -350,51 +350,47 @@ static struct ptirq_remapping_info *add_intx_remapping(struct acrn_vm *vm, uint3
350350
DEFINE_INTX_SID(virt_sid, virt_pin, vpin_ctlr);
351351
uint32_t phys_irq = ioapic_pin_to_irq(phys_pin);
352352

353-
if (((vpin_ctlr == INTX_CTLR_IOAPIC) && (virt_pin >= vioapic_pincount(vm))) || ((vpin_ctlr == INTX_CTLR_PIC) && (virt_pin >= vpic_pincount()))) {
354-
pr_err("ptirq_add_intx_remapping fails!\n");
355-
} else if (!ioapic_irq_is_gsi(phys_irq)) {
356-
pr_err("%s, invalid phys_pin: %d <-> irq: 0x%x is not a GSI\n", __func__, phys_pin, phys_irq);
357-
} else {
358-
entry = ptirq_lookup_entry_by_sid(PTDEV_INTR_INTX, &phys_sid, NULL);
359-
if (entry == NULL) {
360-
if (ptirq_lookup_entry_by_sid(PTDEV_INTR_INTX, &virt_sid, vm) == NULL) {
361-
entry = ptirq_alloc_entry(vm, PTDEV_INTR_INTX);
362-
if (entry != NULL) {
363-
entry->phys_sid.value = phys_sid.value;
364-
entry->virt_sid.value = virt_sid.value;
365-
entry->release_cb = ptirq_free_irte;
366-
367-
/* activate entry */
368-
if (ptirq_activate_entry(entry, phys_irq) < 0) {
369-
ptirq_release_entry(entry);
370-
entry = NULL;
371-
}
372-
}
373-
} else {
374-
pr_err("INTX re-add vpin %d", virt_pin);
375-
}
376-
} else if (entry->vm != vm) {
377-
if (is_sos_vm(entry->vm)) {
378-
entry->vm = vm;
353+
entry = ptirq_lookup_entry_by_sid(PTDEV_INTR_INTX, &phys_sid, NULL);
354+
if (entry == NULL) {
355+
if (ptirq_lookup_entry_by_sid(PTDEV_INTR_INTX, &virt_sid, vm) == NULL) {
356+
entry = ptirq_alloc_entry(vm, PTDEV_INTR_INTX);
357+
if (entry != NULL) {
358+
entry->phys_sid.value = phys_sid.value;
379359
entry->virt_sid.value = virt_sid.value;
380-
entry->polarity = 0U;
381-
} else {
382-
pr_err("INTX pin%d already in vm%d with vpin%d, not able to add into vm%d with vpin%d",
383-
phys_pin, entry->vm->vm_id, entry->virt_sid.intx_id.pin, vm->vm_id, virt_pin);
384-
entry = NULL;
360+
entry->release_cb = ptirq_free_irte;
361+
362+
/* activate entry */
363+
if (ptirq_activate_entry(entry, phys_irq) < 0) {
364+
ptirq_release_entry(entry);
365+
entry = NULL;
366+
}
385367
}
386368
} else {
387-
/* The mapping has already been added to the VM. No action
388-
* required. */
369+
pr_err("INTX re-add vpin %d", virt_pin);
389370
}
390-
391-
/*
392-
* ptirq entry is either created or transferred from SOS VM to Post-launched VM
393-
*/
394-
if (entry != NULL) {
395-
dev_dbg(DBG_LEVEL_IRQ, "VM%d INTX add pin mapping vpin%d:ppin%d",
396-
entry->vm->vm_id, virt_pin, phys_pin);
371+
} else if (entry->vm != vm) {
372+
if (is_sos_vm(entry->vm)) {
373+
entry->vm = vm;
374+
entry->virt_sid.value = virt_sid.value;
375+
entry->polarity = 0U;
376+
} else {
377+
pr_err("INTX pin%d already in vm%d with vpin%d, not able to add into vm%d with vpin%d",
378+
phys_pin, entry->vm->vm_id, entry->virt_sid.intx_id.pin, vm->vm_id, virt_pin);
379+
entry = NULL;
397380
}
381+
} else {
382+
/* The mapping has already been added to the VM. No action
383+
* required. */
384+
}
385+
386+
387+
/*
388+
* ptirq entry is either created or transferred from SOS VM to Post-launched VM
389+
*/
390+
391+
if (entry != NULL) {
392+
dev_dbg(DBG_LEVEL_IRQ, "VM%d INTX add pin mapping vpin%d:ppin%d",
393+
entry->vm->vm_id, virt_pin, phys_pin);
398394
}
399395

400396
return entry;
@@ -408,31 +404,27 @@ static void remove_intx_remapping(const struct acrn_vm *vm, uint32_t virt_pin, e
408404
struct intr_source intr_src;
409405
DEFINE_INTX_SID(virt_sid, virt_pin, vpin_ctlr);
410406

411-
if (((vpin_ctlr == INTX_CTLR_IOAPIC) && (virt_pin >= vioapic_pincount(vm))) || ((vpin_ctlr == INTX_CTLR_PIC) && (virt_pin >= vpic_pincount()))) {
412-
pr_err("virtual irq pin is invalid!\n");
413-
} else {
414-
entry = ptirq_lookup_entry_by_sid(PTDEV_INTR_INTX, &virt_sid, vm);
415-
if (entry != NULL) {
416-
if (is_entry_active(entry)) {
417-
phys_irq = entry->allocated_pirq;
418-
/* disable interrupt */
419-
ioapic_gsi_mask_irq(phys_irq);
420-
421-
ptirq_deactivate_entry(entry);
422-
intr_src.is_msi = false;
423-
intr_src.src.ioapic_id = ioapic_irq_to_ioapic_id(phys_irq);
424-
425-
dmar_free_irte(intr_src, (uint16_t)phys_irq);
426-
dev_dbg(DBG_LEVEL_IRQ,
427-
"deactive %s intx entry:ppin=%d, pirq=%d ",
428-
(vpin_ctlr == INTX_CTLR_PIC) ? "vPIC" : "vIOAPIC",
429-
entry->phys_sid.intx_id.pin, phys_irq);
430-
dev_dbg(DBG_LEVEL_IRQ, "from vm%d vpin=%d\n",
431-
entry->vm->vm_id, virt_pin);
432-
}
407+
entry = ptirq_lookup_entry_by_sid(PTDEV_INTR_INTX, &virt_sid, vm);
408+
if (entry != NULL) {
409+
if (is_entry_active(entry)) {
410+
phys_irq = entry->allocated_pirq;
411+
/* disable interrupt */
412+
ioapic_gsi_mask_irq(phys_irq);
433413

434-
ptirq_release_entry(entry);
414+
ptirq_deactivate_entry(entry);
415+
intr_src.is_msi = false;
416+
intr_src.src.ioapic_id = ioapic_irq_to_ioapic_id(phys_irq);
417+
418+
dmar_free_irte(intr_src, (uint16_t)phys_irq);
419+
dev_dbg(DBG_LEVEL_IRQ,
420+
"deactive %s intx entry:ppin=%d, pirq=%d ",
421+
(vpin_ctlr == INTX_CTLR_PIC) ? "vPIC" : "vIOAPIC",
422+
entry->phys_sid.intx_id.pin, phys_irq);
423+
dev_dbg(DBG_LEVEL_IRQ, "from vm%d vpin=%d\n",
424+
entry->vm->vm_id, virt_pin);
435425
}
426+
427+
ptirq_release_entry(entry);
436428
}
437429
}
438430

hypervisor/common/hypercall.c

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <hypercall.h>
1919
#include <errno.h>
2020
#include <logmsg.h>
21+
#include <ioapic.h>
2122

2223
#define DBG_LEVEL_HYCALL 6U
2324

@@ -905,8 +906,14 @@ int32_t hcall_set_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t pa
905906
vdev = pci_find_vdev(vpci, bdf);
906907
spinlock_release(&vpci->lock);
907908
if ((vdev != NULL) && (vdev->pdev->bdf.value == irq.phys_bdf)) {
908-
ret = ptirq_add_intx_remapping(target_vm, irq.intx.virt_pin,
909-
irq.intx.phys_pin, irq.intx.pic_pin);
909+
if ((((!irq.intx.pic_pin) && (irq.intx.virt_pin < vioapic_pincount(target_vm))) ||
910+
((irq.intx.pic_pin) && (irq.intx.virt_pin < vpic_pincount()))) &&
911+
ioapic_irq_is_gsi(irq.intx.phys_pin)) {
912+
ret = ptirq_add_intx_remapping(target_vm, irq.intx.virt_pin,
913+
irq.intx.phys_pin, irq.intx.pic_pin);
914+
} else {
915+
pr_err("%s: Invalid phys pin or virt pin\n", __func__);
916+
}
910917
}
911918
} else {
912919
pr_err("%s: Invalid irq type: %u\n", __func__, irq.type);
@@ -948,8 +955,13 @@ hcall_reset_ptdev_intr_info(struct acrn_vm *vm, uint16_t vmid, uint64_t param)
948955
vdev = pci_find_vdev(vpci, bdf);
949956
spinlock_release(&vpci->lock);
950957
if ((vdev != NULL) && (vdev->pdev->bdf.value == irq.phys_bdf)) {
951-
ptirq_remove_intx_remapping(target_vm, irq.intx.virt_pin, irq.intx.pic_pin);
952-
ret = 0;
958+
if (((!irq.intx.pic_pin) && (irq.intx.virt_pin < vioapic_pincount(target_vm))) ||
959+
((irq.intx.pic_pin) && (irq.intx.virt_pin < vpic_pincount()))) {
960+
ptirq_remove_intx_remapping(target_vm, irq.intx.virt_pin, irq.intx.pic_pin);
961+
ret = 0;
962+
} else {
963+
pr_err("%s: Invalid virt pin\n", __func__);
964+
}
953965
}
954966
} else {
955967
pr_err("%s: Invalid irq type: %u\n", __func__, irq.type);

0 commit comments

Comments
 (0)