Skip to contentSkip to conversation

vm_event: sync domctl

PATCH In review Tamas K Lengyel 5 participants 21 messages Dec 23, 2015 – Jan 12, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 vm_event: sync domctl

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be paused, thus allowing the subscriber to sync up on the state of the domain. This is especially useful when the subscribed wants to disable certain events from being delivered and wants to ensure no more requests are pending on the ring before doing so.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru <[email protected]>
---
 tools/libxc/include/xenctrl.h | 11 +++++++++++
 tools/libxc/xc_vm_event.c     | 16 ++++++++++++++++
 xen/common/vm_event.c         | 23 +++++++++++++++++++++++
 xen/include/public/domctl.h   | 14 +++++++++++++-
 4 files changed, 63 insertions(+), 1 deletion(-)
tools/libxc/include/xenctrl.h +11 -0
index 01a6dda..27bb907 100644
@@ -2433,6 +2433,17 @@ int xc_monitor_emulate_each_rep(xc_interface *xch, domid_t domain_id,
                                 bool enable);
 
 /***
+ * xc_vm_event_sync_on can be used by a vm_event subscriber to pause all vCPUs
+ * that do not currently have a pending vm_event request. This allows the
+ * subscriber to sync up on the domain's status and process all outstanding
+ * vm_event requests without any new ones being placed on the ring. A caller
+ * of xc_vm_event_sync_on can resume these vCPUs by calling
+ * xc_vm_event_sync_off.
+ */
+int xc_vm_event_sync_on(xc_interface *xch, domid_t domain_id);
+int xc_vm_event_sync_off(xc_interface *xch, domid_t domain_id);
+
+/***
  * Memory sharing operations.
  *
  * Unles otherwise noted, these calls return 0 on succes, -1 and errno on
tools/libxc/xc_vm_event.c +16 -0
index 2fef96a..6b39908 100644
@@ -156,3 +156,19 @@ void *xc_vm_event_enable(xc_interface *xch, domid_t domain_id, int param,
 
     return ring_page;
 }
+
+int xc_vm_event_sync_on(xc_interface *xch, domid_t domain_id)
+{
+    return xc_vm_event_control(xch, domain_id,
+                               XEN_VM_EVENT_ENABLE,
+                               XEN_DOMCTL_VM_EVENT_OP_SYNC,
+                               NULL);
+}
+
+int xc_vm_event_sync_off(xc_interface *xch, domid_t domain_id)
+{
+    return xc_vm_event_control(xch, domain_id,
+                               XEN_VM_EVENT_DISABLE,
+                               XEN_DOMCTL_VM_EVENT_OP_SYNC,
+                               NULL);
+}
xen/common/vm_event.c +23 -0
index 28a7add..b8298bd 100644
@@ -726,6 +726,29 @@ int vm_event_domctl(struct domain *d, xen_domctl_vm_event_op_t *vec,
     break;
 #endif
 
+    case XEN_DOMCTL_VM_EVENT_OP_SYNC:
+    {
+        struct vcpu *v;
+        rc = 0;
+
+        switch( vec->op )
+        {
+        case XEN_VM_EVENT_ENABLE:
+            for_each_vcpu( d, v )
+                if ( !atomic_read(&v->vm_event_pause_count) )
+                    vcpu_pause(v);
+            break;
+
+        default:
+            for_each_vcpu( d, v )
+                if ( !atomic_read(&v->vm_event_pause_count) )
+                    vcpu_unpause(v);
+            break;
+        };
+    }
+    break;
+
+
     default:
         rc = -ENOSYS;
     }
xen/include/public/domctl.h +13 -1
index 7a56b3f..486c667 100644
@@ -749,7 +749,8 @@ struct xen_domctl_gdbsx_domstatus {
  * sharing, monitor and paging. This hypercall allows one to
  * control these rings (enable/disable), as well as to signal
  * to the hypervisor to pull responses (resume) from the given
- * ring.
+ * ring. Sync will pause/unpause all vCPUs which don't have
+ * a pending vm_event.
  */
 #define XEN_VM_EVENT_ENABLE               0
 #define XEN_VM_EVENT_DISABLE              1
