From: Dario Faggioli Subject: Re: crash in csched_load_balance after xl vcpu-pin Date: Tue, 10 Apr 2018 13:31:05 +0200 Message-ID: <7be768660a2060fda2dc0d6a6fc8a38f6fcc6b09.camel@suse.com> References: <20180410085729.GA472@aepfle.de> <1FC4A4E4-BA31-4B3A-9D3A-7E31CAAC9AE5@citrix.com> <95482342-8b80-e295-badf-6b20ad09276f@citrix.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5880288448331413786==" Return-path: In-Reply-To: <95482342-8b80-e295-badf-6b20ad09276f@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" To: George Dunlap , Olaf Hering Cc: "xen-devel@lists.xen.org" List-Id: xen-devel@lists.xenproject.org --===============5880288448331413786== Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-p7jmItCHr2lKgqgssCc0" --=-p7jmItCHr2lKgqgssCc0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 2018-04-10 at 11:59 +0100, George Dunlap wrote: > On 04/10/2018 11:33 AM, Dario Faggioli wrote: > > On Tue, 2018-04-10 at 09:34 +0000, George Dunlap wrote: > > > Assuming the bug is this one: > > >=20 > > > BUG_ON( cpu !=3D snext->vcpu->processor ); > > >=20 > >=20 > > Yes, it is that one. > >=20 > > Another stack trace, this time from a debug=3Dy built hypervisor, of > > what > > we are thinking it is the same bug (although reproduced in a > > slightly > > different way) is this: > >=20 > > (XEN) ----[ Xen-4.7.2_02-36.1.12847.11.PTF x86_64 debug=3Dy Not > > tainted ]---- > > (XEN) CPU: 45 > > (XEN) RIP: e008:[] > > sched_credit.c#csched_schedule+0x361/0xaa9 > > ... > > (XEN) Xen call trace: > > (XEN) [] > > sched_credit.c#csched_schedule+0x361/0xaa9 > > (XEN) [] schedule.c#schedule+0x109/0x5d6 > > (XEN) [] softirq.c#__do_softirq+0x7f/0x8a > > (XEN) [] do_softirq+0x13/0x15 > > (XEN) [] vmx_asm_do_vmentry+0x25/0x2a > >=20 > > (I can provide it all, if necessary.) > >=20 > > I've done some analysis, although when we still were not entirely > > sure > > that changing the affinities was the actual cause (or, at least, > > what > > is triggering the whole thing). > >=20 > > In the specific case of this stack trace, the current vcpu running > > on > > CPU 45 is d3v11. It is not in the runqueue, because it has been > > removed, and not added back to it, and the reason is it is not > > runnable > > (it has VPF_migrating on in pause_flags). > >=20 > > The runqueue of pcpu 45 looks fine (i.e., it is not corrupt or > > anything > > like that), it has d3v10,d9v1,d32767v45 in it (in this order) > >=20 > > d3v11->processor is 45, so that is also fine. > >=20 > > Basically, d3v11 wants to move away from pcpu 45, and this might > > (but > > that's not certain) be the reson because we're rescheduling. The > > fact > > that there are vcpus wanting to migrate can very well be the cause > > of > > affinity being changed. > >=20 > > Now, the problem is that, looking into the runqueue, I found out > > that > > d3v10->processor=3D32. I.e., d3v10 is queued in pcpu 45's runqueue, > > with > > processor=3D32, which really shouldn't happen. > >=20 > > This leads to the bug triggering, as, in csched_schedule(), we read > > the > > head of the runqueue with: > >=20 > > snext =3D __runq_elem(runq->next); > >=20 > > and then we pass snext to csched_load_balance(), where the BUG_ON > > is. > >=20 > > Another thing that I've found out, is that all "misplaced" vcpus > > (i.e., > > in this and also in other manifestations of this bug) have their > > csched_vcpu.flags=3D4, which is CSCHED_FLAGS_VCPU_MIGRATING. > >=20 > > This, basically, is again a sign of vcpu_migrate() having been > > called, > > on d3v10 as well, which in turn has called csched_vcpu_pick(). > >=20 > > > a nasty race condition=E2=80=A6 a vcpu has just been taken off the > > > runqueue > > > of the current pcpu, but it=E2=80=99s apparently been assigned to a > > > different > > > cpu. > > >=20 > >=20 > > Nasty indeed. I've been looking into this on and off, but so far I > > haven't found the root cause. > >=20 > > Now that we know for sure that it is changing affinity that trigger > > it, > > the field of the investigation can be narrowed a little bit... But > > I > > still am finding hard to spot where the race happens. > >=20 > > I'll look more into this later in the afternoon. I'll let know if > > something comes to mind. >=20 > Actually, it looks quite simple: schedule.c:vcpu_move_locked() is > supposed to actually do the moving; if vcpu_scheduler()->migrate is > defined, it calls that; otherwise, it just sets v- > >processor. Credit1 > doesn't define migrate. So when changing the vcpu affinity on > credit1, > v->processor is simply modified without it changing runqueues. >=20 > The real question is why it's so hard to actually trigger any > problems! >=20 Wait, but when vcpu_move_locked() is called, the vcpu being moved should not be in any runqueue. In fact, it is called from vcpu_migrate() which, in its turn, is always preceded by a call to vcpu_sleep_nosync(), that removes the vcpu from the runqueue. The only exception is when it is called from context_saved(). But then again, the vcpu on which it is called is not on the runqueue, because it was found not runnable. That is why things works... well, apart from this bug. :-) I mean, the root cause of this bug may very well be that there is a code path that leads to calling vcpu_move_locked() on a vcpu that is still in a runqueue... but have you actually identified it? > But as a quick fix, implementing csched_vcpu_migrate() is probably > the > best solution. Do you want to pick that up, or should I? >=20 And what should csched_vcpu_migrate() do, apart from changing vc->processor? Regards, Dario --=20 <> (Raistlin Majere) ----------------------------------------------------------------- Dario Faggioli, Ph.D, http://about.me/dario.faggioli Software Engineer @ SUSE https://www.suse.com/ --=-p7jmItCHr2lKgqgssCc0 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEES5ssOj3Vhr0WPnOLFkJ4iaW4c+4FAlrMoHoACgkQFkJ4iaW4 c+5zZw/+PsSprBSfNvZg8D8WfKggPD7XSI8JTP5JZPr9w1cHDnLcTwrmZXUOlovu JsgRK1avBdwPEkaCaM/veAFwVPL9qV8bgIx5RDSDjEh4cWlKxSfmePKtXnIdhrgs g17m67FSJvA1exYL9IWdQhWeYQHTMUOBgIwzV61dIJZYfl0eXlGcCxR//E+bEdlZ EBOdQHmtZTtcAM/HHHsRZQ/MZrhjsYc2PTG2jrYSKCKrK1rYaF1QrU/E1uyr14c2 7HnjqddxJFd6ebzjqcGghuKK/tGVS6uI9bs6wQYr2j4/P45LRpHIb6UOBVTNP00Y emDtQwUB/OqcX+F+mRhG5zKbEze7mCWMSztrtFcKzz68LgJrAUSsJffASBkzmPjq qcp3ALdzpq8p5bPcvChIP/C12S9a2BusuRkqEAk2JTRm7b6Neibwb6Tch8tHxWui hNib2iPdDlAO7i5wDASSVwVKM/ZQC4OuiL7rcrfsDdgWXPh7GBiR9AwLmne5n7pn m22/F+xm3PDjFoM/M2rpeTW+SeRgl3Sd/iUwozDBGqehHd3G5mD4Atmfp/qwnCxs vZrFwYc/RVdiT96DVAA8dbFjZUgJc0jwUPp0/BV70C9Wvt216jnPjeDRSwpldewB VJ+y0FD+DuxIZk5moe3e/mCBbgRxK3QAjoiUIb8KCdQiRZl+G7o= =RT2L -----END PGP SIGNATURE----- --=-p7jmItCHr2lKgqgssCc0-- --===============5880288448331413786== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KWGVuLWRldmVs IG1haWxpbmcgbGlzdApYZW4tZGV2ZWxAbGlzdHMueGVucHJvamVjdC5vcmcKaHR0cHM6Ly9saXN0 cy54ZW5wcm9qZWN0Lm9yZy9tYWlsbWFuL2xpc3RpbmZvL3hlbi1kZXZlbA== --===============5880288448331413786==--