mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roman Gushchin <guro@fb.com>
To: "Alex Xu (Hello71)" <alex_y_xu@yahoo.ca>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"tj@kernel.org" <tj@kernel.org>,
	"oleg@redhat.com" <oleg@redhat.com>,
	"Kernel Team" <Kernel-team@fb.com>
Subject: Re: [REGRESSION] ptrace broken from "cgroup: cgroup v2 freezer" (76f969e)
Date: Mon, 13 May 2019 17:03:58 +0000	[thread overview]
Message-ID: <20190513170354.GB10982@tower.DHCP.thefacebook.com> (raw)
In-Reply-To: <1557709124.798rxdb4l3.astroid@alex-desktop.none>

Hi Alex!

Thank you for the report!
It's super clear, and contains all the details, so it took me 30s
to reproduce the issue. Really appreciate your effort!



On Sun, May 12, 2019 at 09:20:12PM -0400, Alex Xu (Hello71) wrote:
> Hi,
> 
> I was trying to use strace recently and found that it exhibited some 
> strange behavior. I produced this minimal test case:
> 
> #include <unistd.h>
> 
> int main() {
>     write(1, "a", 1);
>     return 0;
> }
> 
> which, when run using "gcc test.c && strace ./a.out" produces this 
> strace output:
> 
> [ pre-main omitted ]
> write(1, "a", 1)                        = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
> write(1, "a", 1)                        = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
> write(1, "a", 1)                        = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
> write(1, "a", 1)                        = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
> write(1, "a", 1)                        = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
> write(1, "a", 1)                        = ? ERESTARTSYS (To be restarted if SA_RESTART is set)
> [ repeats forever ]
> 
> The correct result is of course:
> 
> [ pre-main omitted ]
> write(1, "a", 1)                        = 1
> exit_group(0)                           = ?
> +++ exited with 0 +++
> 
> Strangely, this only occurs when outputting to a tty-like output. 
> Running "strace ./a.out" from a native Linux x86 console or a terminal 
> emulator causes the abnormal behavior. However, the following commands 
> work correctly:
> 
> - strace ./a.out >/dev/null
> - strace ./a.out >/tmp/a # /tmp is a standard tmpfs
> - strace ./a.out >&- # causes -1 EBADF (Bad file descriptor)
> 
> "strace -o /tmp/a ./a.out" hangs and produces the above (infinite) 
> output to /tmp/a.
> 
> I bisected this to 76f969e, "cgroup: cgroup v2 freezer". I reverted the 
> entire patchset (reverting only that one caused a conflict), which 
> resolved the issue. I skimmed the patch and came up with this 
> workaround, which also resolves the issue. I am not at all clear on the 
> technical workings of the patchset, but it seems to me like a process's 
> frozen status is supposed to be "suspended" when a frozen process is 
> ptraced, and "unsuspended" when ptracing ends. Therefore, it seems 
> suspicious to always "enter frozen" whether or not the cgroup is 
> actually frozen. It seems like the code should instead check if the 
> cgroup is actually frozen, and if so, restore the frozen status.

So, the thing is that when the freezer tries to freeze all tasks
in the cgroup, some tasks may sleep (e.g. being SIGSTOPPed),
and the freezer can't get them out of this state and put them back correctly
after unfreezing. So instead it leaves such tasks in the original state
and treats them as frozen. This is why we need this unconditional
cgroup_enter_frozen(). It's not the problem.

Anyway, I'm sure that with great help from Oleg we'll be able
to fix the issue very soon (I already posted a preliminary patch).

Once again, thank you for the report!

Roman

      parent reply	other threads:[~2019-05-13 17:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-13  1:20 Alex Xu (Hello71)
2019-05-13  1:57 ` Valdis Klētnieks
2019-05-13 12:17 ` Oleg Nesterov
2019-05-13 16:38   ` Oleg Nesterov
2019-05-13 16:54     ` Roman Gushchin
2019-05-13 17:03 ` Roman Gushchin [this message]

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=20190513170354.GB10982@tower.DHCP.thefacebook.com \
    --to=guro@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=alex_y_xu@yahoo.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=tj@kernel.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 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®