@@ -810,6 +811,17 @@ struct xen_domctl_gdbsx_domstatus {
  */
 #define XEN_DOMCTL_VM_EVENT_OP_SHARING           3
 
+/*
+ * SYNC is a special vm_event operation where all vCPUs get paused
+ * to allow the toolstack to sync up with the state of the domain,
+ * without any new vm_event requests being produced by the domain
+ * on any of the rings.
+ * When issued with ENABLE all the vCPUs get paused that aren't
+ * already paused for a vm_event request. When issued with DISABLE
+ * or RESUME the vCPUs without a pending vm_event request get unpaused.
+ */
+#define XEN_DOMCTL_VM_EVENT_OP_SYNC           4
+
 /* Use for teardown/setup of helper<->hypervisor interface for paging, 
  * access and sharing.*/
 struct xen_domctl_vm_event_op {
Signature · 1 line
2.1.4
#1 lore raw

PATCH 2/2 vm_event: Add altp2m info to HVM events as well

Add altp2m information to HVM events as well when altp2m is active.

Cc Razvan Cojocaru <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/event.c | 7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/x86/hvm/event.c +7 -0
index 73c8f14..a3d4892 100644
@@ -22,6 +22,7 @@
 #include <xen/paging.h>
 #include <asm/hvm/event.h>
 #include <asm/monitor.h>
+#include <asm/altp2m.h>
 #include <public/vm_event.h>
 
 static void hvm_event_fill_regs(vm_event_request_t *req)
@@ -83,6 +84,12 @@ static int hvm_event_traps(uint8_t sync, vm_event_request_t *req)
         vm_event_vcpu_pause(curr);
     }
 
+    if ( altp2m_active(currd) )
+    {
+        req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M;
+        req->altp2m_idx = vcpu_altp2m(curr).p2midx;
+    }
+
     hvm_event_fill_regs(req);
     vm_event_put_request(currd, &currd->vm_event->monitor, req);
 
Signature · 1 line
2.1.4
Acked-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] vm_event: Add altp2m info to HVM events as well

Quoted 10 lines · Tamas K Lengyel

Add altp2m information to HVM events as well when altp2m is active.

Cc Razvan Cojocaru <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/event.c | 7 +++++++
 1 file changed, 7 insertions(+)

Thanks,
Razvan

Reviewed-by
#3 lore raw

Re: [PATCH 2/2] vm_event: Add altp2m info to HVM events as well

Quoted 11 lines · Razvan Cojocaru
Quoted 10 lines · Tamas K Lengyel

Add altp2m information to HVM events as well when altp2m is active.

Cc Razvan Cojocaru <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Andrew Cooper <[email protected]>
---
 xen/arch/x86/hvm/event.c | 7 +++++++
 1 file changed, 7 insertions(+)
Quoted 1 line
#4 lore raw

Re: [PATCH 2/2] vm_event: Add altp2m info to HVM events as well

In reply to Tamas K Lengyel

xen/arch/x86/hvm/event.c static int hvm_event_traps(uint8_t sync, vm_event_request_t *req) · line 91

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 23.12.15 at 15:53, <[email protected]> wrote:
xen/arch/x86/hvm/event.c +5 -0
@@ -83,6 +84,12 @@ static int hvm_event_traps(uint8_t sync, vm_event_request_t *req)
         vm_event_vcpu_pause(curr);
     }
 
+    if ( altp2m_active(currd) )
+    {
+        req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M;
+        req->altp2m_idx = vcpu_altp2m(curr).p2midx;
+    }

So far this info was provided just for MEM_ACCESS events. Now you provide it for a few more ones, but wouldn't this then better be supplied for all of them, namely also the other two MEM ones?

Jan

#5 lore raw

Re: [PATCH 2/2] vm_event: Add altp2m info to HVM events as well

Quoted 12 lines · Jan Beulich

Review static int hvm_event_traps(uint8_t sync,

Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 23.12.15 at 15:53, <[email protected]> wrote:
(quoted diff) +0 -0
@@ -83,6 +84,12 @@ static int hvm_event_traps(uint8_t sync,

vm_event_request_t *req)

xen/arch/x86/hvm/event.c static int hvm_event_traps(uint8_t sync, vm_event_request_t *req) · line 91

Quoted 8 lines
xen/arch/x86/hvm/event.c +5 -0
         vm_event_vcpu_pause(curr);
     }
 
+    if ( altp2m_active(currd) )
+    {
+        req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M;
+        req->altp2m_idx = vcpu_altp2m(curr).p2midx;
+    }
Quoted 4 lines

So far this info was provided just for MEM_ACCESS events. Now you provide it for a few more ones, but wouldn't this then better be supplied for all of them, namely also the other two MEM ones?

AFAIK altp2m is currently incompatible with sharing. I'm not 100% sure but I think it's also incompatible with paging.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#6 lore raw

Re: [PATCH 2/2] vm_event: Add altp2m info to HVM events as well

Quoted 22 lines · Tamas K Lengyel

Review static int hvm_event_traps(uint8_t sync,

Quoted 2 lines · On Wed, Jan 6, 2016 at 12:32 PM, Jan Beulich <[email protected]…
Quoted 1 line
Quoted 1 line · On 23.12.15 at 15:53, <[email protected] <mailto:[email protected]>> wrote:
(quoted diff) +0 -0
@@ -83,6 +84,12 @@ static int hvm_event_traps(uint8_t sync,
    vm_event_request_t *req)
    >          vm_event_vcpu_pause(curr);
    >      }
    >
    > +    if ( altp2m_active(currd) )
    > +    {
    > +        req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M;
    > +        req->altp2m_idx = vcpu_altp2m(curr).p2midx;
    > +    }

    So far this info was provided just for MEM_ACCESS events. Now
    you provide it for a few more ones, but wouldn't this then better
    be supplied for all of them, namely also the other two MEM ones?
