Skip to contentSkip to conversation

Various IOMMU related simplifications

PATCH In review Teddy Astie 4 participants 17 messages Oct 23, 2025 – Nov 19, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover Various IOMMU related simplifications

Various simplifications in the VT-d and IO-APIC code (mostly related to legacy ia64 code).

No functional change intended.

Changed in v2 :
- drop (un)map_vtd_domain_page wrapper instead of moving it
- drop deprecated and Intel-exclusive iommu_inclusive_mapping=<boolean>
- description and formatting changes

Teddy Astie (5):
vtd: Drop (un)map_vtd_domain_page wrapper
vtd: Drop "iommu_inclusive_mapping" command-line option
vtd: Collapse x86 subdirectory
vtd: Remove IO_xAPIC_route_entry macro x86/ioapic: Don't open-code 32-bits rte reads

 CHANGELOG.md                                |  2 +
 docs/misc/xen-command-line.pandoc           |  6 --
 xen/arch/x86/include/asm/io_apic.h          |  1 +
 xen/arch/x86/io_apic.c                      | 29 +++----
 xen/drivers/passthrough/vtd/Makefile        |  3 +-
 xen/drivers/passthrough/vtd/{x86 => }/ats.c | 21 ++---
 xen/drivers/passthrough/vtd/dmar.c          |  2 +-
 xen/drivers/passthrough/vtd/extern.h        |  3 -
 xen/drivers/passthrough/vtd/intremap.c      | 34 ++++----
 xen/drivers/passthrough/vtd/iommu.c         | 88 ++++++++++-----------
 xen/drivers/passthrough/vtd/iommu.h         |  7 +-
 xen/drivers/passthrough/vtd/qinval.c        | 13 +--
 xen/drivers/passthrough/vtd/utils.c         | 25 +++---
 xen/drivers/passthrough/vtd/vtd.h           |  3 -
 xen/drivers/passthrough/vtd/x86/Makefile    |  2 -
 xen/drivers/passthrough/vtd/x86/vtd.c       | 48 -----------
 16 files changed, 108 insertions(+), 179 deletions(-)
 rename xen/drivers/passthrough/vtd/{x86 => }/ats.c (92%)
 delete mode 100644 xen/drivers/passthrough/vtd/x86/Makefile
 delete mode 100644 xen/drivers/passthrough/vtd/x86/vtd.c
Signature · 10 lines
2.51.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#1 lore raw

PATCH v2 1/5 vtd: Drop (un)map_vtd_domain_page wrapper

Replace use of (un)map_vtd_domain_page with its general equivalents. Also take the opportunity to make iommu->root_page (previously root_maddr) use struct page_info instead of u64.

---
v2:
- drop instead of moving
- also replace root_addr with root_page (with struct page_info)

 xen/drivers/passthrough/vtd/dmar.c     |  2 +-
 xen/drivers/passthrough/vtd/extern.h   |  3 -
 xen/drivers/passthrough/vtd/intremap.c | 15 +++--
 xen/drivers/passthrough/vtd/iommu.c    | 88 ++++++++++++--------------
 xen/drivers/passthrough/vtd/iommu.h    |  7 +-
 xen/drivers/passthrough/vtd/qinval.c   | 13 ++--
 xen/drivers/passthrough/vtd/utils.c    | 25 ++++----
 xen/drivers/passthrough/vtd/x86/ats.c  | 11 ++--
 xen/drivers/passthrough/vtd/x86/vtd.c  | 10 ---
 9 files changed, 80 insertions(+), 94 deletions(-)
xen/drivers/passthrough/vtd/dmar.c +1 -1
index 91c22b8330..2380825f1c 100644
@@ -1107,7 +1107,7 @@ int __init acpi_dmar_init(void)
         if ( rhsa )
             iommu->node = pxm_to_node(rhsa->proximity_domain);
 
-        if ( !(iommu->root_maddr = alloc_pgtable_maddr(1, iommu->node)) )
+        if ( !(iommu->root_page = maddr_to_page(alloc_pgtable_maddr(1, iommu->node))) )
             ret = -ENOMEM;
     }
 
xen/drivers/passthrough/vtd/extern.h +0 -3
index c16583c951..2be50de168 100644
@@ -77,9 +77,6 @@ int __must_check qinval_device_iotlb_sync(struct vtd_iommu *iommu,
                                           u16 did, u16 size, u64 addr);
 
 uint64_t alloc_pgtable_maddr(unsigned long npages, nodeid_t node);
