[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <x49lgh54d39.fsf@segfault.boston.devel.redhat.com>
Date: Wed, 10 Jan 2018 16:29:30 -0500
From: Jeff Moyer <jmoyer@...hat.com>
To: Christoph Hellwig <hch@....de>
Cc: viro@...iv.linux.org.uk, Avi Kivity <avi@...lladb.com>,
linux-aio@...ck.org, linux-fsdevel@...r.kernel.org,
netdev@...r.kernel.org, linux-api@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH 27/32] aio: sanitize ki_list handling
Christoph Hellwig <hch@....de> writes:
> Instead of handcoded non-null checks always initialize ki_list to an
> empty list and use list_empty / list_empty_careful on it.
Yeah, who knows why list_empty wasn't used from the beginning. In the
past, tricks were played by overwriting list pointers with non-null, but
that wasn't the case here.
> While we're at it also error out on a double call to
> kiocb_set_cancel_fn instead of ignoring it.
>
> Signed-off-by: Christoph Hellwig <hch@....de>
> ---
> fs/aio.c | 13 ++++++-------
> 1 file changed, 6 insertions(+), 7 deletions(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 496b50f9e9b1..fe241b5b44b2 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -555,13 +555,12 @@ void kiocb_set_cancel_fn(struct kiocb *iocb, kiocb_cancel_fn *cancel)
> struct kioctx *ctx = req->ki_ctx;
> unsigned long flags;
>
> - spin_lock_irqsave(&ctx->ctx_lock, flags);
> -
> - if (!req->ki_list.next)
> - list_add(&req->ki_list, &ctx->active_reqs);
> + if (WARN_ON_ONCE(!list_empty(&req->ki_list)))
> + return;
>
> + spin_lock_irqsave(&ctx->ctx_lock, flags);
> + list_add_tail(&req->ki_list, &ctx->active_reqs);
> req->ki_cancel = cancel;
So, this changes behavior from quietly overwriting the prior cancel
function to not doing it. I don't think it matters one bit, though.
Callers shouldn't do that.
Acked-by: Jeff Moyer <jmoyer@...hat.com>
Powered by blists - more mailing lists