Quoted 2 lines

AFAIK altp2m is currently incompatible with sharing. I'm not 100% sure but I think it's also incompatible with paging.

I don't think they are strictly incompatible; I don't see a technical reason preventing some development work to make them function together.

Whether this happens or not is a very different matter.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#7 lore raw

Re: [PATCH 2/2] vm_event: Add altp2m info to HVM events as well

Quoted 24 lines · Andrew Cooper

On 06/01/16 11:42, Tamas K Lengyel wrote:

Quoted 13 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 23.12.15 at 15:53, < <[email protected]>[email protected]>

Review static int hvm_event_traps(uint8_t sync,

Quoted 1 line · wrote:
(quoted diff) +0 -0
@@ -83,6 +84,12 @@ static int hvm_event_traps(uint8_t sync,

vm_event_request_t *req)

xen/arch/x86/hvm/event.c static int hvm_event_traps(uint8_t sync, vm_event_request_t *req) · line 91

Quoted 8 lines
xen/arch/x86/hvm/event.c +5 -0
         vm_event_vcpu_pause(curr);
     }
 
+    if ( altp2m_active(currd) )
+    {
+        req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M;
+        req->altp2m_idx = vcpu_altp2m(curr).p2midx;
+    }
Quoted 4 lines

So far this info was provided just for MEM_ACCESS events. Now you provide it for a few more ones, but wouldn't this then better be supplied for all of them, namely also the other two MEM ones?

Quoted 9 lines

AFAIK altp2m is currently incompatible with sharing. I'm not 100% sure but I think it's also incompatible with paging.

I don't think they are strictly incompatible; I don't see a technical reason preventing some development work to make them function together.

Whether this happens or not is a very different matter.

Sure, the two systems can be made to work in tandem, this work just hasn't been done yet. I would very much like to get that to work in the future.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#8 lore raw

Re: [PATCH 2/2] vm_event: Add altp2m info to HVM events as well

Quoted 32 lines
Quoted 1 line
Quoted 1 line · On 06.01.16 at 12:50, <[email protected]> wrote:
Quoted 28 lines · Andrew Cooper

On 06/01/16 11:42, Tamas K Lengyel wrote:

Quoted 13 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 23.12.15 at 15:53, < <[email protected]>[email protected]>

Review static int hvm_event_traps(uint8_t sync,

Quoted 1 line · wrote:
(quoted diff) +0 -0
@@ -83,6 +84,12 @@ static int hvm_event_traps(uint8_t sync,

vm_event_request_t *req)

xen/arch/x86/hvm/event.c static int hvm_event_traps(uint8_t sync, vm_event_request_t *req) · line 91

Quoted 8 lines
xen/arch/x86/hvm/event.c +5 -0
         vm_event_vcpu_pause(curr);
     }
 
+    if ( altp2m_active(currd) )
+    {
+        req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M;
+        req->altp2m_idx = vcpu_altp2m(curr).p2midx;
+    }
Quoted 4 lines

So far this info was provided just for MEM_ACCESS events. Now you provide it for a few more ones, but wouldn't this then better be supplied for all of them, namely also the other two MEM ones?

AFAIK altp2m is currently incompatible with sharing. I'm not 100% sure but I think it's also incompatible with paging.

Quoted 7 lines
Quoted 4 lines

I don't think they are strictly incompatible; I don't see a technical reason preventing some development work to make them function together.

Whether this happens or not is a very different matter.

Sure, the two systems can be made to work in tandem, this work just hasn't been done yet. I would very much like to get that to work in the future.

Which re-raises the question: Shouldn't the information then be made available uniformly for all events?

Jan

#9 lore raw

Re: [PATCH 2/2] vm_event: Add altp2m info to HVM events as well

Quoted 3 lines · Jan Beulich
Quoted 3 lines
Quoted 2 lines
Quoted 2 lines · On 06.01.16 at 12:50, <[email protected]> wrote:

On Wed, Jan 6, 2016 at 12:48 PM, Andrew Cooper <

[email protected]>

Quoted 21 lines
Quoted 21 lines
Quoted 19 lines · wrote:

On 06/01/16 11:42, Tamas K Lengyel wrote:

Quoted 13 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line

On 23.12.15 at 15:53, < <[email protected]>[email protected]>

