All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Tomasz Buchert <Tomasz.Buchert-MZpvjPyXg2s@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	Paul Menage <menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] cgroup_freezer: Freezing and task move race fix
Date: Wed, 11 Aug 2010 17:21:54 -0700	[thread overview]
Message-ID: <20100812002154.GJ2927__42952.3837090985$1281572680$gmane$org@count0.beaverton.ibm.com> (raw)
In-Reply-To: <4C6252CF.1090100-MZpvjPyXg2s@public.gmane.org>

On Wed, Aug 11, 2010 at 09:35:43AM +0200, Tomasz Buchert wrote:
> Matt Helsley a écrit :
> > On Wed, Aug 11, 2010 at 12:18:44AM +0200, Tomasz Buchert wrote:
> >> Matt Helsley a écrit :
> >>> On Tue, Aug 10, 2010 at 09:53:21PM +0200, Tomasz Buchert wrote:
> >>>> Writing 'FROZEN' to freezer.state file does not
> >>>> forbid the task to be moved away from its cgroup
> >>>> (for a very short time). Nevertheless the moved task
> >>>> can become frozen OUTSIDE its cgroup which puts
> >>>> discussed task in a permanent 'D' state.
> >>>>
> >>>> This patch forbids migration of either FROZEN
> >>>> or FREEZING tasks.
> >>>>
> >>>> This behavior was observed and easily reproduced on
> >>>> a single core laptop. Program and instructions how
> >>>> to reproduce the bug can be fetched from:
> >>>> http://pentium.hopto.org/~thinred/repos/linux-misc/freezer_bug.c
> >>> Thanks for the report and the test code.
> >>>
> >>> I'm will try to reproduce this race in the next few hours and analyze
> >>> it since I'm not sure the patch really fixes the race -- it may only
> >>> make the race trigger less frequently.
> >>>
> >>> At the very least the patch won't break the current code since it's
> >>> essentially a more-strict version of is_task_frozen_enough() -- it lets
> >>> fewer tasks attach/detach to/from frozen cgroups.
> >>>
> >>> Cheers,
> >>> 	-Matt Helsley
> >> Hi Matt!
> >> I am a novice if it comes to the kernel and I find the cgroup_freezer
> >> code especially complicated, so definetely this may be not enough to fix that.
> >> Notice also that if you uncomment the line 55 in my testcase this will also
> >> trigger the race! This, however, makes sense since process may not be in the cgroup anymore
> >> and consequently won't be thawed.
> > 
> > OK, I triggered it with that. Interesting.
> > 
> 
> Good!
> 
> >> I think that this patch fixes these problems because it does the flag checking in a right order:
> >> first freezing() is used and then frozen() which assures (see frozen_process()) that
> >> the race will not happen. Right? :)
> > 
> > I see what you mean. It still seems like it wouldn't actually fix the race -- just make it
> > harder to trigger. I think you're saying this is what happens without the patch:
> > 
> > Time	"bug" goes through these states		cgroup code checks for these states
> > -----------------------------------------------------------------------------------
> > |	freezing
> > |						is_frozen? Nope.
> > |	frozen
> > |						is_freezing? Nope.
> > |						<move>
> > V
> > 
> My first scenario was a bit different:
> Time	"bug" goes through these states		cgroup code checks for these states
> -----------------------------------------------------------------------------------
> |	freezing
> |						is_task_frozen_enough? Nope.
> |						<move>
> |	frozen
> V
> but the problem is the same.

I think I found a bug in the cgroup freezer which your patch fixes.
However I don't think it's a race.

/* Task is frozen or will freeze immediately when next it gets woken */
static bool is_task_frozen_enough(struct task_struct *task)
{
        return frozen(task) ||
                (task_is_stopped_or_traced(task) && freezing(task));
}

So it will only refuse to attach freezing tasks which have been stopped
or traced! Yet for attach we need to refuse to move _any_ freezing tasks.

Though stopped/traced _is_ relevant to the cgroup freezer state itself.
If we uses frozen(task) || freezing(task) to determine whether a cgroup
is frozen then it would be possible for the task to still be active
when the cgroup is finally reported FROZEN. However that's not possible
when the task is stopped/traced *and* freezing since even if woken it
won't exit the kernel before entering the refrigerator.

> > But, without having carefully investigated the details, this could just as easily happen
> > with your patch:
> > 
> > Time	"bug" goes through these states		cgroup code checks for these states
> > -----------------------------------------------------------------------------------
> > |						is_freezing? Nope.
> > |						is_frozen? Nope.
> > |	freezing
> > |						<move>
> > |	frozen
> > V
> > 
> 
> This can't happen as far as I know because there is cgroup_lock around the code in freezer_write()
> and freezer_can_attach().
> The task can't enter 'freezing' state when can_attach is executed.

You're right, cgroup_mutex should protect against that. However presumably
that same logic applies to the first case. So again I don't think the bug
is a race.

<snipped the remaining cases which should be the same>

