From nobody Tue Nov 14 00:27:24 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 4STnDr2cYcz50MgF; Tue, 14 Nov 2023 00:27:24 +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 4STnDr284Xz4MFK; Tue, 14 Nov 2023 00:27:24 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699921644; 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=tJkXn6ZnLfha1MhzbNxNv3wv+t2yIO/D3JhTfTd6b5k=; b=mgeS0Z3Pf21NZDi7AJv9UHyZ9GxfQwG762H8/wgztKdb4oWn4v5ar4cbjnl5Cphj+JRGXW s+t/XqBVwDl+hUKxEBFgd7kGWHlCcFOX6UdZVxYefqsW4xf+afvBQqRO++x4KeZjCoV95/ HVWAg+NJw9FQqS7i8RYfchXOFgpTSgfWVmQvASOrcgZb0lhRR0iQbe98eiJS1Z1Ux9a+U6 BSdinaWQllMFWi+tNUnBANvGGmkAoIfa7qvDfUKoPevRidqWXpCTKyh46chzkmazU6e2+y gFLLhvaw8b3WoVMy89KSKllCIgWbVkTWUfxkPWCHi/WfEg9Msgm510DOyu03TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699921644; 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=tJkXn6ZnLfha1MhzbNxNv3wv+t2yIO/D3JhTfTd6b5k=; b=pDzVIjhPFUukkdkkYxL7eFLDeiy3rFjY5WmetQ/wZaDW2HpoAHVaxMTTllEgRnJkD5HdmR R6rYp0eIkkTDO3h2rUlRiDuLIb9LpnzVy3wXhMtXIUiBQ9cl3p7ruo9X5+/IlTUTqWlntl aZ5Q0dY8Lzn3oAEU3hwlcWFoWFgal9tS+3OYv1l0Alu1S/z2oxsDtwOft5F9KrukAQJsha ZMptOCYK2q0FKjj7NvUw5KP2n/5pVqLMCrIW6hDnAArwt1NVCVhhOdVFeTYx0fnvdV7Yhz LmCf23SAmWbKdTNCDRlBbJg42IJIOsNcRdBh7ibdr9kxwLuEdu7afZZirRgpeQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699921644; a=rsa-sha256; cv=none; b=dghTybdzDe/L8dcpj5/kEppfKUIAY5jQ0kc1PPxraqHZ5xu3fHXpbJF1PyBKD0Ss66vRnv 6wMd03geYHHbChY7iIHKjWqcRIHfLfZIgUCHiAZgCU0tqh+zZf4C1gna1cdy3wcohZfAEC v1WK40p5mNc6WjyXg06AY41W+Xfx+2wU6guRKNukdnMRwWbgNjEUHt0aQmGrmpvaTttelc RYny+5CbX6HZ5DoknDKE5IUg8xKsK8ouU19sGbi4SV2zSnf9+GfkKoJZpSZK0mtl5nJ+EX +H/xDfjFQTycjHkeYXnN9ZcRv2HAe7Fk6LdyEIP1Ut0J77TUDrNThCuZ/cEK/Q== 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 4STnDr1BzbzBwq; Tue, 14 Nov 2023 00:27:24 +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 3AE0ROZj064281; Tue, 14 Nov 2023 00:27:24 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3AE0ROEj064278; Tue, 14 Nov 2023 00:27:24 GMT (envelope-from git) Date: Tue, 14 Nov 2023 00:27:24 GMT Message-Id: <202311140027.3AE0ROEj064278@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: f15252b4fa02 - stable/14 - linuxkpi: races between linux_queue_delayed_work_on() and linux_cancel_delayed_work_sync() 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: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f15252b4fa0276aa76490e6fb915e95dc5b4e0ef Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=f15252b4fa0276aa76490e6fb915e95dc5b4e0ef commit f15252b4fa0276aa76490e6fb915e95dc5b4e0ef Author: Konstantin Belousov AuthorDate: 2023-11-04 07:45:48 +0000 Commit: Konstantin Belousov CommitDate: 2023-11-13 22:29:30 +0000 linuxkpi: races between linux_queue_delayed_work_on() and linux_cancel_delayed_work_sync() (cherry picked from commit 05fe82455f263ad107a860ce20dd89e1a5c1619c) --- sys/compat/linuxkpi/common/src/linux_work.c | 36 ++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_work.c b/sys/compat/linuxkpi/common/src/linux_work.c index 990ba5d20fd5..888ac97dbff6 100644 --- a/sys/compat/linuxkpi/common/src/linux_work.c +++ b/sys/compat/linuxkpi/common/src/linux_work.c @@ -221,16 +221,19 @@ linux_queue_delayed_work_on(int cpu, struct workqueue_struct *wq, [WORK_ST_EXEC] = WORK_ST_TIMER, /* start timeout */ [WORK_ST_CANCEL] = WORK_ST_TIMER, /* start timeout */ }; + bool res; if (atomic_read(&wq->draining) != 0) return (!work_pending(&dwork->work)); + mtx_lock(&dwork->timer.mtx); switch (linux_update_state(&dwork->work.state, states)) { case WORK_ST_EXEC: case WORK_ST_CANCEL: if (delay == 0 && linux_work_exec_unblock(&dwork->work) != 0) { dwork->timer.expires = jiffies; - return (true); + res = true; + goto out; } /* FALLTHROUGH */ case WORK_ST_IDLE: @@ -240,20 +243,21 @@ linux_queue_delayed_work_on(int cpu, struct workqueue_struct *wq, if (delay == 0) { linux_delayed_work_enqueue(dwork); } else if (unlikely(cpu != WORK_CPU_UNBOUND)) { - mtx_lock(&dwork->timer.mtx); callout_reset_on(&dwork->timer.callout, delay, &linux_delayed_work_timer_fn, dwork, cpu); - mtx_unlock(&dwork->timer.mtx); } else { - mtx_lock(&dwork->timer.mtx); callout_reset(&dwork->timer.callout, delay, &linux_delayed_work_timer_fn, dwork); - mtx_unlock(&dwork->timer.mtx); } - return (true); + res = true; + break; default: - return (false); /* already on a queue */ + res = false; + break; } +out: + mtx_unlock(&dwork->timer.mtx); + return (res); } void @@ -467,8 +471,8 @@ linux_cancel_delayed_work(struct delayed_work *dwork) * fashion. It returns non-zero if the work was successfully * cancelled. Else the work was already cancelled. */ -bool -linux_cancel_delayed_work_sync(struct delayed_work *dwork) +static bool +linux_cancel_delayed_work_sync_int(struct delayed_work *dwork) { static const uint8_t states[WORK_ST_MAX] __aligned(8) = { [WORK_ST_IDLE] = WORK_ST_IDLE, /* NOP */ @@ -478,7 +482,6 @@ linux_cancel_delayed_work_sync(struct delayed_work *dwork) [WORK_ST_CANCEL] = WORK_ST_IDLE, /* cancel and drain */ }; struct taskqueue *tq; - bool retval = false; int ret, state; bool cancelled; @@ -490,7 +493,7 @@ linux_cancel_delayed_work_sync(struct delayed_work *dwork) switch (state) { case WORK_ST_IDLE: mtx_unlock(&dwork->timer.mtx); - return (retval); + return (false); case WORK_ST_TIMER: case WORK_ST_CANCEL: cancelled = (callout_stop(&dwork->timer.callout) == 1); @@ -512,6 +515,17 @@ linux_cancel_delayed_work_sync(struct delayed_work *dwork) } } +bool +linux_cancel_delayed_work_sync(struct delayed_work *dwork) +{ + bool res; + + res = false; + while (linux_cancel_delayed_work_sync_int(dwork)) + res = true; + return (res); +} + /* * This function waits until the given work structure is completed. * It returns non-zero if the work was successfully