Review static int hvm_event_traps(uint8_t sync,

Quoted 1 line · wrote:
(quoted diff) +0 -0
@@ -83,6 +84,12 @@ static int hvm_event_traps(uint8_t sync,

vm_event_request_t *req)

Quoted 8 lines
xen/arch/x86/hvm/event.c +5 -0
         vm_event_vcpu_pause(curr);
     }
 
+    if ( altp2m_active(currd) )
+    {
+        req->flags |= VM_EVENT_FLAG_ALTERNATE_P2M;
+        req->altp2m_idx = vcpu_altp2m(curr).p2midx;
+    }
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

So far this info was provided just for MEM_ACCESS events. Now you provide it for a few more ones, but wouldn't this then better be supplied for all of them, namely also the other two MEM ones?

AFAIK altp2m is currently incompatible with sharing. I'm not 100% sure

but

Quoted 9 lines
Quoted 9 lines
Quoted 7 lines

I think it's also incompatible with paging.

I don't think they are strictly incompatible; I don't see a technical reason preventing some development work to make them function together.

Whether this happens or not is a very different matter.

Sure, the two systems can be made to work in tandem, this work just

hasn't

Quoted 5 lines
Quoted 1 line

been done yet. I would very much like to get that to work in the future.

Which re-raises the question: Shouldn't the information then be made available uniformly for all events?

IMHO there is no point doing so while the systems don't work together.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#10 lore raw
In reply to Tamas K Lengyel
Quoted 7 lines · Tamas K Lengyel

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be paused, thus allowing the subscriber to sync up on the state of the domain. This is especially useful when the subscribed wants to disable certain events from being delivered and wants to ensure no more requests are pending on the ring before doing so.

Quoted 6 lines
Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru <[email protected]>

This certainly looks very interesting. Would xc_domain_pause() not be enough for your use case then?

Thanks,
Razvan

#11 lore raw
Quoted 8 lines · Razvan Cojocaru
Quoted 7 lines · Tamas K Lengyel

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be paused, thus allowing the subscriber to sync up on the state of the domain. This is especially useful when the subscribed wants to disable certain events from being delivered and wants to ensure no more requests are pending on the ring before doing so.

Quoted 8 lines
Quoted 6 lines
Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru <[email protected]>

This certainly looks very interesting. Would xc_domain_pause() not be enough for your use case then?

I second this query. I would have thought xc_domain_pause() does exactly what you want in this case.

The code provided is racy, as it is liable to alter which pause references it takes/releases depending on what other pause/unpause actions are being made.

~Andrew

#12 lore raw
Quoted 17 lines · Andrew Cooper
Quoted 3 lines · Razvan Cojocaru
Quoted 2 lines · Tamas K Lengyel

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be

paused,

Quoted 3 lines
Quoted 3 lines

thus allowing the subscriber to sync up on the state of the domain. This is especially useful when the subscribed wants to disable certain events from being delivered and wants to ensure no more requests are pending

on the

Quoted 8 lines
Quoted 8 lines

ring before doing so.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru <[email protected]>
Quoted 6 lines
Quoted 2 lines

This certainly looks very interesting. Would xc_domain_pause() not be enough for your use case then?

I second this query. I would have thought xc_domain_pause() does exactly what you want in this case.

The problem is in what order the responses are processed. I may not be correct about the logic but here is what my impression was:
xc_domain_unpause resumes all vCPUs even if there is still a vm_event response that has not been processed. Now, if the subscriber set response flags (altp2m switch, singlestep toggle, etc) those actions would not be properly performed on the vCPU before it's resumed. If the subscriber processes all requests and signals via the event channel that the responses are on the ring, then calls xc_domain_unpause, we can still have a race between processing the responses from the ring and unpausing the vCPU.

Quoted 4 lines

The code provided is racy, as it is liable to alter which pause references it takes/releases depending on what other pause/unpause actions are being made.

It's understood that the user would not use xc_domain_pause/unpause while using vm_event responses with response flags specified. Even then, it was already racy IMHO if the user called xc_domain_unpause before processing requests from the vm_event ring that originally paused the vCPU, so this doesn't change that situation.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#13 lore raw
Quoted 45 lines · Tamas K Lengyel

On Wed, Dec 23, 2015 at 6:17 PM, Andrew Cooper <[email protected] <mailto:[email protected]>> wrote:

On 23/12/2015 15:41, Razvan Cojocaru wrote:
> On 12/23/2015 04:53 PM, Tamas K Lengyel wrote:
>> Introduce new vm_event domctl option which allows an event subscriber >> to request all vCPUs not currently pending a vm_event request to be paused, >> thus allowing the subscriber to sync up on the state of the domain. This >> is especially useful when the subscribed wants to disable certain events >> from being delivered and wants to ensure no more requests are pending on the >> ring before doing so.
>>
>> Cc: Ian Jackson <[email protected] <mailto:[email protected]>> >> Cc: Stefano Stabellini <[email protected] <mailto:[email protected]>>
>> Cc: Ian Campbell <[email protected] <mailto:[email protected]>> >> Cc: Wei Liu <[email protected] <mailto:[email protected]>>
>> Cc: Razvan Cojocaru <[email protected] <mailto:[email protected]>> >> Signed-off-by: Tamas K Lengyel <[email protected] <mailto:[email protected]>> > This certainly looks very interesting. Would xc_domain_pause() not be > enough for your use case then?