At this point I think the bug description in your patch needs to change
but the patch itself is perfect. Assuming you agree with my assessment
of the bug I think the process is: you'll rewrite the description, add -stable
maintaners to your current Cc's (since this bug is simple, exists in previous
versions, and is somewhat nasty), add:

Reviewed-by: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Tested-by: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

and send it to Andrew Morton. Hopefully then (if not before) Paul and Li
will ack it.

Thanks!

Cheers,
	-Matt Helsley

  parent reply	other threads:[~2010-08-12  0:21 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-10 19:53 [PATCH] cgroup_freezer: Freezing and task move race fix Tomasz Buchert
2010-08-10 21:57 ` Matt Helsley
2010-08-10 22:18   ` Tomasz Buchert
2010-08-11  4:27     ` Matt Helsley
2010-08-11  7:35       ` Tomasz Buchert
     [not found]         ` <4C6252CF.1090100-MZpvjPyXg2s@public.gmane.org>
2010-08-12  0:21           ` Matt Helsley [this message]
2010-08-12  0:21         ` Matt Helsley
     [not found]           ` <20100812002154.GJ2927-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-12  0:53             ` Tomasz Buchert
2010-08-13  1:35             ` Rafael J. Wysocki
2010-08-12  0:53           ` Tomasz Buchert
2010-08-12 20:13             ` Matt Helsley
2010-08-18  1:13               ` Tomasz Buchert
     [not found]                 ` <4C6B339E.6010907-MZpvjPyXg2s@public.gmane.org>
2010-08-18  2:22                   ` Matt Helsley
2010-08-18  2:22                 ` Matt Helsley
2010-08-19  8:37                   ` Tomasz Buchert
     [not found]                   ` <20100818022210.GH3648-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-19  8:37                     ` Tomasz Buchert
     [not found]               ` <20100812201334.GA29096-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-18  1:13                 ` Tomasz Buchert
     [not found]             ` <4C634605.50301-MZpvjPyXg2s@public.gmane.org>
2010-08-12 20:13               ` Matt Helsley
2010-08-13  1:35           ` Rafael J. Wysocki
     [not found]       ` <20100811042738.GH2927-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-11  7:35         ` Tomasz Buchert
     [not found]     ` <4C61D044.2060703-MZpvjPyXg2s@public.gmane.org>
2010-08-11  4:27       ` Matt Helsley
     [not found]   ` <20100810215741.GC2927-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-10 22:18     ` Tomasz Buchert
2010-08-11  1:10 ` Matt Helsley
     [not found]   ` <20100811011033.GF2927-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-08-11  7:30     ` Tomasz Buchert
2010-08-11  7:30   ` Tomasz Buchert
2010-08-11  8:01     ` Tomasz Buchert
     [not found]     ` <4C625181.4060606-MZpvjPyXg2s@public.gmane.org>
2010-08-11  8:01       ` Tomasz Buchert
2010-08-12  9:45 ` [PATCH 0/3] Two bugfixes for cgroup freezer Tomasz Buchert
2010-08-12  9:45   ` [PATCH 1/3] cgroup_freezer: Unnecessary test in cgroup_freezing_or_frozen Tomasz Buchert
2010-08-12  9:45     ` [PATCH 2/3] cgroup_freezer: Fix can_attach to prohibit moving from/to freezing/frozen cgroups Tomasz Buchert
     [not found]       ` <1281606323-16245-3-git-send-email-tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
2010-08-12  9:45         ` [PATCH 3/3] cgroup_freezer: update_freezer_state does incorrect state transactions Tomasz Buchert
2010-08-12  9:45       ` Tomasz Buchert
     [not found]     ` <1281606323-16245-2-git-send-email-tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
2010-08-12  9:45       ` [PATCH 2/3] cgroup_freezer: Fix can_attach to prohibit moving from/to freezing/frozen cgroups Tomasz Buchert
     [not found]   ` <1281606323-16245-1-git-send-email-tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
2010-08-12  9:45     ` [PATCH 1/3] cgroup_freezer: Unnecessary test in cgroup_freezing_or_frozen Tomasz Buchert
     [not found] ` <1281470001-14320-1-git-send-email-tomasz.buchert-MZpvjPyXg2s@public.gmane.org>
2010-08-10 21:57   ` [PATCH] cgroup_freezer: Freezing and task move race fix Matt Helsley
2010-08-11  1:10   ` Matt Helsley
2010-08-12  9:45   ` [PATCH 0/3] Two bugfixes for cgroup freezer Tomasz Buchert
  -- strict thread matches above, loose matches on Subject: below --
2010-08-10 19:53 [PATCH] cgroup_freezer: Freezing and task move race fix Tomasz Buchert

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='20100812002154.GJ2927__42952.3837090985$1281572680$gmane$org@count0.beaverton.ibm.com' \
    --to=matthltc-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=Tomasz.Buchert-MZpvjPyXg2s@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=menage-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.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.