IOMMU support for ARM
v8 cover IOMMU support for ARM
Hello,
This is the eight version of this patch series to add support for IOMMU on ARM. It also adds driver to support ARM SMMU which is used for instance on Midway.
Major changes see v7:
- Rework patch #4 to handle correctly multiple grant mapping with the same MFN
For all changes see in each patch.
This series also depends on the interrupt reworking series [1]
A working tree can be found here:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch smmu-v8
Sincerely yours,
[1] http://lists.xen.org/archives/html/xen-devel/2014-05/msg02172.html
Julien Grall (4):
xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent
walk
xen: iommu: Define PAGE_{SHIFT,SIZE,ALIGN,MASK)_64K drivers/passthrough: arm: Add support for SMMU drivers xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
xen/arch/arm/mm.c | 10 + xen/arch/arm/p2m.c | 48 +- xen/common/grant_table.c | 4 +- xen/drivers/passthrough/arm/Makefile | 1 + xen/drivers/passthrough/arm/smmu.c | 1786 ++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/iommu.c | 10 + xen/include/asm-arm/grant_table.h | 2 + xen/include/asm-arm/mm.h | 3 + xen/include/asm-arm/p2m.h | 2 + xen/include/asm-x86/grant_table.h | 2 + xen/include/xen/hvm/iommu.h | 6 + xen/include/xen/iommu.h | 24 +- 12 files changed, 1877 insertions(+), 21 deletions(-) create mode 100644 xen/drivers/passthrough/arm/smmu.c
Signature · 1 line
1.7.10.4
PATCH v8 1/4 xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Some IOMMU don't suppport coherent PT walk. When the p2m is shared with the CPU, Xen has to make sure the PT changes have reached the memory.
Introduce new IOMMU function that will check if the IOMMU feature is enabled for a specified domain.
On ARM, the platform can contain multiple IOMMUs. Each of them may not have the same set of feature. The domain parameter will be used to get the set of features for IOMMUs used by this domain.
---
Changes in v8:
- Drop final comma in the enum
- Add function clear_and_clean_page
Changes in v7:
- Add IOMMU_FEAT_count
- Use DECLARE_BITMAP
Changes in v6:
- Rework the condition to flush cache for PT
- Use {set,clear,test}_bit
- Store features in hvm_iommu structure and add accessor
- Don't specificed value in the enum
Changes in v5:
- Flush on every write_pte instead of unmap page. This will avoid to flush a whole page when only few bytes are modified
- Only get iommu feature once.
- Add bits to flush cache when a new table is created
- Fix typoes in commit message and comment
- Use an enum to describe the feature. Each items are a bit position
Changes in v4:
- Patch added
--- xen/arch/arm/mm.c | 10 +++++++++ xen/arch/arm/p2m.c | 46 +++++++++++++++++++++++++-------------- xen/drivers/passthrough/iommu.c | 10 +++++++++ xen/include/asm-arm/mm.h | 3 +++ xen/include/xen/hvm/iommu.h | 6 +++++ xen/include/xen/iommu.h | 9 ++++++++ 6 files changed, 68 insertions(+), 16 deletions(-)
xen/arch/arm/mm.c +10 -0
@@ -1235,6 +1235,16 @@ int is_iomem_page(unsigned long mfn)return 1 ;return 0 ; } + +void clear_and_clean_page (struct page_info *page) +{ +void *p =__map_domain_page (page); + +clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE ); +unmap_domain_page (p); +} +/* * Local variables: * mode: C
xen/arch/arm/p2m.c +30 -16
110 lines not on this page · raw message
xen/drivers/passthrough/iommu.c +10 -0
@@ -344,6 +344,16 @@ void iommu_crash_shutdown(void) iommu_enabled = iommu_intremap =0 ; } +bool_t iommu_has_feature (struct domain *d,enum iommu_feature feature) +{ +const struct hvm_iommu *hd =domain_hvm_iommu (d); + +if ( !iommu_enabled ) +return 0 ; + +return test_bit (feature, hd->features); +} +static void iommu_dump_p2m_table (unsigned char key) {struct domain *d;
xen/include/asm-arm/mm.h +3 -0
@@ -5,6 +5,7 @@#include <xen/kernel.h> #include <asm/page.h> #include <public/xen.h> +#include <xen/domain_page.h> /* Align Xen to a 2 MiB boundary. */ #define XEN_PADDR_ALIGN (1 << 21)
@@ -341,6 +342,8 @@ static inline void put_page_and_type(struct page_info *page) put_page(page); } +void clear_and_clean_page (struct page_info *page); +#endif /* __ARCH_ARM_MM__ */ /* * Local variables:
xen/include/xen/hvm/iommu.h +6 -0
@@ -34,6 +34,12 @@ struct hvm_iommu {/* List of DT devices assigned to this domain */ struct list_head dt_devices;#endif + +/* Features supported by the IOMMU */ + DECLARE_BITMAP(features, IOMMU_FEAT_count); }; +#define iommu_set_feature (d, f) set_bit((f), domain_hvm_iommu(d)->features) +#define iommu_clear_feature (d, f) clear_bit((f), domain_hvm_iommu(d)->features) +#endif /* __XEN_HVM_IOMMU_H__ */
xen/include/xen/iommu.h +9 -0
@@ -67,6 +67,15 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, unsigned int flags);int iommu_unmap_page (struct domain *d,unsigned long gfn); +enum iommu_feature +{ +IOMMU_FEAT_COHERENT_WALK , + IOMMU_FEAT_count +}; + +bool_t iommu_has_feature (struct domain *d,enum iommu_feature feature); + +#ifdef HAS_PCI void pt_pci_init (void );
Signature · 1 line
1.7.10.4
PATCH v8 2/4 xen: iommu: Define PAGE_{SHIFT, SIZE, ALIGN, MASK)_64K
In reply to Julien GrallAlso add IOMMU_PAGE_* helper macros to help creating PAGE_* defines.
---
Changes in v7:
- Drop pointless parentheses
Changes in v6:
- Patch added
--- xen/include/xen/iommu.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
xen/include/xen/iommu.h +12 -3
@@ -35,10 +35,19 @@ extern bool_t iommu_hap_pt_share;extern bool_t iommu_debug;extern bool_t amd_iommu_perdev_intremap; +#define IOMMU_PAGE_SIZE (sz) (1UL << PAGE_SHIFT_##sz) +#define IOMMU_PAGE_MASK (sz) (~(u64)0 << PAGE_SHIFT_##sz) +#define IOMMU_PAGE_ALIGN (sz, addr) (((addr) + ~PAGE_MASK_##sz) & PAGE_MASK_##sz) +#define PAGE_SHIFT_4K (12) -#define PAGE_SIZE_4K (1UL << PAGE_SHIFT_4K) -#define PAGE_MASK_4K (((u64)-1) << PAGE_SHIFT_4K) -#define PAGE_ALIGN_4K (addr) (((addr) + PAGE_SIZE_4K - 1) & PAGE_MASK_4K) +#define PAGE_SIZE_4K IOMMU_PAGE_SIZE(4K) +#define PAGE_MASK_4K IOMMU_PAGE_MASK(4K) +#define PAGE_ALIGN_4K (addr) IOMMU_PAGE_ALIGN(4K, addr) + +#define PAGE_SHIFT_64K (16) +#define PAGE_SIZE_64K IOMMU_PAGE_SIZE(64K) +#define PAGE_MASK_64K IOMMU_PAGE_MASK(64K) +#define PAGE_ALIGN_64K (addr) IOMMU_PAGE_ALIGN(64K, addr)int iommu_setup (void );
Signature · 1 line
1.7.10.4
PATCH v8 3/4 drivers/passthrough: arm: Add support for SMMU drivers
In reply to Julien GrallThis patch add support for ARM architected SMMU driver. It's based on the linux drivers (drivers/iommu/arm-smmu) commit 89ac23cd.
The major differences with the Linux driver are:
- Fault by default if the SMMU is enabled to translate an address (Linux is bypassing the SMMU)
- Using P2M page table instead of creating new one
- Dropped stage-1 support
- Dropped chained SMMUs support for now
- Reworking device assignment and the different structures
Xen is programming each IOMMU by:
- Using stage-2 mode translation
- Sharing the page table with the processor
- Injecting a fault if the device has made a wrong translation
---
Changes in v6:
- Move the definition page PAGE_*_64K in another patch. This patch only contains ARM specific code now.
- Use the new way to set feature
Changes in v5:
- Fix arm_smmu_domain_remove_master by using num_s2crs instead of num_streamids
- IOMMU_FEATURE_COHERENT_WALK is became a bit position
Changes in v4:
- Use the new IRQ API e.g function without _dt_ in the name
- Use IRQF_SHARED to notify that the IRQ can be shared (i.e handle multiple actions)
- Update comment in smmu_init
- Update comment for upgrade barrier in smmu_device_reset
- Update CB_TCR to reflect change in VTCR by commit 8200dae
- Drop gr0_base which is not unused in arm_smmu_init_context_bank
- Rebase on the latest Xen (hwdom series was pushed)
- On 32 bit IPA is encoded on 40-bits. Read CB_FAR_HI on all arch
- Add verbosity in CB fault handler
- Handle 40 bits address space on ARM{32,64}.
- Implement new callback features
- platform_get_irq now returns -1 if an error occured
Changes in v3:
- Missing some static
Changes in v2:
- Update commit message
- Update some comments in the code
- Add new callbacks to assign/reassign DT device
- Rework init_dom0 and domain_teardown. The assignment/deassignement is now made in the generic code
- Set protected field in dt_device_node when the device is under an IOMMU
- Use SZ_64K and SZ_4K by the global PAGE_SIZE_{64,4}K in xen/iommu.h. The first one was not defined.
--- xen/drivers/passthrough/arm/Makefile | 1 + xen/drivers/passthrough/arm/smmu.c | 1742 ++++++++++++++++++++++++++++++++++ 2 files changed, 1743 insertions(+) create mode 100644 xen/drivers/passthrough/arm/smmu.c
xen/drivers/passthrough/arm/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += iommu.o +obj-y += smmu.o
xen/drivers/passthrough/arm/smmu.c new file +1742 -0
1,742 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v8 4/4 xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
In reply to Julien GrallGrant mapping can be used for DMA request. The dev_bus_addr returned by the hypercall is the MFN (not the IPA). Currently Linux is using this address (via swiotlb) to program the DMA.
When the device is protected by IOMMU the request will fail. We have to add 1:1 mapping in the domain p2m to allow DMA request working.
This is valid because DOM0 has its memory mapped 1:1 and therefore we know that RAM and devices cannot clash.
The grant mapping code already handle this case for x86 PV guests. Reuse the same code path for ARM guest.
---
The patch has been heavily rework to use iommu_{,un}map_page. I dropped all the acks.
Changes in v8:
- Rework differently the 1:1 mapping by using iommu_{,un}map_page helpers.
Changes in v5:
- Update commit message
Changes in v4:
- Patch added
--- xen/arch/arm/p2m.c | 2 ++ xen/common/grant_table.c | 4 ++-- xen/drivers/passthrough/arm/smmu.c | 44 ++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/grant_table.h | 2 ++ xen/include/asm-arm/p2m.h | 2 ++ xen/include/asm-x86/grant_table.h | 2 ++ 6 files changed, 54 insertions(+), 2 deletions(-)
xen/arch/arm/p2m.c +2 -0
@@ -227,6 +227,7 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr, e.p2m.write =0 ;break ; +case p2m_iommu_map_rw:case p2m_map_foreign:case p2m_grant_map_rw:case p2m_mmio_direct:
@@ -234,6 +235,7 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr, e.p2m.write =1 ;break ; +case p2m_iommu_map_ro:case p2m_grant_map_ro:case p2m_invalid: e.p2m.xn =1 ;
xen/common/grant_table.c +2 -2
@@ -727,7 +727,7 @@ __gnttab_map_grant_ref(double_gt_lock (lgt, rgt); -if ( !paging_mode_translate (ld) &&need_iommu (ld) ) +if (gnttab_need_iommu_mapping (ld) &&need_iommu (ld) ) {unsigned int wrc, rdc;int err =0 ;
@@ -935,7 +935,7 @@ __gnttab_unmap_common( act->pin -= GNTPIN_hstw_inc; } -if ( !paging_mode_translate (ld) &&need_iommu (ld) ) +if (gnttab_need_iommu_mapping (ld) &&need_iommu (ld) ) {unsigned int wrc, rdc;int err =0 ;
xen/drivers/passthrough/arm/smmu.c +44 -0
56 lines not on this page · raw message
xen/include/asm-arm/grant_table.h +2 -0
@@ -33,6 +33,8 @@ static inline int replace_grant_supported(void) ( ((i >=nr_grant_frames (d->grant_table)) && \ (i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i])) +#define gnttab_need_iommu_mapping (d) is_domain_direct_mapped(d) +#endif /* __ASM_GRANT_TABLE_H__ */ /* * Local variables:
xen/include/asm-arm/p2m.h +2 -0
@@ -45,6 +45,8 @@ typedef enum { p2m_map_foreign,/* Ram pages from foreign domain */ p2m_grant_map_rw,/* Read/write grant mapping */ p2m_grant_map_ro,/* Read-only grant mapping */ + p2m_iommu_map_rw,/* Read/write iommu mapping */ + p2m_iommu_map_ro,/* Read-only iommu mapping */ p2m_max_real_type,/* Types after this won't be store in the p2m */ } p2m_type_t;
xen/include/asm-x86/grant_table.h +2 -0
@@ -65,6 +65,8 @@ static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st)/* Done implicitly when page tables are destroyed. */ #define gnttab_release_host_mappings (domain) ( paging_mode_external(domain) ) +#define gnttab_need_iommu_mapping (d) !paging_mode_translate(d) +static inline int replace_grant_supported (void ) {return 1 ;
Signature · 1 line
1.7.10.4
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 19.05.14 at 18:24, <[email protected]> wrote:
Grant mapping can be used for DMA request. The
dev_bus_addrreturned by the hypercall is the MFN (not the IPA). Currently Linux is using this address (via swiotlb) to program the DMA.
When the device is protected by IOMMU the request will fail. We have to add 1:1 mapping in the domain p2m to allow DMA request working.This is valid because DOM0 has its memory mapped 1:1 and therefore we know that RAM and devices cannot clash.
Wasn't this 1:1 mapping meant as a temporary workaround? If so, does it really make sense to base further code on it?
xen/common/grant_table.c __gnttab_map_grant_ref( · line 730
Quoted 8 lines
xen/common/grant_table.c +1
-1@@ -727,7 +727,7 @@ __gnttab_map_grant_ref(double_gt_lock (lgt, rgt); -if ( !paging_mode_translate (ld) &&need_iommu (ld) ) +if (gnttab_need_iommu_mapping (ld) &&need_iommu (ld) )
I suppose that you want to keep the common bits of this condition common, but the two "need_iommu" in here look sort of redundant:
With the name chosen, I think it would make more sense for the second condition to be moved into gnttab_need_iommu_mapping().
xen/include/asm-arm/grant_table.h static inline int replace_grant_supported(void) · line 36
Quoted 7 lines
xen/include/asm-arm/grant_table.h +1
-0@@ -33,6 +33,8 @@ static inline int replace_grant_supported(void) ( ((i >=nr_grant_frames (d->grant_table)) && \ (i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i])) +#define gnttab_need_iommu_mapping (d) is_domain_direct_mapped(d)
While this one indeed doesn't need extra parentheses, ...
xen/include/asm-x86/grant_table.h static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st) · line 68
Quoted 7 lines
xen/include/asm-x86/grant_table.h +1
-0@@ -65,6 +65,8 @@ static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st)/* Done implicitly when page tables are destroyed. */ #define gnttab_release_host_mappings (domain) ( paging_mode_external(domain) ) +#define gnttab_need_iommu_mapping (d) !paging_mode_translate(d)
... this one does.
Also, with all of this I don't see how other than Dom0 is being (or going to be) handled in this regard.
Jan
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 19.05.14 at 18:24, <[email protected]> wrote:
Grant mapping can be used for DMA request. The
dev_bus_addrreturned by the hypercall is the MFN (not the IPA). Currently Linux is using this address (via swiotlb) to program the DMA.
When the device is protected by IOMMU the request will fail. We have to add 1:1 mapping in the domain p2m to allow DMA request working.
Quoted 5 lines
Quoted 2 lines
This is valid because DOM0 has its memory mapped 1:1 and therefore we know that RAM and devices cannot clash.
Wasn't this 1:1 mapping meant as a temporary workaround? If so, does it really make sense to base further code on it?
IOMMU on ARM has not become so prevalent (yet?) that we can get rid of it. I think we are mostly resigned to keeping it around for the time being. (sadly)
Ian.
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
In reply to Jan BeulichQuoted 6 lines · Jan Beulich
Quoted 6 lines
xen/common/grant_table.c +0
-0@@ -727,7 +727,7 @@ __gnttab_map_grant_ref(double_gt_lock (lgt, rgt);
Quoted 7 lines
xen/common/grant_table.c __gnttab_map_grant_ref( · line 730
Quoted 2 lines
xen/common/grant_table.c +1
-1-if ( !paging_mode_translate (ld) &&need_iommu (ld) ) +if (gnttab_need_iommu_mapping (ld) &&need_iommu (ld) )I suppose that you want to keep the common bits of this condition common, but the two "
need_iommu" in here look sort of redundant:
With the name chosen, I think it would make more sense for the second condition to be moved intognttab_need_iommu_mapping().
Ok. I will move these bits in the macro.
Quoted 16 lines
xen/include/asm-arm/grant_table.h static inline int replace_grant_supported(void) · line 36
Quoted 7 lines
xen/include/asm-arm/grant_table.h +1
-0@@ -33,6 +33,8 @@ static inline int replace_grant_supported(void) ( ((i >=nr_grant_frames (d->grant_table)) && \ (i < max_nr_grant_frames)) ? 0 : (d->arch.grant_table_gpfn[i])) +#define gnttab_need_iommu_mapping (d) is_domain_direct_mapped(d)While this one indeed doesn't need extra parentheses, ...
Quoted 6 lines
xen/include/asm-x86/grant_table.h +0
-0@@ -65,6 +65,8 @@ static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st)/* Done implicitly when page tables are destroyed. */ #define gnttab_release_host_mappings (domain) ( paging_mode_external(domain) )
Quoted 3 lines
xen/include/asm-x86/grant_table.h static inline void gnttab_clear_flag(unsigned int nr, uint16_t *st) · line 68
Quoted 1 line
xen/include/asm-x86/grant_table.h +1
-0+#define gnttab_need_iommu_mapping (d) !paging_mode_translate(d)... this one does.
Oh right, I will fix it in the next version.
Quoted 2 lines
Also, with all of this I don't see how other than Dom0 is being (or going to be) handled in this regard.
Only DOM0 uses direct mapping (i.e 1:1 mapping). The other guests will use their own mapping. As the P2M is shared, we can't insert this 1:1 entry.
Only protected devices (i.e the IOMMU has been programmed by Xen) will be passtrough to the guest. So we will be able to modify dev_bus_addr to return an IPA (guest address) rather than an MFN.
For now, passthrough is not supported, therefore guest doesn't have DMA-capable device. I will take care of this solution with my non-PCI passthrough patch series.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
In reply to Julien GrallQuoted 1 line · Julien Grall
Grant mapping can be used for DMA request. The
dev_bus_addrreturned by the
^Currently (?)
Quoted 2 lines
hypercall is the MFN (not the IPA). Currently Linux is using this address (via swiotlb) to program the DMA.
Rather than talking specifically about Linux and swiotlb I think it is correct to say "Guests expect to be able to use the returned address for DMA".
Quoted 5 lines
When the device is protected by IOMMU the request will fail. We have to add 1:1 mapping in the domain p2m to allow DMA request working.
This is valid because DOM0 has its memory mapped 1:1 and therefore we know that RAM and devices cannot clash.
Is it worth mentioning now that in the future when a domain only has access to protected I/O devices we would instead return dev_bus_addr==IPA and intend to drop this extra 1:1 mapping?
Quoted 2 lines
The grant mapping code already handle this case for x86 PV guests. Reuse the same code path for ARM guest.
In particular do you mean that iommu_{,un}map_page handles the reference counting needed when an mfn is mapped via multiple grant mapping? I think it must be the callers of those functions. Could you say that here please?
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +0
-0
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1545
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +7
-0@@ -1536,6 +1536,48 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d)xfree (smmu_domain); } +static int arm_smmu_map_page (struct domain *d,unsigned long gfn, +unsigned long mfn,unsigned int flags) +{ +p2m_type_t t; + +/* This function should only be used by gnttab code when the domain +* is direct mapped and gfn == mfn.
Is gfn !+ mfn an ASSERT-worthy condition?
Is gnttab the only possible user?
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1554
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c +9
-0+*/ +if ( !is_domain_direct_mapped (d) || gfn != mfn ) +return -EINVAL ; + +/* We only support readable and writable flags */ +if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) ) +return -EINVAL ; + +/* The function guest_physmap_add_entry replace the current mapping
"replaces"
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1555
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+* if there is already one...
... I feel like you intended to describe a consequence of that here. I can't see the relationship between the comment and the selection of rw vs ro mappings.
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1560
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+*/ + t = (flags & IOMMUF_writable)? p2m_iommu_map_rw : p2m_iommu_map_ro; + +/* Grant mapping can be used for DMA request. The dev_bus_addr returned by +* the hypercall is the MFN (not the IPA). For device protected by
"Grant mappings... DMA requests... For devices" (all plural)
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1562
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+* an IOMMU, Xen needs to add a 1:1 mapping in the domain p2m to +* allow DMA request working.
"to allow DMA requests to work"
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+* This is only valid when the domain is directed mapped +*/ +return guest_physmap_add_entry (d, gfn, mfn,0 , t); +}
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1576
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+ +static int arm_smmu_unmap_page (struct domain *d,unsigned long gfn) +{ +/* This function should only be used by gnttab code when the domain +* is direct mapped +*/ +if ( !is_domain_direct_mapped (d) ) +return -EINVAL ; + +guest_physmap_remove_page (d, gfn, gfn,0 );
I think 0 here is really PAGE_ORDER_4K, is it? (other callers of this function seem to be inconsistent about this)
xen/include/asm-arm/p2m.h typedef enum { · line 49
Quoted 10 lines
xen/include/asm-arm/p2m.h +2
-0@@ -45,6 +45,8 @@ typedef enum { p2m_map_foreign,/* Ram pages from foreign domain */ p2m_grant_map_rw,/* Read/write grant mapping */ p2m_grant_map_ro,/* Read-only grant mapping */ + p2m_iommu_map_rw,/* Read/write iommu mapping */ + p2m_iommu_map_ro, /* Read-only iommu mapping */
Why do we need new p2m types, rather than using e.g. the grant map type (which I suppose is what the non-1:1 map uses)?
Could you explain the reason in the commit log too please.
Ian.
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 15 lines · Ian Campbell
Quoted 1 line · Julien Grall
Grant mapping can be used for DMA request. The
dev_bus_addrreturned by the^Currently (?)Quoted 2 lines
hypercall is the MFN (not the IPA). Currently Linux is using this address (via swiotlb) to program the DMA.
Rather than talking specifically about Linux and swiotlb I think it is correct to say "Guests expect to be able to use the returned address for DMA".
Quoted 3 lines
When the device is protected by IOMMU the request will fail. We have to add 1:1 mapping in the domain p2m to allow DMA request working.
Quoted 6 lines
Quoted 2 lines
This is valid because DOM0 has its memory mapped 1:1 and therefore we know that RAM and devices cannot clash.
Is it worth mentioning now that in the future when a domain only has access to protected I/O devices we would instead return dev_bus_addr==IPA and intend to drop this extra 1:1 mapping?
I plan to modify dev_bus_addr with my non-PCI passthrough to return the IPA.
The code has been written to remove easily the 1:1 workaround (see macro is_domain_direct_mapped.
I can make a mention about it in the commit message.
Quoted 7 lines
Quoted 2 lines
The grant mapping code already handle this case for x86 PV guests. Reuse the same code path for ARM guest.
In particular do you mean that iommu_{,un}map_page handles the reference counting needed when an mfn is mapped via multiple grant mapping? I think it must be the callers of those functions. Could you say that here please?
The reference counting is done in common/grant_table (see the wrc/rdc logic before calling iommu_{,un}map_page).
Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -1536,6 +1536,48 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d)xfree (smmu_domain); }
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1545
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c +7
-0+static int arm_smmu_map_page (struct domain *d,unsigned long gfn, +unsigned long mfn,unsigned int flags) +{ +p2m_type_t t; + +/* This function should only be used by gnttab code when the domain +* is direct mapped and gfn == mfn. Is gfn !+ mfn an ASSERT-worthy condition?
The ASSERT would only be for debug build. I'd like to have a safe guard for non-debug build just in case.
Quoted 2 lines
Is gnttab the only possible user?
For ARM yes.
Quoted 12 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1554
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c +9
-0+*/ +if ( !is_domain_direct_mapped (d) || gfn != mfn ) +return -EINVAL ; + +/* We only support readable and writable flags */ +if ( !(flags & (IOMMUF_readable | IOMMUF_writable)) ) +return -EINVAL ; + +/* The function guest_physmap_add_entry replace the current mapping "replaces"
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1555
Quoted 1 line
xen/drivers/passthrough/arm/smmu.c +1
-0+* if there is already one... ... I feel like you intended to describe a consequence of that here. I can't see the relationship between the comment and the selection of rw vs ro mappings.
This was intend to be just above guest_physmap_add_entry. I will move the comment.
Quoted 22 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1560
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+*/ + t = (flags & IOMMUF_writable)? p2m_iommu_map_rw : p2m_iommu_map_ro; + +/* Grant mapping can be used for DMA request. The dev_bus_addr returned by +* the hypercall is the MFN (not the IPA). For device protected by "Grant mappings... DMA requests... For devices" (all plural)
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1562
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c +2
-0+* an IOMMU, Xen needs to add a 1:1 mapping in the domain p2m to +* allow DMA request working. "to allow DMA requests to work"
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c +9
-0+* This is only valid when the domain is directed mapped +*/ +return guest_physmap_add_entry (d, gfn, mfn,0 , t); +} + +static int arm_smmu_unmap_page (struct domain *d,unsigned long gfn) +{ +/* This function should only be used by gnttab code when the domain +* is direct mapped
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1576
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+*/ +if ( !is_domain_direct_mapped (d) ) +return -EINVAL ; + +guest_physmap_remove_page (d, gfn, gfn,0 );I think 0 here is really
PAGE_ORDER_4K, is it? (other callers of this function seem to be inconsistent about this)
Yes, assuming the guest page will always be 4K.
Quoted 15 lines
xen/include/asm-arm/p2m.h typedef enum { · line 49
Quoted 11 lines
xen/include/asm-arm/p2m.h +2
-0@@ -45,6 +45,8 @@ typedef enum { p2m_map_foreign,/* Ram pages from foreign domain */ p2m_grant_map_rw,/* Read/write grant mapping */ p2m_grant_map_ro,/* Read-only grant mapping */ + p2m_iommu_map_rw,/* Read/write iommu mapping */ + p2m_iommu_map_ro, /* Read-only iommu mapping */Why do we need new p2m types, rather than using e.g. the grant map type (which I suppose is what the non-1:1 map uses)?
Could you explain the reason in the commit log too please.
The iommu_map_page could be reuse more generically in long-term. Using p2m_grant_map_{ro,rw} would be confusing here.
What about introducing "dummy type" such as p2m_notype_{ro,rw} which could be use in such case?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 23 lines · Julien Grall
Quoted 15 lines · Ian Campbell
Quoted 1 line · Julien Grall
Grant mapping can be used for DMA request. The
dev_bus_addrreturned by the^Currently (?)Quoted 2 lines
hypercall is the MFN (not the IPA). Currently Linux is using this address (via swiotlb) to program the DMA.
Rather than talking specifically about Linux and swiotlb I think it is correct to say "Guests expect to be able to use the returned address for DMA".
Quoted 3 lines
When the device is protected by IOMMU the request will fail. We have to add 1:1 mapping in the domain p2m to allow DMA request working.
Quoted 6 lines
Quoted 2 lines
This is valid because DOM0 has its memory mapped 1:1 and therefore we know that RAM and devices cannot clash.
Is it worth mentioning now that in the future when a domain only has access to protected I/O devices we would instead return dev_bus_addr==IPA and intend to drop this extra 1:1 mapping?
Quoted 6 lines
I plan to modify
dev_bus_addrwith my non-PCI passthrough to return the IPA.The code has been written to remove easily the 1:1 workaround (see macro
is_domain_direct_mapped.I can make a mention about it in the commit message.
Thanks.
Quoted 10 lines
Quoted 7 lines
Quoted 2 lines
The grant mapping code already handle this case for x86 PV guests. Reuse the same code path for ARM guest.
In particular do you mean that iommu_{,un}map_page handles the reference counting needed when an mfn is mapped via multiple grant mapping? I think it must be the callers of those functions. Could you say that here please?
The reference counting is done in common/grant_table (see the wrc/rdc logic before calling iommu_{,un}map_page).
OK. I take it you plan to insert this into the commit message too.
Quoted 18 lines
Quoted 8 lines
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c +0
-0@@ -1536,6 +1536,48 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d)xfree (smmu_domain); }Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1545
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c +7
-0+static int arm_smmu_map_page (struct domain *d,unsigned long gfn, +unsigned long mfn,unsigned int flags) +{ +p2m_type_t t; + +/* This function should only be used by gnttab code when the domain +* is direct mapped and gfn == mfn. Is gfn !+ mfn an ASSERT-worthy condition?
Quoted 2 lines
The ASSERT would only be for debug build. I'd like to have a safe guard for non-debug build just in case.
That's a BUG_ON then I think, assuming it would be a coding error in the hypervisor (rather than e.g. a guest trying to exploit the issue somehow).
Quoted 3 lines
Quoted 1 line
Is gnttab the only possible user?
For ARM yes.
OK
(out of curiosity what are the other users on x86?)
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
xen/drivers/passthrough/arm/smmu.c +9
-0+* This is only valid when the domain is directed mapped +*/ +return guest_physmap_add_entry (d, gfn, mfn,0 , t); +} + +static int arm_smmu_unmap_page (struct domain *d,unsigned long gfn) +{ +/* This function should only be used by gnttab code when the domain +* is direct mapped Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1576
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +5
-0+*/ +if ( !is_domain_direct_mapped (d) ) +return -EINVAL ; + +guest_physmap_remove_page (d, gfn, gfn,0 );I think 0 here is really
PAGE_ORDER_4K, is it? (other callers of this function seem to be inconsistent about this)
Quoted 1 line
Yes, assuming the guest page will always be 4K.
Even if not then PAGE_ORDER_4K will make good fodder for grep...
Quoted 15 lines
Quoted 6 lines
Quoted 6 lines
xen/include/asm-arm/p2m.h +0
-0@@ -45,6 +45,8 @@ typedef enum { p2m_map_foreign, /* Ram pages from foreign domain */Quoted 8 lines
xen/include/asm-arm/p2m.h typedef enum { · line 49
Quoted 4 lines
xen/include/asm-arm/p2m.h +2
-0p2m_grant_map_rw,/* Read/write grant mapping */ p2m_grant_map_ro,/* Read-only grant mapping */ + p2m_iommu_map_rw,/* Read/write iommu mapping */ + p2m_iommu_map_ro, /* Read-only iommu mapping */Why do we need new p2m types, rather than using e.g. the grant map type (which I suppose is what the non-1:1 map uses)?
Could you explain the reason in the commit log too please.
Quoted 6 lines
The
iommu_map_pagecould be reuse more generically in long-term. Using p2m_grant_map_{ro,rw} would be confusing here.What about introducing "dummy type" such as p2m_notype_{ro,rw} which could be use in such case?
notype is effectively "ram" I think, but that doesn't seem quite right either.
I'm just worried that p2m type bits are in limited supply so I want to be sure using new ones is justified.
Ian.
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 18 lines · Ian Campbell
Quoted 18 lines
Quoted 17 lines
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c +0
-0xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1545
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +7
-0@@ -1536,6 +1536,48 @@ static void arm_smmu_iommu_domain_teardown(struct domain *d)xfree (smmu_domain); } +static int arm_smmu_map_page (struct domain *d,unsigned long gfn, +unsigned long mfn,unsigned int flags) +{ +p2m_type_t t; + +/* This function should only be used by gnttab code when the domain +* is direct mapped and gfn == mfn. Is gfn !+ mfn an ASSERT-worthy condition?
Quoted 6 lines
Quoted 2 lines
The ASSERT would only be for debug build. I'd like to have a safe guard for non-debug build just in case.
That's a
BUG_ONthen I think, assuming it would be a coding error in the hypervisor (rather than e.g. a guest trying to exploit the issue somehow).
The guest should not be able to exploit this issue. I will add a BUG_ON.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Is gnttab the only possible user?
For ARM yes.
OK
(out of curiosity what are the other users on x86?)
It's used for create the IOMMU PT.
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c +4
-0+* This is only valid when the domain is directed mapped +*/ +return guest_physmap_add_entry (d, gfn, mfn,0 , t); +}xen/drivers/passthrough/arm/smmu.c static void arm_smmu_iommu_domain_teardown(struct domain *d) · line 1576
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c +10
-0+ +static int arm_smmu_unmap_page (struct domain *d,unsigned long gfn) +{ +/* This function should only be used by gnttab code when the domain +* is direct mapped +*/ +if ( !is_domain_direct_mapped (d) ) +return -EINVAL ; + +guest_physmap_remove_page (d, gfn, gfn,0 );I think 0 here is really
PAGE_ORDER_4K, is it? (other callers of this function seem to be inconsistent about this)
Quoted 3 lines
Quoted 1 line
Yes, assuming the guest page will always be 4K.
Even if not then
PAGE_ORDER_4Kwill make good fodder for grep...
I will use it in the next version.
Quoted 8 lines
Quoted 2 lines
What about introducing "dummy type" such as p2m_notype_{ro,rw} which could be use in such case?
notype is effectively "ram" I think, but that doesn't seem quite right either.
I'm just worried that p2m type bits are in limited supply so I want to be sure using new ones is justified.
We don't really need to store those type in the P2M. We only need them to choose the page attributes.
We could introduce a virtual type (i.e value > p2m_max_real_type) and store p2m_invalid in the P2M.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 8 lines · Julien Grall
Quoted 2 lines
I'm just worried that p2m type bits are in limited supply so I want to be sure using new ones is justified.
We don't really need to store those type in the P2M. We only need them to choose the page attributes.
We could introduce a virtual type (i.e value >
p2m_max_real_type) and storep2m_invalidin the P2M.
Will finding p2m_invalid under various circumstances not confuse something somewhere?
How about a single real p2m_special and the virtual types you suggest?
Or, TBH, lets just use the two types you propose and do all this when we run out... A comment to the affect that the types are only used for the rw bit might serve as a hint to us in a couple of years that we can easily get rid of them...
Ian.
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
In reply to Julien GrallQuoted 3 lines · Julien Grall
Quoted 1 line
Is gnttab the only possible user?
For ARM yes.
[...]
Quoted 2 lines
The
iommu_map_pagecould be reuse more generically in long-term. Using p2m_grant_map_{ro,rw} would be confusing here.
BTW, those statements contradict each other.
Ian.
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 10 lines · Ian Campbell
Quoted 3 lines · Julien Grall
Quoted 1 line
Is gnttab the only possible user?
For ARM yes.
[...]
Quoted 2 lines
The
iommu_map_pagecould be reuse more generically in long-term. Using p2m_grant_map_{ro,rw} would be confusing here.BTW, those statements contradict each other.
Right. This function could also be used if we want to support per-IOMMU p2m rather than sharing with the CPU.
Signature · 1 line
Julien Grall
Re: [PATCH v8 4/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 6 lines · Julien Grall
Quoted 5 lines · Ian Campbell
Quoted 3 lines · Julien Grall
Quoted 1 line
Is gnttab the only possible user?
For ARM yes.
Quoted 8 lines
Quoted 5 lines
[...]
Quoted 2 lines
The
iommu_map_pagecould be reuse more generically in long-term. Using p2m_grant_map_{ro,rw} would be confusing here.BTW, those statements contradict each other.
Right. This function could also be used if we want to support per-IOMMU p2m rather than sharing with the CPU.
I suspected as much, thanks.
I don't know how likely that is to be a thing which happens.
(I'm not sure what the implications of that are for either the comment or the p2m type name...)
Ian.
Quoted 3 lines · Julien Grall
xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent
walk
xen: iommu: Define PAGE_{SHIFT,SIZE,ALIGN,MASK)_64K
I've committed these.
Quoted 2 lines
drivers/passthrough: arm: Add support for SMMU drivers xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
But not these. The last one has outstanding comments and the penultimate one cannot go in without.