Skip to contentSkip to conversation

xen/arm: fix arm_iommu_map_page after f9f6b22abf1d

PATCH In review Stewart Hildebrand 3 participants 9 messages Jul 25, 2025 – Aug 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/2 xen/arm: fix arm_iommu_map_page after f9f6b22abf1d

From: Stefano Stabellini <[email protected]>

Up until f9f6b22abf1d "xen/arm: Map ITS doorbell register to IOMMU page tables" the only caller of iommu_map on ARM was grant_table.c which has a specific usage model and restrictions as described by the in-code comment in arm_iommu_map_page.

f9f6b22abf1d introduced a second caller to iommu_map on ARM:
vgic_v3_its_init_virtual. This specific statement in the f9f6b22abf1d commit message is partially wrong:

"Note that the 1:1 check in arm_iommu_map_page remains for now, as virtual ITSes are currently only created for hwdom where the doorbell mapping is always 1:1."

Leading to crashes any time the hardware domain is not direct-mapped (e.g. cache coloring and non-Dom0 hardware domain):

(XEN) Xen BUG at drivers/passthrough/arm/iommu_helpers.c:47 [...]
(XEN) Xen call trace:

(XEN)    [<00000a000024c758>] arm_iommu_map_page+0x80/0x90 (PC)
(XEN)    [<00000a000024c750>] arm_iommu_map_page+0x78/0x90 (LR)
(XEN)    [<00000a0000250884>] iommu_map+0xcc/0x29c
(XEN)    [<00000a0000288024>] vgic_v3_its_init_domain+0x18c/0x1e8
(XEN)    [<00000a0000285228>] vgic-v3.c#vgic_v3_domain_init+0x168/0x21c
(XEN)    [<00000a0000281dcc>] domain_vgic_init+0x14c/0x210
(XEN)    [<00000a00002705a4>] arch_domain_create+0x150/0x1f0
(XEN)    [<00000a00002055e8>] domain_create+0x47c/0x6c0
(XEN)    [<00000a00002cf090>] create_domUs+0x7f8/0x8cc
(XEN)    [<00000a00002eb588>] start_xen+0x8f4/0x998
(XEN)    [<00000a000020018c>] head.o#primary_switched+0x4/0x10

Specifically, non-1:1 hardware domain exists with cache coloring enabled. For that, is_domain_direct_mapped(d) is false but domain_use_host_layout(d) is true.

Change the is_domain_direct_mapped(d) checks in arm_iommu_map_page and arm_iommu_unmap_page into domain_use_host_layout(d) checks.

Drop stale in-code comment specific to grant table mappings.

Fixes f9f6b22abf1d ("xen/arm: Map ITS doorbell register to IOMMU page tables")

---
v4->v5:
* drop comment

v3->v4:
* adjust comment to be architecture-neutral

v2->v3:
* split change into 2 patches
* 12-character commit IDs
* change both arm_iommu_map_page and arm_iommu_unmap_page
* s/IPA/GFN/ in comment

---
 xen/drivers/passthrough/arm/iommu_helpers.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)