I second this query. I would have thought xc_domain_pause() does exactly what you want in this case.

The problem is in what order the responses are processed. I may not be correct about the logic but here is what my impression was:
xc_domain_unpause resumes all vCPUs even if there is still a vm_event response that has not been processed. Now, if the subscriber set response flags (altp2m switch, singlestep toggle, etc) those actions would not be properly performed on the vCPU before it's resumed. If the subscriber processes all requests and signals via the event channel that the responses are on the ring, then calls xc_domain_unpause, we can still have a race between processing the responses from the ring and unpausing the vCPU.

The code provided is racy, as it is liable to alter which pause references it takes/releases depending on what other pause/unpause actions are being made.

Quoted 5 lines

It's understood that the user would not use xc_domain_pause/unpause while using vm_event responses with response flags specified. Even then, it was already racy IMHO if the user called xc_domain_unpause before processing requests from the vm_event ring that originally paused the vCPU, so this doesn't change that situation.

There are a bunch of checks in vcpu_wake() (xen/common/schedule.c) that I've always assumed guard against the problem you're describing. I may be wrong (I don't have any experience with the scheduling code), but even if I am, I still think having xc_domain_pause() / xc_domain_unpause() behave correctly is better than adding a new libxc function. Is that an unreasonable goal?

Thanks,
Razvan

#14 lore raw
In reply to Tamas K Lengyel
Quoted 55 lines · Tamas K Lengyel

On Wed, Dec 23, 2015 at 6:17 PM, Andrew Cooper <[email protected] <mailto:[email protected]>> wrote:

On 23/12/2015 15:41, Razvan Cojocaru wrote:
> On 12/23/2015 04:53 PM, Tamas K Lengyel wrote:
>> Introduce new vm_event domctl option which allows an event subscriber
>> to request all vCPUs not currently pending a vm_event request to be paused,
>> thus allowing the subscriber to sync up on the state of the domain. This
>> is especially useful when the subscribed wants to disable certain events
>> from being delivered and wants to ensure no more requests are pending on the
>> ring before doing so.
>>
>> Cc: Ian Jackson <[email protected] <mailto:[email protected]>>
>> Cc: Stefano Stabellini <[email protected] <mailto:[email protected]>>
>> Cc: Ian Campbell <[email protected] <mailto:[email protected]>>
>> Cc: Wei Liu <[email protected] <mailto:[email protected]>> >> Cc: Razvan Cojocaru <[email protected] <mailto:[email protected]>>
>> Signed-off-by: Tamas K Lengyel <[email protected] <mailto:[email protected]>>
> This certainly looks very interesting. Would xc_domain_pause() not be
> enough for your use case then?

I second this query. I would have thought xc_domain_pause() does exactly what you want in this case.

The problem is in what order the responses are processed. I may not be correct about the logic but here is what my impression was:
xc_domain_unpause resumes all vCPUs even if there is still a vm_event response that has not been processed. Now, if the subscriber set response flags (altp2m switch, singlestep toggle, etc) those actions would not be properly performed on the vCPU before it's resumed. If the subscriber processes all requests and signals via the event channel that the responses are on the ring, then calls xc_domain_unpause, we can still have a race between processing the responses from the ring and unpausing the vCPU.

The code provided is racy, as it is liable to alter which pause references it takes/releases depending on what other pause/unpause actions are being made.

Quoted 5 lines

It's understood that the user would not use xc_domain_pause/unpause while using vm_event responses with response flags specified. Even then, it was already racy IMHO if the user called xc_domain_unpause before processing requests from the vm_event ring that originally paused the vCPU, so this doesn't change that situation.

Pausing is strictly reference counted. (or rather, it is since c/s 3eb1c70 "properly reference count DOMCTL_{,un}pausedomain hypercalls". Before then, it definitely was buggy.)

There is the domain pause count, and pause counts per vcpu. All domain pause operations take both a domain pause reference, and a vcpu pause reference on each vcpu. A vcpu is only eligible to be scheduled if its pause reference count is zero. If two independent tasks call vcpu_pause() on the same vcpu, it will remain paused until both independent tasks have called vcpu_unpause().

Having said this, I can well believe that there might be issues with the current uses of pausing.

The vital factor is that the entity which pauses a vcpu is also responsible for unpausing it, and it must be resistant to accidentally leaking its reference.

In this case, I believe that what you want to do is:

1) Identify condition requiring a sync
2) xc_domain_pause()
3) Process all of the pending vm_events
4) Synchronise the state
5) xc_domain_unpause()

