IOMMU support for ARM
v4 cover IOMMU support for ARM
Hello
This is the fourth version of this serie to add support for IOMMU on ARM. It also adds ARM SMMU driver which is used for instance on Midway.
The ARM IOMMU architecture assumes that page table is shared between the processor and each IOMMU.
Major changes in v4:
- Support upstream Linux DOM0 without any change (see patch #18)
- Support 40bits address space in the SMMU drivers
- Rebase on the latest Xen (some patches clashed with the hwdom series)
The patch series is divided following:
- #1-#4: Small fixes on ARM code
- #5: Fix grant-table with IOMMU. Will be necessary for ARM later
- #6-#8: Small changes in amd and vtd IOMMU drivers
- #10-#11: Add new device tree helpers
- #12-#14: Prepare IOMMU code to add support for ARM
- #15-#19: Add IOMMU architecture for ARM
- #20: Add SMMU driver
- #21: Add new bindings to notify Linux the device is protected by an IOMMU. This patch is not mandatory and just here for improvement.
This series also dependency on the interrupt series I've sent earlier (see "xen/arm: Interrupt management reworking").
A working tree can be found here:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch smmu-v4
Sincerely yours,
Julien Grall (21):
xen/arm: map_device: Don't hardcode dom0 in print message xen/arm: Constify address pointer for cache helpers xen/arm: p2m: Move comment that was misplaced
xen/arm: p2m: apply_p2m_changes: Only load domain P2M when we flush
TLBs
xen/common: grant-table: only call IOMMU if paging mode translate is
disabled
xen/passthrough: amd: Remove domain_id from hvm_iommu xen/passthrough: amd: rename iommu_has_feature into
amd_iommu_has_feature
xen/passthrough: vtd: iommu_set_hwdom_mapping is VTD specific xen/dts: Add dt_property_read_bool
xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle xen/passthrough: rework hwdom_pvh_reqs to use it also on ARM xen/passthrough: iommu: Split generic IOMMU code xen/passthrough: iommu: Introduce arch specific code xen/passthrough: iommu: Basic support of device tree assignment xen/passthrough: Introduce IOMMU ARM architecture
MAINTAINERS: Add drivers/passthrough/arm
xen/arm: Don't give IOMMU devices to dom0 when iommu is disabled 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 drivers/passthrough: arm: Add support for SMMU drivers xen/arm: Add the property "protected-devices" in the hypervisor node
MAINTAINERS | 1 + xen/arch/arm/Rules.mk | 1 + xen/arch/arm/device.c | 15 + xen/arch/arm/domain.c | 7 + xen/arch/arm/domain_build.c | 86 +- xen/arch/arm/kernel.h | 3 + xen/arch/arm/mm.c | 33 +- xen/arch/arm/p2m.c | 49 +- xen/arch/arm/setup.c | 2 + xen/arch/x86/domctl.c | 6 +- xen/arch/x86/hvm/io.c | 2 +- xen/arch/x86/tboot.c | 3 +- xen/common/device_tree.c | 161 ++- xen/common/grant_table.c | 7 +- xen/drivers/passthrough/Makefile | 6 +- xen/drivers/passthrough/amd/iommu_cmd.c | 3 +- xen/drivers/passthrough/amd/iommu_detect.c | 2 +- xen/drivers/passthrough/amd/iommu_guest.c | 8 +- xen/drivers/passthrough/amd/iommu_init.c | 16 +- xen/drivers/passthrough/amd/iommu_map.c | 56 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 53 +- xen/drivers/passthrough/arm/Makefile | 2 + xen/drivers/passthrough/arm/iommu.c | 72 + xen/drivers/passthrough/arm/smmu.c | 1750 +++++++++++++++++++++++++ xen/drivers/passthrough/device_tree.c | 111 ++ xen/drivers/passthrough/iommu.c | 516 +------- xen/drivers/passthrough/pci.c | 387 ++++++ xen/drivers/passthrough/vtd/extern.h | 2 + xen/drivers/passthrough/vtd/iommu.c | 76 +- xen/drivers/passthrough/vtd/x86/vtd.c | 2 +- xen/drivers/passthrough/x86/Makefile | 1 + xen/drivers/passthrough/x86/iommu.c | 145 ++ xen/include/asm-arm/device.h | 13 +- xen/include/asm-arm/domain.h | 2 + xen/include/asm-arm/hvm/iommu.h | 10 + xen/include/asm-arm/iommu.h | 36 + xen/include/asm-arm/page.h | 8 +- xen/include/asm-x86/hvm/iommu.h | 22 + xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 2 +- xen/include/asm-x86/iommu.h | 43 + xen/include/xen/device_tree.h | 89 ++ xen/include/xen/hvm/iommu.h | 27 +- xen/include/xen/iommu.h | 83 +- 43 files changed, 3225 insertions(+), 694 deletions(-) create mode 100644 xen/drivers/passthrough/arm/Makefile create mode 100644 xen/drivers/passthrough/arm/iommu.c create mode 100644 xen/drivers/passthrough/arm/smmu.c create mode 100644 xen/drivers/passthrough/device_tree.c create mode 100644 xen/drivers/passthrough/x86/iommu.c create mode 100644 xen/include/asm-arm/hvm/iommu.h create mode 100644 xen/include/asm-arm/iommu.h create mode 100644 xen/include/asm-x86/iommu.h
Signature · 1 line
1.7.10.4
PATCH v4 1/21 xen/arm: map_device: Don't hardcode dom0 in print message
---
Changes in v4:
- Patch added
--- xen/arch/arm/domain_build.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
xen/arch/arm/domain_build.c +3 -2
@@ -754,8 +754,9 @@ static int map_device(struct domain *d, const struct dt_device_node *dev)if ( res ) {printk (XENLOG_ERR "Unable to map 0x%" PRIx64 -" - 0x%" PRIx64" in dom0\n" , - addr &PAGE_MASK ,PAGE_ALIGN (addr + size) -1 ); +" - 0x%" PRIx64" in domain %d\n" , + addr &PAGE_MASK ,PAGE_ALIGN (addr + size) -1 , + d->domain_id);return res; } }
Signature · 1 line
1.7.10.4
Re: [PATCH v4 01/21] xen/arm: map_device: Don't hardcode dom0 in print message
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>
PATCH v4 2/21 xen/arm: Constify address pointer for cache helpers
In reply to Julien GrallThe memory pointed by this pointer is not modified in clean_xen_dcache_va_range and clean_and_invalidate_xen_dcache_va_range.
Constify it. This will allow us to use theses helpers later in code which use const.
--- xen/include/asm-arm/page.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
xen/include/asm-arm/page.h +4 -4
@@ -260,9 +260,9 @@ extern size_t cacheline_bytes;/* Functions for flushing medium-sized areas. * if 'range' is large enough we might want to use model-specific * full-cache flushes. */ -static inline void clean_xen_dcache_va_range (void *p,unsigned long size) +static inline void clean_xen_dcache_va_range (const void *p,unsigned long size) { -void *end; +const void *end;dsb (sy);/* So the CPU issues all writes to the range */ for ( end = p + size; p < end; p += cacheline_bytes ) asm volatile (__clean_xen_dcache_one(0) : : "r" (p));
@@ -270,9 +270,9 @@ static inline void clean_xen_dcache_va_range(void *p, unsigned long size) }static inline void clean_and_invalidate_xen_dcache_va_range - (void *p,unsigned long size) + (const void *p,unsigned long size) { -void *end; +const void *end;dsb (sy);/* So the CPU issues all writes to the range */ for ( end = p + size; p < end; p += cacheline_bytes ) asm volatile (__clean_and_invalidate_xen_dcache_one(0) : : "r" (p));
Signature · 1 line
1.7.10.4
Re: [PATCH v4 02/21] xen/arm: Constify address pointer for cache helpers
Quoted 7 lines · Julien Grall
The memory pointed by this pointer is not modified in
clean_xen_dcache_va_rangeandclean_and_invalidate_xen_dcache_va_range.Constify it. This will allow us to use theses helpers later in code which use const.
Signed-off-by Julien Grall <[email protected]>
PATCH v4 3/21 xen/arm: p2m: Move comment that was misplaced
In reply to Julien Grall---
Changes in v4:
- Patch added
--- xen/arch/arm/p2m.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/arm/p2m.c +1 -1
@@ -383,10 +383,10 @@ static int apply_p2m_changes(struct domain *d,put_page (mfn_to_page (mfn)); } -/* Allocate a new RAM page and attach */ switch (op) {case ALLOCATE : { +/* Allocate a new RAM page and attach */ struct page_info *page;ASSERT (!pte.p2m.valid);
Signature · 1 line
1.7.10.4
Re: [PATCH v4 03/21] xen/arm: p2m: Move comment that was misplaced
Quoted 1 line · Julien Grall
Signed-off-by Julien Grall <[email protected]>
PATCH v4 4/21 xen/arm: p2m: apply_p2m_changes: Only load domain P2M when we flush TLBs
In reply to Julien Grallapply_p2m_changes needs to switch to another VTTBR temporarily to avoid flush every TLBs.
As it's only needed there, we can restrict the scope where the VTTBR of this domain is loaded.
---
Changes in v4:
- Patch added
--- xen/arch/arm/p2m.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
xen/arch/arm/p2m.c +9 -10
@@ -296,9 +296,6 @@ static int apply_p2m_changes(struct domain *d,spin_lock (&p2m->lock); -if ( d != current->domain ) -p2m_load_VTTBR (d); - addr = start_gpaddr;while ( addr < end_gpaddr ) {
@@ -454,12 +451,17 @@ static int apply_p2m_changes(struct domain *d,if ( flush ) { -/* At the beginning of the function, Xen is updating VTTBR -* with the domain where the mappings are created. In this -* case it's only necessary to flush TLBs on every CPUs with -* the current VMID (our domain). +/* Update the VTTBR if necessary with the domain where mappings +* are created. In this case it's only necessary to flush TLBs +* on every CPUs with the current VMID (our domain). */ +if ( d != current->domain ) +p2m_load_VTTBR (d); +flush_tlb (); + +if ( d != current->domain ) +p2m_load_VTTBR (current->domain); }if ( op ==ALLOCATE || op ==INSERT )
@@ -478,9 +480,6 @@ out:if (second)unmap_domain_page (second);if (first)unmap_domain_page (first); -if ( d != current->domain ) -p2m_load_VTTBR (current->domain); -spin_unlock (&p2m->lock);return rc;
Signature · 1 line
1.7.10.4
Re: [PATCH v4 04/21] xen/arm: p2m: apply_p2m_changes: Only load domain P2M when we flush TLBs
Quoted 7 lines · Julien Grall
apply_p2m_changesneeds to switch to another VTTBR temporarily to avoid flush every TLBs.As it's only needed there, we can restrict the scope where the VTTBR of this domain is loaded.
Signed-off-by Julien Grall <[email protected]>
Athough a flush_tlb_domain(d) type thing might be a nice addition.
Quoted 54 lines
---
Changes in v4:
- Patch added--- xen/arch/arm/p2m.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)xen/arch/arm/p2m.c +9
-10@@ -296,9 +296,6 @@ static int apply_p2m_changes(struct domain *d,spin_lock (&p2m->lock); -if ( d != current->domain ) -p2m_load_VTTBR (d); - addr = start_gpaddr;while ( addr < end_gpaddr ) {@@ -454,12 +451,17 @@ static int apply_p2m_changes(struct domain *d,if ( flush ) { -/* At the beginning of the function, Xen is updating VTTBR -* with the domain where the mappings are created. In this -* case it's only necessary to flush TLBs on every CPUs with -* the current VMID (our domain). +/* Update the VTTBR if necessary with the domain where mappings +* are created. In this case it's only necessary to flush TLBs +* on every CPUs with the current VMID (our domain). */ +if ( d != current->domain ) +p2m_load_VTTBR (d); +flush_tlb (); + +if ( d != current->domain ) +p2m_load_VTTBR (current->domain); }if ( op ==ALLOCATE || op ==INSERT )@@ -478,9 +480,6 @@ out:if (second)unmap_domain_page (second);if (first)unmap_domain_page (first); -if ( d != current->domain ) -p2m_load_VTTBR (current->domain); -spin_unlock (&p2m->lock);return rc;
Re: [PATCH v4 04/21] xen/arm: p2m: apply_p2m_changes: Only load domain P2M when we flush TLBs
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Julien Grall
apply_p2m_changesneeds to switch to another VTTBR temporarily to avoid flush every TLBs.
Quoted 8 lines
Quoted 4 lines
As it's only needed there, we can restrict the scope where the VTTBR of this domain is loaded.
Signed-off-by Julien Grall <[email protected]>Acked-by Ian Campbell <[email protected]>Athough a
flush_tlb_domain(d)type thing might be a nice addition.
I will add a flush_tlb_domain in the next version of this patch series.
Regards,
Signature · 1 line
Julien Grall
PATCH v4 5/21 xen/common: grant-table: only call IOMMU if paging mode translate is disabled
In reply to Julien GrallQuoted 1 line
From Xen point of view, ARM guests are PV guest with paging auto translate
enabled.
When IOMMU support will be added for ARM, mapping grant ref will always crash Xen due to the BUG_ON in __gnttab_map_grant_ref.
On x86:
- PV guests always have paging mode translate disabled
- PVH and HVM guests have always paging mode translate enabled
It means that we can safely replace the check that the domain is a PV guests by checking if the guest has paging mode translate enabled.
--- xen/common/grant_table.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
xen/common/grant_table.c +2 -5
@@ -721,12 +721,10 @@ __gnttab_map_grant_ref(double_gt_lock (lgt, rgt); -if (is_pv_domain (ld) &&need_iommu (ld) ) +if ( !paging_mode_translate (ld) &&need_iommu (ld) ) {unsigned int wrc, rdc;int err =0 ; -/* Shouldn't happen, because you can't use iommu in a HVM domain. */ -BUG_ON (paging_mode_translate (ld));/* We're not translated, so we know that gmfns and mfns are the same things, so the IOMMU entry is always 1-to-1. */ mapcount (lgt, rd, frame, &wrc, &rdc);
@@ -931,11 +929,10 @@ __gnttab_unmap_common( act->pin -= GNTPIN_hstw_inc; } -if (is_pv_domain (ld) &&need_iommu (ld) ) +if ( !paging_mode_translate (ld) &&need_iommu (ld) ) {unsigned int wrc, rdc;int err =0 ; -BUG_ON (paging_mode_translate (ld));mapcount (lgt, rd, op->frame, &wrc, &rdc);if ( (wrc + rdc) ==0 ) err =iommu_unmap_page (ld, op->frame);
Signature · 1 line
1.7.10.4
PATCH v4 6/21 xen/passthrough: amd: Remove domain_id from hvm_iommu
In reply to Julien GrallThe structure hvm_iommu contains a shadow value of domain->domain_id. There is no reason to not directly use domain->domain_id.
---
Changes in v3:
- Patch added
--- xen/drivers/passthrough/amd/iommu_cmd.c | 3 +-- xen/drivers/passthrough/amd/iommu_map.c | 2 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 8 +++----- xen/include/xen/hvm/iommu.h | 1 - 4 files changed, 5 insertions(+), 9 deletions(-)
xen/drivers/passthrough/amd/iommu_cmd.c +1 -2
@@ -354,8 +354,7 @@ static void _amd_iommu_flush_pages(struct domain *d, {unsigned long flags;struct amd_iommu *iommu; -struct hvm_iommu *hd =domain_hvm_iommu (d); -unsigned int dom_id = hd->domain_id; +unsigned int dom_id = d->domain_id;/* send INVALIDATE_IOMMU_PAGES command */ for_each_amd_iommu ( iommu )
xen/drivers/passthrough/amd/iommu_map.c +1 -1
@@ -614,7 +614,7 @@ static int update_paging_mode(struct domain *d, unsigned long gfn)/* valid = 0 only works for dom0 passthrough mode */ amd_iommu_set_root_page_table ((u32 *)device_entry,page_to_maddr (hd->root_table), - hd->domain_id, + d->domain_id, hd->paging_mode,1 );amd_iommu_flush_device (iommu, req_id);
xen/drivers/passthrough/amd/pci_amd_iommu.c +3 -5
@@ -138,7 +138,7 @@ static void amd_iommu_setup_domain_device( {/* bind DTE to domain page-tables */ amd_iommu_set_root_page_table ( - (u32 *)dte,page_to_maddr (hd->root_table), hd->domain_id, + (u32 *)dte,page_to_maddr (hd->root_table), domain->domain_id, hd->paging_mode, valid); if ( pci_ats_device(iommu->seg, bus, pdev->devfn) &&
@@ -152,7 +152,7 @@ static void amd_iommu_setup_domain_device("domain = %d, paging mode = %d\n" , req_id, pdev->type,page_to_maddr (hd->root_table), - hd->domain_id, hd->paging_mode); + domain->domain_id, hd->paging_mode); }spin_unlock_irqrestore (&iommu->lock, flags);
@@ -274,8 +274,6 @@ static int amd_iommu_domain_init(struct domain *d) IOMMU_PAGING_MODE_LEVEL_2 :get_paging_mode (max_page); - hd->domain_id = d->domain_id; -guest_iommu_init (d);return 0 ;
@@ -334,7 +332,7 @@ void amd_iommu_disable_domain_device(struct domain *domain,AMD_IOMMU_DEBUG ("Disable: device id = %#x, " "domain = %d, paging mode = %d\n" , - req_id,domain_hvm_iommu (domain)->domain_id, + req_id, domain->domain_id,domain_hvm_iommu (domain)->paging_mode); }spin_unlock_irqrestore (&iommu->lock, flags);
xen/include/xen/hvm/iommu.h +0 -1
@@ -38,7 +38,6 @@ struct hvm_iommu {struct list_head mapped_rmrrs;/* amd iommu support */ -int domain_id;int paging_mode;struct page_info *root_table;struct guest_iommu *g_iommu;
Signature · 1 line
1.7.10.4
Re: [PATCH v4 06/21] xen/passthrough: amd: Remove domain_id from hvm_iommu
Hello Sherry and Suravee,
Can one of you ack this change in the AMD IOMMU drivers?
Regards,
Quoted 98 lines · Julien Grall
The structure
hvm_iommucontains a shadow value ofdomain->domain_id. There is no reason to not directly usedomain->domain_id.Signed-off-by Julien Grall <[email protected]>Acked-by Ian Campbell <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Jan Beulich <[email protected]>---
Changes in v3:
- Patch added--- xen/drivers/passthrough/amd/iommu_cmd.c | 3 +-- xen/drivers/passthrough/amd/iommu_map.c | 2 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 8 +++----- xen/include/xen/hvm/iommu.h | 1 - 4 files changed, 5 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-2@@ -354,8 +354,7 @@ static void _amd_iommu_flush_pages(struct domain *d, {unsigned long flags;struct amd_iommu *iommu; -struct hvm_iommu *hd =domain_hvm_iommu (d); -unsigned int dom_id = hd->domain_id; +unsigned int dom_id = d->domain_id;/* send INVALIDATE_IOMMU_PAGES command */ for_each_amd_iommu ( iommu )xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -614,7 +614,7 @@ static int update_paging_mode(struct domain *d, unsigned long gfn)/* valid = 0 only works for dom0 passthrough mode */ amd_iommu_set_root_page_table ((u32 *)device_entry,page_to_maddr (hd->root_table), - hd->domain_id, + d->domain_id, hd->paging_mode,1 );amd_iommu_flush_device (iommu, req_id);xen/drivers/passthrough/amd/pci_amd_iommu.c +3
-5@@ -138,7 +138,7 @@ static void amd_iommu_setup_domain_device( {/* bind DTE to domain page-tables */ amd_iommu_set_root_page_table ( - (u32 *)dte,page_to_maddr (hd->root_table), hd->domain_id, + (u32 *)dte,page_to_maddr (hd->root_table), domain->domain_id, hd->paging_mode, valid); if ( pci_ats_device(iommu->seg, bus, pdev->devfn) &&@@ -152,7 +152,7 @@ static void amd_iommu_setup_domain_device("domain = %d, paging mode = %d\n" , req_id, pdev->type,page_to_maddr (hd->root_table), - hd->domain_id, hd->paging_mode); + domain->domain_id, hd->paging_mode); }spin_unlock_irqrestore (&iommu->lock, flags);@@ -274,8 +274,6 @@ static int amd_iommu_domain_init(struct domain *d) IOMMU_PAGING_MODE_LEVEL_2 :get_paging_mode (max_page); - hd->domain_id = d->domain_id; -guest_iommu_init (d);return 0 ;@@ -334,7 +332,7 @@ void amd_iommu_disable_domain_device(struct domain *domain,AMD_IOMMU_DEBUG ("Disable: device id = %#x, " "domain = %d, paging mode = %d\n" , - req_id,domain_hvm_iommu (domain)->domain_id, + req_id, domain->domain_id,domain_hvm_iommu (domain)->paging_mode); }spin_unlock_irqrestore (&iommu->lock, flags);xen/include/xen/hvm/iommu.h +0
-1@@ -38,7 +38,6 @@ struct hvm_iommu {struct list_head mapped_rmrrs;/* amd iommu support */ -int domain_id;int paging_mode;struct page_info *root_table;struct guest_iommu *g_iommu;
Signature · 1 line
Julien Grall
Re: [PATCH v4 06/21] xen/passthrough: amd: Remove domain_id from hvm_iommu
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 28.04.14 at 18:38, <[email protected]> wrote:
Hello Sherry and Suravee,
Can one of you ack this change in the AMD IOMMU drivers?
Sherry,
with Suravee having become pretty silent over the last couple of months, and Aravind having shown quite a bit of activity, would it be reasonable to add his as maintainer alongside (or, less ideal, in place of) Suravee for the AMD IOMMU code?
Thanks, Jan
Re: [PATCH v4 06/21] xen/passthrough: amd: Remove domain_id from hvm_iommu
Jan,
Sorry for have not been able to respond earlier. I have been occupied with other works during the past month. I've reviewed and test this patch. We are also planning to add Aravind along as maintainer. We will be sending out the patch for the MAINTAINERS file to include him.
Suravee
Quoted 14 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 28.04.14 at 18:38, <[email protected]> wrote:
Hello Sherry and Suravee,
Can one of you ack this change in the AMD IOMMU drivers?
Sherry,
with Suravee having become pretty silent over the last couple of months, and Aravind having shown quite a bit of activity, would it be reasonable to add his as maintainer alongside (or, less ideal, in place of) Suravee for the AMD IOMMU code?
Thanks, Jan
Re: [PATCH v4 06/21] xen/passthrough: amd: Remove domain_id from hvm_iommu
In reply to Julien GrallSorry for late reply. Reviewed and tested.
Suravee
Quoted 98 lines · Julien Grall
The structure
hvm_iommucontains a shadow value ofdomain->domain_id. There is no reason to not directly usedomain->domain_id.Signed-off-by Julien Grall <[email protected]>Acked-by Ian Campbell <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Jan Beulich <[email protected]>---
Changes in v3:
- Patch added--- xen/drivers/passthrough/amd/iommu_cmd.c | 3 +-- xen/drivers/passthrough/amd/iommu_map.c | 2 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 8 +++----- xen/include/xen/hvm/iommu.h | 1 - 4 files changed, 5 insertions(+), 9 deletions(-)xen/drivers/passthrough/amd/iommu_cmd.c +1
-2@@ -354,8 +354,7 @@ static void _amd_iommu_flush_pages(struct domain *d, {unsigned long flags;struct amd_iommu *iommu; -struct hvm_iommu *hd =domain_hvm_iommu (d); -unsigned int dom_id = hd->domain_id; +unsigned int dom_id = d->domain_id;/* send INVALIDATE_IOMMU_PAGES command */ for_each_amd_iommu ( iommu )xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -614,7 +614,7 @@ static int update_paging_mode(struct domain *d, unsigned long gfn)/* valid = 0 only works for dom0 passthrough mode */ amd_iommu_set_root_page_table ((u32 *)device_entry,page_to_maddr (hd->root_table), - hd->domain_id, + d->domain_id, hd->paging_mode,1 );amd_iommu_flush_device (iommu, req_id);xen/drivers/passthrough/amd/pci_amd_iommu.c +3
-5@@ -138,7 +138,7 @@ static void amd_iommu_setup_domain_device( {/* bind DTE to domain page-tables */ amd_iommu_set_root_page_table ( - (u32 *)dte,page_to_maddr (hd->root_table), hd->domain_id, + (u32 *)dte,page_to_maddr (hd->root_table), domain->domain_id, hd->paging_mode, valid); if ( pci_ats_device(iommu->seg, bus, pdev->devfn) &&@@ -152,7 +152,7 @@ static void amd_iommu_setup_domain_device("domain = %d, paging mode = %d\n" , req_id, pdev->type,page_to_maddr (hd->root_table), - hd->domain_id, hd->paging_mode); + domain->domain_id, hd->paging_mode); }spin_unlock_irqrestore (&iommu->lock, flags);@@ -274,8 +274,6 @@ static int amd_iommu_domain_init(struct domain *d) IOMMU_PAGING_MODE_LEVEL_2 :get_paging_mode (max_page); - hd->domain_id = d->domain_id; -guest_iommu_init (d);return 0 ;@@ -334,7 +332,7 @@ void amd_iommu_disable_domain_device(struct domain *domain,AMD_IOMMU_DEBUG ("Disable: device id = %#x, " "domain = %d, paging mode = %d\n" , - req_id,domain_hvm_iommu (domain)->domain_id, + req_id, domain->domain_id,domain_hvm_iommu (domain)->paging_mode); }spin_unlock_irqrestore (&iommu->lock, flags);xen/include/xen/hvm/iommu.h +0
-1@@ -38,7 +38,6 @@ struct hvm_iommu {struct list_head mapped_rmrrs;/* amd iommu support */ -int domain_id;int paging_mode;struct page_info *root_table;struct guest_iommu *g_iommu;
Re: [PATCH v4 06/21] xen/passthrough: amd: Remove domain_id from hvm_iommu
Hi Suravee,
Quoted 3 lines · Suravee Suthikulpanit
Sorry for late reply. Reviewed and tested.
Thank you for your ack.
Can you also ack patch #7 and #13? (There is some modifications for the AMD iommu).
Regards,
Signature · 1 line
Julien Grall
PATCH v4 7/21 xen/passthrough: amd: rename iommu_has_feature into amd_iommu_has_feature
In reply to Julien GrallThis function is AMD specific and the name will clash with a newly function added in the IOMMU framework.
--- xen/drivers/passthrough/amd/iommu_detect.c | 2 +- xen/drivers/passthrough/amd/iommu_init.c | 16 ++++++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)
xen/drivers/passthrough/amd/iommu_detect.c +1 -1
@@ -95,7 +95,7 @@ void __init get_iommu_features(struct amd_iommu *iommu)while ( feature_str[i] ) { -if (iommu_has_feature (iommu, i) ) +if (amd_iommu_has_feature (iommu, i) )printk (" %s\n" , feature_str[i]); i++; }
xen/drivers/passthrough/amd/iommu_init.c +8 -8
@@ -884,7 +884,7 @@ static void enable_iommu(struct amd_iommu *iommu)register_iommu_event_log_in_mmio_space (iommu);register_iommu_exclusion_range (iommu); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )register_iommu_ppr_log_in_mmio_space (iommu); desc =irq_to_desc (iommu->msi.irq);
@@ -898,15 +898,15 @@ static void enable_iommu(struct amd_iommu *iommu)set_iommu_command_buffer_control (iommu,IOMMU_CONTROL_ENABLED );set_iommu_event_log_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )set_iommu_ppr_log_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) )set_iommu_guest_translation_control (iommu,IOMMU_CONTROL_ENABLED );set_iommu_translation_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) )amd_iommu_flush_all_caches (iommu); iommu->enabled =1 ;
@@ -1009,7 +1009,7 @@ static int __init amd_iommu_init_one(struct amd_iommu *iommu)if (allocate_event_log (iommu) ==NULL ) goto error_out; -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )if (allocate_ppr_log (iommu) ==NULL ) goto error_out;
@@ -1283,10 +1283,10 @@ static void disable_iommu(struct amd_iommu *iommu)set_iommu_command_buffer_control (iommu,IOMMU_CONTROL_DISABLED );set_iommu_event_log_control (iommu,IOMMU_CONTROL_DISABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )set_iommu_ppr_log_control (iommu,IOMMU_CONTROL_DISABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) )set_iommu_guest_translation_control (iommu,IOMMU_CONTROL_DISABLED );set_iommu_translation_control (iommu,IOMMU_CONTROL_DISABLED );
@@ -1356,7 +1356,7 @@ void amd_iommu_resume(void) }/* flush all cache entries after iommu re-enabled */ -if ( !iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) +if ( !amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) {invalidate_all_devices ();invalidate_all_domain_pages ();
xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +1 -1
@@ -210,7 +210,7 @@ static inline int iommu_has_cap(struct amd_iommu *iommu, uint32_t bit)return !!(iommu->cap.header & (1u << bit)); } -static inline int iommu_has_feature (struct amd_iommu *iommu,uint32_t bit) +static inline int amd_iommu_has_feature (struct amd_iommu *iommu,uint32_t bit) {if ( !iommu_has_cap (iommu,PCI_CAP_EFRSUP_SHIFT ) )return 0 ;
Signature · 1 line
1.7.10.4
Re: [PATCH v4 07/21] xen/passthrough: amd: rename iommu_has_feature into amd_iommu_has_feature
Quoted 6 lines · Julien Grall
This function is AMD specific and the name will clash with a newly function added in the IOMMU framework.
Signed-off-by Julien Grall <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Jan Beulich <[email protected]>
Seems reasonable to me FWIW
Re: [PATCH v4 07/21] xen/passthrough: amd: rename iommu_has_feature into amd_iommu_has_feature
In reply to Julien GrallHello Sherry and Suravee,
Can one of you ack this change in the AMD IOMMU drivers?
Regards,
Quoted 102 lines · Julien Grall
This function is AMD specific and the name will clash with a newly function added in the IOMMU framework.
Signed-off-by Julien Grall <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/amd/iommu_detect.c | 2 +- xen/drivers/passthrough/amd/iommu_init.c | 16 ++++++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)xen/drivers/passthrough/amd/iommu_detect.c +1
-1@@ -95,7 +95,7 @@ void __init get_iommu_features(struct amd_iommu *iommu)while ( feature_str[i] ) { -if (iommu_has_feature (iommu, i) ) +if (amd_iommu_has_feature (iommu, i) )printk (" %s\n" , feature_str[i]); i++; }xen/drivers/passthrough/amd/iommu_init.c +8
-8@@ -884,7 +884,7 @@ static void enable_iommu(struct amd_iommu *iommu)register_iommu_event_log_in_mmio_space (iommu);register_iommu_exclusion_range (iommu); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )register_iommu_ppr_log_in_mmio_space (iommu); desc =irq_to_desc (iommu->msi.irq);@@ -898,15 +898,15 @@ static void enable_iommu(struct amd_iommu *iommu)set_iommu_command_buffer_control (iommu,IOMMU_CONTROL_ENABLED );set_iommu_event_log_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )set_iommu_ppr_log_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) )set_iommu_guest_translation_control (iommu,IOMMU_CONTROL_ENABLED );set_iommu_translation_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) )amd_iommu_flush_all_caches (iommu); iommu->enabled =1 ;@@ -1009,7 +1009,7 @@ static int __init amd_iommu_init_one(struct amd_iommu *iommu)if (allocate_event_log (iommu) ==NULL ) goto error_out; -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )if (allocate_ppr_log (iommu) ==NULL ) goto error_out;@@ -1283,10 +1283,10 @@ static void disable_iommu(struct amd_iommu *iommu)set_iommu_command_buffer_control (iommu,IOMMU_CONTROL_DISABLED );set_iommu_event_log_control (iommu,IOMMU_CONTROL_DISABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )set_iommu_ppr_log_control (iommu,IOMMU_CONTROL_DISABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) )set_iommu_guest_translation_control (iommu,IOMMU_CONTROL_DISABLED );set_iommu_translation_control (iommu,IOMMU_CONTROL_DISABLED );@@ -1356,7 +1356,7 @@ void amd_iommu_resume(void) }/* flush all cache entries after iommu re-enabled */ -if ( !iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) +if ( !amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) {invalidate_all_devices ();invalidate_all_domain_pages ();xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +1
-1@@ -210,7 +210,7 @@ static inline int iommu_has_cap(struct amd_iommu *iommu, uint32_t bit)return !!(iommu->cap.header & (1u << bit)); } -static inline int iommu_has_feature (struct amd_iommu *iommu,uint32_t bit) +static inline int amd_iommu_has_feature (struct amd_iommu *iommu,uint32_t bit) {if ( !iommu_has_cap (iommu,PCI_CAP_EFRSUP_SHIFT ) )return 0 ;
Signature · 1 line
Julien Grall
Re: [PATCH v4 07/21] xen/passthrough: amd: rename iommu_has_feature into amd_iommu_has_feature
(Adding Aravind)
Ping?
Quoted 111 lines · Julien Grall
Hello Sherry and Suravee,
Can one of you ack this change in the AMD IOMMU drivers?
Regards,
Quoted 102 lines · Julien Grall
This function is AMD specific and the name will clash with a newly function added in the IOMMU framework.
Signed-off-by Julien Grall <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/amd/iommu_detect.c | 2 +- xen/drivers/passthrough/amd/iommu_init.c | 16 ++++++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)xen/drivers/passthrough/amd/iommu_detect.c +1
-1@@ -95,7 +95,7 @@ void __init get_iommu_features(struct amd_iommu *iommu)while ( feature_str[i] ) { -if (iommu_has_feature (iommu, i) ) +if (amd_iommu_has_feature (iommu, i) )printk (" %s\n" , feature_str[i]); i++; }xen/drivers/passthrough/amd/iommu_init.c +8
-8@@ -884,7 +884,7 @@ static void enable_iommu(struct amd_iommu *iommu)register_iommu_event_log_in_mmio_space (iommu);register_iommu_exclusion_range (iommu); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )register_iommu_ppr_log_in_mmio_space (iommu); desc =irq_to_desc (iommu->msi.irq);@@ -898,15 +898,15 @@ static void enable_iommu(struct amd_iommu *iommu)set_iommu_command_buffer_control (iommu,IOMMU_CONTROL_ENABLED );set_iommu_event_log_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )set_iommu_ppr_log_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) )set_iommu_guest_translation_control (iommu,IOMMU_CONTROL_ENABLED );set_iommu_translation_control (iommu,IOMMU_CONTROL_ENABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) )amd_iommu_flush_all_caches (iommu); iommu->enabled =1 ;@@ -1009,7 +1009,7 @@ static int __init amd_iommu_init_one(struct amd_iommu *iommu)if (allocate_event_log (iommu) ==NULL ) goto error_out; -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )if (allocate_ppr_log (iommu) ==NULL ) goto error_out;@@ -1283,10 +1283,10 @@ static void disable_iommu(struct amd_iommu *iommu)set_iommu_command_buffer_control (iommu,IOMMU_CONTROL_DISABLED );set_iommu_event_log_control (iommu,IOMMU_CONTROL_DISABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_PPRSUP_SHIFT ) )set_iommu_ppr_log_control (iommu,IOMMU_CONTROL_DISABLED ); -if (iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) ) +if (amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_GTSUP_SHIFT ) )set_iommu_guest_translation_control (iommu,IOMMU_CONTROL_DISABLED );set_iommu_translation_control (iommu,IOMMU_CONTROL_DISABLED );@@ -1356,7 +1356,7 @@ void amd_iommu_resume(void) }/* flush all cache entries after iommu re-enabled */ -if ( !iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) +if ( !amd_iommu_has_feature (iommu,IOMMU_EXT_FEATURE_IASUP_SHIFT ) ) {invalidate_all_devices ();invalidate_all_domain_pages ();xen/include/asm-x86/hvm/svm/amd-iommu-proto.h +1
-1@@ -210,7 +210,7 @@ static inline int iommu_has_cap(struct amd_iommu *iommu, uint32_t bit)return !!(iommu->cap.header & (1u << bit)); } -static inline int iommu_has_feature (struct amd_iommu *iommu,uint32_t bit) +static inline int amd_iommu_has_feature (struct amd_iommu *iommu,uint32_t bit) {if ( !iommu_has_cap (iommu,PCI_CAP_EFRSUP_SHIFT ) )return 0 ;
Signature · 1 line
Julien Grall
Aravind Gopalakrishnan
Acked-byRe: [PATCH v4 07/21] xen/passthrough: amd: rename iommu_has_feature into amd_iommu_has_feature
Quoted 25 lines · Julien Grall
(Adding Aravind)
Ping?
Quoted 20 lines · Julien Grall
Hello Sherry and Suravee,
Can one of you ack this change in the AMD IOMMU drivers?
Regards,
Quoted 13 lines · Julien Grall
This function is AMD specific and the name will clash with a newly function added in the IOMMU framework.
Signed-off-by Julien Grall <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/amd/iommu_detect.c | 2 +- xen/drivers/passthrough/amd/iommu_init.c | 16 ++++++++-------- xen/include/asm-x86/hvm/svm/amd-iommu-proto.h | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-)
Thanks,
-Aravind.
PATCH v4 8/21 xen/passthrough: vtd: iommu_set_hwdom_mapping is VTD specific
In reply to Julien GrallThis function was exported in common header. Rename it and move the declaration in drivers/passtrough/vtd/extern.h
---
Changes in v4:
- Patch added
--- xen/drivers/passthrough/vtd/extern.h | 2 ++ xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/drivers/passthrough/vtd/x86/vtd.c | 2 +- xen/include/xen/iommu.h | 1 - 4 files changed, 4 insertions(+), 3 deletions(-)
xen/drivers/passthrough/vtd/extern.h +2 -0
@@ -103,4 +103,6 @@ void pci_vtd_quirk(struct pci_dev *pdev);int platform_supports_intremap (void );int platform_supports_x2apic (void ); +void iommu_vtd_set_hwdom_mapping (struct domain *d); +#endif // _VTD_EXTERN_H_
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -1249,7 +1249,7 @@ static void __hwdom_init intel_iommu_hwdom_init(struct domain *d)if ( !iommu_passthrough && !need_iommu (d) ) {/* Set up 1:1 page table for dom0 */ -iommu_set_hwdom_mapping (d); +iommu_vtd_set_hwdom_mapping (d); }setup_hwdom_pci_devices (d, setup_hwdom_device);
xen/drivers/passthrough/vtd/x86/vtd.c +1 -1
@@ -107,7 +107,7 @@ void hvm_dpci_isairq_eoi(struct domain *d, unsigned int isairq)spin_unlock (&d->event_lock); } -void __hwdom_init iommu_set_hwdom_mapping(struct domain *d) +void __hwdom_init iommu_vtd_set_hwdom_mapping(struct domain *d) {unsigned long i, j, tmp, top;
xen/include/xen/iommu.h +0 -1
@@ -127,7 +127,6 @@ void iommu_suspend(void);void iommu_resume (void );void iommu_crash_shutdown (void ); -void iommu_set_hwdom_mapping (struct domain *d);void iommu_share_p2m_table (struct domain *d); int iommu_do_domctl(struct xen_domctl *, struct domain *d,
Signature · 1 line
1.7.10.4
Re: [PATCH v4 08/21] xen/passthrough: vtd: iommu_set_hwdom_mapping is VTD specific
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
This function was exported in common header. Rename it and move the declaration
indrivers/passtrough/vtd/extern.hSigned-off-by Julien Grall <[email protected]>
albeit if you need to do another iteration ...
xen/drivers/passthrough/vtd/extern.h void pci_vtd_quirk(struct pci_dev *pdev); · line 106
Quoted 7 lines
xen/drivers/passthrough/vtd/extern.h +1
-0@@ -103,4 +103,6 @@ void pci_vtd_quirk(struct pci_dev *pdev);int platform_supports_intremap (void );int platform_supports_x2apic (void ); +void iommu_vtd_set_hwdom_mapping (struct domain *d);
... I'd be happier if you used only one prefix, i.e. vtd_ in this case.
Jan
Re: [PATCH v4 08/21] xen/passthrough: vtd: iommu_set_hwdom_mapping is VTD specific
Hi Jan,
Quoted 10 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
This function was exported in common header. Rename it and move the declaration
indrivers/passtrough/vtd/extern.hSigned-off-by Julien Grall <[email protected]>Reviewed-by Jan Beulich <[email protected]>albeit if you need to do another iteration ...
I believe I will have to do at least another iteration. I will fix it in my branch just in case.
Regards,
Signature · 1 line
Julien Grall
PATCH v4 9/21 xen/dts: Add dt_property_read_bool
In reply to Julien GrallThe function check if a property exists in a specific node.
---
Changes in v2:
- Fix typo in commit message
--- xen/common/device_tree.c | 6 ++---- xen/include/xen/device_tree.h | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-)
xen/common/device_tree.c +2 -4
@@ -512,10 +512,8 @@ static void __init *unflatten_dt_alloc(unsigned long *mem, unsigned long size, }/* Find a property with a given name for a given node and return it. */ -static const struct dt_property * -dt_find_property (const struct dt_device_node *np, -const char *name, -u32 *lenp) +const struct dt_property *dt_find_property (const struct dt_device_node *np, +const char *name,u32 *lenp) {const struct dt_property *pp;
xen/include/xen/device_tree.h +21 -0
@@ -15,6 +15,7 @@#include <xen/init.h> #include <xen/string.h> #include <xen/types.h> +#include <xen/stdbool.h> #define DEVICE_TREE_MAX_DEPTH 16
@@ -348,6 +349,10 @@ struct dt_device_node *dt_find_compatible_node(struct dt_device_node *from,const void *dt_get_property (const struct dt_device_node *np,const char *name,u32 *lenp); +const struct dt_property *dt_find_property (const struct dt_device_node *np, +const char *name,u32 *lenp); + +/** * dt_property_read_u32 - Helper to read a u32 property. * @np: node to get the value
@@ -370,6 +375,22 @@ bool_t dt_property_read_u64(const struct dt_device_node *np, const char *name, u64 *out_value);/** +* dt_property_read_bool - Check if a property exists +* @np: node to get the value +* @name: name of the property +* +* Search for a property in a device node. +* Return true if the property exists false otherwise. +*/ +static inline bool_t dt_property_read_bool (const struct dt_device_node *np, +const char *name) +{ +const struct dt_property *prop =dt_find_property (np, name,NULL ); + +return prop ? true : false; +} + +/** * dt_property_read_string - Find and read a string from a property * @np: Device node from which the property value is to be read * @propname: Name of the property to be searched
Signature · 1 line
1.7.10.4
PATCH v4 10/21 xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle
In reply to Julien GrallCode adapted from linux drivers/of/base.c (commit ef42c58).
---
Changes in v4:
- Replace dt_printk by printk
Changes in v2:
- Remove hard tabs in dt_parse_phandle
--- xen/common/device_tree.c | 151 ++++++++++++++++++++++++++++++++++++++++- xen/include/xen/device_tree.h | 54 +++++++++++++++ 2 files changed, 203 insertions(+), 2 deletions(-)
xen/common/device_tree.c +149 -2
@@ -1090,9 +1090,9 @@ int dt_device_get_address(const struct dt_device_node *dev, int index,* * Returns a node pointer. */ -static const struct dt_device_node *dt_find_node_by_phandle (dt_phandle handle) +static struct dt_device_node *dt_find_node_by_phandle (dt_phandle handle) { -const struct dt_device_node *np; +struct dt_device_node *np;dt_for_each_device_node (dt_host, np)if ( np->phandle == handle )
@@ -1477,6 +1477,153 @@ bool_t dt_device_is_available(const struct dt_device_node *device)return 0 ; } +static int __dt_parse_phandle_with_args (const struct dt_device_node *np, +const char *list_name, +const char *cells_name, +int cell_count,int index, +struct dt_phandle_args *out_args) +{ +const __be32 *list, *list_end; +int rc =0 , cur_index =0 ; +u32 size, count =0 ; +struct dt_device_node *node =NULL ; +dt_phandle phandle; + +/* Retrieve the phandle list property */ + list =dt_get_property (np, list_name, &size); +if ( !list ) +return -ENOENT ; + list_end = list + size /sizeof (*list); + +/* Loop over the phandles until all the requested entry is found */ +while ( list < list_end ) + { + rc = -EINVAL ; + count =0 ; + +/* +* If phandle is 0, then it is an empty entry with no +* arguments. Skip forward to the next entry. +* */ + phandle =be32_to_cpup (list++); +if ( phandle ) + { +/* +* Find the provider node and parse the #*-cells +* property to determine the argument length. +* +* This is not needed if the cell count is hard-coded +* (i.e. cells_name not set, but cell_count is set), +* except when we're going to return the found node +* below. +*/ +if ( cells_name || cur_index == index ) + { + node =dt_find_node_by_phandle (phandle); +if ( !node ) + { +printk (XENLOG_ERR "%s: could not find phandle\n" , + np->full_name); + goto err; + } + } + +if ( cells_name ) + { +if ( !dt_property_read_u32 (node, cells_name, &count) ) + { +printk ("%s: could not get %s for %s\n" , + np->full_name, cells_name, node->full_name); + goto err; + } + } +else + count = cell_count; + +/* +* Make sure that the arguments actually fit in the +* remaining property data length +*/ +if ( list + count > list_end ) + { +printk (XENLOG_ERR "%s: arguments longer than property\n" , + np->full_name); + goto err; + } + } + +/* +* All of the error cases above bail out of the loop, so at +* this point, the parsing is successful. If the requested +* index matches, then fill the out_args structure and return, +* or return -ENOENT for an empty entry. +*/ + rc = -ENOENT ; +if ( cur_index == index ) + { +if (!phandle) + goto err; + +if ( out_args ) + { +int i; + +WARN_ON (count >MAX_PHANDLE_ARGS ); +if (count >MAX_PHANDLE_ARGS ) + count =MAX_PHANDLE_ARGS ; + out_args->np = node; + out_args->args_count = count; +for ( i =0 ; i < count; i++ ) + out_args->args[i] =be32_to_cpup (list++); + } + +/* Found it! return success */ +return 0 ; + } + + node =NULL ; + list += count; + cur_index++; + } + +/* +* Returning result will be one of: +* -ENOENT : index is for empty phandle +* -EINVAL : parsing error on data +* [1..n] : Number of phandle (count mode; when index = -1) +*/ + rc = index <0 ? cur_index : -ENOENT ; +err: +return rc; +} + +struct dt_device_node *dt_parse_phandle (const struct dt_device_node *np, +const char *phandle_name,int index) +{ +struct dt_phandle_args args; + +if (index <0 ) +return NULL ; + +if (__dt_parse_phandle_with_args (np, phandle_name,NULL ,0 , + index, &args)) +return NULL ; + +return args.np; +} + + +int dt_parse_phandle_with_args (const struct dt_device_node *np, +const char *list_name, +const char *cells_name,int index, +struct dt_phandle_args *out_args) +{ +if ( index <0 ) +return -EINVAL ; +return __dt_parse_phandle_with_args (np, list_name, cells_name,0 , + index, out_args); +} +/** * unflatten_dt_node - Alloc and populate a device_node from the flat tree * @fdt: The parent device tree blob
xen/include/xen/device_tree.h +54 -0
66 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v4 11/21 xen/passthrough: rework hwdom_pvh_reqs to use it also on ARM
In reply to Julien GrallHardware domain on ARM will have the same requirements as hwdom PVH when iommu is enabled. Both PVH and ARM guest has paging mode translate enabled, so Xen can use it to know if it needs to check the requirements.
Rename the function and remove "pvh" word in the panic message.
---
Changes in v4:
- Rebase on the latest staging (hwdom series was pushed)
- Remove is_phv_domain bits ... and update the next patch
(should be #7) to create in new function arch_iommu_check_dom0_reqs.
- Update printed message to be more readable
Changes in v2:
- IOMMU can be disabled on ARM if the platform doesn't have IOMMU.
--- xen/drivers/passthrough/iommu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
xen/drivers/passthrough/iommu.c +7 -4
@@ -130,13 +130,17 @@ int iommu_domain_init(struct domain *d)return hd->platform_ops->init (d); } -static void __hwdom_init check_hwdom_pvh_reqs(struct domain *d) +static void __hwdom_init check_hwdom_reqs(struct domain *d) { +if ( !paging_mode_translate (d) ) +return ; +if ( !iommu_enabled )panic ("Presently, iommu must be enabled for pvh dom0\n" );if ( iommu_passthrough ) -panic ("For pvh dom0, dom0-passthrough must not be enabled\n" ); +panic ("Dom0 uses paging translated mode, dom0-passthrough must not be " +"enabled\n" ); iommu_dom0_strict =1 ; }
@@ -145,8 +149,7 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); -if (is_pvh_domain (d) ) -check_hwdom_pvh_reqs (d); +check_hwdom_reqs (d);if ( !iommu_enabled )return ;
Signature · 1 line
1.7.10.4
Re: [PATCH v4 11/21] xen/passthrough: rework hwdom_pvh_reqs to use it also on ARM
Quoted 9 lines · Julien Grall
Hardware domain on ARM will have the same requirements as hwdom PVH when iommu is enabled. Both PVH and ARM guest has paging mode translate enabled, so Xen can use it to know if it needs to check the requirements.
Rename the function and remove "pvh" word in the panic message.
Signed-off-by Julien Grall <[email protected]>Acked-by Jan Beulich <[email protected]>Cc Xiantao Zhang <[email protected]>
Quoted 48 lines
---
Changes in v4:
- Rebase on the latest staging (hwdom series was pushed)
- Removeis_phv_domainbits ... and update the next patch
(should be #7) to create in new functionarch_iommu_check_dom0_reqs.
- Update printed message to be more readable
Changes in v2:
- IOMMU can be disabled on ARM if the platform doesn't have IOMMU.--- xen/drivers/passthrough/iommu.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)xen/drivers/passthrough/iommu.c +7
-4@@ -130,13 +130,17 @@ int iommu_domain_init(struct domain *d)return hd->platform_ops->init (d); } -static void __hwdom_init check_hwdom_pvh_reqs(struct domain *d) +static void __hwdom_init check_hwdom_reqs(struct domain *d) { +if ( !paging_mode_translate (d) ) +return ; +if ( !iommu_enabled )panic ("Presently, iommu must be enabled for pvh dom0\n" );if ( iommu_passthrough ) -panic ("For pvh dom0, dom0-passthrough must not be enabled\n" ); +panic ("Dom0 uses paging translated mode, dom0-passthrough must not be " +"enabled\n" ); iommu_dom0_strict =1 ; }@@ -145,8 +149,7 @@ void __hwdom_init iommu_hwdom_init(struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); -if (is_pvh_domain (d) ) -check_hwdom_pvh_reqs (d); +check_hwdom_reqs (d);if ( !iommu_enabled )return ;
PATCH v4 12/21 xen/passthrough: iommu: Split generic IOMMU code
In reply to Julien GrallThe generic IOMMU framework code (xen/drivers/passthrough/iommu.c) contains functions specific to x86 and PCI.
Split the framework in 3 distincts files:
- iommu.c: contains generic functions shared between x86 and ARM (when it will be supported)
- pci.c: contains specific functions for PCI passthrough
- x86/iommu.c: contains specific functions for x86
io.c contains x86 HVM specific code. Only compile for x86.
This patch is mostly code movement in new files.
---
Changes in v4:
- Rebase on the latest xen (hwdom series was pushed)
- Move iommu_populate_page_table in x86/iommu.c and rename it arch_iommu_populate_page_table
- Introduce arch_iommu_check_hwdom_reqs which will check if the IOMMU is enabled. On ARM the IOMMU is not required because most of current hardware don't provide IOMMU
- iommu_set_hwdom_mapping has been moved in vdt/extern.h (made by another patch)
Changes in v3:
- share_p2m_table should stay in common code
- update_ire_from_msi and read_msi_from_ire should go in pci code
- remove switch case in iommu_do_domctl
Changes in v2:
- Update commit message
- Removing spurious change in drivers/passthrough/vtd/iommu.c
- Move iommu_x86.c in x86/iommu.c
- Merge iommu_pci.c in pci.c
- Introduce iommu_do_pci_domctl
--- xen/drivers/passthrough/Makefile | 4 +- xen/drivers/passthrough/iommu.c | 486 ++-------------------------------- xen/drivers/passthrough/pci.c | 387 +++++++++++++++++++++++++++ xen/drivers/passthrough/x86/Makefile | 1 + xen/drivers/passthrough/x86/iommu.c | 120 +++++++++ xen/include/asm-x86/iommu.h | 41 +++ xen/include/xen/hvm/iommu.h | 1 + xen/include/xen/iommu.h | 51 ++-- 8 files changed, 596 insertions(+), 495 deletions(-) create mode 100644 xen/drivers/passthrough/x86/iommu.c create mode 100644 xen/include/asm-x86/iommu.h
xen/drivers/passthrough/Makefile +2 -2
@@ -3,5 +3,5 @@ subdir-$(x86) += amd subdir-$(x86_64) += x86 obj-y += iommu.o -obj-y += io.o -obj-y += pci.o +obj-$(x86) += io.o +obj-$(HAS_PCI) += pci.o
xen/drivers/passthrough/iommu.c +15 -471
536 lines not on this page · raw message
xen/drivers/passthrough/pci.c +387 -0
399 lines not on this page · raw message
xen/drivers/passthrough/x86/Makefile +1 -0
@@ -1 +1,2 @@ obj-y += ats.o +obj-y += iommu.o
xen/drivers/passthrough/x86/iommu.c new file +120 -0
120 lines not on this page · raw message
xen/include/asm-x86/iommu.h new file +41 -0
41 lines not on this page · raw message
xen/include/xen/hvm/iommu.h +1 -0
@@ -21,6 +21,7 @@#define __XEN_HVM_IOMMU_H__#include <xen/iommu.h> +#include <asm/hvm/iommu.h> struct g2m_ioport {struct list_head list;
xen/include/xen/iommu.h +29 -22
125 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
The generic IOMMU framework code (
xen/drivers/passthrough/iommu.c) contains functions specific to x86 and PCI.Split the framework in 3 distincts files:
-iommu.c: contains generic functions shared between x86 and ARM (when it will be supported)
-pci.c: contains specific functions for PCI passthrough
-x86/iommu.c: contains specific functions for x86
Quoted 5 lines
io.ccontains x86 HVM specific code. Only compile for x86.This patch is mostly code movement in new files.
Signed-off-by Julien Grall <[email protected]>
if one minor inconsistency gets addressed:
xen/drivers/passthrough/x86/iommu.c line 111
Quoted 5 lines
xen/drivers/passthrough/x86/iommu.c new file +5
-0+void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d) +{ +if ( !iommu_enabled ) +panic ("Presently, iommu must be enabled for pvh dom0\n" ); +}
Message text (containing PVH) and function name (not containing PVH) don't fit together, nor does the conditional really establish a connection.
Jan
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
Quoted 11 lines
Quoted 11 lines
Quoted 2 lines · On 22.04.14 at 15:48, <[email protected]> wrote:
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
The generic IOMMU framework code (
xen/drivers/passthrough/iommu.c) contains functions specific to x86 and PCI.Split the framework in 3 distincts files:
-iommu.c: contains generic functions shared between x86 and ARM (when it will be supported)
-pci.c: contains specific functions for PCI passthrough
-x86/iommu.c: contains specific functions for x86
Quoted 8 lines
Quoted 5 lines
io.ccontains x86 HVM specific code. Only compile for x86.This patch is mostly code movement in new files.
Signed-off-by Julien Grall <[email protected]>Acked-by Jan Beulich <[email protected]>if one minor inconsistency gets addressed:
Plus of course assuming that this really is only code movement, i.e. no other non-formatting changes.
Jan
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
In reply to Jan BeulichHi Jan,
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
The generic IOMMU framework code (
xen/drivers/passthrough/iommu.c) contains functions specific to x86 and PCI.Split the framework in 3 distincts files:
-iommu.c: contains generic functions shared between x86 and ARM (when it will be supported)
-pci.c: contains specific functions for PCI passthrough
-x86/iommu.c: contains specific functions for x86
Quoted 7 lines
Quoted 5 lines
io.ccontains x86 HVM specific code. Only compile for x86.This patch is mostly code movement in new files.
Signed-off-by Julien Grall <[email protected]>Acked-by Jan Beulich <[email protected]>
Thanks. To answer to your other mail, I didn't modify the behavior of the functions, only split them.
Quoted 11 lines
if one minor inconsistency gets addressed:
xen/drivers/passthrough/x86/iommu.c line 111
Quoted 5 lines
xen/drivers/passthrough/x86/iommu.c new file +5
-0+void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d) +{ +if ( !iommu_enabled ) +panic ("Presently, iommu must be enabled for pvh dom0\n" ); +}Message text (containing PVH) and function name (not containing PVH) don't fit together, nor does the conditional really establish a connection.
Do you prefer a comment, or an explicit check to is_pvh_domain(d)?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
Quoted 11 lines
Quoted 10 lines
xen/drivers/passthrough/x86/iommu.c line 111
Quoted 6 lines · On 22.04.14 at 16:58, <[email protected]> wrote:
xen/drivers/passthrough/x86/iommu.c new file +5
-0+void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d) +{ +if ( !iommu_enabled ) +panic ("Presently, iommu must be enabled for pvh dom0\n" ); +}Message text (containing PVH) and function name (not containing PVH) don't fit together, nor does the conditional really establish a connection.
Quoted 1 line
Do you prefer a comment, or an explicit check to
is_pvh_domain(d)?
That depends on where it would go: If the caller checks for PVH, then the function name should change. If the caller doesn't, then I don't see how you'd avoid getting here for non-PVH.
Jan
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 10 lines
xen/drivers/passthrough/x86/iommu.c line 111
Quoted 6 lines · On 22.04.14 at 16:58, <[email protected]> wrote:
xen/drivers/passthrough/x86/iommu.c new file +5
-0+void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d) +{ +if ( !iommu_enabled ) +panic ("Presently, iommu must be enabled for pvh dom0\n" ); +}Message text (containing PVH) and function name (not containing PVH) don't fit together, nor does the conditional really establish a connection.
Quoted 5 lines
Quoted 1 line
Do you prefer a comment, or an explicit check to
is_pvh_domain(d)?That depends on where it would go: If the caller checks for PVH, then the function name should change. If the caller doesn't, then I don't see how you'd avoid getting here for non-PVH.
The caller will go there when the DOM0 is auto-translated (i.e PVH as dom0 can't be an HVM).
I can remove PVH from the log, but for the user it's not accurate.
Signature · 1 line
Julien Grall
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 18:45, <[email protected]> wrote:
Quoted 13 lines · Jan Beulich
Quoted 12 lines
Quoted 10 lines
xen/drivers/passthrough/x86/iommu.c line 111
Quoted 6 lines · On 22.04.14 at 16:58, <[email protected]> wrote:
xen/drivers/passthrough/x86/iommu.c new file +5
-0+void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d) +{ +if ( !iommu_enabled ) +panic ("Presently, iommu must be enabled for pvh dom0\n" ); +}Message text (containing PVH) and function name (not containing PVH) don't fit together, nor does the conditional really establish a connection.
Do you prefer a comment, or an explicit check to
is_pvh_domain(d)?
Quoted 8 lines
Quoted 3 lines
That depends on where it would go: If the caller checks for PVH, then the function name should change. If the caller doesn't, then I don't see how you'd avoid getting here for non-PVH.
The caller will go there when the DOM0 is auto-translated (i.e PVH as dom0 can't be an HVM).
I can remove PVH from the log, but for the user it's not accurate.
In which case the function name should reflect this.
Jan
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 18:45, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 11 lines
Quoted 10 lines
xen/drivers/passthrough/x86/iommu.c line 111
Quoted 6 lines · On 22.04.14 at 16:58, <[email protected]> wrote:
xen/drivers/passthrough/x86/iommu.c new file +5
-0+void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d) +{ +if ( !iommu_enabled ) +panic ("Presently, iommu must be enabled for pvh dom0\n" ); +}Message text (containing PVH) and function name (not containing PVH) don't fit together, nor does the conditional really establish a connection.
Quoted 1 line
Do you prefer a comment, or an explicit check to
is_pvh_domain(d)?That depends on where it would go: If the caller checks for PVH, then the function name should change. If the caller doesn't, then I don't see how you'd avoid getting here for non-PVH.
Quoted 6 lines
Quoted 4 lines
The caller will go there when the DOM0 is auto-translated (i.e PVH as dom0 can't be an HVM).
I can remove PVH from the log, but for the user it's not accurate.
In which case the function name should reflect this.
What about arch_iommu_check_autotranslate_hwdom_reqs?
Signature · 1 line
Julien Grall
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 20:02, <[email protected]> wrote:
Quoted 19 lines · Jan Beulich
Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 18:45, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 11 lines
Quoted 10 lines
Review
Quoted 6 lines · On 22.04.14 at 16:58, <[email protected]> wrote:
(quoted diff) +5
-0+void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d) +{ + if ( !iommu_enabled ) + panic("Presently, iommu must be enabled for pvh dom0\n"); +}Message text (containing PVH) and function name (not containing PVH) don't fit together, nor does the conditional really establish a connection.
Quoted 1 line
Do you prefer a comment, or an explicit check to
is_pvh_domain(d)?That depends on where it would go: If the caller checks for PVH, then the function name should change. If the caller doesn't, then I don't see how you'd avoid getting here for non-PVH.
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
The caller will go there when the DOM0 is auto-translated (i.e PVH as dom0 can't be an HVM).
I can remove PVH from the log, but for the user it's not accurate.
In which case the function name should reflect this.
What about
arch_iommu_check_autotranslate_hwdom_reqs?
Getting quite long, but seems okay. Perhaps drop the _reqs?
Jan
Re: [PATCH v4 12/21] xen/passthrough: iommu: Split generic IOMMU code
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 20:02, <[email protected]> wrote:
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 18:45, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 10 lines
Review
Quoted 6 lines · On 22.04.14 at 16:58, <[email protected]> wrote:
(quoted diff) +5
-0+void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d) +{ + if ( !iommu_enabled ) + panic("Presently, iommu must be enabled for pvh dom0\n"); +}Message text (containing PVH) and function name (not containing PVH) don't fit together, nor does the conditional really establish a connection.
Quoted 5 lines
Quoted 1 line
Do you prefer a comment, or an explicit check to
is_pvh_domain(d)?That depends on where it would go: If the caller checks for PVH, then the function name should change. If the caller doesn't, then I don't see how you'd avoid getting here for non-PVH.
The caller will go there when the DOM0 is auto-translated (i.e PVH as dom0 can't be an HVM).
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
I can remove PVH from the log, but for the user it's not accurate.
In which case the function name should reflect this.
What about
arch_iommu_check_autotranslate_hwdom_reqs?Getting quite long, but seems okay. Perhaps drop the
_reqs?
Sounds good to me. I will drop it for the next version.
Regards,
Signature · 1 line
Julien Grall
PATCH v4 13/21 xen/passthrough: iommu: Introduce arch specific code
In reply to Julien GrallCurrently the structure hvm_iommu (xen/include/xen/hvm/iommu.h) contains x86 specific fields.
This patch creates:
- arch_hvm_iommu structure which will contain architecture depend fields
- arch_iommu_domain_{init,destroy} function to execute arch specific during domain creation/destruction
Also move iommu_use_hap_pt and domain_hvm_iommu in asm-x86/iommu.h.
---
Changes in v4:
- Rebase on Xen upstream
- Remove spurious iommu_share_p2m_table in passthrough/x86/iommu.c
- Keep the original order in arch_hvm_iommu
--- xen/arch/x86/domctl.c | 6 +-- xen/arch/x86/hvm/io.c | 2 +- xen/arch/x86/tboot.c | 3 +- xen/drivers/passthrough/amd/iommu_guest.c | 8 +-- xen/drivers/passthrough/amd/iommu_map.c | 54 +++++++++---------- xen/drivers/passthrough/amd/pci_amd_iommu.c | 49 +++++++++--------- xen/drivers/passthrough/iommu.c | 18 +++---- xen/drivers/passthrough/vtd/iommu.c | 74 +++++++++++++-------------- xen/drivers/passthrough/x86/iommu.c | 25 +++++++++ xen/include/asm-x86/hvm/iommu.h | 22 ++++++++ xen/include/asm-x86/iommu.h | 4 +- xen/include/xen/hvm/iommu.h | 19 +------ xen/include/xen/iommu.h | 7 +-- 13 files changed, 158 insertions(+), 133 deletions(-)
xen/arch/x86/domctl.c +3 -3
@@ -754,7 +754,7 @@ long arch_do_domctl("ioport_map:add: dom%d gport=%x mport=%x nr=%x\n" , d->domain_id, fgp, fmp, np); -list_for_each_entry (g2m_ioport, &hd->g2m_ioport_list, list) +list_for_each_entry (g2m_ioport, &hd->arch.g2m_ioport_list, list)if (g2m_ioport->mport == fmp ) { g2m_ioport->gport = fgp;
@@ -773,7 +773,7 @@ long arch_do_domctl( g2m_ioport->gport = fgp; g2m_ioport->mport = fmp; g2m_ioport->np = np; -list_add_tail (&g2m_ioport->list, &hd->g2m_ioport_list); +list_add_tail (&g2m_ioport->list, &hd->arch.g2m_ioport_list); }if ( !ret ) ret =ioports_permit_access (d, fmp, fmp + np -1 );
@@ -788,7 +788,7 @@ long arch_do_domctl(printk (XENLOG_G_INFO "ioport_map:remove: dom%d gport=%x mport=%x nr=%x\n" , d->domain_id, fgp, fmp, np); -list_for_each_entry (g2m_ioport, &hd->g2m_ioport_list, list) +list_for_each_entry (g2m_ioport, &hd->arch.g2m_ioport_list, list)if ( g2m_ioport->mport == fmp ) {list_del (&g2m_ioport->list);
xen/arch/x86/hvm/io.c +1 -1
@@ -451,7 +451,7 @@ int dpci_ioport_intercept(ioreq_t *p)unsigned int s =0 , e =0 ;int rc; -list_for_each_entry ( g2m_ioport, &hd->g2m_ioport_list, list ) +list_for_each_entry ( g2m_ioport, &hd->arch.g2m_ioport_list, list ) { s = g2m_ioport->gport; e = s + g2m_ioport->np;
xen/arch/x86/tboot.c +2 -1
@@ -228,7 +228,8 @@ static void tboot_gen_domain_integrity(const uint8_t key[TB_KEY_SIZE],if ( !is_idle_domain (d) ) {struct hvm_iommu *hd =domain_hvm_iommu (d); -update_iommu_mac (&ctx, hd->pgd_maddr,agaw_to_level (hd->agaw)); +update_iommu_mac (&ctx, hd->arch.pgd_maddr, +agaw_to_level (hd->arch.agaw)); } }
xen/drivers/passthrough/amd/iommu_guest.c +4 -4
@@ -60,12 +60,12 @@ static uint16_t guest_bdf(struct domain *d, uint16_t machine_bdf)static inline struct guest_iommu *domain_iommu (struct domain *d) { -return domain_hvm_iommu (d)->g_iommu; +return domain_hvm_iommu (d)->arch.g_iommu; }static inline struct guest_iommu *vcpu_iommu (struct vcpu *v) { -return domain_hvm_iommu (v->domain)->g_iommu; +return domain_hvm_iommu (v->domain)->arch.g_iommu; }static void guest_iommu_enable (struct guest_iommu *iommu)
@@ -886,7 +886,7 @@ int guest_iommu_init(struct domain* d)guest_iommu_reg_init (iommu); iommu->domain = d; - hd->g_iommu = iommu; + hd->arch.g_iommu = iommu;tasklet_init (&iommu->cmd_buffer_tasklet, guest_iommu_process_command, (unsigned long )d);
@@ -907,7 +907,7 @@ void guest_iommu_destroy(struct domain *d)tasklet_kill (&iommu->cmd_buffer_tasklet);xfree (iommu); -domain_hvm_iommu (d)->g_iommu =NULL ; +domain_hvm_iommu (d)->arch.g_iommu =NULL ; }static int guest_iommu_mmio_range (struct vcpu *v,unsigned long addr)
xen/drivers/passthrough/amd/iommu_map.c +27 -27
174 lines not on this page · raw message
xen/drivers/passthrough/amd/pci_amd_iommu.c +25 -24
117 lines not on this page · raw message
xen/drivers/passthrough/iommu.c +6 -12
@@ -117,10 +117,11 @@ static void __init parse_iommu_param(char *s)int iommu_domain_init (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); +int ret =0 ; -spin_lock_init (&hd->mapping_lock); -INIT_LIST_HEAD (&hd->g2m_ioport_list); -INIT_LIST_HEAD (&hd->mapped_rmrrs); + ret =arch_iommu_domain_init (d); +if ( ret ) +return ret;if ( !iommu_enabled )return 0 ;
@@ -188,9 +189,7 @@ void iommu_teardown(struct domain *d)void iommu_domain_destroy (struct domain *d) { -struct hvm_iommu *hd =domain_hvm_iommu (d); -struct list_head *ioport_list, *tmp; -struct g2m_ioport *ioport; +struct hvm_iommu *hd =domain_hvm_iommu (d);if ( !iommu_enabled || !hd->platform_ops )return ;
@@ -198,12 +197,7 @@ void iommu_domain_destroy(struct domain *d)if (need_iommu (d) )iommu_teardown (d); - list_for_each_safe ( ioport_list, tmp, &hd->g2m_ioport_list ) - { - ioport = list_entry(ioport_list, struct g2m_ioport, list); -list_del (&ioport->list); -xfree (ioport); - } +arch_iommu_domain_destroy (d); } int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,
xen/drivers/passthrough/vtd/iommu.c +37 -37
236 lines not on this page · raw message
xen/drivers/passthrough/x86/iommu.c +25 -0
@@ -110,6 +110,31 @@ void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d)panic ("Presently, iommu must be enabled for pvh dom0\n" ); } +int arch_iommu_domain_init (struct domain *d) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); + +spin_lock_init (&hd->arch.mapping_lock); +INIT_LIST_HEAD (&hd->arch.g2m_ioport_list); +INIT_LIST_HEAD (&hd->arch.mapped_rmrrs); + +return 0 ; +} + +void arch_iommu_domain_destroy (struct domain *d) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); +struct list_head *ioport_list, *tmp; +struct g2m_ioport *ioport; + + list_for_each_safe ( ioport_list, tmp, &hd->arch.g2m_ioport_list ) + { + ioport = list_entry(ioport_list, struct g2m_ioport, list); +list_del (&ioport->list); +xfree (ioport); + } +} +/* * Local variables: * mode: C
xen/include/asm-x86/hvm/iommu.h +22 -0
@@ -39,4 +39,26 @@ static inline int iommu_hardware_setup(void) return 0; } +struct g2m_ioport { +struct list_head list; +unsigned int gport; +unsigned int mport; +unsigned int np; +}; + +struct arch_hvm_iommu +{ +u64 pgd_maddr;/* io page directory machine address */ +spinlock_t mapping_lock;/* io page table lock */ +int agaw;/* adjusted guest address width, 0 is level 2 30-bit */ +struct list_head g2m_ioport_list;/* guest to machine ioport mapping */ +u64 iommu_bitmap;/* bitmap of iommu(s) that the domain uses */ +struct list_head mapped_rmrrs; + +/* amd iommu support */ +int paging_mode; +struct page_info *root_table; +struct guest_iommu *g_iommu; +}; +#endif /* __ASM_X86_HVM_IOMMU_H__ */
xen/include/asm-x86/iommu.h +3 -1
@@ -17,7 +17,9 @@#define MAX_IOMMUS 32 -#include <asm/msi.h> +/* Does this domain have a P2M table we can use as its IOMMU pagetable? */ +#define iommu_use_hap_pt (d) (hap_enabled(d) && iommu_hap_pt_share) +#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu)void iommu_update_ire_from_apic (unsigned int apic,unsigned int reg,unsigned int value);unsigned int iommu_read_apic_from_ire (unsigned int apic,unsigned int reg);
xen/include/xen/hvm/iommu.h +1 -18
@@ -23,25 +23,8 @@#include <xen/iommu.h> #include <asm/hvm/iommu.h> -struct g2m_ioport { -struct list_head list; -unsigned int gport; -unsigned int mport; -unsigned int np; -}; -struct hvm_iommu { -u64 pgd_maddr;/* io page directory machine address */ -spinlock_t mapping_lock;/* io page table lock */ -int agaw;/* adjusted guest address width, 0 is level 2 30-bit */ -struct list_head g2m_ioport_list;/* guest to machine ioport mapping */ -u64 iommu_bitmap;/* bitmap of iommu(s) that the domain uses */ -struct list_head mapped_rmrrs; - -/* amd iommu support */ -int paging_mode; -struct page_info *root_table; -struct guest_iommu *g_iommu; +struct arch_hvm_iommu arch;/* iommu_ops */ const struct iommu_ops *platform_ops;
xen/include/xen/iommu.h +2 -5
@@ -35,11 +35,6 @@ extern bool_t iommu_hap_pt_share;extern bool_t iommu_debug;extern bool_t amd_iommu_perdev_intremap; -/* Does this domain have a P2M table we can use as its IOMMU pagetable? */ -#define iommu_use_hap_pt (d) (hap_enabled(d) && iommu_hap_pt_share) - -#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu) -#define PAGE_SHIFT_4K (12)#define PAGE_SIZE_4K (1UL << PAGE_SHIFT_4K)#define PAGE_MASK_4K (((u64)-1) << PAGE_SHIFT_4K)
@@ -55,6 +50,8 @@ void iommu_hwdom_init(struct domain *d);void iommu_domain_destroy (struct domain *d);int deassign_device (struct domain *d,u16 seg,u8 bus,u8 devfn); +void arch_iommu_domain_destroy (struct domain *d); +int arch_iommu_domain_init (struct domain *d);int arch_iommu_populate_page_table (struct domain *d);void arch_iommu_check_hwdom_reqs (struct domain *d);
Signature · 1 line
1.7.10.4
Re: [PATCH v4 13/21] xen/passthrough: iommu: Introduce arch specific code
Hello Sherry and Suravee,
Can one of you ack this change in the AMD IOMMU drivers?
Regards,
Quoted 906 lines · Julien Grall
Currently the structure
hvm_iommu(xen/include/xen/hvm/iommu.h) contains x86 specific fields.This patch creates:
-arch_hvm_iommustructure which will contain architecture depend fields
- arch_iommu_domain_{init,destroy} function to execute arch specific during domain creation/destructionAlso move
iommu_use_hap_ptanddomain_hvm_iommuinasm-x86/iommu.h.Signed-off-by Julien Grall <[email protected]>Acked-by Jan Beulich <[email protected]>Cc Keir Fraser <[email protected]>Cc Joseph Cihula <[email protected]>Cc Gang Wei <[email protected]>Cc Shane Wang <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Xiantao Zhang <[email protected]>---
Changes in v4:
- Rebase on Xen upstream
- Remove spuriousiommu_share_p2m_tableinpassthrough/x86/iommu.c
- Keep the original order inarch_hvm_iommu--- xen/arch/x86/domctl.c | 6 +-- xen/arch/x86/hvm/io.c | 2 +- xen/arch/x86/tboot.c | 3 +- xen/drivers/passthrough/amd/iommu_guest.c | 8 +-- xen/drivers/passthrough/amd/iommu_map.c | 54 +++++++++---------- xen/drivers/passthrough/amd/pci_amd_iommu.c | 49 +++++++++--------- xen/drivers/passthrough/iommu.c | 18 +++---- xen/drivers/passthrough/vtd/iommu.c | 74 +++++++++++++-------------- xen/drivers/passthrough/x86/iommu.c | 25 +++++++++ xen/include/asm-x86/hvm/iommu.h | 22 ++++++++ xen/include/asm-x86/iommu.h | 4 +- xen/include/xen/hvm/iommu.h | 19 +------ xen/include/xen/iommu.h | 7 +-- 13 files changed, 158 insertions(+), 133 deletions(-)xen/arch/x86/domctl.c +3
-3@@ -754,7 +754,7 @@ long arch_do_domctl("ioport_map:add: dom%d gport=%x mport=%x nr=%x\n" , d->domain_id, fgp, fmp, np); -list_for_each_entry (g2m_ioport, &hd->g2m_ioport_list, list) +list_for_each_entry (g2m_ioport, &hd->arch.g2m_ioport_list, list)if (g2m_ioport->mport == fmp ) { g2m_ioport->gport = fgp;@@ -773,7 +773,7 @@ long arch_do_domctl( g2m_ioport->gport = fgp; g2m_ioport->mport = fmp; g2m_ioport->np = np; -list_add_tail (&g2m_ioport->list, &hd->g2m_ioport_list); +list_add_tail (&g2m_ioport->list, &hd->arch.g2m_ioport_list); }if ( !ret ) ret =ioports_permit_access (d, fmp, fmp + np -1 );@@ -788,7 +788,7 @@ long arch_do_domctl(printk (XENLOG_G_INFO "ioport_map:remove: dom%d gport=%x mport=%x nr=%x\n" , d->domain_id, fgp, fmp, np); -list_for_each_entry (g2m_ioport, &hd->g2m_ioport_list, list) +list_for_each_entry (g2m_ioport, &hd->arch.g2m_ioport_list, list)if ( g2m_ioport->mport == fmp ) {list_del (&g2m_ioport->list);xen/arch/x86/hvm/io.c +1
-1@@ -451,7 +451,7 @@ int dpci_ioport_intercept(ioreq_t *p)unsigned int s =0 , e =0 ;int rc; -list_for_each_entry ( g2m_ioport, &hd->g2m_ioport_list, list ) +list_for_each_entry ( g2m_ioport, &hd->arch.g2m_ioport_list, list ) { s = g2m_ioport->gport; e = s + g2m_ioport->np;xen/arch/x86/tboot.c +2
-1@@ -228,7 +228,8 @@ static void tboot_gen_domain_integrity(const uint8_t key[TB_KEY_SIZE],if ( !is_idle_domain (d) ) {struct hvm_iommu *hd =domain_hvm_iommu (d); -update_iommu_mac (&ctx, hd->pgd_maddr,agaw_to_level (hd->agaw)); +update_iommu_mac (&ctx, hd->arch.pgd_maddr, +agaw_to_level (hd->arch.agaw)); } }xen/drivers/passthrough/amd/iommu_guest.c +4
-4@@ -60,12 +60,12 @@ static uint16_t guest_bdf(struct domain *d, uint16_t machine_bdf)static inline struct guest_iommu *domain_iommu (struct domain *d) { -return domain_hvm_iommu (d)->g_iommu; +return domain_hvm_iommu (d)->arch.g_iommu; }static inline struct guest_iommu *vcpu_iommu (struct vcpu *v) { -return domain_hvm_iommu (v->domain)->g_iommu; +return domain_hvm_iommu (v->domain)->arch.g_iommu; }static void guest_iommu_enable (struct guest_iommu *iommu)@@ -886,7 +886,7 @@ int guest_iommu_init(struct domain* d)guest_iommu_reg_init (iommu); iommu->domain = d; - hd->g_iommu = iommu; + hd->arch.g_iommu = iommu;tasklet_init (&iommu->cmd_buffer_tasklet, guest_iommu_process_command, (unsigned long )d);@@ -907,7 +907,7 @@ void guest_iommu_destroy(struct domain *d)tasklet_kill (&iommu->cmd_buffer_tasklet);xfree (iommu); -domain_hvm_iommu (d)->g_iommu =NULL ; +domain_hvm_iommu (d)->arch.g_iommu =NULL ; }static int guest_iommu_mmio_range (struct vcpu *v,unsigned long addr)xen/drivers/passthrough/amd/iommu_map.c +27
-27@@ -344,7 +344,7 @@ static int iommu_update_pde_count(struct domain *d, unsigned long pt_mfn,struct hvm_iommu *hd =domain_hvm_iommu (d);bool_t ok =0 ; -ASSERT (spin_is_locked (&hd->mapping_lock) && pt_mfn ); +ASSERT (spin_is_locked (&hd->arch.mapping_lock) && pt_mfn ); next_level = merge_level -1 ;@@ -398,7 +398,7 @@ static int iommu_merge_pages(struct domain *d, unsigned long pt_mfn,unsigned long first_mfn;struct hvm_iommu *hd =domain_hvm_iommu (d); -ASSERT (spin_is_locked (&hd->mapping_lock) && pt_mfn ); +ASSERT (spin_is_locked (&hd->arch.mapping_lock) && pt_mfn ); table =map_domain_page (pt_mfn); pde = table +pfn_to_pde_idx (gfn, merge_level);@@ -448,8 +448,8 @@ static int iommu_pde_from_gfn(struct domain *d, unsigned long pfn,struct page_info *table;struct hvm_iommu *hd =domain_hvm_iommu (d); - table = hd->root_table; - level = hd->paging_mode; + table = hd->arch.root_table; + level = hd->arch.paging_mode;BUG_ON ( table ==NULL || level <IOMMU_PAGING_MODE_LEVEL_1 || level >IOMMU_PAGING_MODE_LEVEL_6 );@@ -557,11 +557,11 @@ static int update_paging_mode(struct domain *d, unsigned long gfn)unsigned long old_root_mfn;struct hvm_iommu *hd =domain_hvm_iommu (d); - level = hd->paging_mode; - old_root = hd->root_table; + level = hd->arch.paging_mode; + old_root = hd->arch.root_table; offset = gfn >> (PTE_PER_TABLE_SHIFT * (level -1 )); -ASSERT (spin_is_locked (&hd->mapping_lock) &&is_hvm_domain (d)); +ASSERT (spin_is_locked (&hd->arch.mapping_lock) &&is_hvm_domain (d));while ( offset >=PTE_PER_TABLE_SIZE ) {@@ -587,8 +587,8 @@ static int update_paging_mode(struct domain *d, unsigned long gfn)if ( new_root !=NULL ) { - hd->paging_mode = level; - hd->root_table = new_root; + hd->arch.paging_mode = level; + hd->arch.root_table = new_root;if ( !spin_is_locked (&pcidevs_lock) ) AMD_IOMMU_DEBUG("%s Try to access pdev_list "@@ -613,9 +613,9 @@ static int update_paging_mode(struct domain *d, unsigned long gfn)/* valid = 0 only works for dom0 passthrough mode */ amd_iommu_set_root_page_table ((u32 *)device_entry, -page_to_maddr (hd->root_table), +page_to_maddr (hd->arch.root_table), d->domain_id, - hd->paging_mode,1 ); + hd->arch.paging_mode,1 );amd_iommu_flush_device (iommu, req_id); bdf += pdev->phantom_stride;@@ -638,14 +638,14 @@ int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,unsigned long pt_mfn[7 ];unsigned int merge_level; -BUG_ON ( !hd->root_table ); +BUG_ON ( !hd->arch.root_table );if (iommu_use_hap_pt (d) )return 0 ;memset (pt_mfn,0 ,sizeof (pt_mfn)); -spin_lock (&hd->mapping_lock); +spin_lock (&hd->arch.mapping_lock);/* Since HVM domain is initialized with 2 level IO page table, * we might need a deeper page table for lager gfn now */ @@ -653,7 +653,7 @@ int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, {if (update_paging_mode (d, gfn) ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);AMD_IOMMU_DEBUG ("Update page mode failed gfn = %lx\n" , gfn);domain_crash (d);return -EFAULT ;@@ -662,7 +662,7 @@ int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,if (iommu_pde_from_gfn (d, gfn, pt_mfn) || (pt_mfn[1 ] ==0 ) ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);AMD_IOMMU_DEBUG ("Invalid IO pagetable entry gfn = %lx\n" , gfn);domain_crash (d);return -EFAULT ;@@ -684,7 +684,7 @@ int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,amd_iommu_flush_pages (d, gfn,0 );for ( merge_level =IOMMU_PAGING_MODE_LEVEL_2 ; - merge_level <= hd->paging_mode; merge_level++ ) + merge_level <= hd->arch.paging_mode; merge_level++ ) {if ( pt_mfn[merge_level] ==0 )break ;@@ -697,7 +697,7 @@ int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,if (iommu_merge_pages (d, pt_mfn[merge_level], gfn, flags, merge_level) ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);AMD_IOMMU_DEBUG ("Merge iommu page failed at level %d, " "gfn = %lx mfn = %lx\n" , merge_level, gfn, mfn);domain_crash (d);@@ -706,7 +706,7 @@ int amd_iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, } out: -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);return 0 ; }@@ -715,14 +715,14 @@ int amd_iommu_unmap_page(struct domain *d, unsigned long gfn)unsigned long pt_mfn[7 ];struct hvm_iommu *hd =domain_hvm_iommu (d); -BUG_ON ( !hd->root_table ); +BUG_ON ( !hd->arch.root_table );if (iommu_use_hap_pt (d) )return 0 ;memset (pt_mfn,0 ,sizeof (pt_mfn)); -spin_lock (&hd->mapping_lock); +spin_lock (&hd->arch.mapping_lock);/* Since HVM domain is initialized with 2 level IO page table, * we might need a deeper page table for lager gfn now */ @@ -730,7 +730,7 @@ int amd_iommu_unmap_page(struct domain *d, unsigned long gfn) {if (update_paging_mode (d, gfn) ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);AMD_IOMMU_DEBUG ("Update page mode failed gfn = %lx\n" , gfn);domain_crash (d);return -EFAULT ;@@ -739,7 +739,7 @@ int amd_iommu_unmap_page(struct domain *d, unsigned long gfn)if (iommu_pde_from_gfn (d, gfn, pt_mfn) || (pt_mfn[1 ] ==0 ) ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);AMD_IOMMU_DEBUG ("Invalid IO pagetable entry gfn = %lx\n" , gfn);domain_crash (d);return -EFAULT ;@@ -747,7 +747,7 @@ int amd_iommu_unmap_page(struct domain *d, unsigned long gfn)/* mark PTE as 'page not present' */ clear_iommu_pte_present (pt_mfn[1 ], gfn); -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);amd_iommu_flush_pages (d, gfn,0 );@@ -792,13 +792,13 @@ void amd_iommu_share_p2m(struct domain *d) pgd_mfn =pagetable_get_mfn (p2m_get_pagetable (p2m_get_hostp2m (d))); p2m_table =mfn_to_page (mfn_x (pgd_mfn)); -if ( hd->root_table != p2m_table ) +if ( hd->arch.root_table != p2m_table ) { -free_amd_iommu_pgtable (hd->root_table); - hd->root_table = p2m_table; +free_amd_iommu_pgtable (hd->arch.root_table); + hd->arch.root_table = p2m_table;/* When sharing p2m with iommu, paging mode = 4 */ - hd->paging_mode =IOMMU_PAGING_MODE_LEVEL_4 ; + hd->arch.paging_mode =IOMMU_PAGING_MODE_LEVEL_4 ;AMD_IOMMU_DEBUG ("Share p2m table with iommu: p2m table = %#lx\n" ,mfn_x (pgd_mfn)); }xen/drivers/passthrough/amd/pci_amd_iommu.c +25
-24@@ -120,7 +120,8 @@ static void amd_iommu_setup_domain_device(struct hvm_iommu *hd =domain_hvm_iommu (domain); -BUG_ON ( !hd->root_table || !hd->paging_mode || !iommu->dev_table.buffer ); +BUG_ON ( !hd->arch.root_table || !hd->arch.paging_mode || + !iommu->dev_table.buffer );if ( iommu_passthrough &&is_hardware_domain (domain) ) valid =0 ;@@ -138,8 +139,8 @@ static void amd_iommu_setup_domain_device( {/* bind DTE to domain page-tables */ amd_iommu_set_root_page_table ( - (u32 *)dte,page_to_maddr (hd->root_table), domain->domain_id, - hd->paging_mode, valid); + (u32 *)dte,page_to_maddr (hd->arch.root_table), domain->domain_id, + hd->arch.paging_mode, valid);if (pci_ats_device (iommu->seg, bus, pdev->devfn) &&iommu_has_cap (iommu,PCI_CAP_IOTLB_SHIFT ) )@@ -151,8 +152,8 @@ static void amd_iommu_setup_domain_device("root table = %#" PRIx64", " "domain = %d, paging mode = %d\n" , req_id, pdev->type, -page_to_maddr (hd->root_table), - domain->domain_id, hd->paging_mode); +page_to_maddr (hd->arch.root_table), + domain->domain_id, hd->arch.paging_mode); }spin_unlock_irqrestore (&iommu->lock, flags);@@ -226,17 +227,17 @@ int __init amd_iov_detect(void)static int allocate_domain_resources (struct hvm_iommu *hd) {/* allocate root table */ -spin_lock (&hd->mapping_lock); -if ( !hd->root_table ) +spin_lock (&hd->arch.mapping_lock); +if ( !hd->arch.root_table ) { - hd->root_table =alloc_amd_iommu_pgtable (); -if ( !hd->root_table ) + hd->arch.root_table =alloc_amd_iommu_pgtable (); +if ( !hd->arch.root_table ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);return -ENOMEM ; } } -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);return 0 ; }@@ -263,14 +264,14 @@ static int amd_iommu_domain_init(struct domain *d)/* allocate page directroy */ if (allocate_domain_resources (hd) !=0 ) { -if ( hd->root_table ) -free_domheap_page (hd->root_table); +if ( hd->arch.root_table ) +free_domheap_page (hd->arch.root_table);return -ENOMEM ; }/* For pv and dom0, stick with get_paging_mode(max_page) * For HVM dom0, use 2 level page table at first */ - hd->paging_mode =is_hvm_domain (d) ? + hd->arch.paging_mode =is_hvm_domain (d) ?IOMMU_PAGING_MODE_LEVEL_2 :get_paging_mode (max_page);@@ -333,7 +334,7 @@ void amd_iommu_disable_domain_device(struct domain *domain,AMD_IOMMU_DEBUG ("Disable: device id = %#x, " "domain = %d, paging mode = %d\n" , req_id, domain->domain_id, -domain_hvm_iommu (domain)->paging_mode); +domain_hvm_iommu (domain)->arch.paging_mode); }spin_unlock_irqrestore (&iommu->lock, flags);@@ -373,7 +374,7 @@ static int reassign_device(struct domain *source, struct domain *target,/* IO page tables might be destroyed after pci-detach the last device * In this case, we have to re-allocate root table for next pci-attach.*/ -if ( t->root_table ==NULL ) +if ( t->arch.root_table ==NULL )allocate_domain_resources (t);amd_iommu_setup_domain_device (target, iommu, devfn, pdev);@@ -455,13 +456,13 @@ static void deallocate_iommu_page_tables(struct domain *d)if (iommu_use_hap_pt (d) )return ; -spin_lock (&hd->mapping_lock); -if ( hd->root_table ) +spin_lock (&hd->arch.mapping_lock); +if ( hd->arch.root_table ) { -deallocate_next_page_table (hd->root_table, hd->paging_mode); - hd->root_table =NULL ; +deallocate_next_page_table (hd->arch.root_table, hd->arch.paging_mode); + hd->arch.root_table =NULL ; } -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock); }@@ -592,11 +593,11 @@ static void amd_dump_p2m_table(struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); -if ( !hd->root_table ) +if ( !hd->arch.root_table )return ; -printk ("p2m table has %d levels\n" , hd->paging_mode); -amd_dump_p2m_table_level (hd->root_table, hd->paging_mode,0 ,0 ); +printk ("p2m table has %d levels\n" , hd->arch.paging_mode); +amd_dump_p2m_table_level (hd->arch.root_table, hd->arch.paging_mode,0 ,0 ); }const struct iommu_ops amd_iommu_ops = {xen/drivers/passthrough/iommu.c +6
-12@@ -117,10 +117,11 @@ static void __init parse_iommu_param(char *s)int iommu_domain_init (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); +int ret =0 ; -spin_lock_init (&hd->mapping_lock); -INIT_LIST_HEAD (&hd->g2m_ioport_list); -INIT_LIST_HEAD (&hd->mapped_rmrrs); + ret =arch_iommu_domain_init (d); +if ( ret ) +return ret;if ( !iommu_enabled )return 0 ;@@ -188,9 +189,7 @@ void iommu_teardown(struct domain *d)void iommu_domain_destroy (struct domain *d) { -struct hvm_iommu *hd =domain_hvm_iommu (d); -struct list_head *ioport_list, *tmp; -struct g2m_ioport *ioport; +struct hvm_iommu *hd =domain_hvm_iommu (d);if ( !iommu_enabled || !hd->platform_ops )return ;@@ -198,12 +197,7 @@ void iommu_domain_destroy(struct domain *d)if (need_iommu (d) )iommu_teardown (d); - list_for_each_safe ( ioport_list, tmp, &hd->g2m_ioport_list ) - { - ioport = list_entry(ioport_list, struct g2m_ioport, list); -list_del (&ioport->list); -xfree (ioport); - } +arch_iommu_domain_destroy (d); } int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn,xen/drivers/passthrough/vtd/iommu.c +37
-37@@ -254,16 +254,16 @@ static u64 addr_to_dma_page_maddr(struct domain *domain, u64 addr, int alloc)struct acpi_drhd_unit *drhd;struct pci_dev *pdev;struct hvm_iommu *hd =domain_hvm_iommu (domain); -int addr_width =agaw_to_width (hd->agaw); +int addr_width =agaw_to_width (hd->arch.agaw);struct dma_pte *parent, *pte =NULL ; -int level =agaw_to_level (hd->agaw); +int level =agaw_to_level (hd->arch.agaw);int offset;u64 pte_maddr =0 , maddr;u64 *vaddr =NULL ; addr &= (((u64 )1 ) << addr_width) -1 ; -ASSERT (spin_is_locked (&hd->mapping_lock)); -if ( hd->pgd_maddr ==0 ) +ASSERT (spin_is_locked (&hd->arch.mapping_lock)); +if ( hd->arch.pgd_maddr ==0 ) {/* * just get any passthrough device in the domainr - assume user @@ -271,11 +271,11 @@ static u64 addr_to_dma_page_maddr(struct domain *domain, u64 addr, int alloc)*/ pdev =pci_get_pdev_by_domain (domain,-1 ,-1 ,-1 ); drhd =acpi_find_matched_drhd_unit (pdev); -if ( !alloc || ((hd->pgd_maddr =alloc_pgtable_maddr (drhd,1 )) ==0 ) ) +if ( !alloc || ((hd->arch.pgd_maddr =alloc_pgtable_maddr (drhd,1 )) ==0 ) ) goto out; } - parent = (struct dma_pte *)map_vtd_domain_page (hd->pgd_maddr); + parent = (struct dma_pte *)map_vtd_domain_page (hd->arch.pgd_maddr);while ( level >1 ) { offset =address_level_offset (addr, level);@@ -585,7 +585,7 @@ static void __intel_iommu_iotlb_flush(struct domain *d, unsigned long gfn, { iommu = drhd->iommu; -if ( !test_bit (iommu->index, &hd->iommu_bitmap) ) +if ( !test_bit (iommu->index, &hd->arch.iommu_bitmap) )continue ; flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ;@@ -626,12 +626,12 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)struct dma_pte *page =NULL , *pte =NULL ;u64 pg_maddr; -spin_lock (&hd->mapping_lock); +spin_lock (&hd->arch.mapping_lock);/* get last level pte */ pg_maddr =addr_to_dma_page_maddr (domain, addr,0 );if ( pg_maddr ==0 ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);return ; }@@ -640,13 +640,13 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)if ( !dma_pte_present (*pte) ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);unmap_vtd_domain_page (page);return ; }dma_clear_pte (*pte); -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);iommu_flush_cache_entry (pte,sizeof (struct dma_pte ));if ( !this_cpu (iommu_dont_flush_iotlb) )@@ -1237,7 +1237,7 @@ static int intel_iommu_domain_init(struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); - hd->agaw =width_to_agaw (DEFAULT_DOMAIN_ADDRESS_WIDTH ); + hd->arch.agaw =width_to_agaw (DEFAULT_DOMAIN_ADDRESS_WIDTH );return 0 ; }@@ -1334,16 +1334,16 @@ int domain_context_mapping_one( }else { -spin_lock (&hd->mapping_lock); +spin_lock (&hd->arch.mapping_lock);/* Ensure we have pagetables allocated down to leaf PTE. */ -if ( hd->pgd_maddr ==0 ) +if ( hd->arch.pgd_maddr ==0 ) {addr_to_dma_page_maddr (domain,0 ,1 ); -if ( hd->pgd_maddr ==0 ) +if ( hd->arch.pgd_maddr ==0 ) { nomem: -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);spin_unlock (&iommu->lock);unmap_vtd_domain_page (context_entries);return -ENOMEM ;@@ -1351,7 +1351,7 @@ int domain_context_mapping_one( }/* Skip top levels of page tables for 2- and 3-level DRHDs. */ - pgd_maddr = hd->pgd_maddr; + pgd_maddr = hd->arch.pgd_maddr;for ( agaw =level_to_agaw (4 ); agaw !=level_to_agaw (iommu->nr_pt_levels); agaw-- )@@ -1369,7 +1369,7 @@ int domain_context_mapping_one(else context_set_translation_type (*context,CONTEXT_TT_MULTI_LEVEL ); -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock); }if (context_set_domain_id (context, domain, iommu) )@@ -1395,7 +1395,7 @@ int domain_context_mapping_one(iommu_flush_iotlb_dsi (iommu,0 ,1 , flush_dev_iotlb); } -set_bit (iommu->index, &hd->iommu_bitmap); +set_bit (iommu->index, &hd->arch.iommu_bitmap);unmap_vtd_domain_page (context_entries);@@ -1638,7 +1638,7 @@ static int domain_context_unmap(struct hvm_iommu *hd =domain_hvm_iommu (domain);int iommu_domid; -clear_bit (iommu->index, &hd->iommu_bitmap); +clear_bit (iommu->index, &hd->arch.iommu_bitmap); iommu_domid =domain_iommu_domid (domain, iommu);if ( iommu_domid ==-1 )@@ -1695,7 +1695,7 @@ static void iommu_domain_teardown(struct domain *d)if (list_empty (&acpi_drhd_units) )return ; - list_for_each_entry_safe ( mrmrr, tmp, &hd->mapped_rmrrs, list ) + list_for_each_entry_safe ( mrmrr, tmp, &hd->arch.mapped_rmrrs, list ) {list_del (&mrmrr->list);xfree (mrmrr);@@ -1704,10 +1704,10 @@ static void iommu_domain_teardown(struct domain *d)if (iommu_use_hap_pt (d) )return ; -spin_lock (&hd->mapping_lock); -iommu_free_pagetable (hd->pgd_maddr,agaw_to_level (hd->agaw)); - hd->pgd_maddr =0 ; -spin_unlock (&hd->mapping_lock); +spin_lock (&hd->arch.mapping_lock); +iommu_free_pagetable (hd->arch.pgd_maddr,agaw_to_level (hd->arch.agaw)); + hd->arch.pgd_maddr =0 ; +spin_unlock (&hd->arch.mapping_lock); } static int intel_iommu_map_page(@@ -1726,12 +1726,12 @@ static int intel_iommu_map_page(if ( iommu_passthrough &&is_hardware_domain (d) )return 0 ; -spin_lock (&hd->mapping_lock); +spin_lock (&hd->arch.mapping_lock); pg_maddr =addr_to_dma_page_maddr (d, (paddr_t )gfn <<PAGE_SHIFT_4K ,1 );if ( pg_maddr ==0 ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);return -ENOMEM ; } page = (struct dma_pte *)map_vtd_domain_page (pg_maddr);@@ -1748,14 +1748,14 @@ static int intel_iommu_map_page(if ( old.val == new.val ) { -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);unmap_vtd_domain_page (page);return 0 ; } *pte = new;iommu_flush_cache_entry (pte,sizeof (struct dma_pte )); -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock);unmap_vtd_domain_page (page);if ( !this_cpu (iommu_dont_flush_iotlb) )@@ -1789,7 +1789,7 @@ void iommu_pte_flush(struct domain *d, u64 gfn, u64 *pte,for_each_drhd_unit ( drhd ) { iommu = drhd->iommu; -if ( !test_bit (iommu->index, &hd->iommu_bitmap) ) +if ( !test_bit (iommu->index, &hd->arch.iommu_bitmap) )continue ; flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ;@@ -1830,7 +1830,7 @@ static void iommu_set_pgd(struct domain *d)return ; pgd_mfn =pagetable_get_mfn (p2m_get_pagetable (p2m_get_hostp2m (d))); - hd->pgd_maddr =pagetable_get_paddr (pagetable_from_mfn (pgd_mfn)); + hd->arch.pgd_maddr =pagetable_get_paddr (pagetable_from_mfn (pgd_mfn)); } static int rmrr_identity_mapping(struct domain *d,@@ -1845,10 +1845,10 @@ static int rmrr_identity_mapping(struct domain *d,ASSERT (rmrr->base_address < rmrr->end_address);/* -* No need to acquire hd->mapping_lock: Both insertion and removal +* No need to acquire hd->arch.mapping_lock: Both insertion and removal * get done while holding pcidevs_lock. */ -list_for_each_entry ( mrmrr, &hd->mapped_rmrrs, list ) +list_for_each_entry ( mrmrr, &hd->arch.mapped_rmrrs, list ) {if ( mrmrr->base == rmrr->base_address && mrmrr->end == rmrr->end_address )@@ -1877,7 +1877,7 @@ static int rmrr_identity_mapping(struct domain *d, mrmrr->base = rmrr->base_address; mrmrr->end = rmrr->end_address; mrmrr->count =1 ; -list_add_tail (&mrmrr->list, &hd->mapped_rmrrs); +list_add_tail (&mrmrr->list, &hd->arch.mapped_rmrrs);return 0 ; }@@ -1964,7 +1964,7 @@ static int intel_iommu_remove_device(u8 devfn, struct pci_dev *pdev)* get done while holding pcidevs_lock. */ ASSERT (spin_is_locked (&pcidevs_lock)); - list_for_each_entry_safe ( mrmrr, tmp, &hd->mapped_rmrrs, list ) + list_for_each_entry_safe ( mrmrr, tmp, &hd->arch.mapped_rmrrs, list ) {unsigned long base_pfn, end_pfn;@@ -2458,8 +2458,8 @@ static void vtd_dump_p2m_table(struct domain *d)return ; hd =domain_hvm_iommu (d); -printk ("p2m table has %d levels\n" ,agaw_to_level (hd->agaw)); -vtd_dump_p2m_table_level (hd->pgd_maddr,agaw_to_level (hd->agaw),0 ,0 ); +printk ("p2m table has %d levels\n" ,agaw_to_level (hd->arch.agaw)); +vtd_dump_p2m_table_level (hd->arch.pgd_maddr,agaw_to_level (hd->arch.agaw),0 ,0 ); }const struct iommu_ops intel_iommu_ops = {xen/drivers/passthrough/x86/iommu.c +25
-0@@ -110,6 +110,31 @@ void __hwdom_init arch_iommu_check_hwdom_reqs(struct domain *d)panic ("Presently, iommu must be enabled for pvh dom0\n" ); } +int arch_iommu_domain_init (struct domain *d) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); + +spin_lock_init (&hd->arch.mapping_lock); +INIT_LIST_HEAD (&hd->arch.g2m_ioport_list); +INIT_LIST_HEAD (&hd->arch.mapped_rmrrs); + +return 0 ; +} + +void arch_iommu_domain_destroy (struct domain *d) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); +struct list_head *ioport_list, *tmp; +struct g2m_ioport *ioport; + + list_for_each_safe ( ioport_list, tmp, &hd->arch.g2m_ioport_list ) + { + ioport = list_entry(ioport_list, struct g2m_ioport, list); +list_del (&ioport->list); +xfree (ioport); + } +} +/* * Local variables: * mode: C xen/include/asm-x86/hvm/iommu.h +22
-0@@ -39,4 +39,26 @@ static inline int iommu_hardware_setup(void) return 0; } +struct g2m_ioport { +struct list_head list; +unsigned int gport; +unsigned int mport; +unsigned int np; +}; + +struct arch_hvm_iommu +{ +u64 pgd_maddr;/* io page directory machine address */ +spinlock_t mapping_lock;/* io page table lock */ +int agaw;/* adjusted guest address width, 0 is level 2 30-bit */ +struct list_head g2m_ioport_list;/* guest to machine ioport mapping */ +u64 iommu_bitmap;/* bitmap of iommu(s) that the domain uses */ +struct list_head mapped_rmrrs; + +/* amd iommu support */ +int paging_mode; +struct page_info *root_table; +struct guest_iommu *g_iommu; +}; +#endif /* __ASM_X86_HVM_IOMMU_H__ */ xen/include/asm-x86/iommu.h +3
-1@@ -17,7 +17,9 @@#define MAX_IOMMUS 32 -#include <asm/msi.h> +/* Does this domain have a P2M table we can use as its IOMMU pagetable? */ +#define iommu_use_hap_pt (d) (hap_enabled(d) && iommu_hap_pt_share) +#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu)void iommu_update_ire_from_apic (unsigned int apic,unsigned int reg,unsigned int value);unsigned int iommu_read_apic_from_ire (unsigned int apic,unsigned int reg);xen/include/xen/hvm/iommu.h +1
-18@@ -23,25 +23,8 @@#include <xen/iommu.h> #include <asm/hvm/iommu.h> -struct g2m_ioport { -struct list_head list; -unsigned int gport; -unsigned int mport; -unsigned int np; -}; -struct hvm_iommu { -u64 pgd_maddr;/* io page directory machine address */ -spinlock_t mapping_lock;/* io page table lock */ -int agaw;/* adjusted guest address width, 0 is level 2 30-bit */ -struct list_head g2m_ioport_list;/* guest to machine ioport mapping */ -u64 iommu_bitmap;/* bitmap of iommu(s) that the domain uses */ -struct list_head mapped_rmrrs; - -/* amd iommu support */ -int paging_mode; -struct page_info *root_table; -struct guest_iommu *g_iommu; +struct arch_hvm_iommu arch;/* iommu_ops */ const struct iommu_ops *platform_ops;xen/include/xen/iommu.h +2
-5@@ -35,11 +35,6 @@ extern bool_t iommu_hap_pt_share;extern bool_t iommu_debug;extern bool_t amd_iommu_perdev_intremap; -/* Does this domain have a P2M table we can use as its IOMMU pagetable? */ -#define iommu_use_hap_pt (d) (hap_enabled(d) && iommu_hap_pt_share) - -#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu) -#define PAGE_SHIFT_4K (12)#define PAGE_SIZE_4K (1UL << PAGE_SHIFT_4K)#define PAGE_MASK_4K (((u64)-1) << PAGE_SHIFT_4K)@@ -55,6 +50,8 @@ void iommu_hwdom_init(struct domain *d);void iommu_domain_destroy (struct domain *d);int deassign_device (struct domain *d,u16 seg,u8 bus,u8 devfn); +void arch_iommu_domain_destroy (struct domain *d); +int arch_iommu_domain_init (struct domain *d);int arch_iommu_populate_page_table (struct domain *d);void arch_iommu_check_hwdom_reqs (struct domain *d);
Signature · 1 line
Julien Grall
A message that is not in the archive (sent off-list or not yet received): CAAAAutDRYoqdSBdDsETqtzVDdXmy6jq1Jnm1ck8c5eTqbkMUFw@mail.gmail.com
Re: Fwd: [PATCH v4 13/21] xen/passthrough: iommu: Introduce arch specific code
xen/drivers/passthrough/amd/pci_amd_iommu.c static void amd_dump_p2m_table(struct domain *d) · line 596
Quoted 8 lines
xen/drivers/passthrough/amd/pci_amd_iommu.c +1
-1@@ -592,11 +593,11 @@ static void amd_dump_p2m_table(struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); -if ( !hd->root_table ) +if ( !hd->arch.root_table )
trailing white space..
xen/drivers/passthrough/amd/pci_amd_iommu.c static void amd_dump_p2m_table(struct domain *d) · line 602
Quoted 9 lines
xen/drivers/passthrough/amd/pci_amd_iommu.c +2
-2return ; -printk ("p2m table has %d levels\n" , hd->paging_mode); -amd_dump_p2m_table_level (hd->root_table, hd->paging_mode,0 ,0 ); +printk ("p2m table has %d levels\n" , hd->arch.paging_mode); +amd_dump_p2m_table_level (hd->arch.root_table, hd->arch.paging_mode,0 ,0 ); }
Tested-by, Reviewed-by: Aravind Gopalakrishnan <[email protected]>
Thanks,
-Aravind.
PATCH v4 14/21 xen/passthrough: iommu: Basic support of device tree assignment
In reply to Julien GrallAdd IOMMU helpers to support device tree assignment/deassignment. This patch introduces 2 new fields in the dt_device_node:
- is_protected: Does the device is protected by an IOMMU
- domain_list: Pointer to the next device assigned to the same domain
This commit contains only support to protected a device with DOM0. Device passthrough to another guest won't work out-of-box.
---
Changes in v4:
- Use hardware_domain instead of dom0 (recently changes in Xen)
- iommu_deassign_dt_device: add back to dom0 list the device
- add comments about the current support of DT device passthrough
- update commit message
- rename next_assigned to domain_list
Changes in v3:
- Remove iommu_dt_domain_{init,destroy} call in common code. Let architecture code to call them
- Fix indentation in xen/include/xen/hvm/iommu.h
Changes in v2:
- Patch added
--- xen/common/device_tree.c | 4 ++ xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/device_tree.c | 111 +++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 14 +++++ xen/include/xen/hvm/iommu.h | 6 ++ xen/include/xen/iommu.h | 16 +++++ 6 files changed, 152 insertions(+) create mode 100644 xen/drivers/passthrough/device_tree.c
xen/common/device_tree.c +4 -0
@@ -1695,6 +1695,10 @@ static unsigned long __init unflatten_dt_node(const void *fdt, np->full_name = ((char *)np) +sizeof (struct dt_device_node );/* By default dom0 owns the device */ np->used_by =0 ; +/* By default the device is not protected */ + np->is_protected = false; +INIT_LIST_HEAD (&np->domain_list); +if ( new_format ) {char *fn = np->full_name;
xen/drivers/passthrough/Makefile +1 -0
@@ -5,3 +5,4 @@ subdir-$(x86_64) += x86 obj-y += iommu.o obj-$(x86) += io.o obj-$(HAS_PCI) += pci.o +obj-$(HAS_DEVICE_TREE) += device_tree.o
xen/drivers/passthrough/device_tree.c new file +111 -0
111 lines not on this page · raw message
xen/include/xen/device_tree.h +14 -0
@@ -16,6 +16,7 @@#include <xen/string.h> #include <xen/types.h> #include <xen/stdbool.h> +#include <xen/list.h> #define DEVICE_TREE_MAX_DEPTH 16
@@ -111,6 +112,9 @@ struct dt_device_node {struct dt_device_node *next;/* TODO: Remove it. Only use to know the last children */ struct dt_device_node *allnext; +/* IOMMU specific fields */ +bool is_protected;/* Tell if the device is protected by an IOMMU */ +struct list_head domain_list; };#define MAX_PHANDLE_ARGS 16
@@ -326,6 +330,16 @@ static inline domid_t dt_device_used_by(const struct dt_device_node *device)return device->used_by; } +static inline void dt_device_set_protected (struct dt_device_node *device) +{ + device->is_protected = true; +} + +static inline bool dt_device_is_protected (const struct dt_device_node *device) +{ +return device->is_protected; +} +static inline bool_t dt_property_name_is_equal (const struct dt_property *pp,const char *name) {
xen/include/xen/hvm/iommu.h +6 -0
@@ -21,6 +21,7 @@#define __XEN_HVM_IOMMU_H__#include <xen/iommu.h> +#include <xen/list.h> #include <asm/hvm/iommu.h> struct hvm_iommu {
@@ -28,6 +29,11 @@ struct hvm_iommu {/* iommu_ops */ const struct iommu_ops *platform_ops; + +#ifdef HAS_DEVICE_TREE +/* List of DT devices assigned to this domain */ +struct list_head dt_devices; +#endif };#endif /* __XEN_HVM_IOMMU_H__ */
xen/include/xen/iommu.h +16 -0
@@ -90,6 +90,16 @@ void iommu_read_msi_from_ire(struct msi_desc *msi_desc, struct msi_msg *msg);#define PT_IRQ_TIME_OUT MILLISECS(8)#endif /* HAS_PCI */ +#ifdef HAS_DEVICE_TREE +#include <xen/device_tree.h> + +int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev); +int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev); +int iommu_dt_domain_init (struct domain *d); +void iommu_dt_domain_destroy (struct domain *d); + +#endif /* HAS_DEVICE_TREE */ +struct page_info ;struct iommu_ops {
@@ -106,6 +116,12 @@ struct iommu_ops {int (*update_ire_from_msi)(struct msi_desc *msi_desc,struct msi_msg *msg);void (*read_msi_from_ire)(struct msi_desc *msi_desc,struct msi_msg *msg);#endif /* HAS_PCI */ +#ifdef HAS_DEVICE_TREE +int (*assign_dt_device)(struct domain *d,const struct dt_device_node *dev); +int (*reassign_dt_device)(struct domain *s,struct domain *t, +const struct dt_device_node *dev); +#endif +void (*teardown)(struct domain *d);int (*map_page)(struct domain *d,unsigned long gfn,unsigned long mfn,unsigned int flags);
Signature · 1 line
1.7.10.4
Re: [PATCH v4 14/21] xen/passthrough: iommu: Basic support of device tree assignment
xen/drivers/passthrough/device_tree.c line 2
Quoted 8 lines · Julien Grall
xen/drivers/passthrough/device_tree.c new file +2
-0@@ -0,0 +1,111 @@ +/* +* xen/drivers/passthrough/arm/device_tree.c
Mismatches the actual path. Please just drop this line.
xen/drivers/passthrough/device_tree.c line 4
Quoted 2 lines
xen/drivers/passthrough/device_tree.c new file +2
-0+* +* Code to passthrough device tree node to a guest
^a
xen/drivers/passthrough/device_tree.c line 6
Quoted 1 line
xen/drivers/passthrough/device_tree.c new file +1
-0+* TODO: This contains only necessary code to protected device with
^the devices passed to
xen/drivers/passthrough/device_tree.c line 7
Quoted 1 line
xen/drivers/passthrough/device_tree.c new file +1
-0+* dom0. It will need some updates when device passthrough will be
s/will be/is.
xen/drivers/passthrough/device_tree.c struct dt_device_node { · line 116
Quoted 6 lines
xen/drivers/passthrough/device_tree.c new file +2
-0@@ -111,6 +112,9 @@ struct dt_device_node {struct dt_device_node *next;/* TODO: Remove it. Only use to know the last children */ struct dt_device_node *allnext; +/* IOMMU specific fields */ +bool is_protected;/* Tell if the device is protected by an IOMMU */
The second comment is a bit redundant given the first command and the filed name but if you want to keep it then either s/Tell/Tells us/ or s/Tell/True/.
Apart from those nits: Acked-by: Ian Campbell <[email protected]>
Ian
Re: [PATCH v4 14/21] xen/passthrough: iommu: Basic support of device tree assignment
Quoted 28 lines · Ian Campbell
xen/drivers/passthrough/device_tree.c line 2
Quoted 8 lines · Julien Grall
xen/drivers/passthrough/device_tree.c new file +2
-0@@ -0,0 +1,111 @@ +/* +* xen/drivers/passthrough/arm/device_tree.c Mismatches the actual path. Please just drop this line.
xen/drivers/passthrough/device_tree.c line 4
Quoted 2 lines
xen/drivers/passthrough/device_tree.c new file +2
-0+* +* Code to passthrough device tree node to a guest ^axen/drivers/passthrough/device_tree.c line 6
Quoted 1 line
xen/drivers/passthrough/device_tree.c new file +1
-0+* TODO: This contains only necessary code to protected device with ^the devices passed to
xen/drivers/passthrough/device_tree.c line 7
Quoted 1 line
xen/drivers/passthrough/device_tree.c new file +1
-0+* dom0. It will need some updates when device passthrough will be s/will be/is.
Quoted 4 lines
xen/drivers/passthrough/device_tree.c new file +0
-0@@ -111,6 +112,9 @@ struct dt_device_node {struct dt_device_node *next;/* TODO: Remove it. Only use to know the last children */ struct dt_device_node *allnext;
Quoted 6 lines
xen/drivers/passthrough/device_tree.c struct dt_device_node { · line 116
Quoted 2 lines
xen/drivers/passthrough/device_tree.c new file +2
-0+/* IOMMU specific fields */ +bool is_protected;/* Tell if the device is protected by an IOMMU */ The second comment is a bit redundant given the first command and the filed name but if you want to keep it then either s/Tell/Tells us/ or s/Tell/True/.
I will drop it in the next version.
Quoted 1 line
Apart from those nits: Acked-by: Ian Campbell <[email protected]>
Thanks!
Signature · 1 line
Julien Grall
PATCH v4 15/21 xen/passthrough: Introduce IOMMU ARM architecture
In reply to Julien GrallThis patch contains the architecture to use IOMMUs on ARM. There is no IOMMU drivers on this patch.
In this implementation, IOMMU page table will be shared with the P2M.
The code will run through the device tree and will initialize every IOMMU. It's possible to have multiple IOMMUs on the same platform, but they must be handled with the same driver. For now, there is no support for using multiple iommu drivers at runtime.
Each new IOMMU drivers should contain:
static const char * const myiommu_dt_compat[] __initconst =
{
/* list of device compatible with the drivers. Will be matched with
* the "compatible" property on the device tree
*/
NULL,
};DT_DEVICE_START(myiommu, "MY IOMMU", DEVICE_IOMMU)
.compatible = myiommu_compatible, .init = myiommu_init,DT_DEVICE_END
---
Changes in v4:
- Rebase on latest Xen (hwdom series was pushed)
- Return directly iommu_dt_domain_init in arch_iommu_domain_init
- Rename hvm_iommu field into iommu
- Implement arch_iommu_check_hwdom_reqs
Changes in v3:
- Call iommu_dt_domain_{init,destroy} function in arch code
Changes in v2:
- Fix typoes in commit message
- Remove useless comment in arch/arm/setup.c
- Update copyright date to 2014
- Move iommu_dom0_init earlier
- Call iommu_assign_dt_device in map_device when the device is protected by an IOMMU
--- xen/arch/arm/Rules.mk | 1 + xen/arch/arm/domain.c | 7 ++++ xen/arch/arm/domain_build.c | 21 ++++++++-- xen/arch/arm/p2m.c | 4 ++ xen/arch/arm/setup.c | 2 + xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/arm/Makefile | 1 + xen/drivers/passthrough/arm/iommu.c | 72 ++++++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 3 +- xen/include/asm-arm/domain.h | 2 + xen/include/asm-arm/hvm/iommu.h | 10 +++++ xen/include/asm-arm/iommu.h | 36 +++++++++++++++++ 12 files changed, 156 insertions(+), 4 deletions(-) create mode 100644 xen/drivers/passthrough/arm/Makefile create mode 100644 xen/drivers/passthrough/arm/iommu.c create mode 100644 xen/include/asm-arm/hvm/iommu.h create mode 100644 xen/include/asm-arm/iommu.h
xen/arch/arm/Rules.mk +1 -0
@@ -9,6 +9,7 @@ HAS_DEVICE_TREE := y HAS_VIDEO := y HAS_ARM_HDLCD := y +HAS_PASSTHROUGH := y CFLAGS += -I$(BASEDIR)/include
xen/arch/arm/domain.c +7 -0
@@ -531,6 +531,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)if (is_hardware_domain (d) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =iommu_domain_init (d)) !=0 ) + goto fail; +return 0 ; fail:
@@ -542,6 +545,10 @@ fail:void arch_domain_destroy (struct domain *d) { +/* IOMMU page table is shared with P2M, always call +* iommu_domain_destroy() before p2m_teardown(). +*/ +iommu_domain_destroy (d);p2m_teardown (d);domain_vgic_free (d);domain_vuart_free (d);
xen/arch/arm/domain_build.c +18 -3
@@ -679,7 +679,7 @@ static int make_timer_node(const struct domain *d, void *fdt, }/* Map the device in the domain */ -static int map_device (struct domain *d,const struct dt_device_node *dev) +static int map_device (struct domain *d,struct dt_device_node *dev) {unsigned int nirq;unsigned int naddr;
@@ -694,6 +694,18 @@ static int map_device(struct domain *d, const struct dt_device_node *dev)DPRINT ("%s nirq = %d naddr = %u\n" ,dt_node_full_name (dev), nirq, naddr); +if (dt_device_is_protected (dev) ) + { +DPRINT ("%s setup iommu\n" ,dt_node_full_name (dev)); + res =iommu_assign_dt_device (d, dev); +if ( res ) + { +printk (XENLOG_ERR "Failed to setup the IOMMU for %s\n" , +dt_node_full_name (dev)); +return res; + } + } +/* Map IRQs */ for ( i =0 ; i < nirq; i++ ) {
@@ -765,7 +777,7 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) }static int handle_node (struct domain *d,struct kernel_info *kinfo, -const struct dt_device_node *node) +struct dt_device_node *node) {static const struct dt_device_match skip_matches[]__initconst = {
@@ -786,7 +798,7 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo, DT_MATCH_TIMER, { /* sentinel */ }, }; -const struct dt_device_node *child; +struct dt_device_node *child;int res;const char *name;const char *path;
@@ -1014,11 +1026,14 @@ int construct_dom0(struct domain *d)printk ("*** LOADING DOMAIN 0 ***\n" ); +iommu_hwdom_init (d); + d->max_pages = ~0U ; kinfo.unassigned_mem = dom0_mem; rc =kernel_probe (&kinfo); +if ( rc <0 )return rc;
xen/arch/arm/p2m.c +4 -0
@@ -451,6 +451,9 @@ static int apply_p2m_changes(struct domain *d,if ( flush ) { +unsigned long sgfn =paddr_to_pfn (start_gpaddr); +unsigned long egfn =paddr_to_pfn (end_gpaddr); +/* Update the VTTBR if necessary with the domain where mappings * are created. In this case it's only necessary to flush TLBs * on every CPUs with the current VMID (our domain).
@@ -459,6 +462,7 @@ static int apply_p2m_changes(struct domain *d,p2m_load_VTTBR (d);flush_tlb (); +iommu_iotlb_flush (d, sgfn, egfn - sgfn);if ( d != current->domain )p2m_load_VTTBR (current->domain);
xen/arch/arm/setup.c +2 -0
@@ -736,6 +736,8 @@ void __init start_xen(unsigned long boot_phys_offset,local_irq_enable ();local_abort_enable (); +iommu_setup (); +smp_prepare_cpus (cpus);initialize_keytable ();
xen/drivers/passthrough/Makefile +1 -0
@@ -1,6 +1,7 @@ subdir-$(x86) += vtd subdir-$(x86) += amd subdir-$(x86_64) += x86 +subdir-$(arm) += arm obj-y += iommu.o obj-$(x86) += io.o
xen/drivers/passthrough/arm/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += iommu.o
xen/drivers/passthrough/arm/iommu.c new file +72 -0
72 lines not on this page · raw message
xen/include/asm-arm/device.h +2 -1
@@ -6,7 +6,8 @@enum device_type { -DEVICE_SERIAL +DEVICE_SERIAL , +DEVICE_IOMMU , };struct device_desc {
xen/include/asm-arm/domain.h +2 -0
@@ -9,6 +9,7 @@#include <asm/vfp.h> #include <public/hvm/params.h> #include <xen/serial.h> +#include <xen/hvm/iommu.h> /* Represents state corresponding to a block of 32 interrupts */ struct vgic_irq_rank {
@@ -72,6 +73,7 @@ struct pending_irqstruct hvm_domain {uint64_t params[HVM_NR_PARAMS ]; +struct hvm_iommu iommu; } __cacheline_aligned;#ifdef CONFIG_ARM_64
xen/include/asm-arm/hvm/iommu.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef __ASM_ARM_HVM_IOMMU_H_ +#define __ASM_ARM_HVM_IOMMU_H_ + +struct arch_hvm_iommu +{ +/* Private information for the IOMMU drivers */ +void *priv; +}; + +#endif /* __ASM_ARM_HVM_IOMMU_H_ */
xen/include/asm-arm/iommu.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; if not, write to the Free Software Foundation, Inc., 59 Temple +* Place - Suite 330, Boston, MA 02111-1307 USA. +*/ +#ifndef __ARCH_ARM_IOMMU_H__ +#define __ARCH_ARM_IOMMU_H__ + +/* Always share P2M Table between the CPU and the IOMMU */ +#define iommu_use_hap_pt (d) (1) +#define domain_hvm_iommu (d) (&d->arch.hvm_domain.iommu) + +const struct iommu_ops *iommu_get_ops (void ); +void __init iommu_set_ops (const struct iommu_ops *ops); + +int __init iommu_hardware_setup (void ); + +#endif /* __ARCH_ARM_IOMMU_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
Re: [PATCH v4 15/21] xen/passthrough: Introduce IOMMU ARM architecture
Quoted 4 lines · Julien Grall
kinfo.unassigned_mem = dom0_mem; rc = kernel_probe(&kinfo);+
Please drop this new blank line.
xen/drivers/passthrough/arm/iommu.c line 2
Quoted 12 lines
if ( rc < 0 ) return rc;xen/drivers/passthrough/arm/iommu.c new file +2
-0@@ -0,0 +1,72 @@ +/* +* xen/drivers/passthrough/arm/iommu.c
At least the path is right this time, but IMHO all these can be dropped.
xen/drivers/passthrough/arm/iommu.c line 37
Quoted 6 lines
xen/drivers/passthrough/arm/iommu.c new file +6
-0+void __init iommu_set_ops (const struct iommu_ops *ops) +{ +BUG_ON (ops ==NULL ); + +if ( iommu_ops && iommu_ops != ops ) +printk ("WARNING: IOMMU ops already set to a different value\n" );
"WARNING: Cannot set IOMMU ops, already set to a different value" ?
Other than those nits: Acked-by: Ian Campbell <[email protected]>
Re: [PATCH v4 15/21] xen/passthrough: Introduce IOMMU ARM architecture
Quoted 12 lines · Ian Campbell
Quoted 4 lines · Julien Grall
kinfo.unassigned_mem = dom0_mem; rc = kernel_probe(&kinfo);+
Please drop this new blank line.
Quoted 3 lines
if ( rc < 0 ) return rc;
Quoted 10 lines
xen/drivers/passthrough/arm/iommu.c line 2
Quoted 8 lines
xen/drivers/passthrough/arm/iommu.c new file +2
-0@@ -0,0 +1,72 @@ +/* +* xen/drivers/passthrough/arm/iommu.c At least the path is right this time, but IMHO all these can be dropped.
I was just following the header comment format as on the other files.
Anyway, I will drop it.
Quoted 10 lines
xen/drivers/passthrough/arm/iommu.c line 37
Quoted 6 lines
xen/drivers/passthrough/arm/iommu.c new file +6
-0+void __init iommu_set_ops (const struct iommu_ops *ops) +{ +BUG_ON (ops ==NULL ); + +if ( iommu_ops && iommu_ops != ops ) +printk ("WARNING: IOMMU ops already set to a different value\n" );"WARNING: Cannot set IOMMU ops, already set to a different value" ?
Other than those nits: Acked-by: Ian Campbell <[email protected]>
Thanks!
Signature · 1 line
Julien Grall
PATCH v4 16/21 MAINTAINERS: Add drivers/passthrough/arm
In reply to Julien GrallAdd the ARM IOMMU directory to "ARM ARCHITECTURE" part
--- MAINTAINERS | 1 + 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
@@ -134,6 +134,7 @@ F: xen/drivers/char/dt-uart.c F: xen/drivers/char/exynos4210-uart.c F: xen/drivers/char/omap-uart.c F: xen/drivers/char/pl011.c +F: xen/drivers/passthrough/arm CPU POOLS M: Juergen Gross <[email protected]>
Signature · 1 line
1.7.10.4
Re: [PATCH v4 16/21] MAINTAINERS: Add drivers/passthrough/arm
MAINTAINERS F: xen/drivers/char/dt-uart.c · line 137
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
MAINTAINERS +1
-0@@ -134,6 +134,7 @@ F: xen/drivers/char/dt-uart.c F: xen/drivers/char/exynos4210-uart.c F: xen/drivers/char/omap-uart.c F: xen/drivers/char/pl011.c +F: xen/drivers/passthrough/arm
This needs a trailing slash, I think.
Jan
Re: [PATCH v4 16/21] MAINTAINERS: Add drivers/passthrough/arm
Hi Jan,
Quoted 10 lines · Jan Beulich
MAINTAINERS F: xen/drivers/char/dt-uart.c · line 137
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
MAINTAINERS +1
-0@@ -134,6 +134,7 @@ F: xen/drivers/char/dt-uart.c F: xen/drivers/char/exynos4210-uart.c F: xen/drivers/char/omap-uart.c F: xen/drivers/char/pl011.c +F: xen/drivers/passthrough/armThis needs a trailing slash, I think.
The trailing is not necessary (it works correctly for me). I can add it for consistency.
While I was testing this patch, I've noticed that get_maintainer.pl is considering that you maintain the directory passthrough/arm with Ian C., Stefano and Tim.
Signature · 1 line
Julien Grall
Re: [PATCH v4 16/21] MAINTAINERS: Add drivers/passthrough/arm
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 17:02, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
MAINTAINERS F: xen/drivers/char/dt-uart.c · line 137
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
MAINTAINERS +1
-0@@ -134,6 +134,7 @@ F: xen/drivers/char/dt-uart.c F: xen/drivers/char/exynos4210-uart.c F: xen/drivers/char/omap-uart.c F: xen/drivers/char/pl011.c +F: xen/drivers/passthrough/armThis needs a trailing slash, I think.
Quoted 2 lines
The trailing is not necessary (it works correctly for me). I can add it for consistency.
Please do, to clarify this is a directory.
Quoted 3 lines
While I was testing this patch, I've noticed that get_maintainer.pl is considering that you maintain the directory passthrough/arm with Ian C., Stefano and Tim.
Likely because you don't also add
X: xen/drivers/passthrough/arm/
to the generic IOMMU section.
Jan
Re: [PATCH v4 16/21] MAINTAINERS: Add drivers/passthrough/arm
Quoted 22 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 17:02, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
MAINTAINERS F: xen/drivers/char/dt-uart.c · line 137
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
MAINTAINERS +1
-0@@ -134,6 +134,7 @@ F: xen/drivers/char/dt-uart.c F: xen/drivers/char/exynos4210-uart.c F: xen/drivers/char/omap-uart.c F: xen/drivers/char/pl011.c +F: xen/drivers/passthrough/armThis needs a trailing slash, I think.
Quoted 2 lines
The trailing is not necessary (it works correctly for me). I can add it for consistency.
Please do, to clarify this is a directory.
Quoted 3 lines
While I was testing this patch, I've noticed that get_maintainer.pl is considering that you maintain the directory passthrough/arm with Ian C., Stefano and Tim.
Quoted 5 lines
Likely because you don't also add
X: xen/drivers/passthrough/arm/
to the generic IOMMU section.
Thanks, I use it in the next version.
Signature · 1 line
Julien Grall
PATCH v4 17/21 xen/arm: Don't give IOMMU devices to dom0 when iommu is disabled
In reply to Julien GrallWhen iommu={disable,off,no,false} is given to Xen command line, the IOMMU framework won't specify that the device shouldn't be passthrough to DOM0.
---
Changes in v2:
- Patch added
--- xen/arch/arm/device.c | 15 +++++++++++++++ xen/arch/arm/domain_build.c | 10 ++++++++++ xen/include/asm-arm/device.h | 10 ++++++++++ 3 files changed, 35 insertions(+)
xen/arch/arm/device.c +15 -0
@@ -67,6 +67,21 @@ int __init device_init(struct dt_device_node *dev, enum device_type type,return -EBADF ; } +enum device_type device_get_type (const struct dt_device_node *dev) +{ +const struct device_desc *desc; + +ASSERT (dev !=NULL ); + +for ( desc = _sdevice; desc != _edevice; desc++ ) + { +if (device_is_compatible (desc, dev) ) +return desc->type; + } + +return DEVICE_UNKNOWN ; +} +/* * Local variables: * mode: C
xen/arch/arm/domain_build.c +10 -0
@@ -11,6 +11,7 @@#include <xen/device_tree.h> #include <xen/libfdt/libfdt.h> #include <xen/guest_access.h> +#include <asm/device.h> #include <asm/setup.h> #include <asm/platform.h> #include <asm/psci.h>
@@ -833,6 +834,15 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,return 0 ; } +/* Even if the IOMMU device is not used by Xen, it should not be +* passthrough to DOM0 +*/ +if (device_get_type (node) ==DEVICE_IOMMU ) + { +DPRINT (" IOMMU, skip it\n" ); +return 0 ; + } +/* * Some device doesn't need to be mapped in Xen: * - Memory: the guest will see a different view of memory. It will
xen/include/asm-arm/device.h +10 -0
@@ -8,6 +8,8 @@ enum device_type {DEVICE_SERIAL ,DEVICE_IOMMU , +/* Use for error */ + DEVICE_UNKNOWN, }; struct device_desc {
@@ -32,6 +34,14 @@ struct device_desc {int __init device_init (struct dt_device_node *dev,enum device_type type,const void *data); +/** +* device_get_type - Get the type of the device +* @dev: device to match +* +* Return the device type on success or DEVICE_ANY on failure +*/ +enum device_type device_get_type (const struct dt_device_node *dev); +#define DT_DEVICE_START (_name, _namestr, _type) \ static const struct device_desc __dev_desc_##_name __used \ __attribute__((__section__(".dev.info"))) = { \
Signature · 1 line
1.7.10.4
PATCH v4 18/21 xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
In reply to Julien GrallSome IOMMU doesn'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 callback that will retrieve the IOMMU feature 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 v4:
- Patch added
--- xen/arch/arm/p2m.c | 24 ++++++++++++++++++------ xen/drivers/passthrough/iommu.c | 11 +++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 34 insertions(+), 6 deletions(-)
xen/arch/arm/p2m.c +18 -6
@@ -274,6 +274,18 @@ enum p2m_operation { CACHEFLUSH, }; +static void unmap_coherent_domain_page (struct domain *d,const void *va) +{ +/* Some IOMMU doesn'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 +*/ +if (need_iommu (d) && !iommu_has_feature (d,IOMMU_FEAT_COHERENT_WALK ) ) +clean_xen_dcache_va_range (va,PAGE_SIZE ); + +unmap_domain_page (va); +} + static int apply_p2m_changes(struct domain *d, enum p2m_operation op, paddr_t start_gpaddr,
@@ -301,7 +313,7 @@ static int apply_p2m_changes(struct domain *d, {if ( cur_first_page !=p2m_first_level_index (addr) ) { -if ( first )unmap_domain_page (first); +if ( first )unmap_coherent_domain_page (d, first); first =p2m_map_first (p2m, addr);if ( !first ) {
@@ -331,7 +343,7 @@ static int apply_p2m_changes(struct domain *d,if ( cur_first_offset !=first_table_offset (addr) ) { -if (second)unmap_domain_page (second); +if (second)unmap_coherent_domain_page (d, second); second =map_domain_page (first[first_table_offset (addr)].p2m.base); cur_first_offset =first_table_offset (addr); }
@@ -357,7 +369,7 @@ static int apply_p2m_changes(struct domain *d,if ( cur_second_offset !=second_table_offset (addr) ) {/* map third level */ -if (third)unmap_domain_page (third); +if (third)unmap_coherent_domain_page (d, third); third =map_domain_page (second[second_table_offset (addr)].p2m.base); cur_second_offset =second_table_offset (addr); }
@@ -480,9 +492,9 @@ static int apply_p2m_changes(struct domain *d, rc =0 ; out: -if (third)unmap_domain_page (third); -if (second)unmap_domain_page (second); -if (first)unmap_domain_page (first); +if (third)unmap_coherent_domain_page (d, third); +if (second)unmap_coherent_domain_page (d, second); +if (first)unmap_coherent_domain_page (d, first);spin_unlock (&p2m->lock);
xen/drivers/passthrough/iommu.c +11 -0
@@ -344,6 +344,17 @@ void iommu_crash_shutdown(void) iommu_enabled = iommu_intremap =0 ; } +bool_t iommu_has_feature (struct domain *d,uint32_t feature) +{ +const struct iommu_ops *ops =domain_hvm_iommu (d)->platform_ops; +uint32_t features =0 ; + +if ( iommu_enabled && ops && ops->features ) + features = ops->features (d); + +return !!(features & feature); +} +static void iommu_dump_p2m_table (unsigned char key) {struct domain *d;
xen/include/xen/iommu.h +5 -0
@@ -67,6 +67,10 @@ 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); +#define IOMMU_FEAT_COHERENT_WALK (1U<<0) +bool_t iommu_has_feature (struct domain *d,uint32_t feature); + +#ifdef HAS_PCI void pt_pci_init (void );
@@ -139,6 +143,7 @@ struct iommu_ops {void (*iotlb_flush)(struct domain *d,unsigned long gfn,unsigned int page_count);void (*iotlb_flush_all)(struct domain *d);void (*dump_p2m_table)(struct domain *d); +uint32_t (*features)(struct domain *d); };void iommu_suspend (void );
Signature · 1 line
1.7.10.4
Re: [PATCH v4 18/21] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Quoted 26 lines · Julien Grall
Some IOMMU doesn'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 callback that will retrieve the IOMMU feature 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]>---
Changes in v4:
- Patch added--- xen/arch/arm/p2m.c | 24 ++++++++++++++++++------ xen/drivers/passthrough/iommu.c | 11 +++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 34 insertions(+), 6 deletions(-)xen/arch/arm/p2m.c +0
-0
xen/arch/arm/p2m.c enum p2m_operation { · line 279
Quoted 6 lines
xen/arch/arm/p2m.c +3
-0@@ -274,6 +274,18 @@ enum p2m_operation { CACHEFLUSH, }; +static void unmap_coherent_domain_page (struct domain *d,const void *va) +{ +/* Some IOMMU doesn't support coherent PT walk. When the p2m is
"don't support"
xen/arch/arm/p2m.c enum p2m_operation { · line 284
Quoted 5 lines
xen/arch/arm/p2m.c +5
-0+* shared with the CPU, Xen has to make sure that the PT changes have +* reached the memory +*/ +if (need_iommu (d) && !iommu_has_feature (d,IOMMU_FEAT_COHERENT_WALK ) ) +clean_xen_dcache_va_range (va,PAGE_SIZE );
This is a fairly large hammer when you might only have touched a few bytes, if any, in the page.
Wouldn't it be better to do this is write_pte, or just after the calls to write_pte?
iommu_has_feature has a lot of callbacks -- worth calling once in apply_p2m_changes?
Ian
Re: [PATCH v4 18/21] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Quoted 25 lines · Ian Campbell
Quoted 10 lines
xen/arch/arm/p2m.c | 24 ++++++++++++++++++------ xen/drivers/passthrough/iommu.c | 11 +++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 34 insertions(+), 6 deletions(-)xen/arch/arm/p2m.c +0
-0xen/arch/arm/p2m.c enum p2m_operation { · line 279
Quoted 6 lines
xen/arch/arm/p2m.c +3
-0@@ -274,6 +274,18 @@ enum p2m_operation { CACHEFLUSH, }; +static void unmap_coherent_domain_page (struct domain *d,const void *va) +{ +/* Some IOMMU doesn't support coherent PT walk. When the p2m is "don't support"
xen/arch/arm/p2m.c enum p2m_operation { · line 284
Quoted 5 lines
xen/arch/arm/p2m.c +5
-0+* shared with the CPU, Xen has to make sure that the PT changes have +* reached the memory +*/ +if (need_iommu (d) && !iommu_has_feature (d,IOMMU_FEAT_COHERENT_WALK ) ) +clean_xen_dcache_va_range (va,PAGE_SIZE );
Quoted 5 lines
This is a fairly large hammer when you might only have touched a few bytes, if any, in the page.
Wouldn't it be better to do this is
write_pte, or just after the calls towrite_pte?
I didn't think that the cache flush on a page was divided in small chunks.
Quoted 2 lines
iommu_has_featurehas a lot of callbacks -- worth calling once inapply_p2m_changes?
I will create a write_pte_coherent helpers which will take in parameter a boolean to know if we need to flush the cache or not.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v4 18/21] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
In reply to Julien GrallI forgot to cc Jan and Xiantao on this patch.
Quoted 130 lines · Julien Grall
Some IOMMU doesn'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 callback that will retrieve the IOMMU feature 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]>---
Changes in v4:
- Patch added--- xen/arch/arm/p2m.c | 24 ++++++++++++++++++------ xen/drivers/passthrough/iommu.c | 11 +++++++++++ xen/include/xen/iommu.h | 5 +++++ 3 files changed, 34 insertions(+), 6 deletions(-)xen/arch/arm/p2m.c +18
-6@@ -274,6 +274,18 @@ enum p2m_operation { CACHEFLUSH, }; +static void unmap_coherent_domain_page (struct domain *d,const void *va) +{ +/* Some IOMMU doesn'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 +*/ +if (need_iommu (d) && !iommu_has_feature (d,IOMMU_FEAT_COHERENT_WALK ) ) +clean_xen_dcache_va_range (va,PAGE_SIZE ); + +unmap_domain_page (va); +} + static int apply_p2m_changes(struct domain *d, enum p2m_operation op, paddr_t start_gpaddr,@@ -301,7 +313,7 @@ static int apply_p2m_changes(struct domain *d, {if ( cur_first_page !=p2m_first_level_index (addr) ) { -if ( first )unmap_domain_page (first); +if ( first )unmap_coherent_domain_page (d, first); first =p2m_map_first (p2m, addr);if ( !first ) {@@ -331,7 +343,7 @@ static int apply_p2m_changes(struct domain *d,if ( cur_first_offset !=first_table_offset (addr) ) { -if (second)unmap_domain_page (second); +if (second)unmap_coherent_domain_page (d, second); second =map_domain_page (first[first_table_offset (addr)].p2m.base); cur_first_offset =first_table_offset (addr); }@@ -357,7 +369,7 @@ static int apply_p2m_changes(struct domain *d,if ( cur_second_offset !=second_table_offset (addr) ) {/* map third level */ -if (third)unmap_domain_page (third); +if (third)unmap_coherent_domain_page (d, third); third =map_domain_page (second[second_table_offset (addr)].p2m.base); cur_second_offset =second_table_offset (addr); }@@ -480,9 +492,9 @@ static int apply_p2m_changes(struct domain *d, rc =0 ; out: -if (third)unmap_domain_page (third); -if (second)unmap_domain_page (second); -if (first)unmap_domain_page (first); +if (third)unmap_coherent_domain_page (d, third); +if (second)unmap_coherent_domain_page (d, second); +if (first)unmap_coherent_domain_page (d, first);spin_unlock (&p2m->lock);xen/drivers/passthrough/iommu.c +11
-0@@ -344,6 +344,17 @@ void iommu_crash_shutdown(void) iommu_enabled = iommu_intremap =0 ; } +bool_t iommu_has_feature (struct domain *d,uint32_t feature) +{ +const struct iommu_ops *ops =domain_hvm_iommu (d)->platform_ops; +uint32_t features =0 ; + +if ( iommu_enabled && ops && ops->features ) + features = ops->features (d); + +return !!(features & feature); +} +static void iommu_dump_p2m_table (unsigned char key) {struct domain *d;xen/include/xen/iommu.h +5
-0@@ -67,6 +67,10 @@ 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); +#define IOMMU_FEAT_COHERENT_WALK (1U<<0) +bool_t iommu_has_feature (struct domain *d,uint32_t feature); + +#ifdef HAS_PCI void pt_pci_init (void );@@ -139,6 +143,7 @@ struct iommu_ops {void (*iotlb_flush)(struct domain *d,unsigned long gfn,unsigned int page_count);void (*iotlb_flush_all)(struct domain *d);void (*dump_p2m_table)(struct domain *d); +uint32_t (*features)(struct domain *d); };void iommu_suspend (void );
Signature · 1 line
Julien Grall
Re: [PATCH v4 18/21] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
In reply to Julien Grallxen/drivers/passthrough/iommu.c void iommu_crash_shutdown(void) · line 356
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +10
-0+bool_t iommu_has_feature (struct domain *d,uint32_t feature) +{ +const struct iommu_ops *ops =domain_hvm_iommu (d)->platform_ops; +uint32_t features =0 ; + +if ( iommu_enabled && ops && ops->features ) + features = ops->features (d); + +return !!(features & feature); +}
That's slightly strange a feature check: Passing in a bit mask allows the caller to set more than one bit, with obvious ambiguity in what this would mean. I'd suggest making this a bit position (with individual bits defined via enumeration), at once hiding from the generic caller whether eventually there might be more than 32 features defined.
Jan
Re: [PATCH v4 18/21] xen/arm: p2m: Clean cache PT when the IOMMU doesn't support coherent walk
Hi Jan,
Quoted 17 lines · Jan Beulich
xen/drivers/passthrough/iommu.c void iommu_crash_shutdown(void) · line 356
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 22.04.14 at 15:14, <[email protected]> wrote:
xen/drivers/passthrough/iommu.c +10
-0+bool_t iommu_has_feature (struct domain *d,uint32_t feature) +{ +const struct iommu_ops *ops =domain_hvm_iommu (d)->platform_ops; +uint32_t features =0 ; + +if ( iommu_enabled && ops && ops->features ) + features = ops->features (d); + +return !!(features & feature); +}That's slightly strange a feature check: Passing in a bit mask allows the caller to set more than one bit, with obvious ambiguity in what this would mean. I'd suggest making this a bit position (with individual bits defined via enumeration), at once hiding from the generic caller whether eventually there might be more than 32 features defined.
I will create a separate patch to add iommu_has_feature. It will be more clearer.
Regards,
Signature · 1 line
Julien Grall
PATCH v4 19/21 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.
---
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 v4 19/21] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 7 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.
Go on to say:
... and therefore we know that RAM and devices cannot clash (or something).
Quoted 1 line
Signed-off-by Julien Grall <[email protected]>
With that: Acked-by: Ian Campbell <[email protected]>
Re: [PATCH v4 19/21] xen/arm: grant: Add another entry to map MFN 1:1 in dom0 p2m
Quoted 7 lines · Ian Campbell
Quoted 6 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.
Quoted 5 lines
Quoted 1 line
This is valid because DOM0 has its memory mapped 1:1.
Go on to say:
... and therefore we know that RAM and devices cannot clash (or something).
Your sentence sounds good. I will update the commit message with it.
Quoted 3 lines
Quoted 1 line
Signed-off-by Julien Grall <[email protected]>With that: Acked-by: Ian Campbell <[email protected]>
Thanks!
Signature · 1 line
Julien Grall
PATCH v4 20/21 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 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 | 1750 ++++++++++++++++++++++++++++++++++ xen/include/xen/iommu.h | 3 + 3 files changed, 1754 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 +1750 -0
1,750 lines not on this page · raw message
xen/include/xen/iommu.h +3 -0
@@ -40,6 +40,9 @@ extern bool_t amd_iommu_perdev_intremap;#define PAGE_MASK_4K (((u64)-1) << PAGE_SHIFT_4K)#define PAGE_ALIGN_4K (addr) (((addr) + PAGE_SIZE_4K - 1) & PAGE_MASK_4K) +#define PAGE_SHIFT_64K (16) +#define PAGE_SIZE_64K (1UL << PAGE_SHIFT_64K) +int iommu_setup (void );int iommu_add_device (struct pci_dev *pdev);
Signature · 1 line
1.7.10.4
Re: [PATCH v4 20/21] drivers/passthrough: arm: Add support for SMMU drivers
Quoted 11 lines · Julien Grall
This patch add support for ARM architected SMMU driver. It's based on the linux drivers (
drivers/iommu/arm-smmu) commit89ac23cd.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
Quoted 8 lines
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 translationSigned-off-by Julien Grall<[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>
PATCH v4 21/21 xen/arm: Add the property "protected-devices" in the hypervisor node
In reply to Julien GrallDOM0 is using the swiotlb to bounce DMA. When the device is protected by an IOMMU, we can safely bypass the swiotlb.
We can't disable the swiotlb for all devices because some of them may not be protected. Only Xen is able to know if an IOMMU protects the device The new property "protected-devices" is a list of device phandles protected by an IOMMU.
---
This patch *MUST NOT* be applied until we agreed on a device binding the device tree folks.
Changes in v4:
- Explained why dt_devlocks is not needed
- Renamed _cells into cells_iter
- next_assigned was renamed into domain_list
- Update commit message to reflect the usage of this property
Changes in v2:
- Patch added
--- xen/arch/arm/domain_build.c | 52 ++++++++++++++++++++++++++++++++++++++----- xen/arch/arm/kernel.h | 3 +++ 2 files changed, 49 insertions(+), 6 deletions(-)
xen/arch/arm/domain_build.c +46 -6
@@ -320,19 +320,22 @@ static int make_memory_node(const struct domain *d,return res; } -static int make_hypervisor_node (struct domain *d, -void *fdt,const struct dt_device_node *parent) +static int make_hypervisor_node (struct domain *d,struct kernel_info *kinfo, +const struct dt_device_node *parent) {const char compat[] = "xen,xen-"__stringify(XEN_VERSION)"."__stringify(XEN_SUBVERSION)"\0""xen,xen" ;__be32 reg[4 ];gic_interrupt_t intr; -__be32 *cells; +__be32 *cells, *cells_iter;int res;int addrcells =dt_n_addr_cells (parent);int sizecells =dt_n_size_cells (parent);paddr_t gnttab_start, gnttab_size; +const struct dt_device_node *dev; +struct hvm_iommu *hd =domain_hvm_iommu (d); +void *fdt = kinfo->fdt;DPRINT ("Create hypervisor node\n" );
@@ -380,6 +383,40 @@ static int make_hypervisor_node(struct domain *d,if ( res )return res; +if ( kinfo->num_dev_protected ) + { +/* Don't need to take dtdevs_lock here, because DOM0 building is +* done with only 1 CPU online */ + cells =xmalloc_array (__be32, kinfo->num_dev_protected * +dt_size_to_cells (sizeof (dt_phandle))); +if ( !cells ) +return -FDT_ERR_XEN (ENOMEM ); + + cells_iter = cells; + +DPRINT (" List of protected devices\n" ); +list_for_each_entry ( dev, &hd->dt_devices, domain_list ) + { +DPRINT (" - %s\n" ,dt_node_full_name (dev)); +if ( !dev->phandle ) + { +printk (XENLOG_ERR "Unable to handle protected device (%s)" +"with no phandle" ,dt_node_full_name (dev)); +xfree (cells); +return -FDT_ERR_XEN (EINVAL ); + } +dt_set_cell (&cells_iter,dt_size_to_cells (sizeof (dt_phandle)), + dev->phandle); + } + + res =fdt_property (fdt,"protected-devices" , cells, +sizeof (dt_phandle) * kinfo->num_dev_protected); + +xfree (cells); +if ( res ) +return res; + } + res =fdt_end_node (fdt);return res;
@@ -680,7 +717,8 @@ static int make_timer_node(const struct domain *d, void *fdt, }/* Map the device in the domain */ -static int map_device (struct domain *d,struct dt_device_node *dev) +static int map_device (struct domain *d,struct kernel_info *kinfo, +struct dt_device_node *dev) {unsigned int nirq;unsigned int naddr;
@@ -705,6 +743,7 @@ static int map_device(struct domain *d, struct dt_device_node *dev) dt_node_full_name(dev));return res; } + kinfo->num_dev_protected++; }/* Map IRQs */
@@ -854,7 +893,7 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,if ( !dt_device_type_is_equal (node,"memory" ) &&dt_device_is_available (node) ) { - res =map_device (d, node); + res =map_device (d, kinfo, node);if ( res )return res;
@@ -885,7 +924,7 @@ static int handle_node(struct domain *d, struct kernel_info *kinfo,if ( node == dt_host ) { - res =make_hypervisor_node (d, kinfo->fdt, node); + res =make_hypervisor_node (d, kinfo, node);if ( res )return res;
@@ -1040,6 +1079,7 @@ int construct_dom0(struct domain *d) d->max_pages = ~0U ; + kinfo.num_dev_protected =0 ; kinfo.unassigned_mem = dom0_mem; rc =kernel_probe (&kinfo);
xen/arch/arm/kernel.h +3 -0
@@ -18,6 +18,9 @@ struct kernel_info {paddr_t unassigned_mem;/* RAM not (yet) assigned to a bank */ struct dt_mem_info mem; +/* Number of devices protected by an IOMMU */ +unsigned int num_dev_protected; +/* kernel entry point */ paddr_t entry;
Signature · 1 line
1.7.10.4
Quoted 8 lines · Julien Grall
Hello
This is the fourth version of this serie to add support for IOMMU on ARM. It also adds ARM SMMU driver which is used for instance on Midway.
The ARM IOMMU architecture assumes that page table is shared between the processor and each IOMMU.
Quoted 8 lines
Major changes in v4:
- Support upstream Linux DOM0 without any change (see patch #18)
- Support 40bits address space in the SMMU drivers
- Rebase on the latest Xen (some patches clashed with the hwdom series)The patch series is divided following:
- #1-#4: Small fixes on ARM code
- #5: Fix grant-table with IOMMU. Will be necessary for ARM later
I applied up to here (wrt #4 and flush_tlb_domain(d) I figured that would be a follow up patch).
Quoted 1 line
- #6-#8: Small changes in amd and vtd IOMMU drivers
#6 was acked but since the other amd change in #7 wasn't I thought I would wait and take these all in one go.
Quoted 1 line
- #10-#11: Add new device tree helpers
I applied these.
The rest I think had comments and I couldn't see anything else which could go in independently.
Ian.
Quoted 4 lines · Ian Campbell
Quoted 1 line
- #6-#8: Small changes in amd and vtd IOMMU drivers
#6 was acked but since the other amd change in #7 wasn't I thought I would wait and take these all in one go.
I'm not sure why Suravee acked patch #6 but not #7... I will ping him again.
Quoted 6 lines
Quoted 1 line
- #10-#11: Add new device tree helpers
I applied these.
The rest I think had comments and I couldn't see anything else which could go in independently.
Thanks!
Signature · 1 line
Julien Grall
Quoted 2 lines · Ian Campbell
Quoted 1 line
- #10-#11: Add new device tree helpers
I applied these.
I wrote by mistake #10-#11 instead of #9-10. It seems you've only applied patch #9 and #10.
Signature · 1 line
Julien Grall
Quoted 6 lines · Julien Grall
Quoted 2 lines · Ian Campbell
Quoted 1 line
- #10-#11: Add new device tree helpers
I applied these.
I wrote by mistake #10-#11 instead of #9-10. It seems you've only applied patch #9 and #10.
I applied the new device tree helpers, whichever patch numbers those were.
Ian.
Quoted 10 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 2 lines · Ian Campbell
Quoted 1 line
- #10-#11: Add new device tree helpers
I applied these.
I wrote by mistake #10-#11 instead of #9-10. It seems you've only applied patch #9 and #10.
I applied the new device tree helpers, whichever patch numbers those were.
Are you sure? I can't find "xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle" in xengit/staging
Regards,
Signature · 1 line
Julien Grall
Quoted 6 lines · Julien Grall
Quoted 5 lines · Ian Campbell
Quoted 4 lines · Julien Grall
Quoted 2 lines · Ian Campbell
Quoted 1 line
- #10-#11: Add new device tree helpers
I applied these.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I wrote by mistake #10-#11 instead of #9-10. It seems you've only applied patch #9 and #10.
I applied the new device tree helpers, whichever patch numbers those were.
Are you sure? I can't find "xen/dts: Add
dt_parse_phandle_with_argsanddt_parse_phandle" in xengit/staging
Hrm, looks like I Only picked up the dt_bool one somehow.
I'll pick up "Add dt_parse_phandle_with_args and dt_parse_phandle" now.
Ian