Skip to content

Commit 95b554b

Browse files
kernel: sched: impl sys workq item no block enforcement
The system workqueue should never be unreadied from a work item handler (while busy). This commit implements an optional check which will invoke a kernel oops is a blocking operation is attempted from a work item passed to the system workqueue. Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent 355fcce commit 95b554b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

doc/kernel/services/threads/workqueue.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ its queue until the handler function finishes executing.
109109
potentially blocking, as there is no guarantee that work items submitted to
110110
it do not depend on subsequent work items in the queue to unblock them.
111111

112+
:kconfig:option:`CONFIG_SYSTEM_WORKQUEUE_NO_BLOCK` enforces that no work
113+
items submitted to the system workqueue perform any blocking operations.
114+
112115
The single argument that is passed to a handler function can be ignored if it
113116
is not required. If the handler function requires additional information about
114117
the work it is to perform, the work item can be embedded in a larger data

kernel/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,14 @@ config SYSTEM_WORKQUEUE_NO_YIELD
600600
cooperative and a sequence of work items is expected to complete
601601
without yielding.
602602

603+
CONFIG_SYSTEM_WORKQUEUE_NO_BLOCK
604+
bool "Select whether system work queue enforces work items dont block"
605+
help
606+
By default, the system work queue does not enforce work items
607+
passed to it dont perform blocking operations. Selecting this
608+
enforces that blocking operations are not performed by invoking
609+
a kernel oops if such operations are attempted.
610+
603611
endmenu
604612

605613
menu "Barrier Operations"

kernel/sched.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,10 @@ static inline void z_vrfy_k_thread_resume(k_tid_t thread)
523523

524524
static void unready_thread(struct k_thread *thread)
525525
{
526+
if (IS_ENABLED(CONFIG_SYSTEM_WORKQUEUE_NO_BLOCK) && k_is_in_sys_work()) {
527+
k_oops();
528+
}
529+
526530
if (z_is_thread_queued(thread)) {
527531
dequeue_thread(thread);
528532
}

0 commit comments

Comments
 (0)