linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Hugh Dickins <hughd@google.com>
To: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org, mgorman@suse.de,
	Andrea Arcangeli <aarcange@redhat.com>,
	Hugh Dickins <hughd@google.com>,
	chrubis@suse.cz
Subject: Re: Corruption with O_DIRECT and unaligned user buffers
Date: Mon, 30 Jun 2014 21:18:15 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LSU.2.11.1406302056510.12406@eggly.anvils> (raw)
In-Reply-To: <53ACD20B.2030601@cn.fujitsu.com>

On Fri, 27 Jun 2014, Xiaoguang Wang wrote:
> Hi maintainers,

That's not me, but I'll answer with my opinion.

> 
> In August 2008, there was a discussion about 'Corruption with O_DIRECT and unaligned user buffers',
> please have a look at this url: http://thread.gmane.org/gmane.linux.file-systems/27358

Whereas (now the truth can be told!) "someone wishing to remain anonymous"
in that thread was indeed me.  Then as now, disinclined to spend time on it.

> 
> The attached test program written by Tim has been added to LTP, please see this below url:
> https://github.com/linux-test-project/ltp/blob/master/testcases/kernel/io/direct_io/dma_thread_diotest.c
> 
> 
> Now I tested this program in kernel 3.16.0-rc1+, it seems that the date corruption still exists. Meanwhile
> there is also such a section in open(2)'s manpage warning that O_DIRECT I/Os should never be run
> concurrently with the fork(2) system call. Please see below section:
> 
>     O_DIRECT I/Os should never be run concurrently with the fork(2) system call, if the memory buffer
>     is a private mapping (i.e., any mapping created with the mmap(2) MAP_PRIVATE flag; this includes
>     memory allocated on the heap and statically allocated buffers).  Any such I/Os, whether  submitted
>     via an asynchronous I/O interface or from another thread in the process, should be completed before
>     fork(2) is called.  Failure to do so can result in data corruption and undefined behavior in parent
>     and child processes.  This restriction does not apply when the memory buffer for  the  O_DIRECT
>     I/Os  was  created  using shmat(2) or mmap(2) with the MAP_SHARED flag.  Nor does this restriction
>     apply when the memory buffer has been advised as MADV_DONTFORK with madvise(2), ensuring that it will
>     not be available to the child after fork(2).
> 
> Hmm, so I'd like to know whether you have some plans to fix this bug, or this is not considered as a
> bug, it's just a programming specification that we should avoid doing fork() while we are having O_DIRECT
> file operation with non-page aligned IO, thanks.
> 
> Steps to run this attached program:
> 1. ./dma_thread  # create temp files
> 2. ./dma_thread -a 512 -w 8 $ alignment is 512 and create 8 threads.

I regard it, then and now, as a displeasing limitation;
but one whose fix would cause more trouble than it's worth.

I thought we settled long ago on MADV_DONTFORK as an imperfect but
good enough workaround.  Not everyone will agree.  I certainly have
no plans to go further myself.

Hugh

--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  reply	other threads:[~2014-07-01  4:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-27  2:08 Xiaoguang Wang
2014-07-01  4:18 ` Hugh Dickins [this message]
2014-07-02 11:39   ` Xiaoguang Wang
  -- strict thread matches above, loose matches on Subject: below --
2008-11-14 17:04 Tim LaBerge
2008-11-19  4:25 ` Nick Piggin
2008-11-19  6:52   ` Nick Piggin
2008-11-19 16:58   ` Andrea Arcangeli
2008-12-18 15:29     ` Andrea Arcangeli
2008-12-19  2:21       ` KAMEZAWA Hiroyuki
2008-12-19  5:06         ` KAMEZAWA Hiroyuki
2008-12-19  6:34       ` KOSAKI Motohiro
2008-12-20 16:02         ` Andrea Arcangeli
2008-12-19  7:19       ` KAMEZAWA Hiroyuki
2008-12-19  7:44         ` Li Zefan
2008-12-19  8:45           ` Li Zefan
2008-12-19 20:27           ` Andrea Arcangeli
2008-12-20 15:55         ` Andrea Arcangeli
2008-12-19 11:51       ` Li Zefan
2008-12-19 12:14         ` KOSAKI Motohiro
2008-12-19 12:58         ` Hugh Dickins
2008-12-19 20:34         ` Andrea Arcangeli

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=alpine.LSU.2.11.1406302056510.12406@eggly.anvils \
    --to=hughd@google.com \
    --cc=aarcange@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=chrubis@suse.cz \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@suse.de \
    --cc=wangxg.fnst@cn.fujitsu.com \
    /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