From mboxrd@z Thu Jan 1 00:00:00 1970 From: Viktor Kleinik Subject: Re: ARM: access to iomem and HW IRQ Date: Thu, 27 Feb 2014 17:11:41 +0000 Message-ID: References: <1393496069.3921.14.camel@Solace> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6125966010409888447==" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Eric Trudeau Cc: Julien Grall , Dario Faggioli , "xen-devel@lists.xen.org" , Arianna Avanzini , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org --===============6125966010409888447== Content-Type: multipart/alternative; boundary=f46d041825ea3e27bf04f3666a14 --f46d041825ea3e27bf04f3666a14 Content-Type: text/plain; charset=ISO-8859-1 Thank you all for your responses. I will try those changes on our platform. Are you planning push the implementation of xc_domain_memory_mapping/XEN_DOMCTL_memory_mapping and xc_physdev_map_pirq/PHYSDEVOP_map_pirq hypercalls into official Xen release? Regards, Victor On Thu, Feb 27, 2014 at 2:11 PM, Eric Trudeau wrote: > > -----Original Message----- > > From: Stefano Stabellini [mailto:stefano.stabellini@eu.citrix.com] > > Sent: Thursday, February 27, 2014 8:16 AM > > To: Dario Faggioli > > Cc: Viktor Kleinik; xen-devel@lists.xen.org; Arianna Avanzini; Stefano > Stabellini; > > Julien Grall; Eric Trudeau > > Subject: Re: [Xen-devel] ARM: access to iomem and HW IRQ > > > > On Thu, 27 Feb 2014, Dario Faggioli wrote: > > > On mer, 2014-02-26 at 15:43 +0000, Viktor Kleinik wrote: > > > > Hi all, > > > > > > > Hi, > > > > > > > Does anyone knows something about future plans to implement > > > > xc_domain_memory_mapping/XEN_DOMCTL_memory_mapping and > > > > xc_physdev_map_pirq/PHYSDEVOP_map_pirq calls for ARM? > > > > > > > I think Arianna is working on an implementation of the former > > > (XEN_DOMCTL_memory_mapping), and she should be sending patches to this > > > list soon, isn't it so, Arianna? > > > > Eric Trudeau did some work in the area too: > > > > http://marc.info/?l=xen-devel&m=137338996422503 > > http://marc.info/?l=xen-devel&m=137365750318936 > > I checked our repo and the route IRQ changes to DomUs in the second patch > URL Stefano provided below are up-to-date with what we have been using on > our platforms. We made no further changes after that patch, i.e. we left > the 100 msec max wait for a domain to finish an ISR when destroying it. > > We also added support for a DomU to map in I/O memory with the iomem > configuration parameter. Unfortunately, I don't have time to provide an > official patch on recent Xen upstream code due to time constraints, but > below is a patch based on last October, :( , commit > d70d87d2ccf93e3d5302bb034c0a1ae1d6fc1d29. > I hope this is helpful, because that is the best I can do at this time. > > ----------------- > > tools/libxl/libxl_create.c | 5 +++-- > xen/arch/arm/domctl.c | 74 > +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- > 2 files changed, 76 insertions(+), 3 deletions(-) > > diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c > index 1b320d3..53ed52e 100644 > --- a/tools/libxl/libxl_create.c > +++ b/tools/libxl/libxl_create.c > @@ -976,8 +976,9 @@ static void domcreate_launch_dm(libxl__egc *egc, > libxl__multidev *multidev, > LOG(DEBUG, "dom%d iomem %"PRIx64"-%"PRIx64, > domid, io->start, io->start + io->number - 1); > > - ret = xc_domain_iomem_permission(CTX->xch, domid, > - io->start, io->number, 1); > + ret = xc_domain_memory_mapping(CTX->xch, domid, > + io->start, io->start, > + io->number, 1); > if (ret < 0) { > LOGE(ERROR, > "failed give dom%d access to iomem range > %"PRIx64"-%"PRIx64, > diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c > index 851ee40..222aac9 100644 > --- a/xen/arch/arm/domctl.c > +++ b/xen/arch/arm/domctl.c > @@ -10,11 +10,83 @@ > #include > #include > #include > +#include > +#include > +#include > +#include > > long arch_do_domctl(struct xen_domctl *domctl, struct domain *d, > XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl) > { > - return -ENOSYS; > + long ret = 0; > + bool_t copyback = 0; > + > + switch ( domctl->cmd ) > + { > + 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; > + > + /* removing i/o memory is not implemented yet */ > + if (!add) { > + ret = -ENOSYS; > + break; > + } > + ret = -EINVAL; > + if ( (mfn + nr_mfns - 1) < mfn || /* wrap? */ > + /* x86 checks wrap based on paddr_bits which is not > implemented on ARM? */ > + /* ((mfn | (mfn + nr_mfns - 1)) >> (paddr_bits - > PAGE_SHIFT)) || */ > + (gfn + nr_mfns - 1) < gfn ) /* wrap? */ > + break; > + > + ret = -EPERM; > + if ( current->domain->domain_id != 0 ) > + break; > + > + ret = xsm_iomem_mapping(XSM_HOOK, d, mfn, mfn + nr_mfns - 1, add); > + if ( ret ) > + break; > + > + 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 && paging_mode_translate(d) ) > + { > + ret = map_mmio_regions(d, gfn << PAGE_SHIFT, > + (gfn + nr_mfns) << PAGE_SHIFT, > + mfn << PAGE_SHIFT); > + if ( ret ) > + { > + printk(XENLOG_G_WARNING > + "memory_map:fail: dom%d gfn=%lx mfn=%lx > nr=%lx\n", > + d->domain_id, gfn, mfn, nr_mfns); > + 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); > + } > + } > + } > + } > + break; > + > + default: > + ret = -ENOSYS; > + break; > + } > + > + if ( copyback && __copy_to_guest(u_domctl, domctl, 1) ) > + ret = -EFAULT; > + > + return ret; > } > > void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c) > --f46d041825ea3e27bf04f3666a14 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thank you all for your responses.

