IOMMU support for ARM
v7 cover IOMMU support for ARM
Hello,
This is the seventh 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.
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-v7
Sincerely yours,
[1] https://list.xen.org/archives/html/xen-devel/2014-05/msg01523.html
Julien Grall (4):
xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent
walk
xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
xen: iommu: Define PAGE_{SHIFT,SIZE,ALIGN,MASK)_64K drivers/passthrough: arm: Add support for SMMU drivers
xen/arch/arm/mm.c | 33 +- xen/arch/arm/p2m.c | 38 +- xen/drivers/passthrough/arm/Makefile | 1 + xen/drivers/passthrough/arm/smmu.c | 1742 ++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/iommu.c | 10 + xen/include/xen/hvm/iommu.h | 6 + xen/include/xen/iommu.h | 24 +- 7 files changed, 1838 insertions(+), 16 deletions(-) create mode 100644 xen/drivers/passthrough/arm/smmu.c
Signature · 1 line
1.7.10.4
PATCH v7 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 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/p2m.c | 38 ++++++++++++++++++++++++++++++-------- xen/drivers/passthrough/iommu.c | 10 ++++++++++ xen/include/xen/hvm/iommu.h | 6 ++++++ xen/include/xen/iommu.h | 9 +++++++++ 4 files changed, 55 insertions(+), 8 deletions(-)
xen/arch/arm/p2m.c +30 -8
@@ -253,9 +253,15 @@ static lpae_t mfn_to_p2m_entry(unsigned long mfn, unsigned int mattr,return e; } +static inline void p2m_write_pte (lpae_t *p,lpae_t pte,bool_t flush_cache) +{ +write_pte (p, pte); +if ( flush_cache ) +clean_xen_dcache (*p); +} +/* Allocate a new page table page and hook it in via the given entry */ -static int p2m_create_table (struct domain *d, -lpae_t *entry) +static int p2m_create_table (struct domain *d,lpae_t *entry,bool_t flush_cache) {struct p2m_domain *p2m = &d->arch.p2m;struct page_info *page;
@@ -272,11 +278,13 @@ static int p2m_create_table(struct domain *d, p =__map_domain_page (page);clear_page (p); +if ( flush_cache ) +clean_xen_dcache_va_range (p,PAGE_SIZE );unmap_domain_page (p); pte =mfn_to_p2m_entry (page_to_mfn (page),MATTR_MEM , p2m_invalid); -write_pte (entry, pte); +p2m_write_pte (entry, pte, flush_cache);return 0 ; }
@@ -308,6 +316,13 @@ static int apply_p2m_changes(struct domain *d,unsigned int flush =0 ;bool_t populate = (op ==INSERT || op ==ALLOCATE );lpae_t pte; +bool_t flush_pt; + +/* Some IOMMU don't support coherent PT walk. When the p2m is +* shared with the CPU, Xen has to make sure that the PT changes have +* reached the memory +*/ + flush_pt = iommu_enabled && !iommu_has_feature (d,IOMMU_FEAT_COHERENT_WALK );spin_lock (&p2m->lock);
@@ -334,7 +349,8 @@ static int apply_p2m_changes(struct domain *d,continue ; } - rc =p2m_create_table (d, &first[first_table_offset (addr)]); + rc =p2m_create_table (d, &first[first_table_offset (addr)], + flush_pt);if ( rc <0 ) {printk ("p2m_populate_ram: L1 failed\n" );
@@ -360,7 +376,8 @@ static int apply_p2m_changes(struct domain *d,continue ; } - rc =p2m_create_table (d, &second[second_table_offset (addr)]); + rc =p2m_create_table (d, &second[second_table_offset (addr)], + flush_pt);if ( rc <0 ) {printk ("p2m_populate_ram: L2 failed\n" ); goto out;
@@ -411,13 +428,15 @@ static int apply_p2m_changes(struct domain *d, pte =mfn_to_p2m_entry (page_to_mfn (page), mattr, t); -write_pte (&third[third_table_offset (addr)], pte); +p2m_write_pte (&third[third_table_offset (addr)], + pte, flush_pt); }break ;case INSERT : { pte =mfn_to_p2m_entry (maddr >>PAGE_SHIFT , mattr, t); -write_pte (&third[third_table_offset (addr)], pte); +p2m_write_pte (&third[third_table_offset (addr)], + pte, flush_pt); maddr +=PAGE_SIZE ; }break ;
@@ -433,7 +452,8 @@ static int apply_p2m_changes(struct domain *d, count +=0x10 ;memset (&pte,0x00 ,sizeof (pte)); -write_pte (&third[third_table_offset (addr)], pte); +p2m_write_pte (&third[third_table_offset (addr)], + pte, flush_pt); count++; }break ;
@@ -548,10 +568,12 @@ int p2m_alloc_table(struct domain *d)/* Clear both first level pages */ p =__map_domain_page (page);clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE );unmap_domain_page (p); p =__map_domain_page (page +1 );clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE );unmap_domain_page (p); p2m->first_level = page;
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/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
Re: [PATCH v7 1/4] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Quoted 11 lines · Julien Grall
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.
Signed-off-by Julien Grall <[email protected]>
xen/arch/arm/p2m.c int p2m_alloc_table(struct domain *d) · line 576
Quoted 10 lines
xen/arch/arm/p2m.c +2
-0@@ -548,10 +568,12 @@ int p2m_alloc_table(struct domain *d)/* Clear both first level pages */ p =__map_domain_page (page);clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE );unmap_domain_page (p); p =__map_domain_page (page +1 );clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE );
I wonder if we need clear_and_clean_page()?
xen/include/xen/iommu.h int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 73
Quoted 5 lines
xen/include/xen/iommu.h +4
-0+enum iommu_feature +{ +IOMMU_FEAT_COHERENT_WALK , + IOMMU_FEAT_count,
Lowercase?
Ian.
Re: [PATCH v7 1/4] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
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.
Quoted 7 lines
Quoted 5 lines
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.
Signed-off-by Julien Grall <[email protected]>
Thanks!
Quoted 7 lines
Quoted 7 lines
xen/arch/arm/p2m.c +1
-0@@ -548,10 +568,12 @@ int p2m_alloc_table(struct domain *d)/* Clear both first level pages */ p =__map_domain_page (page);clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE );unmap_domain_page (p);
Quoted 6 lines
xen/arch/arm/p2m.c int p2m_alloc_table(struct domain *d) · line 576
Quoted 3 lines
xen/arch/arm/p2m.c +1
-0p =__map_domain_page (page +1 );clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE );I wonder if we need
clear_and_clean_page()?
I though about it but I was too lazy to create one. I will add a helper if I need to resend this series.
Quoted 7 lines
xen/include/xen/iommu.h int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 73
Quoted 5 lines
xen/include/xen/iommu.h +4
-0+enum iommu_feature +{ +IOMMU_FEAT_COHERENT_WALK , + IOMMU_FEAT_count,Lowercase?
What do you mean?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v7 1/4] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Quoted 36 lines · Julien Grall
Quoted 7 lines · Ian Campbell
Quoted 6 lines · Julien Grall
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.
Quoted 7 lines
Quoted 5 lines
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.
Signed-off-by Julien Grall <[email protected]>Thanks!
Quoted 7 lines
Quoted 7 lines
xen/arch/arm/p2m.c +1
-0@@ -548,10 +568,12 @@ int p2m_alloc_table(struct domain *d)/* Clear both first level pages */ p =__map_domain_page (page);clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE );unmap_domain_page (p);Quoted 6 lines
xen/arch/arm/p2m.c int p2m_alloc_table(struct domain *d) · line 576
Quoted 3 lines
xen/arch/arm/p2m.c +1
-0p =__map_domain_page (page +1 );clear_page (p); +clean_xen_dcache_va_range (p,PAGE_SIZE );I wonder if we need
clear_and_clean_page()?I though about it but I was too lazy to create one. I will add a helper if I need to resend this series.
Quoted 1 line
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
xen/include/xen/iommu.h int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 73
Quoted 4 lines
xen/include/xen/iommu.h +4
-0+enum iommu_feature +{ +IOMMU_FEAT_COHERENT_WALK , + IOMMU_FEAT_count,Lowercase?
What do you mean?
Enums are normally all uppercase.
Ian.
Re: [PATCH v7 1/4] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
In reply to Ian CampbellQuoted 8 lines
Quoted 1 line
Quoted 1 line · On 15.05.14 at 17:20, <[email protected]> wrote:
xen/include/xen/iommu.h int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 73
Quoted 4 lines · Julien Grall
xen/include/xen/iommu.h +4
-0+enum iommu_feature +{ +IOMMU_FEAT_COHERENT_WALK , + IOMMU_FEAT_count,Lowercase?
I intentionally suggested it that way to make the sentinel stand out from the "normal" entries.
Jan
Re: [PATCH v7 1/4] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
In reply to Julien GrallQuoted 4 lines
Quoted 1 line
Quoted 1 line · On 15.05.14 at 16:16, <[email protected]> wrote:
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.
Quoted 8 lines
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.
Signed-off-by Julien Grall <[email protected]>
IOMMU part:
with one final nit:
xen/include/xen/iommu.h int iommu_map_page(struct domain *d, unsigned long gfn, · line 74
Quoted 11 lines
xen/include/xen/iommu.h +4
-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,
This is supposed to be the terminal entry, no matter what future additions may arise. Therefore it shouldn't have a (potentially misleading) trailing comma on it.
Jan
Re: [PATCH v7 1/4] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.05.14 at 16:16, <[email protected]> wrote:
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.
Quoted 8 lines
Quoted 5 lines
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.
Signed-off-by Julien Grall <[email protected]>IOMMU part:
Acked-by Jan Beulich <[email protected]>
Thanks. Ian, will you take care to remove the "," in this patch? It will avoid me to resend the whole series for this small change.
Quoted 9 lines
with one final nit:
Quoted 7 lines
xen/include/xen/iommu.h +0
-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);
Quoted 4 lines
xen/include/xen/iommu.h int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 73
Quoted 4 lines
xen/include/xen/iommu.h +4
-0+enum iommu_feature +{ +IOMMU_FEAT_COHERENT_WALK , + IOMMU_FEAT_count,
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v7 1/4] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Quoted 12 lines · Julien Grall
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 15.05.14 at 16:16, <[email protected]> wrote:
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.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Signed-off-by Julien Grall <[email protected]>IOMMU part:
Acked-by Jan Beulich <[email protected]>Thanks. Ian, will you take care to remove the "," in this patch? It will avoid me to resend the whole series for this small change.
I can do, yes.
Quoted 17 lines
Quoted 10 lines
with one final nit:
Quoted 7 lines
xen/include/xen/iommu.h +0
-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);Quoted 4 lines
xen/include/xen/iommu.h int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, · line 73
Quoted 4 lines
xen/include/xen/iommu.h +4
-0+enum iommu_feature +{ +IOMMU_FEAT_COHERENT_WALK , + IOMMU_FEAT_count,Regards,
PATCH v7 2/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.
---
Changes in v5:
- Update commit message
Changes in v4:
- Patch added
--- xen/arch/arm/mm.c | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-)
xen/arch/arm/mm.c +28 -5
@@ -1199,6 +1199,7 @@ int create_grant_host_mapping(unsigned long addr, unsigned long frame, {int rc;p2m_type_t t = p2m_grant_map_rw; +struct domain *d = current->domain;if ( cache_flags || (flags & ~GNTMAP_readonly) != GNTMAP_host_map )return GNTST_general_error;
@@ -1206,13 +1207,32 @@ int create_grant_host_mapping(unsigned long addr, unsigned long frame,if ( flags & GNTMAP_readonly ) t = p2m_grant_map_ro; - rc =guest_physmap_add_entry (current->domain, addr >>PAGE_SHIFT , - frame,0 , t); + rc =guest_physmap_add_entry (d, addr >>PAGE_SHIFT , frame,0 , t);if ( rc ) -return GNTST_general_error; -else -return GNTST_okay; + goto gerror; + +/* 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 +* an IOMMU, Xen needs to add a 1:1 mapping in the domain p2m to +* allow DMA request working. +* This is only valid when the domain is directed mapped +*/ +if (is_domain_direct_mapped (d) &&need_iommu (d) ) + { + rc =guest_physmap_add_entry (d, frame, frame,0 , t); +if ( rc ) + goto unmap; + } + +return GNTST_okay; + +unmap: +guest_physmap_remove_page (d, addr >>PAGE_SHIFT , frame,0 ); + +gerror: +return GNTST_general_error; + } int replace_grant_host_mapping(unsigned long addr, unsigned long mfn,
@@ -1226,6 +1246,9 @@ int replace_grant_host_mapping(unsigned long addr, unsigned long mfn,guest_physmap_remove_page (d, gfn, mfn,0 ); +if (is_domain_direct_mapped (d) &&need_iommu (d) ) +guest_physmap_remove_page (d, mfn, mfn,0 ); +return GNTST_okay; }
Signature · 1 line
1.7.10.4
Re: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 8 lines · Julien Grall
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.
I though a bit more about this patch. It doesn't handle the case where 2 grant use the same MFN, which is valid.
In this case, we should remove the 1:1 mapping only when the last grant is removed.
I'm not sure how to handle this case.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 11 lines · Julien Grall
Quoted 8 lines · Julien Grall
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.
Quoted 7 lines
I though a bit more about this patch. It doesn't handle the case where 2 grant use the same MFN, which is valid.
In this case, we should remove the 1:1 mapping only when the last grant is removed.
I'm not sure how to handle this case.
Urk, yes indeed.
This is all hypervisor side stuff I think, right?
I wonder if the grant table maptrack stuff is helpful here, i.e. could it contain a reference count (if it doesn't already)? Some care and attention would be needed to make it safe, but it might be doable.
Ian.
Re: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 15 lines · Ian Campbell
Quoted 14 lines · Julien Grall
Quoted 8 lines · Julien Grall
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.
I though a bit more about this patch. It doesn't handle the case where 2 grant use the same MFN, which is valid.
Quoted 8 lines
Quoted 4 lines
In this case, we should remove the 1:1 mapping only when the last grant is removed.
I'm not sure how to handle this case.
Urk, yes indeed.
This is all hypervisor side stuff I think, right?
There is 2 issues (one in hypervisor side, the other in DOM0).
The issue I'm talking here is in the hypervisor side.
Quoted 3 lines
I wonder if the grant table maptrack stuff is helpful here, i.e. could it contain a reference count (if it doesn't already)? Some care and attention would be needed to make it safe, but it might be doable.
It seems that mapcount (common/grant_table.c), do the job for us. I will give a look on it.
The other issue (from DOM0 side) comes from the swiotlb implementation for ARM (see arch/arm/xen/p2m.c). We are unable to handle multiple PFN linked to a same MFN.
This case will be silently ignore and still work (???). This is happening with Freebsd on ARM when portsnap is executed for the first time. I'm not sure why.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 36 lines · Julien Grall
Quoted 15 lines · Ian Campbell
Quoted 14 lines · Julien Grall
Quoted 8 lines · Julien Grall
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.
I though a bit more about this patch. It doesn't handle the case where 2 grant use the same MFN, which is valid.
Quoted 8 lines
Quoted 4 lines
In this case, we should remove the 1:1 mapping only when the last grant is removed.
I'm not sure how to handle this case.
Urk, yes indeed.
This is all hypervisor side stuff I think, right?
There is 2 issues (one in hypervisor side, the other in DOM0).
The issue I'm talking here is in the hypervisor side.
Quoted 3 lines
I wonder if the grant table maptrack stuff is helpful here, i.e. could it contain a reference count (if it doesn't already)? Some care and attention would be needed to make it safe, but it might be doable.
It seems that mapcount (
common/grant_table.c), do the job for us. I will give a look on it.
Quoted 7 lines
The other issue (from DOM0 side) comes from the swiotlb implementation for ARM (see
arch/arm/xen/p2m.c). We are unable to handle multiple PFN linked to a same MFN.This case will be silently ignore and still work (???). This is happening with Freebsd on ARM when portsnap is executed for the first time. I'm not sure why.
Not sure I'm following what's going on here, are you saying that FreeBSD blkfront uses the same grant ref on two (or more) requests at the same time?
Roger.
Re: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 2 lines · Roger Pau Monné
Not sure I'm following what's going on here, are you saying that FreeBSD blkfront uses the same grant ref on two (or more) requests at the same time?
My understanding was that there were two grant refs to the same mfn, which could happen if two threads were doing (direct?) IO to buffers which happened to lie on the same page, or with aio etc.
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 7 lines · Ian Campbell
Quoted 2 lines · Roger Pau Monné
Not sure I'm following what's going on here, are you saying that FreeBSD blkfront uses the same grant ref on two (or more) requests at the same time?
My understanding was that there were two grant refs to the same mfn, which could happen if two threads were doing (direct?) IO to buffers which happened to lie on the same page, or with aio etc.
Sorry I wasn't clear on the use-case.
I'm trying to run portsnap on a FreeBSD ARM guest. The first time I load the software, the guest is sending (in xbd_queue_cb) at the same time multiple grant with the same IPA (guest address). This will result to the same MFN from DOM0/Xen POV.
I did a bit of debug, and this come from the same thread. I have virtual buffer where each page of this buffer pointed to the same physical address.
FreeBSD is asking to write this buffer to the disk but from what I see it mostly contains garbage (full of 0xc2).
I can't find where this comes and wondering if you have any thoughts.
I was wondering if this things happen on FreeBSD x86.
Regards,
Signature · 6 lines
Julien Grall _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 4 lines · Julien Grall
FreeBSD is asking to write this buffer to the disk but from what I see it mostly contains garbage (full of
0xc2).I can't find where this comes and wondering if you have any thoughts.
0xc2 is the value which Xen uses to scrub pages when debug=y (see xen/common/page_alloc.c:scrub_one_page).
Ian.
Re: [PATCH v7 2/4] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 8 lines · Ian Campbell
Quoted 4 lines · Julien Grall
FreeBSD is asking to write this buffer to the disk but from what I see it mostly contains garbage (full of
0xc2).I can't find where this comes and wondering if you have any thoughts.
0xc2is the value which Xen uses to scrub pages when debug=y (see xen/common/page_alloc.c:scrub_one_page).
I though about it, but I find strange that the guest is trying to write non-modified page to the disk.
I will try to debug a bit more on it.
Signature · 1 line
Julien Grall
PATCH v7 3/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 v7 4/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