linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Benjamin LaHaise <bcrl@kvack.org>
Cc: linux-aio@kvack.org, Linux Kernel <linux-kernel@vger.kernel.org>
Subject: Re: [GIT PULL] aio: fix sleeping while TASK_INTERRUPTIBLE
Date: Sun, 1 Feb 2015 15:09:37 -0800	[thread overview]
Message-ID: <CA+55aFx=H-pthwKGn7ZsT0kz2ZWgmypM-JdWAwUQt=tnVdscwA@mail.gmail.com> (raw)
In-Reply-To: <20150201221458.GN2974@kvack.org>

On Sun, Feb 1, 2015 at 2:14 PM, Benjamin LaHaise <bcrl@kvack.org> wrote:
>
> It's ugly, but it actually is revealing a bug.

If so, that patch is *still* not the right thing to do. Leave the
warning. It's better than horrible crap code that doesn't warn, but
also doesn't make any *sense*.

Because code like this is just crap:

+       int running = current->state == TASK_RUNNING;

really. It's just crazy.

It makes no sense. It's all just avoiding the warning, it's not making
the code any better. In fact, it's actively making it worse, because
now the code is literally designed to give random different behavior
depending on timing.


For all I know, there might be multiple concurrent waiters etc that
got woken up on the same wait-queue, afaik, so the "am I runnable"
question is fundamentally nonsensical, since it isn't necessarily the
same as testing the state of the ring that we're waiting for anyway.
And if it *is* the same thing (because maybe the locking does end up
guaranteeing that "running" here ends up always matching some
particular state of the aio ring), then it should still be rewritten
in terms of that ring state, not some random "am I runnable" question.

So *clearly* the code has explicitly been written for the debug test,
not to make sense. Seriously. It's the only possible reason for why it
would test "current->state".

If the code relies on some 1:1 relationship with the wakeups
(*despite* having comments currently explicitly saying that it
doesn't), then use the new "wait_woken()" interface instead, which
actually does exactly that. That one doesn't test some random state,
it tests "was I explicitly woken". Then the whole "oh, but the mutex
changed the task state" doesn't even *matter*.

Which may in the end be the same thing in practice, but at least the
code makes *sense*. In ways that that "current->state == TASK_RUNNING"
test does not.

                         Linus

  reply	other threads:[~2015-02-01 23:09 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-01 14:40 [GIT PULL] aio: fix sleeping while TASK_INTERRUPTIBLE Benjamin LaHaise
2015-02-01 21:01 ` Linus Torvalds
2015-02-01 22:14   ` Benjamin LaHaise
2015-02-01 23:09     ` Linus Torvalds [this message]
2015-02-01 23:33     ` Linus Torvalds
2015-02-02  0:16       ` Benjamin LaHaise
2015-02-02  1:18         ` Linus Torvalds
2015-02-02  5:29           ` Dave Chinner
     [not found]             ` <CA+55aFwvEcq-rAbqF2qTut=kJgFZZnhHptoPi6FSVrF4+1tBNA@mail.gmail.com>
2015-02-02  5:54               ` Dave Chinner
2015-02-02 18:45                 ` Linus Torvalds
2015-02-03 22:23                   ` Dave Chinner
2015-02-03 23:34                     ` Benjamin LaHaise
2015-02-03 11:27           ` Peter Zijlstra
2015-02-03 11:33             ` Peter Zijlstra
2015-02-03 11:55               ` Peter Zijlstra
2015-02-03 23:24                 ` Jens Axboe
2015-02-04 10:18                   ` [PATCH] block: Simplify bsg complete all Peter Zijlstra
2015-02-04 17:06                     ` Jens Axboe
2015-02-03 12:25             ` [PATCH] iommu/amd: Fix amd_iommu_free_device() Peter Zijlstra
2015-02-03 17:04               ` Jesse Barnes
2015-02-03 17:34               ` Joerg Roedel
2015-02-03 19:23                 ` Linus Torvalds
2015-02-03 22:56                   ` Joerg Roedel
2015-02-04 14:35               ` Joerg Roedel

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='CA+55aFx=H-pthwKGn7ZsT0kz2ZWgmypM-JdWAwUQt=tnVdscwA@mail.gmail.com' \
    --to=torvalds@linux-foundation.org \
    --cc=bcrl@kvack.org \
    --cc=linux-aio@kvack.org \
    --cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).