xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* monitor access to pages with a specific p2m_type_t
@ 2016-06-22 11:38 sepanta s
  2016-06-24 11:05 ` George Dunlap
  0 siblings, 1 reply; 14+ messages in thread
From: sepanta s @ 2016-06-22 11:38 UTC (permalink / raw)
  To: Xen-devel


[-- Attachment #1.1: Type: text/plain, Size: 85 bytes --]

Hi,
Is it possible to monitor the access on the pages withp2m_type_t
p2m_ram_shared?

[-- Attachment #1.2: Type: text/html, Size: 142 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-06-22 11:38 monitor access to pages with a specific p2m_type_t sepanta s
@ 2016-06-24 11:05 ` George Dunlap
  2016-06-24 11:20   ` Razvan Cojocaru
  0 siblings, 1 reply; 14+ messages in thread
From: George Dunlap @ 2016-06-24 11:05 UTC (permalink / raw)
  To: sepanta s; +Cc: Tamas K Lengyel, Razvan Cojocaru, xen-devel@lists.xen.org

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_type_t
> p2m_ram_shared?

cc'ing Tamas and Razvan

 -George

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-06-24 11:05 ` George Dunlap
@ 2016-06-24 11:20   ` Razvan Cojocaru
  2016-06-24 15:40     ` Tamas K Lengyel
  0 siblings, 1 reply; 14+ messages in thread
From: Razvan Cojocaru @ 2016-06-24 11:20 UTC (permalink / raw)
  To: George Dunlap, sepanta s; +Cc: Tamas K Lengyel, xen-devel@lists.xen.org

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_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

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-06-24 11:20   ` Razvan Cojocaru
@ 2016-06-24 15:40     ` Tamas K Lengyel
  2016-06-26 12:45       ` sepanta s
  0 siblings, 1 reply; 14+ messages in thread
From: Tamas K Lengyel @ 2016-06-24 15:40 UTC (permalink / raw)
  To: Razvan Cojocaru; +Cc: George Dunlap, xen-devel@lists.xen.org, sepanta s


[-- Attachment #1.1: Type: text/plain, Size: 1302 bytes --]

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_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

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

[-- Attachment #1.2: Type: text/html, Size: 1664 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-06-24 15:40     ` Tamas K Lengyel
@ 2016-06-26 12:45       ` sepanta s
  2016-07-10 12:20         ` sepanta s
  0 siblings, 1 reply; 14+ messages in thread
From: sepanta s @ 2016-06-26 12:45 UTC (permalink / raw)
  To: Tamas K Lengyel; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1: Type: text/plain, Size: 1656 bytes --]

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_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 ?

[-- Attachment #1.2: Type: text/html, Size: 2589 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-06-26 12:45       ` sepanta s
@ 2016-07-10 12:20         ` sepanta s
  2016-07-11 12:25           ` sepanta s
  0 siblings, 1 reply; 14+ messages in thread
From: sepanta s @ 2016-07-10 12:20 UTC (permalink / raw)
  To: Tamas K Lengyel; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1: Type: text/plain, Size: 1830 bytes --]

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_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 ?

[-- Attachment #1.2: Type: text/html, Size: 3008 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-07-10 12:20         ` sepanta s
@ 2016-07-11 12:25           ` sepanta s
  2016-07-12 18:26             ` Tamas K Lengyel
  0 siblings, 1 reply; 14+ messages in thread
From: sepanta s @ 2016-07-11 12:25 UTC (permalink / raw)
  To: Tamas K Lengyel; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1: Type: text/plain, Size: 3324 bytes --]

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_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 ?

[-- Attachment #1.2: Type: text/html, Size: 6335 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-07-11 12:25           ` sepanta s
@ 2016-07-12 18:26             ` Tamas K Lengyel
  2016-07-23 11:19               ` sepanta s
  0 siblings, 1 reply; 14+ messages in thread
From: Tamas K Lengyel @ 2016-07-12 18:26 UTC (permalink / raw)
  To: sepanta s; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1: Type: text/plain, Size: 4155 bytes --]

