Skip to contentSkip to conversation

xen/arm: Fix P2M root page tables invalidation

PATCH In review Michal Orzel 4 participants 6 messages Jun 16, 2025 – Jun 17, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/arm: Fix P2M root page tables invalidation

Fix the condition part of the for loop in p2m_invalidate_root() that uses P2M_ROOT_LEVEL instead of P2M_ROOT_PAGES. The goal here is to invalidate all root page tables (that can be concatenated), so the loop must iterate through all these pages. Root level can be 0 or 1, whereas there can be 1,2,8,16 root pages. The issue may lead to some pages not being invalidated and therefore the guest access won't be trapped. We use it to track pages accessed by guest for set/way emulation provided no IOMMU, IOMMU not enabled for the domain or P2M not shared with IOMMU.

Fixes 2148a125b73b ("xen/arm: Track page accessed between batch of Set/Way operations")
---
 xen/arch/arm/mmu/p2m.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/mmu/p2m.c +1 -1
index d96078f547d5..67296dabb587 100644
@@ -1291,7 +1291,7 @@ static void p2m_invalidate_root(struct p2m_domain *p2m)
 
     p2m_write_lock(p2m);
 
-    for ( i = 0; i < P2M_ROOT_LEVEL; i++ )
+    for ( i = 0; i < P2M_ROOT_PAGES; i++ )
         p2m_invalidate_table(p2m, page_to_mfn(p2m->root + i));
 
     p2m_write_unlock(p2m);
Signature · 1 line
2.25.1
#1 lore raw
Quoted 8 lines · Michal Orzel

Fix the condition part of the for loop in p2m_invalidate_root() that uses P2M_ROOT_LEVEL instead of P2M_ROOT_PAGES. The goal here is to invalidate all root page tables (that can be concatenated), so the loop must iterate through all these pages. Root level can be 0 or 1, whereas there can be 1,2,8,16 root pages. The issue may lead to some pages not being invalidated and therefore the guest access won't be trapped. We use it to track pages accessed by guest for set/way emulation provided no IOMMU, IOMMU not enabled for the domain or P2M not shared with IOMMU.

IOW no security concerns?

Quoted 2 lines
Fixes 2148a125b73b ("xen/arm: Track page accessed between batch of Set/Way operations")

Credit Oleksii with a Reported-by?

Jan

#2 lore raw
Quoted 11 lines · Jan Beulich
Quoted 8 lines · Michal Orzel

Fix the condition part of the for loop in p2m_invalidate_root() that uses P2M_ROOT_LEVEL instead of P2M_ROOT_PAGES. The goal here is to invalidate all root page tables (that can be concatenated), so the loop must iterate through all these pages. Root level can be 0 or 1, whereas there can be 1,2,8,16 root pages. The issue may lead to some pages not being invalidated and therefore the guest access won't be trapped. We use it to track pages accessed by guest for set/way emulation provided no IOMMU, IOMMU not enabled for the domain or P2M not shared with IOMMU.

IOW no security concerns?

I discussed this with Julien and we don't think there are any.

Quoted 5 lines
Quoted 3 lines
Fixes 2148a125b73b ("xen/arm: Track page accessed between batch of Set/Way operations")

Credit Oleksii with a Reported-by?

Sure thing:

~Michal

#3 lore raw
In reply to Jan Beulich

Hi Jan,

Quoted 11 lines · Jan Beulich
Quoted 8 lines · Michal Orzel

Fix the condition part of the for loop in p2m_invalidate_root() that uses P2M_ROOT_LEVEL instead of P2M_ROOT_PAGES. The goal here is to invalidate all root page tables (that can be concatenated), so the loop must iterate through all these pages. Root level can be 0 or 1, whereas there can be 1,2,8,16 root pages. The issue may lead to some pages not being invalidated and therefore the guest access won't be trapped. We use it to track pages accessed by guest for set/way emulation provided no IOMMU, IOMMU not enabled for the domain or P2M not shared with IOMMU.

IOW no security concerns?

Copying/pasting what I wrote on the security channel for the record. (This was sent after you asked on xen-devel, sorry I should have done it before hand):

We both looked at the code and concluded that it is guarantreed that P2M_ROOT_PAGES >= P2M_ROOT_LEVEL. This means the only issue is an under invalidation. The logic is only used for the benefit of invalidating the guest memory when using cache flush by set/way. Because of the issue, the guest we may not clean & invalidate some RAM belonging to itself. We also don't rely on the p2m_invalidate_root() to ensure any scrubbed pages content have reached memory. So any under invalidation will only impact the guest.

Hence why we concluded it wasn't a security issue.

Cheers,

Signature · 1 line
Julien Grall
Reviewed-by on v1 1/1
#4 lore raw
In reply to Michal Orzel

(+Oleksii)

Hi,

Adding Oleksii for visibility.

Quoted 11 lines · Michal Orzel

Fix the condition part of the for loop in p2m_invalidate_root() that uses P2M_ROOT_LEVEL instead of P2M_ROOT_PAGES. The goal here is to invalidate all root page tables (that can be concatenated), so the loop must iterate through all these pages. Root level can be 0 or 1, whereas there can be 1,2,8,16 root pages. The issue may lead to some pages not being invalidated and therefore the guest access won't be trapped. We use it to track pages accessed by guest for set/way emulation provided no IOMMU, IOMMU not enabled for the domain or P2M not shared with IOMMU.

Fixes 2148a125b73b ("xen/arm: Track page accessed between batch of Set/Way operations")

Cheers,

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

(+Oleksii)

Hi,

Adding Oleksii for visibility.

Thanks for adding me.

Quoted 4 lines · Michal Orzel
Quoted 2 lines

Fix the condition part of the for loop in p2m_invalidate_root() that uses P2M_ROOT_LEVEL instead of P2M_ROOT_PAGES. The goal here is to

I used P2M_ROOT_PAGES for RISC-V for the similar case. This patch just confirms that it was a correct decision.

Thanks.

~ Oleksii

Quoted 14 lines
Quoted 9 lines

invalidate all root page tables (that can be concatenated), so the loop must iterate through all these pages. Root level can be 0 or 1, whereas there can be 1,2,8,16 root pages. The issue may lead to some pages not being invalidated and therefore the guest access won't be trapped. We use it to track pages accessed by guest for set/way emulation provided no IOMMU, IOMMU not enabled for the domain or P2M not shared with IOMMU.

Fixes 2148a125b73b ("xen/arm: Track page accessed between batch of Set/Way operations")

Cheers,