From nobody Fri Aug 26 17:34:55 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 4MDn5r1Bccz4ZYXq; Fri, 26 Aug 2022 17:34:56 +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 4MDn5r0gVfz3WGS; Fri, 26 Aug 2022 17:34:56 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661535296; 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=X7T82F+gKepY5KAX2yZXbrrfucgukIv9lcnsrtBEexI=; b=eVIu7ys6n/QLK0SW0/p/4yxN9ivRjD/RhUwRtAism3tuA5A4trWGoa6fuTpDn2LKifT4W3 ayYqGkkbrfNXOClVeF1XFXuTzynYM027rvul9vM8enx1X7EOtv/m5oW1fqFSLm2peSByHQ oM77AWvRpG8WyPbiosP6ChOUiEMeSBwtRTRMKWA//dW11iCMum1WnwHxivzevaKqm+iHVw QrJOZxhu1kEeO/l6fnC2alPjJhW1I/1fUxIuVD6NcDILJM7+cr+VBiTD3NT45n6s9mm5uH /m+Lkp/RrNwDej2GO22VGQyCrcKXvCfpbQYEHkgiwkvRnQLARcdydC/r2NQrmw== 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 4MDn5q6nBXzT2S; Fri, 26 Aug 2022 17:34:55 +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 27QHYtG8081236; Fri, 26 Aug 2022 17:34:55 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27QHYtmv081235; Fri, 26 Aug 2022 17:34:55 GMT (envelope-from git) Date: Fri, 26 Aug 2022 17:34:55 GMT Message-Id: <202208261734.27QHYtmv081235@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: 768f6373eb3d - main - Fix compat10 semaphore interface race 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 768f6373eb3d60e346d3bfa495e04315aeed8ff9 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1661535296; 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=X7T82F+gKepY5KAX2yZXbrrfucgukIv9lcnsrtBEexI=; b=h55vQkKr9J7BKjH4SoMqL3yjY70GDJDG4FEXd1/Q37fucOmk4n/Ziqo539QCXg8WD1ZrMq sE1WSYDXA4t+4hDL+a03/OajZOfk9yqhaxL86D/dplgPeILBcSjHbfbK2vdKrcNZ4Hy3LM jEKxoMPqXy6qbNp9O4kxrAr4MFVk3/DFxizvi4CgsMyuXmWFRetslzl8K9dXyZui+8M/G2 qAVtoSscwzQxZfataytjcarScJjqWF1oX1KTgRQG1mVAQfa7HoJJ/vILyp9JM7+CjYwubj SFeqo2W1fE2rjAOz8yCN4CWetVzmdJ8/jvIiEyhmxh7Gssmb4IC5ACEkasYBlg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1661535296; a=rsa-sha256; cv=none; b=bIvpP0gzLren+HEVPHf1jsk7TycRsII2NdlA3RHrQWzVyyN5Iy7fDqRJJy5NsSPvnM8MnR IwCDGHdMbcUIxZeJtRSSelaMzpNBtPvzD2/13l0d3YNDsMrTkdoVahUpVWNthye65l5iDv IX6HQggJIsyFQiLGFrbJZzau4TS2qdrye1UD5g0GNjn1iHzjm+vcaGvBCR3J1L+jyUnigK 7xFPLHkQ152Qytk3JTWb6+9amnhsV0vBptpJlahlM9GltW5J4skDiaL0ORtSL+sXp0dTJT QNBF7WNwvdGrzJZWjBr1FquBJ/4eWsrJb/VXu5LRXB8UGklMwJqMJ8UU97qQMg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=768f6373eb3d60e346d3bfa495e04315aeed8ff9 commit 768f6373eb3d60e346d3bfa495e04315aeed8ff9 Author: firk AuthorDate: 2022-08-26 08:05:56 +0000 Commit: Konstantin Belousov CommitDate: 2022-08-26 17:34:29 +0000 Fix compat10 semaphore interface race Wrong has-waiters and missing unconditional _count==0 check may cause infinite waiting with already non-zero count. 1) properly clear _has_waiters flag when waiting failed to start 2) always check _count before start waiting PR: 265997 Reviewed by: kib MFC after: 1 week Differential revision: https://reviews.freebsd.org/D36272 --- sys/kern/kern_umtx.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/sys/kern/kern_umtx.c b/sys/kern/kern_umtx.c index c8307fb337c2..6b4e3ca38d03 100644 --- a/sys/kern/kern_umtx.c +++ b/sys/kern/kern_umtx.c @@ -3547,24 +3547,28 @@ again: umtxq_insert(uq); umtxq_unlock(&uq->uq_key); rv = casueword32(&sem->_has_waiters, 0, &count1, 1); - if (rv == 0) + if (rv != -1) rv1 = fueword32(&sem->_count, &count); - if (rv == -1 || (rv == 0 && (rv1 == -1 || count != 0)) || - (rv == 1 && count1 == 0)) { + if (rv == -1 || rv1 == -1 || count != 0 || (rv == 1 && count1 == 0)) { + if (rv == 0) + suword32(&sem->_has_waiters, 0); umtxq_lock(&uq->uq_key); umtxq_unbusy(&uq->uq_key); umtxq_remove(uq); umtxq_unlock(&uq->uq_key); - if (rv == 1) { - rv = thread_check_susp(td, true); - if (rv == 0) - goto again; - error = rv; + if (rv == -1 || rv1 == -1) { + error = EFAULT; + goto out; + } + if (count != 0) { + error = 0; goto out; } + MPASS(rv == 1 && count1 == 0); + rv = thread_check_susp(td, true); if (rv == 0) - rv = rv1; - error = rv == -1 ? EFAULT : 0; + goto again; + error = rv; goto out; } umtxq_lock(&uq->uq_key);