xen/drivers/passthrough/arm/iommu_helpers.c +2 -14
index 5cb198748193..bdb271584b0d 100644
@@ -36,15 +36,7 @@ int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn,
 {
     p2m_type_t t;
 
-    /*
-     * Grant mappings can be used for DMA requests. The dev_bus_addr
-     * returned by the hypercall is the MFN (not the IPA). For device
-     * protected by an IOMMU, Xen needs to add a 1:1 mapping in the domain
-     * p2m to allow DMA request to work.
-     * This is only valid when the domain is directed mapped. Hence this
-     * function should only be used by gnttab code with gfn == mfn == dfn.
-     */
-    BUG_ON(!is_domain_direct_mapped(d));
+    BUG_ON(!domain_use_host_layout(d));
     BUG_ON(mfn_x(mfn) != dfn_x(dfn));
 
     /* We only support readable and writable flags */
@@ -66,11 +58,7 @@ int __must_check arm_iommu_unmap_page(struct domain *d, dfn_t dfn,
                                       unsigned int order,
                                       unsigned int *flush_flags)
 {
-    /*
-     * This function should only be used by gnttab code when the domain
-     * is direct mapped (i.e. gfn == mfn == dfn).
-     */
-    if ( !is_domain_direct_mapped(d) )
+    if ( !domain_use_host_layout(d) )
         return -EINVAL;
 
     return guest_physmap_remove_page(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn)),

base-commit: 6cd9b9226c65c962b0f0e040e7d3d5c4053f8e06

Signature · 1 line
2.50.1
#1 lore raw

PATCH v5 2/2 xen/arm: allow translated iommu mappings

From: Stefano Stabellini <[email protected]>

In preparation of exposing vITS to domUs, generalize arm_iommu_map_page and arm_iommu_unmap_page to allow ITS doorbell mappings with dfn != mfn.

The mfn does not need to be passed to guest_physmap_remove_page since there is no mfn checking on the p2m_iommu_map_{rw,ro} p2m types during unmap. Pass INVALID_MFN to guest_physmap_remove_page.

---
v4->v5:
* no change

v3->v4:
* no change

v2->v3:
* split change from ("xen/arm: fix arm_iommu_map_page after f9f6b22ab")
* both map and unmap

---
 xen/drivers/passthrough/arm/iommu_helpers.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)
xen/drivers/passthrough/arm/iommu_helpers.c +2 -9
index bdb271584b0d..a3e3cafb8705 100644
@@ -36,9 +36,6 @@ int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn,
 {
     p2m_type_t t;
 
-    BUG_ON(!domain_use_host_layout(d));
-    BUG_ON(mfn_x(mfn) != dfn_x(dfn));
-
     /* We only support readable and writable flags */
     if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) )
         return -EINVAL;
@@ -49,7 +46,7 @@ int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn,
      * The function guest_physmap_add_entry replaces the current mapping
      * if there is already one...
      */
-    return guest_physmap_add_entry(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn)),
+    return guest_physmap_add_entry(d, _gfn(dfn_x(dfn)), mfn,
                                    IOMMUF_order(flags), t);
 }
 
@@ -58,11 +55,7 @@ int __must_check arm_iommu_unmap_page(struct domain *d, dfn_t dfn,
                                       unsigned int order,
                                       unsigned int *flush_flags)
 {
-    if ( !domain_use_host_layout(d) )
-        return -EINVAL;
-
-    return guest_physmap_remove_page(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn)),
-                                     order);
+    return guest_physmap_remove_page(d, _gfn(dfn_x(dfn)), INVALID_MFN, order);
 }
 
 /*
Signature · 1 line
2.50.1
Reviewed-by on v5 2/2
#2 lore raw

Re: [PATCH v5 2/2] xen/arm: allow translated iommu mappings

Hi,

Quoted 11 lines · Stewart Hildebrand

From: Stefano Stabellini <[email protected]>

In preparation of exposing vITS to domUs, generalize arm_iommu_map_page and arm_iommu_unmap_page to allow ITS doorbell mappings with dfn != mfn.

The mfn does not need to be passed to guest_physmap_remove_page since there is no mfn checking on the p2m_iommu_map_{rw,ro} p2m types during unmap. Pass INVALID_MFN to guest_physmap_remove_page.

Quoted 50 lines

---
v4->v5:
* no change

v3->v4:
* no change

v2->v3:
* split change from ("xen/arm: fix arm_iommu_map_page after f9f6b22ab")
* both map and unmap

---
  xen/drivers/passthrough/arm/iommu_helpers.c | 11 ++---------
  1 file changed, 2 insertions(+), 9 deletions(-)
xen/drivers/passthrough/arm/iommu_helpers.c +2 -9
index bdb271584b0d..a3e3cafb8705 100644
@@ -36,9 +36,6 @@ int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn,
  {
      p2m_type_t t;
 
-    BUG_ON(!domain_use_host_layout(d));
-    BUG_ON(mfn_x(mfn) != dfn_x(dfn));
-
      /* We only support readable and writable flags */
      if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) )
          return -EINVAL;
@@ -49,7 +46,7 @@ int __must_check arm_iommu_map_page(struct domain *d, dfn_t dfn, mfn_t mfn,
       * The function guest_physmap_add_entry replaces the current mapping
       * if there is already one...
       */
-    return guest_physmap_add_entry(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn)),
+    return guest_physmap_add_entry(d, _gfn(dfn_x(dfn)), mfn,
                                     IOMMUF_order(flags), t);
  }
 
@@ -58,11 +55,7 @@ int __must_check arm_iommu_unmap_page(struct domain *d, dfn_t dfn,
                                        unsigned int order,
                                        unsigned int *flush_flags)
  {
-    if ( !domain_use_host_layout(d) )
-        return -EINVAL;
-
-    return guest_physmap_remove_page(d, _gfn(dfn_x(dfn)), _mfn(dfn_x(dfn)),
-                                     order);
+    return guest_physmap_remove_page(d, _gfn(dfn_x(dfn)), INVALID_MFN, order);
  }
 
  /*
Signature · 1 line
Julien Grall
Tested-by
#3 lore raw

Re: [PATCH v5 2/2] xen/arm: allow translated iommu mappings

Quoted 8 lines · Julien Grall

Hi,

Quoted 5 lines · Stewart Hildebrand

From: Stefano Stabellini <[email protected]>

In preparation of exposing vITS to domUs, generalize arm_iommu_map_page and arm_iommu_unmap_page to allow ITS doorbell mappings with dfn != mfn.

Quoted 8 lines
Quoted 6 lines

The mfn does not need to be passed to guest_physmap_remove_page since there is no mfn checking on the p2m_iommu_map_{rw,ro} p2m types during unmap. Pass INVALID_MFN to guest_physmap_remove_page.

Thanks,
Jason

Reviewed-by on v5 1/2
#4 lore raw
In reply to Stewart Hildebrand

Hi,

Quoted 37 lines · Stewart Hildebrand

From: Stefano Stabellini <[email protected]>

Up until f9f6b22abf1d "xen/arm: Map ITS doorbell register to IOMMU page tables" the only caller of iommu_map on ARM was grant_table.c which has a specific usage model and restrictions as described by the in-code comment in arm_iommu_map_page.

f9f6b22abf1d introduced a second caller to iommu_map on ARM:
vgic_v3_its_init_virtual. This specific statement in the f9f6b22abf1d commit message is partially wrong:

"Note that the 1:1 check in arm_iommu_map_page remains for now, as virtual ITSes are currently only created for hwdom where the doorbell mapping is always 1:1."

Leading to crashes any time the hardware domain is not direct-mapped (e.g. cache coloring and non-Dom0 hardware domain):

(XEN) Xen BUG at drivers/passthrough/arm/iommu_helpers.c:47 [...]
(XEN) Xen call trace:

(XEN)    [<00000a000024c758>] arm_iommu_map_page+0x80/0x90 (PC)
(XEN)    [<00000a000024c750>] arm_iommu_map_page+0x78/0x90 (LR)
(XEN)    [<00000a0000250884>] iommu_map+0xcc/0x29c
(XEN)    [<00000a0000288024>] vgic_v3_its_init_domain+0x18c/0x1e8
(XEN)    [<00000a0000285228>] vgic-v3.c#vgic_v3_domain_init+0x168/0x21c
(XEN)    [<00000a0000281dcc>] domain_vgic_init+0x14c/0x210
(XEN)    [<00000a00002705a4>] arch_domain_create+0x150/0x1f0
(XEN)    [<00000a00002055e8>] domain_create+0x47c/0x6c0
(XEN)    [<00000a00002cf090>] create_domUs+0x7f8/0x8cc
(XEN)    [<00000a00002eb588>] start_xen+0x8f4/0x998
(XEN)    [<00000a000020018c>] head.o#primary_switched+0x4/0x10

Specifically, non-1:1 hardware domain exists with cache coloring enabled. For that, is_domain_direct_mapped(d) is false but domain_use_host_layout(d) is true.

Quoted 8 lines

Change the is_domain_direct_mapped(d) checks in arm_iommu_map_page and arm_iommu_unmap_page into domain_use_host_layout(d) checks.

Drop stale in-code comment specific to grant table mappings.

Fixes f9f6b22abf1d ("xen/arm: Map ITS doorbell register to IOMMU page tables")

Cheers,

Signature · 1 line
Julien Grall
#5 lore raw
Quoted 43 lines · Julien Grall

Hi,

Quoted 40 lines · Stewart Hildebrand

From: Stefano Stabellini <[email protected]>

Up until f9f6b22abf1d "xen/arm: Map ITS doorbell register to IOMMU page tables" the only caller of iommu_map on ARM was grant_table.c which has a specific usage model and restrictions as described by the in-code comment in arm_iommu_map_page.

f9f6b22abf1d introduced a second caller to iommu_map on ARM:
vgic_v3_its_init_virtual. This specific statement in the f9f6b22abf1d commit message is partially wrong:

"Note that the 1:1 check in arm_iommu_map_page remains for now, as virtual ITSes are currently only created for hwdom where the doorbell mapping is always 1:1."

Leading to crashes any time the hardware domain is not direct-mapped (e.g. cache coloring and non-Dom0 hardware domain):

(XEN) Xen BUG at drivers/passthrough/arm/iommu_helpers.c:47 [...]
(XEN) Xen call trace:
(XEN)    [<00000a000024c758>] arm_iommu_map_page+0x80/0x90 (PC) (XEN)    [<00000a000024c750>] arm_iommu_map_page+0x78/0x90 (LR) (XEN)    [<00000a0000250884>] iommu_map+0xcc/0x29c
(XEN)    [<00000a0000288024>] vgic_v3_its_init_domain+0x18c/0x1e8 (XEN)    [<00000a0000285228>] vgic-v3.c#vgic_v3_domain_init+0x168/0x21c (XEN)    [<00000a0000281dcc>] domain_vgic_init+0x14c/0x210 (XEN)    [<00000a00002705a4>] arch_domain_create+0x150/0x1f0 (XEN)    [<00000a00002055e8>] domain_create+0x47c/0x6c0 (XEN)    [<00000a00002cf090>] create_domUs+0x7f8/0x8cc
(XEN)    [<00000a00002eb588>] start_xen+0x8f4/0x998
(XEN)    [<00000a000020018c>] head.o#primary_switched+0x4/0x10

Specifically, non-1:1 hardware domain exists with cache coloring enabled. For that, is_domain_direct_mapped(d) is false but domain_use_host_layout(d) is true.

Change the is_domain_direct_mapped(d) checks in arm_iommu_map_page and arm_iommu_unmap_page into domain_use_host_layout(d) checks.

Quoted 7 lines
Quoted 5 lines

Drop stale in-code comment specific to grant table mappings.

Fixes f9f6b22abf1d ("xen/arm: Map ITS doorbell register to IOMMU page tables")

Thanks for the review! Is this ready to be committed?

Tested-by
#6 lore raw
Quoted 46 lines · Stewart Hildebrand
Quoted 45 lines · Julien Grall

Hi,

Quoted 42 lines · Stewart Hildebrand

From: Stefano Stabellini <[email protected]>

Up until f9f6b22abf1d "xen/arm: Map ITS doorbell register to IOMMU page tables" the only caller of iommu_map on ARM was grant_table.c which has a specific usage model and restrictions as described by the in-code comment in arm_iommu_map_page.

f9f6b22abf1d introduced a second caller to iommu_map on ARM:
vgic_v3_its_init_virtual. This specific statement in the f9f6b22abf1d commit message is partially wrong:

"Note that the 1:1 check in arm_iommu_map_page remains for now, as virtual ITSes are currently only created for hwdom where the doorbell mapping is always 1:1."

Leading to crashes any time the hardware domain is not direct-mapped (e.g. cache coloring and non-Dom0 hardware domain):

(XEN) Xen BUG at drivers/passthrough/arm/iommu_helpers.c:47 [...]
(XEN) Xen call trace:
(XEN)    [<00000a000024c758>] arm_iommu_map_page+0x80/0x90 (PC) (XEN)    [<00000a000024c750>] arm_iommu_map_page+0x78/0x90 (LR) (XEN)    [<00000a0000250884>] iommu_map+0xcc/0x29c
(XEN)    [<00000a0000288024>] vgic_v3_its_init_domain+0x18c/0x1e8 (XEN)    [<00000a0000285228>] vgic-v3.c#vgic_v3_domain_init+0x168/0x21c (XEN)    [<00000a0000281dcc>] domain_vgic_init+0x14c/0x210 (XEN)    [<00000a00002705a4>] arch_domain_create+0x150/0x1f0 (XEN)    [<00000a00002055e8>] domain_create+0x47c/0x6c0 (XEN)    [<00000a00002cf090>] create_domUs+0x7f8/0x8cc
(XEN)    [<00000a00002eb588>] start_xen+0x8f4/0x998
(XEN)    [<00000a000020018c>] head.o#primary_switched+0x4/0x10

Specifically, non-1:1 hardware domain exists with cache coloring enabled. For that, is_domain_direct_mapped(d) is false but domain_use_host_layout(d) is true.

Change the is_domain_direct_mapped(d) checks in arm_iommu_map_page and arm_iommu_unmap_page into domain_use_host_layout(d) checks.

Drop stale in-code comment specific to grant table mappings.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Fixes f9f6b22abf1d ("xen/arm: Map ITS doorbell register to IOMMU page tables")

Thanks for the review! Is this ready to be committed?

Thanks,
Jason

#7 lore raw
In reply to Stewart Hildebrand

Hi Stewart,

Quoted 46 lines · Stewart Hildebrand
Quoted 45 lines · Julien Grall

Hi,

Quoted 42 lines · Stewart Hildebrand

From: Stefano Stabellini <[email protected]>

Up until f9f6b22abf1d "xen/arm: Map ITS doorbell register to IOMMU page tables" the only caller of iommu_map on ARM was grant_table.c which has a specific usage model and restrictions as described by the in-code comment in arm_iommu_map_page.

f9f6b22abf1d introduced a second caller to iommu_map on ARM:
vgic_v3_its_init_virtual. This specific statement in the f9f6b22abf1d commit message is partially wrong:

"Note that the 1:1 check in arm_iommu_map_page remains for now, as virtual ITSes are currently only created for hwdom where the doorbell mapping is always 1:1."

Leading to crashes any time the hardware domain is not direct-mapped (e.g. cache coloring and non-Dom0 hardware domain):

(XEN) Xen BUG at drivers/passthrough/arm/iommu_helpers.c:47 [...]
(XEN) Xen call trace:
(XEN)    [<00000a000024c758>] arm_iommu_map_page+0x80/0x90 (PC) (XEN)    [<00000a000024c750>] arm_iommu_map_page+0x78/0x90 (LR) (XEN)    [<00000a0000250884>] iommu_map+0xcc/0x29c
(XEN)    [<00000a0000288024>] vgic_v3_its_init_domain+0x18c/0x1e8 (XEN)    [<00000a0000285228>] vgic-v3.c#vgic_v3_domain_init+0x168/0x21c (XEN)    [<00000a0000281dcc>] domain_vgic_init+0x14c/0x210 (XEN)    [<00000a00002705a4>] arch_domain_create+0x150/0x1f0 (XEN)    [<00000a00002055e8>] domain_create+0x47c/0x6c0 (XEN)    [<00000a00002cf090>] create_domUs+0x7f8/0x8cc
(XEN)    [<00000a00002eb588>] start_xen+0x8f4/0x998
(XEN)    [<00000a000020018c>] head.o#primary_switched+0x4/0x10

Specifically, non-1:1 hardware domain exists with cache coloring enabled. For that, is_domain_direct_mapped(d) is false but domain_use_host_layout(d) is true.

Change the is_domain_direct_mapped(d) checks in arm_iommu_map_page and arm_iommu_unmap_page into domain_use_host_layout(d) checks.

Drop stale in-code comment specific to grant table mappings.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Fixes f9f6b22abf1d ("xen/arm: Map ITS doorbell register to IOMMU page tables")

Thanks for the review! Is this ready to be committed?

Yes. Sorry, this fell through the cracks. I have queue the patch for testing and committing.

Cheers,

Signature · 1 line
Julien Grall
#8 lore raw
Quoted 51 lines · Julien Grall
Quoted 50 lines · Stewart Hildebrand
Quoted 49 lines · Julien Grall

Hi,

Quoted 45 lines · Stewart Hildebrand

From: Stefano Stabellini <[email protected]>

Up until f9f6b22abf1d "xen/arm: Map ITS doorbell register to IOMMU page tables" the only caller of iommu_map on ARM was grant_table.c which has a specific usage model and restrictions as described by the in-code comment in arm_iommu_map_page.

f9f6b22abf1d introduced a second caller to iommu_map on ARM:
vgic_v3_its_init_virtual. This specific statement in the f9f6b22abf1d commit message is partially wrong:

"Note that the 1:1 check in arm_iommu_map_page remains for now, as virtual ITSes are currently only created for hwdom where the doorbell mapping is always 1:1."

Leading to crashes any time the hardware domain is not direct-mapped (e.g. cache coloring and non-Dom0 hardware domain):

(XEN) Xen BUG at drivers/passthrough/arm/iommu_helpers.c:47 [...]
(XEN) Xen call trace:
(XEN)    [<00000a000024c758>] arm_iommu_map_page+0x80/0x90 (PC) (XEN)    [<00000a000024c750>] arm_iommu_map_page+0x78/0x90 (LR) (XEN)    [<00000a0000250884>] iommu_map+0xcc/0x29c
(XEN)    [<00000a0000288024>] vgic_v3_its_init_domain+0x18c/0x1e8 (XEN)    [<00000a0000285228>] vgic-v3.c#vgic_v3_domain_init+0x168/0x21c (XEN)    [<00000a0000281dcc>] domain_vgic_init+0x14c/0x210 (XEN)    [<00000a00002705a4>] arch_domain_create+0x150/0x1f0 (XEN)    [<00000a00002055e8>] domain_create+0x47c/0x6c0 (XEN)    [<00000a00002cf090>] create_domUs+0x7f8/0x8cc
(XEN)    [<00000a00002eb588>] start_xen+0x8f4/0x998
(XEN)    [<00000a000020018c>] head.o#primary_switched+0x4/0x10

Specifically, non-1:1 hardware domain exists with cache coloring enabled. For that, is_domain_direct_mapped(d) is false but domain_use_host_layout(d) is true.

Change the is_domain_direct_mapped(d) checks in arm_iommu_map_page and arm_iommu_unmap_page into domain_use_host_layout(d) checks.

Drop stale in-code comment specific to grant table mappings.

Fixes f9f6b22abf1d ("xen/arm: Map ITS doorbell register to IOMMU page tables")
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Thanks for the review! Is this ready to be committed?

Yes. Sorry, this fell through the cracks. I have queue the patch for testing and committing.

This is now merged.

Cheers,

Signature · 1 line
Julien Grall