|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v10 4/4] vpci/msix: Free MSIX resources when init_msix() fails
On 05.08.2025 05:49, Jiqian Chen wrote:
> --- a/xen/drivers/vpci/msix.c
> +++ b/xen/drivers/vpci/msix.c
> @@ -655,6 +655,48 @@ int vpci_make_msix_hole(const struct pci_dev *pdev)
> return 0;
> }
>
> +static int cf_check cleanup_msix(const struct pci_dev *pdev)
> +{
> + int rc;
> + struct vpci *vpci = pdev->vpci;
> + const unsigned int msix_pos = pdev->msix_pos;
> +
> + if ( !msix_pos )
> + return 0;
> +
> + rc = vpci_remove_registers(vpci, msix_control_reg(msix_pos), 2);
> + if ( rc )
> + {
> + printk(XENLOG_ERR "%pd %pp: fail to remove MSIX handlers rc=%d\n",
> + pdev->domain, &pdev->sbdf, rc);
> + ASSERT_UNREACHABLE();
> + return rc;
> + }
> +
> + if ( vpci->msix )
> + {
> + list_del(&vpci->msix->next);
> + for ( unsigned int i = 0; i < ARRAY_SIZE(vpci->msix->table); i++ )
> + if ( vpci->msix->table[i] )
> + iounmap(vpci->msix->table[i]);
> +
> + XFREE(vpci->msix);
> + }
> +
> + /*
> + * The driver may not traverse the capability list and think device
> + * supports MSIX by default. So here let the control register of MSIX
> + * be Read-Only is to ensure MSIX disabled.
> + */
> + rc = vpci_add_register(vpci, vpci_hw_read16, NULL,
> + msix_control_reg(msix_pos), 2, NULL);
> + if ( rc )
> + printk(XENLOG_ERR "%pd %pp: fail to add MSIX ctrl handler rc=%d\n",
> + pdev->domain, &pdev->sbdf, rc);
Here as well as for MSI: Wouldn't this better be limited to the init-failure
case? No point in adding a register hook (and possibly emitting a misleading
log message) when we're tearing down anyway. IOW I think the ->cleanup()
hook needs a boolean parameter, unless the distinction of the two cases can
be (reliably) inferred from some other property.
> --- a/xen/drivers/vpci/vpci.c
> +++ b/xen/drivers/vpci/vpci.c
> @@ -321,6 +321,27 @@ void vpci_deassign_device(struct pci_dev *pdev)
> &pdev->domain->vpci_dev_assigned_map);
> #endif
>
> + for ( i = 0; i < NUM_VPCI_INIT; i++ )
> + {
> + const vpci_capability_t *capability = &__start_vpci_array[i];
> + const unsigned int cap = capability->id;
> + unsigned int pos = 0;
> +
> + if ( !capability->is_ext )
> + pos = pci_find_cap_offset(pdev->sbdf, cap);
> + else if ( is_hardware_domain(pdev->domain) )
> + pos = pci_find_ext_capability(pdev->sbdf, cap);
> +
> + if ( pos && capability->cleanup )
> + {
> + int rc = capability->cleanup(pdev);
> + if ( rc )
> + printk(XENLOG_ERR "%pd %pp: clean %s cap %u fail rc=%d\n",
> + pdev->domain, &pdev->sbdf,
> + capability->is_ext ? "extended" : "legacy", cap, rc);
> + }
> + }
With this imo the patch subject is now wrong, too.
Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |