From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
To: keescook@chromium.org, joe@perches.com, pavel@ucw.cz,
akpm@linux-foundation.org
Cc: geert@linux-m68k.org, jkosina@suse.cz, viro@zeniv.linux.org.uk,
davem@davemloft.net, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/vsprintf: add %pT[C012] format specifier
Date: Sun, 5 Jan 2014 12:15:57 +0900 [thread overview]
Message-ID: <201401051215.ACJ30759.MJSHtFFFVOOOQL@I-love.SAKURA.ne.jp> (raw)
In-Reply-To: <201401041126.BHJ81291.VOHLOtMFOJFQFS@I-love.SAKURA.ne.jp>
Tetsuo Handa wrote:
> Since my purpose is to make reading of task_struct->comm consistent, %pT-like
> extension is what I want for centralizing pointer dereferences.
If we have no objections for %pT[C012] patch, I'd like to propose a counterpart
patch for users reading/copying task_struct->comm for non-printing purposes.
With %pT[C012] patch and this patch, we can convert almost all
task_struct->comm users.
----------
>From 89e676ddce3e2a232fbb760085a1954cd53c8b63 Mon Sep 17 00:00:00 2001
From: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Date: Sun, 5 Jan 2014 11:54:39 +0900
Subject: [PATCH] exec: Add wrapper functions for reading/copying task_struct->comm.
Since task_struct->comm can be modified by other threads while the current
thread is reading it, it is recommended to use get_task_comm() for reading it.
However, since get_task_comm() holds task_struct->alloc_lock spinlock,
some users cannot use get_task_comm(). Also, a lot of users are directly
reading from task_struct->comm even if they can use get_task_comm().
Such users might obtain inconsistent comm name.
This patch introduces wrapper functions for reading/copying task_struct->comm
so that in the future we need to modify only these wrapper functions to obtain
consistent comm name.
Users directly reading from task_struct->comm for printing purpose can use
%pT[C012] format specifiers rather than these wrapper functions.
Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
---
include/linux/sched.h | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 53f97eb..ead439f 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1665,6 +1665,40 @@ static inline cputime_t task_gtime(struct task_struct *t)
extern void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
+/**
+ * commcmp - Compare task_struct->comm .
+ *
+ * @tsk: Pointer to "struct task_struct".
+ * @comm: Comm name.
+ *
+ * Returns return value of strcmp(@tsk->comm, @comm).
+ *
+ * Please use this wrapper function which will be updated in the future to read
+ * @tsk->comm in a consistent way.
+ */
+static inline int commcmp(const struct task_struct *tsk, const char *comm)
+{
+ return strcmp(tsk->comm, comm);
+}
+
+/**
+ * commcpy - Copy task_struct->comm to buffer.
+ *
+ * @buf: Buffer to copy @tsk->comm which must be at least TASK_COMM_LEN bytes.
+ * @tsk: Pointer to "struct task_struct".
+ *
+ * Returns return value of memcpy(@buf, @tsk->comm, TASK_COMM_LEN).
+ *
+ * Please use get_task_comm(@buf, @tsk) if it is safe to call task_lock(@tsk),
+ * for get_task_comm() reads @tsk->comm in a consistent way. Otherwise, please
+ * use this wrapper function which will be updated in the future to read
+ * @tsk->comm in a consistent way.
+ */
+static inline void *commcpy(void *buf, const struct task_struct *tsk)
+{
+ return memcpy(buf, tsk->comm, TASK_COMM_LEN);
+}
+
/*
* Per process flags
*/
--
1.7.9.5
next prev parent reply other threads:[~2014-01-05 3:17 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-25 12:37 Tetsuo Handa
2013-12-26 8:43 ` Joe Perches
2013-12-27 23:02 ` Andrew Morton
2013-12-28 3:43 ` Tetsuo Handa
2013-12-28 18:57 ` Geert Uytterhoeven
2013-12-28 19:25 ` Andrew Morton
2013-12-28 19:25 ` Geert Uytterhoeven
2013-12-28 19:53 ` Joe Perches
2013-12-28 20:08 ` Andrew Morton
2013-12-28 20:24 ` Joe Perches
2013-12-29 0:32 ` Tetsuo Handa
2013-12-29 2:07 ` Joe Perches
2013-12-29 12:13 ` Tetsuo Handa
2013-12-30 16:55 ` Joe Perches
2013-12-31 6:53 ` Tetsuo Handa
2013-12-31 16:24 ` Joe Perches
2014-01-01 5:34 ` Tetsuo Handa
2014-01-01 5:49 ` Joe Perches
2014-01-01 10:02 ` Tetsuo Handa
2014-01-02 1:33 ` Joe Perches
2014-01-02 4:49 ` Tetsuo Handa
2014-01-03 17:08 ` Kees Cook
2014-01-03 17:39 ` Joe Perches
2014-01-03 17:49 ` Kees Cook
2014-01-04 2:26 ` Tetsuo Handa
2014-01-05 3:15 ` Tetsuo Handa [this message]
2014-01-05 18:09 ` Joe Perches
2014-01-06 14:00 ` Tetsuo Handa
2014-01-06 17:34 ` Joe Perches
2014-01-06 21:41 ` Tetsuo Handa
2014-01-06 22:25 ` Joe Perches
2014-01-07 0:16 ` Pavel Machek
2014-01-07 1:03 ` Joe Perches
2014-01-07 8:37 ` Pavel Machek
2014-01-07 17:34 ` Joe Perches
2014-01-07 17:56 ` Pavel Machek
2014-01-07 18:28 ` Geert Uytterhoeven
2014-01-08 14:19 ` Tetsuo Handa
2014-01-08 14:46 ` Pavel Machek
2014-01-06 21:34 ` Pavel Machek
2014-01-05 22:27 ` Pavel Machek
2014-01-06 14:02 ` Tetsuo Handa
2014-01-10 13:15 ` Tetsuo Handa
2014-01-02 1:38 ` Joe Perches
2014-01-02 11:51 ` Pavel Machek
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=201401051215.ACJ30759.MJSHtFFFVOOOQL@I-love.SAKURA.ne.jp \
--to=penguin-kernel@i-love.sakura.ne.jp \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=geert@linux-m68k.org \
--cc=jkosina@suse.cz \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@ucw.cz \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®