From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tamas K Lengyel Subject: Re: [PATCH v5 1/2] x86/mem-sharing: Bulk mem-sharing entire domains Date: Tue, 14 Jun 2016 10:42:41 -0600 Message-ID: References: <1465687481-10095-1-git-send-email-tamas@tklengyel.com> <20160614163334.GA11034@char.us.oracle.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0378006296579021906==" Return-path: Received: from mail6.bemta14.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bCrQL-000805-IP for xen-devel@lists.xenproject.org; Tue, 14 Jun 2016 16:42:45 +0000 Received: by mail-wm0-f67.google.com with SMTP id k184so23704226wme.2 for ; Tue, 14 Jun 2016 09:42:43 -0700 (PDT) Received: from mail-wm0-f44.google.com (mail-wm0-f44.google.com. [74.125.82.44]) by smtp.gmail.com with ESMTPSA id ib10sm29487370wjb.31.2016.06.14.09.42.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Jun 2016 09:42:42 -0700 (PDT) Received: by mail-wm0-f44.google.com with SMTP id v199so129433045wmv.0 for ; Tue, 14 Jun 2016 09:42:41 -0700 (PDT) In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: Konrad Rzeszutek Wilk Cc: Xen-devel List-Id: xen-devel@lists.xenproject.org --===============0378006296579021906== Content-Type: multipart/alternative; boundary=001a114b0cd88ddd1205353fb16a --001a114b0cd88ddd1205353fb16a Content-Type: text/plain; charset=UTF-8 On Jun 14, 2016 10:33, "Konrad Rzeszutek Wilk" wrote: > > > diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_sharing.c > > index a522423..ba06fb0 100644 > > --- a/xen/arch/x86/mm/mem_sharing.c > > +++ b/xen/arch/x86/mm/mem_sharing.c > > @@ -1294,6 +1294,54 @@ int relinquish_shared_pages(struct domain *d) > > return rc; > > } > > > > +static int bulk_share(struct domain *d, struct domain *cd, unsigned long limit, > > + struct mem_sharing_op_bulk *bulk) > > +{ > > + int rc = 0; > > + shr_handle_t sh, ch; > > + > > + while( limit > bulk->start ) > > You are missing a space there. Ack. > > + { > > + /* > > + * We only break out if we run out of memory as individual pages may > > + * legitimately be unsharable and we just want to skip over those. > > + */ > > + rc = mem_sharing_nominate_page(d, bulk->start, 0, &sh); > > + if ( rc == -ENOMEM ) > > + break; > > + if ( !rc ) > > + { > > + rc = mem_sharing_nominate_page(cd, bulk->start, 0, &ch); > > + if ( rc == -ENOMEM ) > > + break; > > + if ( !rc ) > > + { > > + /* If we get here this should be guaranteed to succeed. */ > > + rc = mem_sharing_share_pages(d, bulk->start, sh, > > + cd, bulk->start, ch); > > + ASSERT(!rc); > > + } > > + } > > + > > + /* Check for continuation if it's not the last iteration. */ > > + if ( limit > ++bulk->start && hypercall_preempt_check() ) > > I surprised the compiler didn't complain to you about lack of parenthesis. This seems to be standard way to create continuation used in multiple places throughout Xen. I don't personally like it much but I guess it's better to be consistent. > > > + { > > + rc = 1; > > + break; > > + } > > + } > > + > > + /* > > + * We only propagate -ENOMEM as individual pages may fail with -EINVAL, > > + * and for bulk sharing we only care if -ENOMEM was encountered so we reset > > + * rc here. > > + */ > > + if ( rc < 0 && rc != -ENOMEM ) > > + rc = 0; > > + > > + return rc; > > +} > > + > > int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) > > { > > int rc; > > @@ -1468,6 +1516,79 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharing_op_t) arg) > > } > > break; > > > > + case XENMEM_sharing_op_bulk_share: > > + { > > + unsigned long max_sgfn, max_cgfn; > > + struct domain *cd; > > + > > + rc = -EINVAL; > > + if( mso.u.bulk._pad[0] || mso.u.bulk._pad[1] || mso.u.bulk._pad[2] ) > > The "if(".. Ack. Thanks, Tamas --001a114b0cd88ddd1205353fb16a Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Jun 14, 2016 10:33, "Konrad Rzeszutek Wilk" <konrad.wilk@oracle.com> wrote:
>
> > diff --git a/xen/arch/x86/mm/mem_sharing.c b/xen/arch/x86/mm/mem_= sharing.c
> > index a522423..ba06fb0 100644
> > --- a/xen/arch/x86/mm/mem_sharing.c
> > +++ b/xen/arch/x86/mm/mem_sharing.c
> > @@ -1294,6 +1294,54 @@ int relinquish_shared_pages(struct domain = *d)
> >=C2=A0 =C2=A0 =C2=A0 return rc;
> >=C2=A0 }
> >
> > +static int bulk_share(struct domain *d, struct domain *cd, unsig= ned long limit,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 struct mem_sharing_op_bulk *bulk)
> > +{
> > +=C2=A0 =C2=A0 int rc =3D 0;
> > +=C2=A0 =C2=A0 shr_handle_t sh, ch;
> > +
> > +=C2=A0 =C2=A0 while( limit > bulk->start )
>
> You are missing a space there.

Ack.

> > +=C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 /*
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* We only break out if we run = out of memory as individual pages may
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0* legitimately be unsharable a= nd we just want to skip over those.
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0*/
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 rc =3D mem_sharing_nominate_page(d, = bulk->start, 0, &sh);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if ( rc =3D=3D -ENOMEM )
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if ( !rc )
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rc =3D mem_sharing_nom= inate_page(cd, bulk->start, 0, &ch);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if ( rc =3D=3D -ENOMEM= )
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break; > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if ( !rc )
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* If we= get here this should be guaranteed to succeed. */
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rc =3D m= em_sharing_share_pages(d, bulk->start, sh,
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0cd, bulk->start, ch);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ASSERT(!= rc);
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Check for continuation if it'= s not the last iteration. */
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 if ( limit > ++bulk->start &am= p;& hypercall_preempt_check() )
>
> I surprised the compiler didn't complain to you about lack of pare= nthesis.

This seems to be standard way to create continuation used in= multiple places throughout Xen. I don't personally like it much but I = guess it's better to be consistent.

>
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rc =3D 1;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> > +=C2=A0 =C2=A0 }
> > +
> > +=C2=A0 =C2=A0 /*
> > +=C2=A0 =C2=A0 =C2=A0* We only propagate -ENOMEM as individual pa= ges may fail with -EINVAL,
> > +=C2=A0 =C2=A0 =C2=A0* and for bulk sharing we only care if -ENOM= EM was encountered so we reset
> > +=C2=A0 =C2=A0 =C2=A0* rc here.
> > +=C2=A0 =C2=A0 =C2=A0*/
> > +=C2=A0 =C2=A0 if ( rc < 0 && rc !=3D -ENOMEM )
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 rc =3D 0;
> > +
> > +=C2=A0 =C2=A0 return rc;
> > +}
> > +
> >=C2=A0 int mem_sharing_memop(XEN_GUEST_HANDLE_PARAM(xen_mem_sharin= g_op_t) arg)
> >=C2=A0 {
> >=C2=A0 =C2=A0 =C2=A0 int rc;
> > @@ -1468,6 +1516,79 @@ int mem_sharing_memop(XEN_GUEST_HANDLE_PAR= AM(xen_mem_sharing_op_t) arg)
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
> >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 break;
> >
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 case XENMEM_sharing_op_bulk_share: > > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 {
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 unsigned long max_sgfn= , max_cgfn;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 struct domain *cd;
> > +
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 rc =3D -EINVAL;
> > +=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if( mso.u.bulk._pad[0]= || mso.u.bulk._pad[1] || mso.u.bulk._pad[2] )
>
> The "if("..

Ack.

Thanks,
Tamas

--001a114b0cd88ddd1205353fb16a-- --===============0378006296579021906== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwOi8vbGlzdHMueGVuLm9y Zy94ZW4tZGV2ZWwK --===============0378006296579021906==--