<= div>I will try those changes on our platform.
Are you plannin= g push the implementation of
xc_domain_memory_mapping/XEN_DOMCTL_memory= _mapping and
xc_physdev_map_pirq/PHYSDEVOP_map_pirq hypercalls into
offic= ial Xen release?

Regards,
Victor
<= div class=3D"gmail_extra">

On Thu, Feb 27= , 2014 at 2:11 PM, Eric Trudeau <etrudeau@broadcom.com> = wrote:
> -----Original Message-----
> From: Stefano Stabellini [mailto:stefano.stabellini@eu.citrix.com]
> Sent: Thursday, February 27, 2014 8:16 AM
> To: Dario Faggioli
> Cc: Viktor Kleinik; xen-dev= el@lists.xen.org; Arianna Avanzini; Stefano Stabellini;
> Julien Grall; Eric Trudeau
> Subject: Re: [Xen-devel] ARM: access to iomem and HW IRQ
>
> On Thu, 27 Feb 2014, Dario Faggioli wrote:
> > On mer, 2014-02-26 at 15:43 +0000, Viktor Kleinik wrote:
> > > Hi all,
> > >
> > Hi,
> >
> > > Does anyone knows something about future plans to implement<= br> > > > xc_domain_memory_mapping/XEN_DOMCTL_memory_mapping and
> > > xc_physdev_map_pirq/PHYSDEVOP_map_pirq calls for ARM?
> > >
> > I think Arianna is working on an implementation of the former
> > (XEN_DOMCTL_memory_mapping), and she should be sending patches to= this
> > list soon, isn't it so, Arianna?
>
> Eric Trudeau did some work in the area too:
>
> http://marc.info/?l=3Dxen-devel&m=3D137338996422503=
> http://marc.info/?l=3Dxen-devel&m=3D137365750318936=

I checked our repo and the route IRQ changes to DomUs in the se= cond patch URL Stefano provided below are up-to-date with what we have been= using on our platforms. =A0We made no further changes after that patch, i.= e. we left the 100 msec max wait for a domain to finish an ISR when destroy= ing it.

We also added support for a DomU to map in I/O memory with the iomem config= uration parameter. =A0Unfortunately, I don't have time to provide an of= ficial patch on recent Xen upstream code due to time constraints, but below= is a patch based on last October, :( , commit d70d87d2ccf93e3d5302bb034c0a= 1ae1d6fc1d29.
I hope this is helpful, because that is the best I can do at this time.

-----------------

tools/libxl/libxl_create.c | =A05 +++--
=A0xen/arch/arm/domctl.c =A0 =A0 =A0| 74 ++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++++++++++++-
=A02 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index 1b320d3..53ed52e 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -976,8 +976,9 @@ static void domcreate_launch_dm(libxl__egc *egc, libxl_= _multidev *multidev,
=A0 =A0 =A0 =A0 =A0LOG(DEBUG, "dom%d iomem %"PRIx64"-%"= PRIx64,
=A0 =A0 =A0 =A0 =A0 =A0 =A0domid, io->start, io->start + io->numbe= r - 1);

- =A0 =A0 =A0 =A0ret =3D xc_domain_iomem_permission(CTX->xch, domid,
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0io->start, io->number, 1);
+ =A0 =A0 =A0 =A0ret =3D xc_domain_memory_mapping(CTX->xch, domid,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 io->start, io->start,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 io->number, 1);
=A0 =A0 =A0 =A0 =A0if (ret < 0) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0LOGE(ERROR,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "failed give dom%d access to iomem= range %"PRIx64"-%"PRIx64,
diff --git a/xen/arch/arm/domctl.c b/xen/arch/arm/domctl.c
index 851ee40..222aac9 100644
--- a/xen/arch/arm/domctl.c
+++ b/xen/arch/arm/domctl.c
@@ -10,11 +10,83 @@
=A0#include <xen/errno.h>
=A0#include <xen/sched.h>
=A0#include <public/domctl.h>
+#include <xen/iocap.h>
+#include <xsm/xsm.h>
+#include <xen/paging.h>
+#include <xen/guest_access.h>

=A0long arch_do_domctl(struct xen_domctl *domctl, struct domain *d,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0XEN_GUEST_HANDLE_PARAM(xen_domct= l_t) u_domctl)
=A0{
- =A0 =A0return -ENOSYS;
+ =A0 =A0long ret =3D 0;
+ =A0 =A0bool_t copyback =3D 0;
+
+ =A0 =A0switch ( domctl->cmd )
+ =A0 =A0{
+ =A0 =A0case XEN_DOMCTL_memory_mapping:
+ =A0 =A0{
+ =A0 =A0 =A0 =A0unsigned long gfn =3D domctl->u.memory_mapping.first_gf= n;
+ =A0 =A0 =A0 =A0unsigned long mfn =3D domctl->u.memory_mapping.first_mf= n;
+ =A0 =A0 =A0 =A0unsigned long nr_mfns =3D domctl->u.memory_mapping.nr_m= fns;
+ =A0 =A0 =A0 =A0int add =3D domctl->u.memory_mapping.add_mapping;
+
+ =A0 =A0 =A0 =A0/* removing i/o memory is not implemented yet */
+ =A0 =A0 =A0 =A0if (!add) {
+ =A0 =A0 =A0 =A0 =A0 =A0ret =3D -ENOSYS;
+ =A0 =A0 =A0 =A0 =A0 =A0break;
+ =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0ret =3D -EINVAL;
+ =A0 =A0 =A0 =A0if ( (mfn + nr_mfns - 1) < mfn || /* wrap? */
+ =A0 =A0 =A0 =A0 =A0 =A0 /* x86 checks wrap based on paddr_bits which is n= ot implemented on ARM? */
+ =A0 =A0 =A0 =A0 =A0 =A0 /* ((mfn | (mfn + nr_mfns - 1)) >> (paddr_b= its - PAGE_SHIFT)) || */
+ =A0 =A0 =A0 =A0 =A0 =A0 (gfn + nr_mfns - 1) < gfn ) /* wrap? */
+ =A0 =A0 =A0 =A0 =A0 =A0break;
+
+ =A0 =A0 =A0 =A0ret =3D -EPERM;
+ =A0 =A0 =A0 =A0if ( current->domain->domain_id !=3D 0 )
+ =A0 =A0 =A0 =A0 =A0 =A0break;
+
+ =A0 =A0 =A0 =A0ret =3D xsm_iomem_mapping(XSM_HOOK, d, mfn, mfn + nr_mfns = - 1, add);
+ =A0 =A0 =A0 =A0if ( ret )
+ =A0 =A0 =A0 =A0 =A0 =A0break;
+
+ =A0 =A0 =A0 =A0if ( add )
+ =A0 =A0 =A0 =A0{
+ =A0 =A0 =A0 =A0 =A0 =A0printk(XENLOG_G_INFO
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "memory_map:add: dom%d gfn=3D%lx= mfn=3D%lx nr=3D%lx\n",
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->domain_id, gfn, mfn, nr_mfns);<= br> +
+ =A0 =A0 =A0 =A0 =A0 =A0ret =3D iomem_permit_access(d, mfn, mfn + nr_mfns = - 1);
+ =A0 =A0 =A0 =A0 =A0 =A0if ( !ret && paging_mode_translate(d) ) + =A0 =A0 =A0 =A0 =A0 =A0{
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D map_mmio_regions(d, gfn << P= AGE_SHIFT,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 (gfn + nr_mfns) << PAGE_SHIFT,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 mfn << PAGE_SHIFT);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ( ret )
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0{
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(XENLOG_G_WARNING
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "memory_map:fail= : dom%d gfn=3D%lx mfn=3D%lx nr=3D%lx\n",
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->domain_id, gfn,= mfn, nr_mfns);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if ( iomem_deny_access(d, mfn, mfn= + nr_mfns - 1) &&
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 is_hardware_domain(curren= t->domain) )
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0printk(XENLOG_ERR
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "memory_= map: failed to deny dom%d access to [%lx,%lx]\n",
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 d->domain_= id, mfn, mfn + nr_mfns - 1);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0 =A0 =A0}
+ =A0 =A0 =A0 =A0}
+ =A0 =A0}
+ =A0 =A0break;
+
+ =A0 =A0default:
+ =A0 =A0 =A0 =A0ret =3D -ENOSYS;
+ =A0 =A0 =A0 =A0break;
+ =A0 =A0}
+
+ =A0 =A0if ( copyback && __copy_to_guest(u_domctl, domctl, 1) ) + =A0 =A0 =A0 =A0ret =3D -EFAULT;
+
+ =A0 =A0return ret;
=A0}

=A0void arch_get_info_guest(struct vcpu *v, vcpu_guest_context_u c)
--f46d041825ea3e27bf04f3666a14-- --===============6125966010409888447== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --===============6125966010409888447==--