All vcpus of the domain should stay descheduled between points 2 and 5. If this doesn't have the intended effect, then I suspect there is a bug in the pause reference handing of the vm_event subsystem.

Is this clearer, or have I misunderstood the problem?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#15 lore raw
Quoted 85 lines · Andrew Cooper

On 23/12/2015 18:11, Tamas K Lengyel wrote:

Quoted 19 lines · Andrew Cooper
Quoted 3 lines · Razvan Cojocaru
Quoted 2 lines · Tamas K Lengyel

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be

paused,

Quoted 1 line
Quoted 1 line

thus allowing the subscriber to sync up on the state of the domain.

This

Quoted 1 line
Quoted 1 line

is especially useful when the subscribed wants to disable certain

events

Quoted 1 line
Quoted 1 line

from being delivered and wants to ensure no more requests are pending

on the

Quoted 4 lines
Quoted 4 lines

ring before doing so.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini < <[email protected]>

[email protected]>

Quoted 3 lines
Quoted 3 lines
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru < <[email protected]>
Quoted 9 lines

[email protected]>

Quoted 1 line
Quoted 1 line

[email protected]>

Quoted 2 lines

This certainly looks very interesting. Would xc_domain_pause() not be enough for your use case then?

I second this query. I would have thought xc_domain_pause() does exactly what you want in this case.

The problem is in what order the responses are processed. I may not be correct about the logic but here is what my impression was:
xc_domain_unpause resumes all vCPUs even if there is still a vm_event response that has not been processed. Now, if the subscriber set response flags (altp2m switch, singlestep toggle, etc) those actions would not be properly performed on the vCPU before it's resumed. If the subscriber processes all requests and signals via the event channel that the responses are on the ring, then calls xc_domain_unpause, we can still have a race between processing the responses from the ring and unpausing the vCPU.

Quoted 4 lines

The code provided is racy, as it is liable to alter which pause references it takes/releases depending on what other pause/unpause actions are being made.

It's understood that the user would not use xc_domain_pause/unpause while using vm_event responses with response flags specified. Even then, it was already racy IMHO if the user called xc_domain_unpause before processing requests from the vm_event ring that originally paused the vCPU, so this doesn't change that situation.

Pausing is strictly reference counted. (or rather, it is since c/s 3eb1c70 "properly reference count DOMCTL_{,un}pausedomain hypercalls". Before then, it definitely was buggy.)

There is the domain pause count, and pause counts per vcpu. All domain pause operations take both a domain pause reference, and a vcpu pause reference on each vcpu. A vcpu is only eligible to be scheduled if its pause reference count is zero. If two independent tasks call vcpu_pause() on the same vcpu, it will remain paused until both independent tasks have called vcpu_unpause().

Having said this, I can well believe that there might be issues with the current uses of pausing.

The vital factor is that the entity which pauses a vcpu is also responsible for unpausing it, and it must be resistant to accidentally leaking its reference.

In this case, I believe that what you want to do is:

1) Identify condition requiring a sync
2) xc_domain_pause()
3) Process all of the pending vm_events
4) Synchronise the state
5) xc_domain_unpause()

Quoted 6 lines

All vcpus of the domain should stay descheduled between points 2 and 5. If this doesn't have the intended effect, then I suspect there is a bug in the pause reference handing of the vm_event subsystem.

Is this clearer, or have I misunderstood the problem?

The problem is with step 4&5 IMHO. The event channel notification AFAIK is asynchronous in that it just starts the processing of the pending vm_event responses and returns, doesn't wait for the responses to be all processed. Now if we progress to step 5, we might still have some responses on the ring which have not gotten processed yet, so there is a race-condition. There is currently no way to get a notification when all responses have been processed, so the best thing we can do is to make sure we can pause/unpause vCPUs without pending requests/responses as those are safe to be resumed, while restricting the other vCPUs to be only unpaused through the pending vm_event response. I hope this make sense.

That being said, I haven't yet encountered an instance where this racecondition was lost, so this is just a pre-caution.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#16 lore raw
Quoted 66 lines · Tamas K Lengyel
Quoted 60 lines · Andrew Cooper

On 23/12/2015 18:11, Tamas K Lengyel wrote:

On Wed, Dec 23, 2015 at 6:17 PM, Andrew Cooper <[email protected]

Quoted 21 lines

wrote:

Quoted 3 lines · Razvan Cojocaru
Quoted 2 lines · Tamas K Lengyel

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be

paused,

Quoted 1 line
Quoted 1 line

thus allowing the subscriber to sync up on the state of the domain.

This