On Mon, Jul 11, 2016 at 6:25 AM, sepanta s <sapanta992@gmail.com> wrote:

>
>
> 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_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?
>

Not sure what ring_page you are talking about, but if you mark the pages
read-only with mem_access you will get notifications for events that lead
to unsharing with p2m_ram_shared type pages as well.


>
> 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);*
> *}*
>
>
IMHO this duplicates a lot of what mem_access does already, I don't think
there is a need for a separate notification on another ring.


> 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.
>

Yes, I would say that's expected.


> When I do the sharing one more time, there is not any pages unshared as
> the total number of shared pages stay the same.
>

Well, if you let the domain run for a while after sharing, then you do the
sharing like that again you are likely going to crash the VM.


> 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 ?
>

I would guess the the VM crashed and that's why you don't see any more
unsharing at that point.

Tamas

[-- Attachment #1.2: Type: text/html, Size: 8099 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-07-12 18:26             ` Tamas K Lengyel
@ 2016-07-23 11:19               ` sepanta s
  2016-08-02  6:19                 ` sepanta s
  0 siblings, 1 reply; 14+ messages in thread
From: sepanta s @ 2016-07-23 11:19 UTC (permalink / raw)
  To: Tamas K Lengyel; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1.1: Type: text/plain, Size: 3739 bytes --]

>
>
>> 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?
>>
>
> Not sure what ring_page you are talking about, but if you mark the pages
> read-only with mem_access you will get notifications for events that lead
> to unsharing with p2m_ram_shared type pages as well.
>

There was a function in mem-sharing.c which is intended to announce the
failed unshared pages. It is "mem_sharing_notify_enomem" .
I added "mem_sharing_notify_unshare" as a new function and call it in
also XEN_DOMCTL_VM_EVENT_OP_UNSHARING
and "HVM_PARAM_USHARING_RING_PFN". I also added the required codes in
/xen/common/vm_event.c and /tools/libxc/xc_vm_event so as
I have added a new event for the unsharing actions of a page.
Then, I wrote a sample code line xen-access and create a ring for the pages
of a domain and listen to unshared events of it.

>
>> 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);*
>> *}*
>>
>>
> IMHO this duplicates a lot of what mem_access does already, I don't think
> there is a need for a separate notification on another ring.
>
>
You are right, xen-access should work but I couldn't change its code and
couldn't get the mem-access events.
 I just added the above function to be sure that unsharing a page happens
and works fine. Because I couldn't get the access requests on shared-pages
of a vm.
In xen-access, Instead of setting all the pages' default access to rx , I
just call xc_set_mem_access for the pages with p2m_ram_shared and assign rx
as the default access but there is no requests on this ring.

>

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.
>>
>
> Yes, I would say that's expected.
>

>
>> When I do the sharing one more time, there is not any pages unshared as
>> the total number of shared pages stay the same.
>>
>
> Well, if you let the domain run for a while after sharing, then you do the
> sharing like that again you are likely going to crash the VM.
>
>
>> 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 ?
>>
>
> I would guess the the VM crashed and that's why you don't see any more
> unsharing at that point.
>
Yes it was crashed as I checked it.
The scenario of sharing is I use:
I pause the origin VM and then run memshrtool on origin VM and clone VM.
After sharing all the pages between these two VMs,Clone VM seems to be
inaccessible. The clone seems to work as the attached photo shows, its cpu
time increases and it exceeds the dom0 cpu time but when I use gvncviewer
to see the GUI of the Clone VM, the mouse or keyboard don't work. (origin
VM is ubunut-64-1 and clone VM is ubuntu-64-clone-1). Is there anything I
have missed in sharing between two VMs?

[image: Inline image 2]