-void free_pgtable_maddr(u64 maddr);
-void *map_vtd_domain_page(u64 maddr);
-void unmap_vtd_domain_page(const void *va);
 int domain_context_mapping_one(struct domain *domain, struct vtd_iommu *iommu,
                                uint8_t bus, uint8_t devfn,
                                const struct pci_dev *pdev, domid_t domid,
xen/drivers/passthrough/vtd/intremap.c +8 -7
index 7726ee618a..6c779d476d 100644
@@ -17,6 +17,7 @@
  * Copyright (C) Xiaohui Xin <[email protected]>
  */
 
+#include <xen/domain_page.h>
 #include <xen/irq.h>
 #include <xen/sched.h>
 #include <xen/iommu.h>
@@ -222,7 +223,7 @@ static void free_remap_entry(struct vtd_iommu *iommu, int index)
     iommu_sync_cache(iremap_entry, sizeof(*iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
 
-    unmap_vtd_domain_page(iremap_entries);
+    unmap_domain_page(iremap_entries);
     iommu->intremap.num--;
 }
 
@@ -244,7 +245,7 @@ static unsigned int alloc_remap_entry(struct vtd_iommu *iommu, unsigned int nr)
         {
             /* This entry across page boundry */
             if ( iremap_entries )
-                unmap_vtd_domain_page(iremap_entries);
+                unmap_domain_page(iremap_entries);
 
             GET_IREMAP_ENTRY(iommu->intremap.maddr, i,
                              iremap_entries, p);
@@ -259,7 +260,7 @@ static unsigned int alloc_remap_entry(struct vtd_iommu *iommu, unsigned int nr)
     }
 
     if ( iremap_entries )
-        unmap_vtd_domain_page(iremap_entries);
+        unmap_domain_page(iremap_entries);
 
     if ( i < IREMAP_ENTRY_NR )
         iommu->intremap.num += nr;
@@ -291,7 +292,7 @@ static int remap_entry_to_ioapic_rte(
         dprintk(XENLOG_ERR VTDPREFIX,
                 "IO-APIC index (%d) has an empty entry\n",
                 index);
-        unmap_vtd_domain_page(iremap_entries);
+        unmap_domain_page(iremap_entries);
         spin_unlock_irqrestore(&iommu->intremap.lock, flags);
         return -EFAULT;
     }
@@ -309,7 +310,7 @@ static int remap_entry_to_ioapic_rte(
         old_rte->dest.logical.logical_dest = iremap_entry->remap.dst >> 8;
     }
 
-    unmap_vtd_domain_page(iremap_entries);
+    unmap_domain_page(iremap_entries);
     spin_unlock_irqrestore(&iommu->intremap.lock, flags);
 
     return 0;
@@ -388,7 +389,7 @@ static int ioapic_rte_to_remap_entry(struct vtd_iommu *iommu,
     iommu_sync_cache(iremap_entry, sizeof(*iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
 
-    unmap_vtd_domain_page(iremap_entries);
+    unmap_domain_page(iremap_entries);
     spin_unlock_irqrestore(&iommu->intremap.lock, flags);
     return 0;
 }
@@ -607,7 +608,7 @@ static int msi_msg_to_remap_entry(
     iommu_sync_cache(iremap_entry, sizeof(*iremap_entry));
     iommu_flush_iec_index(iommu, 0, index);
 
-    unmap_vtd_domain_page(iremap_entries);
+    unmap_domain_page(iremap_entries);
     spin_unlock_irqrestore(&iommu->intremap.lock, flags);
 
     return alloc;
xen/drivers/passthrough/vtd/iommu.c +41 -47

296 lines not on this page · raw message

xen/drivers/passthrough/vtd/iommu.h +4 -3
index 29d350b23d..7c40f81408 100644
@@ -19,6 +19,7 @@
 #ifndef DRIVERS__PASSTHROUGH__VTD__IOMMU_H
 #define DRIVERS__PASSTHROUGH__VTD__IOMMU_H
 
+#include <xen/domain_page.h>
 #include <xen/iommu.h>
 #include <asm/msi.h>
 
@@ -366,8 +367,8 @@ struct iremap_entry {
  */
 #define GET_IREMAP_ENTRY(maddr, index, entries, entry)                        \
 do {                                                                          \
-    entries = (struct iremap_entry *)map_vtd_domain_page(                     \
-              (maddr) + (( (index) >> IREMAP_ENTRY_ORDER ) << PAGE_SHIFT ) ); \
+    entries = (struct iremap_entry *)map_domain_page(maddr_to_mfn(            \
+              (maddr) + (( (index) >> IREMAP_ENTRY_ORDER ) << PAGE_SHIFT ) ));\
     entry = &entries[(index) % (1 << IREMAP_ENTRY_ORDER)];                    \
 } while(0)
 
@@ -482,7 +483,7 @@ struct vtd_iommu {
     u64	ecap;
     spinlock_t lock; /* protect context */
     spinlock_t register_lock; /* protect iommu register handling */
-    u64 root_maddr; /* root entry machine address */
+    struct page_info *root_page; /* root entry page */
     nodeid_t node;
     struct msi_desc msi;
     struct acpi_drhd_unit *drhd;
xen/drivers/passthrough/vtd/qinval.c +7 -6
index 036f3e8505..eb37832363 100644
@@ -18,6 +18,7 @@
  */
 
 
+#include <xen/domain_page.h>
 #include <xen/sched.h>
 #include <xen/iommu.h>
 #include <xen/time.h>
@@ -81,7 +82,7 @@ static struct qinval_entry *qi_map_entry(const struct vtd_iommu *iommu,
 {
     paddr_t base = iommu->qinval_maddr +
                    ((index * sizeof(struct qinval_entry)) & PAGE_MASK);
-    struct qinval_entry *entries = map_vtd_domain_page(base);
+    struct qinval_entry *entries = map_domain_page(maddr_to_mfn(base));
 
     return &entries[index % (PAGE_SIZE / sizeof(*entries))];
 }
@@ -111,7 +112,7 @@ static int __must_check queue_invalidate_context_sync(struct vtd_iommu *iommu,
     qinval_update_qtail(iommu, index);
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 
-    unmap_vtd_domain_page(qinval_entry);
+    unmap_domain_page(qinval_entry);
 
     return invalidate_sync(iommu);
 }
@@ -145,7 +146,7 @@ static int __must_check queue_invalidate_iotlb_sync(struct vtd_iommu *iommu,
     qinval_update_qtail(iommu, index);
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 
-    unmap_vtd_domain_page(qinval_entry);
+    unmap_domain_page(qinval_entry);
 
     return invalidate_sync(iommu);
 }
@@ -176,7 +177,7 @@ static int __must_check queue_invalidate_wait(struct vtd_iommu *iommu,
     qinval_update_qtail(iommu, index);
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 
-    unmap_vtd_domain_page(qinval_entry);
+    unmap_domain_page(qinval_entry);
 
     /* Now we don't support interrupt method */
     if ( sw )
@@ -277,7 +278,7 @@ int qinval_device_iotlb_sync(struct vtd_iommu *iommu, struct pci_dev *pdev,
     qinval_update_qtail(iommu, index);
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 
-    unmap_vtd_domain_page(qinval_entry);
+    unmap_domain_page(qinval_entry);
 
     return dev_invalidate_sync(iommu, pdev, did);
 }
@@ -305,7 +306,7 @@ static int __must_check queue_invalidate_iec_sync(struct vtd_iommu *iommu,
     qinval_update_qtail(iommu, index);
     spin_unlock_irqrestore(&iommu->register_lock, flags);
 
-    unmap_vtd_domain_page(qinval_entry);
+    unmap_domain_page(qinval_entry);
 
     ret = invalidate_sync(iommu);
 
xen/drivers/passthrough/vtd/utils.c +13 -12
index 7c4d032f4f..5d365ea4e9 100644
@@ -18,6 +18,7 @@
 
 #include <xen/sched.h>
 #include <xen/delay.h>
+#include <xen/domain_page.h>
 #include <xen/iommu.h>
 #include <xen/time.h>
 #include <xen/pci.h>
@@ -99,38 +100,38 @@ void print_vtd_entries(struct vtd_iommu *iommu, int bus, int devfn, u64 gmfn)
            iommu->index, &PCI_SBDF(iommu->drhd->segment, bus, devfn),
            gmfn);
 
-    if ( iommu->root_maddr == 0 )
+    if ( iommu->root_page == NULL )
     {
-        printk("    iommu->root_maddr = 0\n");
+        printk("    iommu->root_maddr = NULL\n");
         return;
     }
 
-    root_entry = (struct root_entry *)map_vtd_domain_page(iommu->root_maddr);
+    root_entry = __map_domain_page(iommu->root_page);
 
     printk("    root_entry[%02x] = %"PRIx64"\n", bus, root_entry[bus].val);
     if ( !root_present(root_entry[bus]) )
     {
-        unmap_vtd_domain_page(root_entry);
+        unmap_domain_page(root_entry);
         printk("    root_entry[%02x] not present\n", bus);
         return;
     }
 
     val = root_entry[bus].val;
-    unmap_vtd_domain_page(root_entry);
-    ctxt_entry = map_vtd_domain_page(val);
+    unmap_domain_page(root_entry);
+    ctxt_entry = map_domain_page(maddr_to_mfn(val));
 
     val = ctxt_entry[devfn].lo;
     printk("    context[%02x] = %"PRIx64"_%"PRIx64"\n",
            devfn, ctxt_entry[devfn].hi, val);
     if ( !context_present(ctxt_entry[devfn]) )
     {
-        unmap_vtd_domain_page(ctxt_entry);
+        unmap_domain_page(ctxt_entry);
         printk("    ctxt_entry[%02x] not present\n", devfn);
         return;
     }
 
     level = agaw_to_level(context_address_width(ctxt_entry[devfn]));
-    unmap_vtd_domain_page(ctxt_entry);
+    unmap_domain_page(ctxt_entry);
     if ( level != VTD_PAGE_TABLE_LEVEL_3 &&
          level != VTD_PAGE_TABLE_LEVEL_4)
     {
@@ -140,10 +141,10 @@ void print_vtd_entries(struct vtd_iommu *iommu, int bus, int devfn, u64 gmfn)
 
     do
     {
-        l = map_vtd_domain_page(val);
+        l = map_domain_page(maddr_to_mfn(val));
         l_index = get_level_index(gmfn, level);
         pte.val = l[l_index];
-        unmap_vtd_domain_page(l);
+        unmap_domain_page(l);
         printk("    l%u[%03x] = %"PRIx64" %c%c\n", level, l_index, pte.val,
                dma_pte_read(pte) ? 'r' : '-',
                dma_pte_write(pte) ? 'w' : '-');
@@ -204,7 +205,7 @@ void cf_check vtd_dump_iommu_info(unsigned char key)
                 {
                     /* This entry across page boundry */
                     if ( iremap_entries )
-                        unmap_vtd_domain_page(iremap_entries);
+                        unmap_domain_page(iremap_entries);
 
                     GET_IREMAP_ENTRY(iremap_maddr, i,
                                      iremap_entries, p);
@@ -232,7 +233,7 @@ void cf_check vtd_dump_iommu_info(unsigned char key)
                 print_cnt++;
             }
             if ( iremap_entries )
-                unmap_vtd_domain_page(iremap_entries);
+                unmap_domain_page(iremap_entries);
             if ( iommu->intremap.num != print_cnt )
                 printk("Warning: Print %u IRTE (actually have %u)!\n",
                         print_cnt, iommu->intremap.num);
xen/drivers/passthrough/vtd/x86/ats.c +6 -5
index 61052ef580..fed3588e8e 100644
@@ -16,6 +16,7 @@
  * Author: Allen Kay <[email protected]>
  */
 
+#include <xen/domain_page.h>
 #include <xen/sched.h>
 #include <xen/iommu.h>
 #include <xen/time.h>
@@ -83,17 +84,17 @@ static bool device_in_domain(const struct vtd_iommu *iommu,
     unsigned int tt;
     bool found = false;
 
-    if ( unlikely(!iommu->root_maddr) )
+    if ( unlikely(!iommu->root_page) )
     {
         ASSERT_UNREACHABLE();
         return false;
     }
 
-    root_entry = map_vtd_domain_page(iommu->root_maddr);
+    root_entry = __map_domain_page(iommu->root_page);
     if ( !root_present(root_entry[pdev->bus]) )
         goto out;
 
-    ctxt_entry = map_vtd_domain_page(root_entry[pdev->bus].val);
+    ctxt_entry = map_domain_page(maddr_to_mfn(root_entry[pdev->bus].val));
     if ( context_domain_id(ctxt_entry[pdev->devfn]) != did )
         goto out;
 
@@ -104,10 +105,10 @@ static bool device_in_domain(const struct vtd_iommu *iommu,
     found = true;
 out:
     if ( root_entry )
-        unmap_vtd_domain_page(root_entry);
+        unmap_domain_page(root_entry);
 
     if ( ctxt_entry )
-        unmap_vtd_domain_page(ctxt_entry);
+        unmap_domain_page(ctxt_entry);
 
     return found;
 }
xen/drivers/passthrough/vtd/x86/vtd.c +0 -10
index 76f12adc23..b0798dc6a1 100644
@@ -36,13 +36,3 @@
  * 1:1 iommu mappings except xen and unusable regions.
  */
 boolean_param("iommu_inclusive_mapping", iommu_hwdom_inclusive);
-
-void *map_vtd_domain_page(u64 maddr)
-{
-    return map_domain_page(_mfn(paddr_to_pfn(maddr)));
-}
-
-void unmap_vtd_domain_page(const void *va)
-{
-    unmap_domain_page(va);
-}
Signature · 10 lines
2.51.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#2 lore raw

Re: [PATCH v2 1/5] vtd: Drop (un)map_vtd_domain_page wrapper

Quoted 3 lines · Teddy Astie

Replace use of (un)map_vtd_domain_page with its general equivalents. Also take the opportunity to make iommu->root_page (previously root_maddr) use struct page_info instead of u64.

free_pgtable_maddr() also goes away as it seems.

xen/drivers/passthrough/vtd/intremap.c static unsigned int alloc_remap_entry(struct vtd_iommu *iommu, unsigned int nr) · line 248

Quoted 6 lines
xen/drivers/passthrough/vtd/intremap.c +1 -1
@@ -244,7 +245,7 @@ static unsigned int alloc_remap_entry(struct vtd_iommu *iommu, unsigned int nr)
         {
             /* This entry across page boundry */
             if ( iremap_entries )
-                unmap_vtd_domain_page(iremap_entries);
+                unmap_domain_page(iremap_entries);

Please can you also drop such redundant conditionals then? unmap_domain_page() may validly be called with NULL. Overall it looks as if this patch could do with splitting, as the unmap_vtd_domain_page() replacement is an entirely mechanical one (and accounts for a fair part of the patch). I'm not going to insist, though.

xen/drivers/passthrough/vtd/iommu.h struct iremap_entry { · line 373

Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.h +2 -2
@@ -366,8 +367,8 @@ struct iremap_entry {
  */
 #define GET_IREMAP_ENTRY(maddr, index, entries, entry)                        \
 do {                                                                          \
-    entries = (struct iremap_entry *)map_vtd_domain_page(                     \
-              (maddr) + (( (index) >> IREMAP_ENTRY_ORDER ) << PAGE_SHIFT ) ); \
+    entries = (struct iremap_entry *)map_domain_page(maddr_to_mfn(            \
+              (maddr) + (( (index) >> IREMAP_ENTRY_ORDER ) << PAGE_SHIFT ) ));\
     entry = &entries[(index) % (1 << IREMAP_ENTRY_ORDER)];                    \
 } while(0)

You drop casts elsewhere - why not here? Also, as you touch the 2nd of the lines, can you please also drop the excess blanks? And then, while only theoretically at risk of overflowing, the open-coded left shift may also want replacing by e.g. pfn_to_paddr(), i.e. something which incorporates a suitable cast to paddr_t.

xen/drivers/passthrough/vtd/qinval.c line 24

Quoted 10 lines
xen/drivers/passthrough/vtd/qinval.c +1 -0
@@ -18,6 +18,7 @@
  */
 
 
+#include <xen/domain_page.h>
 #include <xen/sched.h>
 #include <xen/iommu.h>
 #include <xen/time.h>

Please could you take the opportunity and also get rid of one of the two blank lines?

xen/drivers/passthrough/vtd/qinval.c void print_vtd_entries(struct vtd_iommu *iommu, int bus, int devfn, u64 gmfn) · line 105

Quoted 9 lines
xen/drivers/passthrough/vtd/qinval.c +2 -2
@@ -99,38 +100,38 @@ void print_vtd_entries(struct vtd_iommu *iommu, int bus, int devfn, u64 gmfn)
            iommu->index, &PCI_SBDF(iommu->drhd->segment, bus, devfn),
            gmfn);
 
-    if ( iommu->root_maddr == 0 )
+    if ( iommu->root_page == NULL )
     {
-        printk("    iommu->root_maddr = 0\n");
+        printk("    iommu->root_maddr = NULL\n");

root_page here then as well?

Jan

#3 lore raw

PATCH v2 2/5 vtd: Drop "iommu_inclusive_mapping" command-line option

In reply to Teddy Astie

This command-line option is deprecated and super-seeded with dom0-iommu=map-inclusive. Drop this command-line parameter and delete vtd/x86/vtd.c which is now empty.

---
v2:
- new

 CHANGELOG.md                             |  2 ++
 docs/misc/xen-command-line.pandoc        |  6 ----
 xen/drivers/passthrough/vtd/x86/Makefile |  3 +-
 xen/drivers/passthrough/vtd/x86/vtd.c    | 38 ------------------------
 4 files changed, 3 insertions(+), 46 deletions(-)
 delete mode 100644 xen/drivers/passthrough/vtd/x86/vtd.c
CHANGELOG.md +2 -0
index 0cf9ad2d95..d4a22b8f8b 100644
@@ -50,6 +50,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
  - On x86:
    - GNTTABOP_cache_flush: it's unused on x86 and the implementation is
      broken.
+   - Intel-specific iommu_inclusive_mapping=<boolean> option: super-seeded
+     by dom0-iommu=map-inclusive since Xen 4.16.
 
  - Support of qemu-traditional has been removed.
 
docs/misc/xen-command-line.pandoc +0 -6
index 28a98321c7..0af71e289a 100644
@@ -1691,12 +1691,6 @@ Specify the timeout of the device IOTLB invalidation in milliseconds.
 By default, the timeout is 1000 ms. When you see error 'Queue invalidate
 wait descriptor timed out', try increasing this value.
 
-### iommu_inclusive_mapping
-> `= <boolean>`
-
-**WARNING: This command line option is deprecated, and superseded by
-_dom0-iommu=map-inclusive_ - using both options in combination is undefined.**
-
 ### irq-max-guests (x86)
 > `= <integer>`
 
xen/drivers/passthrough/vtd/x86/Makefile +1 -2
index fe20a0b019..82b3904a91 100644
@@ -1,2 +1 @@
-obj-y += ats.o
-obj-y += vtd.o
+obj-y += ats.o
\ No newline at end of file
xen/drivers/passthrough/vtd/x86/vtd.c deleted +0 -38
deleted file mode 100644
index b0798dc6a1..0000000000
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2008, Intel Corporation.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; If not, see <http://www.gnu.org/licenses/>.
- *
- * Copyright (C) Allen Kay <[email protected]>
- * Copyright (C) Weidong Han <[email protected]>
- */
-
-#include <xen/param.h>
-#include <xen/sched.h>
-#include <xen/softirq.h>
-#include <xen/domain_page.h>
-#include <asm/paging.h>
-#include <xen/iommu.h>
-#include <xen/irq.h>
-#include <xen/numa.h>
-#include <asm/fixmap.h>
-#include "../iommu.h"
-#include "../dmar.h"
-#include "../vtd.h"
-#include "../extern.h"
-
-/*
- * iommu_inclusive_mapping: when set, all memory below 4GB is included in dom0
- * 1:1 iommu mappings except xen and unusable regions.
- */
-boolean_param("iommu_inclusive_mapping", iommu_hwdom_inclusive);
Signature · 10 lines
2.51.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#4 lore raw

Re: [PATCH v2 2/5] vtd: Drop "iommu_inclusive_mapping" command-line option

CHANGELOG.md The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) · line 56

Quoted 10 lines · Teddy Astie
CHANGELOG.md +2 -0
@@ -50,6 +50,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
  - On x86:
    - GNTTABOP_cache_flush: it's unused on x86 and the implementation is
      broken.
+   - Intel-specific iommu_inclusive_mapping=<boolean> option: super-seeded
+     by dom0-iommu=map-inclusive since Xen 4.16.
 
  - Support of qemu-traditional has been removed.

This is the kind of change that isn't very useful to post during the freeze period. The change to this file will need re-basing anyway after branching, when in fact it may then still (wrongly) apply cleanly.

Jan

#5 lore raw

PATCH v2 3/5 vtd: Collapse x86 subdirectory

In reply to Teddy Astie

The x86 subdirectory was originally meant to split x86-specific logic from general VT-d code. Today, Xen only supports VT-d on x86 and the code actually implemented in this subdirectory isn't x86-specific (e.g ATS code is not x86 specific).

As ats.c is the only remaining file in this directory, and isn't x86 specific, move it up to vtd directory and remove the now empty x86 subdirectory.

---
v2:
- reviewed commit description

 xen/drivers/passthrough/vtd/Makefile        |  3 +--
 xen/drivers/passthrough/vtd/{x86 => }/ats.c | 10 +++++-----
 xen/drivers/passthrough/vtd/x86/Makefile    |  1 -
 3 files changed, 6 insertions(+), 8 deletions(-)
 rename xen/drivers/passthrough/vtd/{x86 => }/ats.c (97%)
 delete mode 100644 xen/drivers/passthrough/vtd/x86/Makefile
xen/drivers/passthrough/vtd/Makefile +1 -2
index fde7555fac..328a014016 100644
@@ -1,5 +1,4 @@
-obj-$(CONFIG_X86) += x86/
-
+obj-y += ats.o
 obj-y += iommu.o
 obj-y += dmar.o
 obj-y += utils.o
xen/drivers/passthrough/vtd/ats.c renamed from xen/drivers/passthrough/vtd/x86/ats.c +5 -5
similarity index 97%
rename from xen/drivers/passthrough/vtd/x86/ats.c
rename to xen/drivers/passthrough/vtd/ats.c
index fed3588e8e..3b7c4028a6 100644
@@ -23,11 +23,11 @@
 #include <xen/pci.h>
 #include <xen/pci_regs.h>
 #include <asm/msi.h>
-#include "../iommu.h"
-#include "../dmar.h"
-#include "../vtd.h"
-#include "../extern.h"
-#include "../../ats.h"
+#include "iommu.h"
+#include "dmar.h"
+#include "vtd.h"
+#include "extern.h"
+#include "../ats.h"
 
 static LIST_HEAD(ats_dev_drhd_units);
 
xen/drivers/passthrough/vtd/x86/Makefile deleted +0 -1
deleted file mode 100644
index 82b3904a91..0000000000
@@ -1 +0,0 @@
-obj-y += ats.o
\ No newline at end of file
Signature · 10 lines
2.51.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#6 lore raw

Re: [PATCH v2 3/5] vtd: Collapse x86 subdirectory

Quoted 13 lines · Teddy Astie

The x86 subdirectory was originally meant to split x86-specific logic from general VT-d code. Today, Xen only supports VT-d on x86 and the code actually implemented in this subdirectory isn't x86-specific (e.g ATS code is not x86 specific).

As ats.c is the only remaining file in this directory, and isn't x86 specific, move it up to vtd directory and remove the now empty x86 subdirectory.

---
v2:
- reviewed commit description

Quoted 6 lines
 xen/drivers/passthrough/vtd/Makefile        |  3 +--
 xen/drivers/passthrough/vtd/{x86 => }/ats.c | 10 +++++-----
 xen/drivers/passthrough/vtd/x86/Makefile    |  1 -
 3 files changed, 6 insertions(+), 8 deletions(-)
 rename xen/drivers/passthrough/vtd/{x86 => }/ats.c (97%)
 delete mode 100644 xen/drivers/passthrough/vtd/x86/Makefile

I should have remembered this when looking at v1 already: While some of your other changes go farther (and hence are likely preferable), this one I'd rather not see go in. I'd favor respective pieces of what's still pending from
https://lists.xen.org/archives/html/xen-devel/2024-02/msg00983.html. First and foremost because ATS really is not only not x86-specific - it's not VT-d- specific either.

Jan

#7 lore raw

Re: [PATCH v2 3/5] vtd: Collapse x86 subdirectory

Le 23/10/2025 à 12:20, Jan Beulich a écrit :

Quoted 21 lines · Teddy Astie
Quoted 13 lines

The x86 subdirectory was originally meant to split x86-specific logic from general VT-d code. Today, Xen only supports VT-d on x86 and the code actually implemented in this subdirectory isn't x86-specific (e.g ATS code is not x86 specific).

As ats.c is the only remaining file in this directory, and isn't x86 specific, move it up to vtd directory and remove the now empty x86 subdirectory.

---
v2:
- reviewed commit description

Quoted 6 lines
  xen/drivers/passthrough/vtd/Makefile        |  3 +--
  xen/drivers/passthrough/vtd/{x86 => }/ats.c | 10 +++++-----
  xen/drivers/passthrough/vtd/x86/Makefile    |  1 -
  3 files changed, 6 insertions(+), 8 deletions(-)

rename xen/drivers/passthrough/vtd/{x86 => }/ats.c (97%) delete mode 100644 xen/drivers/passthrough/vtd/x86/Makefile

Quoted 6 lines

I should have remembered this when looking at v1 already: While some of your other changes go farther (and hence are likely preferable), this one I'd rather not see go in. I'd favor respective pieces of what's still pending from
https://lists.xen.org/archives/html/xen-devel/2024-02/msg00983.html. First and foremost because ATS really is not only not x86-specific - it's not VT-d- specific either.

CC-ing Jason Andryuk now reviewer of AMD-Vi code and likely interested with https://lists.xen.org/archives/html/xen-devel/2024-02/msg00983.html
at least for the AMD part.

I wasn't aware of this pending series. And some of my patches overlap with some of these ones, so I guess we need to complete it and then I rebase mine on top of it.

Quoted 3 lines

Jan

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#8 lore raw

Re: [PATCH v2 3/5] vtd: Collapse x86 subdirectory

Quoted 29 lines · Teddy Astie

Le 23/10/2025 à 12:20, Jan Beulich a écrit :

Quoted 21 lines · Teddy Astie
Quoted 13 lines

The x86 subdirectory was originally meant to split x86-specific logic from general VT-d code. Today, Xen only supports VT-d on x86 and the code actually implemented in this subdirectory isn't x86-specific (e.g ATS code is not x86 specific).

As ats.c is the only remaining file in this directory, and isn't x86 specific, move it up to vtd directory and remove the now empty x86 subdirectory.

---
v2:
- reviewed commit description

Quoted 6 lines
  xen/drivers/passthrough/vtd/Makefile        |  3 +--
  xen/drivers/passthrough/vtd/{x86 => }/ats.c | 10 +++++-----
  xen/drivers/passthrough/vtd/x86/Makefile    |  1 -
  3 files changed, 6 insertions(+), 8 deletions(-)

rename xen/drivers/passthrough/vtd/{x86 => }/ats.c (97%) delete mode 100644 xen/drivers/passthrough/vtd/x86/Makefile

Quoted 6 lines

I should have remembered this when looking at v1 already: While some of your other changes go farther (and hence are likely preferable), this one I'd rather not see go in. I'd favor respective pieces of what's still pending from
https://lists.xen.org/archives/html/xen-devel/2024-02/msg00983.html. First and foremost because ATS really is not only not x86-specific - it's not VT-d- specific either.

Quoted 7 lines

CC-ing Jason Andryuk now reviewer of AMD-Vi code and likely interested with https://lists.xen.org/archives/html/xen-devel/2024-02/msg00983.html
at least for the AMD part.

I wasn't aware of this pending series. And some of my patches overlap with some of these ones, so I guess we need to complete it and then I rebase mine on top of it.

It's going to be an intermix, I think. Your map/unmap changes are preferable to mine, for example.

Jan

#9 lore raw

PATCH v2 4/5 vtd: Remove IO_xAPIC_route_entry macro

In reply to Teddy Astie

This macro was introduced to abstract between IO-APIC and IO-SAPIC (ia64), now that ia64 isn't supported anymore, this macro now only refers to IO-APIC.

---
v2:
- formatting changes

 xen/drivers/passthrough/vtd/intremap.c | 10 +++++-----
 xen/drivers/passthrough/vtd/vtd.h      |  3 ---
 2 files changed, 5 insertions(+), 8 deletions(-)
xen/drivers/passthrough/vtd/intremap.c +5 -5
index 6c779d476d..612e08bcec 100644
@@ -269,7 +269,7 @@ static unsigned int alloc_remap_entry(struct vtd_iommu *iommu, unsigned int nr)
 }
 
 static int remap_entry_to_ioapic_rte(
-    struct vtd_iommu *iommu, int index, struct IO_xAPIC_route_entry *old_rte)
+    struct vtd_iommu *iommu, int index, struct IO_APIC_route_entry *old_rte)
 {
     struct iremap_entry *iremap_entry = NULL, *iremap_entries;
     unsigned long flags;
@@ -317,8 +317,8 @@ static int remap_entry_to_ioapic_rte(
 }
 
 static int ioapic_rte_to_remap_entry(struct vtd_iommu *iommu,
-    int apic, unsigned int ioapic_pin, struct IO_xAPIC_route_entry *old_rte,
-    struct IO_xAPIC_route_entry new_rte)
+    int apic, unsigned int ioapic_pin, struct IO_APIC_route_entry *old_rte,
+    struct IO_APIC_route_entry new_rte)
 {
     struct iremap_entry *iremap_entry = NULL, *iremap_entries;
     struct iremap_entry new_ire;
@@ -399,7 +399,7 @@ unsigned int cf_check io_apic_read_remap_rte(
 {
     unsigned int ioapic_pin = (reg - 0x10) / 2;
     int index;
-    struct IO_xAPIC_route_entry old_rte = { };
+    struct IO_APIC_route_entry old_rte = {};
     int rte_upper = (reg & 1) ? 1 : 0;
     struct vtd_iommu *iommu = ioapic_to_iommu(IO_APIC_ID(apic));
 
@@ -421,7 +421,7 @@ unsigned int cf_check io_apic_read_remap_rte(
 void cf_check io_apic_write_remap_rte(
     unsigned int apic, unsigned int pin, uint64_t rte)
 {
-    struct IO_xAPIC_route_entry old_rte = {}, new_rte;
+    struct IO_APIC_route_entry old_rte = {}, new_rte;
     struct vtd_iommu *iommu = ioapic_to_iommu(IO_APIC_ID(apic));
     int rc;
 
xen/drivers/passthrough/vtd/vtd.h +0 -3
index b95124517b..f0286b40c3 100644
@@ -31,9 +31,6 @@
 #define MAP_ERROR_RECOVERY    (1u << 2)
 #define UNMAP_ME_PHANTOM_FUNC (1u << 3)
 
-/* Allow for both IOAPIC and IOSAPIC. */
-#define IO_xAPIC_route_entry IO_APIC_route_entry
-
 struct IO_APIC_route_remap_entry {
     union {
         u64 val;
Signature · 10 lines
2.51.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#10 lore raw

Re: [PATCH v2 4/5] vtd: Remove IO_xAPIC_route_entry macro

Quoted 7 lines · Teddy Astie

This macro was introduced to abstract between IO-APIC and IO-SAPIC (ia64), now that ia64 isn't supported anymore, this macro now only refers to IO-APIC.

---
v2:
- formatting changes

But you could have retained Andrew's ack, I suppose?

Jan

#11 lore raw

PATCH v2 5/5 x86/ioapic: Don't open-code 32-bits rte reads

In reply to Teddy Astie

There are many places where we use interesting ways of reading 32-bits components of the RTE. Introduce and use low and high components directly to the rte structure instead.

Also take the opportunity to simplify "x & 1 ? 1 : 0".

---
v2:
- make rte_upper to use bool instead

 xen/arch/x86/include/asm/io_apic.h     |  1 +
 xen/arch/x86/io_apic.c                 | 29 ++++++++++----------------
 xen/drivers/passthrough/vtd/intremap.c |  9 +++-----
 3 files changed, 15 insertions(+), 24 deletions(-)
xen/arch/x86/include/asm/io_apic.h +1 -0
index 4680dce9e1..0e85f2a860 100644
@@ -122,6 +122,7 @@ struct IO_APIC_route_entry {
             } dest;
         };
         uint64_t raw;
+        struct { uint32_t low, high; };
     };
 };
 
xen/arch/x86/io_apic.c +11 -18
index 24447aef6c..9d2edec179 100644
@@ -257,28 +257,23 @@ nomem:
     return NULL;
 }
 
-union entry_union {
-    struct { u32 w1, w2; };
-    struct IO_APIC_route_entry entry;
-};
-
 struct IO_APIC_route_entry __ioapic_read_entry(
     unsigned int apic, unsigned int pin, bool raw)
 {
-    union entry_union eu;
+    struct IO_APIC_route_entry entry;
 
     if ( raw || !iommu_intremap )
     {
-        eu.w1 = __io_apic_read(apic, 0x10 + 2 * pin);
-        eu.w2 = __io_apic_read(apic, 0x11 + 2 * pin);
+        entry.low  = __io_apic_read(apic, 0x10 + 2 * pin);
+        entry.high = __io_apic_read(apic, 0x11 + 2 * pin);
     }
     else
     {
-        eu.w1 = iommu_read_apic_from_ire(apic, 0x10 + 2 * pin);
-        eu.w2 = iommu_read_apic_from_ire(apic, 0x11 + 2 * pin);
+        entry.low  = iommu_read_apic_from_ire(apic, 0x10 + 2 * pin);
+        entry.high = iommu_read_apic_from_ire(apic, 0x11 + 2 * pin);
     }
 
-    return eu.entry;
+    return entry;
 }
 
 static struct IO_APIC_route_entry ioapic_read_entry(
@@ -297,12 +292,10 @@ void __ioapic_write_entry(
     unsigned int apic, unsigned int pin, bool raw,
     struct IO_APIC_route_entry e)
 {
-    union entry_union eu = { .entry = e };
-
     if ( raw || !iommu_intremap )
     {
-        __io_apic_write(apic, 0x11 + 2 * pin, eu.w2);
-        __io_apic_write(apic, 0x10 + 2 * pin, eu.w1);
+        __io_apic_write(apic, 0x11 + 2 * pin, e.high);
+        __io_apic_write(apic, 0x10 + 2 * pin, e.low);
         /*
          * Might be called before io_apic_pin_eoi is allocated.  Entry will be
          * initialized to the RTE value once the cache is allocated.
@@ -2235,7 +2228,7 @@ int ioapic_guest_read(unsigned long physbase, unsigned int reg, u32 *pval)
     dprintk(XENLOG_INFO, "IO-APIC: apic=%d, pin=%d, irq=%d\n" \
             XENLOG_INFO "IO-APIC: new_entry=%08x\n"           \
             XENLOG_INFO "IO-APIC: " f "\n",                   \
-            apic, pin, irq, *(u32 *)&rte, ##a )
+            apic, pin, irq, rte.low, ##a )
 
 int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val)
 {
@@ -2254,7 +2247,7 @@ int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val)
     pin = (reg - 0x10) >> 1;
 
     /* Write first half from guest; second half is target info. */
-    *(u32 *)&rte = val;
+    rte.low = val;
 
     /*
      * What about weird destination types?
@@ -2305,7 +2298,7 @@ int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val)
         ret = io_apic_read(apic, 0x10 + 2 * pin);
         spin_unlock_irqrestore(&ioapic_lock, flags);
         rte.vector = desc->arch.vector;
-        if ( *(u32*)&rte != ret )
+        if ( rte.low != ret )
             WARN_BOGUS_WRITE("old_entry=%08x pirq=%d\n" XENLOG_INFO
                              "IO-APIC: Attempt to modify IO-APIC pin for in-use IRQ!",
                              ret, pirq);
xen/drivers/passthrough/vtd/intremap.c +3 -6
index 612e08bcec..a276518c52 100644
@@ -400,7 +400,7 @@ unsigned int cf_check io_apic_read_remap_rte(
     unsigned int ioapic_pin = (reg - 0x10) / 2;
     int index;
     struct IO_APIC_route_entry old_rte = {};
-    int rte_upper = (reg & 1) ? 1 : 0;
+    bool rte_upper = reg & 1;
     struct vtd_iommu *iommu = ioapic_to_iommu(IO_APIC_ID(apic));
 
     if ( !iommu->intremap.num ||
@@ -411,11 +411,8 @@ unsigned int cf_check io_apic_read_remap_rte(
 
     if ( remap_entry_to_ioapic_rte(iommu, index, &old_rte) )
         return __io_apic_read(apic, reg);
-
-    if ( rte_upper )
-        return (*(((u32 *)&old_rte) + 1));
-    else
-        return (*(((u32 *)&old_rte) + 0));
+    
+    return rte_upper ? old_rte.high : old_rte.low;
 }
 
 void cf_check io_apic_write_remap_rte(
Signature · 10 lines
2.51.1



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#12 lore raw

Re: [PATCH v2 5/5] x86/ioapic: Don't open-code 32-bits rte reads

Quoted 6 lines · Teddy Astie
xen/drivers/passthrough/vtd/intremap.c +0 -0
index 612e08bcec..a276518c52 100644
@@ -411,11 +411,8 @@ unsigned int cf_check io_apic_read_remap_rte(
 

xen/drivers/passthrough/vtd/intremap.c unsigned int cf_check io_apic_read_remap_rte( · line 416

Quoted 10 lines
xen/drivers/passthrough/vtd/intremap.c +2 -5
     if ( remap_entry_to_ioapic_rte(iommu, index, &old_rte) )
         return __io_apic_read(apic, reg);
-
-    if ( rte_upper )
-        return (*(((u32 *)&old_rte) + 1));
-    else
-        return (*(((u32 *)&old_rte) + 0));
+    
+    return rte_upper ? old_rte.high : old_rte.low;
 }

This hunk introduces trailing whitespace where there was none previously.

~Andrew

#13 lore raw

PATCH v2 5/5 x86/ioapic: Don't open-code 32-bits rte reads

In reply to Teddy Astie

There are many places where we use interesting ways of reading 32-bits components of the RTE. Introduce and use low and high components directly to the rte structure instead.

Also take the opportunity to simplify "x & 1 ? 1 : 0".

---
v2.1:
- fix trailing spaces
v2:
- make rte_upper to use bool instead

 xen/arch/x86/include/asm/io_apic.h     |  1 +
 xen/arch/x86/io_apic.c                 | 29 ++++++++++----------------
 xen/drivers/passthrough/vtd/intremap.c |  7 ++-----
 3 files changed, 14 insertions(+), 23 deletions(-)
xen/arch/x86/include/asm/io_apic.h +1 -0
index 4680dce9e1..0e85f2a860 100644
@@ -122,6 +122,7 @@ struct IO_APIC_route_entry {
             } dest;
         };
         uint64_t raw;
+        struct { uint32_t low, high; };
     };
 };
 
xen/arch/x86/io_apic.c +11 -18
index d20ab2aa98..46c2a43dac 100644
@@ -254,28 +254,23 @@ nomem:
     return NULL;
 }
 
-union entry_union {
-    struct { u32 w1, w2; };
-    struct IO_APIC_route_entry entry;
-};
-
 struct IO_APIC_route_entry __ioapic_read_entry(
     unsigned int apic, unsigned int pin, bool raw)
 {
-    union entry_union eu;
+    struct IO_APIC_route_entry entry;
 
     if ( raw || !iommu_intremap )
     {
-        eu.w1 = __io_apic_read(apic, 0x10 + 2 * pin);
-        eu.w2 = __io_apic_read(apic, 0x11 + 2 * pin);
+        entry.low  = __io_apic_read(apic, 0x10 + 2 * pin);
+        entry.high = __io_apic_read(apic, 0x11 + 2 * pin);
     }
     else
     {
-        eu.w1 = iommu_read_apic_from_ire(apic, 0x10 + 2 * pin);
-        eu.w2 = iommu_read_apic_from_ire(apic, 0x11 + 2 * pin);
+        entry.low  = iommu_read_apic_from_ire(apic, 0x10 + 2 * pin);
+        entry.high = iommu_read_apic_from_ire(apic, 0x11 + 2 * pin);
     }
 
-    return eu.entry;
+    return entry;
 }
 
 static struct IO_APIC_route_entry ioapic_read_entry(
@@ -294,12 +289,10 @@ void __ioapic_write_entry(
     unsigned int apic, unsigned int pin, bool raw,
     struct IO_APIC_route_entry e)
 {
-    union entry_union eu = { .entry = e };
-
     if ( raw || !iommu_intremap )
     {
-        __io_apic_write(apic, 0x11 + 2 * pin, eu.w2);
-        __io_apic_write(apic, 0x10 + 2 * pin, eu.w1);
+        __io_apic_write(apic, 0x11 + 2 * pin, e.high);
+        __io_apic_write(apic, 0x10 + 2 * pin, e.low);
         /*
          * Might be called before io_apic_pin_eoi is allocated.  Entry will be
          * initialized to the RTE value once the cache is allocated.
@@ -2218,7 +2211,7 @@ int ioapic_guest_read(unsigned long physbase, unsigned int reg, u32 *pval)
     dprintk(XENLOG_INFO, "IO-APIC: apic=%d, pin=%d, irq=%d\n" \
             XENLOG_INFO "IO-APIC: new_entry=%08x\n"           \
             XENLOG_INFO "IO-APIC: " f "\n",                   \
-            apic, pin, irq, *(u32 *)&rte, ##a )
+            apic, pin, irq, rte.low, ##a )
 
 int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val)
 {
@@ -2237,7 +2230,7 @@ int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val)
     pin = (reg - 0x10) >> 1;
 
     /* Write first half from guest; second half is target info. */
-    *(u32 *)&rte = val;
+    rte.low = val;
 
     /*
      * What about weird destination types?
@@ -2288,7 +2281,7 @@ int ioapic_guest_write(unsigned long physbase, unsigned int reg, u32 val)
         ret = io_apic_read(apic, 0x10 + 2 * pin);
         spin_unlock_irqrestore(&ioapic_lock, flags);
         rte.vector = desc->arch.vector;
-        if ( *(u32*)&rte != ret )
+        if ( rte.low != ret )
             WARN_BOGUS_WRITE("old_entry=%08x pirq=%d\n" XENLOG_INFO
                              "IO-APIC: Attempt to modify IO-APIC pin for in-use IRQ!",
                              ret, pirq);
xen/drivers/passthrough/vtd/intremap.c +2 -5
index 116c2e75ae..ac39405c0d 100644
@@ -399,7 +399,7 @@ unsigned int cf_check io_apic_read_remap_rte(
     unsigned int ioapic_pin = (reg - 0x10) / 2;
     int index;
     struct IO_APIC_route_entry old_rte = {};
-    int rte_upper = (reg & 1) ? 1 : 0;
+    bool rte_upper = reg & 1;
     struct vtd_iommu *iommu = ioapic_to_iommu(IO_APIC_ID(apic));
 
     if ( !iommu->intremap.num ||
@@ -411,10 +411,7 @@ unsigned int cf_check io_apic_read_remap_rte(
     if ( remap_entry_to_ioapic_rte(iommu, index, &old_rte) )
         return __io_apic_read(apic, reg);
 
-    if ( rte_upper )
-        return (*(((u32 *)&old_rte) + 1));
-    else
-        return (*(((u32 *)&old_rte) + 0));
+    return rte_upper ? old_rte.high : old_rte.low;
 }
 
 void cf_check io_apic_write_remap_rte(
Signature · 10 lines
2.51.2



--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech
#14 lore raw

Re: [PATCH v2.1 5/5] x86/ioapic: Don't open-code 32-bits rte reads

Quoted 11 lines · Teddy Astie

There are many places where we use interesting ways of reading 32-bits components of the RTE. Introduce and use low and high components directly to the rte structure instead.

Also take the opportunity to simplify "x & 1 ? 1 : 0".

---
v2.1:
- fix trailing spaces

You did notice v2 was committed already, didn't you? I suppose that's what made Andrew notice the style issue.

Jan

#15 lore raw
In reply to Teddy Astie

Le 23/10/2025 à 11:12, Teddy Astie a écrit :

Quoted 33 lines

Various simplifications in the VT-d and IO-APIC code (mostly related to legacy ia64 code).

No functional change intended.

Changed in v2 :
- drop (un)map_vtd_domain_page wrapper instead of moving it
- drop deprecated and Intel-exclusive iommu_inclusive_mapping=<boolean>
- description and formatting changes

Teddy Astie (5):
vtd: Drop (un)map_vtd_domain_page wrapper
vtd: Drop "iommu_inclusive_mapping" command-line option
vtd: Collapse x86 subdirectory
vtd: Remove IO_xAPIC_route_entry macro x86/ioapic: Don't open-code 32-bits rte reads

  CHANGELOG.md                                |  2 +
  docs/misc/xen-command-line.pandoc           |  6 --
  xen/arch/x86/include/asm/io_apic.h          |  1 +
  xen/arch/x86/io_apic.c                      | 29 +++----
  xen/drivers/passthrough/vtd/Makefile        |  3 +-
  xen/drivers/passthrough/vtd/{x86 => }/ats.c | 21 ++---
  xen/drivers/passthrough/vtd/dmar.c          |  2 +-
  xen/drivers/passthrough/vtd/extern.h        |  3 -
  xen/drivers/passthrough/vtd/intremap.c      | 34 ++++----
  xen/drivers/passthrough/vtd/iommu.c         | 88 ++++++++++-----------
  xen/drivers/passthrough/vtd/iommu.h         |  7 +-
  xen/drivers/passthrough/vtd/qinval.c        | 13 +--
  xen/drivers/passthrough/vtd/utils.c         | 25 +++---
  xen/drivers/passthrough/vtd/vtd.h           |  3 -
  xen/drivers/passthrough/vtd/x86/Makefile    |  2 -
  xen/drivers/passthrough/vtd/x86/vtd.c       | 48 -----------
  16 files changed, 108 insertions(+), 179 deletions(-)
Quoted 4 lines

rename xen/drivers/passthrough/vtd/{x86 => }/ats.c (92%) delete mode 100644 xen/drivers/passthrough/vtd/x86/Makefile delete mode 100644 xen/drivers/passthrough/vtd/x86/vtd.c

I forgot to add the CC-ed people

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web: https://vates.tech

#16 lore raw
Quoted 2 lines · Teddy Astie

Le 23/10/2025 à 11:12, Teddy Astie a écrit :

Quoted 1 line

Various simplifications in the VT-d and IO-APIC code (mostly related to legacy ia64 code).

I think these changes isn't very critical for the current stage of release, so I suggest to have them in 4.22.

Thanks.

~ Oleksii

Quoted 47 lines
Quoted 32 lines

No functional change intended.

Changed in v2 :
- drop (un)map_vtd_domain_page wrapper instead of moving it
- drop deprecated and Intel-exclusive iommu_inclusive_mapping=<boolean>
- description and formatting changes

Teddy Astie (5):
vtd: Drop (un)map_vtd_domain_page wrapper
vtd: Drop "iommu_inclusive_mapping" command-line option
vtd: Collapse x86 subdirectory
vtd: Remove IO_xAPIC_route_entry macro x86/ioapic: Don't open-code 32-bits rte reads

   CHANGELOG.md                                |  2 +
   docs/misc/xen-command-line.pandoc           |  6 --
   xen/arch/x86/include/asm/io_apic.h          |  1 +
   xen/arch/x86/io_apic.c                      | 29 +++----
   xen/drivers/passthrough/vtd/Makefile        |  3 +-
   xen/drivers/passthrough/vtd/{x86 => }/ats.c | 21 ++---
   xen/drivers/passthrough/vtd/dmar.c          |  2 +-
   xen/drivers/passthrough/vtd/extern.h        |  3 -
   xen/drivers/passthrough/vtd/intremap.c      | 34 ++++----
   xen/drivers/passthrough/vtd/iommu.c         | 88 ++++++++++-----------
   xen/drivers/passthrough/vtd/iommu.h         |  7 +-
   xen/drivers/passthrough/vtd/qinval.c        | 13 +--
   xen/drivers/passthrough/vtd/utils.c         | 25 +++---
   xen/drivers/passthrough/vtd/vtd.h           |  3 -
   xen/drivers/passthrough/vtd/x86/Makefile    |  2 -
   xen/drivers/passthrough/vtd/x86/vtd.c       | 48 -----------
   16 files changed, 108 insertions(+), 179 deletions(-)
Quoted 4 lines

rename xen/drivers/passthrough/vtd/{x86 => }/ats.c (92%) delete mode 100644 xen/drivers/passthrough/vtd/x86/Makefile delete mode 100644 xen/drivers/passthrough/vtd/x86/vtd.c

I forgot to add the CC-ed people

--
Teddy Astie | Vates XCP-ng Developer

XCP-ng & Xen Orchestra - Vates solutions

web:https://vates.tech