[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


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Date: Wed, 6 Aug 2025 03:35:14 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dSwADwyUi7M3qzOKNGpXHFSSgPCyCBzt0V8PoiLjUTo=; b=mMbt9Co8bwPMLPd/y1b1IhSRhws7QU/Pv3WDIpAjvTaD1NsrEUC9M3UMyOzP/aZxFs4jXnecsK8qEqO4eqIwZ3mQ7hgdd91rWqEgreauF1JMKG9Zd4sgtpZUIqqYj9cq/Z2dBTFZHnxOwJjBNRosh//ia/3rh2aeULIkU/UeQPOtZEP9sw9/kGxkwBNanaSPqBch+UdUEXJYgL1J6qIsSbFi9u077sqh27TM0YQUq9LCYjcCgXTYu1wd+8AyS6jKQpOfvrTA2x98PQfcP+HORzxf9GRpIrXZUKo/CsDRR6QLuYIj+5OQgBaLq6tKUDXzt8YvcOWNFX4fKvXnAeXmjQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=QlcDGS/zh+vispZ3GWsevTb1Sz9gzieYa6u6FsSJlw09oY/3Ixka83M5BMqOdZe/PIpyLREUfYubtm3lI3smo6Pd+9FAkypSX7Rk4bsewYQZ7PzbJ1i5izydCYQE7P+ROd63f9urq/nALIJ88wByOngUDDGm6KFUij85nTcORUyvblPf8U3yJFKUsvHk+4mduocMO2kz8fD+GQnNXPLlqvxsH9Nn7wYeTKoRbMxd+i2uDHQKkNd7LRc0JNly3xUWtQu0mU9z1jh+wK0rk826Ai+HLH8Um4zT3UotN+nPEP9cfw+U+0HtkJ1wglIjq/eINSRqIlVbuAL1nrK0abV9rw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Huang, Ray" <Ray.Huang@xxxxxxx>, "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Delivery-date: Wed, 06 Aug 2025 03:35:39 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcBbvzKmM00rEmukmd//khB9ysKbRTvniAgAHAdwA=
  • Thread-topic: [PATCH v10 4/4] vpci/msix: Free MSIX resources when init_msix() fails

On 2025/8/5 16:43, Jan Beulich wrote:
> 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.
To make these changes, can I add a new patch as the last patch of this series?
And the new patch will do:
1. add a boolean parameter for cleanup hook to separate whose calls 
cleanup(during initialization or during deassign device).
2. call all cleanup hooks in vpci_deassign_device().
3. remove the MSI/MSIX specific free actions in vpci_deassign_device().

> 
>> --- 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

-- 
Best regards,
Jiqian Chen.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.