From: Benjamin LaHaise <bcrl@kvack.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Kent Overstreet <kmo@daterainc.com>,
Al Viro <viro@zeniv.linux.org.uk>,
linux-aio@kvack.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 1/2] aio: change exit_aio() to load mm->ioctx_table once and avoid rcu_read_lock()
Date: Wed, 30 Apr 2014 11:23:44 -0400 [thread overview]
Message-ID: <20140430152344.GD28959@kvack.org> (raw)
In-Reply-To: <20140430141616.GB18539@redhat.com>
Hi Oleg,
On Wed, Apr 30, 2014 at 04:16:16PM +0200, Oleg Nesterov wrote:
> 1. We can read ->ioctx_table only once and we do not read rcu_read_lock()
> or even rcu_dereference().
>
> This mm has no users, nobody else can play with ->ioctx_table. Otherwise
> the code is buggy anyway, if we need rcu_read_lock() in a loop because
> ->ioctx_table can be updated then kfree(table) is obviously wrong.
>
> 2. Update the comment. "exit_mmap(mm) is coming" is the good reason to avoid
> munmap(), but another reason is that we simply can't do vm_munmap() unless
> current->mm == mm and this is not true in general, the caller is mmput().
>
> 3. We do not really need to nullify mm->ioctx_table before return, probably
> the current code does this to catch the potential problems. But in this
> case RCU_INIT_POINTER(NULL) looks better.
Looks pretty good. One minor style comment below.
> Signed-off-by: Oleg Nesterov <oleg@redhat.com>
> ---
> fs/aio.c | 47 ++++++++++++++++++-----------------------------
> 1 files changed, 18 insertions(+), 29 deletions(-)
>
> diff --git a/fs/aio.c b/fs/aio.c
> index 79b7e69..3526c2b 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -791,40 +791,29 @@ EXPORT_SYMBOL(wait_on_sync_kiocb);
> */
> void exit_aio(struct mm_struct *mm)
> {
> - struct kioctx_table *table;
> - struct kioctx *ctx;
> - unsigned i = 0;
> -
> - while (1) {
> - rcu_read_lock();
> - table = rcu_dereference(mm->ioctx_table);
> -
> - do {
> - if (!table || i >= table->nr) {
> - rcu_read_unlock();
> - rcu_assign_pointer(mm->ioctx_table, NULL);
> - if (table)
> - kfree(table);
> - return;
> - }
> -
> - ctx = table->table[i++];
> - } while (!ctx);
> + struct kioctx_table *table = rcu_dereference_raw(mm->ioctx_table);
> + int i;
>
> - rcu_read_unlock();
> + if (!table)
> + return;
>
> + for (i = 0; i < table->nr; ++i) {
> + struct kioctx *ctx = table->table[i];
> /*
> - * We don't need to bother with munmap() here -
> - * exit_mmap(mm) is coming and it'll unmap everything.
> - * Since aio_free_ring() uses non-zero ->mmap_size
> - * as indicator that it needs to unmap the area,
> - * just set it to 0; aio_free_ring() is the only
> - * place that uses ->mmap_size, so it's safe.
> + * We don't need to bother with munmap() here - exit_mmap(mm)
> + * is coming and it'll unmap everything. And we simply can't,
> + * this is not necessarily our ->mm.
> + * Since kill_ioctx() uses non-zero ->mmap_size as indicator
> + * that it needs to unmap the area, just set it to 0.
> */
> - ctx->mmap_size = 0;
> -
> - kill_ioctx(mm, ctx, NULL);
> + if (ctx) {
> + ctx->mmap_size = 0;
> + kill_ioctx(mm, ctx, NULL);
> + }
Rather than indenting and moving the two lines changing mmap_size and the
kill_ioctx() call, why not just do "if (!ctx) ... continue;"? That reduces
the number of lines changed and avoid excessive indentation.
-ben
> }
> +
> + RCU_INIT_POINTER(mm->ioctx_table, NULL);
> + kfree(table);
> }
>
> static void put_reqs_available(struct kioctx *ctx, unsigned nr)
> --
> 1.5.5.1
>
--
"Thought is the essence of where you are now."
next prev parent reply other threads:[~2014-04-30 15:23 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-29 18:39 [PATCH 0/1] aio: change exit_aio() to load mm->ioctx_table once and avoid rcu_read_lock() Oleg Nesterov
2014-04-29 18:39 ` Oleg Nesterov
2014-04-29 23:36 ` Kent Overstreet
2014-04-29 18:40 ` [PATCH 1/1] " Oleg Nesterov
2014-04-29 20:42 ` Benjamin LaHaise
2014-04-29 21:22 ` Benjamin LaHaise
2014-04-29 23:04 ` Mateusz Guzik
2014-04-30 12:13 ` Oleg Nesterov
2014-04-30 14:15 ` [PATCH v2 0/2] aio: ioctx_table/rcu_read_lock cleanups Oleg Nesterov
2014-04-30 14:16 ` [PATCH v2 1/2] aio: change exit_aio() to load mm->ioctx_table once and avoid rcu_read_lock() Oleg Nesterov
2014-04-30 15:23 ` Benjamin LaHaise [this message]
2014-04-30 17:02 ` [PATCH v3 " Oleg Nesterov
2014-04-30 14:16 ` [PATCH v2 2/2] aio: kill the misleading rcu read locks in ioctx_add_table() and kill_ioctx() Oleg Nesterov
2014-04-29 19:33 ` [PATCH 0/1] aio: change exit_aio() to load mm->ioctx_table once and avoid rcu_read_lock() Benjamin LaHaise
2014-04-29 19:49 ` Oleg Nesterov
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=20140430152344.GD28959@kvack.org \
--to=bcrl@kvack.org \
--cc=akpm@linux-foundation.org \
--cc=kmo@daterainc.com \
--cc=linux-aio@kvack.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.