Skip to contentSkip to conversation

xen: domain_update_node_affinity: Correct the ASSERT

PATCH In review Julien Grall 3 participants 5 messages Aug 1, 2014 – Aug 7, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: domain_update_node_affinity: Correct the ASSERT

The commit bac6334b5 "move domain to cpupool0 before destroying it" make Xen crashes when a domain is destroyed with d->vcpus allocated but no VCPU initialized.

Assertion '!cpumask_empty(dom_cpumask)' failed at domain.c:452 Xen call trace:

    [<00207bd8>] domain_update_node_affinity+0x10c/0x238 (PC)
    [<00000004>] 00000004 (LR)
    [<00226870>] sched_move_domain+0x3cc/0x42c
    [<0020925c>] domain_kill+0xc8/0x178
    [<00206a0c>] do_domctl+0xaac/0x15e4
    [<002529c0>] do_trap_hypervisor+0xc5c/0xf94
    [<002559f0>] return_from_trap+0/0x4

Fix the ASSERT to check if d->vcpu is allocated and VCPU 0 is initialized.

Cc George Dunlap <[email protected]>
Cc Juergen Gross <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Ian Jackson <[email protected]>
Cc Jan Beulich <[email protected]>
Cc Keir Fraser <[email protected]>
Cc Tim Deegan <[email protected]>

---
This patch should be backported to Xen 4.4

Changes in v2:
- Add specify the offended commit ID in the message

---
 xen/common/domain.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
xen/common/domain.c +1 -1
index d7a84cf..188b769 100644
@@ -449,7 +449,7 @@ void domain_update_node_affinity(struct domain *d)
         }
         /* Filter out non-online cpus */
         cpumask_and(dom_cpumask, dom_cpumask, online);
-        ASSERT(!cpumask_empty(dom_cpumask));
+        ASSERT( !d->vcpu || !d->vcpu[0] || !cpumask_empty(dom_cpumask));
         /* And compute the intersection between hard, online and soft */
         cpumask_and(dom_cpumask_soft, dom_cpumask_soft, dom_cpumask);
 
Signature · 1 line
1.9.3
#1 lore raw

xen/common/domain.c void domain_update_node_affinity(struct domain *d) · line 455

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 01.08.14 at 16:52, <[email protected]> wrote:
xen/common/domain.c +1 -1
@@ -449,7 +449,7 @@ void domain_update_node_affinity(struct domain *d)
         }
         /* Filter out non-online cpus */
         cpumask_and(dom_cpumask, dom_cpumask, online);
-        ASSERT(!cpumask_empty(dom_cpumask));
+        ASSERT( !d->vcpu || !d->vcpu[0] || !cpumask_empty(dom_cpumask));
         /* And compute the intersection between hard, online and soft */
         cpumask_and(dom_cpumask_soft, dom_cpumask_soft, dom_cpumask);
 

Actually, with sched_move_domain() having

    /* Do we have vcpus already? If not, no need to update node-affinity */
    if ( d->vcpu )
        domain_update_node_affinity(d);

it should really just be _that_ if() condition to get extended, and the ASSERT() left alone altogether. Or, if any other path can be proven to possibly reach the function with no vCPU allocated (I just went through them and didn't spot any), then it should really be an early bail from the function rather than a pointlessly complicated ASSERT() expression. (And for the record, your expression has a coding style violation anyway in that it begins with a space.)

Jan

#2 lore raw
Quoted 19 lines · Jan Beulich

xen/common/domain.c void domain_update_node_affinity(struct domain *d) · line 455

Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 01.08.14 at 16:52, <[email protected]> wrote:
xen/common/domain.c +1 -1
@@ -449,7 +449,7 @@ void domain_update_node_affinity(struct domain *d)
          }
          /* Filter out non-online cpus */
          cpumask_and(dom_cpumask, dom_cpumask, online);
-        ASSERT(!cpumask_empty(dom_cpumask));
+        ASSERT( !d->vcpu || !d->vcpu[0] || !cpumask_empty(dom_cpumask));
          /* And compute the intersection between hard, online and soft */
          cpumask_and(dom_cpumask_soft, dom_cpumask_soft, dom_cpumask);
 

