public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
To: Tang Chen <tangchen@cn.fujitsu.com>
Cc: <viro@zeniv.linux.org.uk>, <bcrl@kvack.org>, <jmoyer@redhat.com>,
	<kosaki.motohiro@gmail.com>, <kosaki.motohiro@jp.fujitsu.com>,
	<guz.fnst@cn.fujitsu.com>, <linux-fsdevel@vger.kernel.org>,
	<linux-aio@kvack.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 2/2] aio, mem-hotplug: Add memory barrier to aio ring page migration.
Date: Thu, 27 Feb 2014 21:06:05 +0900	[thread overview]
Message-ID: <530F2A2D.50307@jp.fujitsu.com> (raw)
In-Reply-To: <1393497616-16428-3-git-send-email-tangchen@cn.fujitsu.com>

Hi Tang,

(2014/02/27 19:40), Tang Chen wrote:
> When doing aio ring page migration, we migrated the page, and update
> ctx->ring_pages[]. Like the following:
> 
> aio_migratepage()
>   |-> migrate_page_copy(new, old)
>   |   ......				/* Need barrier here */
>   |-> ctx->ring_pages[idx] = new
> 
> Actually, we need a memory barrier between these two operations.
> Otherwise, if ctx->ring_pages[] is updated before memory copy due to
> the compiler optimization, other processes may have an opportunity
> to access to the not fully initialized new ring page.
> 
> So add a wmb to synchronize them.
> 
> Reported-by: Yasuaki Ishimatsu <isimatu.yasuaki@jp.fujitsu.com>
> Signed-off-by: Tang Chen <tangchen@cn.fujitsu.com>
> ---
>   fs/aio.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/fs/aio.c b/fs/aio.c
> index 50c089c..f0ed838 100644
> --- a/fs/aio.c
> +++ b/fs/aio.c
> @@ -327,6 +327,14 @@ static int aio_migratepage(struct address_space *mapping, struct page *new,
>   		pgoff_t idx;
>   		spin_lock_irqsave(&ctx->completion_lock, flags);
>   		migrate_page_copy(new, old);
> +
> +		/*
> +		 * Ensure memory copy is finished before updating
> +		 * ctx->ring_pages[]. Otherwise other processes may access to
> +		 * new ring pages which are not fully initialized.
> +		 */
> +		smp_wmb();
> +

If you put smp_wmb() here, you should put smp_rmb() before kmap() in
aio_read_events_ring().

Thanks,
Yasuaki Ishimatsu

>   		idx = old->index;
>   		if (idx < (pgoff_t)ctx->nr_pages) {
>   			/* And only do the move if things haven't changed */
> 



  reply	other threads:[~2014-02-27 12:06 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-27 10:40 [PATCH 0/2] Bug fix in aio ring page migration Tang Chen
2014-02-27 10:40 ` [PATCH 1/2] aio, memory-hotplug: Fix confliction when migrating and accessing ring pages Tang Chen
2014-03-05 19:23   ` Jeff Moyer
2014-02-27 10:40 ` [PATCH 2/2] aio, mem-hotplug: Add memory barrier to aio ring page migration Tang Chen
2014-02-27 12:06   ` Yasuaki Ishimatsu [this message]
2014-02-27 12:44     ` [Update PATCH " Yasuaki Ishimatsu
2014-03-04  5:35       ` Miao Xie
2014-03-05  3:04         ` KOSAKI Motohiro
2014-03-05  6:59         ` Yasuaki Ishimatsu
2014-03-05  7:17       ` [Update v2 " Yasuaki Ishimatsu
2014-02-27 14:57   ` [PATCH " Benjamin LaHaise
2014-02-28  1:29     ` Gu Zheng
2014-02-28  7:25     ` Yasuaki Ishimatsu

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=530F2A2D.50307@jp.fujitsu.com \
    --to=isimatu.yasuaki@jp.fujitsu.com \
    --cc=bcrl@kvack.org \
    --cc=guz.fnst@cn.fujitsu.com \
    --cc=jmoyer@redhat.com \
    --cc=kosaki.motohiro@gmail.com \
    --cc=kosaki.motohiro@jp.fujitsu.com \
    --cc=linux-aio@kvack.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tangchen@cn.fujitsu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox