IOMMU support for ARM
v3 cover IOMMU support for ARM
Hello,
This is the third 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: Remove domain_id in hvm_iommu
- #3-#4: Adding new device tree functions
- #5-#7: Prepare IOMMU code to add support for ARM
- #8: Adding basic device tree assignment support
- #9-#12: Add IOMMU architecture for ARM
- #13: 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.
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-v3
Any comments, questions are welcomed.
Sincerely yours,
Julien Grall (13):
xen/common: grant-table: only call IOMMU if paging mode translate is
disabled
xen/passthrough: amd: Remove domain_id from hvm_iommu 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: 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 | 3 +- 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 | 70 ++ xen/drivers/passthrough/arm/smmu.c | 1736 +++++++++++++++++++++++++++ xen/drivers/passthrough/device_tree.c | 106 ++ xen/drivers/passthrough/iommu.c | 524 +------- xen/drivers/passthrough/pci.c | 452 +++++++ xen/drivers/passthrough/vtd/iommu.c | 80 +- xen/drivers/passthrough/x86/Makefile | 1 + xen/drivers/passthrough/x86/iommu.c | 91 ++ 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 | 28 + xen/include/asm-x86/iommu.h | 44 + xen/include/xen/device_tree.h | 89 ++ xen/include/xen/hvm/iommu.h | 33 +- xen/include/xen/iommu.h | 70 +- 36 files changed, 3132 insertions(+), 671 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 v3 1/13 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 v3 2/13 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);
@@ -273,8 +273,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 ;
@@ -333,7 +331,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
@@ -44,7 +44,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 v3 02/13] xen/passthrough: amd: Remove domain_id from hvm_iommu
Quoted 6 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]>Cc Suravee Suthikulpanit <[email protected]>Cc Jan Beulich <[email protected]>
(needs ack from one of the above though)
Ian.
Re: [PATCH v3 02/13] xen/passthrough: amd: Remove domain_id from hvm_iommu
Quoted 5 lines
Quoted 1 line
Quoted 1 line · Ian Campbell
Quoted 3 lines · Julien Grall
The structure
hvm_iommucontains a shadow value ofdomain->domain_id. There is no reason to not directly usedomain->domain_id.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Julien Grall <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Jan Beulich <[email protected]>Reviewed-by Ian Campbell <[email protected]>(needs ack from one of the above though)
Right, I was expecting Suravee to take care of this, because I think it was him (or someone else at AMD) who introduced that field (so we don't overlook something non-obvious).
Jan
PATCH v3 3/13 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 v3 4/13 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
Re: [PATCH v3 04/13] xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle
Quoted 3 lines · Julien Grall
Code adapted from linux
drivers/of/base.c(commit ef42c58).Signed-off-by Julien Grall <[email protected]>
PATCH v3 5/13 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
Re: [PATCH v3 05/13] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Quoted 24 lines · Julien Grall
DOM0 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.
Signed-off-by Julien Grall <[email protected]>Acked-by Jan Beulich <[email protected]>Cc Xiantao Zhang <[email protected]>---
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 +0
-0@@ -130,13 +130,17 @@ int iommu_domain_init(struct domain *d)return hd->platform_ops->init (d);
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 138
Quoted 10 lines
xen/drivers/passthrough/iommu.c +5
-2} -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 )
Is is_pvh_domain going to be exposed to common code on ARM?
Or would a arch_check_dom0_reqs be useful here?
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 142
Quoted 5 lines
xen/drivers/passthrough/iommu.c +1
-1panic ("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 "
"paging translated mode" reads more natural to me.
Quoted 14 lines
xen/drivers/passthrough/iommu.c +2
-2+ "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 ;
Re: [PATCH v3 05/13] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Hi Ian,
Quoted 27 lines · Ian Campbell
Quoted 26 lines · Julien Grall
DOM0 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.
Signed-off-by Julien Grall <[email protected]>Acked-by Jan Beulich <[email protected]>Cc Xiantao Zhang <[email protected]>---
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 +0
-0@@ -130,13 +130,17 @@ int iommu_domain_init(struct domain *d)return hd->platform_ops->init (d); }
Quoted 10 lines
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 138
Quoted 8 lines
xen/drivers/passthrough/iommu.c +5
-2-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 )Is
is_pvh_domaingoing to be exposed to common code on ARM?
It will be exposed to common code. For now is_pvh_domain is part of xen/sched.h, do you plan to move it in asm-x86?
Quoted 1 line
Or would a
arch_check_dom0_reqsbe useful here?
I will update patch #7 to create this function.
Quoted 7 lines
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 142
Quoted 5 lines
xen/drivers/passthrough/iommu.c +1
-1panic ("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 ""paging translated mode" reads more natural to me.
I will change in the next version.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 05/13] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Quoted 41 lines · Julien Grall
Hi Ian,
Quoted 27 lines · Ian Campbell
Quoted 26 lines · Julien Grall
DOM0 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.
Signed-off-by Julien Grall <[email protected]>Acked-by Jan Beulich <[email protected]>Cc Xiantao Zhang <[email protected]>---
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 +0
-0@@ -130,13 +130,17 @@ int iommu_domain_init(struct domain *d)return hd->platform_ops->init (d); }Quoted 10 lines
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 138
Quoted 8 lines
xen/drivers/passthrough/iommu.c +5
-2-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 )Is
is_pvh_domaingoing to be exposed to common code on ARM?
Quoted 2 lines
It will be exposed to common code. For now
is_pvh_domainis part ofxen/sched.h, do you plan to move it in asm-x86?
Oh, I hadn't realised it was already common. I don't plan to move it myself.
Quoted 3 lines
Quoted 1 line
Or would a
arch_check_dom0_reqsbe useful here?I will update patch #7 to create this function.
I suppose given that is_pvh_domain is already common this isn't really necessary, although maybe someone would thank you in the future for reducing the common code use of is_pvh_domain a little...
Quoted 10 lines
Quoted 8 lines
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 142
Quoted 6 lines
xen/drivers/passthrough/iommu.c +1
-1panic ("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 ""paging translated mode" reads more natural to me.
I will change in the next version.
Thanks.
Ian.
Re: [PATCH v3 05/13] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Quoted 6 lines · Ian Campbell
Quoted 2 lines · Julien Grall
It will be exposed to common code. For now
is_pvh_domainis part ofxen/sched.h, do you plan to move it in asm-x86?Oh, I hadn't realised it was already common. I don't plan to move it myself.
It might be a good thing to prevent people using is_{hvm,pv,pvh}_domain in common code.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 05/13] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Quoted 10 lines · Julien Grall
Quoted 6 lines · Ian Campbell
Quoted 2 lines · Julien Grall
It will be exposed to common code. For now
is_pvh_domainis part ofxen/sched.h, do you plan to move it in asm-x86?Oh, I hadn't realised it was already common. I don't plan to move it myself.
It might be a good thing to prevent people using is_{hvm,pv,pvh}_domain in common code.
Certainly it's a worth cause.
Ian.
PATCH v3 6/13 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 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 | 483 +--------------------------------- xen/drivers/passthrough/pci.c | 452 +++++++++++++++++++++++++++++++ xen/drivers/passthrough/x86/Makefile | 1 + xen/drivers/passthrough/x86/iommu.c | 50 ++++ xen/include/asm-x86/iommu.h | 42 +++ xen/include/xen/hvm/iommu.h | 1 + xen/include/xen/iommu.h | 47 ++-- 8 files changed, 588 insertions(+), 492 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 +14 -469
527 lines not on this page · raw message
xen/drivers/passthrough/pci.c +452 -0
464 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 +50 -0
50 lines not on this page · raw message
xen/include/asm-x86/iommu.h new file +42 -0
42 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 +26 -21
123 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code
xen/drivers/passthrough/pci.c
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/drivers/passthrough/pci.c +2
-0+static int iommu_populate_page_table (struct domain *d) +{
I continue to be of the opinion that this is misplaced here. There's nothing PCI-related in this function, and I doubt you can get away on ARM without similar code (if you can, this should go into .../x86/iommu.c imo).
xen/include/asm-x86/iommu.h line 32
Quoted 4 lines
xen/include/asm-x86/iommu.h new file +1
-0+void iommu_set_dom0_mapping (struct domain *d);
How is this x86-specific?
Jan
Re: [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code
Hello Jan,
Quoted 11 lines · Jan Beulich
xen/drivers/passthrough/pci.c
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/drivers/passthrough/pci.c +2
-0+static int iommu_populate_page_table (struct domain *d) +{I continue to be of the opinion that this is misplaced here. There's nothing PCI-related in this function, and I doubt you can get away on ARM without similar code (if you can, this should go into
.../x86/iommu.cimo).
On ARM, the page table is shared with the processor, we don't need to populate the page table. Furthermore, this function is using "arch.relmem_list", which is not implemented on ARM.
I can move it in x86/iommu.c and implemented the function is no-op on ARM.
Quoted 7 lines
xen/include/asm-x86/iommu.h line 32
Quoted 5 lines
xen/include/asm-x86/iommu.h new file +1
-0+void iommu_set_dom0_mapping (struct domain *d);How is this x86-specific?
iommu_set_dom0_mapping is implemented in vtd/x86/vtd.c and only used by vtd/iommu.c.
I think this function should be renamed to iommu_vtd_set_dom0_mapping.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code
Quoted 14 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 11 lines · Jan Beulich
xen/drivers/passthrough/pci.c
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Julien Grall
xen/drivers/passthrough/pci.c +2
-0+static int iommu_populate_page_table (struct domain *d) +{I continue to be of the opinion that this is misplaced here. There's nothing PCI-related in this function, and I doubt you can get away on ARM without similar code (if you can, this should go into
.../x86/iommu.cimo).
Quoted 5 lines
On ARM, the page table is shared with the processor, we don't need to populate the page table. Furthermore, this function is using "arch.relmem_list", which is not implemented on ARM.
I can move it in
x86/iommu.cand implemented the function is no-op on ARM.
Yes, please.
Quoted 11 lines
Quoted 6 lines
xen/include/asm-x86/iommu.h line 32
Quoted 4 lines
xen/include/asm-x86/iommu.h new file +1
-0+void iommu_set_dom0_mapping (struct domain *d);How is this x86-specific?
iommu_set_dom0_mappingis implemented invtd/x86/vtd.cand only used byvtd/iommu.c.I think this function should be renamed to
iommu_vtd_set_dom0_mapping.
Ah, indeed. But apart from naming the function properly, it being VT-d only its declaration should be moved into xen/drivers/passthrough/vtd/extern.h instead.
Jan
Re: [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code
In reply to Julien GrallQuoted 10 lines · Julien Grall
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
io.ccontains x86 HVM specific code. Only compile for x86.
Move it to x86/io.c then ?
(no other comments above what Jan has already said)
Ian.
Re: [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code
Hi Ian,
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Julien Grall
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 3 lines
Quoted 1 line
io.ccontains x86 HVM specific code. Only compile for x86.Move it to
x86/io.cthen ?
For now it contains mostly x86 code. The file contains function handle handle pt_irq. I'm not 100% sure if we will need some part for ARM.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code
Quoted 13 lines · Julien Grall
Hi Ian,
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Julien Grall
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 6 lines
Quoted 3 lines
Quoted 1 line
io.ccontains x86 HVM specific code. Only compile for x86.Move it to
x86/io.cthen ?For now it contains mostly x86 code. The file contains function handle handle
pt_irq. I'm not 100% sure if we will need some part for ARM.
Split the certainly-x86 code out into x86/io.c then and leave the plausibly-common stuff in io.c?
Ian
Re: [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code
Quoted 5 lines · Ian Campbell
Quoted 2 lines
For now it contains mostly x86 code. The file contains function handle handle
pt_irq. I'm not 100% sure if we will need some part for ARM.Split the certainly-x86 code out into
x86/io.cthen and leave the plausibly-common stuff inio.c?
Do you mind if I let this part until someone will work device passthrough will be done?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 06/13] xen/passthrough: iommu: Split generic IOMMU code
Quoted 9 lines · Julien Grall
Quoted 5 lines · Ian Campbell
Quoted 2 lines
For now it contains mostly x86 code. The file contains function handle handle
pt_irq. I'm not 100% sure if we will need some part for ARM.Split the certainly-x86 code out into
x86/io.cthen and leave the plausibly-common stuff inio.c?Do you mind if I let this part until someone will work device passthrough will be done?
OK.
PATCH v3 7/13 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_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 | 28 +++------- xen/drivers/passthrough/vtd/iommu.c | 80 +++++++++++++-------------- xen/drivers/passthrough/x86/iommu.c | 41 ++++++++++++++ xen/include/asm-x86/hvm/iommu.h | 28 ++++++++++ xen/include/asm-x86/iommu.h | 4 +- xen/include/xen/hvm/iommu.h | 25 +-------- xen/include/xen/iommu.h | 16 +++--- 13 files changed, 190 insertions(+), 154 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_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 +7 -21
@@ -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)
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 +28 -0
@@ -39,4 +39,32 @@ 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 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 +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 -24
@@ -23,31 +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 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 +8 -8
@@ -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);
@@ -81,9 +79,6 @@ struct hvm_irq_dpci *domain_get_irq_dpci(const struct domain *);void free_hvm_irq_dpci (struct hvm_irq_dpci *dpci);bool_t pt_irq_need_timer (uint32_t flags); -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); -#define PT_IRQ_TIME_OUT MILLISECS(8)#endif /* HAS_PCI */
@@ -127,6 +122,11 @@ struct iommu_ops {void (*dump_p2m_table)(struct domain *d); }; +#ifdef HAS_PCI +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); +#endif +void iommu_suspend (void );void iommu_resume (void );void iommu_crash_shutdown (void );
Signature · 1 line
1.7.10.4
Re: [PATCH v3 07/13] xen/passthrough: iommu: Introduce arch specific code
xen/drivers/passthrough/x86/iommu.c int __init iommu_setup_hpet_msi(struct msi_desc *msi) · line 49
Quoted 7 lines · Julien Grall
xen/drivers/passthrough/x86/iommu.c +7
-0+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); +}
Hmmm ... I should have removed this function for passthrough/x86/iommu.c. By mistake it's duplicate with the one in passthrough/iommu.c
Signature · 1 line
Julien Grall
Re: [PATCH v3 07/13] xen/passthrough: iommu: Introduce arch specific code
In reply to Julien GrallQuoted 10 lines
Quoted 1 line
Quoted 1 line · 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/destruction
Quoted 4 lines
Also move
iommu_use_hap_ptanddomain_hvm_iommuinasm-x86/iommu.h.Signed-off-by Julien Grall <[email protected]>Cc Keir Fraser <[email protected]>
Quoted 1,001 lines
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]>--- 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 | 28 +++------- xen/drivers/passthrough/vtd/iommu.c | 80 +++++++++++++-------------- xen/drivers/passthrough/x86/iommu.c | 41 ++++++++++++++ xen/include/asm-x86/hvm/iommu.h | 28 ++++++++++ xen/include/asm-x86/iommu.h | 4 +- xen/include/xen/hvm/iommu.h | 25 +-------- xen/include/xen/iommu.h | 16 +++--- 13 files changed, 190 insertions(+), 154 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_guest.c +2
-2@@ -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)xen/drivers/passthrough/amd/iommu_guest.c +2
-2@@ -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 +2
-2@@ -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, unsignedlong 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);xen/drivers/passthrough/amd/iommu_map.c +2
-2@@ -448,8 +448,8 @@ static int iommu_pde_from_gfn(struct domain *d, unsignedlong 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 );xen/drivers/passthrough/amd/iommu_map.c +3
-3@@ -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 ){xen/drivers/passthrough/amd/iommu_map.c +2
-2@@ -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"xen/drivers/passthrough/amd/iommu_map.c +2
-2@@ -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;xen/drivers/passthrough/amd/iommu_map.c +2
-2@@ -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 */
xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -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;xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -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;xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -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;xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -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);xen/drivers/passthrough/amd/iommu_map.c +3
-3@@ -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 */
xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -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;xen/drivers/passthrough/amd/iommu_map.c +1
-1@@ -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;xen/drivers/passthrough/amd/iommu_map.c +5
-5@@ -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 +17
-16@@ -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 && (domain->domain_id ==0 ) ) 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);@@ -225,17 +226,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 ; }@@ -262,14 +263,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);@@ -332,7 +333,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);@@ -372,7 +373,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);xen/drivers/passthrough/amd/pci_amd_iommu.c +8
-8@@ -454,13 +455,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); }@@ -591,11 +592,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 +7
-21@@ -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)xen/drivers/passthrough/vtd/iommu.c +4
-4@@ -248,16 +248,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
xen/drivers/passthrough/vtd/iommu.c +2
-2@@ -265,11 +265,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);xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -579,7 +579,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;xen/drivers/passthrough/vtd/iommu.c +4
-4@@ -621,12 +621,12 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr) u64 pg_maddr;struct mapped_rmrr *mrmrr; -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 ; }@@ -635,13 +635,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) )
xen/drivers/passthrough/vtd/iommu.c +2
-2@@ -652,8 +652,8 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr) /* if the cleared address is between mapped RMRR region, * remove the mapped RMRR */ - spin_lock(&hd->mapping_lock); - list_for_each_entry ( mrmrr, &hd->mapped_rmrrs, list ) + spin_lock(&hd->arch.mapping_lock); + list_for_each_entry ( mrmrr, &hd->arch.mapped_rmrrs, list ) {if ( addr >= mrmrr->base && addr <= mrmrr->end ){xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -662,7 +662,7 @@ static void dma_pte_clear_one(struct domain *domain, u64 addr)break ; } } -spin_unlock (&hd->mapping_lock); +spin_unlock (&hd->arch.mapping_lock); }static void
iommu_free_pagetable(u64 pt_maddr, int level)xen/drivers/passthrough/vtd/iommu.c +18
-18@@ -1247,7 +1247,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 ; }@@ -1344,16 +1344,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 ;@@ -1361,7 +1361,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-- )@@ -1379,7 +1379,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) )@@ -1405,7 +1405,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);@@ -1648,7 +1648,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 )@@ -1707,10 +1707,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(@@ -1729,12 +1729,12 @@ static int intel_iommu_map_page(if ( iommu_passthrough && (d->domain_id ==0 ) )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);@@ -1751,14 +1751,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) )@@ -1792,7 +1792,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;xen/drivers/passthrough/vtd/iommu.c +2
-2@@ -1833,7 +1833,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,@@ -1848,10 +1848,10 @@ static int rmrr_identity_mapping(struct domain *d,ASSERT (rmrr->base_address < rmrr->end_address);/* -* No need to acquire hd->mapping_lock, as the only theoretical race is +* No need to acquire hd->arch.mapping_lock, as the only theoretical race is
* with the insertion below (impossible due to holdingpcidevs_lock). */xen/drivers/passthrough/vtd/iommu.c +6
-6-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 )@@ -1876,9 +1876,9 @@ static int rmrr_identity_mapping(struct domain *d,return -ENOMEM ; mrmrr->base = rmrr->base_address; mrmrr->end = rmrr->end_address; -spin_lock (&hd->mapping_lock); -list_add_tail (&mrmrr->list, &hd->mapped_rmrrs); -spin_unlock (&hd->mapping_lock); +spin_lock (&hd->arch.mapping_lock); +list_add_tail (&mrmrr->list, &hd->arch.mapped_rmrrs); +spin_unlock (&hd->arch.mapping_lock);return 0 ; }@@ -2423,8 +2423,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_opsintel_iommu_ops= {xen/drivers/passthrough/x86/iommu.c +41
-0@@ -40,6 +40,47 @@ int __init iommu_setup_hpet_msi(struct msi_desc *msi)return ops->setup_hpet_msi ? ops->setup_hpet_msi (msi) : -ENODEV ; } +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); +} + +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, *rmrr_list, *tmp; +struct g2m_ioport *ioport; +struct mapped_rmrr *mrmrr; + + 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); + } + + list_for_each_safe ( rmrr_list, tmp, &hd->arch.mapped_rmrrs ) + { + mrmrr = list_entry(rmrr_list, struct mapped_rmrr, list); +list_del (&mrmrr->list); +xfree (mrmrr); + } +} +/* * Local variables: * mode: C xen/include/asm-x86/hvm/iommu.h +18
-0@@ -39,4 +39,32 @@ 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 */
xen/include/asm-x86/hvm/iommu.h +6
-0+/* amd iommu support */ +int paging_mode; +struct page_info *root_table; +struct guest_iommu *g_iommu; + +struct list_head g2m_ioport_list;/* guest to machine ioport mapping */
xen/include/asm-x86/hvm/iommu.h +4
-0+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 +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 +0
-18@@ -23,31 +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 */
xen/include/xen/hvm/iommu.h +1
-6-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 +3
-8@@ -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);@@ -81,9 +79,6 @@ struct hvm_irq_dpci *domain_get_irq_dpci(const struct domain *);void free_hvm_irq_dpci (struct hvm_irq_dpci *dpci);bool_t pt_irq_need_timer (uint32_t flags); -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); -#define
PT_IRQ_TIME_OUTMILLISECS(8)
#endif /*HAS_PCI*/xen/include/xen/iommu.h +5
-0@@ -127,6 +122,11 @@ struct iommu_ops {void (*dump_p2m_table)(struct domain *d); }; +#ifdef HAS_PCI +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); +#endif +void iommu_suspend (void );void
iommu_resume(void);
voidiommu_crash_shutdown(void);Signature · 1 line
1.7.10.4
Re: [PATCH v3 07/13] xen/passthrough: iommu: Introduce arch specific code
In reply to Julien Grallxen/include/asm-x86/hvm/iommu.h static inline int iommu_hardware_setup(void) · line 59
Quoted 5 lines · Julien Grall
xen/include/asm-x86/hvm/iommu.h +5
-0+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 */
Blank line here for clarity?
xen/include/asm-x86/hvm/iommu.h static inline int iommu_hardware_setup(void) · line 64
Quoted 5 lines
xen/include/asm-x86/hvm/iommu.h +5
-0+/* amd iommu support */ +int paging_mode; +struct page_info *root_table; +struct guest_iommu *g_iommu; +
I don't think the following are amd specific, in their original home they were up with pgd_maddr and co any way. If they are to stay here perhaps a new /* heading */ comment would help?
xen/include/asm-x86/hvm/iommu.h static inline int iommu_hardware_setup(void) · line 69
Quoted 5 lines
xen/include/asm-x86/hvm/iommu.h +5
-0+struct list_head g2m_ioport_list;/* guest to machine ioport mapping */ +struct list_head mapped_rmrrs; +spinlock_t mapping_lock;/* io page table lock */ +}; +
Ian.
Re: [PATCH v3 07/13] xen/passthrough: iommu: Introduce arch specific code
Hi Ian,
Quoted 8 lines · Ian Campbell
xen/include/asm-x86/hvm/iommu.h static inline int iommu_hardware_setup(void) · line 59
Quoted 5 lines · Julien Grall
xen/include/asm-x86/hvm/iommu.h +5
-0+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 */ Blank line here for clarity?
Sure.
Quoted 9 lines
xen/include/asm-x86/hvm/iommu.h static inline int iommu_hardware_setup(void) · line 64
Quoted 5 lines
xen/include/asm-x86/hvm/iommu.h +5
-0+/* amd iommu support */ +int paging_mode; +struct page_info *root_table; +struct guest_iommu *g_iommu; +I don't think the following are amd specific, in their original home they were up with
pgd_maddrand co any way. If they are to stay here perhaps a new /* heading */ comment would help?
I don't remember why I changed the order. I will go back to original order in the next version.
Regards,
Signature · 1 line
Julien Grall
PATCH v3 8/13 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 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 | 106 +++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 14 +++++ xen/include/xen/hvm/iommu.h | 6 ++ xen/include/xen/iommu.h | 16 +++++ 6 files changed, 147 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/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 HAS_PCI struct msi_desc ;struct msi_msg ;
@@ -103,6 +113,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 v3 08/13] xen/passthrough: iommu: Basic support of device tree assignment
Quoted 9 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]>Cc Xiantao Zhang <[email protected]>
For the modifications to existing files:
Quoted 264 lines
---
Changes in v3:
- Remove iommu_dt_domain_{init,destroy} call in common code. Let architecture code to call them
- Fix indentation inxen/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 | 106 +++++++++++++++++++++++++++++++++ xen/include/xen/device_tree.h | 14 +++++ xen/include/xen/hvm/iommu.h | 6 ++ xen/include/xen/iommu.h | 16 +++++ 6 files changed, 147 insertions(+) create mode 100644 xen/drivers/passthrough/device_tree.cxen/common/device_tree.c +4
-0@@ -1695,6 +1695,10 @@ static unsigned long __init unflatten_dt_node(constvoid *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.oxen/drivers/passthrough/device_tree.c new file +106
-0@@ -0,0 +1,106 @@ +/* +* xen/drivers/passthrough/arm/device_tree.c +* +* Code to passthrough device tree node to a guest +* +* Julien Grall <[email protected]> +* Copyright (c) 2014 Linaro Limited. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that 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. +*/ + +#include <xen/lib.h> +#include <xen/sched.h> +#include <xen/iommu.h> +#include <xen/device_tree.h> + +static spinlock_t dtdevs_lock =SPIN_LOCK_UNLOCKED ; + +int iommu_assign_dt_device (struct domain *d,struct dt_device_node *dev) +{ +int rc = -EBUSY ; +struct hvm_iommu *hd =domain_hvm_iommu (d); + +if ( !iommu_enabled || !hd->platform_ops ) +return -EINVAL ; + +if ( !dt_device_is_protected (dev) ) +return -EINVAL ; + +spin_lock (&dtdevs_lock); + +if ( !list_empty (&dev->next_assigned) ) + goto fail; + + rc = hd->platform_ops->assign_dt_device (d, dev); + +if ( rc ) + goto fail; + +list_add (&dev->next_assigned, &hd->dt_devices); +dt_device_set_used_by (dev, d->domain_id); + +fail: +spin_unlock (&dtdevs_lock); + +return rc; +} + +int iommu_deassign_dt_device (struct domain *d,struct dt_device_node *dev) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); +int rc; + +if ( !iommu_enabled || !hd->platform_ops ) +return -EINVAL ; + +if ( !dt_device_is_protected (dev) ) +return -EINVAL ; + +spin_lock (&dtdevs_lock); + + rc = hd->platform_ops->reassign_dt_device (d, dom0, dev); +if ( rc ) + goto fail; + +dt_device_set_used_by (dev, dom0->domain_id); + +list_del (&dev->next_assigned); + +fail: +spin_unlock (&dtdevs_lock); + +return rc; +} + +int iommu_dt_domain_init (struct domain *d) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); + +INIT_LIST_HEAD (&hd->dt_devices); + +return 0 ; +} + +void iommu_dt_domain_destroy (struct domain *d) +{ +struct hvm_iommu *hd =domain_hvm_iommu (d); +struct dt_device_node *dev, *_dev; +int rc; + +list_for_each_entry_safe (dev, _dev, &hd->dt_devices, next_assigned) + { + rc =iommu_deassign_dt_device (d, dev); +if ( rc ) +dprintk (XENLOG_ERR ,"Failed to deassign %s in domain %u\n" , +dt_node_full_name (dev), d->domain_id); + } +}xen/include/xen/device_tree.h +1
-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;xen/include/xen/device_tree.h +13
-0+/* 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 HAS_PCI struct msi_desc ;struct msi_msg ;@@ -103,6 +113,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 v3 08/13] xen/passthrough: iommu: Basic support of device tree assignment
In reply to Julien GrallQuoted 5 lines · 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 domain
Am I correct that this list is not maintained for dom0? The behaviour of dt_assign_device and dt_deassign_device seems to rely on it?
Quoted 3 lines
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>
Ian.
Re: [PATCH v3 08/13] xen/passthrough: iommu: Basic support of device tree assignment
Hi Ian,
Quoted 9 lines · Ian Campbell
Quoted 5 lines · 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 domainAm I correct that this list is not maintained for dom0? The behaviour of
dt_assign_deviceanddt_deassign_deviceseems to rely on it?
DOM0 will call dt_assign_device for every device protected by the IOMMU (see patch #9). So it will itself have a list maintained.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 08/13] xen/passthrough: iommu: Basic support of device tree assignment
Quoted 10 lines · Julien Grall
Hi Ian,
Quoted 7 lines · Ian Campbell
Quoted 5 lines · 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 domain
Quoted 5 lines
Quoted 2 lines
Am I correct that this list is not maintained for dom0? The behaviour of
dt_assign_deviceanddt_deassign_deviceseems to rely on it?DOM0 will call
dt_assign_devicefor every device protected by the IOMMU (see patch #9). So it will itself have a list maintained.
Does this not mean that iommu_assign_dt_device will refuse to assign the device to another domain (next_assigned list is not empty).
BTW, next_assigned is not a very good name for this list, since the "nextness" is abstracted away. Consider just device_list.
Ian.
Re: [PATCH v3 08/13] xen/passthrough: iommu: Basic support of device tree assignment
Hi Ian,
Quoted 8 lines · Ian Campbell
Quoted 8 lines · Ian Campbell
Quoted 7 lines · Julien Grall
Quoted 5 lines
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 domain
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Am I correct that this list is not maintained for dom0? The behaviour of
dt_assign_deviceanddt_deassign_deviceseems to rely on it?DOM0 will call
dt_assign_devicefor every device protected by the IOMMU (see patch #9). So it will itself have a list maintained.Does this not mean that
iommu_assign_dt_devicewill refuse to assign the device to another domain (next_assignedlist is not empty).
Yes. After thinking, I'm not sure we want maintain a list for dom0.
At least the iommu_deassign_dt_device function is wrong because the device is not reassigned to dom0 (from the list point of view).
Quoted 2 lines
BTW,
next_assignedis not a very good name for this list, since the "nextness" is abstracted away. Consider justdevice_list.
I found device_list too generic. We don't know if it's the list of all the devices or just the ones of a specific domain.
What about domain_device_list?
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 08/13] xen/passthrough: iommu: Basic support of device tree assignment
Quoted 7 lines · Julien Grall
Quoted 2 lines
BTW,
next_assignedis not a very good name for this list, since the "nextness" is abstracted away. Consider justdevice_list.I found
device_listtoo generic. We don't know if it's the list of all the devices or just the ones of a specific domain.What about
domain_device_list?
Just domain_list would do I think, device is before the -> in the uses.
Ian.
PATCH v3 9/13 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 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 | 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 | 70 ++++++++++++++++++++++++++++++++++ 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, 152 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
@@ -550,6 +550,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:
@@ -561,6 +564,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++ ) {
@@ -754,7 +766,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 = {
@@ -775,7 +787,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;
@@ -1008,6 +1020,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
@@ -725,6 +725,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 +70 -0
70 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
Re: [PATCH v3 09/13] xen/passthrough: Introduce IOMMU ARM architecture
Quoted 10 lines · Julien Grall
xen/arch/arm/domain_build.c +1
-1@@ -754,7 +766,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 = {
xen/arch/arm/domain_build.c static int handle_node(struct domain *d, struct kernel_info *kinfo, · line 790
Quoted 5 lines
xen/arch/arm/domain_build.c +1
-1@@ -775,7 +787,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;
Why do these consts become unwanted?
Quoted 5 lines
xen/drivers/passthrough/arm/iommu.c new file +0
-0
[...]
xen/drivers/passthrough/arm/iommu.c line 48
Quoted 7 lines
xen/drivers/passthrough/arm/iommu.c new file +7
-0+int __init iommu_hardware_setup (void ) +{ +struct dt_device_node *np; +int rc; +unsigned int num_iommus =0 ; + +dt_for_each_device_node (dt_host, np)
I can't find dt_host in this or any of the previous patches.
Quoted 6 lines
xen/drivers/passthrough/arm/iommu.c new file +6
-0+ { + rc =device_init (np,DEVICE_IOMMU ,NULL ); +if ( !rc ) + num_iommus++; + } +
xen/drivers/passthrough/arm/iommu.c line 64
Quoted 10 lines
xen/drivers/passthrough/arm/iommu.c new file +10
-0+return ( num_iommus >0 ) ?0 : -ENODEV ; +} + +int arch_iommu_domain_init (struct domain *d) +{ +int ret; + + ret =iommu_dt_domain_init (d); + +return ret;
return iommu_dt-domain_init(d);
?
xen/include/asm-arm/iommu.h line 20
Quoted 7 lines
xen/include/asm-arm/iommu.h new file +1
-0+#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu)
Does this macro give us the freedom to avoid the term "hvm" a bit and use d->arch.iommu?
Ian.
Re: [PATCH v3 09/13] xen/passthrough: Introduce IOMMU ARM architecture
Hi Ian,
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Julien Grall
(quoted diff) +0
-0@@ -754,7 +766,7 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) }
Quoted 14 lines
xen/arch/arm/domain_build.c static int handle_node(struct domain *d, struct kernel_info *kinfo, · line 790
Quoted 12 lines
xen/arch/arm/domain_build.c +2
-2static 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 = {@@ -775,7 +787,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;Why do these consts become unwanted?
Because map_device now calls iommu_assign_dt_device which will update next_assigned in the structure dt_device_node.
Quoted 6 lines
Quoted 5 lines
xen/drivers/passthrough/arm/iommu.c new file +0
-0[...]
Quoted 9 lines
xen/drivers/passthrough/arm/iommu.c line 48
Quoted 7 lines
xen/drivers/passthrough/arm/iommu.c new file +7
-0+int __init iommu_hardware_setup (void ) +{ +struct dt_device_node *np; +int rc; +unsigned int num_iommus =0 ; + +dt_for_each_device_node (dt_host, np)I can't find
dt_hostin this or any of the previous patches.
dt_host was defined a while ago by the device tree code (see xen/include/xen/device_tree.h).
Quoted 11 lines
Quoted 11 lines
xen/drivers/passthrough/arm/iommu.c new file +11
-0+ { + rc =device_init (np,DEVICE_IOMMU ,NULL ); +if ( !rc ) + num_iommus++; + } + +return ( num_iommus >0 ) ?0 : -ENODEV ; +} + +int arch_iommu_domain_init (struct domain *d) +{
Quoted 8 lines
xen/drivers/passthrough/arm/iommu.c line 64
Quoted 5 lines
xen/drivers/passthrough/arm/iommu.c new file +5
-0+int ret; + + ret =iommu_dt_domain_init (d); + +return ret;return iommu_dt-domain_init(d);
?
I will do the change in the next version.
Quoted 10 lines
xen/include/asm-arm/iommu.h line 20
Quoted 7 lines
xen/include/asm-arm/iommu.h new file +1
-0+#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu)Does this macro give us the freedom to avoid the term "hvm" a bit and use
d->arch.iommu?
It's possible, I just blindly copied from x86.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 09/13] xen/passthrough: Introduce IOMMU ARM architecture
Quoted 22 lines · Julien Grall
Hi Ian,
Quoted 4 lines · Ian Campbell
Quoted 3 lines · Julien Grall
(quoted diff) +0
-0@@ -754,7 +766,7 @@ static int map_device(struct domain *d, const struct dt_device_node *dev) }Quoted 14 lines
xen/arch/arm/domain_build.c static int handle_node(struct domain *d, struct kernel_info *kinfo, · line 790
Quoted 12 lines
xen/arch/arm/domain_build.c +2
-2static 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 = {@@ -775,7 +787,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;Why do these consts become unwanted?
Quoted 2 lines
Because
map_devicenow callsiommu_assign_dt_devicewhich will updatenext_assignedin the structuredt_device_node.
OK, makes sense.
Quoted 16 lines
Quoted 6 lines
Quoted 5 lines
xen/drivers/passthrough/arm/iommu.c new file +0
-0[...]
Quoted 9 lines
xen/drivers/passthrough/arm/iommu.c line 48
Quoted 7 lines
xen/drivers/passthrough/arm/iommu.c new file +7
-0+int __init iommu_hardware_setup (void ) +{ +struct dt_device_node *np; +int rc; +unsigned int num_iommus =0 ; + +dt_for_each_device_node (dt_host, np)I can't find
dt_hostin this or any of the previous patches.
Quoted 2 lines
dt_hostwas defined a while ago by the device tree code (seexen/include/xen/device_tree.h).
Doh, I didn't think to look at the existing code ;-)
Quoted 11 lines
Quoted 10 lines
xen/include/asm-arm/iommu.h line 20
Quoted 7 lines
xen/include/asm-arm/iommu.h new file +1
-0+#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu)Does this macro give us the freedom to avoid the term "hvm" a bit and use
d->arch.iommu?
Quoted 1 line
It's possible, I just blindly copied from x86.
Ian.
PATCH v3 10/13 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 v3 11/13 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>
@@ -822,6 +823,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
Re: [PATCH v3 11/13] xen/arm: Don't give IOMMU devices to dom0 when iommu is disabled
Quoted 4 lines · Julien Grall
When 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.
Signed-off-by Julien Grall <[email protected]>
PATCH v3 12/13 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 */
@@ -843,7 +881,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;
@@ -874,7 +912,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;
@@ -1027,6 +1065,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 v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 6 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.
Quoted 6 lines
Signed-off-by Julien Grall <[email protected]>---
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.
LVM works these days I think.
Quoted 39 lines
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 +6
-3@@ -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" );
xen/arch/arm/domain_build.c static int make_hypervisor_node(struct domain *d, · line 392
Quoted 6 lines
xen/arch/arm/domain_build.c +3
-0@@ -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 */
Why not? Please explain in the comment.
xen/arch/arm/domain_build.c static int make_hypervisor_node(struct domain *d, · line 398
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+ cells =xmalloc_array (__be32, kinfo->num_dev_protected * +dt_size_to_cells (sizeof (dt_phandle))); +if ( !cells ) +return -FDT_ERR_XEN (ENOMEM ); + + _cells = cells;
Odd numbers of leading _ are reserved for the compiler IIRC. Even numbers are reserved for the libc/environment which is why we can get away with such names in hypervisor context.
But lets just skirt the whole issue and pick a name which doesn't use a leading _. cells_iter or c or something.
Is there no interface to say "make an fdt_property(name, size)" returning the data to be filled in?
Ian.
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Hi Ian,
Quoted 7 lines · Ian Campbell
Quoted 6 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.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Julien Grall <[email protected]>---
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.LVM works these days I think.
With this patch series applied, LVM will be broken if the hard drive is protected by an IOMMU. It's the case on midway, the platform will crash just after the guest begins to boot.
Quoted 9 lines
xen/arch/arm/domain_build.c static int make_hypervisor_node(struct domain *d, · line 392
Quoted 7 lines
xen/arch/arm/domain_build.c +3
-0@@ -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 */ Why not? Please explain in the comment.
Because, building dom0 is only done with 1 CPU online (e.g CPU0). I though it was obvious, I will update the comment.
Quoted 11 lines
xen/arch/arm/domain_build.c static int make_hypervisor_node(struct domain *d, · line 398
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+ cells =xmalloc_array (__be32, kinfo->num_dev_protected * +dt_size_to_cells (sizeof (dt_phandle))); +if ( !cells ) +return -FDT_ERR_XEN (ENOMEM ); + + _cells = cells;Odd numbers of leading _ are reserved for the compiler IIRC. Even numbers are reserved for the libc/environment which is why we can get away with such names in hypervisor context.
Quoted 5 lines
But lets just skirt the whole issue and pick a name which doesn't use a leading _.
cells_iteror c or something.Is there no interface to say "make an
fdt_property(name, size)" returning the data to be filled in?
No, every helpers request to have an input data in parameters.
I will rename _cells into cells_iter.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 17 lines · Julien Grall
Hi Ian,
Quoted 14 lines · Ian Campbell
Quoted 12 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]>---
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.
Quoted 4 lines
Quoted 1 line
LVM works these days I think.
With this patch series applied, LVM will be broken if the hard drive is protected by an IOMMU.
How/why?
Quoted 2 lines
It's the case on midway, the platform will crash just after the guest begins to boot.
This configuration works today (osstest tests it) so this would be a regression. Can you sort this please?
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
xen/arch/arm/domain_build.c +0
-0@@ -384,6 +387,39 @@ static int make_hypervisor_node(struct domain *d,if ( res )return res;
Quoted 8 lines
Quoted 5 lines
xen/arch/arm/domain_build.c static int make_hypervisor_node(struct domain *d, · line 392
Quoted 3 lines
xen/arch/arm/domain_build.c +3
-0+if ( kinfo->num_dev_protected ) + { +/* Don't need to take dtdevs_lock here */ Why not? Please explain in the comment.
Because, building dom0 is only done with 1 CPU online (e.g CPU0). I though it was obvious, I will update the comment.
Locking is never obvious IMHO.
Quoted 11 lines
Quoted 11 lines
xen/arch/arm/domain_build.c static int make_hypervisor_node(struct domain *d, · line 398
Quoted 6 lines
xen/arch/arm/domain_build.c +6
-0+ cells =xmalloc_array (__be32, kinfo->num_dev_protected * +dt_size_to_cells (sizeof (dt_phandle))); +if ( !cells ) +return -FDT_ERR_XEN (ENOMEM ); + + _cells = cells;Odd numbers of leading _ are reserved for the compiler IIRC. Even numbers are reserved for the libc/environment which is why we can get away with such names in hypervisor context.
Quoted 7 lines
Quoted 5 lines
But lets just skirt the whole issue and pick a name which doesn't use a leading _.
cells_iteror c or something.Is there no interface to say "make an
fdt_property(name, size)" returning the data to be filled in?No, every helpers request to have an input data in parameters.
fdt_setprop_inplace isn't helpful because you need to be able to create the empty prop, which doesn't exist. Oh well.
Quoted 1 line
I will rename
_cellsintocells_iter.
Thanks.
Ian.
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Hi Ian,
Sorry, I forgot to answer to this email...
Quoted 18 lines · Ian Campbell
Quoted 17 lines · Julien Grall
Hi Ian,
Quoted 14 lines · Ian Campbell
Quoted 12 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]>---
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.
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
LVM works these days I think.
With this patch series applied, LVM will be broken if the hard drive is protected by an IOMMU.
How/why?
If the guest is using LVM for its block, bouncing via the swiotlb with IOMMU enabled will result to wrong mapping. If I remember correctly it's because SWIOTLB DMA address is a physical address and not an IPA. So the IOMMU will rejected the request.
So we have to by-pass swiotlb in this case.
Quoted 6 lines
Quoted 3 lines
It's the case on midway, the platform will crash just after the guest begins to boot.
This configuration works today (osstest tests it) so this would be a regression. Can you sort this please?
As said above with IOMMU enabled I won't be able to sort it until my patch series for Linux will be upstreamed.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 28 lines · Julien Grall
Hi Ian,
Sorry, I forgot to answer to this email...
Quoted 23 lines · Ian Campbell
Quoted 21 lines · Julien Grall
Hi Ian,
Quoted 7 lines · Ian Campbell
Quoted 6 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.
Quoted 8 lines
Quoted 6 lines
Signed-off-by Julien Grall <[email protected]>---
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.LVM works these days I think.
With this patch series applied, LVM will be broken if the hard drive is protected by an IOMMU.
Quoted 6 lines
Quoted 1 line
How/why?
If the guest is using LVM for its block, bouncing via the swiotlb with IOMMU enabled will result to wrong mapping. If I remember correctly it's because SWIOTLB DMA address is a physical address and not an IPA. So the IOMMU will rejected the request.
Can this not be made to work? The swiotlb shouldn't be breaking things like this, regardless of whether there is an iommu which it doesn't know about it should be returning sane results, which might imply the Xen needs to be giving it sensible results.
At what point is the IOMMU rejecting the request? I didn't expect it to be involved in the swiotlb path -- that's a copy into dom0 owned RAM with a known 1:1 mapping (provided either by the literal use of a 1:1 mapping or by using the IOMMU to give the guest that impression).
Quoted 11 lines
So we have to by-pass swiotlb in this case.
Quoted 6 lines
Quoted 3 lines
It's the case on midway, the platform will crash just after the guest begins to boot.
This configuration works today (osstest tests it) so this would be a regression. Can you sort this please?
As said above with IOMMU enabled I won't be able to sort it until my patch series for Linux will be upstreamed.
We really need to be able to manage this transition in a compatible way, that means new kernels working on old hypervisors as well as old kernels working on new hypervisors (it's obviously fine for this case to bounce when it doesn't need to).
Ian.
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 4 lines · Ian Campbell
We really need to be able to manage this transition in a compatible way, that means new kernels working on old hypervisors as well as old kernels working on new hypervisors (it's obviously fine for this case to bounce when it doesn't need to).
It's not possible because a same platform can have both protected and non-protected devices. The Linux has to know in some way if the DMA has to be program with IPA or PA.
The only way is to disable the IOMMU, or don't use partition disk for guest, until the DOM0 will be able to disable swiotlb.
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 10 lines · Julien Grall
Quoted 4 lines · Ian Campbell
We really need to be able to manage this transition in a compatible way, that means new kernels working on old hypervisors as well as old kernels working on new hypervisors (it's obviously fine for this case to bounce when it doesn't need to).
It's not possible because a same platform can have both protected and non-protected devices. The Linux has to know in some way if the DMA has to be program with IPA or PA.
Then there must be a negotiation between Xen and the Linux kernel so Xen can know which case to apply.
e.g. if the kernel does not advertise support for protected devices then Xen must act as if no IOMMU was present.
Quoted 3 lines
The only way is to disable the IOMMU, or don't use partition disk for guest, until the DOM0 will be able to disable swiotlb.
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 12 lines · Ian Campbell
Quoted 10 lines · Julien Grall
Quoted 4 lines · Ian Campbell
We really need to be able to manage this transition in a compatible way, that means new kernels working on old hypervisors as well as old kernels working on new hypervisors (it's obviously fine for this case to bounce when it doesn't need to).
It's not possible because a same platform can have both protected and non-protected devices. The Linux has to know in some way if the DMA has to be program with IPA or PA.
Quoted 5 lines
Then there must be a negotiation between Xen and the Linux kernel so Xen can know which case to apply.
e.g. if the kernel does not advertise support for protected devices then Xen must act as if no IOMMU was present.
How the kernel can say "I'm supporting IOMMU"? New hypercall?
Xen has to program the IOMMU quite early (e.g before Linux is booting and use the protected device).
Backporting my patch series to support protected devices is not a big deal. What about disabling IOMMU by default on ARM until a good support is made in Linux?
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 13 lines · Julien Grall
Quoted 12 lines · Ian Campbell
Quoted 10 lines · Julien Grall
Quoted 4 lines · Ian Campbell
We really need to be able to manage this transition in a compatible way, that means new kernels working on old hypervisors as well as old kernels working on new hypervisors (it's obviously fine for this case to bounce when it doesn't need to).
It's not possible because a same platform can have both protected and non-protected devices. The Linux has to know in some way if the DMA has to be program with IPA or PA.
Quoted 7 lines
Quoted 5 lines
Then there must be a negotiation between Xen and the Linux kernel so Xen can know which case to apply.
e.g. if the kernel does not advertise support for protected devices then Xen must act as if no IOMMU was present.
How the kernel can say "I'm supporting IOMMU"? New hypercall?
On x86 we use the ELF notes to communicate it at build time. We don't currently have a similar mechanism under ARM but perhaps we need to invent one now.
There is also __HYPERVISOR_vm_assist which is/was used on PV x86 to signal these sorts of things, if its not too late.
Quoted 2 lines
Xen has to program the IOMMU quite early (e.g before Linux is booting and use the protected device).
In that case an ELF note type solution might be the only option.
However, since this stuff only comes to matter when the guest comes to do grant mapping it might be that we can defer until runtime and require that a modern kernel calls vm_assist before making any grant calls. If it doesn't then it is assumed to be unable to cope with the iommu.
Quoted 3 lines
Backporting my patch series to support protected devices is not a big deal. What about disabling IOMMU by default on ARM until a good support is made in Linux?
I'd rather avoid this if at all possible, upgrading Xen is not supposed to require new dom0 kernel features and it is hard to describe "support for protected devices" as a bug fix.
Ian.
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 32 lines · Ian Campbell
Quoted 13 lines · Julien Grall
Quoted 12 lines · Ian Campbell
Quoted 10 lines · Julien Grall
Quoted 4 lines · Ian Campbell
We really need to be able to manage this transition in a compatible way, that means new kernels working on old hypervisors as well as old kernels working on new hypervisors (it's obviously fine for this case to bounce when it doesn't need to).
It's not possible because a same platform can have both protected and non-protected devices. The Linux has to know in some way if the DMA has to be program with IPA or PA.
Quoted 7 lines
Quoted 5 lines
Then there must be a negotiation between Xen and the Linux kernel so Xen can know which case to apply.
e.g. if the kernel does not advertise support for protected devices then Xen must act as if no IOMMU was present.
How the kernel can say "I'm supporting IOMMU"? New hypercall?
On x86 we use the ELF notes to communicate it at build time. We don't currently have a similar mechanism under ARM but perhaps we need to invent one now.
There is also
__HYPERVISOR_vm_assistwhich is/was used on PV x86 to signal these sorts of things, if its not too late.Quoted 2 lines
Xen has to program the IOMMU quite early (e.g before Linux is booting and use the protected device).
Quoted 6 lines
In that case an ELF note type solution might be the only option.
However, since this stuff only comes to matter when the guest comes to do grant mapping it might be that we can defer until runtime and require that a modern kernel calls
vm_assistbefore making any grant calls. If it doesn't then it is assumed to be unable to cope with the iommu.
Using vm_assist means we can't anymore denied access to invalid transaction by default. It sounds like we want to completely disable the IOMMU, because in this case passthrough should not be enabled.
Futhermore, I can't predict what would happen if the device is used and the kernel decides to call vm_assist (e.g protect devices). I suppose we can break the device at this time.
It's not possible in Xen to know if the decide is used or not.
Quoted 7 lines
Quoted 3 lines
Backporting my patch series to support protected devices is not a big deal. What about disabling IOMMU by default on ARM until a good support is made in Linux?
I'd rather avoid this if at all possible, upgrading Xen is not supposed to require new dom0 kernel features and it is hard to describe "support for protected devices" as a bug fix.
But we can chose to disable IOMMU by default on ARM. And the user will have to decide if it's safe or not to use IOMMU.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 35 lines · Julien Grall
Quoted 34 lines · Ian Campbell
Quoted 13 lines · Julien Grall
Quoted 12 lines · Ian Campbell
Quoted 10 lines · Julien Grall
Quoted 4 lines · Ian Campbell
We really need to be able to manage this transition in a compatible way, that means new kernels working on old hypervisors as well as old kernels working on new hypervisors (it's obviously fine for this case to bounce when it doesn't need to).
It's not possible because a same platform can have both protected and non-protected devices. The Linux has to know in some way if the DMA has to be program with IPA or PA.
Quoted 7 lines
Quoted 5 lines
Then there must be a negotiation between Xen and the Linux kernel so Xen can know which case to apply.
e.g. if the kernel does not advertise support for protected devices then Xen must act as if no IOMMU was present.
How the kernel can say "I'm supporting IOMMU"? New hypercall?
On x86 we use the ELF notes to communicate it at build time. We don't currently have a similar mechanism under ARM but perhaps we need to invent one now.
There is also
__HYPERVISOR_vm_assistwhich is/was used on PV x86 to signal these sorts of things, if its not too late.Quoted 2 lines
Xen has to program the IOMMU quite early (e.g before Linux is booting and use the protected device).
In that case an ELF note type solution might be the only option.
Quoted 8 lines
Quoted 4 lines
However, since this stuff only comes to matter when the guest comes to do grant mapping it might be that we can defer until runtime and require that a modern kernel calls
vm_assistbefore making any grant calls. If it doesn't then it is assumed to be unable to cope with the iommu.Using
vm_assistmeans we can't anymore denied access to invalid transaction by default. It sounds like we want to completely disable the IOMMU, because in this case passthrough should not be enabled.
We could enable both of those things only at the point where vm_assist was called.
And yes, if the dom0 kernel isn't capable of doing stuff with the IOMMU enable we should turn off passthrough too.
Quoted 3 lines
Futhermore, I can't predict what would happen if the device is used and the kernel decides to call
vm_assist(e.g protect devices). I suppose we can break the device at this time.
I think we can reasonably require that vm_assist be called super early, i.e. before any DMA operations occur, in Linux terms I think early_initcall(xen_guest_init) is likely early enough, or we could move xen_guestr_init even sooner.
We also have the option of a build time feature flag in the image itself like on x86. It is likely that going forward we will have other cases where we wished we had such a thing so getting it in place now would be useful.
Quoted 1 line
It's not possible in Xen to know if the decide is used or not.
"the decide"?
Quoted 11 lines
Quoted 8 lines
Quoted 4 lines
Backporting my patch series to support protected devices is not a big deal. What about disabling IOMMU by default on ARM until a good support is made in Linux?
I'd rather avoid this if at all possible, upgrading Xen is not supposed to require new dom0 kernel features and it is hard to describe "support for protected devices" as a bug fix.
But we can chose to disable IOMMU by default on ARM. And the user will have to decide if it's safe or not to use IOMMU.
That's a cop out and a rubbish user experience going forward.
Ian.
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 2 lines · Ian Campbell
We could enable both of those things only at the point where
vm_assistwas called.
[..]
Quoted 4 lines
I think we can reasonably require that
vm_assistbe called super early, i.e. before any DMA operations occur, in Linux terms I thinkearly_initcall(xen_guest_init)is likely early enough, or we could movexen_guestr_initeven sooner.
IHMO, this solution is far too complicate and we will have to fork from the current IOMMU framework.
Quoted 4 lines
We also have the option of a build time feature flag in the image itself like on x86. It is likely that going forward we will have other cases where we wished we had such a thing so getting it in place now would be useful.
I definitely prefer this solution which seems more cleaner than the others.
Is it possible to embedded notes in a zImage? How x86 handle other format than ELF?
Quoted 4 lines
Quoted 2 lines
It's not possible in Xen to know if the decide is used or not.
"the decide"?
The device, I mixed multiple sentences together, sorry.
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 6 lines · Julien Grall
Quoted 2 lines · Ian Campbell
We could enable both of those things only at the point where
vm_assistwas called.[..]
Quoted 7 lines
Quoted 4 lines
I think we can reasonably require that
vm_assistbe called super early, i.e. before any DMA operations occur, in Linux terms I thinkearly_initcall(xen_guest_init)is likely early enough, or we could movexen_guestr_initeven sooner.IHMO, this solution is far too complicate and we will have to fork from the current IOMMU framework.
Eh? On the Linux side? You just call this hypercall super early so that you are sure no drivers have initialised yet and you are done, there is no need to fork anything AFAICT. And in any case if any generic framework needs extending to better work with Xen then we should do that, not fork it or make a worse design to sidestep the need.
Obviously there will be complexity on the Xen side, but I think far too complicated will be an overstatement.
Quoted 9 lines
Quoted 4 lines
We also have the option of a build time feature flag in the image itself like on x86. It is likely that going forward we will have other cases where we wished we had such a thing so getting it in place now would be useful.
I definitely prefer this solution which seems more cleaner than the others.
Is it possible to embedded notes in a zImage? How x86 handle other format than ELF?
The x86 bzImage format embeds an ELF file, which something which was done long ago to improve things for Xen PV x86 use which wants to boot an ELF.
ARM zImage doesn't currently have anything like that so you would be looking at an image format extension.
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
It's not possible in Xen to know if the decide is used or not.
"the decide"?
The device, I mixed multiple sentences together, sorry.
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 15 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 2 lines · Ian Campbell
We could enable both of those things only at the point where
vm_assistwas called.[..]
Quoted 7 lines
Quoted 4 lines
I think we can reasonably require that
vm_assistbe called super early, i.e. before any DMA operations occur, in Linux terms I thinkearly_initcall(xen_guest_init)is likely early enough, or we could movexen_guestr_initeven sooner.IHMO, this solution is far too complicate and we will have to fork from the current IOMMU framework.
Quoted 8 lines
Eh? On the Linux side? You just call this hypercall super early so that you are sure no drivers have initialised yet and you are done, there is no need to fork anything AFAICT. And in any case if any generic framework needs extending to better work with Xen then we should do that, not fork it or make a worse design to sidestep the need.
Obviously there will be complexity on the Xen side, but I think far too complicated will be an overstatement.
I was talking about Xen side. The current IOMMU platform would need some rework to support it.
For me this solution is far too complicate compare to the other solutions (e.g ELF note).
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
We also have the option of a build time feature flag in the image itself like on x86. It is likely that going forward we will have other cases where we wished we had such a thing so getting it in place now would be useful.
I definitely prefer this solution which seems more cleaner than the others.
Is it possible to embedded notes in a zImage? How x86 handle other format than ELF?
Quoted 6 lines
The x86 bzImage format embeds an ELF file, which something which was done long ago to improve things for Xen PV x86 use which wants to boot an ELF.
ARM zImage doesn't currently have anything like that so you would be looking at an image format extension.
Ok. So it will be easy to add support for ELF image. However for zImage, do you think Linux ARM maintainers will accept a change in the format?
Signature · 1 line
Julien Grall
Re: [PATCH v3 12/13] xen/arm: Add the property "protected-devices" in the hypervisor node
Quoted 46 lines · Julien Grall
Quoted 15 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Quoted 2 lines · Ian Campbell
We could enable both of those things only at the point where
vm_assistwas called.[..]
Quoted 7 lines
Quoted 4 lines
I think we can reasonably require that
vm_assistbe called super early, i.e. before any DMA operations occur, in Linux terms I thinkearly_initcall(xen_guest_init)is likely early enough, or we could movexen_guestr_initeven sooner.IHMO, this solution is far too complicate and we will have to fork from the current IOMMU framework.
Quoted 8 lines
Eh? On the Linux side? You just call this hypercall super early so that you are sure no drivers have initialised yet and you are done, there is no need to fork anything AFAICT. And in any case if any generic framework needs extending to better work with Xen then we should do that, not fork it or make a worse design to sidestep the need.
Obviously there will be complexity on the Xen side, but I think far too complicated will be an overstatement.
I was talking about Xen side. The current IOMMU platform would need some rework to support it.
For me this solution is far too complicate compare to the other solutions (e.g ELF note).
Quoted 15 lines
Quoted 10 lines
Quoted 5 lines
We also have the option of a build time feature flag in the image itself like on x86. It is likely that going forward we will have other cases where we wished we had such a thing so getting it in place now would be useful.
I definitely prefer this solution which seems more cleaner than the others.
Is it possible to embedded notes in a zImage? How x86 handle other format than ELF?
The x86 bzImage format embeds an ELF file, which something which was done long ago to improve things for Xen PV x86 use which wants to boot an ELF.
Quoted 5 lines
Quoted 2 lines
ARM zImage doesn't currently have anything like that so you would be looking at an image format extension.
Ok. So it will be easy to add support for ELF image. However for zImage, do you think Linux ARM maintainers will accept a change in the format?
I've no idea. I'm 100% positive that they will require it to be done in a backwards compatible way. I don't know how amenable the zImage format is to such extensions.
On x86 IIRC the kexec people were interested in being able to get an ELF out of a bzImage, you might find that the same is true on ARM, which might help with motivating the change.
Ian.
PATCH v3 13/13 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 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 | 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
Re: [PATCH v3 13/13] 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]>
I don't think it is sensible to try and review this code in great detail given you no doubt did so as you imported it. I looked through the bits which seemed like they were new Xen code rather than imported Linux code. It mostly looks good, one question and when grammar nit.
xen/drivers/passthrough/arm/smmu.c line 1499
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c new file +5
-0+static __init void arm_smmu_device_reset (struct arm_smmu_device *smmu) +{ +[...] +/* Don't upgrade barriers */ + reg &= ~(SMMU_sCR0_BSU_MASK << SMMU_sCR0_BSU_SHIFT);
No? Is that safe when a vcpu migrates around pCPUs?
xen/drivers/passthrough/arm/smmu.c line 1555
Quoted 13 lines
xen/drivers/passthrough/arm/smmu.c new file +13
-0+ +static int __init smmu_init (struct dt_device_node *dev, +const void *data) +{ +struct arm_smmu_device *smmu; +int res; +u64 addr, size; +unsigned int num_irqs, i; +struct dt_phandle_args masterspec; +struct rb_node *node; + +/* Even if the device can't be initialized, we don't want to give to +* dom0 the smmu device
"we don't want to give the smmu device to dom0"
Ian.
Re: [PATCH v3 13/13] drivers/passthrough: arm: Add support for SMMU drivers
Hi Ian,
Quoted 34 lines · Ian Campbell
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 structuresQuoted 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]>I don't think it is sensible to try and review this code in great detail given you no doubt did so as you imported it. I looked through the bits which seemed like they were new Xen code rather than imported Linux code. It mostly looks good, one question and when grammar nit.
xen/drivers/passthrough/arm/smmu.c line 1499
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c new file +5
-0+static __init void arm_smmu_device_reset (struct arm_smmu_device *smmu) +{ +[...] +/* Don't upgrade barriers */ + reg &= ~(SMMU_sCR0_BSU_MASK << SMMU_sCR0_BSU_SHIFT);No? Is that safe when a vcpu migrates around pCPUs?
Quoted 1 line
From the SMMU doc 9.6.3, this field is only used when client devices are
not mapped to a translation context banks.
By default, the policy in Xen is to deny every transaction that doesn't have a valid mapping. So we are safe.
I can update the comment if you want, or even better removing this code.
Quoted 7 lines
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c new file +7
-0+ +static int __init smmu_init (struct dt_device_node *dev, +const void *data) +{ +struct arm_smmu_device *smmu; +int res; +u64 addr, size;
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c line 1555
Quoted 6 lines
xen/drivers/passthrough/arm/smmu.c new file +6
-0+unsigned int num_irqs, i; +struct dt_phandle_args masterspec; +struct rb_node *node; + +/* Even if the device can't be initialized, we don't want to give to +* dom0 the smmu device "we don't want to give the smmu device to dom0"
Will do the modification in the next version.
Regards,
Signature · 1 line
Julien Grall
Re: [PATCH v3 13/13] drivers/passthrough: arm: Add support for SMMU drivers
Quoted 8 lines · Julien Grall
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c line 1499
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c new file +5
-0+static __init void arm_smmu_device_reset (struct arm_smmu_device *smmu) +{ +[...] +/* Don't upgrade barriers */ + reg &= ~(SMMU_sCR0_BSU_MASK << SMMU_sCR0_BSU_SHIFT);No? Is that safe when a vcpu migrates around pCPUs?
Quoted 7 lines
From the SMMU doc 9.6.3, this field is only used when client devices are not mapped to a translation context banks.
By default, the policy in Xen is to deny every transaction that doesn't have a valid mapping. So we are safe.
I can update the comment if you want, or even better removing this code.
I think adding the explanation you just gave would do the job. Even if you were to remove the code an explanation of why it doesn't mess with the BSU mask would still be valuable I think (but I think setting it to a known value even if it is unused would be best).
Ian.
Re: [PATCH v3 13/13] drivers/passthrough: arm: Add support for SMMU drivers
Hi Ian,
Quoted 16 lines · Ian Campbell
Quoted 14 lines · Julien Grall
Quoted 7 lines
xen/drivers/passthrough/arm/smmu.c line 1499
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c new file +5
-0+static __init void arm_smmu_device_reset (struct arm_smmu_device *smmu) +{ +[...] +/* Don't upgrade barriers */ + reg &= ~(SMMU_sCR0_BSU_MASK << SMMU_sCR0_BSU_SHIFT);No? Is that safe when a vcpu migrates around pCPUs?
From the SMMU doc 9.6.3, this field is only used when client devices are
not mapped to a translation context banks.By default, the policy in Xen is to deny every transaction that doesn't have a valid mapping. So we are safe.
Quoted 6 lines
Quoted 1 line
I can update the comment if you want, or even better removing this code.
I think adding the explanation you just gave would do the job. Even if you were to remove the code an explanation of why it doesn't mess with the BSU mask would still be valuable I think (but I think setting it to a known value even if it is unused would be best).
Ok. I will update the comment.
Regards,
Signature · 1 line
Julien Grall