lkml.org 
[lkml]   [2007]   [May]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH 1/7] Freezer: Read PF_BORROWED_MM in a nonracy way
    On 05/11, Andrew Morton wrote:
    >
    > On Fri, 11 May 2007 00:36:25 +0200
    > "Rafael J. Wysocki" <rjw@sisk.pl> wrote:
    >
    > > static inline int is_user_space(struct task_struct *p)
    > > {
    > > - return p->mm && !(p->flags & PF_BORROWED_MM);
    > > + int ret;
    > > +
    > > + task_lock(p);
    > > + ret = p->mm && !(p->flags & PF_BORROWED_MM);
    > > + task_unlock(p);
    > > + return ret;
    > > }
    >
    > The whole function is racy, isn't it? I mean, the condition which it is
    > testing can go from true->false or false->true at any instant after this
    > function returns its now-wrong value.
    >
    > iow, callers of this function need to to something to prevent the expression
    > `p->mm && !(p->flags & PF_BORROWED_MM);' from changing value _anyway_. In
    > which case the new locking is not needed?

    freeze_processes() first freezes user-space tasks only, then kernel threads.

    Without task_lock() we can miss PF_BORROWED_MM and count the kernel thread
    (which is doing use_mm()) as a user space process. This means it will be
    frozen prematurely.

    true->false means daemonize() or do_exit(), seems harmless.

    false->true means exec from kernel space. That is why FREEZER_KERNEL_THREADS
    in fact means all tasks, not only kernel threads.

    Oleg.

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

    \
     
     \ /
      Last update: 2007-05-11 22:23    [W:0.029 / U:29.432 seconds]
    ©2003-2016 Jasper Spaans. hosted at Digital OceanAdvertise on this site