From 00af54ff6ae3e1f4ab702b9529a22f8523d53ea5 Mon Sep 17 00:00:00 2001 From: Teddy Astie Date: Mon, 3 Aug 2026 09:42:16 +0200 Subject: [PATCH] x86/pci: Use pci_sbdf_t in pci_prepare_msix() Also take the opportunity to clean up a bit PHYSDEVOP_{prepare,release}_msix. Signed-off-by: Teddy Astie Acked-by: Jan Beulich --- xen/arch/x86/include/asm/msi.h | 2 +- xen/arch/x86/msi.c | 4 ++-- xen/arch/x86/physdev.c | 16 +++++++++------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/xen/arch/x86/include/asm/msi.h b/xen/arch/x86/include/asm/msi.h index 00059d4a3a..6fb663b2e7 100644 --- a/xen/arch/x86/include/asm/msi.h +++ b/xen/arch/x86/include/asm/msi.h @@ -83,7 +83,7 @@ struct msi_desc; extern int pci_enable_msi(struct pci_dev *pdev, struct msi_info *msi, struct msi_desc **desc); extern void pci_disable_msi(struct msi_desc *msi_desc); -extern int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off); +extern int pci_prepare_msix(pci_sbdf_t sbdf, bool off); extern void pci_cleanup_msi(struct pci_dev *pdev); extern void pci_disable_msi_all(void); extern int setup_msi_irq(struct irq_desc *desc, struct msi_desc *msidesc); diff --git a/xen/arch/x86/msi.c b/xen/arch/x86/msi.c index 3fe22b3b6d..8831ce068c 100644 --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -1153,7 +1153,7 @@ static void __pci_disable_msix(struct msi_desc *entry) _pci_cleanup_msix(dev->msix); } -int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off) +int pci_prepare_msix(pci_sbdf_t sbdf, bool off) { int rc; struct pci_dev *pdev; @@ -1162,7 +1162,7 @@ int pci_prepare_msix(u16 seg, u8 bus, u8 devfn, bool off) return 0; pcidevs_lock(); - pdev = pci_get_pdev(NULL, PCI_SBDF(seg, bus, devfn)); + pdev = pci_get_pdev(NULL, sbdf); if ( !pdev ) rc = -ENODEV; else if ( pdev->msix->used_entries != !!off ) diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 5bbcf3b530..86d7b82127 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -512,15 +512,17 @@ ret_t do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) case PHYSDEVOP_prepare_msix: case PHYSDEVOP_release_msix: { struct physdev_pci_device dev; + pci_sbdf_t sbdf; + ret = -EFAULT; if ( copy_from_guest(&dev, arg, 1) ) - ret = -EFAULT; - else - ret = xsm_resource_setup_pci(XSM_PRIV, - (dev.seg << 16) | (dev.bus << 8) | - dev.devfn) ?: - pci_prepare_msix(dev.seg, dev.bus, dev.devfn, - cmd != PHYSDEVOP_prepare_msix); + break; + + sbdf = PCI_SBDF(dev.seg, dev.bus, dev.devfn); + + ret = xsm_resource_setup_pci(XSM_PRIV, sbdf.sbdf); + if ( !ret ) + ret = pci_prepare_msix(sbdf, cmd != PHYSDEVOP_prepare_msix); break; }