From nobody Sat Oct 01 16:13:27 2022 X-Original-To: dev-commits-src-branches@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 4MfsbC4sDLz4cvrG; Sat, 1 Oct 2022 16:13:27 +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 4MfsbC4KwTz3whf; Sat, 1 Oct 2022 16:13:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664640807; 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=LXTtZjhQKvATUtVnxWEV3DoxeBiB3xUct6rJxnDfT6Q=; b=ST7ICmyqt2YIpPZrXE4KDUgeKQZSjTz4zhQc29km1TJzYc3AdjGNGm46gNjBFDwdAK4sPw SRgsB4AOAiK3LPGNL9lHEum/aDXmYEOq7ym7GaZhIEZ0YM+tVXDfUqyiRj0UWy2mt2vIXQ OTQh/xVa0FNpM7HXp+koVbJdGuzA0qF6vdwZMzecfqSV8E/W40xOFF0Fjy49sMhrPCbIkC v3XBTp/53Fbw6tu6kozkj9UaRlcI4TavXb4W+job0J/wMptzgTVZqVKRvwSMb3kBv8BUxG 7EsbHqLbHgT4klxoEZ6ILUojORYj4oskwbGWXg+n8oOFjue2fH5TynZKfMjYYg== 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 4MfsbC3RQwzZjv; Sat, 1 Oct 2022 16:13:27 +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 291GDRHp048978; Sat, 1 Oct 2022 16:13:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 291GDRvW048977; Sat, 1 Oct 2022 16:13:27 GMT (envelope-from git) Date: Sat, 1 Oct 2022 16:13:27 GMT Message-Id: <202210011613.291GDRvW048977@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: 422ba9ac8373 - stable/13 - sched_4bsd: Fix a racy thread state modification List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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: 422ba9ac83731615083ef15d52d30f3418da8fef Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664640807; 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=LXTtZjhQKvATUtVnxWEV3DoxeBiB3xUct6rJxnDfT6Q=; b=NIpV55gX5YCnkwVVD35qlab3GouwMnTaJpiE/6vf2jZvK6NYNGXOO10S9CEiBmdE7PBmeC 4OEqTKPoGL/QdAuVUj/5cJYdUeAzert9aef1x+JOSqBNTHZzkLxGlgDHcXla0LqNhXrcn3 NWH0GTqp7YGK3kK7eaBBNBdcrd29NrFgS7yovNHOOLgVnguXdOiRSgj4jEgTtUnh8+x8RQ jwGt64VcZg4+nBkHbXdffpwr4BHg6Ae+XgDqLACmrqaCI+Hx/91V+ec0CY6KD//DT7mdgb LmqI9fWsY0CymuUFywI6tUD46IaOSWYBRSHEp+CdRzVHNcKsUgSFxFWJOFE8Sw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664640807; a=rsa-sha256; cv=none; b=PsmcVB0t6d9vf1La5jwhYNk/+u708IlmMJtk8+T0SS4gmoCbIK2NxoJajhLOdtt7+3jTZ2 BPRySt9n+az4VEO4/aF0fX432Gu45MGzZkqLzTyY2ANe2RlDU5YchfXwfEhHftxhIrDUhX qR1Zz6fjjhlGl9TwIyUvK9rS1JbmIPztqwPdDqutSBgCRR14nGIkvXLMLJwyzswd/TSPc3 Wh4yBP7I4TAmXghm4Iq7ctpzdA/+aTtUFk3NJG7ZtjQ9lkpnqBys7Hd7r8K6uoJ3SvH495 sDrd04t5a6HxqiZc6/NInTwt+hCM7zsCh97gYeJ2qkyhU5uZCKGekmLDQwE5yw== 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=422ba9ac83731615083ef15d52d30f3418da8fef commit 422ba9ac83731615083ef15d52d30f3418da8fef Author: Mark Johnston AuthorDate: 2022-09-23 23:41:30 +0000 Commit: Mark Johnston CommitDate: 2022-10-01 15:35:32 +0000 sched_4bsd: Fix a racy thread state modification When a thread switching off-CPU is migrating to a remote CPU, sched_switch() may trigger a rescheduling of the thread currently running on that CPU. When doing so, it must ensure that that thread is locked before modifying thread state. If the thread's lock is not the scheduler lock, then the thread is in the process of switching off-CPU and no extra effort is needed, and the initiator does not hold the thread's lock and thus should not modify any thread state. Reported and tested by: Steve Kargl (cherry picked from commit c2d27b0ec7000d28b4f31148005ccfe371f47db3) --- sys/kern/sched_4bsd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c index 27621b79d4b7..87d317d4f586 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -1248,9 +1248,10 @@ kick_other_cpu(int pri, int cpuid) } #endif /* defined(IPI_PREEMPTION) && defined(PREEMPTION) */ - pcpu->pc_curthread->td_flags |= TDF_NEEDRESCHED; - ipi_cpu(cpuid, IPI_AST); - return; + if (pcpu->pc_curthread->td_lock == &sched_lock) { + pcpu->pc_curthread->td_flags |= TDF_NEEDRESCHED; + ipi_cpu(cpuid, IPI_AST); + } } #endif /* SMP */