From: Benjamin LaHaise <bcrl@kvack.org>
To: Chris Mason <clm@fb.com>
Cc: linux-fsdevel@vger.kernel.org, linux-aio@kvack.org,
Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH RFC] fs/aio: fix sleeping while TASK_INTERRUPTIBLE
Date: Tue, 23 Dec 2014 16:58:47 -0500 [thread overview]
Message-ID: <20141223215847.GD17185@kvack.org> (raw)
In-Reply-To: <1419360926.13012.12@mail.thefacebook.com>
Hi Chris,
On Tue, Dec 23, 2014 at 01:55:26PM -0500, Chris Mason wrote:
> Works for me, the patch is mostly a (somewhat commented) list of all
> the places we're currently doing it wrong.
I think the following change should suffice to fix this issue, and it's a
lot easier to review, too. I've given this a quick test, and it works for
me. I do have one concern: is it safe to call mutex_lock() when the current
task is already on other wait queues? If the answer is no, then it may be
necessary to convert ->ring_lock back into spinlock as it was prior to 3.10
to avoid using mutex_lock(). The same question applies to kmap() and
copy_to_user(), and those concerns might have implications across the rest
of the kernel. Thoughts?
-ben
--
"Thought is the essence of where you are now."
diff --git a/fs/aio.c b/fs/aio.c
index 1b7893e..a25bd96 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -1140,7 +1140,14 @@ static long aio_read_events_ring(struct kioctx *ctx,
long ret = 0;
int copy_ret;
- mutex_lock(&ctx->ring_lock);
+ /* Avoid clobbering current->state during mutex_lock(). */
+ if (!mutex_trylock(&ctx->ring_lock)) {
+ long state = current->state;
+
+ __set_current_state(TASK_RUNNING);
+ mutex_lock(&ctx->ring_lock);
+ __set_current_state(state);
+ }
/* Access to ->ring_pages here is protected by ctx->ring_lock. */
ring = kmap_atomic(ctx->ring_pages[0]);
@@ -1179,6 +1186,7 @@ static long aio_read_events_ring(struct kioctx *ctx,
page = ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE];
pos %= AIO_EVENTS_PER_PAGE;
+ __set_current_state(TASK_RUNNING);
ev = kmap(page);
copy_ret = copy_to_user(event + ret, ev + pos,
sizeof(*ev) * avail);
--
To unsubscribe, send a message with 'unsubscribe linux-aio' in
the body to majordomo@kvack.org. For more info on Linux AIO,
see: http://www.kvack.org/aio/
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>
next prev parent reply other threads:[~2014-12-23 21:58 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-23 0:16 [PATCH RFC] fs/aio: fix sleeping while TASK_INTERRUPTIBLE Chris Mason
2014-12-23 18:43 ` Benjamin LaHaise
2014-12-23 18:55 ` Chris Mason
2014-12-23 21:58 ` Benjamin LaHaise [this message]
2014-12-25 2:59 ` Kent Overstreet
2014-12-25 3:11 ` Benjamin LaHaise
2014-12-25 3:29 ` Kent Overstreet
2014-12-29 1:24 ` Chris Mason
2014-12-25 2:56 ` Kent Overstreet
2014-12-25 14:27 ` Sedat Dilek
2015-01-04 10:16 ` Sedat Dilek
2014-12-29 15:08 ` Chris Mason
2014-12-29 22:08 ` Kent Overstreet
2015-01-13 16:06 ` Benjamin LaHaise
2015-01-13 16:20 ` Chris Mason
2015-01-21 10:13 ` Dave Chinner
2015-01-21 21:42 ` Chris Mason
2015-02-03 9:14 ` Sedat Dilek
2015-02-03 9:54 ` Sedat Dilek
2015-02-09 3:08 ` Sedat Dilek
2015-02-09 4:21 ` Sedat Dilek
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=20141223215847.GD17185@kvack.org \
--to=bcrl@kvack.org \
--cc=clm@fb.com \
--cc=linux-aio@kvack.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=peterz@infradead.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).