Skip to contentSkip to conversation

xen: Improvements to the vcpu create/destroy paths

PATCH In review Andrew Cooper 5 participants 16 messages Sep 6, 2018 – Sep 17, 2018

lore
Share & tools
lore
#0 lore raw

cover xen: Improvements to the vcpu create/destroy paths

This is the start of the work to make the vcpu_destroy() code idempotent, so vcpu construction can be moved into domain_create() and successfully unwound on error.

Andrew Cooper (3):
xen/vcpu: Rename the common interfaces for consistency xen/vcpu: Introduce vcpu_destroy()
xen/vcpu: Rework sanity checks in vcpu_create()

 xen/arch/arm/domain.c       |  6 ++--
 xen/arch/arm/domain_build.c |  4 +--
 xen/arch/arm/setup.c        |  1 -
 xen/arch/x86/dom0_build.c   |  2 +-
 xen/arch/x86/domain.c       |  4 +--
 xen/arch/x86/setup.c        |  1 -
 xen/common/domain.c         | 80 ++++++++++++++++++++++++++++++---------------
 xen/common/domctl.c         |  2 +-
 xen/common/schedule.c       |  4 +--
 xen/include/xen/domain.h    | 10 +++---
 10 files changed, 69 insertions(+), 45 deletions(-)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/3 xen/vcpu: Rename the common interfaces for consistency

The vcpu functions are far less consistent than the domain side of things, and in particular, has vcpu_destroy() for architecture specific functionality.

Perform the following renames:

* alloc_vcpu => vcpu_create
* vcpu_initialise => arch_vcpu_create
* vcpu_destroy => arch_vcpu_destroy

which makes the vcpu hierarchy consistent with the domain hierarchy.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/arch/arm/domain.c       |  6 +++---
 xen/arch/arm/domain_build.c |  4 ++--
 xen/arch/x86/dom0_build.c   |  2 +-
 xen/arch/x86/domain.c       |  4 ++--
 xen/common/domain.c         |  6 +++---
 xen/common/domctl.c         |  2 +-
 xen/common/schedule.c       |  4 ++--
 xen/include/xen/domain.h    | 10 +++++-----
 8 files changed, 19 insertions(+), 19 deletions(-)
xen/arch/arm/domain.c +3 -3
index 4baecc2..feebbf5 100644
@@ -538,7 +538,7 @@ void free_vcpu_struct(struct vcpu *v)
     free_xenheap_pages(v, get_order_from_bytes(sizeof(*v)));
 }
 
-int vcpu_initialise(struct vcpu *v)
+int arch_vcpu_create(struct vcpu *v)
 {
     int rc = 0;
 
@@ -583,11 +583,11 @@ int vcpu_initialise(struct vcpu *v)
     return rc;
 
 fail:
-    vcpu_destroy(v);
+    arch_vcpu_destroy(v);
     return rc;
 }
 
