Skip to contentSkip to conversation

xen/sched: fix freeing of per-vcpu data

PATCH In review Juergen Gross 3 participants 10 messages Sep 25, 2019 – Sep 27, 2019

lore
Share & tools
lore
#0 lore raw

cover xen/sched: fix freeing of per-vcpu data

Fix two latent bugs discovered in review of my core scheduling series.

For the series:

Juergen Gross (2):
xen/sched: fix locking in a653sched_free_vdata() xen/sched: fix freeing per-vcpu data in sched_move_domain()

 xen/common/sched_arinc653.c | 6 ++++++
 xen/common/schedule.c       | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)
Signature · 7 lines
2.16.4


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

PATCH 1/2 xen/sched: fix locking in a653sched_free_vdata()

The arinc653 scheduler's free_vdata() function is missing proper
locking: as it is modifying the scheduler's private vcpu list it needs to take the scheduler lock during that operation.

---
 xen/common/sched_arinc653.c | 6 ++++++
 1 file changed, 6 insertions(+)
xen/common/sched_arinc653.c +6 -0
index 72b988ea5f..d47b747ef4 100644
@@ -442,16 +442,22 @@ a653sched_alloc_vdata(const struct scheduler *ops, struct vcpu *vc, void *dd)
 static void
 a653sched_free_vdata(const struct scheduler *ops, void *priv)
 {
+    a653sched_priv_t *sched_priv = SCHED_PRIV(ops);
     arinc653_vcpu_t *av = priv;
+    unsigned long flags;
 
     if (av == NULL)
         return;
 
+    spin_lock_irqsave(&sched_priv->lock, flags);
+
     if ( !is_idle_vcpu(av->vc) )
         list_del(&av->list);
 
     xfree(av);
     update_schedule_vcpus(ops);
+
+    spin_unlock_irqrestore(&sched_priv->lock, flags);
 }
 
 /**
Signature · 7 lines
2.16.4


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

Re: [Xen-devel] [PATCH 1/2] xen/sched: fix locking in a653sched_free_vdata()

Quoted 5 lines · Juergen Gross

The arinc653 scheduler's free_vdata() function is missing proper
locking: as it is modifying the scheduler's private vcpu list it needs to take the scheduler lock during that operation.

(and maybe also Suspected-by)

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

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

Re: [Xen-devel] [PATCH 1/2] xen/sched: fix locking in a653sched_free_vdata()

In reply to Juergen Gross
Quoted 7 lines · Juergen Gross

The arinc653 scheduler's free_vdata() function is missing proper
locking: as it is modifying the scheduler's private vcpu list it needs
to take the scheduler lock during that operation.

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)

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

#4 lore raw

Re: [Xen-devel] [PATCH 1/2] xen/sched: fix locking in a653sched_free_vdata()

Quoted 9 lines · Dario Faggioli
Quoted 7 lines · Juergen Gross

The arinc653 scheduler's free_vdata() function is missing proper
locking: as it is modifying the scheduler's private vcpu list it needs
to take the scheduler lock during that operation.

As this patch is a prerequisite for my core scheduling series I'd really appreciate if it could be committed rather sooner than later.

Josh, Robert, could you please comment?

Or is Dario's R-b (and Jan's as well) enough in this rather simple and obvious case?

Juergen

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

#5 lore raw

Re: [Xen-devel] [PATCH 1/2] xen/sched: fix locking in a653sched_free_vdata()

Quoted 11 lines · Jürgen Groß
Quoted 9 lines · Dario Faggioli
Quoted 7 lines · Juergen Gross

The arinc653 scheduler's free_vdata() function is missing proper
locking: as it is modifying the scheduler's private vcpu list it needs
to take the scheduler lock during that operation.

Quoted 7 lines

As this patch is a prerequisite for my core scheduling series I'd really appreciate if it could be committed rather sooner than later.

Josh, Robert, could you please comment?

Or is Dario's R-b (and Jan's as well) enough in this rather simple and obvious case?

I was more or less planning to time out on waiting for their ack later today.

Jan

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

#6 lore raw

Re: [Xen-devel] [PATCH 1/2] xen/sched: fix locking in a653sched_free_vdata()

Quoted 15 lines · Jan Beulich
Quoted 14 lines · Jürgen Groß
Quoted 9 lines · Dario Faggioli
Quoted 7 lines · Juergen Gross

The arinc653 scheduler's free_vdata() function is missing proper
locking: as it is modifying the scheduler's private vcpu list it needs
to take the scheduler lock during that operation.

As this patch is a prerequisite for my core scheduling series I'd really appreciate if it could be committed rather sooner than later.

Quoted 7 lines
Quoted 4 lines

Josh, Robert, could you please comment?

Or is Dario's R-b (and Jan's as well) enough in this rather simple and obvious case?

I was more or less planning to time out on waiting for their ack later today.

Thanks.

Juergen

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

#7 lore raw

PATCH 2/2 xen/sched: fix freeing per-vcpu data in sched_move_domain()

In reply to Juergen Gross

In case of an allocation error of per-vcpu data in sched_move_domain() the already allocated data is freed just using xfree(). This is wrong as some schedulers need to do additional operations (e.g. the arinc653 scheduler needs to remove the vcpu-data from a list).

So instead xfree() make use of the sched_free_vdata() hook.

---
 xen/common/schedule.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/schedule.c +1 -1
index 13b5ffc7cf..13c17fe944 100644
@@ -386,7 +386,7 @@ int sched_move_domain(struct domain *d, struct cpupool *c)
         if ( vcpu_priv[v->vcpu_id] == NULL )
         {
             for_each_vcpu ( d, v )
-                xfree(vcpu_priv[v->vcpu_id]);
+                sched_free_vdata(c->sched, vcpu_priv[v->vcpu_id]);
             xfree(vcpu_priv);
             sched_free_domdata(c->sched, domdata);
             return -ENOMEM;
Signature · 7 lines
2.16.4


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

Re: [Xen-devel] [PATCH 2/2] xen/sched: fix freeing per-vcpu data in sched_move_domain()

Quoted 8 lines · Juergen Gross

In case of an allocation error of per-vcpu data in sched_move_domain() the already allocated data is freed just using xfree(). This is wrong as some schedulers need to do additional operations (e.g. the arinc653 scheduler needs to remove the vcpu-data from a list).

So instead xfree() make use of the sched_free_vdata() hook.

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

Reviewed-by on v1 2/2
#9 lore raw

Re: [Xen-devel] [PATCH 2/2] xen/sched: fix freeing per-vcpu data in sched_move_domain()

In reply to Juergen Gross
Quoted 11 lines · Juergen Gross

In case of an allocation error of per-vcpu data in sched_move_domain()
the already allocated data is freed just using xfree(). This is wrong as some schedulers need to do additional operations (e.g. the arinc653
scheduler needs to remove the vcpu-data from a list).

So instead xfree() make use of the sched_free_vdata() hook.

Regards

Signature · 6 lines
Dario Faggioli, Ph.D
http://about.me/dario.faggioli
Virtualization Software Engineer
SUSE Labs, SUSE https://www.suse.com/
-------------------------------------------------------------------
<<This happens because _I_ choose it to happen!>> (Raistlin Majere)

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