Quoted 1 line
Quoted 1 line

is especially useful when the subscribed wants to disable certain

events

Quoted 1 line
Quoted 1 line

from being delivered and wants to ensure no more requests are pending

on the

Quoted 8 lines
Quoted 8 lines

ring before doing so.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru <[email protected]>
Quoted 6 lines
Quoted 2 lines

This certainly looks very interesting. Would xc_domain_pause() not be enough for your use case then?

I second this query. I would have thought xc_domain_pause() does exactly what you want in this case.

The problem is in what order the responses are processed. I may not be correct about the logic but here is what my impression was:
xc_domain_unpause resumes all vCPUs even if there is still a vm_event response that has not been processed. Now, if the subscriber set response flags (altp2m switch, singlestep toggle, etc) those actions would not be properly performed on the vCPU before it's resumed. If the subscriber processes all requests and signals via the event channel that the responses are on the ring, then calls xc_domain_unpause, we can still have a race between processing the responses from the ring and unpausing the vCPU.

Quoted 4 lines

The code provided is racy, as it is liable to alter which pause references it takes/releases depending on what other pause/unpause actions are being made.

It's understood that the user would not use xc_domain_pause/unpause while using vm_event responses with response flags specified. Even then, it was already racy IMHO if the user called xc_domain_unpause before processing requests from the vm_event ring that originally paused the vCPU, so this doesn't change that situation.

Pausing is strictly reference counted. (or rather, it is since c/s 3eb1c70 "properly reference count DOMCTL_{,un}pausedomain hypercalls". Before then, it definitely was buggy.)

Quoted 8 lines
Quoted 7 lines

There is the domain pause count, and pause counts per vcpu. All domain pause operations take both a domain pause reference, and a vcpu pause reference on each vcpu. A vcpu is only eligible to be scheduled if its pause reference count is zero. If two independent tasks call vcpu_pause() on the same vcpu, it will remain paused until both independent tasks have called vcpu_unpause().

Actually, I've double-checked and v->pause_count and v->vm_event_pause_count are both increased for a vm_event request. So you are right, the reference counting will make sure that v->pause_count > 0 until we process the vm_event response and call xc_domain_unpause. I was under the impression that wasn't the case. We can ignore this patch.

Thanks and sorry for the noise ;)
Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#17 lore raw
Quoted 94 lines · Tamas K Lengyel

On Wed, Dec 23, 2015 at 9:55 PM, Tamas K Lengyel <[email protected] <mailto:[email protected]>> wrote:

    On Wed, Dec 23, 2015 at 8:14 PM, Andrew Cooper
    <[email protected] <mailto:[email protected]>> wrote:

        On 23/12/2015 18:11, Tamas K Lengyel wrote:
Quoted 62 lines

On Wed, Dec 23, 2015 at 6:17 PM, Andrew Cooper <[email protected] <mailto:[email protected]>> wrote:

On 23/12/2015 15:41, Razvan Cojocaru wrote:
> On 12/23/2015 04:53 PM, Tamas K Lengyel wrote:
>> Introduce new vm_event domctl option which allows an event subscriber
>> to request all vCPUs not currently pending a vm_event request to be paused,
>> thus allowing the subscriber to sync up on the state of the domain. This
>> is especially useful when the subscribed wants to disable certain events
>> from being delivered and wants to ensure no more requests are pending on the
>> ring before doing so.
>>
>> Cc: Ian Jackson <[email protected] <mailto:[email protected]>>
>> Cc: Stefano Stabellini <[email protected] <mailto:[email protected]>>
>> Cc: Ian Campbell <[email protected] <mailto:[email protected]>>
>> Cc: Wei Liu <[email protected] <mailto:[email protected]>>
>> Cc: Razvan Cojocaru <[email protected] <mailto:[email protected]>>
>> Signed-off-by: Tamas K Lengyel <[email protected] <mailto:[email protected]>>
> This certainly looks very interesting. Would xc_domain_pause() not be
> enough for your use case then?

I second this query. I would have thought xc_domain_pause() does
exactly what you want in this case.

The problem is in what order the responses are processed. I may not be correct about the logic but here is what my impression was: xc_domain_unpause resumes all vCPUs even if there is still a vm_event response that has not been processed. Now, if the subscriber set response flags (altp2m switch, singlestep toggle, etc) those actions would not be properly performed on the vCPU before it's resumed. If the subscriber processes all requests and signals via the event channel that the responses are on the ring, then calls xc_domain_unpause, we can still have a race between processing the responses from the ring and unpausing the vCPU.

The code provided is racy, as it is liable to alter which pause
references it takes/releases depending on what other pause/unpause
actions are being made.

Quoted 6 lines

It's understood that the user would not use xc_domain_pause/unpause while using vm_event responses with response flags specified. Even then, it was already racy IMHO if the user called xc_domain_unpause before processing requests from the vm_event ring that originally paused the vCPU, so this doesn't change that situation.

