Skip to contentSkip to conversation

common/vm_event: Initialize vm_event lists on domain creation

PATCH In review Razvan Cojocaru 5 participants 15 messages Jun 26, 2017 – Jun 27, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 common/vm_event: Initialize vm_event lists on domain creation

Pending livepatch code wants to check if the vm_event wait queues are active, and this is made harder by the fact that they were previously only initialized some time after the domain was created, in vm_event_enable(). This patch initializes the lists immediately after xzalloc()ating the vm_event memory, in domain_create(), in the newly added init_domain_vm_event() function.

---
 xen/common/domain.c        |  5 ++---
 xen/common/vm_event.c      | 23 ++++++++++++++++++++---
 xen/include/xen/vm_event.h |  2 ++
 3 files changed, 24 insertions(+), 6 deletions(-)
xen/common/domain.c +2 -3
index b22aacc..89a8f1d 100644
@@ -362,11 +362,10 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
 
         poolid = 0;
 
-        err = -ENOMEM;
-        d->vm_event = xzalloc(struct vm_event_per_domain);
-        if ( !d->vm_event )
+        if ( (err = init_domain_vm_event(d)) != 0 )
             goto fail;
 
+        err = -ENOMEM;
         d->pbuf = xzalloc_array(char, DOMAIN_PBUF_SIZE);
         if ( !d->pbuf )
             goto fail;
xen/common/vm_event.c +20 -3
index 9291db6..294ddd7 100644
@@ -39,6 +39,26 @@
 #define vm_event_ring_lock(_ved)       spin_lock(&(_ved)->ring_lock)
 #define vm_event_ring_unlock(_ved)     spin_unlock(&(_ved)->ring_lock)
 