[-- Attachment #1.1.2: Type: text/html, Size: 9112 bytes --]

[-- Attachment #1.2: Screenshot from 2016-07-23 15_19_05.png --]
[-- Type: image/png, Size: 18631 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-07-23 11:19               ` sepanta s
@ 2016-08-02  6:19                 ` sepanta s
  2016-08-02 15:53                   ` Tamas K Lengyel
  0 siblings, 1 reply; 14+ messages in thread
From: sepanta s @ 2016-08-02  6:19 UTC (permalink / raw)
  To: Tamas K Lengyel; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1.1: Type: text/plain, Size: 4051 bytes --]

On Sat, Jul 23, 2016 at 3:49 PM, sepanta s <sapanta992@gmail.com> wrote:

>
>>> 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?
>>>
>>
>> Not sure what ring_page you are talking about, but if you mark the pages
>> read-only with mem_access you will get notifications for events that lead
>> to unsharing with p2m_ram_shared type pages as well.
>>
>
> There was a function in mem-sharing.c which is intended to announce the
> failed unshared pages. It is "mem_sharing_notify_enomem" .
> I added "mem_sharing_notify_unshare" as a new function and call it in
> also XEN_DOMCTL_VM_EVENT_OP_UNSHARING and "HVM_PARAM_USHARING_RING_PFN".
> I also added the required codes in /xen/common/vm_event.c and
> /tools/libxc/xc_vm_event so as
> I have added a new event for the unsharing actions of a page.
> Then, I wrote a sample code line xen-access and create a ring for the
> pages of a domain and listen to unshared events of it.
>
>>
>>> 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);*
>>> *}*
>>>
>>>
>> IMHO this duplicates a lot of what mem_access does already, I don't think
>> there is a need for a separate notification on another ring.
>>
>>
> You are right, xen-access should work but I couldn't change its code and
> couldn't get the mem-access events.
>  I just added the above function to be sure that unsharing a page happens
> and works fine. Because I couldn't get the access requests on shared-pages
> of a vm.
> In xen-access, Instead of setting all the pages' default access to rx , I
> just call xc_set_mem_access for the pages with p2m_ram_shared and assign rx
> as the default access but there is no requests on this ring.
>
>>
>
> 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.
>>>
>>
>> Yes, I would say that's expected.
>>
>
>>
>>> When I do the sharing one more time, there is not any pages unshared as
>>> the total number of shared pages stay the same.
>>>
>>
>> Well, if you let the domain run for a while after sharing, then you do
>> the sharing like that again you are likely going to crash the VM.
>>
>>
>>> 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 ?
>>>
>>
>> I would guess the the VM crashed and that's why you don't see any more
>> unsharing at that point.
>>
> Yes it was crashed as I checked it.
> The scenario of sharing is I use:
> I pause the origin VM and then run memshrtool on origin VM and clone VM.
> After sharing all the pages between these two VMs,Clone VM seems to be
> inaccessible. The clone seems to work as the attached photo shows, its cpu
> time increases and it exceeds the dom0 cpu time but when I use gvncviewer
> to see the GUI of the Clone VM, the mouse or keyboard don't work. (origin
> VM is ubunut-64-1 and clone VM is ubuntu-64-clone-1). Is there anything I
> have missed in sharing between two VMs?
>
> [image: Inline image 2]
>

Can someone help please ? still have problem with the machine .
is it because sharing is not based on content?

[-- Attachment #1.1.2: Type: text/html, Size: 9722 bytes --]

[-- Attachment #1.2: Screenshot from 2016-07-23 15_19_05.png --]
[-- Type: image/png, Size: 18631 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-08-02  6:19                 ` sepanta s
@ 2016-08-02 15:53                   ` Tamas K Lengyel
  2016-08-05 11:35                     ` sepanta s
  0 siblings, 1 reply; 14+ messages in thread
From: Tamas K Lengyel @ 2016-08-02 15:53 UTC (permalink / raw)
  To: sepanta s; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1.1: Type: text/plain, Size: 4505 bytes --]

On Tue, Aug 2, 2016 at 12:19 AM, sepanta s <sapanta992@gmail.com> wrote:

>
>
> On Sat, Jul 23, 2016 at 3:49 PM, sepanta s <sapanta992@gmail.com> wrote:
>
>>
>>>> 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?
>>>>
>>>
>>> Not sure what ring_page you are talking about, but if you mark the pages
>>> read-only with mem_access you will get notifications for events that lead
>>> to unsharing with p2m_ram_shared type pages as well.
>>>
>>
>> There was a function in mem-sharing.c which is intended to announce the
>> failed unshared pages. It is "mem_sharing_notify_enomem" .
>> I added "mem_sharing_notify_unshare" as a new function and call it in
>> also XEN_DOMCTL_VM_EVENT_OP_UNSHARING and "HVM_PARAM_USHARING_RING_PFN".
>> I also added the required codes in /xen/common/vm_event.c and
>> /tools/libxc/xc_vm_event so as
>> I have added a new event for the unsharing actions of a page.
>> Then, I wrote a sample code line xen-access and create a ring for the
>> pages of a domain and listen to unshared events of it.
>>
>>>
>>>> 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);*
>>>> *}*
>>>>
>>>>
>>> IMHO this duplicates a lot of what mem_access does already, I don't
>>> think there is a need for a separate notification on another ring.
>>>
>>>
>> You are right, xen-access should work but I couldn't change its code and
>> couldn't get the mem-access events.
>>  I just added the above function to be sure that unsharing a page happens
>> and works fine. Because I couldn't get the access requests on shared-pages
>> of a vm.
>> In xen-access, Instead of setting all the pages' default access to rx , I
>> just call xc_set_mem_access for the pages with p2m_ram_shared and assign rx
>> as the default access but there is no requests on this ring.
>>
>>>
>>
>> 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.
>>>>
>>>
>>> Yes, I would say that's expected.
>>>
>>
>>>
>>>> When I do the sharing one more time, there is not any pages unshared as
>>>> the total number of shared pages stay the same.
>>>>
>>>
>>> Well, if you let the domain run for a while after sharing, then you do
>>> the sharing like that again you are likely going to crash the VM.
>>>
>>>
>>>> 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 ?
>>>>
>>>
>>> I would guess the the VM crashed and that's why you don't see any more
>>> unsharing at that point.
>>>
>> Yes it was crashed as I checked it.
>> The scenario of sharing is I use:
>> I pause the origin VM and then run memshrtool on origin VM and clone VM.
>> After sharing all the pages between these two VMs,Clone VM seems to be
>> inaccessible. The clone seems to work as the attached photo shows, its cpu
>> time increases and it exceeds the dom0 cpu time but when I use gvncviewer
>> to see the GUI of the Clone VM, the mouse or keyboard don't work. (origin
>> VM is ubunut-64-1 and clone VM is ubuntu-64-clone-1). Is there anything I
>> have missed in sharing between two VMs?
>>
>> [image: Inline image 2]
>>
>
> Can someone help please ? still have problem with the machine .
> is it because sharing is not based on content?
>
>
Well, the emulated device contexts probably get all messed up when you just
clone over the memory of the domain and that's why they don't work. The
only way I got this to work is by doing a save/restore of the origin domain
before doing the memory sharing.