Actually, with sched_move_domain() having

     /* Do we have vcpus already? If not, no need to update node-affinity */
     if ( d->vcpu )
         domain_update_node_affinity(d);
Quoted 7 lines

it should really just be _that_ if() condition to get extended, and the ASSERT() left alone altogether. Or, if any other path can be proven to possibly reach the function with no vCPU allocated (I just went through them and didn't spot any), then it should really be an early bail from the function rather than a pointlessly complicated ASSERT() expression. (And for the record, your expression has a coding style violation anyway in that it begins with a space.)

I think changing the if() was what Julien started with; but overall I think that it makes more sense to update the assumption of the code in question than to require all the callers to be careful not to trip over it.

Doing an early bail might make sense as well.

-George

#3 lore raw
Quoted 31 lines · George Dunlap
Quoted 22 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 01.08.14 at 16:52, <[email protected]> wrote:
xen/common/domain.c +1 -1
@@ -449,7 +449,7 @@ void domain_update_node_affinity(struct domain *d)
          }
          /* Filter out non-online cpus */
          cpumask_and(dom_cpumask, dom_cpumask, online);
-        ASSERT(!cpumask_empty(dom_cpumask));
+        ASSERT( !d->vcpu || !d->vcpu[0] ||
 !cpumask_empty(dom_cpumask));
          /* And compute the intersection between hard, online and

soft */

Quoted 2 lines
          cpumask_and(dom_cpumask_soft, dom_cpumask_soft, dom_cpumask);

Actually, with sched_move_domain() having

     /* Do we have vcpus already? If not, no need to update
node-affinity */
     if ( d->vcpu )
         domain_update_node_affinity(d);
Quoted 7 lines

it should really just be _that_ if() condition to get extended, and the ASSERT() left alone altogether. Or, if any other path can be proven to possibly reach the function with no vCPU allocated (I just went through them and didn't spot any), then it should really be an early bail from the function rather than a pointlessly complicated ASSERT() expression. (And for the record, your expression has a coding style violation anyway in that it begins with a space.)

Quoted 5 lines

I think changing the if() was what Julien started with; but overall I think that it makes more sense to update the assumption of the code in question than to require all the callers to be careful not to trip over it.

Doing an early bail might make sense as well.

Ok. So which one should I choose? The early bail out?

Regards,

Signature · 1 line
Julien Grall
#4 lore raw
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 07.08.14 at 17:04, <[email protected]> wrote:
Quoted 31 lines · George Dunlap
Quoted 29 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 01.08.14 at 16:52, <[email protected]> wrote:
xen/common/domain.c +1 -1
@@ -449,7 +449,7 @@ void domain_update_node_affinity(struct domain *d)
          }
          /* Filter out non-online cpus */
          cpumask_and(dom_cpumask, dom_cpumask, online);
-        ASSERT(!cpumask_empty(dom_cpumask));
+        ASSERT( !d->vcpu || !d->vcpu[0] ||
 !cpumask_empty(dom_cpumask));
          /* And compute the intersection between hard, online and

soft */

Quoted 2 lines
          cpumask_and(dom_cpumask_soft, dom_cpumask_soft, dom_cpumask);

Actually, with sched_move_domain() having

     /* Do we have vcpus already? If not, no need to update
node-affinity */
     if ( d->vcpu )
         domain_update_node_affinity(d);

it should really just be _that_ if() condition to get extended, and the ASSERT() left alone altogether. Or, if any other path can be proven to possibly reach the function with no vCPU allocated (I just went through them and didn't spot any), then it should really be an early bail from the function rather than a pointlessly complicated ASSERT() expression. (And for the record, your expression has a coding style violation anyway in that it begins with a space.)

Quoted 7 lines
Quoted 5 lines

I think changing the if() was what Julien started with; but overall I think that it makes more sense to update the assumption of the code in question than to require all the callers to be careful not to trip over it.

Doing an early bail might make sense as well.

Ok. So which one should I choose? The early bail out?

I would indeed favor that over the altered assertion.

Jan