-void vcpu_destroy(struct vcpu *v)
+void arch_vcpu_destroy(struct vcpu *v)
 {
     vcpu_timer_destroy(v);
     vcpu_vgic_free(v);
xen/arch/arm/domain_build.c +2 -2
index 2a383c8..5057ad8 100644
@@ -74,7 +74,7 @@ unsigned int __init dom0_max_vcpus(void)
 
 struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
 {
-    return alloc_vcpu(dom0, 0, 0);
+    return vcpu_create(dom0, 0, 0);
 }
 
 static unsigned int __init get_11_allocation_size(paddr_t size)
@@ -2232,7 +2232,7 @@ int __init construct_dom0(struct domain *d)
     for ( i = 1, cpu = 0; i < d->max_vcpus; i++ )
     {
         cpu = cpumask_cycle(cpu, &cpu_online_map);
-        if ( alloc_vcpu(d, i, cpu) == NULL )
+        if ( vcpu_create(d, i, cpu) == NULL )
         {
             printk("Failed to allocate dom0 vcpu %d on pcpu %d\n", i, cpu);
             break;
xen/arch/x86/dom0_build.c +1 -1
index 423fdec..86eb7db 100644
@@ -134,7 +134,7 @@ struct vcpu *__init dom0_setup_vcpu(struct domain *d,
                                     unsigned int prev_cpu)
 {
     unsigned int cpu = cpumask_cycle(prev_cpu, &dom0_cpus);
-    struct vcpu *v = alloc_vcpu(d, vcpu_id, cpu);
+    struct vcpu *v = vcpu_create(d, vcpu_id, cpu);
 
     if ( v )
     {
xen/arch/x86/domain.c +2 -2
index 313ebb3..d67a047 100644
@@ -322,7 +322,7 @@ void free_vcpu_struct(struct vcpu *v)
     free_xenheap_page(v);
 }
 
-int vcpu_initialise(struct vcpu *v)
+int arch_vcpu_create(struct vcpu *v)
 {
     struct domain *d = v->domain;
     int rc;
@@ -382,7 +382,7 @@ int vcpu_initialise(struct vcpu *v)
     return rc;
 }
 
-void vcpu_destroy(struct vcpu *v)
+void arch_vcpu_destroy(struct vcpu *v)
 {
     xfree(v->arch.vm_event);
     v->arch.vm_event = NULL;
xen/common/domain.c +3 -3
index 78c450e..14c8d00 100644
@@ -123,7 +123,7 @@ static void vcpu_info_reset(struct vcpu *v)
     v->vcpu_info_mfn = INVALID_MFN;
 }
 
-struct vcpu *alloc_vcpu(
+struct vcpu *vcpu_create(
     struct domain *d, unsigned int vcpu_id, unsigned int cpu_id)
 {
     struct vcpu *v;
@@ -165,7 +165,7 @@ struct vcpu *alloc_vcpu(
     if ( sched_init_vcpu(v, cpu_id) != 0 )
         goto fail_wq;
 
-    if ( vcpu_initialise(v) != 0 )
+    if ( arch_vcpu_create(v) != 0 )
     {
         sched_destroy_vcpu(v);
  fail_wq:
@@ -870,7 +870,7 @@ static void complete_domain_destroy(struct rcu_head *head)
         if ( (v = d->vcpu[i]) == NULL )
             continue;
         tasklet_kill(&v->continue_hypercall_tasklet);
-        vcpu_destroy(v);
+        arch_vcpu_destroy(v);
         sched_destroy_vcpu(v);
         destroy_waitqueue_vcpu(v);
     }
xen/common/domctl.c +1 -1
index ed047b7..2facbdb 100644
@@ -571,7 +571,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
                 cpumask_any(online) :
                 cpumask_cycle(d->vcpu[i-1]->processor, online);
 
-            if ( alloc_vcpu(d, i, cpu) == NULL )
+            if ( vcpu_create(d, i, cpu) == NULL )
                 goto maxvcpu_out;
         }
 
xen/common/schedule.c +2 -2
index 05281d6..1ef5be9 100644
@@ -1645,7 +1645,7 @@ static int cpu_schedule_up(unsigned int cpu)
         return 0;
 
     if ( idle_vcpu[cpu] == NULL )
-        alloc_vcpu(idle_vcpu[0]->domain, cpu, cpu);
+        vcpu_create(idle_vcpu[0]->domain, cpu, cpu);
     else
     {
         struct vcpu *idle = idle_vcpu[cpu];
@@ -1817,7 +1817,7 @@ void __init scheduler_init(void)
     BUG_ON(IS_ERR(idle_domain));
     idle_domain->vcpu = idle_vcpu;
     idle_domain->max_vcpus = nr_cpu_ids;
-    if ( alloc_vcpu(idle_domain, 0, 0) == NULL )
+    if ( vcpu_create(idle_domain, 0, 0) == NULL )
         BUG();
     this_cpu(schedule_data).sched_priv = SCHED_OP(&ops, alloc_pdata, 0);
     BUG_ON(IS_ERR(this_cpu(schedule_data).sched_priv));
xen/include/xen/domain.h +5 -5
index 5593495..6df6a58 100644
@@ -13,7 +13,7 @@ typedef union {
     struct compat_vcpu_guest_context *cmp;
 } vcpu_guest_context_u __attribute__((__transparent_union__));
 
-struct vcpu *alloc_vcpu(
+struct vcpu *vcpu_create(
     struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);
 
 unsigned int dom0_max_vcpus(void);
@@ -47,13 +47,13 @@ void free_pirq_struct(void *);
 
 /*
  * Initialise/destroy arch-specific details of a VCPU.
- *  - vcpu_initialise() is called after the basic generic fields of the
+ *  - arch_vcpu_create() is called after the basic generic fields of the
  *    VCPU structure are initialised. Many operations can be applied to the
  *    VCPU at this point (e.g., vcpu_pause()).
- *  - vcpu_destroy() is called only if vcpu_initialise() previously succeeded.
+ *  - arch_vcpu_destroy() is called only if arch_vcpu_create() previously succeeded.
  */
-int  vcpu_initialise(struct vcpu *v);
-void vcpu_destroy(struct vcpu *v);
+int  arch_vcpu_create(struct vcpu *v);
+void arch_vcpu_destroy(struct vcpu *v);
 
 int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset);
 void unmap_vcpu_info(struct vcpu *v);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] xen/vcpu: Rename the common interfaces for consistency

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 06.09.18 at 21:25, <[email protected]> wrote:

The vcpu functions are far less consistent than the domain side of things, and in particular, has vcpu_destroy() for architecture specific functionality.

Perform the following renames:

* alloc_vcpu => vcpu_create
* vcpu_initialise => arch_vcpu_create
* vcpu_destroy => arch_vcpu_destroy

Quoted 5 lines

which makes the vcpu hierarchy consistent with the domain hierarchy.

No functional change.

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

Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] xen/vcpu: Rename the common interfaces for consistency

In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

The vcpu functions are far less consistent than the domain side of things, and in particular, has vcpu_destroy() for architecture specific functionality.

Perform the following renames:

* alloc_vcpu => vcpu_create
* vcpu_initialise => arch_vcpu_create
* vcpu_destroy => arch_vcpu_destroy

Quoted 5 lines

which makes the vcpu hierarchy consistent with the domain hierarchy.

No functional change.

Quoted 14 lines
xen/include/xen/domain.h +1 -1
index 5593495..6df6a58 100644
@@ -13,7 +13,7 @@ typedef union {
     struct compat_vcpu_guest_context *cmp;
 } vcpu_guest_context_u __attribute__((__transparent_union__));
 
-struct vcpu *alloc_vcpu(
+struct vcpu *vcpu_create(
     struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);
 
 unsigned int dom0_max_vcpus(void);

xen/include/xen/domain.h void free_pirq_struct(void *); · line 53

Quoted 9 lines
xen/include/xen/domain.h +2 -2
@@ -47,13 +47,13 @@ void free_pirq_struct(void *);
 
 /*
  * Initialise/destroy arch-specific details of a VCPU.
- *  - vcpu_initialise() is called after the basic generic fields of the
+ *  - arch_vcpu_create() is called after the basic generic fields of the
  *    VCPU structure are initialised. Many operations can be applied to the
  *    VCPU at this point (e.g., vcpu_pause()).
- *  - vcpu_destroy() is called only if vcpu_initialise() previously succeeded.
+ *  - arch_vcpu_destroy() is called only if arch_vcpu_create() previously succeeded.

Line is too long.

Thanks, Roger.

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

Acked-by on v1 1/3
#4 lore raw

Re: [PATCH 1/3] xen/vcpu: Rename the common interfaces for consistency

In reply to Andrew Cooper

Hi,

Quoted 9 lines · Andrew Cooper

The vcpu functions are far less consistent than the domain side of things, and in particular, has vcpu_destroy() for architecture specific functionality.

Perform the following renames:

* alloc_vcpu => vcpu_create
* vcpu_initialise => arch_vcpu_create
* vcpu_destroy => arch_vcpu_destroy

Quoted 5 lines

which makes the vcpu hierarchy consistent with the domain hierarchy.

No functional change.

Cheers,

Quoted 199 lines

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
  xen/arch/arm/domain.c       |  6 +++---
  xen/arch/arm/domain_build.c |  4 ++--
  xen/arch/x86/dom0_build.c   |  2 +-
  xen/arch/x86/domain.c       |  4 ++--
  xen/common/domain.c         |  6 +++---
  xen/common/domctl.c         |  2 +-
  xen/common/schedule.c       |  4 ++--
  xen/include/xen/domain.h    | 10 +++++-----
  8 files changed, 19 insertions(+), 19 deletions(-)
xen/arch/arm/domain.c +3 -3
index 4baecc2..feebbf5 100644
@@ -538,7 +538,7 @@ void free_vcpu_struct(struct vcpu *v)
      free_xenheap_pages(v, get_order_from_bytes(sizeof(*v)));
  }
 
-int vcpu_initialise(struct vcpu *v)
+int arch_vcpu_create(struct vcpu *v)
  {
      int rc = 0;
 
@@ -583,11 +583,11 @@ int vcpu_initialise(struct vcpu *v)
      return rc;
 
  fail:
-    vcpu_destroy(v);
+    arch_vcpu_destroy(v);
      return rc;
  }
 
-void vcpu_destroy(struct vcpu *v)
+void arch_vcpu_destroy(struct vcpu *v)
  {
      vcpu_timer_destroy(v);
      vcpu_vgic_free(v);
xen/arch/arm/domain_build.c +2 -2
index 2a383c8..5057ad8 100644
@@ -74,7 +74,7 @@ unsigned int __init dom0_max_vcpus(void)
 
  struct vcpu *__init alloc_dom0_vcpu0(struct domain *dom0)
  {
-    return alloc_vcpu(dom0, 0, 0);
+    return vcpu_create(dom0, 0, 0);
  }
 
  static unsigned int __init get_11_allocation_size(paddr_t size)
@@ -2232,7 +2232,7 @@ int __init construct_dom0(struct domain *d)
      for ( i = 1, cpu = 0; i < d->max_vcpus; i++ )
      {
          cpu = cpumask_cycle(cpu, &cpu_online_map);
-        if ( alloc_vcpu(d, i, cpu) == NULL )
+        if ( vcpu_create(d, i, cpu) == NULL )
          {
              printk("Failed to allocate dom0 vcpu %d on pcpu %d\n", i, cpu);
              break;
xen/arch/x86/dom0_build.c +1 -1
index 423fdec..86eb7db 100644
@@ -134,7 +134,7 @@ struct vcpu *__init dom0_setup_vcpu(struct domain *d,
                                      unsigned int prev_cpu)
  {
      unsigned int cpu = cpumask_cycle(prev_cpu, &dom0_cpus);
-    struct vcpu *v = alloc_vcpu(d, vcpu_id, cpu);
+    struct vcpu *v = vcpu_create(d, vcpu_id, cpu);
 
      if ( v )
      {
xen/arch/x86/domain.c +2 -2
index 313ebb3..d67a047 100644
@@ -322,7 +322,7 @@ void free_vcpu_struct(struct vcpu *v)
      free_xenheap_page(v);
  }
 
-int vcpu_initialise(struct vcpu *v)
+int arch_vcpu_create(struct vcpu *v)
  {
      struct domain *d = v->domain;
      int rc;
@@ -382,7 +382,7 @@ int vcpu_initialise(struct vcpu *v)
      return rc;
  }
 
-void vcpu_destroy(struct vcpu *v)
+void arch_vcpu_destroy(struct vcpu *v)
  {
      xfree(v->arch.vm_event);
      v->arch.vm_event = NULL;
xen/common/domain.c +3 -3
index 78c450e..14c8d00 100644
@@ -123,7 +123,7 @@ static void vcpu_info_reset(struct vcpu *v)
      v->vcpu_info_mfn = INVALID_MFN;
  }
 
-struct vcpu *alloc_vcpu(
+struct vcpu *vcpu_create(
      struct domain *d, unsigned int vcpu_id, unsigned int cpu_id)
  {
      struct vcpu *v;
@@ -165,7 +165,7 @@ struct vcpu *alloc_vcpu(
      if ( sched_init_vcpu(v, cpu_id) != 0 )
          goto fail_wq;
 
-    if ( vcpu_initialise(v) != 0 )
+    if ( arch_vcpu_create(v) != 0 )
      {
          sched_destroy_vcpu(v);
   fail_wq:
@@ -870,7 +870,7 @@ static void complete_domain_destroy(struct rcu_head *head)
          if ( (v = d->vcpu[i]) == NULL )
              continue;
          tasklet_kill(&v->continue_hypercall_tasklet);
-        vcpu_destroy(v);
+        arch_vcpu_destroy(v);
          sched_destroy_vcpu(v);
          destroy_waitqueue_vcpu(v);
      }
xen/common/domctl.c +1 -1
index ed047b7..2facbdb 100644
@@ -571,7 +571,7 @@ long do_domctl(XEN_GUEST_HANDLE_PARAM(xen_domctl_t) u_domctl)
                  cpumask_any(online) :
                  cpumask_cycle(d->vcpu[i-1]->processor, online);
 
-            if ( alloc_vcpu(d, i, cpu) == NULL )
+            if ( vcpu_create(d, i, cpu) == NULL )
                  goto maxvcpu_out;
          }
 
xen/common/schedule.c +2 -2
index 05281d6..1ef5be9 100644
@@ -1645,7 +1645,7 @@ static int cpu_schedule_up(unsigned int cpu)
          return 0;
 
      if ( idle_vcpu[cpu] == NULL )
-        alloc_vcpu(idle_vcpu[0]->domain, cpu, cpu);
+        vcpu_create(idle_vcpu[0]->domain, cpu, cpu);
      else
      {
          struct vcpu *idle = idle_vcpu[cpu];
@@ -1817,7 +1817,7 @@ void __init scheduler_init(void)
      BUG_ON(IS_ERR(idle_domain));
      idle_domain->vcpu = idle_vcpu;
      idle_domain->max_vcpus = nr_cpu_ids;
-    if ( alloc_vcpu(idle_domain, 0, 0) == NULL )
+    if ( vcpu_create(idle_domain, 0, 0) == NULL )
          BUG();
      this_cpu(schedule_data).sched_priv = SCHED_OP(&ops, alloc_pdata, 0);
      BUG_ON(IS_ERR(this_cpu(schedule_data).sched_priv));
xen/include/xen/domain.h +5 -5
index 5593495..6df6a58 100644
@@ -13,7 +13,7 @@ typedef union {
      struct compat_vcpu_guest_context *cmp;
  } vcpu_guest_context_u __attribute__((__transparent_union__));
 
-struct vcpu *alloc_vcpu(
+struct vcpu *vcpu_create(
      struct domain *d, unsigned int vcpu_id, unsigned int cpu_id);
 
  unsigned int dom0_max_vcpus(void);
@@ -47,13 +47,13 @@ void free_pirq_struct(void *);
 
  /*
   * Initialise/destroy arch-specific details of a VCPU.
- *  - vcpu_initialise() is called after the basic generic fields of the
+ *  - arch_vcpu_create() is called after the basic generic fields of the
   *    VCPU structure are initialised. Many operations can be applied to the
   *    VCPU at this point (e.g., vcpu_pause()).
- *  - vcpu_destroy() is called only if vcpu_initialise() previously succeeded.
+ *  - arch_vcpu_destroy() is called only if arch_vcpu_create() previously succeeded.
   */
-int  vcpu_initialise(struct vcpu *v);
-void vcpu_destroy(struct vcpu *v);
+int  arch_vcpu_create(struct vcpu *v);
+void arch_vcpu_destroy(struct vcpu *v);
 
  int map_vcpu_info(struct vcpu *v, unsigned long gfn, unsigned offset);
  void unmap_vcpu_info(struct vcpu *v);
Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#5 lore raw

PATCH 2/3 xen/vcpu: Introduce vcpu_destroy()

In reply to Andrew Cooper

Like _domain_destroy(), this will eventually idempotently free all parts of a struct vcpu.

While breaking apart the failure path of vcpu_create(), rework the codeflow to be in a line at the end of the function for clarity.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/common/domain.c | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)
xen/common/domain.c +22 -20
index 14c8d00..a9df589 100644
@@ -123,6 +123,16 @@ static void vcpu_info_reset(struct vcpu *v)
     v->vcpu_info_mfn = INVALID_MFN;
 }
 
+static void vcpu_destroy(struct vcpu *v)
+{
+    free_cpumask_var(v->cpu_hard_affinity);
+    free_cpumask_var(v->cpu_hard_affinity_tmp);
+    free_cpumask_var(v->cpu_hard_affinity_saved);
+    free_cpumask_var(v->cpu_soft_affinity);
+
+    free_vcpu_struct(v);
+}
+
 struct vcpu *vcpu_create(
     struct domain *d, unsigned int vcpu_id, unsigned int cpu_id)
 {
@@ -147,7 +157,7 @@ struct vcpu *vcpu_create(
          !zalloc_cpumask_var(&v->cpu_hard_affinity_tmp) ||
          !zalloc_cpumask_var(&v->cpu_hard_affinity_saved) ||
          !zalloc_cpumask_var(&v->cpu_soft_affinity) )
-        goto fail_free;
+        goto fail;
 
     if ( is_idle_domain(d) )
     {
@@ -166,18 +176,7 @@ struct vcpu *vcpu_create(
         goto fail_wq;
 
     if ( arch_vcpu_create(v) != 0 )
-    {
-        sched_destroy_vcpu(v);
- fail_wq:
-        destroy_waitqueue_vcpu(v);
- fail_free:
-        free_cpumask_var(v->cpu_hard_affinity);
-        free_cpumask_var(v->cpu_hard_affinity_tmp);
-        free_cpumask_var(v->cpu_hard_affinity_saved);
-        free_cpumask_var(v->cpu_soft_affinity);
-        free_vcpu_struct(v);
-        return NULL;
-    }
+        goto fail_sched;
 
     d->vcpu[vcpu_id] = v;
     if ( vcpu_id != 0 )
@@ -197,6 +196,15 @@ struct vcpu *vcpu_create(
         domain_update_node_affinity(d);
 
     return v;
+
+ fail_sched:
+    sched_destroy_vcpu(v);
+ fail_wq:
+    destroy_waitqueue_vcpu(v);
+ fail:
+    vcpu_destroy(v);
+
+    return NULL;
 }
 
 static int late_hwdom_init(struct domain *d)
@@ -898,13 +906,7 @@ static void complete_domain_destroy(struct rcu_head *head)
 
     for ( i = d->max_vcpus - 1; i >= 0; i-- )
         if ( (v = d->vcpu[i]) != NULL )
-        {
-            free_cpumask_var(v->cpu_hard_affinity);
-            free_cpumask_var(v->cpu_hard_affinity_tmp);
-            free_cpumask_var(v->cpu_hard_affinity_saved);
-            free_cpumask_var(v->cpu_soft_affinity);
-            free_vcpu_struct(v);
-        }
+            vcpu_destroy(v);
 
     if ( d->target != NULL )
         put_domain(d->target);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 2/3
#6 lore raw

Re: [PATCH 2/3] xen/vcpu: Introduce vcpu_destroy()

Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 06.09.18 at 21:25, <[email protected]> wrote:

Like _domain_destroy(), this will eventually idempotently free all parts of a struct vcpu.

While breaking apart the failure path of vcpu_create(), rework the codeflow to be in a line at the end of the function for clarity.

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

Reviewed-by on v1 2/3
#7 lore raw

Re: [PATCH 2/3] xen/vcpu: Introduce vcpu_destroy()

In reply to Andrew Cooper
Quoted 7 lines · Andrew Cooper

Like _domain_destroy(), this will eventually idempotently free all parts of a struct vcpu.

While breaking apart the failure path of vcpu_create(), rework the codeflow to be in a line at the end of the function for clarity.

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

#8 lore raw

PATCH 3/3 xen/vcpu: Rework sanity checks in vcpu_create()

In reply to Andrew Cooper

Poisoning idle_vcpu[0] with the sanity debug value isn't actually a clever idea, because it passes a NULL pointer check but isn't a usable vcpu. It is also the reason for the (!is_idle_domain(d) || vcpu_id) part of the existing sanity BUG_ON().

Now that d->max_vcpus is appropriately set up before vcpu_create() is called, we can properly range check the requested vcpu_id. Drop the BUG_ON() and replace it with code which is runtime safe but non-fatal.

While v0 must be the first allocated vcpu for for_each_vcpu() to work, it isn't a requirement for the threading the vcpu into the linked list, so update the threading code to be more generic, and add a comment explaining why we need to search for prev_id.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/arch/arm/setup.c |  1 -
 xen/arch/x86/setup.c |  1 -
 xen/common/domain.c  | 32 ++++++++++++++++++++++++++++----
 3 files changed, 28 insertions(+), 6 deletions(-)
xen/arch/arm/setup.c +0 -1
index 01aaaab..d06ac40 100644
@@ -704,7 +704,6 @@ void __init start_xen(unsigned long boot_phys_offset,
     set_processor_id(0); /* needed early, for smp_processor_id() */
 
     set_current((struct vcpu *)0xfffff000); /* debug sanity */
-    idle_vcpu[0] = current;
 
     setup_virtual_regions(NULL, NULL);
     /* Initialize traps early allow us to get backtrace when an error occurred */
xen/arch/x86/setup.c +0 -1
index a2f22a1..5e1e8ae 100644
@@ -691,7 +691,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     set_processor_id(0);
     set_current(INVALID_VCPU); /* debug sanity. */
-    idle_vcpu[0] = current;
     init_shadow_spec_ctrl_state();
 
     percpu_init_areas();
xen/common/domain.c +28 -4
index a9df589..d23b54a 100644
@@ -138,7 +138,19 @@ struct vcpu *vcpu_create(
 {
     struct vcpu *v;
 
-    BUG_ON((!is_idle_domain(d) || vcpu_id) && d->vcpu[vcpu_id]);
+    /*
+     * Sanity check some input expectations:
+     *  - d->max_vcpus and d->vcpu[] should be set up
+     *  - vcpu_id should be bounded by d->max_vcpus
+     *  - v0 must be the first-allocated vcpu
+     *  - No previous vcpu with this id should be allocated
+     */
+    if ( !d->max_vcpus || !d->vcpu || vcpu_id >= d->max_vcpus ||
+         (vcpu_id > 0 && !d->vcpu[0]) || d->vcpu[vcpu_id] )
+    {
+        ASSERT_UNREACHABLE();
+        return NULL;
+    }
 
     if ( (v = alloc_vcpu_struct()) == NULL )
         return NULL;
@@ -178,15 +190,27 @@ struct vcpu *vcpu_create(
     if ( arch_vcpu_create(v) != 0 )
         goto fail_sched;
 
+    /* Insert the vcpu into the domain's vcpu list. */
     d->vcpu[vcpu_id] = v;
     if ( vcpu_id != 0 )
     {
         int prev_id = v->vcpu_id - 1;
+
+        /*
+         * Look for the previously allocated vcpu, and splice into the
+         * next_in_list single linked list.
+         *
+         * All domains other than IDLE have tightly packed vcpu_id's.  IDLE
+         * vcpu_id's are derived from hardware CPU id's and can be sparse.
+         */
         while ( (prev_id >= 0) && (d->vcpu[prev_id] == NULL) )
             prev_id--;
-        BUG_ON(prev_id < 0);
-        v->next_in_list = d->vcpu[prev_id]->next_in_list;
-        d->vcpu[prev_id]->next_in_list = v;
+
+        if ( prev_id >= 0 )
+        {
+            v->next_in_list = d->vcpu[prev_id]->next_in_list;
+            d->vcpu[prev_id]->next_in_list = v;
+        }
     }
 
     /* Must be called after making new vcpu visible to for_each_vcpu(). */
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#9 lore raw

Re: [PATCH 3/3] xen/vcpu: Rework sanity checks in vcpu_create()

Quoted 45 lines · Andrew Cooper

Poisoning idle_vcpu[0] with the sanity debug value isn't actually a clever idea, because it passes a NULL pointer check but isn't a usable vcpu. It is also the reason for the (!is_idle_domain(d) || vcpu_id) part of the existing sanity BUG_ON().

Now that d->max_vcpus is appropriately set up before vcpu_create() is called, we can properly range check the requested vcpu_id. Drop the BUG_ON() and replace it with code which is runtime safe but non-fatal.

While v0 must be the first allocated vcpu for for_each_vcpu() to work, it isn't a requirement for the threading the vcpu into the linked list, so update the threading code to be more generic, and add a comment explaining why we need to search for prev_id.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/arch/arm/setup.c |  1 -
 xen/arch/x86/setup.c |  1 -
 xen/common/domain.c  | 32 ++++++++++++++++++++++++++++----
 3 files changed, 28 insertions(+), 6 deletions(-)
xen/arch/arm/setup.c +0 -1
index 01aaaab..d06ac40 100644
@@ -704,7 +704,6 @@ void __init start_xen(unsigned long boot_phys_offset,
     set_processor_id(0); /* needed early, for smp_processor_id() */
 
     set_current((struct vcpu *)0xfffff000); /* debug sanity */
-    idle_vcpu[0] = current;
 
     setup_virtual_regions(NULL, NULL);
     /* Initialize traps early allow us to get backtrace when an error occurred */
xen/arch/x86/setup.c +0 -0
index a2f22a1..5e1e8ae 100644

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 694

Quoted 4 lines
xen/arch/x86/setup.c +0 -1
@@ -691,7 +691,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     set_processor_id(0);
     set_current(INVALID_VCPU); /* debug sanity. */
-    idle_vcpu[0] = current;

xen/arch/x86/tboot.c:tboot_shutdown() has:

    if ( idle_vcpu[0] != INVALID_VCPU )
        write_ptbase(idle_vcpu[0]);

With your change, this should be update to check for non-NULL.

Regards,
Jason

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

#10 lore raw

Re: [PATCH 3/3] xen/vcpu: Rework sanity checks in vcpu_create()

Quoted 46 lines · Jason Andryuk
Quoted 45 lines · Andrew Cooper

Poisoning idle_vcpu[0] with the sanity debug value isn't actually a clever idea, because it passes a NULL pointer check but isn't a usable vcpu. It is also the reason for the (!is_idle_domain(d) || vcpu_id) part of the existing sanity BUG_ON().

Now that d->max_vcpus is appropriately set up before vcpu_create() is called, we can properly range check the requested vcpu_id. Drop the BUG_ON() and replace it with code which is runtime safe but non-fatal.

While v0 must be the first allocated vcpu for for_each_vcpu() to work, it isn't a requirement for the threading the vcpu into the linked list, so update the threading code to be more generic, and add a comment explaining why we need to search for prev_id.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

---
 xen/arch/arm/setup.c |  1 -
 xen/arch/x86/setup.c |  1 -
 xen/common/domain.c  | 32 ++++++++++++++++++++++++++++----
 3 files changed, 28 insertions(+), 6 deletions(-)
xen/arch/arm/setup.c +0 -1
index 01aaaab..d06ac40 100644
@@ -704,7 +704,6 @@ void __init start_xen(unsigned long boot_phys_offset,
     set_processor_id(0); /* needed early, for smp_processor_id() */
 
     set_current((struct vcpu *)0xfffff000); /* debug sanity */
-    idle_vcpu[0] = current;
 
     setup_virtual_regions(NULL, NULL);
     /* Initialize traps early allow us to get backtrace when an error occurred */
xen/arch/x86/setup.c +0 -0
index a2f22a1..5e1e8ae 100644
@@ -691,7 +691,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
Quoted 8 lines

xen/arch/x86/setup.c void __init noreturn __start_xen(unsigned long mbi_p) · line 694

Quoted 3 lines
xen/arch/x86/setup.c +0 -1
     set_processor_id(0);
     set_current(INVALID_VCPU); /* debug sanity. */
-    idle_vcpu[0] = current;

xen/arch/x86/tboot.c:tboot_shutdown() has:

    if ( idle_vcpu[0] != INVALID_VCPU )
        write_ptbase(idle_vcpu[0]);

With your change, this should be update to check for non-NULL.

Oh - very good catch.  Thanks.

Looking at the code, ideally it would change to write_cr3(idle_pg_table), but that isn't going to include the additional CR4 changes.  Leaving this in this form (with a NULL) check is probably best.

~Andrew

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

#11 lore raw

Re: [PATCH 3/3] xen/vcpu: Rework sanity checks in vcpu_create()

In reply to Andrew Cooper
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.09.18 at 21:25, <[email protected]> wrote:

While v0 must be the first allocated vcpu for for_each_vcpu() to work, it isn't a requirement for the threading the vcpu into the linked list, so update the threading code to be more generic, and add a comment explaining why we need to search for prev_id.

I'm afraid I can't bring this in line with the code change:

xen/common/domain.c struct vcpu *vcpu_create( · line 195

Quoted 7 lines
xen/common/domain.c +1 -0
@@ -178,15 +190,27 @@ struct vcpu *vcpu_create(
     if ( arch_vcpu_create(v) != 0 )
         goto fail_sched;
 
+    /* Insert the vcpu into the domain's vcpu list. */
     d->vcpu[vcpu_id] = v;
     if ( vcpu_id != 0 )

There still is this conditional, and you don't add any else to it. Hence afaics if vCPU 0 was created after vCPU 1, vCPU 0's next_in_list would not be made point to vCPU 1. That's not what I'd call "more generic".

But the question is what use the next_in_list field is in the first place, when the entries there are sorted by ID anyway: Why can't we simply use v->domain->vcpu[] instead? In the common case v->domain->vcpu[v->vcpu_id+1] is not going to be NULL anyway, and I don't think for_each_vcpu() would become that much more complicated that way.

xen/common/domain.c struct vcpu *vcpu_create( · line 201

Quoted 6 lines
xen/common/domain.c +4 -0
     {
         int prev_id = v->vcpu_id - 1;
+
+        /*
+         * Look for the previously allocated vcpu, and splice into the
+         * next_in_list single linked list.

I'm also not very happy about the use of "previously" here: This (to me as a non-native speaker) in no way means "the one with the next lowest ID".

Jan

Quoted 19 lines
xen/common/domain.c +9 -3
+         * All domains other than IDLE have tightly packed vcpu_id's.  IDLE
+         * vcpu_id's are derived from hardware CPU id's and can be sparse.
+         */
         while ( (prev_id >= 0) && (d->vcpu[prev_id] == NULL) )
             prev_id--;
-        BUG_ON(prev_id < 0);
-        v->next_in_list = d->vcpu[prev_id]->next_in_list;
-        d->vcpu[prev_id]->next_in_list = v;
+
+        if ( prev_id >= 0 )
+        {
+            v->next_in_list = d->vcpu[prev_id]->next_in_list;
+            d->vcpu[prev_id]->next_in_list = v;
+        }
     }
 
     /* Must be called after making new vcpu visible to for_each_vcpu(). */
Signature · 1 line
2.1.4

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

#12 lore raw

Re: [PATCH 3/3] xen/vcpu: Rework sanity checks in vcpu_create()

Quoted 11 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 06.09.18 at 21:25, <[email protected]> wrote:

While v0 must be the first allocated vcpu for for_each_vcpu() to work, it isn't a requirement for the threading the vcpu into the linked list, so update the threading code to be more generic, and add a comment explaining why we need to search for prev_id.

I'm afraid I can't bring this in line with the code change:

Quoted 4 lines
xen/common/domain.c +0 -0
@@ -178,15 +190,27 @@ struct vcpu *vcpu_create(
     if ( arch_vcpu_create(v) != 0 )
         goto fail_sched;
 
Quoted 7 lines

xen/common/domain.c struct vcpu *vcpu_create( · line 195

Quoted 3 lines
xen/common/domain.c +1 -0
+    /* Insert the vcpu into the domain's vcpu list. */
     d->vcpu[vcpu_id] = v;
     if ( vcpu_id != 0 )

There still is this conditional, and you don't add any else to it. Hence afaics if vCPU 0 was created after vCPU 1, vCPU 0's next_in_list would not be made point to vCPU 1. That's not what I'd call "more generic".

You are completely correct.  I don't know what I was thinking when saying that this is more generic.

I suspect it also means that, depending on hardware CPU numbering, for_each_vcpu(idle) may not work, but perhaps that is not an issue as the idle domains pointer is actually private to scheduler_init().  It is available from either current->domain, or idle_vcpu[$X]->domain, but I think its reasonable to expect that we never use for_each_vcpu() over the idle domain.

Quoted 6 lines

But the question is what use the next_in_list field is in the first place, when the entries there are sorted by ID anyway: Why can't we simply use v->domain->vcpu[] instead? In the common case v->domain->vcpu[v->vcpu_id+1] is not going to be NULL anyway, and I don't think for_each_vcpu() would become that much more complicated that way.

It would, because every iteration you'd need a check of v->vcpu_id against d->max_vcpus to avoid walking off the end of d->vcpu[]

Quoted 10 lines

xen/common/domain.c struct vcpu *vcpu_create( · line 201

Quoted 7 lines
xen/common/domain.c +4 -0
     {
         int prev_id = v->vcpu_id - 1;
+
+        /*
+         * Look for the previously allocated vcpu, and splice into the
+         * next_in_list single linked list.

I'm also not very happy about the use of "previously" here: This (to me as a non-native speaker) in no way means "the one with the next lowest ID".

Given the simplifying assumption of not the idle domain, the setting up of the single linked list can be made much more concise, as we know the IDs are packed and allocated in ascending order.

~Andrew

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

#13 lore raw

PATCH v2 1/1 xen/vcpu: Rework sanity checks in vcpu_create()

In reply to Andrew Cooper

Poisoning idle_vcpu[0] with the sanity debug value isn't actually a clever idea, because it passes a NULL pointer check but isn't a usable vcpu. It is also the reason for the (!is_idle_domain(d) || vcpu_id) part of the existing sanity BUG_ON().

Now that d->max_vcpus is appropriately set up before vcpu_create() is called, we can properly range check the requested vcpu_id. Drop the BUG_ON() and replace it with code which is runtime safe but non-fatal.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Jason Andryuk <[email protected]>

v2:
* Fix the tboot check following the un-poisioning of idle_vcpu[0]
* Exclude the idle domain from the next_in_list list, and vastly simplify the linking logic.

---
 xen/arch/arm/setup.c |  1 -
 xen/arch/x86/setup.c |  1 -
 xen/arch/x86/tboot.c |  2 +-
 xen/common/domain.c  | 28 ++++++++++++++++++----------
 4 files changed, 19 insertions(+), 13 deletions(-)
xen/arch/arm/setup.c +0 -1
index ea2495a..a80032c 100644
@@ -704,7 +704,6 @@ void __init start_xen(unsigned long boot_phys_offset,
     set_processor_id(0); /* needed early, for smp_processor_id() */
 
     set_current((struct vcpu *)0xfffff000); /* debug sanity */
-    idle_vcpu[0] = current;
 
     setup_virtual_regions(NULL, NULL);
     /* Initialize traps early allow us to get backtrace when an error occurred */
xen/arch/x86/setup.c +0 -1
index 2fbf7d5..2081592 100644
@@ -691,7 +691,6 @@ void __init noreturn __start_xen(unsigned long mbi_p)
 
     set_processor_id(0);
     set_current(INVALID_VCPU); /* debug sanity. */
-    idle_vcpu[0] = current;
     init_shadow_spec_ctrl_state();
 
     percpu_init_areas();
xen/arch/x86/tboot.c +1 -1
index f3fdee4..fff00bf 100644
@@ -395,7 +395,7 @@ void tboot_shutdown(uint32_t shutdown_type)
      * During early boot, we can be called by panic before idle_vcpu[0] is
      * setup, but in that case we don't need to change page tables.
      */
-    if ( idle_vcpu[0] != INVALID_VCPU )
+    if ( idle_vcpu[0] )
         write_ptbase(idle_vcpu[0]);
 
     ((void(*)(void))(unsigned long)g_tboot_shared->shutdown_entry)();
xen/common/domain.c +18 -10
index 66054b3..a0d950c 100644
@@ -138,7 +138,21 @@ struct vcpu *vcpu_create(
 {
     struct vcpu *v;
 
-    BUG_ON((!is_idle_domain(d) || vcpu_id) && d->vcpu[vcpu_id]);
+    /*
+     * Sanity check some input expectations:
+     *  - d->max_vcpus and d->vcpu[] should be set up
+     *  - vcpu_id should be bounded by d->max_vcpus
+     *  - Vcpus should be tightly packed and allocated in ascending order
+     *    (except for the idle domain).
+     *  - No previous vcpu with this id should be allocated
+     */
+    if ( !d->max_vcpus || !d->vcpu || vcpu_id >= d->max_vcpus ||
+         (!is_idle_domain(d) && vcpu_id && !d->vcpu[vcpu_id - 1]) ||
+         d->vcpu[vcpu_id] )
+    {
+        ASSERT_UNREACHABLE();
+        return NULL;
+    }
 
     if ( (v = alloc_vcpu_struct()) == NULL )
         return NULL;
@@ -178,16 +192,10 @@ struct vcpu *vcpu_create(
     if ( arch_vcpu_create(v) != 0 )
         goto fail_sched;
 
+    /* Insert the vcpu into the domain's vcpu list. */
     d->vcpu[vcpu_id] = v;
-    if ( vcpu_id != 0 )
-    {
-        int prev_id = v->vcpu_id - 1;
-        while ( (prev_id >= 0) && (d->vcpu[prev_id] == NULL) )
-            prev_id--;
-        BUG_ON(prev_id < 0);
-        v->next_in_list = d->vcpu[prev_id]->next_in_list;
-        d->vcpu[prev_id]->next_in_list = v;
-    }
+    if ( !is_idle_domain(d) && vcpu_id > 0 )
+        d->vcpu[vcpu_id - 1]->next_in_list = v;
 
     /* Must be called after making new vcpu visible to for_each_vcpu(). */
     vcpu_check_shutdown(v);
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 1/1
#14 lore raw

Re: [PATCH v2] xen/vcpu: Rework sanity checks in vcpu_create()

Quoted 19 lines · Andrew Cooper

Poisoning idle_vcpu[0] with the sanity debug value isn't actually a clever idea, because it passes a NULL pointer check but isn't a usable vcpu. It is also the reason for the (!is_idle_domain(d) || vcpu_id) part of the existing sanity BUG_ON().

Now that d->max_vcpus is appropriately set up before vcpu_create() is called, we can properly range check the requested vcpu_id. Drop the BUG_ON() and replace it with code which is runtime safe but non-fatal.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Jason Andryuk <[email protected]>

Quoted 4 lines

v2:
* Fix the tboot check following the un-poisioning of idle_vcpu[0]
* Exclude the idle domain from the next_in_list list, and vastly simplify the linking logic.

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

#15 lore raw

Re: [PATCH v2] xen/vcpu: Rework sanity checks in vcpu_create()

In reply to Andrew Cooper
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 11.09.18 at 18:46, <[email protected]> wrote:

Poisoning idle_vcpu[0] with the sanity debug value isn't actually a clever idea, because it passes a NULL pointer check but isn't a usable vcpu. It is also the reason for the (!is_idle_domain(d) || vcpu_id) part of the existing sanity BUG_ON().

But you completely discount the intended effect of this poisoning:
During early boot, a NULL deref is liable to not fault, while a deref of INVALID_VCPU is always going to (on x86 at least).

xen/common/domain.c struct vcpu *vcpu_create(

Quoted 3 lines
xen/common/domain.c +0 -0
@@ -138,7 +138,21 @@ struct vcpu *vcpu_create(

This patch does not look to be based on current staging.

Quoted 4 lines
xen/common/domain.c +0 -1
 {
     struct vcpu *v;
 
-    BUG_ON((!is_idle_domain(d) || vcpu_id) && d->vcpu[vcpu_id]);

xen/common/domain.c struct vcpu *vcpu_create( · line 150

Quoted 10 lines
xen/common/domain.c +10 -0
+    /*
+     * Sanity check some input expectations:
+     *  - d->max_vcpus and d->vcpu[] should be set up
+     *  - vcpu_id should be bounded by d->max_vcpus
+     *  - Vcpus should be tightly packed and allocated in ascending order
+     *    (except for the idle domain).
+     *  - No previous vcpu with this id should be allocated
+     */
+    if ( !d->max_vcpus || !d->vcpu || vcpu_id >= d->max_vcpus ||
+         (!is_idle_domain(d) && vcpu_id && !d->vcpu[vcpu_id - 1]) ||

Note how you still require an is_idle_domain() special case here anyway.

xen/common/domain.c struct vcpu *vcpu_create( · line 154

Quoted 4 lines
xen/common/domain.c +4 -0
+         d->vcpu[vcpu_id] )
+    {
+        ASSERT_UNREACHABLE();
+        return NULL;

I assume you consider it acceptable for release builds to report back -ENOMEM in the (hopefully indeed impossible) case of execution going this path?

Quoted 7 lines
xen/common/domain.c +1 -1
@@ -178,16 +192,10 @@ struct vcpu *vcpu_create(
     if ( arch_vcpu_create(v) != 0 )
         goto fail_sched;
 
+    /* Insert the vcpu into the domain's vcpu list. */
     d->vcpu[vcpu_id] = v;
-    if ( vcpu_id != 0 )

xen/common/domain.c struct vcpu *vcpu_create( · line 198

Quoted 10 lines
xen/common/domain.c +2 -8
-    {
-        int prev_id = v->vcpu_id - 1;
-        while ( (prev_id >= 0) && (d->vcpu[prev_id] == NULL) )
-            prev_id--;
-        BUG_ON(prev_id < 0);
-        v->next_in_list = d->vcpu[prev_id]->next_in_list;
-        d->vcpu[prev_id]->next_in_list = v;
-    }
+    if ( !is_idle_domain(d) && vcpu_id > 0 )
+        d->vcpu[vcpu_id - 1]->next_in_list = v;

While before this change for_each_vcpu(idle_domain) was broken only for the (currently impossible on x86 at least) case of CPU0 not being online (nor parked), afaict it will now be broken altogether, leading to NULL deref-s when used. Is that really what you want (if so, the description should say so, and why that's okay)?

Jan

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