Tamas

[-- Attachment #1.1.2: Type: text/html, Size: 10469 bytes --]

[-- Attachment #1.2: Screenshot from 2016-07-23 15_19_05.png --]
[-- Type: image/png, Size: 18631 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-08-02 15:53                   ` Tamas K Lengyel
@ 2016-08-05 11:35                     ` sepanta s
  2016-08-05 18:15                       ` Tamas K Lengyel
  0 siblings, 1 reply; 14+ messages in thread
From: sepanta s @ 2016-08-05 11:35 UTC (permalink / raw)
  To: Tamas K Lengyel; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1.1: Type: text/plain, Size: 5092 bytes --]

On Tue, Aug 2, 2016 at 8:23 PM, Tamas K Lengyel <tamas@tklengyel.com> wrote:

>
>
> On Tue, Aug 2, 2016 at 12:19 AM, sepanta s <sapanta992@gmail.com> wrote:
>
>>
>>
>> On Sat, Jul 23, 2016 at 3:49 PM, sepanta s <sapanta992@gmail.com> wrote:
>>
>>>
>>>>> 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?
>>>>>
>>>>
>>>> Not sure what ring_page you are talking about, but if you mark the
>>>> pages read-only with mem_access you will get notifications for events that
>>>> lead to unsharing with p2m_ram_shared type pages as well.
>>>>
>>>
>>> There was a function in mem-sharing.c which is intended to announce the
>>> failed unshared pages. It is "mem_sharing_notify_enomem" .
>>> I added "mem_sharing_notify_unshare" as a new function and call it in
>>> also XEN_DOMCTL_VM_EVENT_OP_UNSHARING and "HVM_PARAM_USHARING_RING_PFN".
>>> I also added the required codes in /xen/common/vm_event.c and
>>> /tools/libxc/xc_vm_event so as
>>> I have added a new event for the unsharing actions of a page.
>>> Then, I wrote a sample code line xen-access and create a ring for the
>>> pages of a domain and listen to unshared events of it.
>>>
>>>>
>>>>> 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);*
>>>>> *}*
>>>>>
>>>>>
>>>> IMHO this duplicates a lot of what mem_access does already, I don't
>>>> think there is a need for a separate notification on another ring.
>>>>
>>>>
>>> You are right, xen-access should work but I couldn't change its code and
>>> couldn't get the mem-access events.
>>>  I just added the above function to be sure that unsharing a page
>>> happens and works fine. Because I couldn't get the access requests on
>>> shared-pages of a vm.
>>> In xen-access, Instead of setting all the pages' default access to rx ,
>>> I just call xc_set_mem_access for the pages with p2m_ram_shared and assign
>>> rx as the default access but there is no requests on this ring.
>>>
>>>>
>>>
>>> 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.
>>>>>
>>>>
>>>> Yes, I would say that's expected.
>>>>
>>>
>>>>
>>>>> When I do the sharing one more time, there is not any pages unshared
>>>>> as the total number of shared pages stay the same.
>>>>>
>>>>
>>>> Well, if you let the domain run for a while after sharing, then you do
>>>> the sharing like that again you are likely going to crash the VM.
>>>>
>>>>
>>>>> 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 ?
>>>>>
>>>>
>>>> I would guess the the VM crashed and that's why you don't see any more
>>>> unsharing at that point.
>>>>
>>> Yes it was crashed as I checked it.
>>> The scenario of sharing is I use:
>>> I pause the origin VM and then run memshrtool on origin VM and clone VM.
>>> After sharing all the pages between these two VMs,Clone VM seems to be
>>> inaccessible. The clone seems to work as the attached photo shows, its cpu
>>> time increases and it exceeds the dom0 cpu time but when I use gvncviewer
>>> to see the GUI of the Clone VM, the mouse or keyboard don't work. (origin
>>> VM is ubunut-64-1 and clone VM is ubuntu-64-clone-1). Is there anything I
>>> have missed in sharing between two VMs?
>>>
>>> [image: Inline image 2]
>>>
>>
>> Can someone help please ? still have problem with the machine .
>> is it because sharing is not based on content?
>>
>>
> Well, the emulated device contexts probably get all messed up when you
> just clone over the memory of the domain and that's why they don't work.
> The only way I got this to work is by doing a save/restore of the origin
> domain before doing the memory sharing.
>
> Tamas
>
I do so , as I use the following commands to create the clone :
xl save -c origin-domid /tmp/clone
xl restore -p -e  /etc/xen/clone.config  /tmp/clone
Also I keep the origin and clone both unpaused before sharing and after
that, I just unpause the clone , but I
can just run some commands and then the clone stops responding to mouse
operations.
My vms are both ubuntu-14.04 LTS.

[-- Attachment #1.1.2: Type: text/html, Size: 11385 bytes --]

[-- Attachment #1.2: Screenshot from 2016-07-23 15_19_05.png --]
[-- Type: image/png, Size: 18631 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-08-05 11:35                     ` sepanta s
@ 2016-08-05 18:15                       ` Tamas K Lengyel
  2016-08-05 18:26                         ` sepanta s
  0 siblings, 1 reply; 14+ messages in thread
From: Tamas K Lengyel @ 2016-08-05 18:15 UTC (permalink / raw)
  To: sepanta s; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1: Type: text/plain, Size: 5763 bytes --]

On Fri, Aug 5, 2016 at 5:35 AM, sepanta s <sapanta992@gmail.com> wrote:

>
>
> On Tue, Aug 2, 2016 at 8:23 PM, Tamas K Lengyel <tamas@tklengyel.com>
> wrote:
>
>>
>>
>> On Tue, Aug 2, 2016 at 12:19 AM, sepanta s <sapanta992@gmail.com> wrote:
>>
>>>
>>>
>>> On Sat, Jul 23, 2016 at 3:49 PM, sepanta s <sapanta992@gmail.com> wrote:
>>>
>>>>
>>>>>> 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?
>>>>>>
>>>>>
>>>>> Not sure what ring_page you are talking about, but if you mark the
>>>>> pages read-only with mem_access you will get notifications for events that
>>>>> lead to unsharing with p2m_ram_shared type pages as well.
>>>>>
>>>>
>>>> There was a function in mem-sharing.c which is intended to announce the
>>>> failed unshared pages. It is "mem_sharing_notify_enomem" .
>>>> I added "mem_sharing_notify_unshare" as a new function and call it in
>>>> also XEN_DOMCTL_VM_EVENT_OP_UNSHARING and "HVM_PARAM_USHARING_RING_PFN".
>>>> I also added the required codes in /xen/common/vm_event.c and
>>>> /tools/libxc/xc_vm_event so as
>>>> I have added a new event for the unsharing actions of a page.
>>>> Then, I wrote a sample code line xen-access and create a ring for the
>>>> pages of a domain and listen to unshared events of it.
>>>>
>>>>>
>>>>>> 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);*
>>>>>> *}*
>>>>>>
>>>>>>
>>>>> IMHO this duplicates a lot of what mem_access does already, I don't
>>>>> think there is a need for a separate notification on another ring.
>>>>>
>>>>>
>>>> You are right, xen-access should work but I couldn't change its code
>>>> and couldn't get the mem-access events.
>>>>  I just added the above function to be sure that unsharing a page
>>>> happens and works fine. Because I couldn't get the access requests on
>>>> shared-pages of a vm.
>>>> In xen-access, Instead of setting all the pages' default access to rx ,
>>>> I just call xc_set_mem_access for the pages with p2m_ram_shared and assign
>>>> rx as the default access but there is no requests on this ring.
>>>>
>>>>>
>>>>
>>>> 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.
>>>>>>
>>>>>
>>>>> Yes, I would say that's expected.
>>>>>
>>>>
>>>>>
>>>>>> When I do the sharing one more time, there is not any pages unshared
>>>>>> as the total number of shared pages stay the same.
>>>>>>
>>>>>
>>>>> Well, if you let the domain run for a while after sharing, then you do
>>>>> the sharing like that again you are likely going to crash the VM.
>>>>>
>>>>>
>>>>>> 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 ?
>>>>>>
>>>>>
>>>>> I would guess the the VM crashed and that's why you don't see any more
>>>>> unsharing at that point.
>>>>>
>>>> Yes it was crashed as I checked it.
>>>> The scenario of sharing is I use:
>>>> I pause the origin VM and then run memshrtool on origin VM and clone
>>>> VM. After sharing all the pages between these two VMs,Clone VM seems to be
>>>> inaccessible. The clone seems to work as the attached photo shows, its cpu
>>>> time increases and it exceeds the dom0 cpu time but when I use gvncviewer
>>>> to see the GUI of the Clone VM, the mouse or keyboard don't work. (origin
>>>> VM is ubunut-64-1 and clone VM is ubuntu-64-clone-1). Is there anything I
>>>> have missed in sharing between two VMs?
>>>>
>>>> [image: Inline image 2]
>>>>
>>>
>>> Can someone help please ? still have problem with the machine .
>>> is it because sharing is not based on content?
>>>
>>>
>> Well, the emulated device contexts probably get all messed up when you
>> just clone over the memory of the domain and that's why they don't work.
>> The only way I got this to work is by doing a save/restore of the origin
>> domain before doing the memory sharing.
>>
>> Tamas
>>
> I do so , as I use the following commands to create the clone :
> xl save -c origin-domid /tmp/clone
> xl restore -p -e  /etc/xen/clone.config  /tmp/clone
> Also I keep the origin and clone both unpaused before sharing and after
> that, I just unpause the clone , but I
> can just run some commands and then the clone stops responding to mouse
> operations.
> My vms are both ubuntu-14.04 LTS.
>

