lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <d8614d494bb136343c884cbdd780b9985faa07a0.1424109806.git.jpoimboe@redhat.com>
Date:	Mon, 16 Feb 2015 12:52:34 -0600
From:	Josh Poimboeuf <jpoimboe@...hat.com>
To:	Andrew Morton <akpm@...ux-foundation.org>,
	Ingo Molnar <mingo@...hat.com>,
	Peter Zijlstra <peterz@...radead.org>
Cc:	Jiri Kosina <jkosina@...e.cz>, Seth Jennings <sjenning@...hat.com>,
	linux-kernel@...r.kernel.org
Subject: [PATCH 1/3] sched: add sched_task_call()

Add a sched_task_call() to allow a callback function to be called with
the task's rq locked.  It guarantees that a task remains either active
or inactive during the function call, without having to expose rq
locking details outside of the scheduler.

Signed-off-by: Josh Poimboeuf <jpoimboe@...hat.com>
---
 include/linux/sched.h |  4 ++++
 kernel/sched/core.c   | 17 +++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 41c60e5..9b61e66 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2506,6 +2506,10 @@ static inline void set_task_comm(struct task_struct *tsk, const char *from)
 }
 extern char *get_task_comm(char *to, struct task_struct *tsk);
 
+typedef void (*sched_task_call_func_t)(struct task_struct *tsk, void *data);
+extern void sched_task_call(sched_task_call_func_t func,
+			    struct task_struct *tsk, void *data);
+
 #ifdef CONFIG_SMP
 void scheduler_ipi(void);
 extern unsigned long wait_task_inactive(struct task_struct *, long match_state);
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 13049aa..c83a451 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1338,6 +1338,23 @@ void kick_process(struct task_struct *p)
 EXPORT_SYMBOL_GPL(kick_process);
 #endif /* CONFIG_SMP */
 
+/***
+ * sched_task_call - call a function with a task's state locked
+ *
+ * The task is guaranteed to remain either active or inactive during the
+ * function call.
+ */
+void sched_task_call(sched_task_call_func_t func, struct task_struct *p,
+		     void *data)
+{
+	unsigned long flags;
+	struct rq *rq;
+
+	rq = task_rq_lock(p, &flags);
+	func(p, data);
+	task_rq_unlock(rq, p, &flags);
+}
+
 #ifdef CONFIG_SMP
 /*
  * ->cpus_allowed is protected by both rq->lock and p->pi_lock
-- 
2.1.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