Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F173525403
linuxkpi-cancel-delayed-work-dispatch.patch
Public
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
oleglelchuk_gmail.com
Sep 26 2026, 2:35 PM
2026-09-26 14:35:33 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
linuxkpi-cancel-delayed-work-dispatch.patch
View Options
diff --git a/sys/compat/linuxkpi/common/src/linux_work.c b/sys/compat/linuxkpi/common/src/linux_work.c
index bf4c827676216af275fb083219e13ff57fe52961..8667fe75b94884e1629abe2a491871b906d49af1 100644
--- a/sys/compat/linuxkpi/common/src/linux_work.c
+++ b/sys/compat/linuxkpi/common/src/linux_work.c
@@ -507,12 +507,10 @@ linux_cancel_delayed_work(struct delayed_work *dwork)
}
/*
- * This function cancels the given delayed work structure in a
- * synchronous fashion. It returns true if pending delayed work was
- * cancelled. Else the work was not pending.
+ * Cancel and drain delayed work, reporting cancelled pending work through
+ * cancelled and the taskqueue pending count through pending.
*
- * If the work restarted itself or was busy while being cancelled,
- * retry_needed is set to true so the caller can re-check the state.
+ * Return true if the caller needs to re-check the state after draining.
*/
static bool
linux_cancel_delayed_work_sync_int(struct delayed_work *dwork, u_int *pending,
@@ -527,19 +525,30 @@ linux_cancel_delayed_work_sync_int(struct delayed_work *dwork, u_int *pending,
};
struct taskqueue *tq;
int ret, state;
+ bool stopped;
WITNESS_WARN(WARN_GIANTOK | WARN_SLEEPOK, NULL,
"linux_cancel_delayed_work_sync() might sleep");
mtx_lock(&dwork->timer.mtx);
state = linux_update_state(&dwork->work.state, states);
+ /*
+ * A taskqueue worker can have dequeued the task without linux_work_fn()
+ * having claimed the callback yet. In that case taskqueue_cancel()
+ * reports EBUSY with no pending tasks, but our transition to IDLE still
+ * prevents the callback. Account for this using the state consumed by
+ * the atomic transition, not just the native queue's pending count.
+ * WORK_ST_EXEC, in contrast, means the callback was already claimed.
+ */
+ *cancelled = (state == WORK_ST_TIMER || state == WORK_ST_TASK ||
+ state == WORK_ST_CANCEL);
switch (state) {
case WORK_ST_IDLE:
mtx_unlock(&dwork->timer.mtx);
return (false);
case WORK_ST_TIMER:
case WORK_ST_CANCEL:
- *cancelled = (callout_stop(&dwork->timer.callout) == 1);
+ stopped = (callout_stop(&dwork->timer.callout) == 1);
tq = dwork->work.work_queue->taskqueue;
ret = taskqueue_cancel(tq, &dwork->work.work_task, pending);
@@ -547,7 +556,7 @@ linux_cancel_delayed_work_sync_int(struct delayed_work *dwork, u_int *pending,
callout_drain(&dwork->timer.callout);
taskqueue_drain(tq, &dwork->work.work_task);
- return (*cancelled || (ret != 0));
+ return (stopped || (ret != 0));
default:
tq = dwork->work.work_queue->taskqueue;
ret = taskqueue_cancel(tq, &dwork->work.work_task, pending);
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39742782
Default Alt Text
linuxkpi-cancel-delayed-work-dispatch.patch (2 KB)
Attached To
Mode
D60046: LinuxKPI: account for delayed work cancelled after taskqueue dequeue
Referenced
Detach File
Event Timeline
Log In to Comment