xen/arm: Handle translated addresses for hardware domains in GICv2
PATCH 1/1 xen/arm: Handle translated addresses for hardware domains in GICv2
Translated address could have an offset applied to them. Replicate same value for device node to avoid improper address computation in the OS.
--- xen/arch/arm/gic-v2.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
Submit again after release. This patch was developed as a specific platform patch but it applies to all platforms.
Previous discussions at
- http://lists.xen.org/archives/html/xen-devel/2014-11/msg00406.html
- http://lists.xen.org/archives/html/xen-devel/2014-11/msg00520.html
xen/arch/arm/gic-v2.c +10 -10
@@ -590,7 +590,7 @@ static int gicv2_make_dt_node(const struct domain *d,const struct dt_device_node *gic = dt_interrupt_controller;const void *compatible =NULL ;u32 len; -__be32 *new_cells, *tmp; +const __be32 *regs;int res =0 ; compatible =dt_get_property (gic,"compatible" , &len);
@@ -617,18 +617,18 @@ static int gicv2_make_dt_node(const struct domain *d,if ( res )return res; +/* copy GICC and GICD regions */ + regs =dt_get_property (gic,"reg" , &len); +if ( !regs ) + { +dprintk (XENLOG_ERR ,"Can't find reg property for the gic node\n" ); +return -FDT_ERR_XEN (ENOENT ); + } + len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */ - new_cells =xzalloc_bytes (len); -if ( new_cells ==NULL ) -return -FDT_ERR_XEN (ENOMEM ); - - tmp = new_cells; -dt_set_range (&tmp, node, d->arch.vgic.dbase,PAGE_SIZE ); -dt_set_range (&tmp, node, d->arch.vgic.cbase,PAGE_SIZE *2 ); - res =fdt_property (fdt,"reg" , new_cells, len); -xfree (new_cells); + res =fdt_property (fdt,"reg" , regs, len);return res; }
Signature · 1 line
1.9.1
Hi Frediano,
Quoted 5 lines · Frediano Ziglio
Translated address could have an offset applied to them. Replicate same value for device node to avoid improper address computation in the OS.
Signed-off-by Frediano Ziglio <[email protected]>
I'm wondering if it's worth to backport this patch to Xen 4.5?
I will wrote a patch to do the same for GICv3.
Regards,
Signature · 1 line
Julien Grall
Quoted 1 line · Julien Grall
I'm wondering if it's worth to backport this patch to Xen 4.5?
Maybe, I doubt 4.5 is being used on platforms which suffer from this issue, but it's pretty un-intrusive I suppose.
Quoted 1 line
I will wrote a patch to do the same for GICv3.
Thanks.
I certainly wouldn't want to backport a fix to gic v2 only.
Ian.
Quoted 5 lines · Ian Campbell
Quoted 1 line · Julien Grall
I'm wondering if it's worth to backport this patch to Xen 4.5?
Maybe, I doubt 4.5 is being used on platforms which suffer from this issue, but it's pretty un-intrusive I suppose.
There is no reason to consider only the set of platforms we support upstream. We should take into account people who want to ship a product based on Xen 4.5. This release aims to work anywhere by only adding few lines of code in the platform code.
Furthermore, the current code rely on how the device has been written. For instance the calxeda device tree is using ranges and, therefore, the regs contains offset.
Fortunately, the offset and the translated address is the same.
Quoted 1 line
I certainly wouldn't want to backport a fix to gic v2 only.
As we didn't backport other patches related to GICv3, it would not make much sense to backport a similar fix for GICv3..
Regards,
Signature · 1 line
Julien Grall
Quoted 9 lines · Julien Grall
Quoted 5 lines · Ian Campbell
Quoted 1 line · Julien Grall
I'm wondering if it's worth to backport this patch to Xen 4.5?
Maybe, I doubt 4.5 is being used on platforms which suffer from this issue, but it's pretty un-intrusive I suppose.
There is no reason to consider only the set of platforms we support upstream.
No, but it is a factor: we shouldn't be risking destabilising things for those platforms which were supported out of the box on 4.5 for the benefit of platforms which were and are not.
Of course risk is a judgement call, and as I said this change is pretty unobtrusive (read: probably not that risky), hence "maybe" rather than "no".
Quoted 2 lines
We should take into account people who want to ship a product
based on Xen 4.5.
Again, this is a factor but not the most important one.
Quoted 2 lines
This release aims to work anywhere by only adding few
lines of code in the platform code.
And so is this.
Quoted 9 lines
Furthermore, the current code rely on how the device has been written. For instance the calxeda device tree is using ranges and, therefore, the regs contains offset.
Fortunately, the offset and the translated address is the same.Quoted 1 line
I certainly wouldn't want to backport a fix to gic v2 only.
As we didn't backport other patches related to GICv3, it would not make much sense to backport a similar fix for GICv3..
We should consider each patch/series on its own merits. The other GICv3 fixes were far more invasive and complicated than what is being done here.
Assuming the v3 fix is similar to the v2 one here either both are justified or neither.
Ian.
Quoted 5 lines · Ian Campbell
Quoted 5 lines
Furthermore, the current code rely on how the device has been written. For instance the calxeda device tree is using ranges and, therefore, the regs contains offset.
Fortunately, the offset and the translated address is the same.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
I certainly wouldn't want to backport a fix to gic v2 only.
As we didn't backport other patches related to GICv3, it would not make much sense to backport a similar fix for GICv3..
We should consider each patch/series on its own merits. The other GICv3 fixes were far more invasive and complicated than what is being done here.
Agreed. Just it doesn't make sense to backport new GICv3 patches as we know that without the previous series any Linux >= 3.19 won't boot at all.
Regards,
Signature · 1 line
Julien Grall
Quoted 3 lines · Frediano Ziglio
Translated address could have an offset applied to them. Replicate same value for device node to avoid improper address computation in the OS.
I don't think this adequately explains what is going on here.
AIUI the issue is that the values in d->arch.vgic.{c,d}base have already been translated to host level addresses from whatever bus address applied to them in the DT.
By copying the original address from the DT directly we then get the original untranslated reg property, which the guest will then apply the translations to and, presumably, retrieve the same answer we have in {c,d}base.
This relies on us putting our GIC node at the same place as the platforms DTB, which is indeed the case.
Please can you rewrite the commit message to explain this more clearly.
One minor comment on the code:
xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d, · line 629
Quoted 10 lines
xen/arch/arm/gic-v2.c +8
-0+/* copy GICC and GICD regions */ + regs =dt_get_property (gic,"reg" , &len); +if ( !regs ) + { +dprintk (XENLOG_ERR ,"Can't find reg property for the gic node\n" ); +return -FDT_ERR_XEN (ENOENT ); + } + len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */
It takes a second to figure out why we aren't just using the length retrieved from the dt. Please add a comment.
Ian.
Translated address (in d->arch.vgic.{c,d}base) are now bus addresses which could not always be applied to the DT.
Copy the original address from DT directly to get the original untraslated reg property which will give same d->arch.vgic.{c,d}base values once translated again.
--- xen/arch/arm/gic-v2.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
Updated comment and commit message as requested.
xen/arch/arm/gic-v2.c +15 -11
@@ -590,7 +590,7 @@ static int gicv2_make_dt_node(const struct domain *d,const struct dt_device_node *gic = dt_interrupt_controller;const void *compatible =NULL ;u32 len; -__be32 *new_cells, *tmp; +const __be32 *regs;int res =0 ; compatible =dt_get_property (gic,"compatible" , &len);
@@ -617,18 +617,22 @@ static int gicv2_make_dt_node(const struct domain *d,if ( res )return res; - len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); - len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */ - new_cells =xzalloc_bytes (len); -if ( new_cells ==NULL ) -return -FDT_ERR_XEN (ENOMEM ); +/* +* Copy only GICC and GICD regions, not entire regions. +* DTB provides up to 4 regions to handle virtualization +* however dom0 just needs GICC and GICD provided by Xen. +*/ + regs =dt_get_property (gic,"reg" , &len); +if ( !regs ) + { +dprintk (XENLOG_ERR ,"Can't find reg property for the gic node\n" ); +return -FDT_ERR_XEN (ENOENT ); + } - tmp = new_cells; -dt_set_range (&tmp, node, d->arch.vgic.dbase,PAGE_SIZE ); -dt_set_range (&tmp, node, d->arch.vgic.cbase,PAGE_SIZE *2 ); + len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); + len *=2 ; - res =fdt_property (fdt,"reg" , new_cells, len); -xfree (new_cells); + res =fdt_property (fdt,"reg" , regs, len);return res; }
Signature · 1 line
1.9.1
Quoted 1 line · Frediano Ziglio
Translated address (in d->arch.vgic.{c,d}base) are now bus addresses
addresses
Quoted 2 lines
which could not always be applied to the DT.
Copy the original address from DT directly to get the original
addresses
Quoted 1 line
untraslated reg property which will give same d->arch.vgic.{c,d}base
untranslated
Quoted 25 lines
values once translated again.
Signed-off-by Frediano Ziglio <[email protected]>--- xen/arch/arm/gic-v2.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)Updated comment and commit message as requested.
xen/arch/arm/gic-v2.c +1
-1@@ -590,7 +590,7 @@ static int gicv2_make_dt_node(const struct domain *d,const struct dt_device_node *gic = dt_interrupt_controller;const void *compatible =NULL ;u32 len; -__be32 *new_cells, *tmp; +const __be32 *regs;int res =0 ; compatible =dt_get_property (gic,"compatible" , &len);@@ -617,18 +617,22 @@ static int gicv2_make_dt_node(const struct domain *d,if ( res )return res;
xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d, · line 623
Quoted 10 lines
xen/arch/arm/gic-v2.c +4
-5- len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); - len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */ - new_cells =xzalloc_bytes (len); -if ( new_cells ==NULL ) -return -FDT_ERR_XEN (ENOMEM ); +/* +* Copy only GICC and GICD regions, not entire regions. +* DTB provides up to 4 regions to handle virtualization +* however dom0 just needs GICC and GICD provided by Xen.
The 2 sentences say pretty much the same things. Although, the second one is more complete. I would only keep the second one.
Quoted 11 lines
xen/arch/arm/gic-v2.c +7
-2+*/ + regs =dt_get_property (gic,"reg" , &len); +if ( !regs ) + { +dprintk (XENLOG_ERR ,"Can't find reg property for the gic node\n" ); +return -FDT_ERR_XEN (ENOENT ); + } - tmp = new_cells; -dt_set_range (&tmp, node, d->arch.vgic.dbase,PAGE_SIZE );
xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d, · line 638
Quoted 10 lines
xen/arch/arm/gic-v2.c +3
-3-dt_set_range (&tmp, node, d->arch.vgic.cbase,PAGE_SIZE *2 ); + len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); + len *=2 ; - res =fdt_property (fdt,"reg" , new_cells, len); -xfree (new_cells); + res =fdt_property (fdt,"reg" , regs, len);return res; }
Regards,
Signature · 1 line
Julien Grall
PATCH 1/1 xen/arm: Handle translated addresses for hardware domains in GICv2
Translated addresses (in d->arch.vgic.{c,d}base) are now bus addresses which could not always be applied to the DT.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again.
--- xen/arch/arm/gic-v2.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
Fixed typos in comments.
xen/arch/arm/gic-v2.c +14 -11
@@ -590,7 +590,7 @@ static int gicv2_make_dt_node(const struct domain *d,const struct dt_device_node *gic = dt_interrupt_controller;const void *compatible =NULL ;u32 len; -__be32 *new_cells, *tmp; +const __be32 *regs;int res =0 ; compatible =dt_get_property (gic,"compatible" , &len);
@@ -617,18 +617,21 @@ static int gicv2_make_dt_node(const struct domain *d,if ( res )return res; - len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); - len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */ - new_cells =xzalloc_bytes (len); -if ( new_cells ==NULL ) -return -FDT_ERR_XEN (ENOMEM ); +/* +* DTB provides up to 4 regions to handle virtualization +* however dom0 just needs GICC and GICD provided by Xen. +*/ + regs =dt_get_property (gic,"reg" , &len); +if ( !regs ) + { +dprintk (XENLOG_ERR ,"Can't find reg property for the gic node\n" ); +return -FDT_ERR_XEN (ENOENT ); + } - tmp = new_cells; -dt_set_range (&tmp, node, d->arch.vgic.dbase,PAGE_SIZE ); -dt_set_range (&tmp, node, d->arch.vgic.cbase,PAGE_SIZE *2 ); + len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); + len *=2 ; - res =fdt_property (fdt,"reg" , new_cells, len); -xfree (new_cells); + res =fdt_property (fdt,"reg" , regs, len);return res; }
Signature · 1 line
1.9.1
Hi Frediano,
Quoted 27 lines · Frediano Ziglio
Translated addresses (in d->arch.vgic.{c,d}base) are now bus addresses which could not always be applied to the DT.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again.Signed-off-by Frediano Ziglio <[email protected]>--- xen/arch/arm/gic-v2.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)Fixed typos in comments.
xen/arch/arm/gic-v2.c +1
-1@@ -590,7 +590,7 @@ static int gicv2_make_dt_node(const struct domain *d,const struct dt_device_node *gic = dt_interrupt_controller;const void *compatible =NULL ;u32 len; -__be32 *new_cells, *tmp; +const __be32 *regs;int res =0 ; compatible =dt_get_property (gic,"compatible" , &len);
xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d, · line 621
Quoted 10 lines
xen/arch/arm/gic-v2.c +2
-5@@ -617,18 +617,21 @@ static int gicv2_make_dt_node(const struct domain *d,if ( res )return res; - len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); - len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */ - new_cells =xzalloc_bytes (len); -if ( new_cells ==NULL ) -return -FDT_ERR_XEN (ENOMEM ); +/* +* DTB provides up to 4 regions to handle virtualization
Sorry to ask more change.
I'm not sure why you speak about virtualization here.
Also, can you write somewhere that the GICC and GICD are the first 2 regions of the "reg"?
Other than that this patch looks good to me:
Regards,
Signature · 1 line
Julien Grall
Quoted 43 lines · Julien Grall
Hi Frediano,
Quoted 27 lines · Frediano Ziglio
Translated addresses (in d->arch.vgic.{c,d}base) are now bus addresses which could not always be applied to the DT.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again.Signed-off-by Frediano Ziglio <[email protected]>--- xen/arch/arm/gic-v2.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)Fixed typos in comments.
xen/arch/arm/gic-v2.c +1
-1@@ -590,7 +590,7 @@ static int gicv2_make_dt_node(const struct domain *d,const struct dt_device_node *gic = dt_interrupt_controller;const void *compatible =NULL ;u32 len; -__be32 *new_cells, *tmp; +const __be32 *regs;int res =0 ; compatible =dt_get_property (gic,"compatible" , &len);xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d, · line 621
Quoted 10 lines
xen/arch/arm/gic-v2.c +2
-5@@ -617,18 +617,21 @@ static int gicv2_make_dt_node(const struct domain *d,if ( res )return res; - len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); - len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */ - new_cells =xzalloc_bytes (len); -if ( new_cells ==NULL ) -return -FDT_ERR_XEN (ENOMEM ); +/* +* DTB provides up to 4 regions to handle virtualization Sorry to ask more change.
Quoted 1 line
I'm not sure why you speak about virtualization here.
Because two of the regions are GICH and GICV, and those are the ones we are truncating out here.
Quoted 10 lines
Also, can you write somewhere that the GICC and GICD are the first 2 regions of the "reg"?
Other than that this patch looks good to me:
Reviewed-by Julien Grall <[email protected]>Regards,
Quoted 44 lines · Ian Campbell
Quoted 43 lines · Julien Grall
Hi Frediano,
Quoted 27 lines · Frediano Ziglio
Translated addresses (in d->arch.vgic.{c,d}base) are now bus addresses which could not always be applied to the DT.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again.Signed-off-by Frediano Ziglio <[email protected]>--- xen/arch/arm/gic-v2.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)Fixed typos in comments.
xen/arch/arm/gic-v2.c +1
-1@@ -590,7 +590,7 @@ static int gicv2_make_dt_node(const struct domain *d,const struct dt_device_node *gic = dt_interrupt_controller;const void *compatible =NULL ;u32 len; -__be32 *new_cells, *tmp; +const __be32 *regs;int res =0 ; compatible =dt_get_property (gic,"compatible" , &len);xen/arch/arm/gic-v2.c static int gicv2_make_dt_node(const struct domain *d, · line 621
Quoted 10 lines
xen/arch/arm/gic-v2.c +2
-5@@ -617,18 +617,21 @@ static int gicv2_make_dt_node(const struct domain *d,if ( res )return res; - len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); - len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */ - new_cells =xzalloc_bytes (len); -if ( new_cells ==NULL ) -return -FDT_ERR_XEN (ENOMEM ); +/* +* DTB provides up to 4 regions to handle virtualization Sorry to ask more change.
Quoted 4 lines
Quoted 1 line
I'm not sure why you speak about virtualization here.
Because two of the regions are GICH and GICV, and those are the ones we are truncating out here.
I though about it but I wasn't sure if he meant that.
Regards,
Signature · 1 line
Julien Grall
PATCH 1/1 xen/arm: Handle translated addresses for hardware domains in GICv2
Translated addresses (in d->arch.vgic.{c,d}base) are now bus addresses which could not always be applied to the DT.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again.
--- xen/arch/arm/gic-v2.c | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-)
Changed some comments.
xen/arch/arm/gic-v2.c +15 -11
@@ -604,7 +604,7 @@ static int gicv2_make_dt_node(const struct domain *d,const struct dt_device_node *gic = dt_interrupt_controller;const void *compatible =NULL ;u32 len; -__be32 *new_cells, *tmp; +const __be32 *regs;int res =0 ; compatible =dt_get_property (gic,"compatible" , &len);
@@ -631,18 +631,22 @@ static int gicv2_make_dt_node(const struct domain *d,if ( res )return res; - len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); - len *=2 ;/* GIC has two memory regions: Distributor + CPU interface */ - new_cells =xzalloc_bytes (len); -if ( new_cells ==NULL ) -return -FDT_ERR_XEN (ENOMEM ); +/* +* DTB provides up to 4 regions to handle virtualization +* (in order GICD, GICC, GICH and GICV interfaces) +* however dom0 just needs GICD and GICC provided by Xen. +*/ + regs =dt_get_property (gic,"reg" , &len); +if ( !regs ) + { +dprintk (XENLOG_ERR ,"Can't find reg property for the gic node\n" ); +return -FDT_ERR_XEN (ENOENT ); + } - tmp = new_cells; -dt_set_range (&tmp, node, d->arch.vgic.dbase,PAGE_SIZE ); -dt_set_range (&tmp, node, d->arch.vgic.cbase,PAGE_SIZE *2 ); + len =dt_cells_to_size (dt_n_addr_cells (node) +dt_n_size_cells (node)); + len *=2 ; - res =fdt_property (fdt,"reg" , new_cells, len); -xfree (new_cells); + res =fdt_property (fdt,"reg" , regs, len);return res; }
Signature · 1 line
1.9.1
Quoted 7 lines · Frediano Ziglio
Translated addresses (in d->arch.vgic.{c,d}base) are now bus addresses which could not always be applied to the DT.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again.Signed-off-by Frediano Ziglio <[email protected]>
Acked + applied. I reworded the commit message a bit in an attempt to make it clearer:
xen/arm: Handle translated addresses for hardware domains in GICv2
Translated addresses (in d->arch.vgic.{c,d}base) are bus addresses which are not always correct in the context of a subnode in the DTB exposed to domain 0 since they would then be subject to retranslation.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again by the guest.
I hope that is ok.
2015-03-02 14:50 GMT+00:00 Ian Campbell <[email protected]>:
Quoted 22 lines · Frediano Ziglio
Quoted 7 lines
Translated addresses (in d->arch.vgic.{c,d}base) are now bus addresses which could not always be applied to the DT.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again.Signed-off-by Frediano Ziglio <[email protected]>Acked + applied. I reworded the commit message a bit in an attempt to make it clearer:
xen/arm: Handle translated addresses for hardware domains in GICv2
Translated addresses (in d->arch.vgic.{c,d}base) are bus addresses which are not always correct in the context of a subnode in the DTB exposed to domain 0 since they would then be subject to retranslation.
Copy the original addresses from DT directly to get the original untranslated reg property which will give same d->arch.vgic.{c,d}base values once translated again by the guest.
Quoted 6 lines
Signed-off-by Frediano Ziglio <[email protected]>Acked-by Ian Campbell <[email protected]>[ ijc -- attempt to clarify the commit message ]I hope that is ok.
Perfect!
Thanks,
Frediano