From: "Roger Pau Monné" <roger.pau@citrix.com>
To: Jiqian Chen <Jiqian.Chen@amd.com>
Cc: xen-devel@lists.xenproject.org, Huang Rui <ray.huang@amd.com>
Subject: Re: [PATCH v11 5/5] vpci/msix: Implement cleanup function for MSI-X
Date: Fri, 29 Aug 2025 13:06:16 +0200 [thread overview]
Message-ID: <aLGJqMJH46neJYAy@Mac.lan> (raw)
In-Reply-To: <20250808080337.28609-6-Jiqian.Chen@amd.com>
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@amd.com>
> ---
> cc: "Roger Pau Monné" <roger.pau@citrix.com>
> ---
> 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?
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.
next prev parent reply other threads:[~2025-08-29 11:06 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-08 8:03 [PATCH v11 0/5] Support hiding capability when its initialization fails Jiqian Chen
2025-08-08 8:03 ` [PATCH v11 1/5] vpci: Use cleanup to free capability resource during deassign Jiqian Chen
2025-08-08 8:58 ` Jan Beulich
2025-08-11 4:04 ` Chen, Jiqian
2025-08-11 7:24 ` Jan Beulich
2025-08-29 10:07 ` Roger Pau Monné
2025-08-08 8:03 ` [PATCH v11 2/5] vpci: Refactor vpci_remove_register to remove matched registers Jiqian Chen
2025-08-29 10:09 ` Roger Pau Monné
2025-08-08 8:03 ` [PATCH v11 3/5] vpci/rebar: Implement cleanup function for Rebar Jiqian Chen
2025-08-29 10:22 ` Roger Pau Monné
2025-09-10 9:32 ` Chen, Jiqian
2025-08-08 8:03 ` [PATCH v11 4/5] vpci/msi: Implement cleanup function for MSI Jiqian Chen
2025-08-29 10:29 ` Roger Pau Monné
2025-08-29 10:41 ` Roger Pau Monné
2025-09-10 9:57 ` Chen, Jiqian
2025-08-08 8:03 ` [PATCH v11 5/5] vpci/msix: Implement cleanup function for MSI-X Jiqian Chen
2025-08-29 11:06 ` Roger Pau Monné [this message]
2025-09-10 10:11 ` Chen, Jiqian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aLGJqMJH46neJYAy@Mac.lan \
--to=roger.pau@citrix.com \
--cc=Jiqian.Chen@amd.com \
--cc=ray.huang@amd.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.