I guess you mean you keep both of them paused before sharing, and after
sharing you only unpause the clone. I'm not sure xl save -c will keep the
domain paused after it is saved though. Also, in my experience you have to
restore _both_ the origin and the clone domain from a save state for this
to work flawlessly. Underlying reason for this is unknown, I haven't
investigated further into it after finding at least one way to get it
working.

Tamas

[-- Attachment #1.2: Type: text/html, Size: 12282 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: monitor access to pages with a specific p2m_type_t
  2016-08-05 18:15                       ` Tamas K Lengyel
@ 2016-08-05 18:26                         ` sepanta s
  0 siblings, 0 replies; 14+ messages in thread
From: sepanta s @ 2016-08-05 18:26 UTC (permalink / raw)
  To: Tamas K Lengyel; +Cc: George Dunlap, Razvan Cojocaru, xen-devel@lists.xen.org


[-- Attachment #1.1: Type: text/plain, Size: 6143 bytes --]

On Fri, Aug 5, 2016 at 10:45 PM, Tamas K Lengyel <tamas@tklengyel.com>
wrote:

>
>
> On Fri, Aug 5, 2016 at 5:35 AM, sepanta s <sapanta992@gmail.com> wrote:
>
>>
>>
>> On Tue, Aug 2, 2016 at 8:23 PM, Tamas K Lengyel <tamas@tklengyel.com>
>> wrote:
>>
>>>
>>>
>>> On Tue, Aug 2, 2016 at 12:19 AM, sepanta s <sapanta992@gmail.com> wrote:
>>>
>>>>
>>>>
>>>> On Sat, Jul 23, 2016 at 3:49 PM, sepanta s <sapanta992@gmail.com>
>>>> wrote:
>>>>
>>>>>
>>>>>>> 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?
>>>>>>>
>>>>>>
>>>>>> Not sure what ring_page you are talking about, but if you mark the
>>>>>> pages read-only with mem_access you will get notifications for events that
>>>>>> lead to unsharing with p2m_ram_shared type pages as well.
>>>>>>
>>>>>
>>>>> There was a function in mem-sharing.c which is intended to announce
>>>>> the failed unshared pages. It is "mem_sharing_notify_enomem" .
>>>>> I added "mem_sharing_notify_unshare" as a new function and call it in
>>>>> also XEN_DOMCTL_VM_EVENT_OP_UNSHARING and "HVM_PARAM_USHARING_RING_PFN".
>>>>> I also added the required codes in /xen/common/vm_event.c and
>>>>> /tools/libxc/xc_vm_event so as
>>>>> I have added a new event for the unsharing actions of a page.
>>>>> Then, I wrote a sample code line xen-access and create a ring for the
>>>>> pages of a domain and listen to unshared events of it.
>>>>>
>>>>>>
>>>>>>> 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);*
>>>>>>> *}*
>>>>>>>
>>>>>>>
>>>>>> IMHO this duplicates a lot of what mem_access does already, I don't
>>>>>> think there is a need for a separate notification on another ring.
>>>>>>
>>>>>>
>>>>> You are right, xen-access should work but I couldn't change its code
>>>>> and couldn't get the mem-access events.
>>>>>  I just added the above function to be sure that unsharing a page
>>>>> happens and works fine. Because I couldn't get the access requests on
>>>>> shared-pages of a vm.
>>>>> In xen-access, Instead of setting all the pages' default access to rx
>>>>> , I just call xc_set_mem_access for the pages with p2m_ram_shared and
>>>>> assign rx as the default access but there is no requests on this ring.
>>>>>
>>>>>>
>>>>>
>>>>> 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.
>>>>>>>
>>>>>>
>>>>>> Yes, I would say that's expected.
>>>>>>
>>>>>
>>>>>>
>>>>>>> When I do the sharing one more time, there is not any pages unshared
>>>>>>> as the total number of shared pages stay the same.
>>>>>>>
>>>>>>
>>>>>> Well, if you let the domain run for a while after sharing, then you
>>>>>> do the sharing like that again you are likely going to crash the VM.
>>>>>>
>>>>>>
>>>>>>> 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 ?
>>>>>>>
>>>>>>
>>>>>> I would guess the the VM crashed and that's why you don't see any
>>>>>> more unsharing at that point.
>>>>>>
>>>>> Yes it was crashed as I checked it.
>>>>> The scenario of sharing is I use:
>>>>> I pause the origin VM and then run memshrtool on origin VM and clone
>>>>> VM. After sharing all the pages between these two VMs,Clone VM seems to be
>>>>> inaccessible. The clone seems to work as the attached photo shows, its cpu
>>>>> time increases and it exceeds the dom0 cpu time but when I use gvncviewer
>>>>> to see the GUI of the Clone VM, the mouse or keyboard don't work. (origin
>>>>> VM is ubunut-64-1 and clone VM is ubuntu-64-clone-1). Is there anything I
>>>>> have missed in sharing between two VMs?
>>>>>
>>>>> [image: Inline image 2]
>>>>>
>>>>
>>>> Can someone help please ? still have problem with the machine .
>>>> is it because sharing is not based on content?
>>>>
>>>>
>>> Well, the emulated device contexts probably get all messed up when you
>>> just clone over the memory of the domain and that's why they don't work.
>>> The only way I got this to work is by doing a save/restore of the origin
>>> domain before doing the memory sharing.
>>>
>>> Tamas
>>>
>> I do so , as I use the following commands to create the clone :
>> xl save -c origin-domid /tmp/clone
>> xl restore -p -e  /etc/xen/clone.config  /tmp/clone
>> Also I keep the origin and clone both unpaused before sharing and after
>> that, I just unpause the clone , but I
>> can just run some commands and then the clone stops responding to mouse
>> operations.
>> My vms are both ubuntu-14.04 LTS.
>>
>
> I guess you mean you keep both of them paused before sharing, and after
> sharing you only unpause the clone.
>

