@@ -102,6 +102,7 @@ struct passthru_dev {
102
102
int table_size ; /* page aligned size */
103
103
void * table_pages ;
104
104
int table_offset ; /* page aligned */
105
+ bool ptirq_allocated ;
105
106
} msix ;
106
107
bool pcie_cap ;
107
108
struct pcisel sel ;
@@ -465,7 +466,13 @@ init_msix_table(struct vmctx *ctx, struct passthru_dev *ptdev, uint64_t base)
465
466
ptirq .msix .vector_cnt = dev -> msix .table_count ;
466
467
ptirq .msix .table_paddr = 0 ;
467
468
ptirq .msix .table_size = 0 ;
468
- vm_set_ptdev_msix_info (ctx , & ptirq );
469
+ error = vm_set_ptdev_msix_info (ctx , & ptirq );
470
+ if (error ) {
471
+ warnx ("Failed to alloc ptirq entry on %x/%x/%x" , b ,s ,f );
472
+ return error ;
473
+ }
474
+ ptdev -> msix .ptirq_allocated = true;
475
+
469
476
470
477
/* Skip the MSI-X table */
471
478
base += table_size ;
@@ -492,15 +499,18 @@ init_msix_table(struct vmctx *ctx, struct passthru_dev *ptdev, uint64_t base)
492
499
}
493
500
494
501
static void
495
- deinit_msix_table (struct vmctx * ctx , struct pci_vdev * dev )
502
+ deinit_msix_table (struct vmctx * ctx , struct passthru_dev * ptdev )
496
503
{
497
- struct passthru_dev * ptdev = ( struct passthru_dev * ) dev -> arg ; ;
504
+ struct pci_vdev * dev = ptdev -> dev ;
498
505
uint16_t virt_bdf = PCI_BDF (dev -> bus , dev -> slot , dev -> func );
499
506
int vector_cnt = dev -> msix .table_count ;
500
507
501
- printf ("ptdev reset msix: 0x%x-%x, vector_cnt=%d.\n" ,
502
- virt_bdf , ptdev -> phys_bdf , vector_cnt );
503
- vm_reset_ptdev_msix_info (ctx , virt_bdf , vector_cnt );
508
+ if (ptdev -> msix .ptirq_allocated ) {
509
+ printf ("ptdev reset msix: 0x%x-%x, vector_cnt=%d.\n" ,
510
+ virt_bdf , ptdev -> phys_bdf , vector_cnt );
511
+ vm_reset_ptdev_msix_info (ctx , virt_bdf , vector_cnt );
512
+ ptdev -> msix .ptirq_allocated = false;
513
+ }
504
514
505
515
if (ptdev -> msix .table_pages ) {
506
516
pci_device_unmap_range (ptdev -> phys_dev , ptdev -> msix .table_pages , ptdev -> msix .table_size );
@@ -589,8 +599,10 @@ cfginitbar(struct vmctx *ctx, struct passthru_dev *ptdev)
589
599
/* The MSI-X table needs special handling */
590
600
if (i == ptdev_msix_table_bar (ptdev )) {
591
601
error = init_msix_table (ctx , ptdev , base );
592
- if (error )
602
+ if (error ) {
603
+ deinit_msix_table (ctx , ptdev );
593
604
return -1 ;
605
+ }
594
606
} else if (bartype != PCIBAR_IO ) {
595
607
/* Map the physical BAR in the guest MMIO space */
596
608
error = vm_map_ptdev_mmio (ctx , ptdev -> sel .bus ,
@@ -890,7 +902,7 @@ passthru_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
890
902
func = ptdev -> phys_bdf & 0x7 ;
891
903
892
904
if (ptdev -> msix .capoff != 0 )
893
- deinit_msix_table (ctx , dev );
905
+ deinit_msix_table (ctx , ptdev );
894
906
else if (ptdev -> msi .capoff != 0 ) {
895
907
/* Currently only support 1 vector */
896
908
printf ("ptdev reset msi: 0x%x-%x\n" , virt_bdf , ptdev -> phys_bdf );
0 commit comments