From: MaoXiaoyun Subject: RE: [memory sharing] bug on get_page_and_type Date: Mon, 21 Feb 2011 20:29:04 +0800 Message-ID: References: , , , , <20110201142816.GE20638@whitby.uk.xensource.com>, , <20110202161837.GQ8286@whitby.uk.xensource.com>, , <20110209095720.GC18135@whitby.uk.xensource.com>, , <20110211093218.GE18135@whitby.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0911165688==" Return-path: In-Reply-To: <20110211093218.GE18135@whitby.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen devel Cc: george.dunlap@eu.citrix.com, harshan.dll@gmail.com, tim.deegan@citrix.com, juihaochiang@gmail.com List-Id: xen-devel@lists.xenproject.org --===============0911165688== Content-Type: multipart/alternative; boundary="_039a8c48-e75d-4573-a179-c05b49c5dbef_" --_039a8c48-e75d-4573-a179-c05b49c5dbef_ Content-Type: text/plain; charset="gb2312" Content-Transfer-Encoding: quoted-printable Hi Tim: =20 More thoughts on this bug. =20 First some questions =20 1) What PGT_writeable_page means to a page? 2) When a page type will be changed to PGT_writeable_page? 3) It looks like PGT_writeable_page is not sharable? Since only = PGT_none can, right? 4) Could I use get_page_type(page, PGT_writeable_page) before ev= ery is_p2m_shared() check. =20 Since if get_page_type() success, then the page will has no = chance to be shared later and if get_page_type() failed, it page mush has type, it is = either PGT_shared_page or other types,=20 if other types, the page still has no chance to be shared. if PGT_shared_page, that's ok, just do usual is_p2m_shared r= eturn routine. =20 question is, is it ok if we only get_page_type, and not to p= ut_page_type()? =20 =20 > Date: Fri, 11 Feb 2011 09:32:18 +0000 > From: Tim.Deegan@citrix.com > To: tinnycloud@hotmail.com > CC: xen-devel@lists.xensource.com; George.Dunlap@eu.citrix.com; juihaoc= hiang@gmail.com > Subject: Re: [Xen-devel] [memory sharing] bug on get_page_and_type >=20 > At 07:04 +0000 on 11 Feb (1297407854), MaoXiaoyun wrote: > > Thanks Tim. > >=20 > > After discuss with JuiHao, How about fix in this way? > >=20 > > 1) Suppose we have a function, make_page_unsharable() to substitude > > p2m_is_shared() check, if p2mt is not shared, we increase its type co= unt > > to avoid it turn to shared while using it. >=20 > That's a good idea. I'd rather not have the name be anything to do with > "sharable", but we could have a function that does a p2m lookup and a > get-page-and-type, all under the p2m lock, and use it instead of the > lookup-check-getref idiom elsewhere. >=20 > Then if (as you say) the make-shareable and nominate-page actions were > covered by the same lock (or potentially even just called the same > function themselves) we would eliminate a lot of races.=20 >=20 > That will be too big a patch to take before 4.1.0 but I'd consider it > immediately after the release. >=20 > Tim. >=20 > > 1 int make_page_unsharable(int enable) > > 2 { > > 3 p2m_type_t p2mt; > > 4 unsigned long mfn; > > 5 > > 6 p2m_lock() > > 7 mfn =3D mfn_x(gfn_to_mfn(d, gmfn, &p2mt)) > > 8 > > 9 if(p2m_is_shared(p2mt)){ > > 10 p2m_unlock() > > 11 return 1; > > 12 } > > 13 > > 14 get_page_type() / ***increase page type count to avoid page type t= urn to shared, since in > > mem_sharing_nominate_page->page_make_sharable, only type count zero i= s > > allowed to be shared*/ > > 15 p2m_unlock() > > 16 > > 17 return 0; > > 18 } > >=20 > > 2) If p2mt is not shared, we must decrease it type count after we fin= ish using it > > 3) To avoid competition, page_make_sharble() and p2m_change_type() in > > mem_sharing_nominate_page() should be protected in same p2m_lock. > >=20 > > comments? > >=20 > >=20 > > > Date: Wed, 9 Feb 2011 09:57:20 +0000 > > > From: Tim.Deegan@citrix.com > > > To: tinnycloud@hotmail.com > > > CC: xen-devel@lists.xensource.com; George.Dunlap@eu.citrix.com; jui= haochiang@gmail.com > > > Subject: Re: [Xen-devel] [memory sharing] bug on get_page_and_type > > > > > > At 02:46 +0000 on 09 Feb (1297219562), MaoXiaoyun wrote: > > > > I've been looking into the TOCTOU issue quite a while, but > > > > > > > > 1) There are quite a lot judgements like "p2m_is_shared(p2mt)" or > > > > "p2mt =3D=3D p2m_ram_shared", which, for me, is hard to tell whom > > > > are need to be protect by p2m_lock and whom are not So is > > > > there a rule to distinguish these? > > > > > > Not particularly. I suspect that most of them will need to be > > > changed, but as I said I hope we can find something nicer than > > > scattering p2m_lock() around non-p2m code. > > > > > > > 2) Could we improve p2m_lock to sparse lock, which maybe better, = right? > > > > > > Maybe, but not necessarily. Let's get it working properly first and > > > then we can measure lock contention and see whether fancy locks are > > > worthwhile. > > > > > > Tim. > > > > > > > > > > > > Date: Wed, 2 Feb 2011 16:18:37 +0000 > > > > > From: Tim.Deegan@citrix.com > > > > > To: tinnycloud@hotmail.com > > > > > CC: xen-devel@lists.xensource.com; George.Dunlap@eu.citrix.com;= juihaochiang@gmail.com > > > > > Subject: Re: [Xen-devel] [memory sharing] bug on get_page_and_t= ype > > > > > > > > > > At 15:43 +0000 on 02 Feb (1296661396), MaoXiaoyun wrote: > > > > > > Hi Tim: > > > > > > > > > > > > Thanks for both your advice and quick reply. I will follow. > > > > > > > > > > > > So at last we should replace shr_lock with p2m_lock. > > > > > > But more complicate, it seems both the > > > > > > *check action* code and *nominate page* code need to be locke= d ,right? > > > > > > If so, quite a lot of *check action* codes need to be locked. > > > > > > > > > > Yes, I think you're right about that. Unfortunately there are s= ome very > > > > > long TOCTOU windows in those kind of p2m lookups, which will ge= t more > > > > > important as the p2m gets more dynamic. I don't want to have th= e > > > > > callers of p2m code touching the p2m lock directly so we may ne= ed a new > > > > > p2m interface to address it. > > > > > > > > > > Tim. > > > > > > > > > > > -- > > > Tim Deegan > > > Principal Software Engineer, Xen Platform Team > > > Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) >=20 > --=20 > Tim Deegan > Principal Software Engineer, Xen Platform Team > Citrix Systems UK Ltd. (Company #02937203, SL9 0BG) =20 --_039a8c48-e75d-4573-a179-c05b49c5dbef_ Content-Type: text/html; charset="gb2312" Content-Transfer-Encoding: quoted-printable Hi Tim:
 
         More thoughts on this bu= g.
        
         First some questions
 

         1) What PGT_writeable_page means to a page?

         2) When a page type will be changed to PGT_writeable_page?

         3) It looks like PGT_writeable_page is not sharable? Since only PGT_non= e can, right?

         4) Could I use get_page_type(page, PGT_writeable_page) before every is_= p2m_shared() check.

   &n= bsp;           <= /SPAN>

   &n= bsp;         Since if get_page_ty= pe() success, then the page will has no chance to be shared later<= /SPAN>

   &n= bsp;         and if get= _page_type() failed, it page mush has type, it is either  PGT_s= hared_page or other types,

   &n= bsp;         if other types, the = page still has no chance to be shared.

   &n= bsp;         if PGT_shared_page, = that's ok, just do usual is_p2m_shared return routine.

 =

   &n= bsp;         question is, is = ;it ok if we only get_page_type, and not to put_page_type()?<= /SPAN>

   &n= bsp;   


 
