* [PATCH 1/2] aio: correct calculation of available events
@ 2013-02-13 17:45 Benjamin LaHaise
2013-02-14 1:33 ` Kent Overstreet
0 siblings, 1 reply; 2+ messages in thread
From: Benjamin LaHaise @ 2013-02-13 17:45 UTC (permalink / raw)
To: Andrew Morton, Kent Overstreet; +Cc: linux-aio, linux-fsdevel, Linux Kernel
When the number of available events in the ring buffer is calculated,
the avail calculation is incorrect when head == tail. This is harmless
in aio_read_events_ring(), but in free_ioctx() leads to the subsequent
WARN_ON(atomic_read(&ctx->reqs_available) > ctx->nr). Correct this.
Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
---
fs/aio.c | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/aio.c b/fs/aio.c
index 24ba228..dc52b0c 100644
--- a/fs/aio.c
+++ b/fs/aio.c
@@ -337,7 +337,8 @@ static void free_ioctx(struct kioctx *ctx)
while (atomic_read(&ctx->reqs_available) < ctx->nr) {
wait_event(ctx->wait, head != ctx->shadow_tail);
- avail = (head < ctx->shadow_tail ? ctx->shadow_tail : ctx->nr) - head;
+ avail = (head <= ctx->shadow_tail ?
+ ctx->shadow_tail : ctx->nr) - head;
atomic_add(avail, &ctx->reqs_available);
head += avail;
@@ -884,7 +885,7 @@ static long aio_read_events_ring(struct kioctx *ctx,
goto out;
while (ret < nr) {
- long avail = (head < ctx->shadow_tail
+ long avail = (head <= ctx->shadow_tail
? ctx->shadow_tail : ctx->nr) - head;
struct io_event *ev;
struct page *page;
--
1.7.4.1
--
"Thought is the essence of where you are now."
--
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>
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 1/2] aio: correct calculation of available events
2013-02-13 17:45 [PATCH 1/2] aio: correct calculation of available events Benjamin LaHaise
@ 2013-02-14 1:33 ` Kent Overstreet
0 siblings, 0 replies; 2+ messages in thread
From: Kent Overstreet @ 2013-02-14 1:33 UTC (permalink / raw)
To: Benjamin LaHaise; +Cc: Andrew Morton, linux-aio, linux-fsdevel, Linux Kernel
On Wed, Feb 13, 2013 at 12:45:52PM -0500, Benjamin LaHaise wrote:
> When the number of available events in the ring buffer is calculated,
> the avail calculation is incorrect when head == tail. This is harmless
> in aio_read_events_ring(), but in free_ioctx() leads to the subsequent
> WARN_ON(atomic_read(&ctx->reqs_available) > ctx->nr). Correct this.
>
> Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
> ---
> fs/aio.c | 5 +++--
> 1 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 24ba228..dc52b0c 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -337,7 +337,8 @@ static void free_ioctx(struct kioctx *ctx)
> while (atomic_read(&ctx->reqs_available) < ctx->nr) {
> wait_event(ctx->wait, head != ctx->shadow_tail);
>
> - avail = (head < ctx->shadow_tail ? ctx->shadow_tail : ctx->nr) - head;
> + avail = (head <= ctx->shadow_tail ?
> + ctx->shadow_tail : ctx->nr) - head;
>
> atomic_add(avail, &ctx->reqs_available);
> head += avail;
> @@ -884,7 +885,7 @@ static long aio_read_events_ring(struct kioctx *ctx,
> goto out;
>
> while (ret < nr) {
> - long avail = (head < ctx->shadow_tail
> + long avail = (head <= ctx->shadow_tail
> ? ctx->shadow_tail : ctx->nr) - head;
> struct io_event *ev;
> struct page *page;
> --
> 1.7.4.1
>
>
> --
> "Thought is the essence of where you are now."
Whoops!
Reviewed-by: Kent Overstreet <koverstreet@google.com>
--
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>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-02-14 1:33 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-02-13 17:45 [PATCH 1/2] aio: correct calculation of available events Benjamin LaHaise
2013-02-14 1:33 ` Kent Overstreet
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).