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

Re: [PATCH v11 5/5] vpci/msix: Implement cleanup function for MSI-X


  • To: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • From: "Chen, Jiqian" <Jiqian.Chen@xxxxxxx>
  • Date: Wed, 10 Sep 2025 10:11:09 +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=Ph6vbwRzsg4J07rqbqonx8auHwK6/iO33Wn/HOQg+1E=; b=KAEOY4ED8wsiu9QLyibakyb9EVCpKdlMqds8UtKjGQCSrInlFvVrUc29WUjO5ghofy9ZvH/pMjnR8BDmMmb2fno7OAoxd3NlC8B1W99vXUtrrAxN/o7NJzDZfkYUztLIFzwvUARlgAcvBWWUeVW/dhtZ05oyIBnt8kUFBuVPEqmJzQ9+nX/YQ3n7Pxp7lEzYM6uPjI4sn/PGn4Ze/50vfk61Iav6OXBBiN6oKuqmivVvdTk149KaFRDAg+S4wbFzxEoUMxeqUI2P4AvMYt5lMVri+flPr4DXJpe4MpcBgNxlL6GdB21M0BiHXNPqIYBe/udR7SK3t5c5dAiwg0SYZg==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=uqXJgupmxrL/JOX1LMNdYIc0KVIkjkCeEQfanSg5CGJWsqRhan7FlOyW7Bdp5As0r+0RY1Tm4rj37maDz62Pp0HMxs18dDq8zPzUHNh/oulpn3OtLI3nhziwPjf813BltwxQFaCzm56qjqduv2tkZLcFYuGledq2KYD9D5ALVZSjJX4d27bw5XK1GEtPDL8eDVPCZ0ozqp30RZfVzjxFb/jujEYNx59un4k7tn5qdvNwG0NjoWCrC+ZOpk2b+akzxhHakXSN3nsJ7ug2Qn8FV16dxgSyrsUqbmTx2uQv7aFZjU8+3c812wWmpYa4f8P2wNJWgrRzkLynGhx/p+cuVA==
  • 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: Wed, 10 Sep 2025 10:11:22 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHcCDsDNbhhyPeREkWOwl6zipBaO7R5mWoAgBNQ/IA=
  • Thread-topic: [PATCH v11 5/5] vpci/msix: Implement cleanup function for MSI-X

On 2025/8/29 19:06, Roger Pau Monné wrote:
> On Fri, Aug 08, 2025 at 04:03:37PM +0800, Jiqian Chen wrote:
>> When MSI-X initialization fails, vPCI hides the capability, but
>> removing handlers and datas won't be performed until the device is
>> deassigned. So, implement MSI-X cleanup hook that will be called
>> to cleanup MSI-X related handlers and free it's associated data when
>> initialization fails.
>>
>> Since cleanup function of MSI-X is implemented, delete the open-code
>> in vpci_deassign_device().
>>
>> Signed-off-by: Jiqian Chen <Jiqian.Chen@xxxxxxx>
>> ---
>> cc: "Roger Pau Monné" <roger.pau@xxxxxxxxxx>
>> ---
>> v10->v11 changes:
>> * Move calling all cleanup hook in vpci_deassign_device() out of this patch.
>> * Add hide parameter to cleanup_msix().
>> * Check hide, if it is false, return directly instead of letting ctrl RO.
>>
>> v9->v10 changes:
>> * Call all cleanup hook in vpci_deassign_device() instead of cleanup_msix().
>>
>> v8->v9 changes:
>> * Modify commit message.
>> * Call cleanup_msix() in vpci_deassign_device() to remove the open-code to 
>> cleanup msix datas.
>> * In cleanup_msix(), move "list_del(&vpci->msix->next);" above for loop of 
>> iounmap msix tables.
>>
>> v7->v8 changes:
>> * Given the code in vpci_remove_registers() an error in the removal of
>>   registers would likely imply memory corruption, at which point it's
>>   best to fully disable the device. So, Rollback the last two modifications 
>> of v7.
>>
>> v6->v7 changes:
>> * Change the pointer parameter of cleanup_msix() to be const.
>> * When vpci_remove_registers() in cleanup_msix() fails, not to return
>>   directly, instead try to free msix and re-add ctrl handler.
>> * Pass pdev->vpci into vpci_add_register() instead of pdev->vpci->msix in
>>   init_msix() since we need that every handler realize that msix is NULL
>>   when msix is freed but handlers are still in there.
>>
>> v5->v6 changes:
>> * Change the logic to add dummy handler when !vpci->msix in cleanup_msix().
>>
>> 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 | 47 ++++++++++++++++++++++++++++++++++++++++-
>>  xen/drivers/vpci/vpci.c |  8 -------
>>  2 files changed, 46 insertions(+), 9 deletions(-)
>>
>> diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c
>> index 54a5070733aa..287aafda9157 100644
>> --- a/xen/drivers/vpci/msix.c
>> +++ b/xen/drivers/vpci/msix.c
>> @@ -655,6 +655,51 @@ int vpci_make_msix_hole(const struct pci_dev *pdev)
>>      return 0;
>>  }
>>  
>> +static int cf_check cleanup_msix(const struct pci_dev *pdev, bool hide)
>> +{
>> +    int rc;
>> +    struct vpci *vpci = pdev->vpci;
>> +    const unsigned int msix_pos = pdev->msix_pos;
>> +
>> +    if ( !msix_pos )
>> +        return 0;
> 
> Like with the MSI capability, is it possible to get called and
> pdev->msix_pos be 0?
Since currently only vpci_deassign_device and vpci_init_capabilities call 
cleanup hook,
and they both have check to prevent pos being 0, so if you think check here is 
redundancy, I will delete it in next version,
MSI and Rebar cleanup hook are the same as here.

> 
> I would also avoid the call to vpci_remove_registers() if !hide, I
> think you can change the order of the cleanup, so it's:
> 
> 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);
> }
> 
> if ( !hide )
>     return 0;
> 
> rc = vpci_remove_registers(vpci, msix_control_reg(msix_pos), 2);
> ...
> 
> 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®.