IOMMU support for ARM
cover IOMMU support for ARM
Hello,
This patch series add support for IOMMU on ARM. It have also added ARM SMMU driver which is used for instance on Midway.
The IOMMU architecture for ARM is relying on the page table is shared between the processor and each IOMMU.
The patch series is divided following:
- #1: fixing grant-table with IOMMU. Will be necessary for ARM later
- #2-#3: Make static some vtd functions
- #4-#5: Adding new device tree functions
- #6-#9: Prepare IOMMU code to add support for ARM
- #10-#11: Add IOMMU architecture for ARM
- #12: 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. It's a problem for the swiotlb which needs to know if the device is procted or not when foreign mapping is mapped in dom0.
When I talked with Stefano, 2 solutions came:
- Having a property in each "protected" device
- List in the hypervisor node the procted devices
I didn't yet decide which solution I will use.
Any comments, questions are welcomed.
Sincerely yours,
Julien Grall (12):
xen/common: grant-table: only call IOMMU if paging mode translate is
disabled
xen/passthrough: vtd: Don't export iommu_domain_teardown xen/passthrough: vtd: Don't export iommu_set_pgd
xen/dts: Add dt_property_read_bool
xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle xen/passthrough: rework dom0_pvh_reqs to use it also on ARM xen/passthrough: iommu: Don't need to map dom0 page when the PT is
shared
xen/passthrough: iommu: Split generic IOMMU code xen/passthrough: iommu: Introduce arch specific code xen/passthrough: Introduce IOMMU ARM architure
MAINTAINERS: Add drivers/passthrough/arm drivers/passthrough: arm: Add support for SMMU drivers
MAINTAINERS | 1 + xen/arch/arm/Rules.mk | 1 + xen/arch/arm/domain.c | 7 + xen/arch/arm/domain_build.c | 2 + 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 | 157 ++- xen/common/grant_table.c | 7 +- xen/drivers/passthrough/Makefile | 7 +- xen/drivers/passthrough/amd/iommu_cmd.c | 2 +- xen/drivers/passthrough/amd/iommu_guest.c | 8 +- xen/drivers/passthrough/amd/iommu_map.c | 56 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 53 +- xen/drivers/passthrough/arm/Makefile | 2 + xen/drivers/passthrough/arm/iommu.c | 65 + xen/drivers/passthrough/arm/smmu.c | 1701 +++++++++++++++++++++++++++ xen/drivers/passthrough/iommu.c | 525 +-------- xen/drivers/passthrough/iommu_pci.c | 468 ++++++++ xen/drivers/passthrough/iommu_x86.c | 106 ++ xen/drivers/passthrough/vtd/iommu.c | 124 +- 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 + xen/include/asm-x86/hvm/iommu.h | 29 + xen/include/asm-x86/iommu.h | 50 + xen/include/xen/device_tree.h | 75 ++ xen/include/xen/hvm/iommu.h | 27 +- xen/include/xen/iommu.h | 51 +- 32 files changed, 2891 insertions(+), 701 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/iommu_pci.c create mode 100644 xen/drivers/passthrough/iommu_x86.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
RFC 1/12 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
Re: [RFC for-4.5 01/12] xen/common: grant-table: only call IOMMU if paging mode translate is disabled
Quoted 8 lines
Quoted 1 line
Quoted 1 line · Julien Grall
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 theBUG_ONin__gnttab_map_grant_ref.
Quoted 8 lines
On x86:
- PV guests always have paging mode translate disabled
- PVH and HVM guests have always paging mode translate enabledIt 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.
Signed-off-by Julien Grall <[email protected]>
Quoted 44 lines
Cc Keir Fraser <[email protected]>--- 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 · 7 lines
1.7.10.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Re: [RFC for-4.5 01/12] xen/common: grant-table: only call IOMMU if paging mode translate is disabled
In reply to Julien GrallQuoted 10 lines · Julien Grall
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_ONin__gnttab_map_grant_ref.On x86:
- PV guests always have paging mode translate disabled
- PVH and HVM guests have always paging mode translate enabled
Quoted 5 lines
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.
Signed-off-by Julien Grall <[email protected]>Cc Keir Fraser <[email protected]>
RFC 2/12 xen/passthrough: vtd: Don't export iommu_domain_teardown
In reply to Julien Gralliommu_domain_teardown is only used internally inxen/drivers/passthrough/vtd/iommu.c
--- xen/drivers/passthrough/vtd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -1701,7 +1701,7 @@ static int reassign_device_ownership(return ret; } -void iommu_domain_teardown (struct domain *d) +static void iommu_domain_teardown (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);
Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 02/12] xen/passthrough: vtd: Don't export iommu_domain_teardown
Quoted 5 lines · Julien Grall
iommu_domain_teardownis only used internally inxen/drivers/passthrough/vtd/iommu.cSigned-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>
Not really my remit but:
Quoted 17 lines
--- xen/drivers/passthrough/vtd/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -1701,7 +1701,7 @@ static int reassign_device_ownership(return ret; } -void iommu_domain_teardown (struct domain *d) +static void iommu_domain_teardown (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);
RFC 3/12 xen/passthrough: vtd: Don't export iommu_set_pgd
In reply to Julien Gralliommu_set_pgd is only used internally inxen/drivers/passthrough/vtd/iommu.c
--- xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/include/xen/iommu.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)
xen/drivers/passthrough/vtd/iommu.c +1 -1
@@ -1826,7 +1826,7 @@ static int vtd_ept_page_compatible(struct iommu *iommu)/* * set VT-d page table directory to EPT table if allowed */ -void iommu_set_pgd (struct domain *d) +static void iommu_set_pgd (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);mfn_t pgd_mfn;
xen/include/xen/iommu.h +0 -1
@@ -68,7 +68,6 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, unsigned int flags);int iommu_unmap_page (struct domain *d,unsigned long gfn);void iommu_pte_flush (struct domain *d,u64 gfn,u64 *pte,int order,int present); -void iommu_set_pgd (struct domain *d);void iommu_domain_teardown (struct domain *d);void pt_pci_init (void );
Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 03/12] xen/passthrough: vtd: Don't export iommu_set_pgd
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Julien Grall
iommu_set_pgdis only used internally inxen/drivers/passthrough/vtd/iommu.cSigned-off-by Julien Grall <[email protected]>Cc Xiantoa Zhang <[email protected]>
Quoted 35 lines
--- xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/include/xen/iommu.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -1826,7 +1826,7 @@ static int vtd_ept_page_compatible(struct iommu *iommu)/* * set VT-d page table directory to EPT table if allowed */ -void iommu_set_pgd (struct domain *d) +static void iommu_set_pgd (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);mfn_t pgd_mfn;xen/include/xen/iommu.h +0
-1@@ -68,7 +68,6 @@ int iommu_map_page(struct domain *d, unsigned long gfn,unsigned long mfn, unsigned int flags);int iommu_unmap_page (struct domain *d,unsigned long gfn);void iommu_pte_flush (struct domain *d,u64 gfn,u64 *pte,int order,int present); -void iommu_set_pgd (struct domain *d);void iommu_domain_teardown (struct domain *d);void
pt_pci_init(void);Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 03/12] xen/passthrough: vtd: Don't export iommu_set_pgd
Xiantao
-----Original Message-----
From: Jan Beulich [mailto:[email protected]]
Sent: Monday, February 10, 2014 4:05 PM
To: Julien Grall
Cc: [email protected]; [email protected]; Zhang, Xiantao; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC for-4.5 03/12] xen/passthrough: vtd: Don't export iommu_set_pgd
Quoted 6 lines
Quoted 1 line
Quoted 1 line · Julien Grall
iommu_set_pgdis only used internally inxen/drivers/passthrough/vtd/iommu.cSigned-off-by Julien Grall <[email protected]>Cc Xiantoa Zhang <[email protected]>
Quoted 34 lines
--- xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/include/xen/iommu.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -1826,7 +1826,7 @@ static int vtd_ept_page_compatible(struct iommu *iommu)/* * set VT-d page table directory to EPT table if allowed */ -void iommu_set_pgd (struct domain *d) +static void iommu_set_pgd (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);mfn_t pgd_mfn;xen/include/xen/iommu.h index renamed from xen/include/xen/iommu.h +0
-08bb0a1d..fcbc432 100644
xen/include/xen/iommu.h +0
-0@@ -68,7 +68,6 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, unsigned int flags); int iommu_unmap_page(struct domain *d, unsigned long gfn); void iommu_pte_flush(struct domain *d,u64 gfn, u64 *pte, int order, int present); -void
iommu_set_pgd(struct domain *d); voidiommu_domain_teardown(struct domain *d);void
pt_pci_init(void);
--
1.7.10.4
Re: [RFC for-4.5 03/12] xen/passthrough: vtd: Don't export iommu_set_pgd
In reply to Julien GrallQuoted 6 lines · Julien Grall
iommu_set_pgdis only used internally inxen/drivers/passthrough/vtd/iommu.cSigned-off-by Julien Grall <[email protected]>Cc Xiantoa Zhang <[email protected]>Cc Jan Beulich <[email protected]>
(could collapse with the previous patch into a "don't export unnecessary stuff" patch)
Quoted 30 lines
--- xen/drivers/passthrough/vtd/iommu.c | 2 +- xen/include/xen/iommu.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-)xen/drivers/passthrough/vtd/iommu.c +1
-1@@ -1826,7 +1826,7 @@ static int vtd_ept_page_compatible(struct iommu *iommu)/* * set VT-d page table directory to EPT table if allowed */ -void iommu_set_pgd (struct domain *d) +static void iommu_set_pgd (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d);mfn_t pgd_mfn;xen/include/xen/iommu.h +0
-1@@ -68,7 +68,6 @@ int iommu_map_page(struct domain *d, unsigned long gfn, unsigned long mfn, unsigned int flags);int iommu_unmap_page (struct domain *d,unsigned long gfn);void iommu_pte_flush (struct domain *d,u64 gfn,u64 *pte,int order,int present); -void iommu_set_pgd (struct domain *d);void iommu_domain_teardown (struct domain *d);void pt_pci_init (void );
RFC 4/12 xen/dts: Add dt_property_read_bool
In reply to Julien GrallThe function check if property exists in a specific node.
--- 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
Re: [RFC for-4.5 04/12] xen/dts: Add dt_property_read_bool
Quoted 1 line · Julien Grall
The function check if property exists in a specific node.
^a
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>
Re: [RFC for-4.5 04/12] xen/dts: Add dt_property_read_bool
Hi Ian,
Quoted 4 lines · Ian Campbell
Quoted 1 line · Julien Grall
The function check if property exists in a specific node.
^a
I will fix it.
Quoted 4 lines
Quoted 2 lines
Signed-off-by Julien Grall <[email protected]>Acked-by Ian Campbell <[email protected]>
Thanks,
Signature · 1 line
Julien Grall
RFC 5/12 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).
--- 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: [RFC for-4.5 05/12] xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle
Quoted 1 line · Julien Grall
Code adapted from linux
drivers/of/base.c(commit ef42c58).
On that basis I only took a cursory glance through that monster function.
Quoted 21 lines
Signed-off-by Julien Grall <[email protected]>xen/include/xen/device_tree.h +7
-0@@ -112,6 +112,13 @@ struct dt_device_node { }; +#define MAX_PHANDLE_ARGS 16 +struct dt_phandle_args { +struct dt_device_node *np; +int args_count; +uint32_t args[MAX_PHANDLE_ARGS ]; +}; +/** * IRQ line type. *
xen/include/xen/device_tree.h void dt_set_range(__be32 **cellp, const struct dt_device_node *np, · line 636
Quoted 9 lines
xen/include/xen/device_tree.h +6
-0@@ -621,6 +628,53 @@ void dt_set_range(__be32 **cellp, const struct dt_device_node *np,void dt_get_range (const __be32 **cellp,const struct dt_device_node *np,u64 *address,u64 *size); +/** +* dt_parse_phandle - Resolve a phandle property to a device_node pointer +* @np: Pointer to device node holding phandle property +* @phandle_name: Name of property holding a phandle value +* @index: For properties holding a table of phandles, this is the index into +* the table
Otherwise it is -1 or something else?
xen/include/xen/device_tree.h void dt_set_range(__be32 **cellp, const struct dt_device_node *np, · line 641
Quoted 5 lines
xen/include/xen/device_tree.h +5
-0+* +* Returns the device_node pointer. +*/ +struct dt_device_node *dt_parse_phandle(const struct dt_device_node *np, + const char *phandle_name,
Stray hard tabs?
Quoted 20 lines
xen/include/xen/device_tree.h +20
-0+ int index); + +/** +* dt_parse_phandle_with_args() - Find a node pointed by phandle in a list +* @np: pointer to a device tree node containing a list +* @list_name: property name that contains a list +* @cells_name: property name that specifies phandles' arguments count +* @index: index of a phandle to parse out +* @out_args: optional pointer to output arguments structure (will be filled) +* +* This function is useful to parse lists of phandles and their arguments. +* Returns 0 on success and fills out_args, on error returns appropriate +* errno value. +* +* Example: +* +* phandle1: node1 { +* #list-cells = <2>; +* } +*
xen/include/xen/device_tree.h void dt_set_range(__be32 **cellp, const struct dt_device_node *np, · line 671
Quoted 10 lines
xen/include/xen/device_tree.h +10
-0+* phandle2: node2 { +* #list-cells = <1>; +* } +* +* node3 { +* list = <&phandle1 1 2 &phandle2 3>; +* } +* +* To get a device_node of the `node2' node you may call this: +* dt_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
Wow, what an exciting function!
How do I decide the correct size for out_args?
Quoted 9 lines
xen/include/xen/device_tree.h +6
-0+*/ +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); +#endif /* __XEN_DEVICE_TREE_H */ /*
Re: [RFC for-4.5 05/12] xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle
Hello Ian,
Quoted 30 lines · Ian Campbell
Quoted 1 line · Julien Grall
Code adapted from linux
drivers/of/base.c(commit ef42c58).On that basis I only took a cursory glance through that monster function.
Quoted 24 lines
Signed-off-by Julien Grall <[email protected]>xen/include/xen/device_tree.h +7
-0@@ -112,6 +112,13 @@ struct dt_device_node { }; +#define MAX_PHANDLE_ARGS 16 +struct dt_phandle_args { +struct dt_device_node *np; +int args_count; +uint32_t args[MAX_PHANDLE_ARGS ]; +}; +/** * IRQ line type. * @@ -621,6 +628,53 @@ void dt_set_range(__be32 **cellp, const struct dt_device_node *np,void dt_get_range (const __be32 **cellp,const struct dt_device_node *np,u64 *address,u64 *size);
Quoted 8 lines
xen/include/xen/device_tree.h void dt_set_range(__be32 **cellp, const struct dt_device_node *np, · line 636
Quoted 6 lines
xen/include/xen/device_tree.h +6
-0+/** +* dt_parse_phandle - Resolve a phandle property to a device_node pointer +* @np: Pointer to device node holding phandle property +* @phandle_name: Name of property holding a phandle value +* @index: For properties holding a table of phandles, this is the index into +* the table Otherwise it is -1 or something else?
Even with one element, the property contains a table of phandles. So, the first index is always 0.
Quoted 8 lines
xen/include/xen/device_tree.h void dt_set_range(__be32 **cellp, const struct dt_device_node *np, · line 641
Quoted 6 lines
xen/include/xen/device_tree.h +5
-0+* +* Returns the device_node pointer. +*/ +struct dt_device_node *dt_parse_phandle(const struct dt_device_node *np, + const char *phandle_name,Stray hard tabs?
Oops, I forgot to check the hard tabs on this function. I will fix it.
Quoted 33 lines
Quoted 20 lines
xen/include/xen/device_tree.h +20
-0+ int index); + +/** +* dt_parse_phandle_with_args() - Find a node pointed by phandle in a list +* @np: pointer to a device tree node containing a list +* @list_name: property name that contains a list +* @cells_name: property name that specifies phandles' arguments count +* @index: index of a phandle to parse out +* @out_args: optional pointer to output arguments structure (will be filled) +* +* This function is useful to parse lists of phandles and their arguments. +* Returns 0 on success and fills out_args, on error returns appropriate +* errno value. +* +* Example: +* +* phandle1: node1 { +* #list-cells = <2>; +* } +* xen/include/xen/device_tree.h void dt_set_range(__be32 **cellp, const struct dt_device_node *np, · line 671
Quoted 10 lines
xen/include/xen/device_tree.h +10
-0+* phandle2: node2 { +* #list-cells = <1>; +* } +* +* node3 { +* list = <&phandle1 1 2 &phandle2 3>; +* } +* +* To get a device_node of the `node2' node you may call this: +* dt_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args); Wow, what an exciting function!
Quoted 1 line
How do I decide the correct size for
out_args?
out_args is a structure dt_phandle_args which contains the node and an array of arguments.
The function is designed to parse one phandle by one phandle. So out_args is either NULL (we don't want to get the info) or contains a pointer to the structure to fill.
The description of out_args seems clear to me. Does it miss something?
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 05/12] xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle
Quoted 11 lines · Julien Grall
Quoted 8 lines
Quoted 6 lines
+/**
+ *dt_parse_phandle- Resolve a phandle property to adevice_nodepointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ * the tableOtherwise it is -1 or something else?
Even with one element, the property contains a table of phandles. So, the first index is always 0.
OK, so the "For a properties holding a table..." bit is misleading (that's the "otherwise" I was referring too, e..g properties which do not hold a table0, since this is always the index, even if the table has a single element.
Quoted 10 lines
Quoted 1 line
How do I decide the correct size for
out_args?
out_argsis a structuredt_phandle_argswhich contains the node and an array of arguments.The function is designed to parse one phandle by one phandle. So
out_argsis either NULL (we don't want to get the info) or contains a pointer to the structure to fill.The description of
out_argsseems clear to me. Does it miss something?
No, I didn't realise that the array was within dt_phandle_args rather than out_args itself being a pointer to an array (the plural name is a bit confusing in that regard).
I see the name comes from Linux, so no need to change.
Ian.
Re: [RFC for-4.5 05/12] xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle
Quoted 10 lines · Ian Campbell
Quoted 9 lines · Julien Grall
Quoted 8 lines
Quoted 6 lines
+/**
+ *dt_parse_phandle- Resolve a phandle property to adevice_nodepointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ * the tableOtherwise it is -1 or something else?
Quoted 7 lines
Quoted 2 lines
Even with one element, the property contains a table of phandles. So, the first index is always 0.
OK, so the "For a properties holding a table..." bit is misleading (that's the "otherwise" I was referring too, e..g properties which do not hold a table0, since this is always the index, even if the table has a single element.
It was copied from Linux. Shall I update the comment?
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 05/12] xen/dts: Add dt_parse_phandle_with_args and dt_parse_phandle
Quoted 14 lines · Julien Grall
Quoted 13 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Quoted 8 lines
Quoted 6 lines
+/**
+ *dt_parse_phandle- Resolve a phandle property to adevice_nodepointer
+ * @np: Pointer to device node holding phandle property
+ * @phandle_name: Name of property holding a phandle value
+ * @index: For properties holding a table of phandles, this is the index into
+ * the tableOtherwise it is -1 or something else?
Even with one element, the property contains a table of phandles. So, the first index is always 0.
Quoted 6 lines
Quoted 4 lines
OK, so the "For a properties holding a table..." bit is misleading (that's the "otherwise" I was referring too, e..g properties which do not hold a table0, since this is always the index, even if the table has a single element.
It was copied from Linux. Shall I update the comment?
I suppose it is better to not deviate more than necessary, so feel free to leave it.
Ian.
RFC 6/12 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 commit message.
--- xen/drivers/passthrough/iommu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
xen/drivers/passthrough/iommu.c +9 -5
@@ -130,13 +130,18 @@ 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 ( !paging_mode_translate (d) ) +return ; +if ( !iommu_enabled ) -panic ("Presently, iommu must be enabled for pvh dom0\n" ); +panic ("Presently, iommu must be enabled to use dom0 with translate " +"paging mode\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 +150,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: [RFC for-4.5 06/12] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Quoted 7 lines
Quoted 1 line
Quoted 1 line · 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 commit message.
s/commit/panic/ ?
Quoted 3 lines
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>
Other than the above,
Quoted 44 lines
--- xen/drivers/passthrough/iommu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)xen/drivers/passthrough/iommu.c +5
-2@@ -130,13 +130,18 @@ 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 ( !paging_mode_translate (d) ) +return ; +if ( !iommu_enabled ) -panic ("Presently, iommu must be enabled for pvh dom0\n" ); + panic("Presently, iommu must be enabled to use dom0 with translate"
xen/drivers/passthrough/iommu.c +2
-1+ "paging mode\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"
xen/drivers/passthrough/iommu.c +2
-2+ "enabled\n"); iommu_dom0_strict =1 ; }@@ -145,8 +150,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: [RFC for-4.5 06/12] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Hello Jan,
Quoted 9 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · 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 commit message.
s/commit/panic/ ?
It's an error when I wrote the commit message. I will replace it on the next version.
Quoted 6 lines
Quoted 3 lines
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Other than the above,
Acked-by Jan Beulich <[email protected]>
Thanks.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 06/12] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
In reply to Julien GrallQuoted 21 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 commit message.
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/iommu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)xen/drivers/passthrough/iommu.c +0
-0@@ -130,13 +130,18 @@ 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 140
Quoted 10 lines
xen/drivers/passthrough/iommu.c +6
-2-static __init void check_dom0_pvh_reqs (struct domain *d) +static __init void check_dom0_reqs (struct domain *d) { +if ( !paging_mode_translate (d) ) +return ; +if ( !iommu_enabled ) -panic ("Presently, iommu must be enabled for pvh dom0\n" ); +panic ("Presently, iommu must be enabled to use dom0 with translate " +"paging mode\n" );
Hmmm... this change is wrong. I forgot that iommu doesn't exist on some ARM platform (for instance Arndale).
Do we really this check for PVH? If yes, I will add replace the check
by: is_pvh_domain(d) && !iommu_enabled.
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 06/12] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Quoted 34 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 1 line · Julien Grall
DOM0 on ARM will have the same requirements as DOM0 PVH when iommu is
enabled.
Quoted 19 lines
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 commit message.
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/iommu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)xen/drivers/passthrough/iommu.c +0
-0@@ -130,13 +130,18 @@ 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 139
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 ( !paging_mode_translate (d) ) +return ; +if ( !iommu_enabled ) -panic ("Presently, iommu must be enabled for pvh dom0\n" ); + panic("Presently, iommu must be enabled to use dom0 with translate"
Quoted 7 lines
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 140
Quoted 1 line
xen/drivers/passthrough/iommu.c +1
-0+ "paging mode\n");Hmmm... this change is wrong. I forgot that iommu doesn't exist on some ARM platform (for instance Arndale).
Do we really this check for PVH? If yes, I will add replace the check
by:is_pvh_domain(d)&& !iommu_enabled.
Of course we need it: How would PVH Dom0 be able to do any kind of DMA without an IOMMU?
Jan
Re: [RFC for-4.5 06/12] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Quoted 36 lines · Jan Beulich
Quoted 36 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 1 line · Julien Grall
DOM0 on ARM will have the same requirements as DOM0 PVH when iommu is
enabled.
Quoted 19 lines
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 commit message.
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/iommu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)xen/drivers/passthrough/iommu.c +0
-0@@ -130,13 +130,18 @@ 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 139
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 ( !paging_mode_translate (d) ) +return ; +if ( !iommu_enabled ) -panic ("Presently, iommu must be enabled for pvh dom0\n" ); + panic("Presently, iommu must be enabled to use dom0 with translate"
Quoted 1 line
xen/drivers/passthrough/iommu.c +1
-0+ "paging mode\n");
Quoted 8 lines
Quoted 5 lines
Hmmm... this change is wrong. I forgot that iommu doesn't exist on some ARM platform (for instance Arndale).
Do we really this check for PVH? If yes, I will add replace the check
by:is_pvh_domain(d)&& !iommu_enabled.Of course we need it: How would PVH Dom0 be able to do any kind of DMA without an IOMMU?
Right, on ARM we have the 1:1 memory mapping to avoid this issue.
I will fix it. Can I keep your ack on this patch?
Quoted 2 lines
Jan
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 06/12] xen/passthrough: rework dom0_pvh_reqs to use it also on ARM
Quoted 44 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 42 lines · Jan Beulich
Quoted 41 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 1 line · Julien Grall
DOM0 on ARM will have the same requirements as DOM0 PVH when iommu is
enabled.
Quoted 19 lines
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 commit message.
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/iommu.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)xen/drivers/passthrough/iommu.c +0
-0@@ -130,13 +130,18 @@ 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 139
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 ( !paging_mode_translate (d) ) +return ; +if ( !iommu_enabled ) -panic ("Presently, iommu must be enabled for pvh dom0\n" ); + panic("Presently, iommu must be enabled to use dom0 with translate"
xen/drivers/passthrough/iommu.c int iommu_domain_init(struct domain *d) · line 140
Quoted 1 line
xen/drivers/passthrough/iommu.c +1
-0+ "paging mode\n");Hmmm... this change is wrong. I forgot that iommu doesn't exist on some ARM platform (for instance Arndale).
Do we really this check for PVH? If yes, I will add replace the check
by:is_pvh_domain(d)&& !iommu_enabled.
Quoted 6 lines
Quoted 2 lines
Of course we need it: How would PVH Dom0 be able to do any kind of DMA without an IOMMU?
Right, on ARM we have the 1:1 memory mapping to avoid this issue.
I will fix it. Can I keep your ack on this patch?
For this simple an adjustment - sure.
Jan
RFC 7/12 xen/passthrough: iommu: Don't need to map dom0 page when the PT is shared
In reply to Julien GrallCurrently iommu_init_dom0 is browsing the page list and call map_page callback on each page.
On both AMD and VTD drivers, the function will directly return if the page table is shared with the processor. So Xen can safely avoid to run through the page list.
--- xen/drivers/passthrough/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/drivers/passthrough/iommu.c +1 -1
@@ -157,7 +157,7 @@ void __init iommu_dom0_init(struct domain *d)register_keyhandler ('o' , &iommu_p2m_table); d->need_iommu = !!iommu_dom0_strict; -if (need_iommu (d) ) +if (need_iommu (d) && !iommu_use_hap_pt (d) ) {struct page_info *page;unsigned int i =0 ;
Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 07/12] xen/passthrough: iommu: Don't need to map dom0 page when the PT is shared
Quoted 11 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Currently
iommu_init_dom0is browsing the page list and callmap_pagecallback
on each page.On both AMD and VTD drivers, the function will directly return if the page table is shared with the processor. So Xen can safely avoid to run through the page list.
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>
Quoted 19 lines
--- xen/drivers/passthrough/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/drivers/passthrough/iommu.c +1
-1@@ -157,7 +157,7 @@ void __init iommu_dom0_init(struct domain *d)register_keyhandler ('o' , &iommu_p2m_table); d->need_iommu = !!iommu_dom0_strict; -if (need_iommu (d) ) +if (need_iommu (d) && !iommu_use_hap_pt (d) ) {struct page_info *page;unsigned int i =0 ;Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 07/12] xen/passthrough: iommu: Don't need to map dom0 page when the PT is shared
In reply to Julien GrallQuoted 10 lines · Julien Grall
Currently
iommu_init_dom0is browsing the page list and callmap_pagecallback on each page.On both AMD and VTD drivers, the function will directly return if the page table is shared with the processor. So Xen can safely avoid to run through the page list.
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>
Quoted 17 lines
--- xen/drivers/passthrough/iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/drivers/passthrough/iommu.c +1
-1@@ -157,7 +157,7 @@ void __init iommu_dom0_init(struct domain *d)register_keyhandler ('o' , &iommu_p2m_table); d->need_iommu = !!iommu_dom0_strict; -if (need_iommu (d) ) +if (need_iommu (d) && !iommu_use_hap_pt (d) ) {struct page_info *page;unsigned int i =0 ;
RFC 8/12 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)
- iommu_pci.c: contains specific functions for PCI passthrough
- iommu_x86.c: contains specific functions for x86
iommu_pci.c will be only compiled when PCI is supported by the architecture (eg. HAS_PCI is defined).
This patch is mostly code movement in new files.
--- xen/drivers/passthrough/Makefile | 6 +- xen/drivers/passthrough/iommu.c | 473 +---------------------------------- xen/drivers/passthrough/iommu_pci.c | 468 ++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/iommu_x86.c | 65 +++++ xen/drivers/passthrough/vtd/iommu.c | 42 ++-- xen/include/asm-x86/iommu.h | 46 ++++ xen/include/xen/hvm/iommu.h | 1 + xen/include/xen/iommu.h | 42 ++-- 8 files changed, 625 insertions(+), 518 deletions(-) create mode 100644 xen/drivers/passthrough/iommu_pci.c create mode 100644 xen/drivers/passthrough/iommu_x86.c create mode 100644 xen/include/asm-x86/iommu.h
xen/drivers/passthrough/Makefile +4 -2
@@ -3,5 +3,7 @@ subdir-$(x86) += amd subdir-$(x86_64) += x86 obj-y += iommu.o -obj-y += io.o -obj-y += pci.o +obj-$(x86) += iommu_x86.o +obj-$(HAS_PCI) += iommu_pci.o +obj-$(x86) += io.o +obj-$(HAS_PCI) += pci.o
xen/drivers/passthrough/iommu.c +1 -472
509 lines not on this page · raw message
xen/drivers/passthrough/iommu_pci.c new file +468 -0
468 lines not on this page · raw message
xen/drivers/passthrough/iommu_x86.c new file +65 -0
65 lines not on this page · raw message
xen/drivers/passthrough/vtd/iommu.c +21 -21
52 lines not on this page · raw message
xen/include/asm-x86/iommu.h new file +46 -0
46 lines not on this page · raw message
xen/include/xen/hvm/iommu.h +1 -0
@@ -21,6 +21,7 @@#define __XEN_HVM_IOMMU_H__#include <xen/iommu.h> +#include <asm/hvm/iommu.h> struct g2m_ioport {struct list_head list;
xen/include/xen/iommu.h +19 -23
119 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 08/12] xen/passthrough: iommu: Split generic IOMMU code
Quoted 15 lines
Quoted 1 line
Quoted 1 line · 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)
-iommu_pci.c: contains specific functions for PCI passthrough
-iommu_x86.c: contains specific functions for x86
iommu_pci.cwill be only compiled when PCI is supported by the architecture (eg.HAS_PCIis defined).This patch is mostly code movement in new files.
Quoted 7 lines
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/Makefile | 6 +- xen/drivers/passthrough/iommu.c | 473 +---------------------------------- xen/drivers/passthrough/iommu_pci.c | 468 ++++++++++++++++++++++++++++++++++
There's xen/drivers/passthrough/pci.c already - any reason not to move the code there?
Quoted 1 line
xen/drivers/passthrough/iommu_x86.c | 65 +++++
Same here for xen/drivers/passthrough/x86/.
xen/drivers/passthrough/iommu.c void iommu_crash_shutdown(void) · line 701
Quoted 7 lines
xen/drivers/passthrough/iommu.c +0
-3@@ -696,125 +344,6 @@ void iommu_crash_shutdown(void) iommu_enabled = iommu_intremap =0 ; } -int iommu_do_domctl ( -struct xen_domctl *domctl,struct domain *d, -XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl)
The function itself should probably not be moved out. Either the PCI-specific pieces of it should be made conditional, or a descendant function be created. Since (afaict) you'll need all of the domctl-s (with different arguments) too for pass-through on ARM - what's your plan for them?
Quoted 43 lines
xen/drivers/passthrough/vtd/iommu.c +13
-20@@ -1784,31 +1784,31 @@ static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)void iommu_pte_flush (struct domain *d,u64 gfn,u64 *pte,int order,int present) -{ -struct acpi_drhd_unit *drhd; -struct iommu *iommu =NULL ; -struct hvm_iommu *hd =domain_hvm_iommu (d); -int flush_dev_iotlb; -int iommu_domid; + { +struct acpi_drhd_unit *drhd; +struct iommu *iommu =NULL ; +struct hvm_iommu *hd =domain_hvm_iommu (d); +int flush_dev_iotlb; +int iommu_domid; -iommu_flush_cache_entry (pte,sizeof (struct dma_pte )); +iommu_flush_cache_entry (pte,sizeof (struct dma_pte )); -for_each_drhd_unit ( drhd ) - { - iommu = drhd->iommu; -if ( !test_bit (iommu->index, &hd->iommu_bitmap) ) -continue ; +for_each_drhd_unit ( drhd ) + { + iommu = drhd->iommu; +if ( !test_bit (iommu->index, &hd->iommu_bitmap) ) +continue ; - flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ; - iommu_domid=domain_iommu_domid (d, iommu); -if ( iommu_domid ==-1 ) -continue ; -if (iommu_flush_iotlb_psi (iommu, iommu_domid, - (paddr_t )gfn <<PAGE_SHIFT_4K , - order, !present, flush_dev_iotlb) ) -iommu_flush_write_buffer (iommu); + flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ;
xen/drivers/passthrough/vtd/iommu.c static int intel_iommu_unmap_page(struct domain *d, · line 1812
Quoted 10 lines
xen/drivers/passthrough/vtd/iommu.c +8
-1+ iommu_domid=domain_iommu_domid (d, iommu); +if ( iommu_domid ==-1 ) +continue ; +if (iommu_flush_iotlb_psi (iommu, iommu_domid, + (paddr_t )gfn <<PAGE_SHIFT_4K , + order, !present, flush_dev_iotlb) ) +iommu_flush_write_buffer (iommu); + } } -}
What are these changes to indentation about? Are you deliberately breaking common rules here, or is this some sort of unintentional leftover?
Jan
Re: [RFC for-4.5 08/12] xen/passthrough: iommu: Split generic IOMMU code
Hello Jan,
Thanks for the review.
Quoted 23 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · 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)
-iommu_pci.c: contains specific functions for PCI passthrough
-iommu_x86.c: contains specific functions for x86
iommu_pci.cwill be only compiled when PCI is supported by the architecture (eg.HAS_PCIis defined).This patch is mostly code movement in new files.
Quoted 7 lines
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/Makefile | 6 +- xen/drivers/passthrough/iommu.c | 473 +---------------------------------- xen/drivers/passthrough/iommu_pci.c | 468 ++++++++++++++++++++++++++++++++++
Quoted 2 lines
There's
xen/drivers/passthrough/pci.calready - any reason not to move the code there?
I didn't specific about moving the code directly in passthrough/pci.c. I will do on the next version.
Quoted 9 lines
Quoted 2 lines
xen/drivers/passthrough/iommu_x86.c | 65 +++++Same here for xen/drivers/passthrough/x86/.
Quoted 4 lines
xen/drivers/passthrough/iommu.c +0
-0@@ -696,125 +344,6 @@ void iommu_crash_shutdown(void) iommu_enabled = iommu_intremap =0 ; }
Quoted 9 lines
xen/drivers/passthrough/iommu.c void iommu_crash_shutdown(void) · line 701
Quoted 3 lines
xen/drivers/passthrough/iommu.c +0
-3-int iommu_do_domctl ( -struct xen_domctl *domctl,struct domain *d, -XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl)The function itself should probably not be moved out. Either the PCI-specific pieces of it should be made conditional, or a descendant function be created. Since (afaict) you'll need all of the domctl-s (with different arguments) too for pass-through on ARM - what's your plan for them?
PCI passthrough will be supported on ARM in the future. But we will also have to support passthrough (via the device tree). I think, we will add new DOMCTL for that. Didn't really think about that know.
I will add a descendant function to handle PCI DOMCTL.
Quoted 50 lines
Quoted 50 lines
xen/drivers/passthrough/vtd/iommu.c +19
-20@@ -1784,31 +1784,31 @@ static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn)void iommu_pte_flush (struct domain *d,u64 gfn,u64 *pte,int order,int present) -{ -struct acpi_drhd_unit *drhd; -struct iommu *iommu =NULL ; -struct hvm_iommu *hd =domain_hvm_iommu (d); -int flush_dev_iotlb; -int iommu_domid; + { +struct acpi_drhd_unit *drhd; +struct iommu *iommu =NULL ; +struct hvm_iommu *hd =domain_hvm_iommu (d); +int flush_dev_iotlb; +int iommu_domid; -iommu_flush_cache_entry (pte,sizeof (struct dma_pte )); +iommu_flush_cache_entry (pte,sizeof (struct dma_pte )); -for_each_drhd_unit ( drhd ) - { - iommu = drhd->iommu; -if ( !test_bit (iommu->index, &hd->iommu_bitmap) ) -continue ; +for_each_drhd_unit ( drhd ) + { + iommu = drhd->iommu; +if ( !test_bit (iommu->index, &hd->iommu_bitmap) ) +continue ; - flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ; - iommu_domid=domain_iommu_domid (d, iommu); -if ( iommu_domid ==-1 ) -continue ; -if (iommu_flush_iotlb_psi (iommu, iommu_domid, - (paddr_t )gfn <<PAGE_SHIFT_4K , - order, !present, flush_dev_iotlb) ) -iommu_flush_write_buffer (iommu); + flush_dev_iotlb =find_ats_dev_drhd (iommu) ?1 :0 ; + iommu_domid=domain_iommu_domid (d, iommu); +if ( iommu_domid ==-1 ) +continue ; +if (iommu_flush_iotlb_psi (iommu, iommu_domid, + (paddr_t )gfn <<PAGE_SHIFT_4K , + order, !present, flush_dev_iotlb) )
Quoted 8 lines
xen/drivers/passthrough/vtd/iommu.c static int intel_iommu_unmap_page(struct domain *d, unsigned long gfn) · line 1811
Quoted 4 lines
xen/drivers/passthrough/vtd/iommu.c +2
-1+iommu_flush_write_buffer (iommu); + } } -}What are these changes to indentation about? Are you deliberately breaking common rules here, or is this some sort of unintentional leftover?
It's an error when I have created this patch. I will remove it.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 08/12] xen/passthrough: iommu: Split generic IOMMU code
In reply to Julien GrallQuoted 36 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)
-iommu_pci.c: contains specific functions for PCI passthrough
-iommu_x86.c: contains specific functions for x86
iommu_pci.cwill be only compiled when PCI is supported by the architecture (eg.HAS_PCIis defined).This patch is mostly code movement in new files.
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/Makefile | 6 +- xen/drivers/passthrough/iommu.c | 473 +---------------------------------- xen/drivers/passthrough/iommu_pci.c | 468 ++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/iommu_x86.c | 65 +++++ xen/drivers/passthrough/vtd/iommu.c | 42 ++-- xen/include/asm-x86/iommu.h | 46 ++++ xen/include/xen/hvm/iommu.h | 1 + xen/include/xen/iommu.h | 42 ++-- 8 files changed, 625 insertions(+), 518 deletions(-) create mode 100644 xen/drivers/passthrough/iommu_pci.c create mode 100644 xen/drivers/passthrough/iommu_x86.c create mode 100644 xen/include/asm-x86/iommu.hxen/drivers/passthrough/Makefile +0
-0
xen/drivers/passthrough/Makefile subdir-$(x86) += amd · line 8
Quoted 8 lines
xen/drivers/passthrough/Makefile +3
-2@@ -3,5 +3,7 @@ subdir-$(x86) += amd subdir-$(x86_64) += x86 obj-y += iommu.o -obj-y += io.o -obj-y += pci.o +obj-$(x86) += iommu_x86.o +obj-$(HAS_PCI) += iommu_pci.o +obj-$(x86) += io.o
io.[co] not mentioned in the description?
Re: [RFC for-4.5 08/12] xen/passthrough: iommu: Split generic IOMMU code
Hi Ian,
Quoted 39 lines · Ian Campbell
Quoted 38 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)
-iommu_pci.c: contains specific functions for PCI passthrough
-iommu_x86.c: contains specific functions for x86
iommu_pci.cwill be only compiled when PCI is supported by the architecture (eg.HAS_PCIis defined).This patch is mostly code movement in new files.
Signed-off-by Julien Grall <[email protected]>Cc Xiantao Zhang <[email protected]>Cc Jan Beulich <[email protected]>--- xen/drivers/passthrough/Makefile | 6 +- xen/drivers/passthrough/iommu.c | 473 +---------------------------------- xen/drivers/passthrough/iommu_pci.c | 468 ++++++++++++++++++++++++++++++++++ xen/drivers/passthrough/iommu_x86.c | 65 +++++ xen/drivers/passthrough/vtd/iommu.c | 42 ++-- xen/include/asm-x86/iommu.h | 46 ++++ xen/include/xen/hvm/iommu.h | 1 + xen/include/xen/iommu.h | 42 ++-- 8 files changed, 625 insertions(+), 518 deletions(-) create mode 100644 xen/drivers/passthrough/iommu_pci.c create mode 100644 xen/drivers/passthrough/iommu_x86.c create mode 100644 xen/include/asm-x86/iommu.hxen/drivers/passthrough/Makefile +0
-0@@ -3,5 +3,7 @@ subdir-$(x86) += amd subdir-$(x86_64) += x86
Quoted 8 lines
xen/drivers/passthrough/Makefile subdir-$(x86) += amd · line 8
Quoted 6 lines
xen/drivers/passthrough/Makefile +3
-2obj-y += iommu.o -obj-y += io.o -obj-y += pci.o +obj-$(x86) += iommu_x86.o +obj-$(HAS_PCI) += iommu_pci.o +obj-$(x86) += io.oio.[co] not mentioned in the description?
Right, I will udpate the commit message.
Cheers,
Signature · 1 line
Julien Grall
RFC 9/12 xen/passthrough: iommu: Introduce arch specific code
In reply to Julien GrallCurrently the structure hvm_iommu (xen/include/xen/hvm/iommu.h) contains x86 specific fields.
This patch creates:
- arch_hvm_iommu structure which will contain architecture depend fields
- arch_iommu_domain_{init,destroy} function to execute arch specific during domain creation/destruction
Also move iommu_use_hap_pt and domain_hvm_iommu in asm-x86/iommu.h.
--- xen/arch/x86/domctl.c | 6 +- xen/arch/x86/hvm/io.c | 2 +- xen/arch/x86/tboot.c | 3 +- xen/drivers/passthrough/amd/iommu_cmd.c | 2 +- xen/drivers/passthrough/amd/iommu_guest.c | 8 +-- xen/drivers/passthrough/amd/iommu_map.c | 56 +++++++++---------- xen/drivers/passthrough/amd/pci_amd_iommu.c | 53 +++++++++--------- xen/drivers/passthrough/iommu.c | 36 +++--------- xen/drivers/passthrough/iommu_x86.c | 41 ++++++++++++++ xen/drivers/passthrough/vtd/iommu.c | 80 +++++++++++++-------------- xen/include/asm-x86/hvm/iommu.h | 29 ++++++++++ xen/include/asm-x86/iommu.h | 4 ++ xen/include/xen/hvm/iommu.h | 26 +-------- xen/include/xen/iommu.h | 8 +-- 14 files changed, 191 insertions(+), 163 deletions(-)
xen/arch/x86/domctl.c +3 -3
@@ -745,7 +745,7 @@ long arch_do_domctl("ioport_map:add: dom%d gport=%x mport=%x nr=%x\n" , d->domain_id, fgp, fmp, np); -list_for_each_entry (g2m_ioport, &hd->g2m_ioport_list, list) +list_for_each_entry (g2m_ioport, &hd->arch.g2m_ioport_list, list)if (g2m_ioport->mport == fmp ) { g2m_ioport->gport = fgp;
@@ -764,7 +764,7 @@ long arch_do_domctl( g2m_ioport->gport = fgp; g2m_ioport->mport = fmp; g2m_ioport->np = np; -list_add_tail (&g2m_ioport->list, &hd->g2m_ioport_list); +list_add_tail (&g2m_ioport->list, &hd->arch.g2m_ioport_list); }if ( !ret ) ret =ioports_permit_access (d, fmp, fmp + np -1 );
@@ -779,7 +779,7 @@ long arch_do_domctl(printk (XENLOG_G_INFO "ioport_map:remove: dom%d gport=%x mport=%x nr=%x\n" , d->domain_id, fgp, fmp, np); -list_for_each_entry (g2m_ioport, &hd->g2m_ioport_list, list) +list_for_each_entry (g2m_ioport, &hd->arch.g2m_ioport_list, list)if ( g2m_ioport->mport == fmp ) {list_del (&g2m_ioport->list);
xen/arch/x86/hvm/io.c +1 -1
@@ -451,7 +451,7 @@ int dpci_ioport_intercept(ioreq_t *p)unsigned int s =0 , e =0 ;int rc; -list_for_each_entry ( g2m_ioport, &hd->g2m_ioport_list, list ) +list_for_each_entry ( g2m_ioport, &hd->arch.g2m_ioport_list, list ) { s = g2m_ioport->gport; e = s + g2m_ioport->np;
xen/arch/x86/tboot.c +2 -1
@@ -230,7 +230,8 @@ static void tboot_gen_domain_integrity(const uint8_t key[TB_KEY_SIZE],if ( !is_idle_domain (d) ) {struct hvm_iommu *hd =domain_hvm_iommu (d); -update_iommu_mac (&ctx, hd->pgd_maddr,agaw_to_level (hd->agaw)); +update_iommu_mac (&ctx, hd->arch.pgd_maddr, +agaw_to_level (hd->arch.agaw)); } }
xen/drivers/passthrough/amd/iommu_cmd.c +1 -1
@@ -355,7 +355,7 @@ static void _amd_iommu_flush_pages(struct domain *d,unsigned long flags;struct amd_iommu *iommu;struct hvm_iommu *hd =domain_hvm_iommu (d); -unsigned int dom_id = hd->domain_id; +unsigned int dom_id = hd->arch.domain_id;/* send INVALIDATE_IOMMU_PAGES command */ for_each_amd_iommu ( iommu )
xen/drivers/passthrough/amd/iommu_guest.c +4 -4
@@ -60,12 +60,12 @@ static uint16_t guest_bdf(struct domain *d, uint16_t machine_bdf)static inline struct guest_iommu *domain_iommu (struct domain *d) { -return domain_hvm_iommu (d)->g_iommu; +return domain_hvm_iommu (d)->arch.g_iommu; }static inline struct guest_iommu *vcpu_iommu (struct vcpu *v) { -return domain_hvm_iommu (v->domain)->g_iommu; +return domain_hvm_iommu (v->domain)->arch.g_iommu; }static void guest_iommu_enable (struct guest_iommu *iommu)
@@ -886,7 +886,7 @@ int guest_iommu_init(struct domain* d)guest_iommu_reg_init (iommu); iommu->domain = d; - hd->g_iommu = iommu; + hd->arch.g_iommu = iommu;tasklet_init (&iommu->cmd_buffer_tasklet, guest_iommu_process_command, (unsigned long )d);
@@ -907,7 +907,7 @@ void guest_iommu_destroy(struct domain *d)tasklet_kill (&iommu->cmd_buffer_tasklet);xfree (iommu); -domain_hvm_iommu (d)->g_iommu =NULL ; +domain_hvm_iommu (d)->arch.g_iommu =NULL ; }static int guest_iommu_mmio_range (struct vcpu *v,unsigned long addr)
xen/drivers/passthrough/amd/iommu_map.c +28 -28
175 lines not on this page · raw message
xen/drivers/passthrough/amd/pci_amd_iommu.c +27 -26
124 lines not on this page · raw message
xen/drivers/passthrough/iommu.c +7 -29
@@ -117,10 +117,11 @@ static void __init parse_iommu_param(char *s)int iommu_domain_init (struct domain *d) {struct hvm_iommu *hd =domain_hvm_iommu (d); +int ret =0 ; -spin_lock_init (&hd->mapping_lock); -INIT_LIST_HEAD (&hd->g2m_ioport_list); -INIT_LIST_HEAD (&hd->mapped_rmrrs); + ret =arch_iommu_domain_init (d); +if ( ret ) +return ret;if ( !iommu_enabled )return 0 ;
@@ -190,10 +191,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 ;
@@ -201,20 +199,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)
@@ -328,14 +314,6 @@ void iommu_suspend() ops->suspend (); } -void iommu_share_p2m_table (struct domain * d) -{ -const struct iommu_ops *ops =iommu_get_ops (); - -if ( iommu_enabled &&is_hvm_domain (d) ) - ops->share_p2m (d); -} -void iommu_crash_shutdown (void ) {const struct iommu_ops *ops =iommu_get_ops ();
xen/drivers/passthrough/iommu_x86.c +41 -0
47 lines not on this page · raw message
xen/drivers/passthrough/vtd/iommu.c +40 -40
242 lines not on this page · raw message
xen/include/asm-x86/hvm/iommu.h +29 -0
@@ -39,4 +39,33 @@ static inline int iommu_hardware_setup(void) return 0; } +struct g2m_ioport { +struct list_head list; +unsigned int gport; +unsigned int mport; +unsigned int np; +}; + +struct mapped_rmrr { +struct list_head list; +u64 base; +u64 end; +}; + +struct arch_hvm_iommu +{ +u64 pgd_maddr;/* io page directory machine address */ +int agaw;/* adjusted guest address width, 0 is level 2 30-bit */ +u64 iommu_bitmap;/* bitmap of iommu(s) that the domain uses */ +/* amd iommu support */ +int domain_id; +int paging_mode; +struct page_info *root_table; +struct guest_iommu *g_iommu; + +struct list_head g2m_ioport_list;/* guest to machine ioport mapping */ +struct list_head mapped_rmrrs; +spinlock_t mapping_lock;/* io page table lock */ +}; +#endif /* __ASM_X86_HVM_IOMMU_H__ */
xen/include/asm-x86/iommu.h +4 -0
@@ -19,6 +19,10 @@#include <asm/msi.h> +/* Does this domain have a P2M table we can use as its IOMMU pagetable? */ +#define iommu_use_hap_pt (d) (hap_enabled(d) && iommu_hap_pt_share) +#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu) +void iommu_update_ire_from_apic (unsigned int apic,unsigned int reg,unsigned int value);int iommu_update_ire_from_msi (struct msi_desc *msi_desc,struct msi_msg *msg);void iommu_read_msi_from_ire (struct msi_desc *msi_desc,struct msi_msg *msg);
xen/include/xen/hvm/iommu.h +1 -25
@@ -23,32 +23,8 @@#include <xen/iommu.h> #include <asm/hvm/iommu.h> -struct g2m_ioport { -struct list_head list; -unsigned int gport; -unsigned int mport; -unsigned int np; -}; - -struct mapped_rmrr { -struct list_head list; -u64 base; -u64 end; -}; -struct hvm_iommu { -u64 pgd_maddr;/* io page directory machine address */ -spinlock_t mapping_lock;/* io page table lock */ -int agaw;/* adjusted guest address width, 0 is level 2 30-bit */ -struct list_head g2m_ioport_list;/* guest to machine ioport mapping */ -u64 iommu_bitmap;/* bitmap of iommu(s) that the domain uses */ -struct list_head mapped_rmrrs; - -/* amd iommu support */ -int domain_id; -int paging_mode; -struct page_info *root_table; -struct guest_iommu *g_iommu; +struct arch_hvm_iommu arch;/* iommu_ops */ const struct iommu_ops *platform_ops;
xen/include/xen/iommu.h +3 -5
@@ -35,11 +35,6 @@ extern bool_t iommu_hap_pt_share;extern bool_t iommu_debug;extern bool_t amd_iommu_perdev_intremap; -/* Does this domain have a P2M table we can use as its IOMMU pagetable? */ -#define iommu_use_hap_pt (d) (hap_enabled(d) && iommu_hap_pt_share) - -#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu) -#define PAGE_SHIFT_4K (12)#define PAGE_SIZE_4K (1UL << PAGE_SHIFT_4K)#define PAGE_MASK_4K (((u64)-1) << PAGE_SHIFT_4K)
@@ -55,6 +50,9 @@ void iommu_dom0_init(struct domain *d);void iommu_domain_destroy (struct domain *d);int deassign_device (struct domain *d,u16 seg,u8 bus,u8 devfn); +void arch_iommu_domain_destroy (struct domain *d); +int arch_iommu_domain_init (struct domain *d); +/* Function used internally, use iommu_domain_destroy */ void iommu_teardown (struct domain *d);
Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 09/12] xen/passthrough: iommu: Introduce arch specific code
Quoted 11 lines · Julien Grall
Currently the structure
hvm_iommu(xen/include/xen/hvm/iommu.h) contains x86 specific fields.This patch creates:
-arch_hvm_iommustructure which will contain architecture depend fields
- arch_iommu_domain_{init,destroy} function to execute arch specific during domain creation/destructionAlso move
iommu_use_hap_ptanddomain_hvm_iommuinasm-x86/iommu.h.
Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Joseph Cihula <[email protected]>Cc Gang Wei <[email protected]>Cc Shane Wang <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Xiantao Zhang <[email protected]>
Mostly mechanical I guess?
Re: [RFC for-4.5 09/12] xen/passthrough: iommu: Introduce arch specific code
Hi Ian,
Quoted 21 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Currently the structure
hvm_iommu(xen/include/xen/hvm/iommu.h) contains x86 specific fields.This patch creates:
-arch_hvm_iommustructure which will contain architecture depend fields
- arch_iommu_domain_{init,destroy} function to execute arch specific during domain creation/destructionAlso move
iommu_use_hap_ptanddomain_hvm_iommuinasm-x86/iommu.h.Quoted 8 lines
Signed-off-by Julien Grall <[email protected]>Cc Keir Fraser <[email protected]>Cc Jan Beulich <[email protected]>Cc Joseph Cihula <[email protected]>Cc Gang Wei <[email protected]>Cc Shane Wang <[email protected]>Cc Suravee Suthikulpanit <[email protected]>Cc Xiantao Zhang <[email protected]>
Quoted 1 line
Mostly mechanical I guess?
Yes. Mostly replace hd->field by hd->arch.field.
Quoted 1 line
Acked-by Ian Campbell <[email protected]>
Thanks,
Signature · 1 line
Julien Grall
RFC 10/12 xen/passthrough: Introduce IOMMU ARM architure
In reply to Julien GrallThis patch contains the architecture to use IOMMU on ARM. There is no IOMMU drivers on this patch.
The code will run through the device tree and will initialize every IOMMUs. It's possible to have multiple IOMMUs on the same platform, but they should be handled with the same drivers. 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[] __initcontst =
{
/* 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
--- xen/arch/arm/Rules.mk | 1 + xen/arch/arm/domain.c | 7 ++++ xen/arch/arm/domain_build.c | 2 ++ xen/arch/arm/p2m.c | 4 +++ xen/arch/arm/setup.c | 2 ++ xen/drivers/passthrough/Makefile | 1 + xen/drivers/passthrough/arm/Makefile | 1 + xen/drivers/passthrough/arm/iommu.c | 65 ++++++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 3 +- xen/include/asm-arm/domain.h | 2 ++ xen/include/asm-arm/hvm/iommu.h | 10 ++++++ xen/include/asm-arm/iommu.h | 36 +++++++++++++++++++ 12 files changed, 133 insertions(+), 1 deletion(-) 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
@@ -557,6 +557,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:
@@ -568,6 +571,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 +2 -0
@@ -1091,6 +1091,8 @@ int construct_dom0(struct domain *d) } } +iommu_dom0_init (d); +return 0 ; }
xen/arch/arm/p2m.c +4 -0
@@ -401,12 +401,16 @@ static int create_p2m_entries(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 ();/* setup iommu if available */ +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) += iommu_x86.o
xen/drivers/passthrough/arm/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-y += iommu.o
xen/drivers/passthrough/arm/iommu.c new file +65 -0
65 lines not on this page · raw message
xen/include/asm-arm/device.h +2 -1
@@ -6,7 +6,8 @@enum device_type { -DEVICE_SERIAL +DEVICE_SERIAL , +DEVICE_IOMMU , };struct device_desc {
xen/include/asm-arm/domain.h +2 -0
@@ -9,6 +9,7 @@#include <asm/vfp.h> #include <public/hvm/params.h> #include <xen/serial.h> +#include <xen/hvm/iommu.h> /* Represents state corresponding to a block of 32 interrupts */ struct vgic_irq_rank {
@@ -72,6 +73,7 @@ struct pending_irqstruct hvm_domain {uint64_t params[HVM_NR_PARAMS ]; +struct hvm_iommu hvm_iommu; } __cacheline_aligned;#ifdef CONFIG_ARM_64
xen/include/asm-arm/hvm/iommu.h new file +10 -0
@@ -0,0 +1,10 @@ +#ifndef __ASM_ARM_HVM_IOMMU_H_ +#define __ASM_ARM_HVM_IOMMU_H_ + +struct arch_hvm_iommu +{ +/* Private information for the IOMMU drivers */ +void *priv; +}; + +#endif /* __ASM_ARM_HVM_IOMMU_H_ */
xen/include/asm-arm/iommu.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* This program is free software; you can redistribute it and/or modify it +* under the terms and conditions of the GNU General Public License, +* version 2, as published by the Free Software Foundation. +* +* This program is distributed in the hope it will be useful, but WITHOUT +* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +* more details. +* +* You should have received a copy of the GNU General Public License along with +* this program; if not, write to the Free Software Foundation, Inc., 59 Temple +* Place - Suite 330, Boston, MA 02111-1307 USA. +*/ +#ifndef __ARCH_ARM_IOMMU_H__ +#define __ARCH_ARM_IOMMU_H__ + +/* Always share P2M Table between the CPU and the IOMMU */ +#define iommu_use_hap_pt (d) (1) +#define domain_hvm_iommu (d) (&d->arch.hvm_domain.hvm_iommu) + +const struct iommu_ops *iommu_get_ops (void ); +void __init iommu_set_ops (const struct iommu_ops *ops); + +int __init iommu_hardware_setup (void ); + +#endif /* __ARCH_ARM_IOMMU_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 10/12] xen/passthrough: Introduce IOMMU ARM architure
Quoted 1 line · Julien Grall
This patch contains the architecture to use IOMMU on ARM. There is no
s/IOMMU/IOMMUs/
Quoted 3 lines
IOMMU drivers on this patch.
The code will run through the device tree and will initialize every IOMMUs.
s/IOMMUs/IOMMU/
Quoted 1 line
It's possible to have multiple IOMMUs on the same platform, but they should
s/should/must/ I think for now?
Quoted 1 line
be handled with the same drivers.
s/drivers/driver/
Quoted 1 line
For now, there is no support for using multiple iommu drivers at runtime.
But this is in principal possible in the future, right? (I shudder to think what the designers of an SoC with multiple different SMMUs on it would have to be smoking...)
You should mention somewhere that on ARM these are called SMMUs not IOMMUs.
Quoted 3 lines
Each new IOMMU drivers should contain:
static const char * const myiommu_dt_compat[]
__initcontst=
"__initconst".
Quoted 11 lines
{ /* 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
This is the same as for any other driver, right?
xen/arch/arm/domain.c fail: · line 575
Quoted 6 lines
xen/arch/arm/domain.c +2
-0@@ -568,6 +571,10 @@ fail:void arch_domain_destroy (struct domain *d) { +/* IOMMU page table is shared with P2M, always call +* iommu_domain_destroy() before p2m_teardown().
It would be worth adding some commentary on the design we are using (decisions such as whether to share PTs with the stage 2 MMU) in the commit message as well.
I suppose this requirement puts constraints on the SMMU hardware we can support. I think it is fine to live with that until someone shows up with an SMMU with pagetables that are incompatible with the stage 2 paging ones.
xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 728
Quoted 9 lines
xen/arch/arm/setup.c +1
-0@@ -725,6 +725,8 @@ void __init start_xen(unsigned long boot_phys_offset,local_irq_enable ();local_abort_enable (); +iommu_setup ();/* setup iommu if available */
Comment is a bit redundant ;-)
xen/drivers/passthrough/arm/iommu.c line 7
Quoted 13 lines
xen/drivers/passthrough/arm/iommu.c new file +7
-0@@ -0,0 +1,65 @@ +/* +* xen/drivers/passthrough/arm/iommu.c +* +* Generic IOMMU framework via the device tree +* +* Julien Grall <[email protected]> +* Copyright (c) 2013 Linaro Limited.
It's not 2013 any more...
Quoted 6 lines
xen/include/asm-arm/hvm/iommu.h new file +0
-0
xen/include/asm-arm/hvm/iommu.h line 10
Quoted 10 lines
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_ */
Emacs magic block please.
That was a surprisingly small and uncontroversial patch. Well done.
Ian.
Re: [RFC for-4.5 10/12] xen/passthrough: Introduce IOMMU ARM architure
Hi Ian,
Quoted 7 lines · Ian Campbell
Quoted 1 line · Julien Grall
This patch contains the architecture to use IOMMU on ARM. There is no
s/IOMMU/IOMMUs/
Quoted 2 lines
IOMMU drivers on this patch.
Quoted 7 lines
Quoted 1 line
The code will run through the device tree and will initialize every IOMMUs.
s/IOMMUs/IOMMU/
Quoted 1 line
It's possible to have multiple IOMMUs on the same platform, but they should
s/should/must/ I think for now?
Right.
Quoted 9 lines
Quoted 1 line
be handled with the same drivers.
s/drivers/driver/
Quoted 1 line
For now, there is no support for using multiple iommu drivers at runtime.
But this is in principal possible in the future, right? (I shudder to think what the designers of an SoC with multiple different SMMUs on it would have to be smoking...)
In theory yes. I will wait that someone want to support a such platfomr on Xen before implement it :).
Quoted 3 lines
You should mention somewhere that on ARM these are called SMMUs not IOMMUs.
I think SMMU is the name used for ARM IOMMU. Samsung and TI doesn't use the term SMMU.
Quoted 6 lines
Quoted 4 lines
Each new IOMMU drivers should contain:
static const char * const myiommu_dt_compat[]
__initcontst="
__initconst".
Oops. Will fix it.
Quoted 7 lines
Quoted 7 lines
{ /* list of device compatible with the drivers. Will be matched with * the "compatible" property on the device tree */ NULL, };
Quoted 6 lines
Quoted 4 lines
DT_DEVICE_START(myiommu, "MY IOMMU", DEVICE_IOMMU)
.compatible =myiommu_compatible, .init =myiommu_init,DT_DEVICE_ENDThis is the same as for any other driver, right?
Yes, the only change is we need to specify DEVICE_IOMMU in DT_DEVICE_START.
Quoted 11 lines
xen/arch/arm/domain.c fail: · line 575
Quoted 7 lines
xen/arch/arm/domain.c +2
-0@@ -568,6 +571,10 @@ fail:void arch_domain_destroy (struct domain *d) { +/* IOMMU page table is shared with P2M, always call +* iommu_domain_destroy() before p2m_teardown(). It would be worth adding some commentary on the design we are using (decisions such as whether to share PTs with the stage 2 MMU) in the commit message as well.
I will do.
Quoted 4 lines
I suppose this requirement puts constraints on the SMMU hardware we can support. I think it is fine to live with that until someone shows up with an SMMU with pagetables that are incompatible with the stage 2 paging ones.
Adding support for a such hardware should not need too much code.
Quoted 11 lines
xen/arch/arm/setup.c void __init start_xen(unsigned long boot_phys_offset, · line 728
Quoted 9 lines
xen/arch/arm/setup.c +1
-0@@ -725,6 +725,8 @@ void __init start_xen(unsigned long boot_phys_offset,local_irq_enable ();local_abort_enable (); +iommu_setup ();/* setup iommu if available */ Comment is a bit redundant ;-)
Copied for x86/setup.c. I will remove it.
Quoted 16 lines
Quoted 7 lines
xen/drivers/passthrough/arm/iommu.c new file +0
-0xen/drivers/passthrough/arm/iommu.c line 7
Quoted 7 lines
xen/drivers/passthrough/arm/iommu.c new file +7
-0@@ -0,0 +1,65 @@ +/* +* xen/drivers/passthrough/arm/iommu.c +* +* Generic IOMMU framework via the device tree +* +* Julien Grall <[email protected]> +* Copyright (c) 2013 Linaro Limited. It's not 2013 any more...
I have started the implementation in 2013 and forgot to update it.
Quoted 11 lines
Quoted 11 lines
xen/include/asm-arm/hvm/iommu.h new file +4
-0@@ -0,0 +1,10 @@ +#ifndef __ASM_ARM_HVM_IOMMU_H_ +#define __ASM_ARM_HVM_IOMMU_H_ + +struct arch_hvm_iommu
Quoted 8 lines
xen/include/asm-arm/hvm/iommu.h line 10
Quoted 6 lines
xen/include/asm-arm/hvm/iommu.h new file +6
-0+{ +/* Private information for the IOMMU drivers */ +void *priv; +}; + +#endif /* __ASM_ARM_HVM_IOMMU_H_ */ Emacs magic block please.
I will do.
Quoted 1 line
That was a surprisingly small and uncontroversial patch. Well done.
The IOMMU framework in Xen was well designed.
cheers,
Signature · 1 line
Julien Grall
RFC 11/12 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
Re: [RFC for-4.5 11/12] MAINTAINERS: Add drivers/passthrough/arm
Quoted 4 lines · Julien Grall
Add the ARM IOMMU directory to "ARM ARCHITECTURE" part
Signed-off-by Julien Grall <[email protected]>Cc Keir Fraser <[email protected]>
Quoted 16 lines
--- 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]>
RFC 12/12 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.
--- xen/drivers/passthrough/arm/Makefile | 1 + xen/drivers/passthrough/arm/smmu.c | 1701 ++++++++++++++++++++++++++++++++++ 2 files changed, 1702 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 +1701 -0
1,701 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Re: [RFC for-4.5 12/12] drivers/passthrough: arm: Add support for SMMU drivers
Quoted 2 lines · Julien Grall
This patch add support for ARM architected SMMU driver. It's based on the linux drivers (
drivers/iommu/arm-smmu) commit89ac23cd.
Aha, here comes all the hard stuff ;-)
Could you try and briefly enumerate the areas which you had to change please.
Some comments on e.g. which translation context type we are using and how we are configuring things etc might also be helpful here in understanding what is going on.
Also could you give details of the test setup you used, was it just booting dom0 on Midway with these patches? Was the DTB complete etc?
Quoted 2 lines
+ * This driver currently supports:
+ * - SMMUv1 and v2 implementations (didn't try v2 SMMU)
I guess this is Will's original comment, I thought SMMU-400, which you've tried, was v2?
Quoted 17 lines
+ * - Stream-matching and stream-indexing + * - v7/v8 long-descriptor format + * - Non-secure access to the SMMU + * - 4k pages, p2m shared with the processor + * - Up to 40-bit addressing + * - Context fault reporting+ */
xen/drivers/passthrough/arm/smmu.c new file +10
-0+ +#include <xen/config.h> +#include <xen/delay.h> +#include <xen/errno.h> +#include <xen/irq.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/rbtree.h> +#include <xen/sched.h>
xen/drivers/passthrough/arm/smmu.c line 54
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c new file +10
-0+#include <asm/atomic.h> +#include <asm/device.h> +#include <asm/io.h> +#include <asm/platform.h> + +#define SZ_4K (1 << 12) +#define SZ_64K (1 << 16) + +/* Driver options */ +#define SMMU_OPT_SECURE_CONFIG_ACCESS (1 << 0)
Is this just retained to reduce the deviation from the Linux driver? It's no use to us I think. (I suppose that goes for a bunch of other stuff, eg.. the PGSZ_4K stuff, which I will avoid commenting on further).
Quoted 11 lines
xen/drivers/passthrough/arm/smmu.c new file +11
-0+ +void arm_smmu_iommu_dom0_init (struct domain *d) +{ +struct arm_smmu_device *smmu; +struct rb_node *node; + +printk (XENLOG_DEBUG "arm-smmu: Initialize dom0\n" ); + +list_for_each_entry ( smmu, &arm_smmu_devices, list ) + { +for ( node =rb_first (&smmu->masters); node; node =rb_next (node) )
xen/drivers/passthrough/arm/smmu.c line 1475
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c new file +10
-0+ { +struct arm_smmu_master *master; + + master = container_of(node, struct arm_smmu_master, node); + +if (dt_device_used_by (master->dt_node) ==DOMID_XEN || +platform_device_is_blacklisted (master->dt_node) ) +continue ; + +arm_smmu_attach_dev (d, master->dt_node);
Should this not be driven from the same loop as the MMIO mapping setup in dom0 build? Otherwise isn't there a danger that they won't correspond?
A "master" here is a "bus master" i.e. a device, right?
xen/drivers/passthrough/arm/smmu.c line 1520
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c new file +2
-0+/* Even if the device can't be initialized, we don't want to give to +* dom0 the smmu device
"give the smmu device to dom0"
I obviously haven't reviewed all this code in detail, but I have skimmed it and nothing leapt out.
Ian.
Re: [RFC for-4.5 12/12] drivers/passthrough: arm: Add support for SMMU drivers
Quoted 8 lines · Ian Campbell
Quoted 2 lines · Julien Grall
This patch add support for ARM architected SMMU driver. It's based on the linux drivers (
drivers/iommu/arm-smmu) commit89ac23cd.Aha, here comes all the hard stuff ;-)
Could you try and briefly enumerate the areas which you had to change please.
The main changes 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 structure
Quoted 3 lines
Some comments on e.g. which translation context type we are using and how we are configuring things etc might also be helpful here in understanding what is going on.
Honestly, the configuration part was mostly copied from Linux. Some bits are still fuzzy for me. I will try to improve the commit message.
Quoted 2 lines
Also could you give details of the test setup you used, was it just booting dom0 on Midway with these patches? Was the DTB complete etc?
I had to modify the device tree by applying this following patch:
http://www.spinics.net/lists/arm-kernel/msg301163.html
I've tried to boot dom0 and a guest with LVM (a patch is coming to remove swiotlb when the device is protected by an IOMMU).
Quoted 6 lines
Quoted 3 lines
+ * This driver currently supports:
+ * - SMMUv1 and v2 implementations (didn't try v2 SMMU)I guess this is Will's original comment, I thought SMMU-400, which you've tried, was v2?
No it's SMMU v2. As I understand:
- SMMU-400 => SMMU v1
- SMMU-500 => SMMU v2
The words in parenthesis was added by me because I don't have a test box with SMMU v2.
Quoted 25 lines
Quoted 25 lines
+ * - Stream-matching and stream-indexing + * - v7/v8 long-descriptor format + * - Non-secure access to the SMMU + * - 4k pages, p2m shared with the processor + * - Up to 40-bit addressing + * - Context fault reporting+ */
xen/drivers/passthrough/arm/smmu.c new file +17
-0+ +#include <xen/config.h> +#include <xen/delay.h> +#include <xen/errno.h> +#include <xen/irq.h> +#include <xen/lib.h> +#include <xen/list.h> +#include <xen/mm.h> +#include <xen/rbtree.h> +#include <xen/sched.h> +#include <asm/atomic.h> +#include <asm/device.h> +#include <asm/io.h> +#include <asm/platform.h> + +#define SZ_4K (1 << 12) +#define SZ_64K (1 << 16)
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c line 54
Quoted 3 lines
xen/drivers/passthrough/arm/smmu.c new file +3
-0+ +/* Driver options */ +#define SMMU_OPT_SECURE_CONFIG_ACCESS (1 << 0)Is this just retained to reduce the deviation from the Linux driver? It's no use to us I think. (I suppose that goes for a bunch of other stuff, eg.. the
PGSZ_4Kstuff, which I will avoid commenting on further).
SZ_4K and SZ_64K is used later in the code. The SMMU_OPT_SECURE_CONFIG_ACCESS is used for midway as the SMMU is broken.
Quoted 18 lines
Quoted 18 lines
xen/drivers/passthrough/arm/smmu.c new file +17
-0+ +void arm_smmu_iommu_dom0_init (struct domain *d) +{ +struct arm_smmu_device *smmu; +struct rb_node *node; + +printk (XENLOG_DEBUG "arm-smmu: Initialize dom0\n" ); + +list_for_each_entry ( smmu, &arm_smmu_devices, list ) + { +for ( node =rb_first (&smmu->masters); node; node =rb_next (node) ) + { +struct arm_smmu_master *master; + + master = container_of(node, struct arm_smmu_master, node); + + if ( dt_device_used_by(master->dt_node) == DOMID_XEN ||
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c line 1475
Quoted 4 lines
xen/drivers/passthrough/arm/smmu.c new file +4
-0+ platform_device_is_blacklisted(master->dt_node) ) +continue ; + +arm_smmu_attach_dev (d, master->dt_node);Should this not be driven from the same loop as the MMIO mapping setup in dom0 build? Otherwise isn't there a danger that they won't correspond?
On my second version of the patch series I moved out this code in map_device.
Quoted 5 lines
A "master" here is a "bus master" i.e. a device, right?
Quoted 8 lines
xen/drivers/passthrough/arm/smmu.c line 1520
Quoted 2 lines
xen/drivers/passthrough/arm/smmu.c new file +2
-0+/* Even if the device can't be initialized, we don't want to give to +* dom0 the smmu device "give the smmu device to dom0"
I obviously haven't reviewed all this code in detail, but I have skimmed it and nothing leapt out.
Thanks for the review!
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 12/12] drivers/passthrough: arm: Add support for SMMU drivers
Quoted 10 lines · Julien Grall
Quoted 6 lines
Quoted 3 lines
+ * This driver currently supports:
+ * - SMMUv1 and v2 implementations (didn't try v2 SMMU)I guess this is Will's original comment, I thought SMMU-400, which you've tried, was v2?
No it's SMMU v2. As I understand:
- SMMU-400 => SMMU v1
- SMMU-500 => SMMU v2
Ah yes, that sounds more familiar.
Quoted 2 lines
The words in parenthesis was added by me because I don't have a test box with SMMU v2.
OK.
Quoted 11 lines
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c line 54
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c new file +5
-0+#define SZ_4K (1 << 12) +#define SZ_64K (1 << 16) + +/* Driver options */ +#define SMMU_OPT_SECURE_CONFIG_ACCESS (1 << 0)Is this just retained to reduce the deviation from the Linux driver? It's no use to us I think. (I suppose that goes for a bunch of other stuff, eg.. the
PGSZ_4Kstuff, which I will avoid commenting on further).
Quoted 1 line
SZ_4KandSZ_64Kis used later in the code.
But they are actually useless to us aren't they?
Quoted 2 lines
The
SMMU_OPT_SECURE_CONFIG_ACCESSis used for midway as the SMMU is broken.
Ah, so this is effectively a quirk then.
Ian/
Re: [RFC for-4.5 12/12] drivers/passthrough: arm: Add support for SMMU drivers
Quoted 30 lines · Ian Campbell
Quoted 10 lines · Julien Grall
Quoted 6 lines
Quoted 3 lines
+ * This driver currently supports:
+ * - SMMUv1 and v2 implementations (didn't try v2 SMMU)I guess this is Will's original comment, I thought SMMU-400, which you've tried, was v2?
No it's SMMU v2. As I understand:
- SMMU-400 => SMMU v1
- SMMU-500 => SMMU v2Ah yes, that sounds more familiar.
Quoted 2 lines
The words in parenthesis was added by me because I don't have a test box with SMMU v2.
OK.
Quoted 11 lines
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c line 54
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c new file +5
-0+#define SZ_4K (1 << 12) +#define SZ_64K (1 << 16) + +/* Driver options */ +#define SMMU_OPT_SECURE_CONFIG_ACCESS (1 << 0)Is this just retained to reduce the deviation from the Linux driver? It's no use to us I think. (I suppose that goes for a bunch of other stuff, eg.. the
PGSZ_4Kstuff, which I will avoid commenting on further).
Quoted 3 lines
Quoted 1 line
SZ_4KandSZ_64Kis used later in the code.But they are actually useless to us aren't they?
As we use only 4K page in Xen yes. I kept it because there is few place where the SMMU configuration is not the same.
If we want to support 64K page in the future it will harder to had support if this stuff is removed.
The constant was added by himself as it doesn't exists on Xen. I can move it into the generic code.
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 12/12] drivers/passthrough: arm: Add support for SMMU drivers
Quoted 18 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c line 54
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c new file +5
-0+#define SZ_4K (1 << 12) +#define SZ_64K (1 << 16) + +/* Driver options */ +#define SMMU_OPT_SECURE_CONFIG_ACCESS (1 << 0)Is this just retained to reduce the deviation from the Linux driver? It's no use to us I think. (I suppose that goes for a bunch of other stuff, eg.. the
PGSZ_4Kstuff, which I will avoid commenting on further).Quoted 3 lines
Quoted 1 line
SZ_4KandSZ_64Kis used later in the code.But they are actually useless to us aren't they?
Quoted 8 lines
As we use only 4K page in Xen yes. I kept it because there is few place where the SMMU configuration is not the same.
If we want to support 64K page in the future it will harder to had support if this stuff is removed.
The constant was added by himself as it doesn't exists on Xen. I can move it into the generic code.
But if possible I'd like to encourage you using PAGE_SIZE_4K to match up with what we already got in the IOMMU code. Unless deviation from the sources you're cloning is deemed worse than consistency within our code.
Jan
Re: [RFC for-4.5 12/12] drivers/passthrough: arm: Add support for SMMU drivers
Hello Jan,
Quoted 24 lines · Jan Beulich
Quoted 24 lines
Quoted 1 line
Quoted 1 line · Julien Grall
Quoted 12 lines · Ian Campbell
Quoted 11 lines · Julien Grall
Quoted 10 lines
xen/drivers/passthrough/arm/smmu.c line 54
Quoted 5 lines
xen/drivers/passthrough/arm/smmu.c new file +5
-0+#define SZ_4K (1 << 12) +#define SZ_64K (1 << 16) + +/* Driver options */ +#define SMMU_OPT_SECURE_CONFIG_ACCESS (1 << 0)Is this just retained to reduce the deviation from the Linux driver? It's no use to us I think. (I suppose that goes for a bunch of other stuff, eg.. the
PGSZ_4Kstuff, which I will avoid commenting on further).Quoted 3 lines
Quoted 1 line
SZ_4KandSZ_64Kis used later in the code.But they are actually useless to us aren't they?
As we use only 4K page in Xen yes. I kept it because there is few place where the SMMU configuration is not the same.
If we want to support 64K page in the future it will harder to had support if this stuff is removed.
Quoted 7 lines
Quoted 2 lines
The constant was added by himself as it doesn't exists on Xen. I can move it into the generic code.
But if possible I'd like to encourage you using
PAGE_SIZE_4Kto match up with what we already got in the IOMMU code. Unless deviation from the sources you're cloning is deemed worse than consistency within our code.
I think this change is fine. It doesn't fundamentally change the code.
I will update the patch for the next version.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC for-4.5 12/12] drivers/passthrough: arm: Add support for SMMU drivers
In reply to Ian CampbellQuoted 1 line · Ian Campbell
A "master" here is a "bus master" i.e. a device, right?
I forgot to answer to this part: yes.
Signature · 1 line
Julien Grall
I forgot to add a link to repository:
git://xenbits.xen.org/people/julieng/xen-unstable.git branch smmu
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
Quoted 89 lines · Julien Grall
Hello,
This patch series add support for IOMMU on ARM. It have also added ARM SMMU driver which is used for instance on Midway.
The IOMMU architecture for ARM is relying on the page table is shared between the processor and each IOMMU.
The patch series is divided following:
- #1: fixing grant-table with IOMMU. Will be necessary for ARM later
- #2-#3: Make static some vtd functions
- #4-#5: Adding new device tree functions
- #6-#9: Prepare IOMMU code to add support for ARM
- #10-#11: Add IOMMU architecture for ARM
- #12: Add SMMU driversFor 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. It's a problem for the swiotlb which needs to know if the device is procted or not when foreign mapping is mapped in dom0.
When I talked with Stefano, 2 solutions came:
- Having a property in each "protected" device
- List in the hypervisor node the procted devicesI didn't yet decide which solution I will use.
Any comments, questions are welcomed.
Sincerely yours,
Julien Grall (12):
xen/common: grant-table: only call IOMMU if paging mode translate is
disabled
xen/passthrough: vtd: Don't exportiommu_domain_teardownxen/passthrough: vtd: Don't exportiommu_set_pgd
xen/dts: Adddt_property_read_bool
xen/dts: Adddt_parse_phandle_with_argsanddt_parse_phandlexen/passthrough: reworkdom0_pvh_reqsto use it also on ARM xen/passthrough: iommu: Don't need to map dom0 page when the PT is
shared
xen/passthrough: iommu: Split generic IOMMU code xen/passthrough: iommu: Introduce arch specific code xen/passthrough: Introduce IOMMU ARM architure
MAINTAINERS: Adddrivers/passthrough/armdrivers/passthrough: arm: Add support for SMMU driversMAINTAINERS | 1 + xen/arch/arm/Rules.mk | 1 + xen/arch/arm/domain.c | 7 + xen/arch/arm/domain_build.c | 2 + 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 | 157 ++- xen/common/grant_table.c | 7 +- xen/drivers/passthrough/Makefile | 7 +- xen/drivers/passthrough/amd/iommu_cmd.c | 2 +- xen/drivers/passthrough/amd/iommu_guest.c | 8 +- xen/drivers/passthrough/amd/iommu_map.c | 56 +- xen/drivers/passthrough/amd/pci_amd_iommu.c | 53 +- xen/drivers/passthrough/arm/Makefile | 2 + xen/drivers/passthrough/arm/iommu.c | 65 + xen/drivers/passthrough/arm/smmu.c | 1701 +++++++++++++++++++++++++++ xen/drivers/passthrough/iommu.c | 525 +-------- xen/drivers/passthrough/iommu_pci.c | 468 ++++++++ xen/drivers/passthrough/iommu_x86.c | 106 ++ xen/drivers/passthrough/vtd/iommu.c | 124 +- 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 + xen/include/asm-x86/hvm/iommu.h | 29 + xen/include/asm-x86/iommu.h | 50 + xen/include/xen/device_tree.h | 75 ++ xen/include/xen/hvm/iommu.h | 27 +- xen/include/xen/iommu.h | 51 +- 32 files changed, 2891 insertions(+), 701 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/iommu_pci.c create mode 100644 xen/drivers/passthrough/iommu_x86.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
Julien Grall