From nobody Mon Oct 23 17:23:28 2023 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 4SDhqP0856z4yJ7j; Mon, 23 Oct 2023 17:23:29 +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 4SDhqN6lflz4ZxK; Mon, 23 Oct 2023 17:23:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698081808; 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=l4Bc72jf1Av7wumy+Psy2S/YZUbY7kiZ+5d+Nl3jZgk=; b=Yy4FBr0eM0UZREuHsn3V1lJwMRE3x29Jhx0p8zbSvpNiTaoIZhBZsON83FaabwxLTlEaOL AsDOd0lKxX5svc/V69o15AFqRUfOH7bSHvem5m3ys4gYk+wsQ8vOkTdWgtJ/G4FvgadpMz FzbxPRL99hT5XSRrDrHs5o433wSdG3IZOrvROIREAKzSfBog2116uZguw/i6mseNzVkjIC l51cXC/yXm3lESR3mSLi3dJQlbBEtkDPaFgZpLrR0IGyam6odygx1VWEYyqNiCNN0RXqnH V5e/O9jsTWi5EFT7JA/9g5T0fAMfmvUK1284sdqRei+/ZnA86CsFJD+avmkohQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1698081808; a=rsa-sha256; cv=none; b=Kt0x8aMq0OqrC6a6HtPonNY76rBzzYCJC2ZGVJ95lwrozUGDBdMtDfXRhM5tIvnkSfuPwF I1UQhvakWIJotz+bB29oq7cE6G7d41MI4hhwGqXyPN+drzelu5LEZ0Gzd0toAjRCwxFYi9 NF9XCiSEfJvM/X1ywtnjMxGupFSjrWL0K6CBEdezd4ILp4ck7tGm7KNzRYc2JmaHTNBLgs bf3qPq55zixkeTgqgdUMHth2nn1kQyGurchl4B00Pl1Zm/A8EHHAGlupaI6vThlgb+5JZT o6ZZdeTB2kEbsbWHtw1EH/wZl7a/uVx8eOAc3l/IOxr85OGsV4BoSvWQiZvzow== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1698081808; 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=l4Bc72jf1Av7wumy+Psy2S/YZUbY7kiZ+5d+Nl3jZgk=; b=UcMjIVSWSWWwVyVfjKAd/DRTaP0VjkHEYSrONCH12xjQXLwDkTVWDC6dxtqqZAnOGnxVhN 7rp7RrmZiYe9R0LLDHA/WfclilIZOeyeuUb9v9L+dx2akv3sHUg2R1l4Tg3Ei0Mkw3Lg24 2EKaZnis2anEuvecWl3zAewbn2tnl+1Ap6W5dKhyJRvxRWr5SAlxSoYN0xDZYRDgDbZklz GZbzmDobI6EGXwCdmBjtCHsCVaCHPTaduPLbj9qBAZf4zxYHkha60Fr67LrnRPK77RJXoG Iq7LfXM8Uscgi14ry3YuEnWxJHziaHja56KZP/C1SNfwbngobzOhGHQYq6FpBQ== 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 4SDhqN5pnYzpRf; Mon, 23 Oct 2023 17:23:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39NHNS9O063747; Mon, 23 Oct 2023 17:23:28 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39NHNSn8063744; Mon, 23 Oct 2023 17:23:28 GMT (envelope-from git) Date: Mon, 23 Oct 2023 17:23:28 GMT Message-Id: <202310231723.39NHNSn8063744@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: c35f527ed115 - main - sx: unset td_wantedlock around going to sleep 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: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c35f527ed115b792463d30c7d3c8904e435caead Auto-Submitted: auto-generated The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=c35f527ed115b792463d30c7d3c8904e435caead commit c35f527ed115b792463d30c7d3c8904e435caead Author: Mateusz Guzik AuthorDate: 2023-10-23 17:22:12 +0000 Commit: Mateusz Guzik CommitDate: 2023-10-23 17:22:12 +0000 sx: unset td_wantedlock around going to sleep Otherwise it can crash in sleepq_wait_sig -> sleepq_catch_signals -> sig_ast_checksusp -> thread_suspend_check due to a mutex acquire. Reported by: pho Sponsored by: Rubicon Communications, LLC ("Netgate") --- sys/kern/kern_sx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sys/kern/kern_sx.c b/sys/kern/kern_sx.c index bc8a1214689f..455ae165e328 100644 --- a/sys/kern/kern_sx.c +++ b/sys/kern/kern_sx.c @@ -854,10 +854,17 @@ retry_sleepq: sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name, SLEEPQ_SX | ((opts & SX_INTERRUPTIBLE) ? SLEEPQ_INTERRUPTIBLE : 0), SQ_EXCLUSIVE_QUEUE); + /* + * Hack: this can land in thread_suspend_check which will + * conditionally take a mutex, tripping over an assert if a + * lock we are waiting for is set. + */ + THREAD_CONTENTION_DONE(&sx->lock_object); if (!(opts & SX_INTERRUPTIBLE)) sleepq_wait(&sx->lock_object, 0); else error = sleepq_wait_sig(&sx->lock_object, 0); + THREAD_CONTENTION_DONE(&sx->lock_object); #ifdef KDTRACE_HOOKS sleep_time += lockstat_nsecs(&sx->lock_object); sleep_cnt++; @@ -1209,10 +1216,17 @@ retry_sleepq: sleepq_add(&sx->lock_object, NULL, sx->lock_object.lo_name, SLEEPQ_SX | ((opts & SX_INTERRUPTIBLE) ? SLEEPQ_INTERRUPTIBLE : 0), SQ_SHARED_QUEUE); + /* + * Hack: this can land in thread_suspend_check which will + * conditionally take a mutex, tripping over an assert if a + * lock we are waiting for is set. + */ + THREAD_CONTENTION_DONE(&sx->lock_object); if (!(opts & SX_INTERRUPTIBLE)) sleepq_wait(&sx->lock_object, 0); else error = sleepq_wait_sig(&sx->lock_object, 0); + THREAD_CONTENDS_ON_LOCK(&sx->lock_object); #ifdef KDTRACE_HOOKS sleep_time += lockstat_nsecs(&sx->lock_object); sleep_cnt++;