yes, that's true. What is the correct procedure for sharing two machines?


> I'm not sure xl save -c will keep the domain paused after it is saved
> though.
>
No it doesn't, so as I use xl save -p


> Also, in my experience you have to restore _both_ the origin and the clone
> domain from a save state for this to work flawlessly.
>


> Underlying reason for this is unknown, I haven't investigated further into
> it after finding at least one way to get it working.
>
> Tamas
>

[-- Attachment #1.2: Type: text/html, Size: 13509 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-08-05 18:26 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-22 11:38 monitor access to pages with a specific p2m_type_t sepanta s
2016-06-24 11:05 ` George Dunlap
2016-06-24 11:20   ` Razvan Cojocaru
2016-06-24 15:40     ` Tamas K Lengyel
2016-06-26 12:45       ` sepanta s
2016-07-10 12:20         ` sepanta s
2016-07-11 12:25           ` sepanta s
2016-07-12 18:26             ` Tamas K Lengyel
2016-07-23 11:19               ` sepanta s
2016-08-02  6:19                 ` sepanta s
2016-08-02 15:53                   ` Tamas K Lengyel
2016-08-05 11:35                     ` sepanta s
2016-08-05 18:15                       ` Tamas K Lengyel
2016-08-05 18:26                         ` sepanta s

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).