Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1380111

Re: /proc/<pid>/status & task struct locking

From Linus Torvalds <torvalds@linux-foundation.org>
Newsgroups linux.kernel
Subject Re: /proc/<pid>/status & task struct locking
Date 2016-04-15 20:40 +0200
Message-ID <rogOT-7s7-31@gated-at.bofh.it> (permalink)
References <rof6q-63Q-25@gated-at.bofh.it> <roglQ-7dz-21@gated-at.bofh.it> <rogFd-7ma-45@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Fri, Apr 15, 2016 at 11:23 AM, Dave Jones <davej@codemonkey.org.uk> wrote:
>
> To put my mind at rest though, am I wrong about that absent task_lock() stuff ?

So the task shouldn't be going away, because we are using the
proc_single_file_operations, which use proc_single_show(), which in
turn do a

        task = get_pid_task(pid, PIDTYPE_PID);
        ...
        put_task_struct(task);

around it all.

So dereferencing the task pointer is all safe, and the only reason to
use task_lock() is if you end up doing something more complicated.

I'm not seeing anything wrong there. It does do the get_task_mm()
before touching mm fields, and the signal fields get protected by
lock_task_sighand().  The rest seems to just dereference the task
struct directly, and if those values fluctuate that's fine: you get
one or the other, no amount of locking will make /proc/pid/status give
"reliable" values in the big picture, since the user-space reader
won't have the lock anyway.

So it all looks fine to me, but I'm not saying I did some exhaustive check.

                  Linus

Back to linux.kernel | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

/proc/<pid>/status & task struct locking Dave Jones <davej@codemonkey.org.uk> - 2016-04-15 18:50 +0200
  Re: /proc/<pid>/status & task struct locking Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-15 20:10 +0200
    Re: /proc/<pid>/status & task struct locking Dave Jones <davej@codemonkey.org.uk> - 2016-04-15 20:30 +0200
      Re: /proc/<pid>/status & task struct locking Linus Torvalds <torvalds@linux-foundation.org> - 2016-04-15 20:40 +0200

csiph-web