From: Zumeng Chen <zumeng.chen@windriver.com>
To: <linux-mm@kvack.org>, <linux-mips@linux-mips.org>
Cc: <linux-kernel@vger.kernel.org>, <torvalds@linux-foundation.org>,
<mingo@elte.hu>, <ralf@linux-mips.org>,
<bruce.ashfield@gmail.com>
Subject: Re: [PATCH 1/1] mm: msync: fix issues of sys_msync on tmpfs
Date: Sat, 21 Jan 2012 11:23:02 +0800 [thread overview]
Message-ID: <4F1A2F96.2040106@windriver.com> (raw)
In-Reply-To: <1327036719-1965-1-git-send-email-zumeng.chen@windriver.com>
To: linux-mm@kvack.org, and linux-mips@linux-mips.org
于 2012年01月20日 13:18, Zumeng Chen 写道:
> This patch fixes two issues as follows:
>
> For some filesystem with fsync == noop_fsync, there is not so much thing
> to do, so sys_msync just passes by for all arches but some CPUs.
>
> For some CPUs with cache aliases(dmesg|grep alias), it maybe has an issue,
> which reported by msync test suites in ltp-full when the memory of memset
> used by msync01 runs into cache alias randomly.
>
> Consider the following scenario used by msync01 in ltp-full:
> fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0);
> .../* initialization fildes by write(fildes); */
> addr = mmap(0, page_sz, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED,
> fildes, 0);
> /* set buf with memset */
> memset(addr + OFFSET_1, 1, BUF_SIZE);
>
> /* msync the addr before using, or MS_SYNC*/
> msync(addr, page_sz, MS_ASYNC)
>
> /* Tries to read fildes */
> lseek(fildes, (off_t) OFFSET_1, SEEK_SET) != (off_t) OFFSET_1) {
> nread = read(fildes, read_buf, sizeof(read_buf));
>
> /* Then test the result */
> if (read_buf[count] != 1) {
>
> The test result is random too for CPUs with cache alias. So in this
> situation, we have to flush the related vma to make sure the read is
> correct.
>
> Signed-off-by: Zumeng Chen <zumeng.chen@windriver.com>
> ---
> mm/msync.c | 30 ++++++++++++++++++++++++++++++
> 1 files changed, 30 insertions(+), 0 deletions(-)
>
> diff --git a/mm/msync.c b/mm/msync.c
> index 632df45..0021a7e 100644
> --- a/mm/msync.c
> +++ b/mm/msync.c
> @@ -13,6 +13,14 @@
> #include <linux/file.h>
> #include <linux/syscalls.h>
> #include <linux/sched.h>
> +#include <asm/cacheflush.h>
> +
> +/* Cache aliases should be taken into accounts when msync. */
> +#ifdef cpu_has_dc_aliases
> +#define CPU_HAS_CACHE_ALIAS cpu_has_dc_aliases
> +#else
> +#define CPU_HAS_CACHE_ALIAS 0
> +#endif
>
> /*
> * MS_SYNC syncs the entire file - including mappings.
> @@ -78,6 +86,28 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
> }
> file = vma->vm_file;
> start = vma->vm_end;
> +
> + /*
> + * For some filesystems with fsync == noop_fsync, msync just
> + * passes by but some CPUs.
> + * For CPUs with cache alias, msync has to flush the related
> + * vma explicitly to make sure data coherency between memory
> + * and cache, which includes MS_SYNC or MS_ASYNC. That is to
> + * say, cache aliases should not be an async factor, so does
> + * msync on other arches without cache aliases.
> + */
> + if (file && file->f_op && file->f_op->fsync == noop_fsync) {
> + if (CPU_HAS_CACHE_ALIAS)
> + flush_cache_range(vma, vma->vm_start,
> + vma->vm_end);
> + if (start >= end) {
> + error = 0;
> + goto out_unlock;
> + }
> + vma = find_vma(mm, start);
> + continue;
> + }
> +
> if ((flags & MS_SYNC) && file &&
> (vma->vm_flags & VM_SHARED)) {
> get_file(file);
WARNING: multiple messages have this Message-ID (diff)
From: Zumeng Chen <zumeng.chen@windriver.com>
To: linux-mm@kvack.org, linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
mingo@elte.hu, ralf@linux-mips.org, bruce.ashfield@gmail.com
Subject: Re: [PATCH 1/1] mm: msync: fix issues of sys_msync on tmpfs
Date: Sat, 21 Jan 2012 11:23:02 +0800 [thread overview]
Message-ID: <4F1A2F96.2040106@windriver.com> (raw)
Message-ID: <20120121032302.Z6RCblRQpE232VBDpztvbedQ2n36-FNy5_T-3Gx5cSs@z> (raw)
In-Reply-To: <1327036719-1965-1-git-send-email-zumeng.chen@windriver.com>
To: linux-mm@kvack.org, and linux-mips@linux-mips.org
于 2012年01月20日 13:18, Zumeng Chen 写道:
> This patch fixes two issues as follows:
>
> For some filesystem with fsync == noop_fsync, there is not so much thing
> to do, so sys_msync just passes by for all arches but some CPUs.
>
> For some CPUs with cache aliases(dmesg|grep alias), it maybe has an issue,
> which reported by msync test suites in ltp-full when the memory of memset
> used by msync01 runs into cache alias randomly.
>
> Consider the following scenario used by msync01 in ltp-full:
> fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0);
> .../* initialization fildes by write(fildes); */
> addr = mmap(0, page_sz, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED,
> fildes, 0);
> /* set buf with memset */
> memset(addr + OFFSET_1, 1, BUF_SIZE);
>
> /* msync the addr before using, or MS_SYNC*/
> msync(addr, page_sz, MS_ASYNC)
>
> /* Tries to read fildes */
> lseek(fildes, (off_t) OFFSET_1, SEEK_SET) != (off_t) OFFSET_1) {
> nread = read(fildes, read_buf, sizeof(read_buf));
>
> /* Then test the result */
> if (read_buf[count] != 1) {
>
> The test result is random too for CPUs with cache alias. So in this
> situation, we have to flush the related vma to make sure the read is
> correct.
>
> Signed-off-by: Zumeng Chen <zumeng.chen@windriver.com>
> ---
> mm/msync.c | 30 ++++++++++++++++++++++++++++++
> 1 files changed, 30 insertions(+), 0 deletions(-)
>
> diff --git a/mm/msync.c b/mm/msync.c
> index 632df45..0021a7e 100644
> --- a/mm/msync.c
> +++ b/mm/msync.c
> @@ -13,6 +13,14 @@
> #include <linux/file.h>
> #include <linux/syscalls.h>
> #include <linux/sched.h>
> +#include <asm/cacheflush.h>
> +
> +/* Cache aliases should be taken into accounts when msync. */
> +#ifdef cpu_has_dc_aliases
> +#define CPU_HAS_CACHE_ALIAS cpu_has_dc_aliases
> +#else
> +#define CPU_HAS_CACHE_ALIAS 0
> +#endif
>
> /*
> * MS_SYNC syncs the entire file - including mappings.
> @@ -78,6 +86,28 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
> }
> file = vma->vm_file;
> start = vma->vm_end;
> +
> + /*
> + * For some filesystems with fsync == noop_fsync, msync just
> + * passes by but some CPUs.
> + * For CPUs with cache alias, msync has to flush the related
> + * vma explicitly to make sure data coherency between memory
> + * and cache, which includes MS_SYNC or MS_ASYNC. That is to
> + * say, cache aliases should not be an async factor, so does
> + * msync on other arches without cache aliases.
> + */
> + if (file && file->f_op && file->f_op->fsync == noop_fsync) {
> + if (CPU_HAS_CACHE_ALIAS)
> + flush_cache_range(vma, vma->vm_start,
> + vma->vm_end);
> + if (start >= end) {
> + error = 0;
> + goto out_unlock;
> + }
> + vma = find_vma(mm, start);
> + continue;
> + }
> +
> if ((flags & MS_SYNC) && file &&
> (vma->vm_flags & VM_SHARED)) {
> get_file(file);
WARNING: multiple messages have this Message-ID (diff)
From: Zumeng Chen <zumeng.chen@windriver.com>
To: linux-mm@kvack.org, linux-mips@linux-mips.org
Cc: linux-kernel@vger.kernel.org, torvalds@linux-foundation.org,
mingo@elte.hu, ralf@linux-mips.org, bruce.ashfield@gmail.com
Subject: Re: [PATCH 1/1] mm: msync: fix issues of sys_msync on tmpfs
Date: Sat, 21 Jan 2012 11:23:02 +0800 [thread overview]
Message-ID: <4F1A2F96.2040106@windriver.com> (raw)
In-Reply-To: <1327036719-1965-1-git-send-email-zumeng.chen@windriver.com>
To: linux-mm@kvack.org, and linux-mips@linux-mips.org
OU 2012Ae01OA20EO 13:18, Zumeng Chen D'uA:
> This patch fixes two issues as follows:
>
> For some filesystem with fsync == noop_fsync, there is not so much thing
> to do, so sys_msync just passes by for all arches but some CPUs.
>
> For some CPUs with cache aliases(dmesg|grep alias), it maybe has an issue,
> which reported by msync test suites in ltp-full when the memory of memset
> used by msync01 runs into cache alias randomly.
>
> Consider the following scenario used by msync01 in ltp-full:
> fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0);
> .../* initialization fildes by write(fildes); */
> addr = mmap(0, page_sz, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED,
> fildes, 0);
> /* set buf with memset */
> memset(addr + OFFSET_1, 1, BUF_SIZE);
>
> /* msync the addr before using, or MS_SYNC*/
> msync(addr, page_sz, MS_ASYNC)
>
> /* Tries to read fildes */
> lseek(fildes, (off_t) OFFSET_1, SEEK_SET) != (off_t) OFFSET_1) {
> nread = read(fildes, read_buf, sizeof(read_buf));
>
> /* Then test the result */
> if (read_buf[count] != 1) {
>
> The test result is random too for CPUs with cache alias. So in this
> situation, we have to flush the related vma to make sure the read is
> correct.
>
> Signed-off-by: Zumeng Chen <zumeng.chen@windriver.com>
> ---
> mm/msync.c | 30 ++++++++++++++++++++++++++++++
> 1 files changed, 30 insertions(+), 0 deletions(-)
>
> diff --git a/mm/msync.c b/mm/msync.c
> index 632df45..0021a7e 100644
> --- a/mm/msync.c
> +++ b/mm/msync.c
> @@ -13,6 +13,14 @@
> #include <linux/file.h>
> #include <linux/syscalls.h>
> #include <linux/sched.h>
> +#include <asm/cacheflush.h>
> +
> +/* Cache aliases should be taken into accounts when msync. */
> +#ifdef cpu_has_dc_aliases
> +#define CPU_HAS_CACHE_ALIAS cpu_has_dc_aliases
> +#else
> +#define CPU_HAS_CACHE_ALIAS 0
> +#endif
>
> /*
> * MS_SYNC syncs the entire file - including mappings.
> @@ -78,6 +86,28 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags)
> }
> file = vma->vm_file;
> start = vma->vm_end;
> +
> + /*
> + * For some filesystems with fsync == noop_fsync, msync just
> + * passes by but some CPUs.
> + * For CPUs with cache alias, msync has to flush the related
> + * vma explicitly to make sure data coherency between memory
> + * and cache, which includes MS_SYNC or MS_ASYNC. That is to
> + * say, cache aliases should not be an async factor, so does
> + * msync on other arches without cache aliases.
> + */
> + if (file && file->f_op && file->f_op->fsync == noop_fsync) {
> + if (CPU_HAS_CACHE_ALIAS)
> + flush_cache_range(vma, vma->vm_start,
> + vma->vm_end);
> + if (start >= end) {
> + error = 0;
> + goto out_unlock;
> + }
> + vma = find_vma(mm, start);
> + continue;
> + }
> +
> if ((flags & MS_SYNC) && file &&
> (vma->vm_flags & VM_SHARED)) {
> get_file(file);
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2012-01-21 3:25 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-20 5:18 [PATCH 1/1] mm: msync: fix issues of sys_msync on tmpfs Zumeng Chen
2012-01-21 3:23 ` Zumeng Chen [this message]
2012-01-21 3:23 ` Zumeng Chen
2012-01-21 3:23 ` Zumeng Chen
2012-01-21 20:53 ` Hugh Dickins
2012-01-21 20:53 ` Hugh Dickins
2012-02-01 8:51 ` Zumeng Chen
2012-02-01 8:51 ` Zumeng Chen
2012-02-01 8:51 ` Zumeng Chen
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=4F1A2F96.2040106@windriver.com \
--to=zumeng.chen@windriver.com \
--cc=bruce.ashfield@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=linux-mm@kvack.org \
--cc=mingo@elte.hu \
--cc=ralf@linux-mips.org \
--cc=torvalds@linux-foundation.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 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.