From nobody Mon Aug 01 14:19:16 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4LxKxd3NGSz4XtT2; Mon, 1 Aug 2022 14:19:17 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4LxKxd0bggz49Cv; Mon, 1 Aug 2022 14:19:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659363557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9/PJ83/u2L4M6P+fqITFsUx5QSk0Xk3GzZHm+OxyCCw=; b=ErIRWyzDVbaTozPZFShrWvs0Z1bHEU0lMKQzquwdY/XJ0AtRB1WZVqzcygKlQHiXuZKeLi 5qshtj4vOo7wtiiBFigVpxIC1skWOyAu4onY/J6nnj4NTtT6QYh7gpffA73jpab1QCtj1t 8ekrfMHpRLOfupMZDnFbTTJKDlg+zNrNL+TTvreT+mEqaoq6rzCGnUOkSXcSRdK4uzaIaV 2Vtq388bDdnBy6n8N4JEA3fZ4QAbMaQxNGEFplfC8/8Mb/n470r8FNqAIKbzxdAXgGtqmc zvQ9CB+OLLfIJhuFcobWbe9YAdx5vIGxEQ1b5oXFCDA6HQb0MydnrpEwY4dhPQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4LxKxc6qQyzcMd; Mon, 1 Aug 2022 14:19:16 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 271EJG66025289; Mon, 1 Aug 2022 14:19:16 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 271EJGAe025288; Mon, 1 Aug 2022 14:19:16 GMT (envelope-from git) Date: Mon, 1 Aug 2022 14:19:16 GMT Message-Id: <202208011419.271EJGAe025288@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 096c0b9b469b - stable/13 - sched_ule: Ensure we hold the thread lock when modifying td_flags List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 096c0b9b469b9fab1a4d73d13541298af41da9c1 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1659363557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=9/PJ83/u2L4M6P+fqITFsUx5QSk0Xk3GzZHm+OxyCCw=; b=ji7Mf1OB6HbGuMziQjoQQpZOWn54u0D1rJLNNkTbNDAw4r9vy1yOVfC5eiKzmLE+VrMyqY 5N+Rvbvk9Foe4nIqwmv1k8hd2NV1TbIH7gihxzi+cmqWV2KFC9EyQMlKo4aua/CgOS7C+k hUOxBjao3tMuVWDUV2bV7516BhxhyOYqirzn98yZSmpkxgbAXopSwQ3p5CYhpjNGoCupaE dVcVU1ZFPal3nYoL0Hwg+Duw7Szknzu/iTF4dev6KfvOhYECy3789N9QK9SjFLZ2rusBQD CuawdCptey6amJaijwRzPqGqvz+HQF/NuWYCywucxk+bDwiKswfprXtu6nJL9w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1659363557; a=rsa-sha256; cv=none; b=JDHX463t7Ifi+gLnkbk3/L8hbmNSwzMpyixyp/UiDmKM9DjIbz0auih61jgJDNJlqhann9 H9QC16XOznuaCqCmc+4h8a4dloCMgsSLXK4V+XGINWS40BtZ2Cp4nTjr5NoBHKTHdKz1nF OtNxSFdtNnDf1+u3wmDb6dHMqtkS/QaqnVkvwLgKZH60ZLAUVpQldhUqyBHd2BxxqtQbnY Xhg/HIPkHHQed3mNvKI7uqpEEPBkbk/3+YK3N0AcCdosM8SuFBe60QWI25PjB0kT+RZgnX pamwGHg7AziaDRyeqPM3pStDNtAxWR6w1vb1ET2FxJVXqjQXezjNXarvSIKl+g== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=096c0b9b469b9fab1a4d73d13541298af41da9c1 commit 096c0b9b469b9fab1a4d73d13541298af41da9c1 Author: Mark Johnston AuthorDate: 2022-07-18 19:50:45 +0000 Commit: Mark Johnston CommitDate: 2022-08-01 14:13:24 +0000 sched_ule: Ensure we hold the thread lock when modifying td_flags The load balancer may force a running thread to reschedule and pick a new CPU. To do this it sets some flags in the thread running on a loaded CPU. But the code assumed that a running thread's lock is the same as that of the corresponding runqueue, and there are small windows where this is not true. In this case, we can end up with non-atomic modifications to td_flags. Since this load balancing is best-effort, simply give up if the thread's lock doesn't match; in this case the thread is about to enter the scheduler anyway. Reviewed by: kib Reported by: glebius Fixes: e745d729be60 ("sched_ule(4): Improve long-term load balancer.") Sponsored by: The FreeBSD Foundation (cherry picked from commit bd980ca847b76439bd27a4144cf0dd69d48b33af) --- sys/kern/sched_ule.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 519b8275cf7d..0a830da7e2d5 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -871,7 +871,8 @@ sched_balance_group(struct cpu_group *cg) */ TDQ_LOCK(tdq); td = tdq->tdq_curthread; - if ((td->td_flags & TDF_IDLETD) == 0 && + if (td->td_lock == TDQ_LOCKPTR(tdq) && + (td->td_flags & TDF_IDLETD) == 0 && THREAD_CAN_MIGRATE(td)) { td->td_flags |= TDF_NEEDRESCHED | TDF_PICKCPU; if (high != curcpu)