IOMMU support for ARM
v2 cover IOMMU support for ARM
Hello,
This is the second version of the patch series to add support for IOMMU on ARM. It also add ARM SMMU driver which is used for instance on Midway.
The IOMMU architecture for ARM is relying on the page table is shared between the processor and each IOMMU.
The patch series is divided following:
- #1: fixing grant-table with IOMMU. Will be necessary for ARM later
- #2-#3: Make static some vtd functions
- #4-#5: Adding new device tree functions
- #6-#9: Prepare IOMMU code to add support for ARM
- #10: Adding basic device tree assignment support
- #11-#15: Add IOMMU architecture for ARM
- #15: Add SMMU drivers
For now the 1:1 workaround is not removed because a same platform can have DMA-capable device which are under an IOMMU and some not.
Major changes for the RFC:
- Adding basic device tree assignment support
- Draft a binding to notify DOM0 which device is protected
- Couple of fixes when the IOMMU is disabled or there is no IOMMU support for the board.
This series has also dependency on:
- early printk series :
http://lists.xen.org/archives/html/xen-devel/2014-01/msg00288.html
- interrupt series:
http://lists.xen.org/archives/html/xen-devel/2014-01/msg02139.html
- few bug fixes on the previous series
A working tree can be found here:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch smmu-v2
Any comments, questions are welcomed.
Sincerely yours,
Julien Grall (15):
xen/common: grant-table: only call IOMMU if paging mode translate is
disabled
xen/passthrough: vtd: Don't export iommu_domain_teardown xen/passthrough: vtd: Don't export iommu_set_pgd
xen/dts: Add dt_property_read_bool
xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle xen/passthrough: rework dom0_pvh_reqs to use it also on ARM xen/passthrough: iommu: Don't need to map dom0 page when the PT is
shared
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: Add the property "protected-devices" in the hypervisor node drivers/passthrough: arm: Add support for SMMU drivers
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 | 78 +- xen/arch/arm/kernel.h | 3 + xen/arch/arm/p2m.c | 4 + 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 | 2 +- xen/drivers/passthrough/amd/iommu_guest.c | 8 +- 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 | 65 + xen/drivers/passthrough/arm/smmu.c | 1736 +++++++++++++++++++++++++++ xen/drivers/passthrough/device_tree.c | 106 ++ xen/drivers/passthrough/iommu.c | 542 +-------- xen/drivers/passthrough/pci.c | 437 +++++++ xen/drivers/passthrough/vtd/iommu.c | 84 +- xen/drivers/passthrough/x86/Makefile | 1 + xen/drivers/passthrough/x86/iommu.c | 106 ++ 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-x86/hvm/iommu.h | 29 + xen/include/asm-x86/iommu.h | 50 + xen/include/xen/device_tree.h | 89 ++ xen/include/xen/hvm/iommu.h | 33 +- xen/include/xen/iommu.h | 71 +- 36 files changed, 3148 insertions(+), 679 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 v2 1/15 xen/common: grant-table: only call IOMMU if paging mode translate is disabled
Quoted 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 v2 2/15 xen/passthrough: vtd: Don't export iommu_domain_teardown
In reply to Julien Gralliommu_domain_teardown is only used internally inxen/drivers/passthrough/vtd/iommu.c
--- xen/drivers/passthrough/vtd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -1701,7 +1701,7 @@ static int reassign_device_ownership(return ret; } -void iommu_domain_teardown (struct domain *d) +static void iommu_domain_teardown (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);
Signature · 1 line
1.7.10.4
Re: [PATCH v2 02/15] xen/passthrough: vtd: Don't export iommu_domain_teardown
Quoted 17 lines
Quoted 1 line
Quoted 1 line · Julien Grall
iommu_domain_teardownis only used internally inxen/drivers/passthrough/vtd/iommu.cSigned-off-by Julien Grall <[email protected]>Acked-by Ian Cambell <[email protected]>Cc Xiantao Zhang <[email protected]>--- xen/drivers/passthrough/vtd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.c +0
-0
xen/drivers/passthrough/vtd/iommu.c static int reassign_device_ownership( · line 1707
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -1701,7 +1701,7 @@ static int reassign_device_ownership(return ret; } -void iommu_domain_teardown (struct domain *d) +static void iommu_domain_teardown (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);
Please build-test your changes - this was lacking the removal of the function's declaration from xen/iommu.h.
Jan
Re: [PATCH v2 02/15] xen/passthrough: vtd: Don't export iommu_domain_teardown
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Julien Grall
iommu_domain_teardownis only used internally inxen/drivers/passthrough/vtd/iommu.cSigned-off-by Julien Grall <[email protected]>Acked-by Ian Cambell <[email protected]>Cc Xiantao Zhang <[email protected]>--- xen/drivers/passthrough/vtd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.c +0
-0@@ -1701,7 +1701,7 @@ static int reassign_device_ownership(return ret; }
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c static int reassign_device_ownership( · line 1707
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +1
-1-void iommu_domain_teardown (struct domain *d) +static void iommu_domain_teardown (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);Please build-test your changes - this was lacking the removal of the function's declaration from
xen/iommu.h.
Actually I did the build test on x86 ... By mistake I remove the function's declaration in the wrong patch "xen/passthrough: iommu: Split generic IOMMU code".
I will fix it in the next patch series.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 02/15] xen/passthrough: vtd: Don't export iommu_domain_teardown
Quoted 31 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Julien Grall
iommu_domain_teardownis only used internally inxen/drivers/passthrough/vtd/iommu.cSigned-off-by Julien Grall <[email protected]>Acked-by Ian Cambell <[email protected]>Cc Xiantao Zhang <[email protected]>--- xen/drivers/passthrough/vtd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.c +0
-0@@ -1701,7 +1701,7 @@ static int reassign_device_ownership(return ret; }Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c static int reassign_device_ownership( · line 1707
Quoted 5 lines
xen/drivers/passthrough/vtd/iommu.c +1
-1-void iommu_domain_teardown (struct domain *d) +static void iommu_domain_teardown (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);Please build-test your changes - this was lacking the removal of the function's declaration from
xen/iommu.h.
Quoted 3 lines
Actually I did the build test on x86 ... By mistake I remove the function's declaration in the wrong patch "xen/passthrough: iommu: Split generic IOMMU code".
So I suppose you build tested the whole series, but not each individual patch...
Quoted 1 line
I will fix it in the next patch series.
In the sense that you need to drop the change from the later patch then, as I applied the trivial three patches from the series already.
Jan
Re: [PATCH v2 02/15] xen/passthrough: vtd: Don't export iommu_domain_teardown
Quoted 2 lines · Jan Beulich
So I suppose you build tested the whole series, but not each individual patch...
I did on most of the patches. But forget to do it for trivial patches.
Quoted 5 lines
Quoted 1 line
I will fix it in the next patch series.
In the sense that you need to drop the change from the later patch then, as I applied the trivial three patches from the series already.
Thanks,
Signature · 1 line
Julien Grall
PATCH v2 3/15 xen/passthrough: vtd: Don't export iommu_set_pgd
In reply to Julien Gralliommu_set_pgd is only used internally inxen/drivers/passthrough/vtd/iommu.c
--- xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/include/xen/iommu.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -1826,7 +1826,7 @@ static int vtd_ept_page_compatible(struct iommu *iommu)/* * set VT-d page table directory to EPT table if allowed */ -void iommu_set_pgd (struct domain *d) +static void iommu_set_pgd (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);mfn_t pgd_mfn;
xen/include/xen/iommu.h +0 -1
@@ -68,7 +68,6 @@ 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);void iommu_pte_flush (struct domain *d,u64 gfn,u64 *pte,int order,int present); -void iommu_set_pgd (struct domain *d);void iommu_domain_teardown (struct domain *d);void pt_pci_init (void );
Signature · 1 line
1.7.10.4
PATCH v2 4/15 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
@@ -347,6 +348,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
@@ -369,6 +374,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 v2 5/15 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 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 ) + { +dt_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) ) + { +dt_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 ) + { +dt_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 v2 6/15 xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
In reply to Julien GrallDOM0 on ARM will have the same requirements as DOM0 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 v2:
- IOMMU can be disabled on ARM if the platform doesn't have IOMMU.
--- xen/drivers/passthrough/iommu.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
xen/drivers/passthrough/iommu.c +8 -5
@@ -130,13 +130,17 @@ int iommu_domain_init(struct domain *d)return hd->platform_ops->init (d); } -static __init void check_dom0_pvh_reqs (struct domain *d) +static __init void check_dom0_reqs (struct domain *d) { -if ( !iommu_enabled ) +if ( !paging_mode_translate (d) ) +return ; + +if (is_pvh_domain (d) && !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 translate paging mode, dom0-passthrough must not be " +"enabled\n" ); iommu_dom0_strict =1 ; }
@@ -145,8 +149,7 @@ void __init iommu_dom0_init(struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); -if (is_pvh_domain (d) ) -check_dom0_pvh_reqs (d); +check_dom0_reqs (d);if ( !iommu_enabled )return ;
Signature · 1 line
1.7.10.4
PATCH v2 7/15 xen/passthrough: iommu: Don't need to map dom0 page when the PT is shared
In reply to Julien GrallCurrently iommu_init_dom0 is browsing the page list and call map_page callback on each page.
On both AMD and VTD drivers, the function will directly return if the page table is shared with the processor. So Xen can safely avoid to run through the page list.
--- xen/drivers/passthrough/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/iommu.c +1 -1
@@ -156,7 +156,7 @@ void __init iommu_dom0_init(struct domain *d)register_keyhandler ('o' , &iommu_p2m_table); d->need_iommu = !!iommu_dom0_strict; -if (need_iommu (d) ) +if (need_iommu (d) && !iommu_use_hap_pt (d) ) {struct page_info *page;unsigned int i =0 ;
Signature · 1 line
1.7.10.4
PATCH v2 8/15 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 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 | 493 ++-------------------------------- xen/drivers/passthrough/pci.c | 437 ++++++++++++++++++++++++++++++ xen/drivers/passthrough/x86/Makefile | 1 + xen/drivers/passthrough/x86/iommu.c | 65 +++++ xen/include/asm-x86/iommu.h | 46 ++++ xen/include/xen/hvm/iommu.h | 1 + xen/include/xen/iommu.h | 43 ++- 8 files changed, 597 insertions(+), 493 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 +24 -469
537 lines not on this page · raw message
xen/drivers/passthrough/pci.c +437 -0
449 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 +65 -0
65 lines not on this page · raw message
xen/include/asm-x86/iommu.h new file +46 -0
46 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 +21 -22
120 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v2 08/15] xen/passthrough: iommu: Split generic IOMMU code
Quoted 27 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/drivers/passthrough/iommu.c +9
-14+int iommu_do_domctl ( +struct xen_domctl *domctl,struct domain *d, +XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl) { -const struct iommu_ops *ops =iommu_get_ops (); -if ( iommu_intremap ) - ops->read_msi_from_ire (msi_desc, msg); -} +int ret =0 ; -unsigned int iommu_read_apic_from_ire (unsigned int apic,unsigned int reg) -{ -const struct iommu_ops *ops =iommu_get_ops (); -return ops->read_apic_from_ire (apic, reg); -} +if ( !iommu_enabled ) +return -ENOSYS ; -int __init iommu_setup_hpet_msi (struct msi_desc *msi) -{ -const struct iommu_ops *ops =iommu_get_ops (); -return ops->setup_hpet_msi ? ops->setup_hpet_msi (msi) : -ENODEV ; -} +switch ( domctl->cmd ) + { +#ifdef HAS_PCI
xen/drivers/passthrough/iommu.c int __init iommu_setup(void) · line 344
Quoted 10 lines
xen/drivers/passthrough/iommu.c +10
-0+case XEN_DOMCTL_get_device_group: +case XEN_DOMCTL_test_assign_device: +case XEN_DOMCTL_assign_device: +case XEN_DOMCTL_deassign_device: + ret =iommu_do_pci_domctl (domctl, d, u_domctl); +break ; +#endif +default : + ret = -ENOSYS ; + }
Please simply have the default case chain to iommu_do_pci_domctl(), avoiding the need to change two source files when new sub-ops get added.
Also, last case in the set of case statements or not - the default case should also have a break statement.
xen/drivers/passthrough/pci.c static int __init setup_dump_pcidevs(void) · line 987
Quoted 9 lines
xen/drivers/passthrough/pci.c +2
-0@@ -980,6 +983,440 @@ static int __init setup_dump_pcidevs(void) }__initcall (setup_dump_pcidevs); +static int iommu_populate_page_table (struct domain *d) +{
Now why is this function being moved here? It doesn't appear to have anything PCI specific at all.
Quoted 22 lines
xen/drivers/passthrough/x86/iommu.c new file +19
-0@@ -0,0 +1,65 @@ +/* +* 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. +*/ + +#include <xen/sched.h> +#include <xen/iommu.h> +#include <xen/paging.h> +#include <xen/guest_access.h>
xen/drivers/passthrough/x86/iommu.c line 29
Quoted 10 lines
xen/drivers/passthrough/x86/iommu.c new file +10
-0+#include <xen/event.h> +#include <xen/softirq.h> +#include <xsm/xsm.h> + +void iommu_update_ire_from_apic ( +unsigned int apic,unsigned int reg,unsigned int value) +{ +const struct iommu_ops *ops =iommu_get_ops (); + ops->update_ire_from_apic (apic, reg, value); +}
While one might argue that this one is x86-specific (albeit from past IA64 days we know it isn't entirely), ...
xen/drivers/passthrough/x86/iommu.c line 36
Quoted 7 lines
xen/drivers/passthrough/x86/iommu.c new file +7
-0+ +int iommu_update_ire_from_msi ( +struct msi_desc *msi_desc,struct msi_msg *msg) +{ +const struct iommu_ops *ops =iommu_get_ops (); +return iommu_intremap ? ops->update_ire_from_msi (msi_desc, msg) :0 ; +}
... this one clearly isn't - I'm sure once you support PCI on ARM, you will also want/need to support MSI. (The same then of course goes for the respective functions' declarations.)
Quoted 13 lines
xen/include/asm-x86/iommu.h new file +10
-0@@ -0,0 +1,46 @@ +/* +* 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. +*
xen/include/asm-x86/iommu.h line 20
Quoted 10 lines
xen/include/asm-x86/iommu.h new file +10
-0+* 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_X86_IOMMU_H__ +#define __ARCH_X86_IOMMU_H__ + +#define MAX_IOMMUS 32 + +#include <asm/msi.h>
Please don't, if at all possible.
xen/include/asm-x86/iommu.h void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci); · line 90
Quoted 10 lines
xen/include/asm-x86/iommu.h new file +3
-0@@ -84,52 +82,56 @@ void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci);bool_t pt_irq_need_timer (uint32_t flags);#define PT_IRQ_TIME_OUT MILLISECS(8) +#endif /* HAS_PCI */ +#ifdef CONFIG_X86 struct msi_desc ;struct msi_msg ; +#endif /* CONFIG_X86 */
Hardly - this again is a direct descendant from PCI.
xen/include/asm-x86/iommu.h void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci); · line 98
Quoted 8 lines
xen/include/asm-x86/iommu.h new file +3
-0+#ifdef CONFIG_X86 void (*update_ire_from_apic)(unsigned int apic,unsigned int reg,unsigned int value);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);unsigned int (*read_apic_from_ire)(unsigned int apic,unsigned int reg);int (*setup_hpet_msi)(struct msi_desc *); +void (*share_p2m)(struct domain *d); +#endif /* CONFIG_X86 */
Is that last one really x86-specific in any way?
Jan
Re: [PATCH v2 08/15] xen/passthrough: iommu: Split generic IOMMU code
Hi Jan,
Quoted 33 lines · Jan Beulich
Quoted 33 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/drivers/passthrough/iommu.c +15
-14+int iommu_do_domctl ( +struct xen_domctl *domctl,struct domain *d, +XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl) { -const struct iommu_ops *ops =iommu_get_ops (); -if ( iommu_intremap ) - ops->read_msi_from_ire (msi_desc, msg); -} +int ret =0 ; -unsigned int iommu_read_apic_from_ire (unsigned int apic,unsigned int reg) -{ -const struct iommu_ops *ops =iommu_get_ops (); -return ops->read_apic_from_ire (apic, reg); -} +if ( !iommu_enabled ) +return -ENOSYS ; -int __init iommu_setup_hpet_msi (struct msi_desc *msi) -{ -const struct iommu_ops *ops =iommu_get_ops (); -return ops->setup_hpet_msi ? ops->setup_hpet_msi (msi) : -ENODEV ; -} +switch ( domctl->cmd ) + { +#ifdef HAS_PCI +case XEN_DOMCTL_get_device_group: +case XEN_DOMCTL_test_assign_device: +case XEN_DOMCTL_assign_device: +case XEN_DOMCTL_deassign_device: + ret =iommu_do_pci_domctl (domctl, d, u_domctl); +break ;
Quoted 8 lines
xen/drivers/passthrough/iommu.c int __init iommu_setup(void) · line 344
Quoted 4 lines
xen/drivers/passthrough/iommu.c +4
-0+#endif +default : + ret = -ENOSYS ; + }Please simply have the default case chain to
iommu_do_pci_domctl(), avoiding the need to change two source files when new sub-ops get added.
I wrote in this manner because we will add soon "iommu_do_dt_domctl" to handle DOMCTL for device tree assignment.
For one of this function we will have to deal with this trick. Or ... we can do:
ret = iommu_do_pci_domctl(...)
if ( ret != ENOSYS )
return ret;
ret = iommu_do_dt_domctl(...)
IHMO, I would prefer the former solution.
Quoted 3 lines
Also, last case in the set of case statements or not - the default case should also have a break statement.
I will add it.
Quoted 7 lines
Quoted 7 lines
xen/drivers/passthrough/pci.c +0
-0@@ -980,6 +983,440 @@ static int __init setup_dump_pcidevs(void) }__initcall (setup_dump_pcidevs);
Quoted 5 lines
xen/drivers/passthrough/pci.c static int __init setup_dump_pcidevs(void) · line 987
Quoted 2 lines
xen/drivers/passthrough/pci.c +2
-0+static int iommu_populate_page_table (struct domain *d) +{Now why is this function being moved here? It doesn't appear to have anything PCI specific at all.
Because this function is only used in assign_device.
I also remember this function can't work on ARM (arch.relmem_list doesn't exists). I will move this code in x86/iommu.c because it's seems architecture initialization.
Quoted 37 lines
Quoted 23 lines
xen/drivers/passthrough/x86/iommu.c new file +19
-0@@ -0,0 +1,65 @@ +/* +* 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. +*/ + +#include <xen/sched.h> +#include <xen/iommu.h> +#include <xen/paging.h> +#include <xen/guest_access.h> xen/drivers/passthrough/x86/iommu.c line 29
Quoted 10 lines
xen/drivers/passthrough/x86/iommu.c new file +10
-0+#include <xen/event.h> +#include <xen/softirq.h> +#include <xsm/xsm.h> + +void iommu_update_ire_from_apic ( +unsigned int apic,unsigned int reg,unsigned int value) +{ +const struct iommu_ops *ops =iommu_get_ops (); + ops->update_ire_from_apic (apic, reg, value); +}While one might argue that this one is x86-specific (albeit from past IA64 days we know it isn't entirely), ...
Quoted 11 lines
xen/drivers/passthrough/x86/iommu.c line 36
Quoted 7 lines
xen/drivers/passthrough/x86/iommu.c new file +7
-0+ +int iommu_update_ire_from_msi ( +struct msi_desc *msi_desc,struct msi_msg *msg) +{ +const struct iommu_ops *ops =iommu_get_ops (); +return iommu_intremap ? ops->update_ire_from_msi (msi_desc, msg) :0 ; +}... this one clearly isn't - I'm sure once you support PCI on ARM, you will also want/need to support MSI. (The same then of course goes for the respective functions' declarations.)
Right, I guess it's the same for iommu_read_msi_from_ire.
Quoted 17 lines
Quoted 17 lines
xen/include/asm-x86/iommu.h new file +14
-0@@ -0,0 +1,46 @@ +/* +* 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. +*/
Quoted 8 lines
xen/include/asm-x86/iommu.h line 20
Quoted 6 lines
xen/include/asm-x86/iommu.h new file +6
-0+#ifndef __ARCH_X86_IOMMU_H__ +#define __ARCH_X86_IOMMU_H__ + +#define MAX_IOMMUS 32 + +#include <asm/msi.h> Please don't, if at all possible.
I'm not sure to understand ... what do you mean? Don't include "asm/msi.h"?
Quoted 6 lines
Quoted 6 lines
xen/include/asm-x86/iommu.h new file +1
-0@@ -84,52 +82,56 @@ void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci);bool_t pt_irq_need_timer (uint32_t flags);#define PT_IRQ_TIME_OUT MILLISECS(8) +#endif /* HAS_PCI */
Quoted 6 lines
xen/include/asm-x86/iommu.h void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci); · line 90
Quoted 4 lines
xen/include/asm-x86/iommu.h new file +2
-0+#ifdef CONFIG_X86 struct msi_desc ;struct msi_msg ; +#endif /* CONFIG_X86 */ Hardly - this again is a direct descendant from PCI.
I will #ifdef HAS_PCI.
Quoted 10 lines
xen/include/asm-x86/iommu.h void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci); · line 98
Quoted 8 lines
xen/include/asm-x86/iommu.h new file +3
-0+#ifdef CONFIG_X86 void (*update_ire_from_apic)(unsigned int apic,unsigned int reg,unsigned int value);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);unsigned int (*read_apic_from_ire)(unsigned int apic,unsigned int reg);int (*setup_hpet_msi)(struct msi_desc *); +void (*share_p2m)(struct domain *d); +#endif /* CONFIG_X86 */ Is that last one really x86-specific in any way?
On ARM, P2M are share by default. You don't need to call this function explicitly. So I think we can safely say it's x86-specific.
Developper won't call this function by mistake.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 08/15] xen/passthrough: iommu: Split generic IOMMU code
Quoted 25 lines
Quoted 10 lines
Quoted 10 lines · Julien Grall
xen/drivers/passthrough/iommu.c +9
-0+switch ( domctl->cmd ) + { +#ifdef HAS_PCI +case XEN_DOMCTL_get_device_group: +case XEN_DOMCTL_test_assign_device: +case XEN_DOMCTL_assign_device: +case XEN_DOMCTL_deassign_device: + ret =iommu_do_pci_domctl (domctl, d, u_domctl); +break ;Quoted 8 lines
xen/drivers/passthrough/iommu.c int __init iommu_setup(void) · line 344
Quoted 4 lines
xen/drivers/passthrough/iommu.c +4
-0+#endif +default : + ret = -ENOSYS ; + }Please simply have the default case chain to
iommu_do_pci_domctl(), avoiding the need to change two source files when new sub-ops get added.I wrote in this manner because we will add soon "
iommu_do_dt_domctl" to handle DOMCTL for device tree assignment.For one of this function we will have to deal with this trick. Or ... we can do:
Quoted 6 lines
ret = iommu_do_pci_domctl(...) if ( ret != ENOSYS ) return ret; ret = iommu_do_dt_domctl(...)IHMO, I would prefer the former solution.
While I'd prefer the latter, perhaps slightly adjusted to not as heavily special case -ENOSYS (i.e. call the second function if any error was returned from the first, and use the error value that was not -ENOSYS unless both functions returned it).
Quoted 10 lines
Quoted 8 lines
xen/include/asm-x86/iommu.h line 20
Quoted 6 lines
xen/include/asm-x86/iommu.h new file +6
-0+#ifndef __ARCH_X86_IOMMU_H__ +#define __ARCH_X86_IOMMU_H__ + +#define MAX_IOMMUS 32 + +#include <asm/msi.h> Please don't, if at all possible.
I'm not sure to understand ... what do you mean? Don't include "
asm/msi.h"?
Exactly. All you need in this header are forward declarations of two struct-s.
Quoted 11 lines
Quoted 10 lines
xen/include/xen/iommu.h void free_hvm_irq_dpci(struct hvm_irq_dpci *dpci); · line 118
Quoted 8 lines
xen/include/xen/iommu.h +3
-0+#ifdef CONFIG_X86 void (*update_ire_from_apic)(unsigned int apic,unsigned int reg,unsigned int value);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);unsigned int (*read_apic_from_ire)(unsigned int apic,unsigned int reg);int (*setup_hpet_msi)(struct msi_desc *); +void (*share_p2m)(struct domain *d); +#endif /* CONFIG_X86 */ Is that last one really x86-specific in any way?
Quoted 4 lines
On ARM, P2M are share by default. You don't need to call this function explicitly. So I think we can safely say it's x86-specific.
Developper won't call this function by mistake.
But then again this could easily be dealt with in ARM (providing a no-op stub) or the generic code (checking the pointer to be non- NULL), allowing future ports (or ARM itself, should it ever need to) to use it.
Jan
PATCH v2 9/15 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.
--- xen/arch/x86/domctl.c | 6 +- xen/arch/x86/hvm/io.c | 2 +- xen/arch/x86/tboot.c | 3 +- xen/drivers/passthrough/amd/iommu_cmd.c | 2 +- xen/drivers/passthrough/amd/iommu_guest.c | 8 +-- xen/drivers/passthrough/amd/iommu_map.c | 56 +++++++++---------- xen/drivers/passthrough/amd/pci_amd_iommu.c | 53 +++++++++--------- xen/drivers/passthrough/iommu.c | 36 +++--------- xen/drivers/passthrough/vtd/iommu.c | 80 +++++++++++++-------------- xen/drivers/passthrough/x86/iommu.c | 41 ++++++++++++++ xen/include/asm-x86/hvm/iommu.h | 29 ++++++++++ xen/include/asm-x86/iommu.h | 4 ++ xen/include/xen/hvm/iommu.h | 26 +-------- xen/include/xen/iommu.h | 8 +-- 14 files changed, 191 insertions(+), 163 deletions(-)
xen/arch/x86/domctl.c +3 -3
@@ -745,7 +745,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;
@@ -764,7 +764,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 );
@@ -779,7 +779,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
@@ -230,7 +230,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_cmd.c +1 -1
@@ -355,7 +355,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 = hd->arch.domain_id;/* send INVALIDATE_IOMMU_PAGES command */ for_each_amd_iommu ( iommu )
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 +28 -28
175 lines not on this page · raw message
xen/drivers/passthrough/amd/pci_amd_iommu.c +27 -26
124 lines not on this page · raw message
xen/drivers/passthrough/iommu.c +7 -29
@@ -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 ;
@@ -189,10 +190,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, *rmrr_list, *tmp; -struct g2m_ioport *ioport; -struct mapped_rmrr *mrmrr; +struct hvm_iommu *hd =domain_hvm_iommu (d);if ( !iommu_enabled || !hd->platform_ops )return ;
@@ -200,20 +198,8 @@ 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); - } - - list_for_each_safe ( rmrr_list, tmp, &hd->mapped_rmrrs ) - { - mrmrr = list_entry(rmrr_list, struct mapped_rmrr, list); -list_del (&mrmrr->list); -xfree (mrmrr); - } -} +arch_iommu_domain_destroy (d); + }int iommu_map_page (struct domain *d,unsigned long gfn,unsigned long mfn,unsigned int flags)
@@ -353,14 +339,6 @@ void iommu_suspend() ops->suspend (); } -void iommu_share_p2m_table (struct domain * d) -{ -const struct iommu_ops *ops =iommu_get_ops (); - -if ( iommu_enabled &&is_hvm_domain (d) ) - ops->share_p2m (d); -} -void iommu_crash_shutdown (void ) {const struct iommu_ops *ops =iommu_get_ops ();
xen/drivers/passthrough/vtd/iommu.c +40 -40
242 lines not on this page · raw message
xen/drivers/passthrough/x86/iommu.c +41 -0
47 lines not on this page · raw message
xen/include/asm-x86/hvm/iommu.h +29 -0
@@ -39,4 +39,33 @@ 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 mapped_rmrr { +struct list_head list; +u64 base; +u64 end; +}; + +struct arch_hvm_iommu +{ +u64 pgd_maddr;/* io page directory machine address */ +int agaw;/* adjusted guest address width, 0 is level 2 30-bit */ +u64 iommu_bitmap;/* bitmap of iommu(s) that the domain uses */ +/* amd iommu support */ +int domain_id; +int paging_mode; +struct page_info *root_table; +struct guest_iommu *g_iommu; + +struct list_head g2m_ioport_list;/* guest to machine ioport mapping */ +struct list_head mapped_rmrrs; +spinlock_t mapping_lock;/* io page table lock */ +}; +#endif /* __ASM_X86_HVM_IOMMU_H__ */
xen/include/asm-x86/iommu.h +4 -0
@@ -19,6 +19,10 @@#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);int iommu_update_ire_from_msi (struct msi_desc *msi_desc,struct msi_msg *msg);void iommu_read_msi_from_ire (struct msi_desc *msi_desc,struct msi_msg *msg);
xen/include/xen/hvm/iommu.h +1 -25
@@ -23,32 +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 mapped_rmrr { -struct list_head list; -u64 base; -u64 end; -}; -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 domain_id; -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 +3 -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,9 @@ void iommu_dom0_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); +/* Function used internally, use iommu_domain_destroy */ void iommu_teardown (struct domain *d);
Signature · 1 line
1.7.10.4
Re: [PATCH v2 09/15] xen/passthrough: iommu: Introduce arch specific code
Quoted 20 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/include/xen/hvm/iommu.h +0
-13@@ -23,32 +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 mapped_rmrr { -struct list_head list; -u64 base; -u64 end; -}; -
xen/include/xen/hvm/iommu.h line 48
Quoted 10 lines
xen/include/xen/hvm/iommu.h +0
-9struct 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 domain_id;
At the very least this field doesn't look all that architecture specific, even if it might only be used on x86/AMD right now.
xen/include/xen/hvm/iommu.h line 49
Quoted 1 line
xen/include/xen/hvm/iommu.h +0
-1-int paging_mode;
The same might go for this one.
Jan
Re: [PATCH v2 09/15] xen/passthrough: iommu: Introduce arch specific code
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/include/xen/hvm/iommu.h +0
-16@@ -23,32 +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 mapped_rmrr { -struct list_head list; -u64 base; -u64 end; -}; -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 */
Quoted 8 lines
xen/include/xen/hvm/iommu.h line 48
Quoted 6 lines
xen/include/xen/hvm/iommu.h +0
-6-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 domain_id;At the very least this field doesn't look all that architecture specific, even if it might only be used on x86/AMD right now.
Furthermore, it can be found using container_of()
The current size of struct domain is 3584 bytes, which is quite close to the 1 page limit. We should certainly be taking opportunities like this to reduce bloat.
~Andrew
Quoted 11 lines
xen/include/xen/hvm/iommu.h line 49
Quoted 2 lines
xen/include/xen/hvm/iommu.h +0
-1-int paging_mode;The same might go for this one.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [PATCH v2 09/15] xen/passthrough: iommu: Introduce arch specific code
Hi Andrew,
Quoted 34 lines · Andrew Cooper
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/include/xen/hvm/iommu.h +0
-16@@ -23,32 +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 mapped_rmrr { -struct list_head list; -u64 base; -u64 end; -}; -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 */ Quoted 8 lines
xen/include/xen/hvm/iommu.h line 48
Quoted 6 lines
xen/include/xen/hvm/iommu.h +0
-6-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 domain_id;At the very least this field doesn't look all that architecture specific, even if it might only be used on x86/AMD right now.
Quoted 1 line
Furthermore, it can be found using
container_of()
Every AMD function starts with:
hd = domain_hvm_iommu(d)
And then use hd->arch.domain_id in the code.
x86/AMD iommu can directly use d->domain_id, as it's already done in some place. No need to use container_of() :).
I will send a patch to remove domain_id in the structure.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 09/15] xen/passthrough: iommu: Introduce arch specific code
In reply to Jan BeulichHi Jan,
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/include/xen/hvm/iommu.h +0
-17@@ -23,32 +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 mapped_rmrr { -struct list_head list; -u64 base; -u64 end; -}; -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 */
Quoted 8 lines
xen/include/xen/hvm/iommu.h line 48
Quoted 5 lines
xen/include/xen/hvm/iommu.h +0
-5-u64 iommu_bitmap;/* bitmap of iommu(s) that the domain uses */ -struct list_head mapped_rmrrs; - -/* amd iommu support */ -int domain_id;At the very least this field doesn't look all that architecture specific, even if it might only be used on x86/AMD right now.
On ARM, each IOMMU will have it's own private data stored in arch.priv. I don't think domain_id will be used as the driver can directly use d->domain_id.
I gave a look on AMD IOMMU drivers, and in a same function they mixed d->domain_id and domain_hvm_iommu(d)->arch.domain_id. The latter one has been initialized to d->domain_id in amd_iommu_domain_init.
I think, we can even remove this field for x86...
Quoted 3 lines
xen/include/xen/hvm/iommu.h line 49
Quoted 1 line
xen/include/xen/hvm/iommu.h +0
-1-int paging_mode;The same might go for this one.
There is only one paging mode on ARM.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v2 09/15] xen/passthrough: iommu: Introduce arch specific code
Quoted 19 lines
Quoted 12 lines
xen/include/xen/hvm/iommu.h line 48
Quoted 11 lines · Julien Grall
struct
hvm_iommu{xen/include/xen/hvm/iommu.h +0
-9-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 domain_id;Quoted 2 lines
At the very least this field doesn't look all that architecture specific, even if it might only be used on x86/AMD right now.
On ARM, each IOMMU will have it's own private data stored in arch.priv. I don't think
domain_idwill be used as the driver can directly used->domain_id.
Quoted 5 lines
I gave a look on AMD IOMMU drivers, and in a same function they mixed
d->domain_idand domain_hvm_iommu(d)->arch.domain_id. The latter one has been initialized tod->domain_idinamd_iommu_domain_init.I think, we can even remove this field for x86...
As Andrew suggested too.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
- int
paging_mode;The same might go for this one.
There is only one paging mode on ARM.
But please make your changes here not in the spirit of fitting in ARM, but to make the code reasonable architecture clean. Which means that fields having a purpose outside of x86 should remain common, instead of making x86-specific everything that ARM (currently) has no use for.
Jan
Re: [PATCH v2 09/15] xen/passthrough: iommu: Introduce arch specific code
Quoted 31 lines · Jan Beulich
Quoted 19 lines
Quoted 12 lines
xen/include/xen/hvm/iommu.h line 48
Quoted 11 lines · Julien Grall
struct
hvm_iommu{xen/include/xen/hvm/iommu.h +0
-9-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 domain_id;Quoted 2 lines
At the very least this field doesn't look all that architecture specific, even if it might only be used on x86/AMD right now.
On ARM, each IOMMU will have it's own private data stored in arch.priv. I don't think
domain_idwill be used as the driver can directly used->domain_id.Quoted 5 lines
I gave a look on AMD IOMMU drivers, and in a same function they mixed
d->domain_idand domain_hvm_iommu(d)->arch.domain_id. The latter one has been initialized tod->domain_idinamd_iommu_domain_init.I think, we can even remove this field for x86...
As Andrew suggested too.
Quoted 4 lines
Quoted 3 lines
Quoted 1 line
- int
paging_mode;The same might go for this one.
Quoted 7 lines
Quoted 1 line
There is only one paging mode on ARM.
But please make your changes here not in the spirit of fitting in ARM, but to make the code reasonable architecture clean. Which means that fields having a purpose outside of x86 should remain common, instead of making x86-specific everything that ARM (currently) has no use for.
I didn't want to repeat that I said for the previous field. ARM doesn't have a generic IOMMU driver (or two) as x86. Basically every vendor can decide to design it's own IOMMU.
To avoid to have a big structure with some fields used only by one driver, every IOMMU ARM drivers as its own private structure.
IHMO, I think every fields stored in the generic hvm_iommu structure should be initialized by generic code, not by a specific driver.
Signature · 1 line
Julien Grall
PATCH v2 10/15 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
- next_assigned: Pointer to the next device assigned to the same domain
---
Changes in v2:
- Patch added
--- xen/common/device_tree.c | 4 ++ xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/device_tree.c | 106 +++++++++++++++++++++++++++++++++ xen/drivers/passthrough/iommu.c | 10 ++++ xen/include/xen/device_tree.h | 14 +++++ xen/include/xen/hvm/iommu.h | 6 ++ xen/include/xen/iommu.h | 16 +++++ 7 files changed, 157 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->next_assigned); +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 +106 -0
106 lines not on this page · raw message
xen/drivers/passthrough/iommu.c +10 -0
@@ -123,6 +123,12 @@ int iommu_domain_init(struct domain *d)if ( ret )return ret; +#if HAS_DEVICE_TREE + ret =iommu_dt_domain_init (d); +if ( ret ) +return ret; +#endif +if ( !iommu_enabled )return 0 ;
@@ -198,6 +204,10 @@ void iommu_domain_destroy(struct domain *d)if (need_iommu (d) )iommu_teardown (d); +#ifdef HAS_DEVICE_TREE +iommu_dt_domain_destroy (d); +#endif +arch_iommu_domain_destroy (d); }
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
@@ -110,6 +111,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 next_assigned; };#define MAX_PHANDLE_ARGS 16
@@ -325,6 +329,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
@@ -82,6 +82,16 @@ bool_t pt_irq_need_timer(uint32_t flags);#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 */ +#ifdef CONFIG_X86 struct msi_desc ;struct msi_msg ;
@@ -101,6 +111,12 @@ struct iommu_ops { u8 devfn, struct pci_dev *);int (*get_device_group_id)(u16 seg,u8 bus,u8 devfn);#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 v2 10/15] xen/passthrough: iommu: Basic support of device tree assignment
Quoted 12 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Add 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
-next_assigned: Pointer to the next device assigned to the same domainSigned-off-by Julien Grall <[email protected]>---
Changes in v2:
- Patch added
Quoted 8 lines
--- xen/common/device_tree.c | 4 ++ xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/device_tree.c | 106 +++++++++++++++++++++++++++++++++ xen/drivers/passthrough/iommu.c | 10 ++++ xen/include/xen/device_tree.h | 14 +++++ xen/include/xen/hvm/iommu.h | 6 ++ xen/include/xen/iommu.h | 16 +++++
No matter how small the changes to generic IOMMU code, you should Cc the maintainers.
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 130
Quoted 11 lines
xen/drivers/passthrough/iommu.c +5
-0@@ -123,6 +123,12 @@ int iommu_domain_init(struct domain *d)if ( ret )return ret; +#if HAS_DEVICE_TREE + ret =iommu_dt_domain_init (d); +if ( ret ) +return ret; +#endif
Why can this not be part of arch_iommu_domain_init()?
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 211
Quoted 9 lines
xen/drivers/passthrough/iommu.c +4
-0@@ -198,6 +204,10 @@ void iommu_domain_destroy(struct domain *d)if (need_iommu (d) )iommu_teardown (d); +#ifdef HAS_DEVICE_TREE +iommu_dt_domain_destroy (d); +#endif +arch_iommu_domain_destroy (d);
And the former one here part of the latter?
xen/drivers/passthrough/iommu.c struct hvm_iommu { · line 36
Quoted 9 lines
xen/drivers/passthrough/iommu.c +5
-0@@ -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
Indentation.
Jan
Re: [PATCH v2 10/15] xen/passthrough: iommu: Basic support of device tree assignment
Hi Jan,
Quoted 21 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Add 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
-next_assigned: Pointer to the next device assigned to the same domainSigned-off-by Julien Grall <[email protected]>---
Changes in v2:
- Patch addedQuoted 8 lines
--- xen/common/device_tree.c | 4 ++ xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/device_tree.c | 106 +++++++++++++++++++++++++++++++++ xen/drivers/passthrough/iommu.c | 10 ++++ xen/include/xen/device_tree.h | 14 +++++ xen/include/xen/hvm/iommu.h | 6 ++ xen/include/xen/iommu.h | 16 +++++
Quoted 2 lines
No matter how small the changes to generic IOMMU code, you should Cc the maintainers.
Oops, sorry.
Quoted 6 lines
Quoted 6 lines
xen/drivers/passthrough/iommu.c +0
-0@@ -123,6 +123,12 @@ int iommu_domain_init(struct domain *d)if ( ret )return ret;
Quoted 7 lines
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 130
Quoted 5 lines
xen/drivers/passthrough/iommu.c +5
-0+#if HAS_DEVICE_TREE + ret =iommu_dt_domain_init (d); +if ( ret ) +return ret; +#endif Why can this not be part of
arch_iommu_domain_init()?
I didn't think about this solution. I will move in arch_iommu_domain_init in the next version.
Quoted 11 lines
xen/drivers/passthrough/iommu.c void iommu_domain_destroy(struct domain *d) · line 211
Quoted 9 lines
xen/drivers/passthrough/iommu.c +4
-0@@ -198,6 +204,10 @@ void iommu_domain_destroy(struct domain *d)if (need_iommu (d) )iommu_teardown (d); +#ifdef HAS_DEVICE_TREE +iommu_dt_domain_destroy (d); +#endif +arch_iommu_domain_destroy (d);And the former one here part of the latter?
Ok.
Quoted 11 lines
xen/drivers/passthrough/iommu.c struct hvm_iommu { · line 36
Quoted 9 lines
xen/drivers/passthrough/iommu.c +5
-0@@ -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 Indentation.
Will do.
Cheers,
Signature · 1 line
Julien Grall
PATCH v2 11/15 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 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 | 19 ++++++++-- 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 | 65 ++++++++++++++++++++++++++++++++++ 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, 147 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
@@ -546,6 +546,9 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags)if ( (d->domain_id ==0 ) && (rc =domain_vuart_init (d)) ) goto fail; +if ( (rc =iommu_domain_init (d)) !=0 ) + goto fail; +return 0 ; fail:
@@ -557,6 +560,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 +16 -3
@@ -669,7 +669,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;
@@ -684,6 +684,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++ ) {
@@ -755,7 +767,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 = {
@@ -776,7 +788,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;
@@ -1009,6 +1021,7 @@ int construct_dom0(struct domain *d) kinfo.unassigned_mem = dom0_mem;allocate_memory (d, &kinfo); +iommu_dom0_init (d); rc =kernel_prepare (&kinfo);if ( rc <0 )
xen/arch/arm/p2m.c +4 -0
@@ -412,12 +412,16 @@ 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); +/* 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). */ flush_tlb (); +iommu_iotlb_flush (d, sgfn, egfn - sgfn); }if ( op ==ALLOCATE || op ==INSERT )
xen/arch/arm/setup.c +2 -0
@@ -728,6 +728,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 +65 -0
65 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 hvm_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.hvm_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
PATCH v2 12/15 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
@@ -130,6 +130,7 @@ S: Supported L: [email protected] F: xen/arch/arm/ F: xen/include/asm-arm/ +F: xen/drivers/passthrough/arm CPU POOLS M: Juergen Gross <[email protected]>
Signature · 1 line
1.7.10.4
PATCH v2 13/15 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>
@@ -823,6 +824,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 v2 14/15 xen/arm: Add the property "protected-devices" in the hypervisor node
In reply to Julien GrallDOM0 is using the swiotlb to bounce DMA. With the IOMMU support in Xen, protected devices should not use it.
Only Xen is abled 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. DOM0 can run safely with swiotlb on protected devices while LVM is not used for guest disk.
Changes in v2:
- Patch added
--- xen/arch/arm/domain_build.c | 51 ++++++++++++++++++++++++++++++++++++++----- xen/arch/arm/kernel.h | 3 +++ 2 files changed, 48 insertions(+), 6 deletions(-)
xen/arch/arm/domain_build.c +45 -6
@@ -324,19 +324,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;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" );
@@ -384,6 +387,39 @@ 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 */ + cells =xmalloc_array (__be32, kinfo->num_dev_protected * +dt_size_to_cells (sizeof (dt_phandle))); +if ( !cells ) +return -FDT_ERR_XEN (ENOMEM ); + + _cells = cells; + +DPRINT (" List of protected devices\n" ); +list_for_each_entry ( dev, &hd->dt_devices, next_assigned ) + { +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,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;
@@ -670,7 +706,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;
@@ -695,6 +732,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 */
@@ -844,7 +882,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;
@@ -875,7 +913,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;
@@ -1028,6 +1066,7 @@ int construct_dom0(struct domain *d) d->max_pages = ~0U ; + kinfo.num_dev_protected =0 ; kinfo.unassigned_mem = dom0_mem;allocate_memory (d, &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; +paddr_t dtb_paddr;paddr_t entry;
Signature · 1 line
1.7.10.4
Re: [PATCH v2 14/15] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 7 lines · Julien Grall
DOM0 is using the swiotlb to bounce DMA. With the IOMMU support in Xen, protected devices should not use it.
Only Xen is abled to know if an IOMMU protects the device. The new property "protected-devices" is a list of device phandles protected by an IOMMU.
Signed-off-by Julien Grall <[email protected]>
You need to send a patch to
Documentation/devicetree/bindings/arm/xen.txt
I would like the commit message of this patch to reference the changes to it
Quoted 142 lines
This patch *MUST NOT* be applied until we agreed on a device binding the device tree folks. DOM0 can run safely with swiotlb on protected devices while LVM is not used for guest disk.
Changes in v2:
- Patch added--- xen/arch/arm/domain_build.c | 51 ++++++++++++++++++++++++++++++++++++++----- xen/arch/arm/kernel.h | 3 +++ 2 files changed, 48 insertions(+), 6 deletions(-)xen/arch/arm/domain_build.c +45
-6@@ -324,19 +324,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;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" );@@ -384,6 +387,39 @@ 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 */ + cells =xmalloc_array (__be32, kinfo->num_dev_protected * +dt_size_to_cells (sizeof (dt_phandle))); +if ( !cells ) +return -FDT_ERR_XEN (ENOMEM ); + + _cells = cells; + +DPRINT (" List of protected devices\n" ); +list_for_each_entry ( dev, &hd->dt_devices, next_assigned ) + { +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,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;@@ -670,7 +706,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;@@ -695,6 +732,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 */ @@ -844,7 +882,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;@@ -875,7 +913,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;@@ -1028,6 +1066,7 @@ int construct_dom0(struct domain *d) d->max_pages = ~0U ; + kinfo.num_dev_protected =0 ; kinfo.unassigned_mem = dom0_mem;allocate_memory (d, &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; +paddr_t dtb_paddr;paddr_t entry;Signature · 1 line
1.7.10.4
Re: [PATCH v2 14/15] xen/arm: Add the property "protected-devices" in the hypervisor node
Hi Stefano,
Quoted 10 lines · Stefano Stabellini
Quoted 7 lines · Julien Grall
DOM0 is using the swiotlb to bounce DMA. With the IOMMU support in Xen, protected devices should not use it.
Only Xen is abled to know if an IOMMU protects the device. The new property "protected-devices" is a list of device phandles protected by an IOMMU.
Signed-off-by Julien Grall <[email protected]>You need to send a patch to
I already sent the patch Friday: https://patches.linaro.org/25070/.
Cheers,
Signature · 1 line
Julien Grall
PATCH v2 15/15 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 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 | 1736 ++++++++++++++++++++++++++++++++++ xen/include/xen/iommu.h | 3 + 3 files changed, 1740 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 +1736 -0
1,736 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