From nobody Sat Sep 24 00:16:29 2022 X-Original-To: dev-commits-src-main@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 4MZ8hG16G7z4dJLf; Sat, 24 Sep 2022 00:16:30 +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 4MZ8hG0gqRz3vPZ; Sat, 24 Sep 2022 00:16:30 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663978590; 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=9hzlS435wofrXCIjeeyVTu5Tm024KWl0G1X8gHh3v1c=; b=oIby5/TcFvZE4g3Nvhywdi0A+fByF5sBRJ/yprqv+KKU8+JWKHdcgALVQISQoqaJDbz2lI 7GiiN29Xu3EJ/js92BWRmBR7J9j0pfb0eurnvgG83QPLDsLRJ9mWVB+VomrxB0F33uleTu jLkx4KcZ2Mu06TAFxrNvAlWMm2Y+ZPpdTegi57ErJxD2ela8LQu1vF6rIbWJJkc24B9m78 7C9fYV/T0UPqYYtwGZVuHRdIrFPEPYUAnTLAwttCeln4vYPxc0x3B+PNPACk6f2bpG4XaR sBqHATqFDd4meOtkfCZMT7LZjdNbf+5Lz+vAvu4jq2uzX/zQApQnu+poRCbxkQ== 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 4MZ8hF6m4szv65; Sat, 24 Sep 2022 00:16:29 +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 28O0GTEB031409; Sat, 24 Sep 2022 00:16:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 28O0GTSx031408; Sat, 24 Sep 2022 00:16:29 GMT (envelope-from git) Date: Sat, 24 Sep 2022 00:16:29 GMT Message-Id: <202209240016.28O0GTSx031408@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: c2d27b0ec700 - main - sched_4bsd: Fix a racy thread state modification List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: c2d27b0ec7000d28b4f31148005ccfe371f47db3 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1663978590; 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=9hzlS435wofrXCIjeeyVTu5Tm024KWl0G1X8gHh3v1c=; b=dn4lOI3qKeXybgw69veIv8RcqUR1EmGLLVFGOsk1MYuqskqBvef4VdXszdPSua77fqANqn CqWEXp/kMAcBA2es+/46Nmqi5LEliKYMZbaaknB+5nOR9JJvYpH4pPuN7rBHV0WJtg1SnJ uKIrYQmkPXr1+ueCatyvpOxfGSpDQgSO1cJ4g3C+8W2Nx5nGlxug9+EAZMGC53gvfbRBRI JHVGZq8PcpOAEqENIoxC9DEPjzMRHHiAFWGH2jVsBSmalI8DCfXlZ88zO5bZmsobLdWv/R MCIFIFJLz6wk6se/QhoOf6R1XO/NwC6h2RqH9dID1GCpmgEKzUUQxF2n8jMWcQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1663978590; a=rsa-sha256; cv=none; b=koCNvKZbfXAuDrDu6bHjmEAMEZIH01g5pyCaVansPP3Q8BuJOtlk3tH960klzLdcfyGyNl JmgICJB6ldSLpn4kp6PSTmBZFDUXp+5TbIuj+7zUNtMijlgbyZ5LqwVqi3EfJZJ1EHsEwW AATIBJnPNOqX/+FdDGuwXUfvz9nREUj/B9WuC0NvJYqd8U8fLFtnPZXi//Bodvmdf8lWoL IJbxKyi6Ihw5HUaTSJYiP68GiCxOkETIR8D0/uNEcyKxR1TTUnTT9laipxytAKcbiySQMA 3MgIp/YxiCH7qxwk0HfdZsgwsmcOB2Xb3xiOb88aJKTstNd+/I0GH9n7QJ1UQg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=c2d27b0ec7000d28b4f31148005ccfe371f47db3 commit c2d27b0ec7000d28b4f31148005ccfe371f47db3 Author: Mark Johnston AuthorDate: 2022-09-23 23:41:30 +0000 Commit: Mark Johnston CommitDate: 2022-09-24 00:09:06 +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 MFC after: 1 week --- 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 9d48aa746f6d..8bd697a67e7e 100644 --- a/sys/kern/sched_4bsd.c +++ b/sys/kern/sched_4bsd.c @@ -1282,9 +1282,10 @@ kick_other_cpu(int pri, int cpuid) } #endif /* defined(IPI_PREEMPTION) && defined(PREEMPTION) */ - ast_sched_locked(pcpu->pc_curthread, TDA_SCHED); - ipi_cpu(cpuid, IPI_AST); - return; + if (pcpu->pc_curthread->td_lock == &sched_lock) { + ast_sched_locked(pcpu->pc_curthread, TDA_SCHED); + ipi_cpu(cpuid, IPI_AST); + } } #endif /* SMP */