From: "Eric W. Biederman" <ebiederm@xmission.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Alexey Gladkov <legion@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Kees Cook <keescook@chromium.org>,
Oleg Nesterov <oleg@redhat.com>
Subject: Re: [GIT PULL] signal/exit/ptrace changes for v5.17
Date: Mon, 17 Jan 2022 09:31:48 -0600 [thread overview]
Message-ID: <87bl0aidjv.fsf@email.froward.int.ebiederm.org> (raw)
In-Reply-To: <CAHk-=wgS865kHU=4NO=AvK07fcK7M6C6EYGdk80R1tkPKTLyhQ@mail.gmail.com> (Linus Torvalds's message of "Mon, 17 Jan 2022 06:08:49 +0200")
Linus Torvalds <torvalds@linux-foundation.org> writes:
> On Sat, Jan 15, 2022 at 2:00 AM Eric W. Biederman <ebiederm@xmission.com> wrote:
>>
>> I am currently investigating to figure out if wake_up_interruptible
>> (instead of simply wake_up) ever makes sense outside of the signal code.
>
> It may not be a huge deal, but it *absolutely* makes sense.
>
> Any subsystem that uses "wait_event_interruptible()" (or variations of
> that) should by default only use "wake_up_interruptible()" to wake the
> wait queue.
>
> The reason? Being (interruptibly) on one wait-queue does *NOT* make it
> impossible that the very same process isn't waiting non-interruptibly
> on another one.
>
> It's not hugely common, but the Linux kernel wait-queues have very
> much been designed for the whole "one process can be on multiple wait
> queues for different reasons at the same time" model. That is *very*
> core.
>
> People sometimes think that is just a "poll/select()" thing, but
> that's not at all true. It's quite valid to do things like
>
> add_wait_queue(..)
> for (.. some loop ..) {
> set_current_state(TASK_INTERRUPTIBLE);
> ... do various things, checking state etc ..
> schedule();
> }
> set_current_state(TASK_RUNNABLE);
> remove_wait_queue();
>
> and part of that "do various things" is obviously checking for signals
> and other "exit this wait loop", but other things can be things like
> taking a page fault because you copied data from user space etc.
>
> And that in turn may end up having a nested wait on another waitqueue
> (for the IO), and the outer wait queue should basically strive to not
> wake up unrelated "deeper" sleeps, because that is pointless and just
> causes extra wakeups.
>
> So the page fault event will cause a nested TASK_UNINTERRUPTIBLE
> sleep, and when that IO has completed, it goes into TASK_RUNNABLE, so
> the outer (interruptible) loop above will have a "dummy schedule()"
> and loop around again to be put back into TASK_INTERRUPTIBLE sleep
> next time around.
>
> But note how it would be pointless to use a "wake_up()" on this outer
> wait queue - it would wake up the deeper IO sleep too, and that would
> just see "oh, the IO I'm waiting for hasn't completed, so I'll just
> have to go to sleep again".
>
> Would it still _work_? Yes. Is the above _common_? No. But it's a
> really fundamnetal pattern in the kernel, and it's fundamentally how
> wait queues work, and how they should work, and an interruptible sleep
> should generally be seen as pairing with an interruptible wake,
> because that's just how things are.
>
> Why would you want to change something basic like that? Yes, using
> "wake_up()" instead of "wake_up_interruptible()" would still result in
> a working kernel, but it's just _pointless_.
Thank you for the detailed reply. I am going to have to spend a little
bit digesting it.
They why is that I am digging into how to reliably test for and get
just the wakeups needed in the coredump code.
As a first approximation writing to files and causing dump_interrupted
to change for signal_pending to fatal_sending_pending worked like a
charm. Unfortunately the pipe code is still performing interruptible
waits and io_uring causes truncated coredumps.
I would like to have a version of pipe_write that sleeps in
TASK_KILLABLE. I want the I/O wake-ups and I want the SIGKILL wake ups
but I don't want any other wake-ups. Unfortunately the I/O wake-ups in
the pipe code are sent with wake_up_interruptible. So a task sleeping
in TASK_KILLABLE won't get them.
Which means that the obvious solution of changing
wait_event_interruptible to wake_event_killable breaks coredump support
(as I found out the hard way).
I understand things well enough that I can change the signal code and
not make the coredump code worse. I am still trying to figure out what
a clean maintainable solution for coredumps writing to pipes is going to
be. So I will dig in and read the code that has the nested wait queues
and see if I can understand that logic, and keep thinking about the
coredump support.
Eric
next prev parent reply other threads:[~2022-01-17 15:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-14 23:59 Eric W. Biederman
2022-01-17 4:08 ` Linus Torvalds
2022-01-17 4:15 ` Linus Torvalds
2022-01-17 15:45 ` Eric W. Biederman
2022-01-17 15:31 ` Eric W. Biederman [this message]
2022-01-17 15:44 ` Linus Torvalds
2022-01-17 16:31 ` Eric W. Biederman
2022-01-17 5:18 ` pr-tracker-bot
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=87bl0aidjv.fsf@email.froward.int.ebiederm.org \
--to=ebiederm@xmission.com \
--cc=keescook@chromium.org \
--cc=legion@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=torvalds@linux-foundation.org \
--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
Powered by JetHome