Skip to content

kernel/fork: beware of __put_task_struct calling context

Wander Lairson Costa lkml 6 versions – Applied

Status from this message: The following commit has been merged into the sched/core branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v10 Latest2 patches 1 replyApplied
  2. v91 patch 15 repliesSuperseded
  3. v81 patch 4 repliesSuperseded
Earlier versions · 3
VersionPostedPatchesRepliesStatus
v51 patch4 repliesSuperseded
v41 patch11 repliesSuperseded
v31 patch3 repliesSuperseded

Changes in v10 from the cover letter

* Add a patch preventing a splat when compile with CONFIG_PROVE_RAW_LOCK_NESTING.

Patches in v10 Applied

#Subject and filesSizeRepliesApplied
1/2kernel/fork: beware of __put_task_struct calling contextinclude/linux/sched/task.h kernel/fork.c+35 -10 replies
2/2sched: avoid false lockdep splat in put_task_struct()include/linux/sched/task.h+14 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v10 yet.

Read the v10 thread

Cover letter [PATCH v10 0/2] kernel/fork: beware of __put_task_struct calling context

Under PREEMPT_RT, __put_task_struct() indirectly acquires sleeping locks. Therefore, it can't be called from an non-preemptible context.

Instead of calling __put_task_struct() directly, we defer it using call_rcu(). A more natural approach would use a workqueue, but since in PREEMPT_RT, we can't allocate dynamic memory from atomic context, the code would become more complex because we would need to put the work_struct instance in the task_struct and initialize it when we allocate a new task_struct.

Changelog
=========

v1:
* Initial implementation fixing the splat.

v2:
* Isolate the logic in its own function.
* Fix two more cases caught in review.

v3:
* Change __put_task_struct() to handle the issue internally.

v4:
* Explain why call_rcu() is safe to call from interrupt context.

v5:
* Explain why __put_task_struct() doesn't conflict with put_task_sruct_rcu_user.

v6:
* As per Sebastian's review, revert back the implementation of v2 with a distinct function.
* Add a check in put_task_struct() to warning when called from a non-sleepable context.
* Address more call sites.

v7:
* Fix typos.
* Add an explanation why the new function doesn't conflict with delayed_free_task().

v8:
* Bring back v5.
* Fix coding style.

v9:
* Reorganize to not need ___put_task_struct() by Oleg's suggestion.

v10:
* Add a patch preventing a splat when compile with CONFIG_PROVE_RAW_LOCK_NESTING.

Cc Sebastian Andrzej Siewior <[email protected]>
Cc Paul McKenney <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Luis Goncalves <[email protected]>

Wander Lairson Costa (2):
kernel/fork: beware of __put_task_struct calling context
sched: avoid false lockdep splat in put_task_struct()

 include/linux/sched/task.h | 38 +++++++++++++++++++++++++++++++++++++-
 kernel/fork.c              |  8 ++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
Signature · 1 line
2.40.1