diff mbox

[Xen-devel,RFC,0/2] xen/arm: fix "xen_add_mach_to_phys_entry: cannot add" problem

Message ID alpine.DEB.2.02.1407072007470.27641@kaball.uk.xensource.com
State New
Headers show

Commit Message

Stefano Stabellini July 7, 2014, 8:24 p.m. UTC
Hi all,
Xen support in Linux for ARM and ARM64 suffers from lack of support for
multiple mfn to pfn mappings: whenever a frontend grants the same page
multiple times to the backend, the mfn to pfn accounting in
arch/arm/xen/p2m.c fails. The issue has become critical since v3.15,
when xen-netfront/xen-netback switched from grant copies to grant
mappings, therefore causing the issue to happen much more often.

Fixing the mfn to pfn accounting in p2m.c is difficult and expensive,
therefore we are looking for alternative solutions. One idea is avoiding
mfn to pfn conversions altogether. The only code path that needs them is
swiotlb-xen:unmap_page (and single_for_cpu and single_for_device).

To avoid mfn to pfn conversions we rely on a second p2m mapping done by
Xen, see the attached patch. In Linux we use it to perform the cache
maintenance operations without mfns conversions.



Stefano Stabellini (2):
      xen/arm: reimplement xen_dma_unmap_page & friends
      xen/arm: remove mach_to_phys rbtree

 arch/arm/include/asm/xen/page-coherent.h |   25 ++--
 arch/arm/include/asm/xen/page.h          |    9 --
 arch/arm/xen/Makefile                    |    2 +-
 arch/arm/xen/mm32.c                      |  202 ++++++++++++++++++++++++++++++
 arch/arm/xen/p2m.c                       |   64 +---------
 5 files changed, 211 insertions(+), 91 deletions(-)
 create mode 100644 arch/arm/xen/mm32.c

Comments

Julien Grall July 8, 2014, 9:37 a.m. UTC | #1
On 07/07/14 21:24, Stefano Stabellini wrote:
> Hi all,

Hi Stefano,

> Xen support in Linux for ARM and ARM64 suffers from lack of support for
> multiple mfn to pfn mappings: whenever a frontend grants the same page
> multiple times to the backend, the mfn to pfn accounting in
> arch/arm/xen/p2m.c fails. The issue has become critical since v3.15,
> when xen-netfront/xen-netback switched from grant copies to grant
> mappings, therefore causing the issue to happen much more often.
>
> Fixing the mfn to pfn accounting in p2m.c is difficult and expensive,
> therefore we are looking for alternative solutions. One idea is avoiding
> mfn to pfn conversions altogether. The only code path that needs them is
> swiotlb-xen:unmap_page (and single_for_cpu and single_for_device).
>
> To avoid mfn to pfn conversions we rely on a second p2m mapping done by
> Xen, see the attached patch. In Linux we use it to perform the cache
> maintenance operations without mfns conversions.

I tried this series on midway with a FreeBSD guest. I got those errors 
in DOM0 log:

xen_add_phys_to_mach_entry: cannot add pfn=0x002d99330003cdc7 -> 
mfn=0x00000001002d9933: pfn=0x002d99330003e3ea -> mfn=0x00000001002d9933 
already exists
xen_add_phys_to_mach_entry: cannot add pfn=0x002d99330003d47a -> 
mfn=0x00000001002d9933: pfn=0x002d99330003e3ea -> mfn=0x00000001002d9933 
already exists

It looks like you forgot to modify xen_add_phys_to_mach_entry.

Regards,
David Vrabel July 8, 2014, 10:50 a.m. UTC | #2
On 07/07/14 21:24, Stefano Stabellini wrote:
> Hi all,
> Xen support in Linux for ARM and ARM64 suffers from lack of support for
> multiple mfn to pfn mappings: whenever a frontend grants the same page
> multiple times to the backend, the mfn to pfn accounting in
> arch/arm/xen/p2m.c fails. The issue has become critical since v3.15,
> when xen-netfront/xen-netback switched from grant copies to grant
> mappings, therefore causing the issue to happen much more often.
> 
> Fixing the mfn to pfn accounting in p2m.c is difficult and expensive,
> therefore we are looking for alternative solutions. One idea is avoiding
> mfn to pfn conversions altogether. The only code path that needs them is
> swiotlb-xen:unmap_page (and single_for_cpu and single_for_device).
> 
> To avoid mfn to pfn conversions we rely on a second p2m mapping done by
> Xen, see the attached patch. In Linux we use it to perform the cache
> maintenance operations without mfns conversions.

This will only work with PIPT caches (or certain types of VIPT that also
have alias detection).  Do all the CPUs that Xen runs on have these type
of cache?

David
Stefano Stabellini July 8, 2014, 11 a.m. UTC | #3
On Tue, 8 Jul 2014, David Vrabel wrote:
> On 07/07/14 21:24, Stefano Stabellini wrote:
> > Hi all,
> > Xen support in Linux for ARM and ARM64 suffers from lack of support for
> > multiple mfn to pfn mappings: whenever a frontend grants the same page
> > multiple times to the backend, the mfn to pfn accounting in
> > arch/arm/xen/p2m.c fails. The issue has become critical since v3.15,
> > when xen-netfront/xen-netback switched from grant copies to grant
> > mappings, therefore causing the issue to happen much more often.
> > 
> > Fixing the mfn to pfn accounting in p2m.c is difficult and expensive,
> > therefore we are looking for alternative solutions. One idea is avoiding
> > mfn to pfn conversions altogether. The only code path that needs them is
> > swiotlb-xen:unmap_page (and single_for_cpu and single_for_device).
> > 
> > To avoid mfn to pfn conversions we rely on a second p2m mapping done by
> > Xen, see the attached patch. In Linux we use it to perform the cache
> > maintenance operations without mfns conversions.
> 
> This will only work with PIPT caches (or certain types of VIPT that also
> have alias detection).  Do all the CPUs that Xen runs on have these type
> of cache?

Given that Xen only runs on v7 or newer I think we should be safe.
Ian Campbell July 8, 2014, 11:06 a.m. UTC | #4
On Tue, 2014-07-08 at 11:50 +0100, David Vrabel wrote:
> On 07/07/14 21:24, Stefano Stabellini wrote:
> > Hi all,
> > Xen support in Linux for ARM and ARM64 suffers from lack of support for
> > multiple mfn to pfn mappings: whenever a frontend grants the same page
> > multiple times to the backend, the mfn to pfn accounting in
> > arch/arm/xen/p2m.c fails. The issue has become critical since v3.15,
> > when xen-netfront/xen-netback switched from grant copies to grant
> > mappings, therefore causing the issue to happen much more often.
> > 
> > Fixing the mfn to pfn accounting in p2m.c is difficult and expensive,
> > therefore we are looking for alternative solutions. One idea is avoiding
> > mfn to pfn conversions altogether. The only code path that needs them is
> > swiotlb-xen:unmap_page (and single_for_cpu and single_for_device).
> > 
> > To avoid mfn to pfn conversions we rely on a second p2m mapping done by
> > Xen, see the attached patch. In Linux we use it to perform the cache
> > maintenance operations without mfns conversions.
> 
> This will only work with PIPT caches (or certain types of VIPT that also
> have alias detection).  Do all the CPUs that Xen runs on have these type
> of cache?

v7 (at least, didn't check/don't care about v6) mandates PIPT for data
caches, yes.

Ian.
diff mbox

Patch

diff --git a/xen/include/asm-arm/grant_table.h b/xen/include/asm-arm/grant_table.h
index eac8a70..95519c5 100644
--- a/xen/include/asm-arm/grant_table.h
+++ b/xen/include/asm-arm/grant_table.h
@@ -34,7 +34,7 @@  static inline int replace_grant_supported(void)
      (i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i]))
 
 #define gnttab_need_iommu_mapping(d)                    \
-    (is_domain_direct_mapped(d) && need_iommu(d))
+    (is_domain_direct_mapped(d))
 
 #endif /* __ASM_GRANT_TABLE_H__ */
 /*