+int init_domain_vm_event(struct domain *d)
+{
+    d->vm_event = xzalloc(struct vm_event_per_domain);
+
+    if ( !d->vm_event )
+        return -ENOMEM;
+
+#ifdef CONFIG_HAS_MEM_PAGING
+    init_waitqueue_head(&d->vm_event->paging.wq);
+#endif
+
+    init_waitqueue_head(&d->vm_event->monitor.wq);
+
+#ifdef CONFIG_HAS_MEM_SHARING
+    init_waitqueue_head(&d->vm_event->share.wq);
+#endif
+
+    return 0;
+}
+
 static int vm_event_enable(
     struct domain *d,
     xen_domctl_vm_event_op_t *vec,
@@ -93,9 +113,6 @@ static int vm_event_enable(
     /* Save the pause flag for this particular ring. */
     ved->pause_flag = pause_flag;
 
-    /* Initialize the last-chance wait queue. */
-    init_waitqueue_head(&ved->wq);
-
     vm_event_ring_unlock(ved);
     return 0;
 
xen/include/xen/vm_event.h +2 -0
index 2fb3951..482243e 100644
@@ -80,6 +80,8 @@ void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp);
 
 void vm_event_monitor_next_interrupt(struct vcpu *v);
 
+int init_domain_vm_event(struct domain *d);
+
 #endif /* __VM_EVENT_H__ */
 
 /*
Signature · 7 lines
1.9.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 2 lines · Razvan Cojocaru

Pending livepatch code wants to check if the vm_event wait queues are active, and this is made harder by the fact that they were

Hmm, it wants to? Is there an missing patch that hasn't been posted for this?

If you mean to post this _before_ the other one please adjust the commit description.

Quoted 85 lines

previously only initialized some time after the domain was created, in vm_event_enable(). This patch initializes the lists immediately after xzalloc()ating the vm_event memory, in domain_create(), in the newly added init_domain_vm_event() function.

---

xen/common/domain.c        |  5 ++---
xen/common/vm_event.c      | 23 ++++++++++++++++++++---
xen/include/xen/vm_event.h |  2 ++
3 files changed, 24 insertions(+), 6 deletions(-)
xen/common/domain.c +2 -3
index b22aacc..89a8f1d 100644
@@ -362,11 +362,10 @@ struct domain *domain_create(domid_t domid,
 unsigned int domcr_flags,
 
        poolid = 0;
 
-        err = -ENOMEM;
-        d->vm_event = xzalloc(struct vm_event_per_domain);
-        if ( !d->vm_event )
+        if ( (err = init_domain_vm_event(d)) != 0 )
            goto fail;
 
+        err = -ENOMEM;
        d->pbuf = xzalloc_array(char, DOMAIN_PBUF_SIZE);
        if ( !d->pbuf )
            goto fail;
xen/common/vm_event.c +20 -0
index 9291db6..294ddd7 100644
@@ -39,6 +39,26 @@
 #define vm_event_ring_lock(_ved)       spin_lock(&(_ved)->ring_lock)
 #define vm_event_ring_unlock(_ved)     spin_unlock(&(_ved)->ring_lock)
 
+int init_domain_vm_event(struct domain *d)
+{
+    d->vm_event = xzalloc(struct vm_event_per_domain);
+
+    if ( !d->vm_event )
+        return -ENOMEM;
+
+#ifdef CONFIG_HAS_MEM_PAGING
+    init_waitqueue_head(&d->vm_event->paging.wq);
+#endif
+
+    init_waitqueue_head(&d->vm_event->monitor.wq);
+
+#ifdef CONFIG_HAS_MEM_SHARING
+    init_waitqueue_head(&d->vm_event->share.wq);
+#endif
+
+    return 0;
+}
+

static int vm_event_enable(
struct domain *d,
xen_domctl_vm_event_op_t *vec,

xen/common/vm_event.c +0 -3
@@ -93,9 +113,6 @@ static int vm_event_enable(
    /* Save the pause flag for this particular ring. */
    ved->pause_flag = pause_flag;
 
-    /* Initialize the last-chance wait queue. */
-    init_waitqueue_head(&ved->wq);
-
    vm_event_ring_unlock(ved);
    return 0;
 
xen/include/xen/vm_event.h +2 -0
index 2fb3951..482243e 100644
@@ -80,6 +80,8 @@ void vm_event_set_registers(struct vcpu *v,
 vm_event_response_t *rsp);
 
 void vm_event_monitor_next_interrupt(struct vcpu *v);
 
+int init_domain_vm_event(struct domain *d);
+
 #endif /* __VM_EVENT_H__ */
 
Quoted 9 lines

/*

Signature · 7 lines
1.9.1


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

Thanks!

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

#2 lore raw
Quoted 8 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Razvan Cojocaru

Pending livepatch code wants to check if the vm_event wait queues are active, and this is made harder by the fact that they were

Hmm, it wants to? Is there an missing patch that hasn't been posted for this?

If you mean to post this _before_ the other one please adjust the commit description.

Yes, I think that patch hasn't been posted yet (Andrew is / was working on it). I thought "pending" was appropriate in the description, but I can change the text (after seeing if there are more comments on the code).

Thanks,
Razvan

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

#3 lore raw
In reply to Konrad Rzeszutek Wilk
Quoted 7 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Razvan Cojocaru

Pending livepatch code wants to check if the vm_event wait queues are active, and this is made harder by the fact that they were

Hmm, it wants to? Is there an missing patch that hasn't been posted for this?

If you mean to post this _before_ the other one please adjust the commit description.

I was intending patch is only for XenServer. Its a stopgap solution to prevent livepatching from crashing the hypervisor if there are active waitqueues.

The longterm solution is to get multipage rings working (so there are guaranteed to be sufficient slots not to block) and drop waitqueues entirely. In the short term however, I suppose a variant of it might be useful, depending on how supported vm_event actually is.

Razvan: I'd reword this to not mention livepatching. Simply having list_empty() working is a good enough reason alone.

~Andrew

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

#4 lore raw
Quoted 2 lines · Andrew Cooper

Razvan: I'd reword this to not mention livepatching. Simply having list_empty() working is a good enough reason alone.

Fair enough, I'll change the patch description as soon as we hear from Tamas, so that I might address as many comments as possible.

Thanks,
Razvan

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

#5 lore raw
In reply to Razvan Cojocaru
Quoted 37 lines · Razvan Cojocaru

Pending livepatch code wants to check if the vm_event wait queues are active, and this is made harder by the fact that they were previously only initialized some time after the domain was created, in vm_event_enable(). This patch initializes the lists immediately after xzalloc()ating the vm_event memory, in domain_create(), in the newly added init_domain_vm_event() function.

---
 xen/common/domain.c        |  5 ++---
 xen/common/vm_event.c      | 23 ++++++++++++++++++++---
 xen/include/xen/vm_event.h |  2 ++
 3 files changed, 24 insertions(+), 6 deletions(-)
xen/common/domain.c +2 -3
index b22aacc..89a8f1d 100644
@@ -362,11 +362,10 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
 
         poolid = 0;
 
-        err = -ENOMEM;
-        d->vm_event = xzalloc(struct vm_event_per_domain);
-        if ( !d->vm_event )
+        if ( (err = init_domain_vm_event(d)) != 0 )
             goto fail;
 
+        err = -ENOMEM;
         d->pbuf = xzalloc_array(char, DOMAIN_PBUF_SIZE);
         if ( !d->pbuf )
             goto fail;
xen/common/vm_event.c +0 -0
index 9291db6..294ddd7 100644

xen/common/vm_event.c line 42

Quoted 4 lines
xen/common/vm_event.c +1 -0
@@ -39,6 +39,26 @@
 #define vm_event_ring_lock(_ved)       spin_lock(&(_ved)->ring_lock)
 #define vm_event_ring_unlock(_ved)     spin_unlock(&(_ved)->ring_lock)
 
+int init_domain_vm_event(struct domain *d)

We already have a vm_event_init_domain function so the naming of this one here is not a particularly good one. It also looks like to me these two functions could simply be merged..

xen/common/vm_event.c line 53

Quoted 11 lines
xen/common/vm_event.c +11 -0
+{
+    d->vm_event = xzalloc(struct vm_event_per_domain);
+
+    if ( !d->vm_event )
+        return -ENOMEM;
+
+#ifdef CONFIG_HAS_MEM_PAGING
+    init_waitqueue_head(&d->vm_event->paging.wq);
+#endif
+
+    init_waitqueue_head(&d->vm_event->monitor.wq);

Move this one up before the #ifdef block for MEM_PAGING.

Quoted 35 lines
xen/common/vm_event.c +8 -3
+
+#ifdef CONFIG_HAS_MEM_SHARING
+    init_waitqueue_head(&d->vm_event->share.wq);
+#endif
+
+    return 0;
+}
+
 static int vm_event_enable(
     struct domain *d,
     xen_domctl_vm_event_op_t *vec,
@@ -93,9 +113,6 @@ static int vm_event_enable(
     /* Save the pause flag for this particular ring. */
     ved->pause_flag = pause_flag;
 
-    /* Initialize the last-chance wait queue. */
-    init_waitqueue_head(&ved->wq);
-
     vm_event_ring_unlock(ved);
     return 0;
 
xen/include/xen/vm_event.h +2 -1
index 2fb3951..482243e 100644
@@ -80,6 +80,8 @@ void vm_event_set_registers(struct vcpu *v, vm_event_response_t *rsp);
 
 void vm_event_monitor_next_interrupt(struct vcpu *v);
 
+int init_domain_vm_event(struct domain *d);
+
 #endif /* __VM_EVENT_H__ */
 
 /*
--
Quoted 1 line

1.9.1

Tamas

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

#6 lore raw
Quoted 42 lines · Tamas K Lengyel
Quoted 40 lines · Razvan Cojocaru

Pending livepatch code wants to check if the vm_event wait queues are active, and this is made harder by the fact that they were previously only initialized some time after the domain was created, in vm_event_enable(). This patch initializes the lists immediately after xzalloc()ating the vm_event memory, in domain_create(), in the newly added init_domain_vm_event() function.

---
 xen/common/domain.c        |  5 ++---
 xen/common/vm_event.c      | 23 ++++++++++++++++++++---
 xen/include/xen/vm_event.h |  2 ++
 3 files changed, 24 insertions(+), 6 deletions(-)
xen/common/domain.c +2 -3
index b22aacc..89a8f1d 100644
@@ -362,11 +362,10 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
 
         poolid = 0;
 
-        err = -ENOMEM;
-        d->vm_event = xzalloc(struct vm_event_per_domain);
-        if ( !d->vm_event )
+        if ( (err = init_domain_vm_event(d)) != 0 )
             goto fail;
 
+        err = -ENOMEM;
         d->pbuf = xzalloc_array(char, DOMAIN_PBUF_SIZE);
         if ( !d->pbuf )
             goto fail;
xen/common/vm_event.c +0 -0
index 9291db6..294ddd7 100644
@@ -39,6 +39,26 @@
 #define vm_event_ring_lock(_ved)       spin_lock(&(_ved)->ring_lock)
 #define vm_event_ring_unlock(_ved)     spin_unlock(&(_ved)->ring_lock)
 
Quoted 4 lines

xen/common/vm_event.c line 42

Quoted 1 line
xen/common/vm_event.c +1 -0
+int init_domain_vm_event(struct domain *d)

We already have a vm_event_init_domain function so the naming of this one here is not a particularly good one. It also looks like to me these two functions could simply be merged..

They shouldn't be merged.

The current vm_event_init_domain() should probably be init_domain_arch_vm_event(), as it deals with constructing d->arch.vm_event, whereas this function deals with d->vm_event.

There is also a difference in timing; vm_event_init_domain() is called when vm_event is started on the domain, not when the domain is constructed. IMO, the two should happen at the same time to be consistent. I'm not fussed at which point, as it would be fine (in principle) for d->vm_event to be NULL in most cases.

~Andrew

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

#7 lore raw
Quoted 48 lines · Andrew Cooper
Quoted 42 lines · Tamas K Lengyel
Quoted 40 lines · Razvan Cojocaru

Pending livepatch code wants to check if the vm_event wait queues are active, and this is made harder by the fact that they were previously only initialized some time after the domain was created, in vm_event_enable(). This patch initializes the lists immediately after xzalloc()ating the vm_event memory, in domain_create(), in the newly added init_domain_vm_event() function.

---
 xen/common/domain.c        |  5 ++---
 xen/common/vm_event.c      | 23 ++++++++++++++++++++---
 xen/include/xen/vm_event.h |  2 ++
 3 files changed, 24 insertions(+), 6 deletions(-)
xen/common/domain.c +2 -3
index b22aacc..89a8f1d 100644
@@ -362,11 +362,10 @@ struct domain *domain_create(domid_t domid, unsigned int domcr_flags,
 
         poolid = 0;
 
-        err = -ENOMEM;
-        d->vm_event = xzalloc(struct vm_event_per_domain);
-        if ( !d->vm_event )
+        if ( (err = init_domain_vm_event(d)) != 0 )
             goto fail;
 
+        err = -ENOMEM;
         d->pbuf = xzalloc_array(char, DOMAIN_PBUF_SIZE);
         if ( !d->pbuf )
             goto fail;
xen/common/vm_event.c +0 -0
index 9291db6..294ddd7 100644
@@ -39,6 +39,26 @@
 #define vm_event_ring_lock(_ved)       spin_lock(&(_ved)->ring_lock)
 #define vm_event_ring_unlock(_ved)     spin_unlock(&(_ved)->ring_lock)
 
Quoted 4 lines

xen/common/vm_event.c line 42

Quoted 1 line
xen/common/vm_event.c +1 -0
+int init_domain_vm_event(struct domain *d)

We already have a vm_event_init_domain function so the naming of this one here is not a particularly good one. It also looks like to me these two functions could simply be merged..

Quoted 5 lines

They shouldn't be merged.

The current vm_event_init_domain() should probably be init_domain_arch_vm_event(), as it deals with constructing d->arch.vm_event, whereas this function deals with d->vm_event.

That would be fine for me, it's really the naming that I had a problem with.

Thanks,
Tamas

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

#8 lore raw
In reply to Andrew Cooper
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 06/26/17 5:11 PM >>>

There is also a difference in timing; vm_event_init_domain() is called when vm_event is started on the domain, not when the domain is constructed. IMO, the two should happen at the same time to be consistent. I'm not fussed at which point, as it would be fine (in principle) for d->vm_event to be NULL in most cases.

I very much support that last aspect - there's shouldn't be any memory allocated here if the domain isn't going to make use of VM events.

Jan

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

#9 lore raw
Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 06/26/17 5:11 PM >>>

There is also a difference in timing; vm_event_init_domain() is called when vm_event is started on the domain, not when the domain is constructed. IMO, the two should happen at the same time to be consistent. I'm not fussed at which point, as it would be fine (in principle) for d->vm_event to be NULL in most cases.

I very much support that last aspect - there's shouldn't be any memory allocated here if the domain isn't going to make use of VM events.

Unfortunately it's not as simple as that.

While I didn't write that code, it would seem that on domain creation that data is being allocated because it holds information about 3 different vm_event subsystems - monitor, paging, and memshare.

vm_event_init_domain() is then not being called when vm_event generally is started on the domain, but when a specific vm_event part is being initialized (monitor usually, but could be paging, etc.).

Thanks,
Razvan

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

#10 lore raw
Quoted 9 lines
Quoted 1 line
Quoted 1 line

Razvan Cojocaru <[email protected]> 06/27/17 10:32 AM >>>

Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 06/26/17 5:11 PM >>>

There is also a difference in timing; vm_event_init_domain() is called when vm_event is started on the domain, not when the domain is constructed. IMO, the two should happen at the same time to be consistent. I'm not fussed at which point, as it would be fine (in principle) for d->vm_event to be NULL in most cases.

Quoted 8 lines
Quoted 2 lines

I very much support that last aspect - there's shouldn't be any memory allocated here if the domain isn't going to make use of VM events.

Unfortunately it's not as simple as that.

While I didn't write that code, it would seem that on domain creation that data is being allocated because it holds information about 3 different vm_event subsystems - monitor, paging, and memshare.

But it can't be that difficult to make it work the suggested way?

Jan

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

#11 lore raw
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line

Razvan Cojocaru <[email protected]> 06/27/17 10:32 AM >>>

Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 06/26/17 5:11 PM >>>

There is also a difference in timing; vm_event_init_domain() is called when vm_event is started on the domain, not when the domain is constructed. IMO, the two should happen at the same time to be consistent. I'm not fussed at which point, as it would be fine (in principle) for d->vm_event to be NULL in most cases.

I very much support that last aspect - there's shouldn't be any memory allocated here if the domain isn't going to make use of VM events.

Quoted 7 lines
Quoted 5 lines

Unfortunately it's not as simple as that.

While I didn't write that code, it would seem that on domain creation that data is being allocated because it holds information about 3 different vm_event subsystems - monitor, paging, and memshare.

But it can't be that difficult to make it work the suggested way?

We can lazy-allocate that the first time any one of the three gets initialized (monitor, paging, share), and update all the code that checks d->vm_event->member to check that d->vm_event is not NULL before that.

Any objections?

Thanks,
Razvan

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

#12 lore raw
Quoted 20 lines
Quoted 1 line
Quoted 1 line

Razvan Cojocaru <[email protected]> 06/27/17 1:38 PM >>>

Quoted 18 lines · Jan Beulich
Quoted 17 lines
Quoted 1 line
Quoted 1 line

Razvan Cojocaru <[email protected]> 06/27/17 10:32 AM >>>

Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 06/26/17 5:11 PM >>>

There is also a difference in timing; vm_event_init_domain() is called when vm_event is started on the domain, not when the domain is constructed. IMO, the two should happen at the same time to be consistent. I'm not fussed at which point, as it would be fine (in principle) for d->vm_event to be NULL in most cases.

I very much support that last aspect - there's shouldn't be any memory allocated here if the domain isn't going to make use of VM events.

Unfortunately it's not as simple as that.

While I didn't write that code, it would seem that on domain creation that data is being allocated because it holds information about 3 different vm_event subsystems - monitor, paging, and memshare.

Quoted 8 lines
Quoted 1 line

But it can't be that difficult to make it work the suggested way?

We can lazy-allocate that the first time any one of the three gets initialized (monitor, paging, share), and update all the code that checks d->vm_event->member to check that d->vm_event is not NULL before that.

Any objections?

None here.

Jan

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

#13 lore raw
Quoted 22 lines · Jan Beulich
Quoted 22 lines
Quoted 1 line
Quoted 1 line

Razvan Cojocaru <[email protected]> 06/27/17 1:38 PM >>>

Quoted 19 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line

Razvan Cojocaru <[email protected]> 06/27/17 10:32 AM >>>

Quoted 7 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 06/26/17 5:11 PM >>>

There is also a difference in timing; vm_event_init_domain() is called when vm_event is started on the domain, not when the domain is constructed. IMO, the two should happen at the same time to be consistent. I'm not fussed at which point, as it would be fine (in principle) for d->vm_event to be NULL in most cases.

Quoted 8 lines
Quoted 2 lines

I very much support that last aspect - there's shouldn't be any memory allocated here if the domain isn't going to make use of VM events.

Unfortunately it's not as simple as that.

While I didn't write that code, it would seem that on domain creation that data is being allocated because it holds information about 3 different vm_event subsystems - monitor, paging, and memshare.

But it can't be that difficult to make it work the suggested way?

Quoted 8 lines
Quoted 6 lines

We can lazy-allocate that the first time any one of the three gets initialized (monitor, paging, share), and update all the code that checks d->vm_event->member to check that d->vm_event is not NULL before that.

Any objections?

None here.

That's actually much more involved than I thought: almost every vm_event function assumes that for a created domain d->vm_event is not NULL, and takes a struct vm_event_domain *ved parameter to differentiate between monitor, mem paging and mem sharing. So while this technically is not a hard thing to fix at all, it would touch a lot of ARM and x86 code and be quite an overhaul of vm_event.

My immediate reaction was to add small helper functions such as:

42 static struct vm_event_domain *vm_event_get_ved(
43 struct domain *d,
44 enum vm_event_domain_type domain_type)
45 {
46 if ( !d->vm_event )
47 return NULL;
48
49 switch ( domain_type )
50 {
51 #ifdef CONFIG_HAS_MEM_PAGING
52 case VM_EVENT_DOMAIN_TYPE_MEM_PAGING:
53 return &d->vm_event->paging;
54 #endif
55 case VM_EVENT_DOMAIN_TYPE_MONITOR:
56 return &d->vm_event->monitor;
57 #ifdef CONFIG_HAS_MEM_SHARING
58 case VM_EVENT_DOMAIN_TYPE_MEM_SHARING:
59 return &d->vm_event->share;
60 #endif
61 default:
62 return NULL;
63 }
64 }

and try to get all places to use that line of thinking, but there's quite a lot of them.

Tamas, any thoughts on this before going deeper?

Thanks,
Razvan

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

#14 lore raw
Quoted 30 lines · Razvan Cojocaru
Quoted 29 lines · Jan Beulich
Quoted 28 lines
Quoted 1 line
Quoted 1 line

Razvan Cojocaru <[email protected]> 06/27/17 1:38 PM >>>

Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line

Razvan Cojocaru <[email protected]> 06/27/17 10:32 AM >>>

Quoted 9 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line

Andrew Cooper <[email protected]> 06/26/17 5:11 PM >>>

There is also a difference in timing; vm_event_init_domain() is called when vm_event is started on the domain, not when the domain is constructed. IMO, the two should happen at the same time to be consistent. I'm not fussed at which point, as it would be fine (in principle) for d->vm_event to be NULL in most cases.

I very much support that last aspect - there's shouldn't be any memory allocated here if the domain isn't going to make use of VM events.

Quoted 7 lines
Quoted 5 lines

Unfortunately it's not as simple as that.

While I didn't write that code, it would seem that on domain creation that data is being allocated because it holds information about 3 different vm_event subsystems - monitor, paging, and memshare.

But it can't be that difficult to make it work the suggested way?

We can lazy-allocate that the first time any one of the three gets initialized (monitor, paging, share), and update all the code that checks d->vm_event->member to check that d->vm_event is not NULL before that.

Any objections?

Quoted 8 lines
Quoted 1 line

None here.

That's actually much more involved than I thought: almost every vm_event function assumes that for a created domain d->vm_event is not NULL, and takes a struct vm_event_domain *ved parameter to differentiate between monitor, mem paging and mem sharing. So while this technically is not a hard thing to fix at all, it would touch a lot of ARM and x86 code and be quite an overhaul of vm_event.

That sounds right, since currently if a domain is created it is guaranteed to have d->vm_event allocated. That is quite a large struct so I think it would be a nice optimization to only allocate it when needed. If we are reworking this code, I would prefer to see that structure actually being removed altogether and just have three pointers to vm_event_domain's (monitor/sharing/paging), which get allocated when needed. The pointers for paging and sharing could then further be wrapped in ifdef CONFIG checks, so we really only have memory for what we need to.

Quoted 27 lines

My immediate reaction was to add small helper functions such as:

42 static struct vm_event_domain *vm_event_get_ved(
43 struct domain *d,
44 enum vm_event_domain_type domain_type)
45 {
46 if ( !d->vm_event )
47 return NULL;
48
49 switch ( domain_type )
50 {
51 #ifdef CONFIG_HAS_MEM_PAGING
52 case VM_EVENT_DOMAIN_TYPE_MEM_PAGING:
53 return &d->vm_event->paging;
54 #endif
55 case VM_EVENT_DOMAIN_TYPE_MONITOR:
56 return &d->vm_event->monitor;
57 #ifdef CONFIG_HAS_MEM_SHARING
58 case VM_EVENT_DOMAIN_TYPE_MEM_SHARING:
59 return &d->vm_event->share;
60 #endif
61 default:
62 return NULL;
63 }
64 }

Quoted 4 lines

and try to get all places to use that line of thinking, but there's quite a lot of them.

Tamas, any thoughts on this before going deeper?

Having this helper would be fine (even with my proposed changes above). And yes, I can see this would involve touching a lot of code, but I presume it will be mostly mechanical.

Tamas

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