> Date: Fri, 11 Feb 2011 09:32:18 +0000
> From: Tim.Deegan@citri= x.com
> To: tinnycloud@hotmail.com
> CC: xen-devel@lists.xens= ource.com; George.Dunlap@eu.citrix.com; juihaochiang@gmail.com
> Su= bject: Re: [Xen-devel] [memory sharing] bug on get_page_and_type
> =
> At 07:04 +0000 on 11 Feb (1297407854), MaoXiaoyun wrote:
>= > Thanks Tim.
> >
> > After discuss with JuiHao, H= ow about fix in this way?
> >
> > 1) Suppose we have a= function, make_page_unsharable() to substitude
> > p2m_is_share= d() check, if p2mt is not shared, we increase its type count
> >= to avoid it turn to shared while using it.
>
> That's a goo= d idea. I'd rather not have the name be anything to do with
> "shar= able", but we could have a function that does a p2m lookup and a
> = get-page-and-type, all under the p2m lock, and use it instead of the
&= gt; lookup-check-getref idiom elsewhere.< BR>>
> Then if (as you say) the make-shareable and nominate-pa= ge actions were
> covered by the same lock (or potentially even jus= t called the same
> function themselves) we would eliminate a lot o= f races.
>
> That will be too big a patch to take before 4.= 1.0 but I'd consider it
> immediately after the release.
> > Tim.
>
> > 1 int make_page_unsharable(int enable)<= BR>> > 2 {
> > 3 p2m_type_t p2mt;
> > 4 unsigned = long mfn;
> > 5
> > 6 p2m_lock()
> > 7 mfn =3D= mfn_x(gfn_to_mfn(d, gmfn, &p2mt))
> > 8
> > 9 if(p= 2m_is_shared(p2mt)){
> > 10 p2m_unlock()
> > 11 return = 1;
> > 12 }
> > 13
> > 14 get_page_type() / **= *increase page type count to avoid page type turn to shared, since in
= > > mem_sharing_nominate_page->page_make_sharable, only type cou= nt zero is
> > allowed to be shared */
> > 15 p2m_unlock()
> > 16
> > 17 return 0= ;
> > 18 }
> >
> > 2) If p2mt is not shared, = we must decrease it type count after we finish using it
> > 3) T= o avoid competition, page_make_sharble() and p2m_change_type() in
>= > mem_sharing_nominate_page() should be protected in same p2m_lock.> >
> > comments?
> >
> >
> &= gt; > Date: Wed, 9 Feb 2011 09:57:20 +0000
> > > From: Tim= .Deegan@citrix.com
> > > To: tinnycloud@hotmail.com
> &= gt; > CC: xen-devel@lists.xensource.com; George.Dunlap@eu.citrix.com; = juihaochiang@gmail.com
> > > Subject: Re: [Xen-devel] [memory= sharing] bug on get_page_and_type
> > >
> > > At= 02:46 +0000 on 09 Feb (1297219562), MaoXiaoyun wrote:
> > > = > I've been looking into the TOCTOU issue quite a while, but
> &= gt; > >
> > > > 1) Th ere are quite a lot judgements like "p2m_is_shared(p2mt)" or
> >= ; > > "p2mt =3D=3D p2m_ram_shared", which, for me, is hard to tell = whom
> > > > are need to be protect by p2m_lock and whom a= re not So is
> > > > there a rule to distinguish these?> > >
> > > Not particularly. I suspect that most o= f them will need to be
> > > changed, but as I said I hope we= can find something nicer than
> > > scattering p2m_lock() ar= ound non-p2m code.
> > >
> > > > 2) Could we i= mprove p2m_lock to sparse lock, which maybe better, right?
> > &= gt;
> > > Maybe, but not necessarily. Let's get it working pr= operly first and
> > > then we can measure lock contention an= d see whether fancy locks are
> > > worthwhile.
> > = >
> > > Tim.
> > >
> > > >
&= gt; > > > > Date: Wed, 2 Feb 2011=20 16:18:37 +0000
> > > > > From: Tim.Deegan@citrix.com> > > > > To: tinnycloud@hotmail.com
> > > &= gt; > CC: xen-devel@lists.xensource.com; George.Dunlap@eu.citrix.com; = juihaochiang@gmail.com
> > > > > Subject: Re: [Xen-deve= l] [memory sharing] bug on get_page_and_type
> > > > ><= BR>> > > > > At 15:43 +0000 on 02 Feb (1296661396), MaoXia= oyun wrote:
> > > > > > Hi Tim:
> > > &g= t; > >
> > > > > > Thanks for both your advice= and quick reply. I will follow.
> > > > > >
>= > > > > > So at last we should replace shr_lock with p2m_= lock.
> > > > > > But more complicate, it seems both= the
> > > > > > *check action* code and *nominate p= age* code need to be locked ,right?
> > > > > > If s= o, quite a lot of *check action* codes nee d to be locked.
> > > > >
> > > > > = Yes, I think you're right about that. Unfortunately there are some very> > > > > long TOCTOU windows in those kind of p2m looku= ps, which will get more
> > > > > important as the p2m = gets more dynamic. I don't want to have the
> > > > > c= allers of p2m code touching the p2m lock directly so we may need a new> > > > > p2m interface to address it.
> > > = > >
> > > > > Tim.
> > > > >> > >
> > > --
> > > Tim Deegan <Tim= .Deegan@citrix.com>
> > > Principal Software Engineer, Xen= Platform Team
> > > Citrix Systems UK Ltd. (Company #0293720= 3, SL9 0BG)
>
> --
> Tim Deegan <Tim.Deegan@citrix= .com>
> Principal Software Engineer, Xen Platform Team
> C= itrix Systems UK Ltd. (Company #02937203,=20 SL9 0BG)
--_039a8c48-e75d-4573-a179-c05b49c5dbef_-- --===============0911165688== 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.xensource.com http://lists.xensource.com/xen-devel --===============0911165688==--