diff mbox series

vpci/msix: use host msix table address

Message ID 20250415180200.436578-1-stewart.hildebrand@amd.com (mailing list archive)
State New
Headers show
Series vpci/msix: use host msix table address | expand

Commit Message

Stewart Hildebrand April 15, 2025, 6:01 p.m. UTC
Introduce vmsix_table_host_{addr,base} returning the host physical MSI-X
table address and base. Use them in update_entry() and get_table().

Remove stale comment.

Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>
---
I considered adding this tag:
Fixes: 52ebde3cfae2 ("vpci/header: program p2m with guest BAR view")
but I left it out since upstream currently only supports identity-mapped
vPCI.
---
 xen/drivers/vpci/msix.c | 14 ++++----------
 xen/include/xen/vpci.h  | 13 +++++++++++++
 2 files changed, 17 insertions(+), 10 deletions(-)


base-commit: 38d07809794e3c723a4de7e10c25c1f6cb590dc6

Comments

Roger Pau Monné April 17, 2025, 1:46 p.m. UTC | #1
On Tue, Apr 15, 2025 at 02:01:56PM -0400, Stewart Hildebrand wrote:
> Introduce vmsix_table_host_{addr,base} returning the host physical MSI-X
> table address and base. Use them in update_entry() and get_table().
> 
> Remove stale comment.
> 
> Signed-off-by: Stewart Hildebrand <stewart.hildebrand@amd.com>

Reviewed-by: Roger Pau Monné <roger.pau@citrix.com>

> ---
> I considered adding this tag:
> Fixes: 52ebde3cfae2 ("vpci/header: program p2m with guest BAR view")
> but I left it out since upstream currently only supports identity-mapped
> vPCI.

Hm, not sure.  As you say non-identity mapped vPCI usage is not
supported, so I wouldn't insist in backporting the patch.

Thanks, Roger.
diff mbox series

Patch

diff --git a/xen/drivers/vpci/msix.c b/xen/drivers/vpci/msix.c
index 6bd8c55bb48e..f3804ce047a3 100644
--- a/xen/drivers/vpci/msix.c
+++ b/xen/drivers/vpci/msix.c
@@ -57,8 +57,8 @@  static void update_entry(struct vpci_msix_entry *entry,
     }
 
     rc = vpci_msix_arch_enable_entry(entry, pdev,
-                                     vmsix_table_base(pdev->vpci,
-                                                      VPCI_MSIX_TABLE));
+                                     vmsix_table_host_base(pdev->vpci,
+                                                           VPCI_MSIX_TABLE));
     if ( rc )
     {
         gprintk(XENLOG_WARNING, "%pp: unable to enable entry %u: %d\n",
@@ -218,14 +218,14 @@  static void __iomem *get_table(const struct vpci *vpci, unsigned int slot)
         addr = vmsix_table_size(vpci, VPCI_MSIX_TABLE);
         fallthrough;
     case VPCI_MSIX_TBL_HEAD:
-        addr += vmsix_table_addr(vpci, VPCI_MSIX_TABLE);
+        addr += vmsix_table_host_addr(vpci, VPCI_MSIX_TABLE);
         break;
 
     case VPCI_MSIX_PBA_TAIL:
         addr = vmsix_table_size(vpci, VPCI_MSIX_PBA);
         fallthrough;
     case VPCI_MSIX_PBA_HEAD:
-        addr += vmsix_table_addr(vpci, VPCI_MSIX_PBA);
+        addr += vmsix_table_host_addr(vpci, VPCI_MSIX_PBA);
         break;
 
     default:
@@ -242,12 +242,6 @@  static unsigned int get_slot(const struct vpci *vpci, unsigned long addr)
 {
     unsigned long pfn = PFN_DOWN(addr);
 
-    /*
-     * The logic below relies on having the tables identity mapped to the guest
-     * address space, or for the `addr` parameter to be translated into its
-     * host physical memory address equivalent.
-     */
-
     if ( pfn == PFN_DOWN(vmsix_table_addr(vpci, VPCI_MSIX_TABLE)) )
         return VPCI_MSIX_TBL_HEAD;
     if ( pfn == PFN_DOWN(vmsix_table_addr(vpci, VPCI_MSIX_TABLE) +
diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h
index 807401b2eaa2..475981cb8155 100644
--- a/xen/include/xen/vpci.h
+++ b/xen/include/xen/vpci.h
@@ -231,6 +231,19 @@  int vpci_msix_arch_print(const struct vpci_msix *msix);
  * Helper functions to fetch MSIX related data. They are used by both the
  * emulated MSIX code and the BAR handlers.
  */
+static inline paddr_t vmsix_table_host_base(const struct vpci *vpci,
+                                            unsigned int nr)
+{
+    return vpci->header.bars[vpci->msix->tables[nr] & PCI_MSIX_BIRMASK].addr;
+}
+
+static inline paddr_t vmsix_table_host_addr(const struct vpci *vpci,
+                                            unsigned int nr)
+{
+    return vmsix_table_host_base(vpci, nr) +
+           (vpci->msix->tables[nr] & ~PCI_MSIX_BIRMASK);
+}
+
 static inline paddr_t vmsix_table_base(const struct vpci *vpci, unsigned int nr)
 {
     return vpci->header.bars[vpci->msix->tables[nr] &