From mboxrd@z Thu Jan 1 00:00:00 1970 From: sepanta s Subject: Re: monitor access to pages with a specific p2m_type_t Date: Mon, 11 Jul 2016 16:55:09 +0430 Message-ID: References: <5f69be9a-9747-2103-3d4e-62518a7969b8@bitdefender.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5454106845323635392==" Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" To: Tamas K Lengyel Cc: George Dunlap , Razvan Cojocaru , "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org --===============5454106845323635392== Content-Type: multipart/alternative; boundary=94eb2c0876a2474a4805375b3e8c --94eb2c0876a2474a4805375b3e8c Content-Type: text/plain; charset=UTF-8 On Sun, Jul 10, 2016 at 4:50 PM, sepanta s wrote: > > > On Sun, Jun 26, 2016 at 5:15 PM, sepanta s wrote: > >> >> >> >> On Fri, Jun 24, 2016 at 8:10 PM, Tamas K Lengyel >> wrote: >> >>> >>> On Jun 24, 2016 05:19, "Razvan Cojocaru" >>> wrote: >>> > >>> > On 06/24/2016 02:05 PM, George Dunlap wrote: >>> > > On Wed, Jun 22, 2016 at 12:38 PM, sepanta s >>> wrote: >>> > >> Hi, >>> > >> Is it possible to monitor the access on the pages withp2m_type_t >>> > >> p2m_ram_shared? >>> > > >>> > > cc'ing Tamas and Razvan >>> > >>> > Thanks for the CC. Judging by the "if ( npfec.write_access && (p2mt == >>> > p2m_ram_shared) )" line in hvm_hap_nested_page_fault() (from >>> > xen/arch/x86/hvm/hvm.c), I'd say it certainly looks possible. But I >>> > don't know what the context of the question is. >>> > >>> > >>> > Thanks, >>> > Razvan >>> >> The question is just getting the gfn and mfn of the page which is as >> type: p2m_ram_shared to see which pages are written and unshared. >> >>> Yes, p2m_ram_shared type pages can be monitored with mem_access just as >>> normal pages. The only part that may be tricky is if you map the page into >>> your monitoring application while the page is shared. Your handle will >>> continue to be valid even if the page is unshared but it will continue to >>> point to the shared page. However, even if you catch write access events to >>> the shared page that will lead to unsharing, the mem_access notification is >>> sent before unsharing. I just usually do unsharing myself in the mem_access >>> callback manually for monitored pages for this reason. I might change the >>> flow in 4.8 to send the notification after the unsharing happened to >>> simplify this. >>> >>> Tamas >>> >> Thanks, but in mem_access , what APIs can be used to see such events ? >> > > Should I mark the shared pages as rx only ? > > Hi, Is there any sample code which I can undestand how to capture the events on the gfns which have p2m_ram_shared enabled ? I couldn't find any ... . I would be grateful if any help , as there is not any documents through net to use :( Should I just set the ring_page as the pages which are shared and mark them read-only, then capture the write events? BTW, I added a function called mem_sharing_notify_unshare to mem_sharing.c and added it to __mem_sharing_unshare_page at this part: *if ( p2m_change_type_one(d, gfn, p2m_ram_shared, p2m_ram_rw) )* *{* *gdprintk(XENLOG_ERR, "Could not change p2m type d %hu gfn %lx.\n", * *d->domain_id, gfn);* *BUG();* *}else {* * mem_sharing_notify_unshare(d,gfn.0);* *}* So by having a vm event channel listening to unsharing event, I can see the notification in xen-access . To do so, I have used vm_event_enable which uses HVM_PARAM_SHARING_RING_PFN . But, when I used memshrtool to share all the pages of two vms - my vm1 and its clone vm2 . About 900 MB of the ram is shared but there are a lot of unshared events happening. When I do the sharing one more time, there is not any pages unshared as the total number of shared pages stay the same. Seems no unsharing is done as the number of shared pages are the same. Does any page fault triggers when a write operation is done on a shared page among two vms ? --94eb2c0876a2474a4805375b3e8c Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable


On Sun, Jul 10, 2016 at 4:50 PM, sepanta s <sapanta992@gmail.com> wrote:


On Sun, = Jun 26, 2016 at 5:15 PM, sepanta s <sapanta992@gmail.com>= wrote:



On Fri, Jun 24, 2016 at 8:10 PM, = Tamas K Lengyel <tamas@tklengyel.com> wrote:


On Jun 24, 2016 05:19, "Razvan Cojocaru" <rcojocaru@bitdefender.com>= ; wrote:
>
> On 06/24/2016 02:05 PM, George Dunlap wrote:
> > On Wed, Jun 22, 2016 at 12:38 PM, sepanta s <sapanta992@gmail.com> wrote= :
> >> Hi,
> >> Is it possible to monitor the access on the pages withp2m_typ= e_t
> >> p2m_ram_shared?
> >
> > cc'ing Tamas and Razvan
>
> Thanks for the CC. Judging by the "if ( npfec.write_access &&= amp; (p2mt =3D=3D
> p2m_ram_shared) )" line in hvm_hap_nested_page_fault() (from
> xen/arch/x86/hvm/hvm.c), I'd say it certainly looks possible. But = I
> don't know what the context of the question is.
>
>
> Thanks,
> Razvan

The question is just ge= tting the gfn and mfn of the page which is as type: p2m_ram_shared to see w= hich pages are written and unshared.=C2=A0

Yes, p2m_ram_shared type pages can be monitored = with mem_access just as normal pages. The only part that may be tricky is i= f you map the page into your monitoring application while the page is share= d. Your handle will continue to be valid even if the page is unshared but i= t will continue to point to the shared page. However, even if you catch wri= te access events to the shared page that will lead to unsharing, the mem_ac= cess notification is sent before unsharing. I just usually do unsharing mys= elf in the mem_access callback manually for monitored pages for this reason= . I might change the flow in 4.8 to send the notification after the unshari= ng happened to simplify this.

Tamas

Thanks, but in mem_access , what AP= Is can be used to see such events ?

Should I mark the shared pages as rx only ?

=C2=A0
Hi,=C2=A0
Is there= any sample code which I can undestand how to capture the events on the gfn= s which have p2m_ram_shared enabled=C2=A0?=
I couldn't find any = ... .
I would be grat= eful if any help , as there is not any documents through net to use :(

Should I just = set the ring_page as the pages which are shared and mark them read-only, th= en capture the write events?


<= /div>
BTW, I added a function called= =C2=A0mem_sharing_notify_unshare to mem_sharing.c and added it to __= mem_sharing_unshare_page at this part:

if=C2=A0(=C2=A0p2m_change_type_one(d, gfn, p2m_ram_s= hared, p2m_ram_rw) )
{
gdprintk(XENLOG_ERR,=C2=A0"Could not change p2m type d=C2=A0%hu=C2=A0gfn=C2=A0%lx.\n",=C2=A0
d->do= main_id, gfn);
BUG();
}else {

=
=C2=A0mem_sharing_notify_unshare(d,gfn.0);
}

So by having a vm event channel listenin= g to unsharing event, I can see the notification in xen-access . To do so, = I=C2=A0
have used vm_event_enable which uses HVM_PARAM_SHARING_RI= NG_PFN .
But, when I used memshrtool to share all the pages of tw= o vms - my vm1 and its clone vm2 .
About 900 MB of the ram is sha= red but there are a lot of unshared events happening.
When I do t= he sharing one more time, there is not any pages unshared as the total numb= er of shared pages stay the same.
Seems no unsharing is done as t= he number of shared pages are the same.
Does any page fault trigg= ers when a write operation is done on a shared page among two vms ?


--94eb2c0876a2474a4805375b3e8c-- --===============5454106845323635392== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVuLm9yZwpodHRwczovL2xpc3RzLnhlbi5v cmcveGVuLWRldmVsCg== --===============5454106845323635392==--