Implement the XEN_DOMCTL_memory_mapping hypecall for arm32
cover Implement the XEN_DOMCTL_memory_mapping hypecall for arm32
Hello,
this patchset adds a first attempt of implementation of the XEN_DOMCTL_memory_mapping hypercall for the arm32 architecture.
As a part of my thesis project (developed with Paolo Valente, in Italy, [1]), I am porting an automotive-grade real-time OS (Evidence's ERIKA Enterprise, [2], [3]) on Xen on ARM, and the port of the OS as a domU has required the OS to be able to access peripherals performing memory-mapped I/O; as a consequence, the I/O-memory ranges related to such peripherals had to be made accessible to the domU.
I have been working on this patchset for the last weeks after reading a related xen-devel discussion ([4]), and I had no idea that Eric Trudeau had already proposed to this mailing list an implementation of the hypercall ([5], [6]). Any comment is obviously welcome on this point, and if he wants so I will of course add his Signed-off-by to the patches.
Any feedback about the patches is more than welcome. The code has been tested with Linux v3.13 as dom0 and ERIKA Enterprise as domU.
[1] http://www.unimore.it/
[2] http://www.evidence.eu.com/
[3] http://erika.tuxfamily.org/drupal/
[4] http://lists.xen.org/archives/html/xen-devel/2013-06/msg00870.html
[5] http://marc.info/?l=xen-devel&m=137338996422503
[6] http://lists.xen.org/archives/html/xen-devel/2014-02/msg02514.html
Arianna Avanzini (3):
arch, arm32: add definition of paddr_bits
arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall tools, libxl: handle the iomem parameter with the memory_mapping hcall
tools/libxl/libxl_create.c | 10 ++++++ xen/arch/arm/arm32/cpu.h | 7 ++++ xen/arch/arm/arm32/domctl.c | 74 +++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/p2m.c | 9 +++++ xen/include/asm-arm/p2m.h | 2 ++ xen/include/asm-arm/processor.h | 2 ++ 6 files changed, 104 insertions(+) create mode 100644 xen/arch/arm/arm32/cpu.h
Signature · 1 line
1.8.5.3
RFC PATCH 1/3 arch, arm32: add definition of paddr_bits
Currently, the paddr_bits variable, which keeps the machine word size, is not defined for the arm32 architecture. This commits adds its definition for arm32 in a new header in the architecture-specific directory.
This change is instrumental to the implementation of the XEN_DOMCTL_memory_mapping hypercall, added in the following commit.
--- xen/arch/arm/arm32/cpu.h | 7 +++++++ xen/include/asm-arm/processor.h | 2 ++ 2 files changed, 9 insertions(+) create mode 100644 xen/arch/arm/arm32/cpu.h
xen/arch/arm/arm32/cpu.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef __ARM_ARM32_CPU_H +#define __ARM_ARM32_CPU_H + +/* ARM-v7 features LPAE (machine word size is 40 bit) */ +unsigned int paddr_bits =40 ; + +#endif /* __ARM_ARM32_CPU_H */
xen/include/asm-arm/processor.h +2 -0
@@ -226,6 +226,8 @@ struct cpuinfo_arm {* capabilities of CPUs */ +extern unsigned int paddr_bits; +extern struct cpuinfo_arm boot_cpu_data;extern void identify_cpu (struct cpuinfo_arm *);
Signature · 1 line
1.8.5.3
Re: [RFC PATCH 1/3] arch, arm32: add definition of paddr_bits
Hello Arianna,
Quoted 7 lines · Arianna Avanzini
Currently, the
paddr_bitsvariable, which keeps the machine word size, is not defined for the arm32 architecture. This commits adds its definition for arm32 in a new header in the architecture-specific directory.
This change is instrumental to the implementation of theXEN_DOMCTL_memory_mappinghypercall, added in the following commit.
paddr_bits doesn't keep the machine word size but the size of the physical address.
On ARM, this value is fixed and defined as PADDR_BITS inxen/include/asm-arm/page.h. I don't think we need to introduce a variable for this purpose. x86 defines paddr_bits because the value can change on some processor.
xen/arch/arm/arm32/cpu.h line 6
Quoted 12 lines
xen/arch/arm/arm32/cpu.h new file +6
-0@@ -0,0 +1,7 @@ +#ifndef __ARM_ARM32_CPU_H +#define __ARM_ARM32_CPU_H + +/* ARM-v7 features LPAE (machine word size is 40 bit) */ +unsigned int paddr_bits =40 ; +
Global variable must not be defined in headers. If someone decides to include this header in 2 differents C files, the variable will be defined twice. Therefore the linker-step will fail.
You should define it in a c-file.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 1/3] arch, arm32: add definition of paddr_bits
Quoted 2 lines · Julien Grall
Hello Arianna,
Hello,
Quoted 9 lines · Arianna Avanzini
Quoted 7 lines
Currently, the
paddr_bitsvariable, which keeps the machine word size, is not defined for the arm32 architecture. This commits adds its definition for arm32 in a new header in the architecture-specific directory.
This change is instrumental to the implementation of theXEN_DOMCTL_memory_mappinghypercall, added in the following commit.
Quoted 7 lines
paddr_bitsdoesn't keep the machine word size but the size of the physical address.On ARM, this value is fixed and defined as
PADDR_BITSinxen/include/asm-arm/page.h. I don't think we need to introduce a variable for this purpose. x86 definespaddr_bitsbecause the value can change on some processor.
Thank you for explaining that. I've tried to fix as suggested.
Quoted 17 lines
xen/arch/arm/arm32/cpu.h line 6
Quoted 12 lines
xen/arch/arm/arm32/cpu.h new file +6
-0@@ -0,0 +1,7 @@ +#ifndef __ARM_ARM32_CPU_H +#define __ARM_ARM32_CPU_H + +/* ARM-v7 features LPAE (machine word size is 40 bit) */ +unsigned int paddr_bits =40 ; +Global variable must not be defined in headers. If someone decides to include this header in 2 differents C files, the variable will be defined twice. Therefore the linker-step will fail.
Quoted 2 lines
You should define it in a c-file.
OK, thank you again.
Quoted 2 lines
Regards,
Signature · 5 lines
/* * Arianna Avanzini * [email protected] * [email protected] */
RFC PATCH 2/3 arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
In reply to Arianna AvanziniThis commit introduces a first attempt of implementation of the XEN_DOMCTL_memory_mapping hypercall for arm32. The following warnings must be taken into consideration:
. currently, the hypercall simply performs an 1:1 mapping of I/O
memory ranges (mfn == gfn);
. the range of I/O memory addresses is mapped all at once with
map_mmio_regions();
. the hypercall takes for granted that any I/O memory range can
be mapped to a domU if the current domain is dom0.
--- xen/arch/arm/arm32/domctl.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/p2m.c | 9 ++++++ xen/include/asm-arm/p2m.h | 2 ++ 3 files changed, 85 insertions(+)
xen/arch/arm/arm32/domctl.c +74 -0
@@ -10,8 +10,11 @@#include <xen/errno.h> #include <xen/sched.h> #include <xen/hypercall.h> +#include <xen/iocap.h> #include <public/domctl.h> +#include "cpu.h" +long subarch_do_domctl (struct xen_domctl *domctl,struct domain *d,XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl) {
@@ -19,6 +22,77 @@ long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d, {case XEN_DOMCTL_set_address_size:return domctl->u.address_size.size ==32 ?0 : -EINVAL ; +case XEN_DOMCTL_memory_mapping: + { +unsigned long gfn = domctl->u.memory_mapping.first_gfn; +unsigned long mfn = domctl->u.memory_mapping.first_mfn; +unsigned long nr_mfns = domctl->u.memory_mapping.nr_mfns; +int add = domctl->u.memory_mapping.add_mapping; +long int ret; + + ret = -EINVAL ; +if ( (mfn + nr_mfns -1 ) < mfn ||/* wrap? */ + ((mfn | (mfn + nr_mfns -1 )) >> (paddr_bits -PAGE_SHIFT )) || + (gfn + nr_mfns -1 ) < gfn )/* wrap? */ +return ret; + + ret = -EPERM ; +/* +* NOTE: dom0 seems to have empty iomem_caps but to be however able to +* access I/O memory ranges. The following check takes for granted +* that any iomem range can be mapped to a domU if the current +* domain is dom0. +*/ +if ( current->domain->domain_id !=0 && + !iomem_access_permitted (current->domain, mfn, mfn + nr_mfns -1 ) ) +return ret; + + ret =xsm_iomem_mapping (XSM_HOOK , d, mfn, mfn + nr_mfns -1 , add); +if ( ret ) +return ret; + +if ( add ) + { +printk (XENLOG_G_INFO +"memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n" , + d->domain_id, gfn, mfn, nr_mfns); + ret =iomem_permit_access (d, mfn, mfn + nr_mfns -1 ); +if ( !ret ) + { +/* 1:1 iomem mapping (gfn == mfn) */ + ret =map_mmio_regions (d, gfn, gfn + nr_mfns -1 , mfn); +if ( ret ) + { +printk (XENLOG_G_WARNING +"memory_map:fail: dom%d gfn=%lx mfn=%lx\n" , + d->domain_id, gfn, mfn); +if (iomem_deny_access (d, mfn, mfn + nr_mfns -1 ) && +is_hardware_domain (current->domain) ) +printk (XENLOG_ERR +"memory_map: failed to deny dom%d access " +"to [%lx,%lx]\n" , + d->domain_id, mfn, mfn + nr_mfns -1 ); + } + } + } +else + { +printk (XENLOG_G_INFO +"memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n" , + d->domain_id, gfn, mfn, nr_mfns); + + add =unmap_mmio_regions (d, gfn, gfn + nr_mfns -1 , mfn); + ret =iomem_deny_access (d, mfn, mfn + nr_mfns -1 ); +if ( ret && add ) + ret = -EIO ; +if ( ret &&is_hardware_domain (current->domain) ) +printk (XENLOG_ERR +"memory_map: error %ld %s dom%d access to [%lx,%lx]\n" , + ret, add ?"removing" :"denying" , d->domain_id, + mfn, mfn + nr_mfns -1 ); + } +return ret; + }default :return -ENOSYS ; }
xen/arch/arm/p2m.c +9 -0
@@ -461,6 +461,15 @@ int map_mmio_regions(struct domain *d, maddr, MATTR_DEV, p2m_mmio_direct); } +int unmap_mmio_regions (struct domain *d, +paddr_t start_gaddr, +paddr_t end_gaddr, +paddr_t maddr) +{ +return apply_p2m_changes (d,REMOVE , start_gaddr, end_gaddr, + maddr,MATTR_DEV , p2m_mmio_direct); +} + int guest_physmap_add_entry(struct domain *d, unsigned long gpfn, unsigned long mfn,
xen/include/asm-arm/p2m.h +2 -0
@@ -88,6 +88,8 @@ int p2m_populate_ram(struct domain *d, paddr_t start, paddr_t end);* address maddr. */ int map_mmio_regions (struct domain *d,paddr_t start_gaddr,paddr_t end_gaddr,paddr_t maddr); +int unmap_mmio_regions (struct domain *d,paddr_t start_gaddr, +paddr_t end_gaddr,paddr_t maddr); int guest_physmap_add_entry(struct domain *d, unsigned long gfn,
Signature · 1 line
1.8.5.3
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Hello Arianna,
Quoted 17 lines · Arianna Avanzini
This commit introduces a first attempt of implementation of the
XEN_DOMCTL_memory_mappinghypercall for arm32. The following warnings must be taken into consideration:
. currently, the hypercall simply performs an 1:1 mapping of I/O
memory ranges (mfn == gfn);
. the range of I/O memory addresses is mapped all at once with
map_mmio_regions();
. the hypercall takes for granted that any I/O memory range can
be mapped to a domU if the current domain is dom0.Signed-off-by Arianna Avanzini <[email protected]>Cc Dario Faggioli <[email protected]>Cc Paolo Valente <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Julien Grall <[email protected]>Cc Eric Trudeau <[email protected]>Cc Viktor Kleinik <[email protected]>
Quoted 2 lines
--- xen/arch/arm/arm32/domctl.c | 74 +++++++++++++++++++++++++++++++++++++++++++++
The implementation of XEN_DOMCTL_memory_mapping is not ARM32 specific. It can be implemented in arch/arm/domctl.c.
Quoted 39 lines
xen/arch/arm/p2m.c | 9 ++++++ xen/include/asm-arm/p2m.h | 2 ++ 3 files changed, 85 insertions(+)xen/arch/arm/arm32/domctl.c +16
-0@@ -10,8 +10,11 @@#include <xen/errno.h> #include <xen/sched.h> #include <xen/hypercall.h> +#include <xen/iocap.h> #include <public/domctl.h> +#include "cpu.h" +long subarch_do_domctl (struct xen_domctl *domctl,struct domain *d,XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl) {@@ -19,6 +22,77 @@ long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d, {case XEN_DOMCTL_set_address_size:return domctl->u.address_size.size ==32 ?0 : -EINVAL ; +case XEN_DOMCTL_memory_mapping: + { +unsigned long gfn = domctl->u.memory_mapping.first_gfn; +unsigned long mfn = domctl->u.memory_mapping.first_mfn; +unsigned long nr_mfns = domctl->u.memory_mapping.nr_mfns; +int add = domctl->u.memory_mapping.add_mapping; +long int ret; + + ret = -EINVAL ; +if ( (mfn + nr_mfns -1 ) < mfn ||/* wrap? */ + ((mfn | (mfn + nr_mfns -1 )) >> (paddr_bits -PAGE_SHIFT )) || + (gfn + nr_mfns -1 ) < gfn )/* wrap? */ +return ret;xen/arch/arm/ renamed from xen/arch/arm/arm32/domctl.c +1
-0+
xen/arch/arm/
Quoted 10 lines
xen/arch/arm/ renamed from xen/arch/arm/arm32/domctl.c +10
-0+ ret = -EPERM; + /* + * NOTE: dom0 seems to have empty iomem_caps but to be however able to + * access I/O memory ranges. The following check takes for granted + * that any iomem range can be mapped to a domU if the current + * domain is dom0. + */ + if ( current->domain->domain_id != 0 && + !iomem_access_permitted(current->domain, mfn, mfn + nr_mfns - 1) ) + return ret;
This check can be removed by adding in construct_dom0 (arch/arm/domain_build.c) something like that:
/* DOM0 is permitted full I/O capabilities */
rc = iomem_permit_access(d, 0UL, ~OUL);
I'm wondering if we can even restrict dom0 I/0 access by only permit access on devices passthrough to it. Because dom0 should not be allowed to map I/O ranges which belong to device used by Xen e.g : GIC, RAM,...
I think we should at least restrict dom0 to use the hypercall for mapping device memory. Otherwise dom0 may be allowed to map Xen address range, do wrong thing with foreign mapping...
Quoted 5 lines
xen/arch/arm/ renamed from xen/arch/arm/arm32/domctl.c +5
-0+ + ret = xsm_iomem_mapping(XSM_HOOK, d, mfn, mfn + nr_mfns - 1, add); + if ( ret ) + return ret; +
xen/arch/arm/
Quoted 10 lines
xen/arch/arm/ renamed from xen/arch/arm/arm32/domctl.c +10
-0+ if ( add ) + { + printk(XENLOG_G_INFO + "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n", + d->domain_id, gfn, mfn, nr_mfns); + ret = iomem_permit_access(d, mfn, mfn + nr_mfns - 1); + if ( !ret ) + { + /* 1:1 iomem mapping (gfn == mfn) */ + ret = map_mmio_regions(d, gfn, gfn + nr_mfns - 1, mfn);
The comment "1:1 iomem mapping (gfn == mfn)" seems wrong here. The implementation you wrote allow gfn != mfn.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 16 lines · Julien Grall
xen/arch/arm/arm32/domctl.c long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d, · line 48
Quoted 11 lines · Arianna Avanzini
xen/arch/arm/arm32/domctl.c +11
-0+ + ret = -EPERM ; +/* +* NOTE: dom0 seems to have empty iomem_caps but to be however able to +* access I/O memory ranges. The following check takes for granted +* that any iomem range can be mapped to a domU if the current +* domain is dom0. +*/ +if ( current->domain->domain_id !=0 && + !iomem_access_permitted (current->domain, mfn, mfn + nr_mfns -1 ) ) +return ret;This check can be removed by adding in
construct_dom0(arch/arm/domain_build.c) something like that:
Quoted 3 lines
/* DOM0 is permitted full I/O capabilities */ rc = iomem_permit_access(d, 0UL, ~OUL);
Right. FTR, xen/arch/x86/domain_build.c, has this (also in construct_dom0):
/* DOM0 is permitted full I/O capabilities. */
rc |= ioports_permit_access(dom0, 0, 0xFFFF);
rc |= iomem_permit_access(dom0, 0UL, ~0UL);
rc |= irqs_permit_access(dom0, 1, nr_irqs_gsi - 1);Do you want a patch to that/similar effect?
Quoted 4 lines
I'm wondering if we can even restrict dom0 I/0 access by only permit access on devices passthrough to it. Because dom0 should not be allowed to map I/O ranges which belong to device used by Xen e.g : GIC, RAM,...
So, this is probably me messing up with the terminology, but what 'devices passthrough to it [dom0]' would mean, for example in cases where we don't have an IOMMU (like cubie* boards), and hence where proper passtrhogh will never be, I think, supported? Or do we plan to have it working there too?
Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 23 lines · Dario Faggioli
Quoted 16 lines · Julien Grall
xen/arch/arm/arm32/domctl.c long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d, · line 48
Quoted 11 lines · Arianna Avanzini
xen/arch/arm/arm32/domctl.c +11
-0+ + ret = -EPERM ; +/* +* NOTE: dom0 seems to have empty iomem_caps but to be however able to +* access I/O memory ranges. The following check takes for granted +* that any iomem range can be mapped to a domU if the current +* domain is dom0. +*/ +if ( current->domain->domain_id !=0 && + !iomem_access_permitted (current->domain, mfn, mfn + nr_mfns -1 ) ) +return ret;This check can be removed by adding in
construct_dom0(arch/arm/domain_build.c) something like that:Quoted 3 lines
/* DOM0 is permitted full I/O capabilities */ rc = iomem_permit_access(d, 0UL, ~OUL);Right. FTR,
xen/arch/x86/domain_build.c, has this (also inconstruct_dom0):
Quoted 6 lines
/* DOM0 is permitted full I/O capabilities. */ rc |= ioports_permit_access(dom0, 0, 0xFFFF); rc |= iomem_permit_access(dom0, 0UL, ~0UL); rc |= irqs_permit_access(dom0, 1, nr_irqs_gsi - 1);Do you want a patch to that/similar effect?
Yes. Maybe a bit more smarter than permitting full I/0 caps for dom0.
Quoted 9 lines
Quoted 4 lines
I'm wondering if we can even restrict dom0 I/0 access by only permit access on devices passthrough to it. Because dom0 should not be allowed to map I/O ranges which belong to device used by Xen e.g : GIC, RAM,...
So, this is probably me messing up with the terminology, but what 'devices passthrough to it [dom0]' would mean, for example in cases where we don't have an IOMMU (like cubie* boards), and hence where proper passtrhogh will never be, I think, supported? Or do we plan to have it working there too?
My term seems to be wrong for dom0 :).
On ARM, some device is used by Xen and therefore not exposed to dom0. By passthrough to dom0 I meant every device that are given to dom0, no matter if the platform has an IOMMU.
I think DOM0 should only be able to map theses devices to a guest. It seems stupid to allow dom0 mapping RAM or the UART used by Xen.
Signature · 1 line
Julien Grall
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 5 lines · Julien Grall
Quoted 3 lines · Dario Faggioli
Right. FTR,
xen/arch/x86/domain_build.c, has this (also inconstruct_dom0):
Quoted 9 lines
Quoted 6 lines
/* DOM0 is permitted full I/O capabilities. */ rc |= ioports_permit_access(dom0, 0, 0xFFFF); rc |= iomem_permit_access(dom0, 0UL, ~0UL); rc |= irqs_permit_access(dom0, 1, nr_irqs_gsi - 1);Do you want a patch to that/similar effect?
Yes. Maybe a bit more smarter than permitting full I/0 caps for dom0.
EhEh... do you mean to say that x86 is "not smart" ? :-)
Quoted 6 lines
Quoted 5 lines
So, this is probably me messing up with the terminology, but what 'devices passthrough to it [dom0]' would mean, for example in cases where we don't have an IOMMU (like cubie* boards), and hence where proper passtrhogh will never be, I think, supported? Or do we plan to have it working there too?
Quoted 6 lines
My term seems to be wrong for dom0 :).
On ARM, some device is used by Xen and therefore not exposed to dom0. By passthrough to dom0 I meant every device that are given to dom0, no matter if the platform has an IOMMU.
Ok, now I got it.
Quoted 3 lines
I think DOM0 should only be able to map theses devices to a guest. It seems stupid to allow dom0 mapping RAM or the UART used by Xen.
I see, and it does make sense.
Of course, I really don't know what these devices are and what the best approach would be to hide/revoke permissions to their iomem/irqs (e.g., allow everything and then revoke some, allow selectively in the first place, etc.).
I'm quite sure Arianna is keen on helping with this, but it better be, if possible, someone of you ARM folks suggesting her what, where and how. :-)
Thanks and Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Hi Dario,
Quoted 11 lines · Dario Faggioli
Quoted 10 lines · Julien Grall
Quoted 8 lines · Dario Faggioli
Right. FTR,
xen/arch/x86/domain_build.c, has this (also inconstruct_dom0):/* DOM0 is permitted full I/O capabilities. */ rc |= ioports_permit_access(dom0, 0, 0xFFFF); rc |= iomem_permit_access(dom0, 0UL, ~0UL); rc |= irqs_permit_access(dom0, 1, nr_irqs_gsi - 1);
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Do you want a patch to that/similar effect?
Yes. Maybe a bit more smarter than permitting full I/0 caps for dom0.
EhEh... do you mean to say that x86 is "not smart" ? :-)
No :).
Quoted 18 lines
Quoted 7 lines
Quoted 6 lines
So, this is probably me messing up with the terminology, but what 'devices passthrough to it [dom0]' would mean, for example in cases where we don't have an IOMMU (like cubie* boards), and hence where proper passtrhogh will never be, I think, supported? Or do we plan to have it working there too?
Quoted 6 lines
My term seems to be wrong for dom0 :).
On ARM, some device is used by Xen and therefore not exposed to dom0. By passthrough to dom0 I meant every device that are given to dom0, no matter if the platform has an IOMMU.
Ok, now I got it.
Quoted 3 lines
I think DOM0 should only be able to map theses devices to a guest. It seems stupid to allow dom0 mapping RAM or the UART used by Xen.
Quoted 6 lines
I see, and it does make sense.
Of course, I really don't know what these devices are and what the best approach would be to hide/revoke permissions to their iomem/irqs (e.g., allow everything and then revoke some, allow selectively in the first place, etc.).
I think the best place to permit access is in map_device (xen/arch/arm/domain_build.c).
This function is called for every devices used by dom0 to map I/O mem and IRQ.
Quoted 4 lines
I'm quite sure Arianna is keen on helping with this, but it better be, if possible, someone of you ARM folks suggesting her what, where and how. :-)
Either the ML or #xenarm channel on Freenode are the best to ask question. Arianna, I advice you to join the IRC channel if it's not already the case ;).
Cheers,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 47 lines · Julien Grall
Hi Dario,
Quoted 11 lines · Dario Faggioli
Quoted 10 lines · Julien Grall
Quoted 8 lines · Dario Faggioli
Right. FTR,
xen/arch/x86/domain_build.c, has this (also inconstruct_dom0):/* DOM0 is permitted full I/O capabilities. */ rc |= ioports_permit_access(dom0, 0, 0xFFFF); rc |= iomem_permit_access(dom0, 0UL, ~0UL); rc |= irqs_permit_access(dom0, 1, nr_irqs_gsi - 1);Quoted 5 lines
Quoted 4 lines
Quoted 1 line
Do you want a patch to that/similar effect?
Yes. Maybe a bit more smarter than permitting full I/0 caps for dom0.
EhEh... do you mean to say that x86 is "not smart" ? :-)
No :).
Quoted 18 lines
Quoted 7 lines
Quoted 6 lines
So, this is probably me messing up with the terminology, but what 'devices passthrough to it [dom0]' would mean, for example in cases where we don't have an IOMMU (like cubie* boards), and hence where proper passtrhogh will never be, I think, supported? Or do we plan to have it working there too?
Quoted 6 lines
My term seems to be wrong for dom0 :).
On ARM, some device is used by Xen and therefore not exposed to dom0. By passthrough to dom0 I meant every device that are given to dom0, no matter if the platform has an IOMMU.
Ok, now I got it.
Quoted 3 lines
I think DOM0 should only be able to map theses devices to a guest. It seems stupid to allow dom0 mapping RAM or the UART used by Xen.
Quoted 6 lines
I see, and it does make sense.
Of course, I really don't know what these devices are and what the best approach would be to hide/revoke permissions to their iomem/irqs (e.g., allow everything and then revoke some, allow selectively in the first place, etc.).
Quoted 5 lines
I think the best place to permit access is in
map_device(xen/arch/arm/domain_build.c).This function is called for every devices used by dom0 to map I/O mem and IRQ.
Thank you both for making this point more clear to me. I have tried to fix as specified.
Quoted 10 lines
Quoted 4 lines
I'm quite sure Arianna is keen on helping with this, but it better be, if possible, someone of you ARM folks suggesting her what, where and how. :-)
Either the ML or #xenarm channel on Freenode are the best to ask question. Arianna, I advice you to join the IRC channel if it's not already the case ;).
Cheers,
Signature · 5 lines
/* * Arianna Avanzini * [email protected] * [email protected] */
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
In reply to Julien GrallQuoted 38 lines
-----Original Message-----
From: Julien Grall [mailto:[email protected]]
Sent: Monday, March 03, 2014 10:21 AM
To: Dario Faggioli
Cc: Arianna Avanzini; [email protected]; [email protected]; [email protected]; [email protected]; Eric Trudeau; [email protected]; Ian Campbell; Tim Deegan
Subject: Re: [Xen-devel] [RFC PATCH 2/3] arch, arm32: add theXEN_DOMCTL_memory_mappinghypercallQuoted 7 lines · Dario Faggioli
Quoted 6 lines · Julien Grall
xen/arch/arm/arm32/domctl.c long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
Quoted 4 lines · Arianna Avanzini
xen/arch/arm/arm32/domctl.c +4
-0+ + ret = -EPERM ; +/* +* NOTE: dom0 seems to have empty iomem_caps but to be however able to
Quoted 6 lines
Quoted 6 lines
xen/arch/arm/arm32/domctl.c long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d,
Quoted 6 lines
xen/arch/arm/arm32/domctl.c +6
-0+* access I/O memory ranges. The following check takes for granted +* that any iomem range can be mapped to a domU if the current +* domain is dom0. +*/ +if ( current->domain->domain_id !=0 && + !iomem_access_permitted(current->domain, mfn, mfn + nr_mfns -1) )
Quoted 10 lines
Quoted 7 lines
Quoted 1 line
+ return ret;
This check can be removed by adding in
construct_dom0(arch/arm/domain_build.c) something like that:/* DOM0 is permitted full I/O capabilities */ rc = iomem_permit_access(d, 0UL, ~OUL);Right. FTR,
xen/arch/x86/domain_build.c, has this (also inconstruct_dom0):
Quoted 9 lines
Quoted 6 lines
/* DOM0 is permitted full I/O capabilities. */ rc |= ioports_permit_access(dom0, 0, 0xFFFF); rc |= iomem_permit_access(dom0, 0UL, ~0UL); rc |= irqs_permit_access(dom0, 1, nr_irqs_gsi - 1);Do you want a patch to that/similar effect?
Yes. Maybe a bit more smarter than permitting full I/0 caps for dom0.
Our implementation does not require Dom0 access permission in order for it to grant access permission to a DomU. I suppose it wouldn't hurt for iomem_permit_access because we allow iomem regions to be mapped into multiple domains; however, I think the irqs_permit_access call keeps multiple domains from "owning" the same IRQ. I might be wrong about that.
Quoted 21 lines
Quoted 9 lines
Quoted 4 lines
I'm wondering if we can even restrict dom0 I/0 access by only permit access on devices passthrough to it. Because dom0 should not be allowed to map I/O ranges which belong to device used by Xen e.g : GIC, RAM,...
So, this is probably me messing up with the terminology, but what 'devices passthrough to it [dom0]' would mean, for example in cases where we don't have an IOMMU (like cubie* boards), and hence where proper passtrhogh will never be, I think, supported? Or do we plan to have it working there too?
My term seems to be wrong for dom0 :).
On ARM, some device is used by Xen and therefore not exposed to dom0. By passthrough to dom0 I meant every device that are given to dom0, no matter if the platform has an IOMMU.
I think DOM0 should only be able to map theses devices to a guest. It seems stupid to allow dom0 mapping RAM or the UART used by Xen.
--
Julien Grall
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 10 lines · Eric Trudeau
Quoted 10 lines
Quoted 9 lines
Right. FTR,
xen/arch/x86/domain_build.c, has this (also inconstruct_dom0):/* DOM0 is permitted full I/O capabilities. */ rc |= ioports_permit_access(dom0, 0, 0xFFFF); rc |= iomem_permit_access(dom0, 0UL, ~0UL); rc |= irqs_permit_access(dom0, 1, nr_irqs_gsi - 1);Do you want a patch to that/similar effect?
Quoted 9 lines
Quoted 2 lines
Yes. Maybe a bit more smarter than permitting full I/0 caps for dom0.
Our implementation does not require Dom0 access permission in order for it to grant access permission to a DomU. I suppose it wouldn't hurt for
iomem_permit_accessbecause we allow iomem regions to be mapped into multiple domains; however, I think theirqs_permit_accesscall keeps multiple domains from "owning" the same IRQ. I might be wrong about that.
As far as I understood it, it is not required here either. And in fact, such permission is not there, and things works for Arianna too.
However, it seemed a sane check to have in place (e.g., the x86 implementation does check for that), that's why she's trying to introduce it properly. :-)
After all, as far as I remember, you do have something like this:
if ( current->domain->domain_id != 0 )
break;don't you?
Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 39 lines
-----Original Message-----
From: Dario Faggioli [mailto:[email protected]]
Sent: Monday, March 03, 2014 11:35 AM
To: Eric Trudeau
Cc: Julien Grall; Arianna Avanzini; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Ian Campbell; Tim Deegan
Subject: Re: [Xen-devel] [RFC PATCH 2/3] arch, arm32: add theXEN_DOMCTL_memory_mappinghypercallQuoted 10 lines · Eric Trudeau
Quoted 10 lines
Quoted 9 lines
Right. FTR,
xen/arch/x86/domain_build.c, has this (also inconstruct_dom0):/* DOM0 is permitted full I/O capabilities. */ rc |= ioports_permit_access(dom0, 0, 0xFFFF); rc |= iomem_permit_access(dom0, 0UL, ~0UL); rc |= irqs_permit_access(dom0, 1, nr_irqs_gsi - 1);Do you want a patch to that/similar effect?
Quoted 9 lines
Quoted 2 lines
Yes. Maybe a bit more smarter than permitting full I/0 caps for dom0.
Our implementation does not require Dom0 access permission in order for it to grant access permission to a DomU. I suppose it wouldn't hurt for
iomem_permit_accessbecause we allow iomem regions to be mapped into multiple domains; however, I think theirqs_permit_accesscall keeps multiple domains from "owning" the same IRQ. I might be wrong about that.As far as I understood it, it is not required here either. And in fact, such permission is not there, and things works for Arianna too.
However, it seemed a sane check to have in place (e.g., the x86 implementation does check for that), that's why she's trying to introduce it properly. :-)
Quoted 7 lines
After all, as far as I remember, you do have something like this:
if ( current->domain->domain_id != 0 ) break;don't you?
Yes, we only allow Domain 0 to perform the memory_mapping hypercall. As mentioned in one of the related threads to the patch, in embedded system implementations like ours, we are partitioning devices to various DomU's and Dom0 is really the control domain with a few shared devices. If it gets hacked we want to make it that much harder to get access to a device because it does not have access to it, although the hacker potentially would make the hypercall to get access, etc. We think of it in the same way that normally on Linux, you run without privileges and use sudo when you really want to get more control temporarily.
I checked the flow for when we route an IRQ to multiple domains and it does not check for more than one domain having permission to access the PIRQ, it checks whether another domain already has the IRQ routed to it. So, even with IRQs, it should not be a problem to have Dom0 have permission to all non-hypervisor IRQs.
Quoted 8 lines
Regards,
Dario--
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
In reply to Julien GrallQuoted 2 lines · Julien Grall
Hello Arianna,
Hello,
thank you all for your comments. I'm currently trying to address at my best the issues pointed out throughout the discussion. Also, sorry for the delay in replying.
Quoted 98 lines · Arianna Avanzini
Quoted 17 lines
This commit introduces a first attempt of implementation of the
XEN_DOMCTL_memory_mappinghypercall for arm32. The following warnings must be taken into consideration:
. currently, the hypercall simply performs an 1:1 mapping of I/O
memory ranges (mfn == gfn);
. the range of I/O memory addresses is mapped all at once with
map_mmio_regions();
. the hypercall takes for granted that any I/O memory range can
be mapped to a domU if the current domain is dom0.Signed-off-by Arianna Avanzini <[email protected]>Cc Dario Faggioli <[email protected]>Cc Paolo Valente <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Julien Grall <[email protected]>Cc Eric Trudeau <[email protected]>Cc Viktor Kleinik <[email protected]>Quoted 2 lines
--- xen/arch/arm/arm32/domctl.c | 74 +++++++++++++++++++++++++++++++++++++++++++++The implementation of
XEN_DOMCTL_memory_mappingis not ARM32 specific. It can be implemented inarch/arm/domctl.c.Quoted 40 lines
xen/arch/arm/p2m.c | 9 ++++++ xen/include/asm-arm/p2m.h | 2 ++ 3 files changed, 85 insertions(+)xen/arch/arm/arm32/domctl.c +16
-0@@ -10,8 +10,11 @@#include <xen/errno.h> #include <xen/sched.h> #include <xen/hypercall.h> +#include <xen/iocap.h> #include <public/domctl.h> +#include "cpu.h" +long subarch_do_domctl (struct xen_domctl *domctl,struct domain *d,XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl) {@@ -19,6 +22,77 @@ long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d, {case XEN_DOMCTL_set_address_size:return domctl->u.address_size.size ==32 ?0 : -EINVAL ; +case XEN_DOMCTL_memory_mapping: + { +unsigned long gfn = domctl->u.memory_mapping.first_gfn; +unsigned long mfn = domctl->u.memory_mapping.first_mfn; +unsigned long nr_mfns = domctl->u.memory_mapping.nr_mfns; +int add = domctl->u.memory_mapping.add_mapping; +long int ret; + + ret = -EINVAL ; +if ( (mfn + nr_mfns -1 ) < mfn ||/* wrap? */ + ((mfn | (mfn + nr_mfns -1 )) >> (paddr_bits -PAGE_SHIFT )) || + (gfn + nr_mfns -1 ) < gfn )/* wrap? */ +return ret;xen/arch/arm/ renamed from xen/arch/arm/arm32/domctl.c +1
-0+xen/arch/arm/
Quoted 10 lines
xen/arch/arm/ renamed from xen/arch/arm/arm32/domctl.c +10
-0+ ret = -EPERM; + /* + * NOTE: dom0 seems to have empty iomem_caps but to be however able to + * access I/O memory ranges. The following check takes for granted + * that any iomem range can be mapped to a domU if the current + * domain is dom0. + */ + if ( current->domain->domain_id != 0 && + !iomem_access_permitted(current->domain, mfn, mfn + nr_mfns - 1) ) + return ret;This check can be removed by adding in
construct_dom0(arch/arm/domain_build.c) something like that:
/* DOM0 is permitted full I/O capabilities */
rc =iomem_permit_access(d, 0UL, ~OUL);I'm wondering if we can even restrict dom0 I/0 access by only permit access on devices passthrough to it. Because dom0 should not be allowed to map I/O ranges which belong to device used by Xen e.g : GIC, RAM,...
I think we should at least restrict dom0 to use the hypercall for mapping device memory. Otherwise dom0 may be allowed to map Xen address range, do wrong thing with foreign mapping...
Quoted 10 lines
xen/arch/arm/ renamed from xen/arch/arm/arm32/domctl.c +10
-0+ + ret = xsm_iomem_mapping(XSM_HOOK, d, mfn, mfn + nr_mfns - 1, add); + if ( ret ) + return ret; + + if ( add ) + { + printk(XENLOG_G_INFO + "memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n", + d->domain_id, gfn, mfn, nr_mfns);
Quoted 9 lines
xen/arch/arm/
Quoted 5 lines
xen/arch/arm/ renamed from xen/arch/arm/arm32/domctl.c +5
-0+ ret = iomem_permit_access(d, mfn, mfn + nr_mfns - 1); + if ( !ret ) + { + /* 1:1 iomem mapping (gfn == mfn) */ + ret = map_mmio_regions(d, gfn, gfn + nr_mfns - 1, mfn);The comment "1:1 iomem mapping (gfn == mfn)" seems wrong here. The implementation you wrote allow gfn != mfn.
Right, thank you.
Sorry if I bother you with one more question about this hunk; aside from the error pointed out by Eric with the usage of pfn instead of paddr_t, is it OK to map the address range all at once with map_mmio_regions() as proposed? I noticed that the x86-related code seems to map the range one mfn at a time with set_mmio_p2m_entry(), and I wonder if this different approach has any benefit I didn't think about.
Quoted 2 lines
Regards,
Signature · 5 lines
/* * Arianna Avanzini * [email protected] * [email protected] */
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 1 line · Arianna Avanzini
Hello,
Hello Arianna,
Quoted 11 lines
Quoted 3 lines
The comment "1:1 iomem mapping (gfn == mfn)" seems wrong here. The implementation you wrote allow gfn != mfn.
Right, thank you.
Sorry if I bother you with one more question about this hunk; aside from the error pointed out by Eric with the usage of pfn instead ofpaddr_t, is it OK to map the address range all at once withmap_mmio_regions()as proposed? I noticed that the x86-related code seems to map the range one mfn at a time withset_mmio_p2m_entry(), and I wonder if this different approach has any benefit I didn't think about.
map_mmio_regions will take p2m lock and do MMU management (e.g TLB flush...). For the latter the code has been written to only do TLB flush, if needed, once per call. More the range is large, better it is.
So, it's better to call the function only once for the whole range.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 19 lines · Julien Grall
Quoted 1 line · Arianna Avanzini
Hello,
Hello Arianna,
Quoted 11 lines
Quoted 3 lines
The comment "1:1 iomem mapping (gfn == mfn)" seems wrong here. The implementation you wrote allow gfn != mfn.
Right, thank you.
Sorry if I bother you with one more question about this hunk; aside from the error pointed out by Eric with the usage of pfn instead ofpaddr_t, is it OK to map the address range all at once withmap_mmio_regions()as proposed? I noticed that the x86-related code seems to map the range one mfn at a time withset_mmio_p2m_entry(), and I wonder if this different approach has any benefit I didn't think about.
Quoted 6 lines
map_mmio_regionswill take p2m lock and do MMU management (e.g TLB flush...). For the latter the code has been written to only do TLB flush, if needed, once per call. More the range is large, better it is.So, it's better to call the function only once for the whole range.
OK, thank you for the clear explanation.
Quoted 2 lines
Regards,
Signature · 5 lines
/* * Arianna Avanzini * [email protected] * [email protected] */
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
In reply to Arianna AvanziniQuoted 85 lines
-----Original Message-----
From: Arianna Avanzini [mailto:[email protected]]
Sent: Saturday, March 01, 2014 7:49 PM
To: [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Eric Trudeau; [email protected]
Subject: [RFC PATCH 2/3] arch, arm32: add theXEN_DOMCTL_memory_mappinghypercallThis commit introduces a first attempt of implementation of the
XEN_DOMCTL_memory_mappinghypercall for arm32. The following warnings must be taken into consideration:
. currently, the hypercall simply performs an 1:1 mapping of I/O
memory ranges (mfn == gfn);
. the range of I/O memory addresses is mapped all at once with
map_mmio_regions();
. the hypercall takes for granted that any I/O memory range can
be mapped to a domU if the current domain is dom0.Signed-off-by Arianna Avanzini <[email protected]>Cc Dario Faggioli <[email protected]>Cc Paolo Valente <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Julien Grall <[email protected]>Cc Eric Trudeau <[email protected]>Cc Viktor Kleinik <[email protected]>--- xen/arch/arm/arm32/domctl.c | 74 +++++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/p2m.c | 9 ++++++ xen/include/asm-arm/p2m.h | 2 ++ 3 files changed, 85 insertions(+)xen/arch/arm/arm32/domctl.c +20
-0@@ -10,8 +10,11 @@#include <xen/errno.h> #include <xen/sched.h> #include <xen/hypercall.h> +#include <xen/iocap.h> #include <public/domctl.h> +#include "cpu.h" +long subarch_do_domctl (struct xen_domctl *domctl,struct domain *d,XEN_GUEST_HANDLE_PARAM (xen_domctl_t) u_domctl) {@@ -19,6 +22,77 @@ long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d, {case XEN_DOMCTL_set_address_size:return domctl->u.address_size.size ==32 ?0 : -EINVAL ; +case XEN_DOMCTL_memory_mapping: + { +unsigned long gfn = domctl->u.memory_mapping.first_gfn; +unsigned long mfn = domctl->u.memory_mapping.first_mfn; +unsigned long nr_mfns = domctl->u.memory_mapping.nr_mfns; +int add = domctl->u.memory_mapping.add_mapping; +long int ret; + + ret = -EINVAL ; +if ( (mfn + nr_mfns -1 ) < mfn ||/* wrap? */ + ((mfn | (mfn + nr_mfns -1 )) >> (paddr_bits -PAGE_SHIFT )) || + (gfn + nr_mfns -1 ) < gfn )/* wrap? */ +return ret; + + ret = -EPERM ; +/* +* NOTE: dom0 seems to have empty iomem_caps but to be however able to
xen/arch/arm/arm32/domctl.c +12
-0+* access I/O memory ranges. The following check takes for granted +* that any iomem range can be mapped to a domU if the current +* domain is dom0. +*/ +if ( current->domain->domain_id !=0 && + !iomem_access_permitted (current->domain, mfn, mfn + nr_mfns -1 ) ) +return ret; + + ret =xsm_iomem_mapping (XSM_HOOK , d, mfn, mfn + nr_mfns -1 , add); +if ( ret ) +return ret; +
xen/arch/arm/arm32/domctl.c long subarch_do_domctl(struct xen_domctl *domctl, struct domain *d, · line 63
Quoted 10 lines
xen/arch/arm/arm32/domctl.c +10
-0+if ( add ) + { +printk (XENLOG_G_INFO +"memory_map:add: dom%d gfn=%lx mfn=%lx nr=%lx\n" , + d->domain_id, gfn, mfn, nr_mfns); + ret =iomem_permit_access (d, mfn, mfn + nr_mfns -1 ); +if ( !ret ) + { +/* 1:1 iomem mapping (gfn == mfn) */ + ret =map_mmio_regions (d, gfn, gfn + nr_mfns -1 , mfn);
Last I checked, map_mmio_regions takes paddr_t, not frame numbers.
Beware: I found that map_mmio_regions was off by one page unless I changed "gfn + nr_mfns - 1" to "gfn + nr_mfns".
This may have been fixed in more recent upstream code.
Quoted 71 lines
xen/arch/arm/arm32/domctl.c +32
-0+if ( ret ) + { +printk (XENLOG_G_WARNING +"memory_map:fail: dom%d gfn=%lx mfn=%lx\n" , + d->domain_id, gfn, mfn); +if (iomem_deny_access (d, mfn, mfn + nr_mfns -1 ) && +is_hardware_domain (current->domain) ) +printk (XENLOG_ERR +"memory_map: failed to deny dom%d access " +"to [%lx,%lx]\n" , + d->domain_id, mfn, mfn + nr_mfns -1 ); + } + } + } +else + { +printk (XENLOG_G_INFO +"memory_map:remove: dom%d gfn=%lx mfn=%lx nr=%lx\n" , + d->domain_id, gfn, mfn, nr_mfns); + + add =unmap_mmio_regions (d, gfn, gfn + nr_mfns -1 , mfn); + ret =iomem_deny_access (d, mfn, mfn + nr_mfns -1 ); +if ( ret && add ) + ret = -EIO ; +if ( ret &&is_hardware_domain (current->domain) ) +printk (XENLOG_ERR +"memory_map: error %ld %s dom%d access to [%lx,%lx]\n" , + ret, add ?"removing" :"denying" , d->domain_id, + mfn, mfn + nr_mfns -1 ); + } +return ret; + }default :return -ENOSYS ; }xen/arch/arm/p2m.c +9
-0@@ -461,6 +461,15 @@ int map_mmio_regions(struct domain *d, maddr, MATTR_DEV, p2m_mmio_direct); } +int unmap_mmio_regions (struct domain *d, +paddr_t start_gaddr, +paddr_t end_gaddr, +paddr_t maddr) +{ +return apply_p2m_changes (d,REMOVE , start_gaddr, end_gaddr, + maddr,MATTR_DEV , p2m_mmio_direct); +} + int guest_physmap_add_entry(struct domain *d, unsigned long gpfn, unsigned long mfn,xen/include/asm-arm/p2m.h +2
-0@@ -88,6 +88,8 @@ int p2m_populate_ram(struct domain *d, paddr_t start,paddr_t end); * address maddr. */ int map_mmio_regions (struct domain *d,paddr_t start_gaddr,paddr_t end_gaddr,paddr_t maddr); +int unmap_mmio_regions (struct domain *d,paddr_t start_gaddr, +paddr_t end_gaddr,paddr_t maddr); int guest_physmap_add_entry(struct domain *d,unsigned long gfn,
--
1.8.5.3
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Hello Eric,
Quoted 1 line · Eric Trudeau
Last I checked,
map_mmio_regionstakespaddr_t, not frame numbers.
Right.
Quoted 3 lines
Beware: I found that
map_mmio_regionswas off by one page unless I changed "gfn +nr_mfns- 1" to "gfn +nr_mfns".
This may have been fixed in more recent upstream code.
That makes me think, map_mmio_regions is buggy if the range is not correctly aligned. For instance:
start_gaddr = 0x1001 and end_gaddr = 0x2001, we only map 0x1000-0x2000 to the domain.
The problem is the same with p2m_populate_ram (even if I doubt that RAM range is not page-aligned).
I see 2 solutions to fix it:
- Change map_mmio_regions prototype to use frame is instead address.
- Aligned the input addresses.
IHMO, the former seems to be better, at least it avoid developer to discover that some bits was mapped under his feet.
Ian, do you have any opinion?
Regards,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 7 lines · Julien Grall
Hello Eric,
Quoted 1 line · Eric Trudeau
Last I checked,
map_mmio_regionstakespaddr_t, not frame numbers.Right.
Thank you both, I have tried to fix by using the correct conversion macro.
Quoted 13 lines
Quoted 3 lines
Beware: I found that
map_mmio_regionswas off by one page unless I changed "gfn +nr_mfns- 1" to "gfn +nr_mfns".
This may have been fixed in more recent upstream code.That makes me think,
map_mmio_regionsis buggy if the range is not correctly aligned. For instance:
start_gaddr=0x1001andend_gaddr=0x2001, we only map 0x1000-0x2000 to the domain.The problem is the same with
p2m_populate_ram(even if I doubt that RAM range is not page-aligned).
Quoted 7 lines
I see 2 solutions to fix it:
- Changemap_mmio_regionsprototype to use frame is instead address.
- Aligned the input addresses.IHMO, the former seems to be better, at least it avoid developer to discover that some bits was mapped under his feet.
Sorry if I intrude here, thank you for pointing that out. As of now I have tried to simply pass aligned addresses to map_mmio_regions() when it is invoked by the memory_mapping hypercall.
Sorry for the additional question, do you think that it would be appropriate to add to the series a patch implementing one of the above-described solutions (the one believed to be better)?
Quoted 4 lines
Ian, do you have any opinion?
Regards,
Signature · 5 lines
/* * Arianna Avanzini * [email protected] * [email protected] */
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Hello Arianna,
Quoted 17 lines · Arianna Avanzini
Quoted 17 lines
Quoted 3 lines
Beware: I found that
map_mmio_regionswas off by one page unless I changed "gfn +nr_mfns- 1" to "gfn +nr_mfns".
This may have been fixed in more recent upstream code.That makes me think,
map_mmio_regionsis buggy if the range is not correctly aligned. For instance:
start_gaddr=0x1001andend_gaddr=0x2001, we only map 0x1000-0x2000 to the domain.The problem is the same with
p2m_populate_ram(even if I doubt that RAM range is not page-aligned).I see 2 solutions to fix it:
- Changemap_mmio_regionsprototype to use frame is instead address.
- Aligned the input addresses.
Quoted 7 lines
Quoted 3 lines
IHMO, the former seems to be better, at least it avoid developer to discover that some bits was mapped under his feet.
Sorry if I intrude here, thank you for pointing that out. As of now I have tried to simply pass aligned addresses to
map_mmio_regions()when it is invoked by thememory_mappinghypercall.
FYI, the end address should be PAGE-aligned minus 1. Otherwise you will map a spurious page to the guest.
Quoted 3 lines
Sorry for the additional question, do you think that it would be appropriate to add to the series a patch implementing one of the above-described solutions (the one believed to be better)?
I'd like to have some input from Ian before. I think for now it's fine to stay with the current implementation.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 2/3] arch, arm32: add the XEN_DOMCTL_memory_mapping hypercall
Quoted 25 lines · Julien Grall
Hello Arianna,
Quoted 21 lines · Arianna Avanzini
Quoted 20 lines
Quoted 3 lines
Beware: I found that
map_mmio_regionswas off by one page unless I changed "gfn +nr_mfns- 1" to "gfn +nr_mfns".
This may have been fixed in more recent upstream code.That makes me think,
map_mmio_regionsis buggy if the range is not correctly aligned. For instance:
start_gaddr=0x1001andend_gaddr=0x2001, we only map 0x1000-0x2000 to the domain.The problem is the same with
p2m_populate_ram(even if I doubt that RAM range is not page-aligned).I see 2 solutions to fix it:
- Changemap_mmio_regionsprototype to use frame is instead address.
- Aligned the input addresses.IHMO, the former seems to be better, at least it avoid developer to discover that some bits was mapped under his feet.
Quoted 7 lines
Quoted 3 lines
Sorry if I intrude here, thank you for pointing that out. As of now I have tried to simply pass aligned addresses to
map_mmio_regions()when it is invoked by thememory_mappinghypercall.FYI, the end address should be PAGE-aligned minus 1. Otherwise you will map a spurious page to the guest.
Thank you for pointing that out.
Quoted 7 lines
Quoted 3 lines
Sorry for the additional question, do you think that it would be appropriate to add to the series a patch implementing one of the above-described solutions (the one believed to be better)?
I'd like to have some input from Ian before. I think for now it's fine to stay with the current implementation.
OK. Thank you for making this clear.
Quoted 2 lines
Regards,
Signature · 5 lines
/* * Arianna Avanzini * [email protected] * [email protected] */
RFC PATCH 3/3 tools, libxl: handle the iomem parameter with the memory_mapping hcall
In reply to Arianna AvanziniCurrently, the configuration-parsing code concerning the handling of the iomem parameter only invokes the XEN_DOMCTL_iomem_permission hypercall. This commit lets the XEN_DOMCTL_memory_mapping hypercall be invoked after XEN_DOMCTL_iomem_permission when the iomem parameter is parsed from a domU configuration file.
--- tools/libxl/libxl_create.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
tools/libxl/libxl_create.c +10 -0
@@ -1099,6 +1099,16 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,"failed give dom%d access to iomem range %" PRIx64"-%" PRIx64, domid, io->start, io->start + io->number - 1); ret =ERROR_FAIL ; + }else { + ret =xc_domain_memory_mapping (CTX ->xch, domid, + io->start, io->start, + io->number,1 ); +if (ret <0 ) { +LOGE (ERROR , +"failed to map to dom%d iomem range %" PRIx64"-%" PRIx64, + domid, io->start, io->start + io->number -1 ); + ret =ERROR_FAIL ; + } } }
Signature · 1 line
1.8.5.3
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
Hello Arianna,
Adding Ian Jackson, maintainer of libxl.
Quoted 5 lines · Arianna Avanzini
Currently, the configuration-parsing code concerning the handling of the iomem parameter only invokes the
XEN_DOMCTL_iomem_permissionhypercall. This commit lets theXEN_DOMCTL_memory_mappinghypercall be invoked afterXEN_DOMCTL_iomem_permissionwhen the iomem parameter is parsed from a domU configuration file.
Do you plan to give I/O mem range which is not describe by the device tree?
IHMO, allow the user to specify which I/O mem region will be mapped to the guest on ARM is wrong. As the platform is described via the device tree, the guest configuration should have a list of node to map to domU. Then {lib,}xl will parse/map/update the DT node to the guest.
Quoted 19 lines
Signed-off-by Arianna Avanzini <[email protected]>Cc Dario Faggioli <[email protected]>Cc Paolo Valente <[email protected]>Cc Stefano Stabellini <[email protected]>Cc Julien Grall <[email protected]>Cc Eric Trudeau <[email protected]>Cc Viktor Kleinik <[email protected]>--- tools/libxl/libxl_create.c | 10 ++++++++++ 1 file changed, 10 insertions(+)tools/libxl/libxl_create.c +0
-0@@ -1099,6 +1099,16 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,"failed give dom%d access to iomem range %" PRIx64"-%" PRIx64, domid, io->start, io->start + io->number - 1); ret =ERROR_FAIL ;
tools/libxl/libxl_create.c static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev, · line 1111
Quoted 10 lines
tools/libxl/libxl_create.c +10
-0+ }else { + ret =xc_domain_memory_mapping (CTX ->xch, domid, + io->start, io->start, + io->number,1 ); +if (ret <0 ) { +LOGE (ERROR , +"failed to map to dom%d iomem range %" PRIx64"-%" PRIx64, + domid, io->start, io->start + io->number -1 ); + ret =ERROR_FAIL ; + }
This code is common on both x86 and ARM. On x86, we don't want to map the I/O mem region in the guest here. QEMU will do it later.
The 1:1 mapping doesn't seem correct because the range could clash with the guest layout (e.g: GIC base address, RAM base address) which is for now hardcoded (see xen/include/public/arch-arm.h:358).
I have various solution to fix this issue:
- Relocate the GIC/RAM base address and notify Xen that the GIC base
address has changed. So we can keep the 1:1 mapping.
- Let libxl decide where to map the I/O mem range in the guest.
For the latter solution, we will have to find a way to tell to the guest : "This I/O mem range is here ...". Perhaps via the device tree.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
Quoted 11 lines · Julien Grall
Hello Arianna,
Adding Ian Jackson, maintainer of libxl.
Quoted 5 lines · Arianna Avanzini
Currently, the configuration-parsing code concerning the handling of the iomem parameter only invokes the
XEN_DOMCTL_iomem_permissionhypercall. This commit lets theXEN_DOMCTL_memory_mappinghypercall be invoked afterXEN_DOMCTL_iomem_permissionwhen the iomem parameter is parsed from a domU configuration file.
Quoted 6 lines
Do you plan to give I/O mem range which is not describe by the device tree?
IHMO, allow the user to specify which I/O mem region will be mapped to the guest on ARM is wrong. As the platform is described via the device tree, the guest configuration should have a list of node to map to domU. Then {lib,}xl will parse/map/update the DT node to the guest.
I think there is room for both models. People just doing basic device pass-through will probably want a "user friendly" DT based option, but others might want to use a lower level raw interface, just like on x86 where we provide both the low level iomem/ioport/irq interface and the pci passthrough syntax.
If they want to hard code an address in both their cfg file and their guest kernel then that is up to them, they get to keep both pieces when we changes things of course.
Quoted 8 lines
The 1:1 mapping doesn't seem correct because the range could clash with the guest layout (e.g: GIC base address, RAM base address) which is for now hardcoded (see
xen/include/public/arch-arm.h:358).I have various solution to fix this issue:
- Relocate the GIC/RAM base address and notify Xen that the GIC base
address has changed. So we can keep the 1:1 mapping.
- Let libxl decide where to map the I/O mem range in the guest.
We might need some sort of ARM equivalent to the x86 "e820_host" option -- which makes the guest address space look like the hosts (similar to what we do for dom0 on ARM).
Quoted 5 lines
For the latter solution, we will have to find a way to tell to the guest : "This I/O mem range is here ...". Perhaps via the device tree.
Regards,
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Julien Grall
Do you plan to give I/O mem range which is not describe by the device tree?
IHMO, allow the user to specify which I/O mem region will be mapped to the guest on ARM is wrong. As the platform is described via the device tree, the guest configuration should have a list of node to map to domU. Then {lib,}xl will parse/map/update the DT node to the guest.
Quoted 6 lines
I think there is room for both models. People just doing basic device pass-through will probably want a "user friendly" DT based option, but others might want to use a lower level raw interface, just like on x86 where we provide both the low level iomem/ioport/irq interface and the pci passthrough syntax.
That indeed is the case. The automotive OS Arianna is porting on Xen on ARM doesn't know anything about device trees. Actually, a DT parser would probably be more code than the OS itself! :-P
AFAIUI, that's Eric's case too. In fact this is, I think, quite common in small/embedded OSes, and it would be a good thing for Xen to allow them to work as guests, without necessarily requiring them to go for DT (of course, the cost of keeping things consistent is on them!).
Quoted 4 lines
If they want to hard code an address in both their cfg file and their guest kernel then that is up to them, they get to keep both pieces when we changes things of course.
Right. So, just to make sure I understand it correctly, you're saying that it is fine to have the hypercall implemented and called sort of like how Arianna is doing it, modulo moving the call outside of common ARM and x86 code, as Julien pointed out, is this correct? If yes, I (FWIW) totally concur. :-)
For the sake of this series, do you think there is something that Arianna should do, if not to ensure 100% consistency (which is not Xen's job, in this case) but, perhaps, just to put things on the safe side?
Quoted 4 lines
We might need some sort of ARM equivalent to the x86 "
e820_host" option -- which makes the guest address space look like the hosts (similar to what we do for dom0 on ARM).
Right. Again, and sorry for not getting it just from the above, do you think this is something Arianna should take care of, when reposting the series, or can/should it be done also later?
Thanks and Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
Quoted 5 lines · Dario Faggioli
Right. So, just to make sure I understand it correctly, you're saying that it is fine to have the hypercall implemented and called sort of like how Arianna is doing it, modulo moving the call outside of common ARM and x86 code, as Julien pointed out, is this correct? If yes, I (FWIW) totally concur. :-)
I think in both solution, this hypercall should be implemented :).
Quoted 7 lines
For the sake of this series, do you think there is something that Arianna should do, if not to ensure 100% consistency (which is not Xen's job, in this case) but, perhaps, just to put things on the safe side?
Right. Again, and sorry for not getting it just from the above, do you think this is something Arianna should take care of, when reposting the series, or can/should it be done also later?
I think Arianna solution's might not work if the 1:1 mapping clash with existing layout. I might help Arianna on this subject because it will be useful to passthrough a device to the guest.
Signature · 1 line
Julien Grall
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
Quoted 15 lines · Julien Grall
Quoted 5 lines · Dario Faggioli
Right. So, just to make sure I understand it correctly, you're saying that it is fine to have the hypercall implemented and called sort of like how Arianna is doing it, modulo moving the call outside of common ARM and x86 code, as Julien pointed out, is this correct? If yes, I (FWIW) totally concur. :-)
I think in both solution, this hypercall should be implemented :).
Quoted 4 lines
For the sake of this series, do you think there is something that Arianna should do, if not to ensure 100% consistency (which is not Xen's job, in this case) but, perhaps, just to put things on the safe side?
Quoted 8 lines
Quoted 3 lines
Right. Again, and sorry for not getting it just from the above, do you think this is something Arianna should take care of, when reposting the series, or can/should it be done also later?
I think Arianna solution's might not work if the 1:1 mapping clash with existing layout. I might help Arianna on this subject because it will be useful to passthrough a device to the guest.
Sorry for the delay and for bothering you with another question. In order to ensure that the 1:1 mapping of a new range of I/O memory does not clash with the existing layout, we should then check that nothing else has been mapped to that address range in the domU's address space?
Again, sorry for the probably obvious question.
Signature · 5 lines
/* * Arianna Avanzini * [email protected] * [email protected] */
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
Hello Arianna,
Quoted 10 lines · Arianna Avanzini
Quoted 5 lines
I think Arianna solution's might not work if the 1:1 mapping clash with existing layout. I might help Arianna on this subject because it will be useful to passthrough a device to the guest.
Sorry for the delay and for bothering you with another question. In order to ensure that the 1:1 mapping of a new range of I/O memory does not clash with the existing layout, we should then check that nothing else has been mapped to that address range in the domU's address space?
I think checking is not the right solution, what will you do if the range is effectively clash to another one?
On a previous mail (see http://lists.xenproject.org/archives/html/xen-devel/2014-03/msg00036.html), Ian has proposed to exposed the layout of the host to the guest. That will allow you to map the memory in 1:1.
I will need this item for device passthrough soon. I can take care of this item if you want.
Regards,
Signature · 1 line
Julien Grall
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
Quoted 9 lines · Julien Grall
Hello Arianna,
Quoted 6 lines · Arianna Avanzini
Quoted 5 lines
I think Arianna solution's might not work if the 1:1 mapping clash with existing layout. I might help Arianna on this subject because it will be useful to passthrough a device to the guest.
Quoted 8 lines
Quoted 4 lines
Sorry for the delay and for bothering you with another question. In order to ensure that the 1:1 mapping of a new range of I/O memory does not clash with the existing layout, we should then check that nothing else has been mapped to that address range in the domU's address space?
I think checking is not the right solution, what will you do if the range is effectively clash to another one?
Right, sorry.
Quoted 8 lines
On a previous mail (see
http://lists.xenproject.org/archives/html/xen-devel/2014-03/msg00036.html), Ian has proposed to exposed the layout of the host to the guest. That will allow you to map the memory in 1:1.I will need this item for device passthrough soon. I can take care of this item if you want.
OK, thank you again for replying and making this clear.
Quoted 2 lines
Regards,
Signature · 5 lines
/* * Arianna Avanzini * [email protected] * [email protected] */
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
In reply to Julien GrallQuoted 13 lines · Julien Grall
Quoted 13 lines
tools/libxl/libxl_create.c +5
-0@@ -1099,6 +1099,16 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev,"failed give dom%d access to iomem range %" PRIx64"-%" PRIx64, domid, io->start, io->start + io->number - 1); ret =ERROR_FAIL ; + }else { + ret =xc_domain_memory_mapping (CTX ->xch, domid, + io->start, io->start, + io->number,1 ); +if (ret <0 ) {
Quoted 9 lines
tools/libxl/libxl_create.c static void domcreate_launch_dm(libxl__egc *egc, libxl__multidev *multidev, · line 1111
Quoted 5 lines
tools/libxl/libxl_create.c +5
-0+LOGE (ERROR , +"failed to map to dom%d iomem range %" PRIx64"-%" PRIx64, + domid, io->start, io->start + io->number -1 ); + ret =ERROR_FAIL ; + }This code is common on both x86 and ARM. On x86, we don't want to map the I/O mem region in the guest here. QEMU will do it later.
Right. I took a quick look and, as you're saying, I found the call sites of xc_domain_memory_mapping() in QEMU's code (in _pt_iomem_helper() ). At the same time, I see QEMU being created as a device model in this same function, below this hunk... But that does _not_ _always_ happen, I think, does it?
In particular, what about PV guests for which libxl__need_xenpv_qemu() returns 0? Who calls xc_domain_memory_mapping() on the specified iomem region(s) for them?
I'm asking because libxl__need_xenpv_qemu() does not look like it's considering num_iomem / num_irqs at all and, although I know ARM guests are not 'full PV', we don't have QEMU there (yet) either... so I think it's a similar situation.
Sorry if I'm missing something obvious, I'm not super familiar with this code, and I guess Arianna can just try investigate this a bit further, but if someone has any ideas... :-P
Thanks and Regards,
Dario
Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: [RFC PATCH 3/3] tools, libxl: handle the iomem parameter with the memory_mapping hcall
Quoted 9 lines · Dario Faggioli
Quoted 3 lines
This code is common on both x86 and ARM. On x86, we don't want to map the I/O mem region in the guest here. QEMU will do it later.
Right. I took a quick look and, as you're saying, I found the call sites of
xc_domain_memory_mapping()in QEMU's code (in_pt_iomem_helper()). At the same time, I see QEMU being created as a device model in this same function, below this hunk... But that does _not_ _always_ happen, I think, does it?
Quoted 3 lines
In particular, what about PV guests for which
libxl__need_xenpv_qemu()returns 0? Who callsxc_domain_memory_mapping()on the specified iomem region(s) for them?
Only the PV guest knows its memory layout. I guess xc_domain_memory_mapping is called by itself.
Adding Tim and Jan that might be able to answer to this question.
Signature · 1 line
Julien Grall
Quoted 1 line · Arianna Avanzini
Hello,
Hello Arianna,
Quoted 2 lines
this patchset adds a first attempt of implementation of the
XEN_DOMCTL_memory_mappinghypercall for the arm32 architecture.
Thanks for this patch series. I have added Ian Campbell and Tim Deegan, they are the maintainers of the ARM port.
Quoted 2 lines
Any feedback about the patches is more than welcome. The code has been tested with Linux v3.13 as dom0 and ERIKA Enterprise as domU.
See my answers on the different patch for feedbacks.
Regards,
Signature · 1 line
Julien Grall