Hit ASSERT in credit2 code with NR_CPUS=1 build
Hello,
While looking at the NR_CPUS == 1 build I realized I could reliable trigger the following ASSERT by creating a guest (note that dom0 seems to be fine):
(XEN) Assertion 'i != cpu' failed at credit2.c:1725
(XEN) ----[ Xen-4.15.0-rc x86_64 debug=y Tainted: C ]----
(XEN) CPU: 0
(XEN) RIP: e008:[<ffff82d040249399>] common/sched/credit2.c#runq_tickle+0x469/0x571
(XEN) RFLAGS: 0000000000010046 CONTEXT: hypervisor (d4v0)
(XEN) rax: ffffffffffffffff rbx: 0000000000000000 rcx: 0000000000000000 (XEN) rdx: ffff83086c62feb0 rsi: 0000012774fba66c rdi: ffff8307e11d5d40 (XEN) rbp: ffff83008c8c7cf8 rsp: ffff83008c8c7c68 r8: ffff83086c66d6c0 (XEN) r9: ffff82d0405d1218 r10: 0000000000000000 r11: ffff83086c631000 (XEN) r12: ffff83086c6437c0 r13: 0000000000000000 r14: ffff83086c62fe20 (XEN) r15: ffff82d0405d0320 cr0: 0000000080050033 cr4: 00000000003526e0 (XEN) cr3: 00000007e130d000 cr2: ffff88826910cb38 (XEN) fsb: 00007efee038b780 gsb: ffff888273400000 gss: 0000000000000000
(XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: e010 cs: e008
(XEN) Xen code around <ffff82d040249399> (common/sched/credit2.c#runq_tickle+0x469/0x571):
(XEN) ac ff 75 3d 0f 0b 0f 0b <0f> 0b c7 45 ac 00 00 00 00 48 8d 05 6f 7e 38 00 (XEN) Xen stack trace from rsp=ffff83008c8c7c68:
(XEN) ffff83008c8c7c88 0000012774fba66c ffff82d0404ab4e0 ffff82d0405d0320 (XEN) ffff82d0405d0320 ffff83086c62feb0 ffff83086c643760 ffffffff00000002 (XEN) ffff83008c8c7cd8 ffff82d0402f9234 ffff8307e131e000 0000000000000000 (XEN) ffff83008c8c7ce8 ffff83086c62feb0 ffff83086c62fe20 ffff83086c6437c0 (XEN) 0000012774fba66c ffff82d0405e64a0 ffff83008c8c7d58 ffff82d040249eb6 (XEN) ffff83008c8c7fff ffff82d0404ab4e0 ffff83008c8c7d18 ffff83008c8c7d18 (XEN) ffff83008c8c7d48 ffff83086c62fe20 ffff83086c66d620 ffff8307e11d5d40 (XEN) ffff83086c66d620 0000000000000000 ffff83008c8c7d78 ffff82d040253752 (XEN) ffff83086c61a000 ffff8307e11ca000 ffff83008c8c7da8 ffff82d040255d8b (XEN) ffff8307e11ca000 ffff83086c61a000 ffff8307e131e000 ffff83086c631000 (XEN) ffff83008c8c7df8 ffff82d04031edd6 ffff83086c61a060 0000000000000296 (XEN) 0000012774fb8f84 ffff8307e11ca000 ffff83086c61a000 0000000000000001 (XEN) 0000012774fb8f84 0000000000000000 ffff83008c8c7e38 ffff82d040255e37 (XEN) ffff83008c8c7e28 ffff83086c66d620 0000000000000000 ffff8307e11d5d40 (XEN) 0000000000000000 0000000000000001 ffff83008c8c7e98 ffff82d040256844 (XEN) ffff83086c61a000 ffff83086c62fe20 ffff82d0403953d4 ffff83086c6437c0 (XEN) deadbeefdeadf00d ffff82d0405d6e80 ffff82d0405d6e80 ffffffffffffffff (XEN) ffff83008c8c7fff 0000000000000000 ffff83008c8c7ed8 ffff82d04022dc68 (XEN) ffff82d0403953d4 ffff83086c61a000 0000000000000000 0000000000000000 (XEN) 0000000000000000 0000000000000000 ffff83008c8c7ee8 ffff82d04022dcfd (XEN) Xen call trace: (XEN) [<ffff82d040249399>] R common/sched/credit2.c#runq_tickle+0x469/0x571 (XEN) [<ffff82d040249eb6>] F common/sched/credit2.c#csched2_context_saved+0x27f/0x284 (XEN) [<ffff82d040253752>] F common/sched/core.c#unit_context_saved+0x56/0x84 (XEN) [<ffff82d040255d8b>] F sched_context_switched+0x14d/0x161 (XEN) [<ffff82d04031edd6>] F context_switch+0x15b/0x11dd (XEN) [<ffff82d040255e37>] F common/sched/core.c#sched_context_switch+0x98/0x1e0 (XEN) [<ffff82d040256844>] F common/sched/core.c#schedule+0x216/0x2e5 (XEN) [<ffff82d04022dc68>] F common/softirq.c#__do_softirq+0x8a/0xb6 (XEN) [<ffff82d04022dcfd>] F do_softirq+0x13/0x15 (XEN) [<ffff82d040318176>] F x86_64/entry.S#process_softirqs+0x6/0x20
(XEN)
(XEN)
(XEN) **************************************** (XEN) Panic on CPU 0:
(XEN) Assertion 'i != cpu' failed at credit2.c:1725 (XEN) ****************************************
This corresponds to the following chunk of code:
for_each_cpu(i, &mask)
{
s_time_t score;
/* Already looked at this one above */
ASSERT(i != cpu); <====
score = tickle_score(ops, now, new, i);
if ( score > max )
{
max = score;
ipid = i;
}
}In runq_tickle. I'm afraid I have no clue of what's going on. FTR using a non-debug build with NR_CPUS == 1 does seem to work fine and I don't see any ill effects. Obviously the ASSERT is no longer there.
Thanks, Roger.
Quoted 2 lines · Roger Pau Monné
Hello,
Hey,
Quoted 5 lines
While looking at the
NR_CPUS== 1 build I realized I could reliable trigger the following ASSERT by creating a guest (note that dom0 seems
to be fine):
Yes, I'm (somewhat, not sure if exactly though) able to reproduce.
Quoted 25 lines
(XEN) Assertion 'i != cpu' failed at credit2.c:1725
(XEN) ----[ Xen-4.15.0-rc x86_64 debug=y Tainted: C ]---- (XEN) CPU: 0
(XEN) RIP: e008:[<ffff82d040249399>] common/sched/credit2.c#runq_tickle+0x469/0x571
(XEN) RFLAGS: 0000000000010046 CONTEXT: hypervisor (d4v0) (XEN) rax: ffffffffffffffff rbx: 0000000000000000 rcx:
0000000000000000
(XEN) rdx: ffff83086c62feb0 rsi: 0000012774fba66c rdi:ffff8307e11d5d40
(XEN) rbp: ffff83008c8c7cf8 rsp: ffff83008c8c7c68 r8:ffff83086c66d6c0
(XEN) r9: ffff82d0405d1218 r10: 0000000000000000 r11:ffff83086c631000
(XEN) r12: ffff83086c6437c0 r13: 0000000000000000 r14:ffff83086c62fe20
(XEN) r15: ffff82d0405d0320 cr0: 0000000080050033 cr4:00000000003526e0
(XEN) cr3: 00000007e130d000 cr2:ffff88826910cb38
(XEN) fsb: 00007efee038b780 gsb: ffff888273400000 gss:
0000000000000000
(XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: e010 cs: e008 (XEN) Xen code around <ffff82d040249399> (common/sched/credit2.c#runq_tickle+0x469/0x571):
(XEN) ac ff 75 3d 0f 0b 0f 0b <0f> 0b c7 45 ac 00 00 00 00 48 8d 05
Quoted 9 lines
6f 7e 38 00
(XEN) Xen stack trace from rsp=ffff83008c8c7c68:
[...]
(XEN)
(XEN) **************************************** (XEN) Panic on CPU 0:
(XEN) Assertion 'i != cpu' failed at credit2.c:1725 (XEN) ****************************************
Interesting... So, how do cpumasks look like/work, with NR_CPUS=1 (sorry, I couldn't follow all the aspects of it too closely) ?
I'm asking because, what we're doing here is the following. First of all we put together a cpumask (in mask) out of the intersection of the CPUs that are in the vcpu's hard/soft affinity, are part of this runqueue, are idle and have not been tickled (where tickled == they've been poked and will go through schedule() soon):
cpumask_andnot(&mask, &rqd->active, &rqd->idle);
cpumask_andnot(&mask, &mask, &rqd->tickled);
cpumask_and(&mask, &mask, cpumask_scratch_cpu(cpu));Now, I would very much expect for mask to have at most one bit set (i.e., the one of our only CPU). Actually, considering how unlikely it would be that our only CPU is both idle and not-tickled, I expect mask to be empty most of the times.
Anyway, let's say the cpumask has 1 bit set (in which case, it must be the one associated to CPU 0, I presume?). What we do now is this:
if ( __cpumask_test_and_clear_cpu(cpu, &mask) )
{
...
}Which I think means that, no matter whether or not we enter the loop, we clear the bit. Of course, which bit depends on the value of cpu... But with NR_CPUS=1, I don't see how cpu can have a value different than the ID of the one and only CPU we have.
So, in my mind, now mask is empty. Therefore, I'm currently clueless about why we enter this loop...
Quoted 7 lines
for_each_cpu(i, &mask)
{
s_time_tscore;/* Already looked at this one above */
ASSERT(i != cpu); <====
... and we reach this point.
I tried to build staging here (with NR_CPUS=1), and I think the code for this ASSERT(), for me, is:
test %ebx,%ebx
je ffff82d040245ac5 <runq_tickle+0x48a>
(and ffff82d040245ac5 is of course ud2.)
Snf this kind of makes sense. Or, at least, I'm not surprised that, if we are inside this loop, i is actually equal to cpu.
What I'm surprised about is that we are inside the loop in the first place...
I guess I need to think more about it. Any bright ideas that explain what is going on would be more than appreciated.
Quoted 5 lines
In
runq_tickle. I'm afraid I have no clue of what's going on. FTR using a non-debug build withNR_CPUS== 1 does seem to work fine and I
don't see any ill effects.
Well, yes, special casing cpu and dealing with it outside of the loop is just an optimization, for when soft-affinity is defined for the vcpu. So it makes sense that things work without the ASSERT().
However, the ASSERT() was there as a consistency check, and it looks to me to be a valid one, even with NR_CPUS=1, so I really don't know why it triggers...
Thanks and 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)
Quoted 80 lines · Dario Faggioli
Quoted 2 lines · Roger Pau Monné
Hello,
Hey,
Quoted 5 lines
While looking at the
NR_CPUS== 1 build I realized I could reliable trigger the following ASSERT by creating a guest (note that dom0 seems
to be fine):Yes, I'm (somewhat, not sure if exactly though) able to reproduce.
Quoted 25 lines
(XEN) Assertion 'i != cpu' failed at credit2.c:1725
(XEN) ----[ Xen-4.15.0-rc x86_64 debug=y Tainted: C ]---- (XEN) CPU: 0
(XEN) RIP: e008:[<ffff82d040249399>] common/sched/credit2.c#runq_tickle+0x469/0x571
(XEN) RFLAGS: 0000000000010046 CONTEXT: hypervisor (d4v0) (XEN) rax: ffffffffffffffff rbx: 0000000000000000 rcx:
0000000000000000
(XEN) rdx: ffff83086c62feb0 rsi: 0000012774fba66c rdi:ffff8307e11d5d40
(XEN) rbp: ffff83008c8c7cf8 rsp: ffff83008c8c7c68 r8:ffff83086c66d6c0
(XEN) r9: ffff82d0405d1218 r10: 0000000000000000 r11:ffff83086c631000
(XEN) r12: ffff83086c6437c0 r13: 0000000000000000 r14:ffff83086c62fe20
(XEN) r15: ffff82d0405d0320 cr0: 0000000080050033 cr4:00000000003526e0
(XEN) cr3: 00000007e130d000 cr2:ffff88826910cb38
(XEN) fsb: 00007efee038b780 gsb: ffff888273400000 gss:
0000000000000000
(XEN) ds: 0000 es: 0000 fs: 0000 gs: 0000 ss: e010 cs: e008 (XEN) Xen code around <ffff82d040249399> (common/sched/credit2.c#runq_tickle+0x469/0x571):
(XEN) ac ff 75 3d 0f 0b 0f 0b <0f> 0b c7 45 ac 00 00 00 00 48 8d 05Quoted 9 lines
6f 7e 38 00
(XEN) Xen stack trace from rsp=ffff83008c8c7c68:
[...]
(XEN)
(XEN) **************************************** (XEN) Panic on CPU 0:
(XEN) Assertion 'i != cpu' failed at credit2.c:1725 (XEN) ****************************************Interesting... So, how do cpumasks look like/work, with NR_CPUS=1 (sorry, I couldn't follow all the aspects of it too closely) ?
I'm asking because, what we're doing here is the following. First of all we put together a cpumask (in
mask) out of the intersection of the CPUs that are in the vcpu's hard/soft affinity, are part of this runqueue, are idle and have not been tickled (where tickled == they've been poked and will go throughschedule()soon):cpumask_andnot(&mask, &rqd->active, &rqd->idle); cpumask_andnot(&mask, &mask, &rqd->tickled); cpumask_and(&mask, &mask, cpumask_scratch_cpu(cpu));Now, I would very much expect for
maskto have at most one bit set (i.e., the one of our only CPU). Actually, considering how unlikely it would be that our only CPU is both idle and not-tickled, I expect mask to be empty most of the times.Anyway, let's say the cpumask has 1 bit set (in which case, it must be the one associated to CPU 0, I presume?). What we do now is this:
if (
__cpumask_test_and_clear_cpu(cpu, &mask)){ ... }Which I think means that, no matter whether or not we enter the loop, we clear the bit. Of course, which bit depends on the value of
cpu... But with NR_CPUS=1, I don't see howcpucan have a value different than the ID of the one and only CPU we have.So, in my mind, now
maskis empty. Therefore, I'm currently clueless about why we enter this loop...
Quoted 8 lines
Quoted 7 lines
for_each_cpu(i, &mask)
{
s_time_tscore;/* Already looked at this one above */
ASSERT(i != cpu); <====... and we reach this point.
from xen/cpumask.h:
#define for_each_cpu(cpu, mask) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)(mask))
I'm struggling though why this is this way.
Jan
Quoted 11 lines · Jan Beulich
Quoted 10 lines · Dario Faggioli
So, in my mind, now
maskis empty. Therefore, I'm currently clueless about why we enter this loop...Quoted 7 lines
for_each_cpu(i, &mask)
{
s_time_tscore;/* Already looked at this one above */
ASSERT(i != cpu); <====
Quoted 8 lines
Quoted 1 line
... and we reach this point.
from
xen/cpumask.h:#define for_each_cpu(cpu, mask) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)(mask))I'm struggling though why this is this way.
Quoting Linux 5.11 (where, long ago, our code came from):
#define for_each_cpu(cpu, mask) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) #define for_each_cpu_not(cpu, mask) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask) #define for_each_cpu_wrap(cpu, mask, start) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)(start)) #define for_each_cpu_and(cpu, mask1, mask2) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask1, (void)mask2)
where I find particularly odd that for_each_cpu() and for_each_cpu_not() have the same effect when really they should act on disjoint sets of CPUs.
I can't find anything under Documentation/ there, so my best guess is that this is either a bug we share, or there was some historical reason for the behavior which wasn't written down anywhere.
Jan