All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frederic Weisbecker <frederic@kernel.org>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <frederic@kernel.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>, Ian Rogers <irogers@google.com>,
	Adrian Hunter <adrian.hunter@intel.com>
Subject: [PATCH 2/4] task_work: Introduce task_work_cancel() again
Date: Sat, 30 Mar 2024 00:58:10 +0100	[thread overview]
Message-ID: <20240329235812.18917-3-frederic@kernel.org> (raw)
In-Reply-To: <20240329235812.18917-1-frederic@kernel.org>

Re-introduce task_work_cancel(), this time to cancel an actual callback
and not *any* callback pointing to a given function. This is going to be
needed for perf events event freeing.

Signed-off-by: Frederic Weisbecker <frederic@kernel.org>
---
 include/linux/task_work.h |  1 +
 kernel/task_work.c        | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/include/linux/task_work.h b/include/linux/task_work.h
index 89ee2cbf044b..58e42ef59580 100644
--- a/include/linux/task_work.h
+++ b/include/linux/task_work.h
@@ -37,6 +37,7 @@ int task_work_add(struct task_struct *task, struct callback_head *twork,
 struct callback_head *task_work_cancel_match(struct task_struct *task,
 	bool (*match)(struct callback_head *, void *data), void *data);
 struct callback_head *task_work_cancel_func(struct task_struct *, task_work_func_t);
+bool task_work_cancel(struct task_struct *, struct callback_head *twork);
 void task_work_run(void);
 
 static inline void exit_task_work(struct task_struct *task)
diff --git a/kernel/task_work.c b/kernel/task_work.c
index c1b4d3ba2590..9e85ac7632ae 100644
--- a/kernel/task_work.c
+++ b/kernel/task_work.c
@@ -136,6 +136,30 @@ task_work_cancel_func(struct task_struct *task, task_work_func_t func)
 	return task_work_cancel_match(task, task_work_func_match, func);
 }
 
+static bool task_work_match(struct callback_head *cb, void *data)
+{
+	return cb == data;
+}
+
+/**
+ * task_work_cancel - cancel a pending work added by task_work_add()
+ * @task: the task which should execute the work
+ * @func: the work to remove if queued
+ *
+ * Remove a callback from a task's queue if queued.
+ *
+ * RETURNS:
+ * True if the callback was queued and got cancelled, false otherwise.
+ */
+bool task_work_cancel(struct task_struct *task, struct callback_head *cb)
+{
+	struct callback_head *ret;
+
+	ret = task_work_cancel_match(task, task_work_match, cb);
+
+	return ret == cb;
+}
+
 /**
  * task_work_run - execute the works added by task_work_add()
  *
-- 
2.44.0


  parent reply	other threads:[~2024-03-29 23:58 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29 23:58 [PATCH 0/4] perf: Fix leaked events when sigtrap = 1 Frederic Weisbecker
2024-03-29 23:58 ` [PATCH 1/4] task_work: s/task_work_cancel()/task_work_cancel_func()/ Frederic Weisbecker
2024-03-29 23:58 ` Frederic Weisbecker [this message]
2024-03-30 21:10   ` [PATCH 2/4] task_work: Introduce task_work_cancel() again kernel test robot
2024-03-29 23:58 ` [PATCH 3/4] perf: Fix event leak upon exit Frederic Weisbecker
2024-03-29 23:58 ` [PATCH 4/4] perf: Fix event leak upon exec and file release Frederic Weisbecker
2024-03-30  3:23 ` [PATCH 0/4] perf: Fix leaked events when sigtrap = 1 Ian Rogers
2024-04-08 19:43   ` Frederic Weisbecker
2024-04-08 20:20     ` Arnaldo Carvalho de Melo
2024-04-08 20:58       ` Frederic Weisbecker
  -- strict thread matches above, loose matches on Subject: below --
2024-05-15 14:43 [PATCH 0/4 v2] perf: Fix leaked sigtrap events Frederic Weisbecker
2024-05-15 14:43 ` [PATCH 2/4] task_work: Introduce task_work_cancel() again Frederic Weisbecker
2024-05-16 14:09 [PATCH 0/4 v3] perf: Fix leaked sigtrap events Frederic Weisbecker
2024-05-16 14:09 ` [PATCH 2/4] task_work: Introduce task_work_cancel() again Frederic Weisbecker
2024-06-21  9:15 [PATCH 0/4 v4] perf: Fix leaked sigtrap events Frederic Weisbecker
2024-06-21  9:15 ` [PATCH 2/4] task_work: Introduce task_work_cancel() again Frederic Weisbecker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240329235812.18917-3-frederic@kernel.org \
    --to=frederic@kernel.org \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.