Pausing is strictly reference counted. (or rather, it is since c/s 3eb1c70 "properly reference count DOMCTL_{,un}pausedomain hypercalls". Before then, it definitely was buggy.)

There is the domain pause count, and pause counts per vcpu. All domain pause operations take both a domain pause reference, and a vcpu pause reference on each vcpu. A vcpu is only eligible to be scheduled if its pause reference count is zero. If two independent tasks call vcpu_pause() on the same vcpu, it will remain paused until both independent tasks have called vcpu_unpause().

Quoted 8 lines

Actually, I've double-checked and v->pause_count and v->vm_event_pause_count are both increased for a vm_event request. So you are right, the reference counting will make sure that v->pause_count > 0 until we process the vm_event response and call xc_domain_unpause. I was under the impression that wasn't the case. We can ignore this patch.

Thanks and sorry for the noise ;)

Not a problem at all. This is complicated stuff, and IMO it was equally as likely that there was a real bug lurking.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v1 1/2
#18 lore raw
In reply to Tamas K Lengyel
Quoted 15 lines · Tamas K Lengyel

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be paused,
thus allowing the subscriber to sync up on the state of the domain. This is especially useful when the subscribed wants to disable certain events from being delivered and wants to ensure no more requests are pending on the
ring before doing so.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru <[email protected]>
Quoted 3 lines

---
 tools/libxc/include/xenctrl.h | 11 +++++++++++ tools/libxc/xc_vm_event.c     | 16 ++++++++++++++++

Tools side is pretty trivial, assuming there is agreement on the underlying hypercall interface:

Quoted 2 lines

+/***
  * Memory sharing operations.

Do you also maintain this? If so do you fancy sending a patch to fix:

Quoted 2 lines

  *
  * Unles otherwise noted, these calls return 0 on succes, -1 and errno on

"Unless" and "success" ?

Ian..

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#19 lore raw
Quoted 20 lines · Ian Campbell
Quoted 15 lines · Tamas K Lengyel

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be paused,
thus allowing the subscriber to sync up on the state of the domain. This is especially useful when the subscribed wants to disable certain events from being delivered and wants to ensure no more requests are pending on the
ring before doing so.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru <[email protected]>
Quoted 3 lines
---
 tools/libxc/include/xenctrl.h | 11 +++++++++++
 tools/libxc/xc_vm_event.c     | 16 ++++++++++++++++
Quoted 5 lines

Tools side is pretty trivial, assuming there is agreement on the underlying hypercall interface:

Thanks, we've decided that this patch is actually not needed as the pause reference count is already good enough.

Quoted 4 lines
Quoted 3 lines

+/***
* Memory sharing operations.

Quoted 8 lines

Do you also maintain this? If so do you fancy sending a patch to fix:

Quoted 2 lines

*
* Unles otherwise noted, these calls return 0 on succes, -1 and errno

on

"Unless" and "success" ?

Sure, that could be done in a separate patch. IMHO the whole sharing subsystem could use a cleanup series of its own to fix things like this, style issues and whatnot.

Tamas

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#20 lore raw
Quoted 27 lines · Tamas K Lengyel
Quoted 23 lines · Ian Campbell
Quoted 4 lines · Tamas K Lengyel

Introduce new vm_event domctl option which allows an event subscriber to request all vCPUs not currently pending a vm_event request to be paused,
thus allowing the subscriber to sync up on the state of the domain.

This

Quoted 1 line

is especially useful when the subscribed wants to disable certain

events

Quoted 1 line

from being delivered and wants to ensure no more requests are pending

on

Quoted 12 lines

the
ring before doing so.

Cc Ian Jackson <[email protected]>
Cc Stefano Stabellini <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Wei Liu <[email protected]>
Cc Razvan Cojocaru <[email protected]>

---
 tools/libxc/include/xenctrl.h | 11 +++++++++++ tools/libxc/xc_vm_event.c     | 16 ++++++++++++++++

Quoted 7 lines
Quoted 5 lines

Tools side is pretty trivial, assuming there is agreement on the underlying
hypercall interface:

Thanks, we've decided that this patch is actually not needed as the pause reference count is already good enough.

OK, thanks.

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

+/***
  * Memory sharing operations.

Do you also maintain this? If so do you fancy sending a patch to fix:

Quoted 7 lines
Quoted 6 lines
Quoted 2 lines

  *
  * Unles otherwise noted, these calls return 0 on succes, -1 and

errno on

"Unless" and "success" ?

Sure, that could be done in a separate patch.

Yes, that's what I intended.

Quoted 2 lines

IMHO the whole sharing subsystem could use a cleanup series of its own
to fix things like this, style issues and whatnot.

Ian.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel