[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v5 10/10] vpci/msix: Free MSIX resources when init_msix() fails


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Date: Fri, 6 Jun 2025 08:44:02 +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=Io3dMfdBKgUW1y+TKqfLJgdQwWxKRLi6oYFFFcNT3/w=; b=ABcKmXvt6alBurM9+8+wa/vVGadLezhjSwiOSp2D0AuZhkdVu1kY5bYNITfoSWAIuW4NKIFcqIRBwvzsg4Td4DgjxSoUBgY4ee1O7QKHE9wUfFTaDjN8gM+CaXHj5iPJ0ZGqEyrP+0YqifX5YWVHzENllZjm6hgu7pNt17FNdTYAAlcsAeGSiFr1RNWk+3jwzMGQ036DREFTdKkVn4ez2mf6s53S8qfojfogwqc4S13V96dHsBNJ6Hfmhir/BSYl7eIhJkO0W5aOHvkXU2sqAdYGhfXrxyezENXM5g++X+ogkyOTy5bMj9YmySIHsFEI0s8df0xuaYu6U8J9FeDuNQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=sV1Wnv0AHnWdznHQGD1RzOI16qSApVICcjPpsvr0t/5LI0WmNXDhR4KggUeDDYWyCpLdUxniyLUrQU48RUrwEYidi6QKg+XH+E66kWnkwxLXZm2yfxUbUSVvXYi2Vc1D66x02ZIHqaB+IIghm/A5Bhqwi85O+7pgpg8MuMAswZYsQxumoSa0UGednUeOLNe4BitVuef0tE/6c3WQOt26pZBhkjiBBDieQ6zlXOsQ7pZ/rbfdApZ1uESA+nMOvL7IKxFUu2KcjtGoziuyjVX9k8k8tzHFy67JEur/f5GWgR5L8e73wFV+z6LTAQp3SRcP47nH07+z4mn0H8g+BVKNiQ==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Huang, Ray" <Ray.Huang@xxxxxxx>, "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Delivery-date: Fri, 06 Jun 2025 08:44:10 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHbziMTqeagkRx4hES1pSa65nFeRrP0wkuAgAGlSYA=
  • Thread-topic: [PATCH v5 10/10] vpci/msix: Free MSIX resources when init_msix() fails

On 2025/6/5 23:34, Roger Pau Monné wrote:
> On Mon, May 26, 2025 at 05:45:59PM +0800, Jiqian Chen wrote:
>> When init_msix() fails, current logic return fail and free MSIX-related
>> resources in vpci_deassign_device(). But the previous new changes will
>> hide MSIX capability and return success, it can't reach
>> vpci_deassign_device() to remove resources if hiding success, so those
>> resources must be removed in cleanup function of MSIX.
>>
>> To do that, implement cleanup function for MSIX.
>>
>> Signed-off-by: Jiqian Chen <Jiqian.Chen@xxxxxxx>
> 
> 
> 
>> ---
>> cc: "Roger Pau Monné" <roger.pau@xxxxxxxxxx>
>> ---
>> v4->v5 changes:
>> * Change definition "static void cleanup_msix" to "static int cf_check 
>> cleanup_msix" since cleanup hook is changed to be int.
>> * Add a read-only register for MSIX Control Register in the end of 
>> cleanup_msix().
>>
>> v3->v4 changes:
>> * Change function name from fini_msix() to cleanup_msix().
>> * Change to use XFREE to free vpci->msix.
>> * In cleanup function, change the sequence of check and remove action 
>> according to init_msix().
>>
>> v2->v3 changes:
>> * Remove unnecessary clean operations in fini_msix().
>>
>> v1->v2 changes:
>> new patch.
>>
>> Best regards,
>> Jiqian Chen.
>> ---
>>  xen/drivers/vpci/msix.c | 29 ++++++++++++++++++++++++++++-
>>  1 file changed, 28 insertions(+), 1 deletion(-)
>>
>> diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c
>> index 674815ead025..cf79320d3b6f 100644
>> --- a/xen/drivers/vpci/msix.c
>> +++ b/xen/drivers/vpci/msix.c
>> @@ -655,6 +655,33 @@ int vpci_make_msix_hole(const struct pci_dev *pdev)
>>      return 0;
>>  }
>>  
>> +static int cf_check cleanup_msix(struct pci_dev *pdev)
>> +{
>> +    int rc;
>> +    struct vpci *vpci = pdev->vpci;
>> +    const unsigned int msix_pos = pdev->msix_pos;
>> +
>> +    if ( !msix_pos )
Need to change this check as previous patch, I think.

>> +        return 0;
>> +
>> +    rc = vpci_remove_registers(vpci, msix_control_reg(msix_pos), 2);
>> +    if ( rc )
>> +        return rc;
>> +
>> +    if ( !vpci->msix )
>> +        return 0;
> 
> You cannot short-circuit here, as it then prevents adding the dummy
> handlers done in the last return.
> 
>> +
>> +    for ( unsigned int i = 0; i < ARRAY_SIZE(vpci->msix->table); i++ )
>> +        if ( vpci->msix->table[i] )
>> +            iounmap(vpci->msix->table[i]);
>> +
>> +    list_del(&vpci->msix->next);
>> +    XFREE(vpci->msix);
>> +
>> +    return vpci_add_register(pdev->vpci, vpci_hw_read16, NULL,
>> +                             msix_control_reg(msix_pos), 2, NULL);
> 
> The above needs to be added even if !vpci->msix.
Oh, right.
I will change to

    if ( vpci->msix )
    {
        for ( unsigned int i = 0; i < ARRAY_SIZE(vpci->msix->table); i++ )
            if ( vpci->msix->table[i] )
                iounmap(vpci->msix->table[i]);

        list_del(&vpci->msix->next);
        XFREE(vpci->msix);
    }

    return vpci_add_register(pdev->vpci, vpci_hw_read16, NULL,
                             msix_control_reg(msix_pos), 2, NULL);


> 
> Thanks, Roger.

-- 
Best regards,
Jiqian Chen.

 


Rackspace

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