@@ -628,7 +628,8 @@ static void activate_physical_ioapic(struct acrn_vm *vm,
628
628
int32_t ptirq_intx_pin_remap (struct acrn_vm * vm , uint8_t virt_pin ,
629
629
enum ptirq_vpin_source vpin_src )
630
630
{
631
- struct ptirq_remapping_info * entry ;
631
+ int32_t status = 0 ;
632
+ struct ptirq_remapping_info * entry = NULL ;
632
633
bool need_switch_vpin_src = false;
633
634
DEFINE_IOAPIC_SID (virt_sid , virt_pin , vpin_src );
634
635
bool pic_pin = (vpin_src == PTDEV_VPIN_PIC );
@@ -647,80 +648,80 @@ int32_t ptirq_intx_pin_remap(struct acrn_vm *vm, uint8_t virt_pin,
647
648
/* no remap for hypervisor owned intx */
648
649
#ifdef CONFIG_COM_IRQ
649
650
if (ptdev_hv_owned_intx (vm , & virt_sid )) {
650
- goto END ;
651
+ status = - ENODEV ;
651
652
}
652
653
#endif /* CONFIG_COM_IRQ */
653
654
654
- /* query if we have virt to phys mapping */
655
- spinlock_obtain (& ptdev_lock );
656
- entry = ptirq_lookup_entry_by_vpin (vm , virt_pin , pic_pin );
657
- if (entry == NULL ) {
658
- if (is_vm0 (vm )) {
659
-
660
- /* for vm0, there is chance of vpin source switch
661
- * between vPIC & vIOAPIC for one legacy phys_pin.
662
- *
663
- * here checks if there is already mapping entry from
664
- * the other vpin source for legacy pin. If yes, then
665
- * switch vpin source is needed
666
- */
667
- if (virt_pin < NR_LEGACY_PIN ) {
668
- uint8_t vpin = pic_ioapic_pin_map [virt_pin ];
669
-
670
- entry = ptirq_lookup_entry_by_vpin (vm , vpin , !pic_pin );
671
- if (entry != NULL ) {
672
- need_switch_vpin_src = true;
655
+ if (status || (pic_pin && (virt_pin >= NR_VPIC_PINS_TOTAL ))) {
656
+ status = - EINVAL ;
657
+ } else {
658
+ /* query if we have virt to phys mapping */
659
+ spinlock_obtain (& ptdev_lock );
660
+ entry = ptirq_lookup_entry_by_vpin (vm , virt_pin , pic_pin );
661
+ if (entry == NULL ) {
662
+ if (is_vm0 (vm )) {
663
+
664
+ /* for vm0, there is chance of vpin source switch
665
+ * between vPIC & vIOAPIC for one legacy phys_pin.
666
+ *
667
+ * here checks if there is already mapping entry from
668
+ * the other vpin source for legacy pin. If yes, then
669
+ * switch vpin source is needed
670
+ */
671
+ if (virt_pin < NR_LEGACY_PIN ) {
672
+ uint8_t vpin = pic_ioapic_pin_map [virt_pin ];
673
+
674
+ entry = ptirq_lookup_entry_by_vpin (vm , vpin , !pic_pin );
675
+ if (entry != NULL ) {
676
+ need_switch_vpin_src = true;
677
+ }
673
678
}
674
- }
675
-
676
- /* entry could be updated by above switch check */
677
- if (entry == NULL ) {
678
- uint8_t phys_pin = virt_pin ;
679
679
680
- /* fix vPIC pin to correct native IOAPIC pin */
681
- if (pic_pin ) {
682
- phys_pin = pic_ioapic_pin_map [virt_pin ];
683
- }
684
- entry = add_intx_remapping (vm ,
685
- virt_pin , phys_pin , pic_pin );
680
+ /* entry could be updated by above switch check */
686
681
if (entry == NULL ) {
687
- pr_err ("%s, add intx remapping failed" ,
688
- __func__ );
689
- spinlock_release (& ptdev_lock );
690
- return - ENODEV ;
682
+ uint8_t phys_pin = virt_pin ;
683
+
684
+ /* fix vPIC pin to correct native IOAPIC pin */
685
+ if (pic_pin ) {
686
+ phys_pin = pic_ioapic_pin_map [virt_pin ];
687
+ }
688
+ entry = add_intx_remapping (vm ,
689
+ virt_pin , phys_pin , pic_pin );
690
+ if (entry == NULL ) {
691
+ pr_err ("%s, add intx remapping failed" ,
692
+ __func__ );
693
+ status = - ENODEV ;
694
+ }
691
695
}
696
+ } else {
697
+ /* ptirq_intx_pin_remap is triggered by vPIC/vIOAPIC
698
+ * everytime a pin get unmask, here filter out pins
699
+ * not get mapped.
700
+ */
701
+ status = - ENODEV ;
692
702
}
693
- } else {
694
- /* ptirq_intx_pin_remap is triggered by vPIC/vIOAPIC
695
- * everytime a pin get unmask, here filter out pins
696
- * not get mapped.
697
- */
698
- spinlock_release (& ptdev_lock );
699
- goto END ;
700
703
}
704
+ spinlock_release (& ptdev_lock );
701
705
}
702
706
703
- /* if vpin source need switch */
704
- if (need_switch_vpin_src ) {
705
- dev_dbg (ACRN_DBG_IRQ ,
706
- "IOAPIC pin=%hhu pirq=%u vpin=%d switch from %s to %s "
707
- "vpin=%d for vm%d" , entry -> phys_sid .intx_id .pin ,
708
- entry -> allocated_pirq , entry -> virt_sid .intx_id .pin ,
709
- (vpin_src == 0 )? "vPIC" : "vIOAPIC" ,
710
- (vpin_src == 0 )? "vIOPIC" : "vPIC" ,
711
- virt_pin , entry -> vm -> vm_id );
712
- entry -> virt_sid .value = virt_sid .value ;
707
+ if (!status ) {
708
+ spinlock_obtain (& ptdev_lock );
709
+ /* if vpin source need switch */
710
+ if ((need_switch_vpin_src ) && (entry != NULL )) {
711
+ dev_dbg (ACRN_DBG_IRQ ,
712
+ "IOAPIC pin=%hhu pirq=%u vpin=%d switch from %s to %s vpin=%d for vm%d" ,
713
+ entry -> phys_sid .intx_id .pin ,
714
+ entry -> allocated_pirq , entry -> virt_sid .intx_id .pin ,
715
+ (vpin_src == 0 ) ? "vPIC" : "vIOAPIC" ,
716
+ (vpin_src == 0 ) ? "vIOPIC" : "vPIC" ,
717
+ virt_pin , entry -> vm -> vm_id );
718
+ entry -> virt_sid .value = virt_sid .value ;
719
+ }
720
+ spinlock_release (& ptdev_lock );
721
+ activate_physical_ioapic (vm , entry );
713
722
}
714
- spinlock_release (& ptdev_lock );
715
723
716
- activate_physical_ioapic (vm , entry );
717
- dev_dbg (ACRN_DBG_IRQ ,
718
- "IOAPIC pin=%hhu pirq=%u assigned to vm%d %s vpin=%d" ,
719
- entry -> phys_sid .intx_id .pin , entry -> allocated_pirq ,
720
- entry -> vm -> vm_id , vpin_src == PTDEV_VPIN_PIC ?
721
- "vPIC" : "vIOAPIC" , virt_pin );
722
- END :
723
- return 0 ;
724
+ return status ;
724
725
}
725
726
726
727
/* @pre vm != NULL
0 commit comments